From 65a431fe1fc7e3745a5de88a3d93b734329926bc Mon Sep 17 00:00:00 2001 From: Dave Wysochanski Date: Fri, 25 Jul 2008 14:59:51 +0000 Subject: [PATCH] Refactor pvcreate - simplify return codes. --- test/t-pvcreate-operation.sh | 12 ++++++++++++ tools/pvcreate.c | 16 ++++++++-------- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/test/t-pvcreate-operation.sh b/test/t-pvcreate-operation.sh index 5554108fb..62e13704e 100755 --- a/test/t-pvcreate-operation.sh +++ b/test/t-pvcreate-operation.sh @@ -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 \ diff --git a/tools/pvcreate.c b/tools/pvcreate.c index 893175611..45859061b 100644 --- a/tools/pvcreate.c +++ b/tools/pvcreate.c @@ -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; } -- 2.43.5