From c2d72fd4025cc0411998e87d1eb5fc3ed698d17b Mon Sep 17 00:00:00 2001 From: Alasdair Kergon Date: Wed, 28 Nov 2001 18:03:11 +0000 Subject: [PATCH] Add -t or --test arg to all tools that update metadata to avoid committing metadata changes or (de)activating. --- lib/activate/activate.c | 10 +++++++ lib/device/dev-io.c | 4 +++ tools/commands.h | 58 ++++++++++++++++++++++++++++------------- tools/lvm.c | 5 +++- tools/lvremove.c | 4 +-- 5 files changed, 60 insertions(+), 21 deletions(-) diff --git a/lib/activate/activate.c b/lib/activate/activate.c index 3faf82b5f..e23f658af 100644 --- a/lib/activate/activate.c +++ b/lib/activate/activate.c @@ -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; diff --git a/lib/device/dev-io.c b/lib/device/dev-io.c index 64632762f..cd0b1f9e4 100644 --- a/lib/device/dev-io.c +++ b/lib/device/dev-io.c @@ -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); diff --git a/tools/commands.h b/tools/commands.h index 46a44e2ba..b2d55be6f 100644 --- a/tools/commands.h +++ b/tools/commands.h @@ -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", diff --git a/tools/lvm.c b/tools/lvm.c index 7f654d784..f14244636 100644 --- a/tools/lvm.c +++ b/tools/lvm.c @@ -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); diff --git a/tools/lvremove.c b/tools/lvremove.c index 697ce2a99..5c474547b 100644 --- a/tools/lvremove.c +++ b/tools/lvremove.c @@ -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 -- 2.43.5