1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-03-31 14:50:37 +03:00

Add -t or --test arg to all tools that update metadata to avoid

committing metadata changes or (de)activating.
This commit is contained in:
Alasdair Kergon 2001-11-28 18:03:11 +00:00
parent 54fad845c9
commit 6eeb5528f5
5 changed files with 60 additions and 21 deletions

View File

@ -165,6 +165,9 @@ int _load(struct logical_volume *lv, int task)
/* FIXME: Always display error msg */
int lv_activate(struct logical_volume *lv)
{
if (test_mode())
return 0;
return _load(lv, DM_DEVICE_CREATE) && fs_add_lv(lv);
}
@ -190,6 +193,10 @@ int _suspend(struct logical_volume *lv, int sus)
int lv_reactivate(struct logical_volume *lv)
{
int r;
if (test_mode())
return 0;
if (!_suspend(lv, 1)) {
stack;
return 0;
@ -210,6 +217,9 @@ int lv_deactivate(struct logical_volume *lv)
int r;
struct dm_task *dmt;
if (test_mode())
return 0;
if (!(dmt = _setup_task(lv, DM_DEVICE_REMOVE))) {
stack;
return 0;

View File

@ -121,6 +121,10 @@ int _write(int fd, const void *buf, size_t count)
size_t n = 0;
int tot = 0;
/* Skip all writes */
if (test_mode())
return count;
while (tot < count) {
do
n = write(fd, buf, count - tot);

View File

@ -57,11 +57,12 @@ xx(lvchange,
"\t[-h/-?/--help]\n"
"\t[-p/--permission r/rw]\n"
"\t[-r/--readahead ReadAheadSectors]\n"
"\t[-t/--test]\n"
"\t[-v/--verbose]\n"
"\tLogicalVolume[Path] [LogicalVolume[Path]...]\n",
autobackup_ARG, available_ARG, contiguous_ARG,
permission_ARG, readahead_ARG)
permission_ARG, readahead_ARG, test_ARG)
xx(lvcreate,
"Create a logical volume",
@ -76,6 +77,7 @@ xx(lvcreate,
"[-n|--name LogicalVolumeName]\n\t"
"[-p|--permission {r|rw}] "
"[-r|--readahead ReadAheadSectors]\n\t"
"[-t|--test] "
"[-v|--verbose] "
"[-Z|--zero {y|n}] "
"[--version]\n\t"
@ -86,11 +88,12 @@ xx(lvcreate,
"{-l|--extents LogicalExtentsNumber |\n\t"
" -L|--size LogicalVolumeSize[kKmMgGtT]}\n\t"
"-n|--name SnapshotLogicalVolumeName\n\t"
"[-t|--test]\n\t"
"LogicalVolume[Path] [PhysicalVolumePath...]\n",
autobackup_ARG, chunksize_ARG, contiguous_ARG,
stripes_ARG, stripesize_ARG, extents_ARG, size_ARG, name_ARG,
permission_ARG, readahead_ARG, snapshot_ARG, zero_ARG)
permission_ARG, readahead_ARG, snapshot_ARG, test_ARG, zero_ARG)
xx(lvdisplay,
"Display information about a logical volume",
@ -113,10 +116,12 @@ xx(lvextend,
"\t[-i|--stripes Stripes [-I|--stripesize StripeSize]]\n"
"\t{-l/--extents [+]LogicalExtentsNumber |\n"
"\t -L/--size [+]LogicalVolumeSize[kKmMgGtT]}\n"
"\t[-t/--test]\n"
"\t[-v/--verbose]\n"
"\tLogicalVolume[Path] [ PhysicalVolumePath... ]\n",
autobackup_ARG, extents_ARG, size_ARG, stripes_ARG, stripesize_ARG)
autobackup_ARG, extents_ARG, size_ARG, stripes_ARG, stripesize_ARG,
test_ARG)
xx(lvmchange,
"With the device mapper, lvmchange is obsolete and does nothing.",
@ -169,11 +174,12 @@ xx(lvreduce,
"\t[-h/-?/--help]\n"
"\t{-l/--extents [-]LogicalExtentsNumber |\n"
"\t -L/--size [-]LogicalVolumeSize[kKmMgGtT]}\n"
"\t[-t/--test]\n"
"\t[-v/--verbose]\n"
"\tLogicalVolume[Path]\n",
autobackup_ARG, force_ARG, extents_ARG,
size_ARG, yes_ARG)
size_ARG, test_ARG, yes_ARG)
xx(lvremove,
"Remove logical volume(s) from the system",
@ -182,10 +188,11 @@ xx(lvremove,
"\t[-d/--debug]\n"
"\t[-f/--force]\n"
"\t[-h/-?/--help]\n"
"\t[-t/--test]\n"
"\t[-v/--verbose]\n"
"\tLogicalVolume[Path] [LogicalVolume[Path]...]\n",
autobackup_ARG, force_ARG)
autobackup_ARG, force_ARG, test_ARG)
xx(lvrename,
"Rename a logical volume",
@ -193,12 +200,13 @@ xx(lvrename,
"[-A|--autobackup {y|n}] "
"[-d|--debug] "
"[-h|--help] "
"[-t|--test] "
"[-v|--verbose]\n\t"
"[--version] "
"{ OldLogicalVolumePath NewLogicalVolumePath |\n\t"
" VolumeGroupName OldLogicalVolumeName NewLogicalVolumeName }\n",
autobackup_ARG)
autobackup_ARG, test_ARG)
xx(lvresize,
"Resize a logical volume",
@ -209,10 +217,12 @@ xx(lvresize,
"\t[-i|--stripes Stripes [-I|--stripesize StripeSize]]\n"
"\t{-l/--extents [+/-]LogicalExtentsNumber |\n"
"\t -L/--size [+/-]LogicalVolumeSize[kKmMgGtT]}\n"
"\t[-t|--test]\n"
"\t[-v/--verbose]\n"
"\tLogicalVolume[Path] [ PhysicalVolumePath... ]\n",
autobackup_ARG, extents_ARG, size_ARG, stripes_ARG, stripesize_ARG)
autobackup_ARG, extents_ARG, size_ARG, stripes_ARG, stripesize_ARG,
test_ARG)
xx(lvscan,
"List all logical volumes in all volume groups",
@ -234,10 +244,11 @@ xx(pvchange,
"\t[-h/-?/--help]\n"
"\t[-v/--verbose]\n"
"\t[-a/--all]\n"
"\t[-t|--test]\n"
"\t[-x/--allocation y/n]\n"
"\t[PhysicalVolumePath...]\n",
all_ARG, autobackup_ARG, allocation_ARG)
all_ARG, autobackup_ARG, allocation_ARG, test_ARG)
xx(pvcreate,
"Initialize physical volume(s) for use by LVM",
@ -246,11 +257,12 @@ xx(pvcreate,
"[-f[f]|--force [--force]] "
"[-h|--help] "
"[-y|--yes]\n\t"
"[-t|--test] "
"[-v|--verbose] "
"[--version] "
"PhysicalVolume [PhysicalVolume...]\n",
force_ARG, yes_ARG)
force_ARG, test_ARG, yes_ARG)
xx(pvdata,
"Display the on-disk metadata for physical volume(s)",
@ -343,7 +355,8 @@ xx(vgchange,
"vgchange\n\t"
"[-A|--autobackup {y|n}] "
"[-d|--debug] "
"[-h|--help]\n\t"
"[-h|--help] "
"[-t|--test]\n\t"
"[-v|--verbose] "
"[--version]\n\t"
"{-a|--available {y|n} |\n\t"
@ -351,7 +364,8 @@ xx(vgchange,
" -l|--logicalvolume MaxLogicalVolumes}\n\t"
"[VolumeGroupName...]\n",
autobackup_ARG, available_ARG, logicalvolume_ARG, allocation_ARG )
autobackup_ARG, available_ARG, logicalvolume_ARG, allocation_ARG,
test_ARG)
xx(vgck,
"Check the consistency of volume group(s)",
@ -370,13 +384,14 @@ xx(vgcreate,
"[-p|--maxphysicalvolumes MaxPhysicalVolumes] "
"[-h|--help]\n\t"
"[-s|--physicalextentsize PhysicalExtentSize[kKmMgGtT]] "
"[-t|--test] "
"[-v|--verbose]\n\t"
"[--version] "
"VolumeGroupName "
"PhysicalVolume [PhysicalVolume...]\n",
autobackup_ARG, maxlogicalvolumes_ARG, maxphysicalvolumes_ARG,
physicalextentsize_ARG)
physicalextentsize_ARG, test_ARG)
xx(vgdisplay,
"Display volume group information",
@ -399,7 +414,7 @@ xx(vgexport,
"[--version] "
"VolumeGroupName [VolumeGroupName...]\n",
all_ARG)
all_ARG, test_ARG)
xx(vgextend,
"Add physical volumes to a volume group",
@ -407,11 +422,12 @@ xx(vgextend,
"\t[-A/--autobackup y/n]\n"
"\t[-d/--debug]\n"
"\t[-h/-?/--help]\n"
"\t[-t/--test]\n"
"\t[-v/--verbose]\n"
"\tVolumeGroupName\n"
"\tPhysicalDevicePath [PhysicalDevicePath...]\n",
autobackup_ARG)
autobackup_ARG, test_ARG)
xx(vgimport,
"Register exported volume group with system",
@ -419,11 +435,12 @@ xx(vgimport,
"[-d|--debug] "
"[-f|--force] "
"[-h|--help] "
"[-t|--test] "
"[-v|--verbose]\n\t"
"VolumeGroupName PhysicalVolumePath "
"[PhysicalVolumePath...]\n",
force_ARG)
force_ARG, test_ARG)
xx(vgmerge,
"Merge volume groups",
@ -453,19 +470,23 @@ xx(vgreduce,
"\t[-A/--autobackup y/n]\n"
"\t[-d/--debug]\n"
"\t[-h/-?/--help]\n"
"\t[-t/--test]\n"
"\t[-v/--verbose]\n"
"\tVolumeGroupName\n"
"\t[PhysicalVolumePath...]\n",
all_ARG, autobackup_ARG)
all_ARG, autobackup_ARG, test_ARG)
xx(vgremove,
"Remove volume group(s)",
"vgremove\n"
"\t[-d/--debug]\n"
"\t[-h/-?/--help]\n"
"\t[-t/--test]\n"
"\t[-v/--verbose]\n"
"\tVolumeGroupName [VolumeGroupName...]\n" )
"\tVolumeGroupName [VolumeGroupName...]\n",
test_ARG)
xx(vgrename,
"Rename a volume group",
@ -474,11 +495,12 @@ xx(vgrename,
"\t[-d/--debug]\n"
"\t[-f/--force]\n"
"\t[-h/-?/--help]\n"
"\t[-t/--test]\n"
"\t[-v/--verbose]\n"
"\tOldVolumeGroupPath NewVolumeGroupPath /\n"
"\tOldVolumeGroupName NewVolumeGroupName\n",
autobackup_ARG, force_ARG)
autobackup_ARG, force_ARG, test_ARG)
xx(vgscan,
"Search for all volume groups",

View File

@ -479,7 +479,10 @@ static int process_common_commands(struct command *com)
init_verbose(arg_count(verbose_ARG));
init_test(arg_count(test_ARG));
if ((l = arg_count(test_ARG))) {
log_error("Test mode. Metadata will NOT be updated.");
init_test(l);
}
if (arg_count(help_ARG)) {
usage(com->name);

View File

@ -53,7 +53,7 @@ static int lvremove_single(struct logical_volume *lv)
}
/* FIXME Force option? */
if (lv_open_count(lv)) {
if (lv_open_count(lv) > 0) {
log_error("Can't remove open logical volume %s", lv->name);
return ECMD_FAILED;
}
@ -84,7 +84,7 @@ static int lvremove_single(struct logical_volume *lv)
**********/
/* store it on disks */
if (fid->ops->vg_write(fid, vg))
if (!fid->ops->vg_write(fid, vg))
return ECMD_FAILED;
/******** FIXME