public inbox for lvm2-cvs@sourceware.org
help / color / mirror / Atom feed
* LVM2 test/t-pvcreate-operation.sh tools/pvcreate.c
@ 2008-07-25 14:59 wysochanski
0 siblings, 0 replies; 3+ messages in thread
From: wysochanski @ 2008-07-25 14:59 UTC (permalink / raw)
To: lvm-devel, lvm2-cvs
CVSROOT: /cvs/lvm2
Module name: LVM2
Changes by: wysochanski@sourceware.org 2008-07-25 14:59:51
Modified files:
test : t-pvcreate-operation.sh
tools : pvcreate.c
Log message:
Refactor pvcreate - simplify return codes.
Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/test/t-pvcreate-operation.sh.diff?cvsroot=lvm2&r1=1.5&r2=1.6
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/tools/pvcreate.c.diff?cvsroot=lvm2&r1=1.72&r2=1.73
--- LVM2/test/t-pvcreate-operation.sh 2008/07/25 14:36:52 1.5
+++ LVM2/test/t-pvcreate-operation.sh 2008/07/25 14:59:51 1.6
@@ -42,6 +42,18 @@
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 \
--- LVM2/tools/pvcreate.c 2008/07/25 14:45:24 1.72
+++ LVM2/tools/pvcreate.c 2008/07/25 14:59:51 1.73
@@ -153,13 +153,13 @@
(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 @@
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 @@
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 @@
}
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;
}
^ permalink raw reply [flat|nested] 3+ messages in thread
* LVM2 test/t-pvcreate-operation.sh tools/pvcreate.c
@ 2008-07-25 14:37 wysochanski
0 siblings, 0 replies; 3+ messages in thread
From: wysochanski @ 2008-07-25 14:37 UTC (permalink / raw)
To: lvm-devel, lvm2-cvs
CVSROOT: /cvs/lvm2
Module name: LVM2
Changes by: wysochanski@sourceware.org 2008-07-25 14:36:56
Modified files:
test : t-pvcreate-operation.sh
tools : pvcreate.c
Log message:
Refactor pvcreate - --force parameter.
Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/test/t-pvcreate-operation.sh.diff?cvsroot=lvm2&r1=1.4&r2=1.5
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/tools/pvcreate.c.diff?cvsroot=lvm2&r1=1.70&r2=1.71
--- LVM2/test/t-pvcreate-operation.sh 2008/07/25 00:30:57 1.4
+++ LVM2/test/t-pvcreate-operation.sh 2008/07/25 14:36:52 1.5
@@ -45,7 +45,7 @@
done
test_expect_success \
- 'pvcreate (lvm2) fails when PV with metadatacopies=0 belongs to VG' \
+ 'pvcreate (lvm2) fails without -ff when PV with metadatacopies=0 belongs to VG' \
'pvcreate --metadatacopies 0 $d1 &&
pvcreate --metadatacopies 1 $d2 &&
vgcreate $vg1 $d1 $d2 &&
--- LVM2/tools/pvcreate.c 2008/07/25 14:12:29 1.70
+++ LVM2/tools/pvcreate.c 2008/07/25 14:36:55 1.71
@@ -28,6 +28,7 @@
uint32_t extent_count;
uint32_t extent_size;
const char *restorefile; /* 0 if no --restorefile option */
+ force_t force;
};
const char _really_init[] =
@@ -64,7 +65,7 @@
/* Allow partial & exported VGs to be destroyed. */
/* We must have -ff to overwrite a non orphan */
- if (pv && !is_orphan(pv) && arg_count(cmd, force_ARG) != 2) {
+ if (pv && !is_orphan(pv) && pp->force != DONT_PROMPT_OVERRIDE) {
log_error("Can't initialize physical volume \"%s\" of "
"volume group \"%s\" without -ff", name, pv_vg_name(pv));
return 0;
@@ -129,7 +130,7 @@
if (sigint_caught())
return 0;
- if (pv && !is_orphan(pv) && arg_count(cmd, force_ARG)) {
+ if (pv && !is_orphan(pv) && pp->force) {
log_warn("WARNING: Forcing physical volume creation on "
"%s%s%s%s", name,
!is_orphan(pv) ? " of volume group \"" : "",
@@ -291,6 +292,8 @@
return 0;
}
+ pp->force = arg_count(cmd, force_ARG);
+
if (arg_int_value(cmd, labelsector_ARG, 0) >= LABEL_SCAN_SECTORS) {
log_error("labelsector must be less than %lu",
LABEL_SCAN_SECTORS);
^ permalink raw reply [flat|nested] 3+ messages in thread
* LVM2 test/t-pvcreate-operation.sh tools/pvcreate.c
@ 2008-07-25 0:30 wysochanski
0 siblings, 0 replies; 3+ messages in thread
From: wysochanski @ 2008-07-25 0:30 UTC (permalink / raw)
To: lvm-devel, lvm2-cvs
CVSROOT: /cvs/lvm2
Module name: LVM2
Changes by: wysochanski@sourceware.org 2008-07-25 00:30:57
Modified files:
test : t-pvcreate-operation.sh
tools : pvcreate.c
Log message:
Refactor pvcreate - move uuid and restorefile options.
Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/test/t-pvcreate-operation.sh.diff?cvsroot=lvm2&r1=1.3&r2=1.4
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/tools/pvcreate.c.diff?cvsroot=lvm2&r1=1.68&r2=1.69
--- LVM2/test/t-pvcreate-operation.sh 2008/07/24 17:33:40 1.3
+++ LVM2/test/t-pvcreate-operation.sh 2008/07/25 00:30:57 1.4
@@ -91,8 +91,8 @@
test_expect_success \
'pvcreate rejects uuid already in use' \
- 'pvcreate --uuid freddy-fred-fred-fred-fred-fred-freddy $d1 &&
- pvcreate --uuid freddy-fred-fred-fred-fred-fred-freddy $d2;
+ 'pvcreate --uuid $uuid1 $d1 &&
+ pvcreate --uuid $uuid1 $d2;
status=$?; echo status=$status; test $status != 0'
test_expect_success \
--- LVM2/tools/pvcreate.c 2008/07/24 15:25:09 1.68
+++ LVM2/tools/pvcreate.c 2008/07/25 00:30:57 1.69
@@ -22,6 +22,12 @@
int pvmetadatacopies;
uint64_t pvmetadatasize;
int64_t labelsector;
+ struct id id; /* FIXME: redundant */
+ struct id *idp;
+ uint64_t pe_start;
+ uint32_t extent_count;
+ uint32_t extent_size;
+ const char *restorefile;
};
const char _really_init[] =
@@ -138,47 +144,16 @@
{
struct pvcreate_params *pp = (struct pvcreate_params *) handle;
void *pv;
- void *existing_pv;
- struct id id, *idp = NULL;
- const char *uuid = NULL;
struct device *dev;
struct list mdas;
- struct volume_group *vg;
- const char *restorefile;
- uint64_t pe_start = 0;
- uint32_t extent_count = 0, extent_size = 0;
- if (arg_count(cmd, uuidstr_ARG)) {
- uuid = arg_str_value(cmd, uuidstr_ARG, "");
- if (!id_read_format(&id, uuid))
- return EINVALID_CMD_LINE;
- if ((dev = device_from_pvid(cmd, &id)) &&
+ if (pp->idp) {
+ if ((dev = device_from_pvid(cmd, pp->idp)) &&
(dev != dev_cache_get(pv_name, cmd->filter))) {
- log_error("uuid %s already in use on \"%s\"", uuid,
- dev_name(dev));
- return ECMD_FAILED;
- }
- idp = &id;
- }
-
- if (arg_count(cmd, restorefile_ARG)) {
- restorefile = arg_str_value(cmd, restorefile_ARG, "");
- /* The uuid won't already exist */
- init_partial(1);
- if (!(vg = backup_read_vg(cmd, NULL, restorefile))) {
- log_error("Unable to read volume group from %s",
- restorefile);
- return ECMD_FAILED;
- }
- init_partial(0);
- if (!(existing_pv = find_pv_in_vg_by_uuid(vg, idp))) {
- log_error("Can't find uuid %s in backup file %s",
- uuid, restorefile);
+ log_error("uuid %s already in use on \"%s\"",
+ pp->idp->uuid, dev_name(dev));
return ECMD_FAILED;
}
- pe_start = pv_pe_start(existing_pv);
- extent_size = pv_pe_size(existing_pv);
- extent_count = pv_pe_count(existing_pv);
}
if (!lock_vol(cmd, VG_ORPHANS, LCK_VG_WRITE)) {
@@ -199,8 +174,9 @@
}
list_init(&mdas);
- if (!(pv = pv_create(cmd, dev, idp, pp->size, pe_start,
- extent_count, extent_size, pp->pvmetadatacopies,
+ if (!(pv = pv_create(cmd, dev, pp->idp, pp->size, pp->pe_start,
+ pp->extent_count, pp->extent_size,
+ pp->pvmetadatacopies,
pp->pvmetadatasize,&mdas))) {
log_error("Failed to setup physical volume \"%s\"", pv_name);
goto error;
@@ -261,6 +237,12 @@
int argc, char **argv,
struct pvcreate_params *pp)
{
+ const char *uuid = NULL;
+ void *existing_pv;
+ struct volume_group *vg;
+
+ memset(pp, 0, sizeof(*pp));
+
if (!argc) {
log_error("Please enter a physical volume path");
return 0;
@@ -276,6 +258,33 @@
return 0;
}
+ if (arg_count(cmd, uuidstr_ARG)) {
+ uuid = arg_str_value(cmd, uuidstr_ARG, "");
+ if (!id_read_format(&pp->id, uuid))
+ return 0;
+ pp->idp = &pp->id;
+ }
+
+ if (arg_count(cmd, restorefile_ARG)) {
+ pp->restorefile = arg_str_value(cmd, restorefile_ARG, "");
+ /* The uuid won't already exist */
+ init_partial(1);
+ if (!(vg = backup_read_vg(cmd, NULL, pp->restorefile))) {
+ log_error("Unable to read volume group from %s",
+ pp->restorefile);
+ return 0;
+ }
+ init_partial(0);
+ if (!(existing_pv = find_pv_in_vg_by_uuid(vg, pp->idp))) {
+ log_error("Can't find uuid %s in backup file %s",
+ uuid, pp->restorefile);
+ return 0;
+ }
+ pp->pe_start = pv_pe_start(existing_pv);
+ pp->extent_size = pv_pe_size(existing_pv);
+ pp->extent_count = pv_pe_count(existing_pv);
+ }
+
if (arg_count(cmd, yes_ARG) && !arg_count(cmd, force_ARG)) {
log_error("Option y can only be given with option f");
return 0;
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2008-07-25 14:59 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-07-25 14:59 LVM2 test/t-pvcreate-operation.sh tools/pvcreate.c wysochanski
-- strict thread matches above, loose matches on Subject: below --
2008-07-25 14:37 wysochanski
2008-07-25 0:30 wysochanski
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).