]> sourceware.org Git - lvm2.git/commitdiff
Refactor pvcreate - simplify return codes.
authorDave Wysochanski <dwysocha@redhat.com>
Fri, 25 Jul 2008 14:59:51 +0000 (14:59 +0000)
committerDave Wysochanski <dwysocha@redhat.com>
Fri, 25 Jul 2008 14:59:51 +0000 (14:59 +0000)
test/t-pvcreate-operation.sh
tools/pvcreate.c

index 5554108fb2517a64ce85f1f649d75a71b2673723..62e13704e57d4f20809e32347778cfeba0bbbc95 100755 (executable)
@@ -42,6 +42,18 @@ test_expect_success \
    vgremove -f $vg1 &&
    pvremove -f $d1'
 
+test_expect_success \
+  "pvcreate (lvm$mdatype) fails when PV1 does and PV2 does not belong to VG" \
+  'pvcreate -M$mdatype $d1 &&
+   pvcreate -M$mdatype $d2 &&
+   vgcreate -M$mdatype $vg1 $d1 &&
+   echo pvcreate a second time on $d2 and $d1 &&
+   pvcreate -M$mdatype $d2 $d1;
+   status=$?; echo status=$status; test $status != 0 &&
+   vgremove -f $vg1 &&
+   pvremove -f $d2 &&
+   pvremove -f $d1'
+
 done
 
 test_expect_success \
index 893175611f98c0c553e6b689489832625f4b19c9..45859061bff768c926e545979bd4a88042ed6513 100644 (file)
@@ -153,13 +153,13 @@ static int pvcreate_single(struct cmd_context *cmd, const char *pv_name,
                    (dev != dev_cache_get(pv_name, cmd->filter))) {
                        log_error("uuid %s already in use on \"%s\"",
                                  pp->idp->uuid, dev_name(dev));
-                       return ECMD_FAILED;
+                       return 0;
                }
        }
 
        if (!lock_vol(cmd, VG_ORPHANS, LCK_VG_WRITE)) {
                log_error("Can't get lock for orphan PVs");
-               return ECMD_FAILED;
+               return 0;
        }
 
        if (!pvcreate_check(cmd, pv_name, pp))
@@ -218,11 +218,11 @@ static int pvcreate_single(struct cmd_context *cmd, const char *pv_name,
        log_print("Physical volume \"%s\" successfully created", pv_name);
 
        unlock_vg(cmd, VG_ORPHANS);
-       return ECMD_PROCESSED;
+       return 1;
 
       error:
        unlock_vg(cmd, VG_ORPHANS);
-       return ECMD_FAILED;
+       return 0;
 }
 
 /*
@@ -352,7 +352,7 @@ static int pvcreate_validate_params(struct cmd_context *cmd,
 
 int pvcreate(struct cmd_context *cmd, int argc, char **argv)
 {
-       int i, r;
+       int i;
        int ret = ECMD_PROCESSED;
        struct pvcreate_params pp;
 
@@ -361,9 +361,9 @@ int pvcreate(struct cmd_context *cmd, int argc, char **argv)
        }
 
        for (i = 0; i < argc; i++) {
-               r = pvcreate_single(cmd, argv[i], &pp);
-               if (r > ret)
-                       ret = r;
+               if (!pvcreate_single(cmd, argv[i], &pp))
+                       ret = ECMD_FAILED;
+
                if (sigint_caught())
                        return ret;
        }
This page took 0.033191 seconds and 5 git commands to generate.