LCOV - code coverage report
Current view: top level - misc/kabi/lvm2.git/tools - vgcreate.c (source / functions) Hit Total Coverage
Test: unnamed Lines: 0 65 0.0 %
Date: 2010-04-13 Functions: 0 1 0.0 %
Branches: 0 50 0.0 %

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :  * Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved.
       3                 :            :  * Copyright (C) 2004-2009 Red Hat, Inc. All rights reserved.
       4                 :            :  *
       5                 :            :  * This file is part of LVM2.
       6                 :            :  *
       7                 :            :  * This copyrighted material is made available to anyone wishing to use,
       8                 :            :  * modify, copy, or redistribute it subject to the terms and conditions
       9                 :            :  * of the GNU Lesser General Public License v.2.1.
      10                 :            :  *
      11                 :            :  * You should have received a copy of the GNU Lesser General Public License
      12                 :            :  * along with this program; if not, write to the Free Software Foundation,
      13                 :            :  * Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
      14                 :            :  */
      15                 :            : 
      16                 :            : #include "tools.h"
      17                 :            : 
      18                 :          0 : int vgcreate(struct cmd_context *cmd, int argc, char **argv)
      19                 :            : {
      20                 :            :         struct vgcreate_params vp_new;
      21                 :            :         struct vgcreate_params vp_def;
      22                 :            :         struct volume_group *vg;
      23                 :            :         const char *tag;
      24                 :          0 :         const char *clustered_message = "";
      25                 :            :         char *vg_name;
      26                 :            :         struct pvcreate_params pp;
      27                 :            : 
      28         [ #  # ]:          0 :         if (!argc) {
      29                 :          0 :                 log_error("Please provide volume group name and "
      30                 :            :                           "physical volumes");
      31                 :          0 :                 return EINVALID_CMD_LINE;
      32                 :            :         }
      33                 :            : 
      34                 :          0 :         vg_name = argv[0];
      35                 :          0 :         argc--;
      36                 :          0 :         argv++;
      37                 :            : 
      38         [ #  # ]:          0 :         if (arg_count(cmd, metadatacopies_ARG)) {
      39                 :          0 :                 log_error("Invalid option --metadatacopies, "
      40                 :            :                           "use --pvmetadatacopies instead.");
      41                 :          0 :                 return EINVALID_CMD_LINE;
      42                 :            :         }
      43                 :          0 :         pvcreate_params_set_defaults(&pp);
      44         [ #  # ]:          0 :         if (!pvcreate_params_validate(cmd, argc, argv, &pp)) {
      45                 :          0 :                 return EINVALID_CMD_LINE;
      46                 :            :         }
      47                 :            : 
      48                 :          0 :         vgcreate_params_set_defaults(&vp_def, NULL);
      49                 :          0 :         vp_def.vg_name = vg_name;
      50         [ #  # ]:          0 :         if (vgcreate_params_set_from_args(cmd, &vp_new, &vp_def))
      51                 :          0 :                 return EINVALID_CMD_LINE;
      52                 :            : 
      53         [ #  # ]:          0 :         if (vgcreate_params_validate(cmd, &vp_new))
      54                 :          0 :             return EINVALID_CMD_LINE;
      55                 :            : 
      56                 :            :         /* Create the new VG */
      57                 :          0 :         vg = vg_create(cmd, vp_new.vg_name);
      58         [ #  # ]:          0 :         if (vg_read_error(vg)) {
      59         [ #  # ]:          0 :                 if (vg_read_error(vg) == FAILED_EXIST)
      60                 :          0 :                         log_error("A volume group called %s already exists.", vp_new.vg_name);
      61                 :            :                 else
      62                 :          0 :                         log_error("Can't get lock for %s.", vp_new.vg_name);
      63                 :          0 :                 vg_release(vg);
      64                 :          0 :                 return ECMD_FAILED;
      65                 :            :         }
      66                 :            : 
      67 [ #  #  #  #  # :          0 :         if (!vg_set_extent_size(vg, vp_new.extent_size) ||
          #  #  #  #  # ]
      68                 :          0 :             !vg_set_max_lv(vg, vp_new.max_lv) ||
      69                 :          0 :             !vg_set_max_pv(vg, vp_new.max_pv) ||
      70                 :          0 :             !vg_set_alloc_policy(vg, vp_new.alloc) ||
      71                 :          0 :             !vg_set_clustered(vg, vp_new.clustered))
      72                 :            :                 goto bad_orphan;
      73                 :            : 
      74         [ #  # ]:          0 :         if (!lock_vol(cmd, VG_ORPHANS, LCK_VG_WRITE)) {
      75                 :          0 :                 log_error("Can't get lock for orphan PVs");
      76                 :          0 :                 goto bad_orphan;
      77                 :            :         }
      78                 :            : 
      79                 :            :         /* attach the pv's */
      80         [ #  # ]:          0 :         if (!vg_extend(vg, argc, argv, &pp))
      81                 :          0 :                 goto_bad;
      82                 :            : 
      83         [ #  # ]:          0 :         if (vp_new.max_lv != vg->max_lv)
      84                 :          0 :                 log_warn("WARNING: Setting maxlogicalvolumes to %d "
      85                 :            :                          "(0 means unlimited)", vg->max_lv);
      86                 :            : 
      87         [ #  # ]:          0 :         if (vp_new.max_pv != vg->max_pv)
      88                 :          0 :                 log_warn("WARNING: Setting maxphysicalvolumes to %d "
      89                 :            :                          "(0 means unlimited)", vg->max_pv);
      90                 :            : 
      91         [ #  # ]:          0 :         if (arg_count(cmd, addtag_ARG)) {
      92         [ #  # ]:          0 :                 if (!(tag = arg_str_value(cmd, addtag_ARG, NULL))) {
      93                 :          0 :                         log_error("Failed to get tag");
      94                 :          0 :                         goto bad;
      95                 :            :                 }
      96                 :            : 
      97         [ #  # ]:          0 :                 if (!vg_change_tag(vg, tag, 1))
      98                 :          0 :                         goto_bad;
      99                 :            :         }
     100                 :            : 
     101         [ #  # ]:          0 :         if (vg_is_clustered(vg)) {
     102                 :          0 :                 clustered_message = "Clustered ";
     103                 :            :         } else {
     104         [ #  # ]:          0 :                 if (locking_is_clustered())
     105                 :          0 :                         clustered_message = "Non-clustered ";
     106                 :            :         }
     107                 :            : 
     108         [ #  # ]:          0 :         if (!archive(vg))
     109                 :          0 :                 goto_bad;
     110                 :            : 
     111                 :            :         /* Store VG on disk(s) */
     112 [ #  # ][ #  # ]:          0 :         if (!vg_write(vg) || !vg_commit(vg))
     113                 :          0 :                 goto_bad;
     114                 :            : 
     115                 :          0 :         unlock_vg(cmd, VG_ORPHANS);
     116                 :          0 :         unlock_vg(cmd, vp_new.vg_name);
     117                 :            : 
     118                 :          0 :         backup(vg);
     119                 :            : 
     120         [ #  # ]:          0 :         log_print("%s%colume group \"%s\" successfully created",
     121                 :            :                   clustered_message, *clustered_message ? 'v' : 'V', vg->name);
     122                 :            : 
     123                 :          0 :         vg_release(vg);
     124                 :          0 :         return ECMD_PROCESSED;
     125                 :            : 
     126                 :            : bad:
     127                 :          0 :         unlock_vg(cmd, VG_ORPHANS);
     128                 :            : bad_orphan:
     129                 :          0 :         vg_release(vg);
     130                 :          0 :         unlock_vg(cmd, vp_new.vg_name);
     131                 :          0 :         return ECMD_FAILED;
     132                 :            : }

Generated by: LCOV version 1.8