stable-2.03.14 - lvmdevices check: error exit if update is needed
by David Teigland
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=bb477d63e336a10e595...
Commit: bb477d63e336a10e5959962a9f26a028ea9e55eb
Parent: a5c37afdca97d6565ea02bc4bc7d52f360823cd3
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Thu Jan 13 14:52:54 2022 -0600
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Fri Jan 14 15:53:13 2022 -0600
lvmdevices check: error exit if update is needed
. error exit means that lvmdevices --update would make a change.
. remove check of PART field from --check because it isn't used.
. unlink searched_devnames file to ensure check|update will search
---
lib/device/device_id.c | 3 ++-
test/shell/devicesfile-realdevs.sh | 8 ++++----
tools/args.h | 3 ++-
tools/lvmdevices.c | 37 ++++++++++++++++---------------------
4 files changed, 24 insertions(+), 27 deletions(-)
diff --git a/lib/device/device_id.c b/lib/device/device_id.c
index 0621bc858..a33dcebe0 100644
--- a/lib/device/device_id.c
+++ b/lib/device/device_id.c
@@ -2271,7 +2271,8 @@ void device_ids_find_renamed_devs(struct cmd_context *cmd, struct dm_list *dev_l
continue;
}
- log_warn("Devices file PVID %s updating IDNAME to %s.", dev->pvid, devname);
+ if (!noupdate)
+ log_warn("Devices file PVID %s updating IDNAME to %s.", dev->pvid, devname);
free(du->idname);
free(du->devname);
diff --git a/test/shell/devicesfile-realdevs.sh b/test/shell/devicesfile-realdevs.sh
index 8d4aa3e67..23d4bedb4 100644
--- a/test/shell/devicesfile-realdevs.sh
+++ b/test/shell/devicesfile-realdevs.sh
@@ -423,7 +423,7 @@ sed "s/$pvid1/badpvid/" "$DF.orig" |tee $DF
not grep $pvid1 $DF
grep $did1 $DF
-lvmdevices --check 2>&1|tee out
+not lvmdevices --check 2>&1|tee out
grep $dev1 out
grep badpvid out
grep $pvid1 out
@@ -493,7 +493,7 @@ rm $DF
d1=$(basename $dev1)
d3=$(basename $dev3)
sed "s/$d1/$d3/" "$DF.orig" |tee $DF
-lvmdevices --check 2>&1 |tee out
+not lvmdevices --check 2>&1 |tee out
grep $dev1 out
lvmdevices --update
@@ -515,7 +515,7 @@ sed "s/$d1/tmp/" "$DF.orig" |tee ${DF}_1
sed "s/$d2/$d1/" "${DF}_1" |tee ${DF}_2
sed "s/tmp/$d2/" "${DF}_2" |tee $DF
rm ${DF}_1 ${DF}_2
-lvmdevices --check 2>&1 |tee out
+not lvmdevices --check 2>&1 |tee out
grep $dev1 out
grep $dev2 out
@@ -536,7 +536,7 @@ rm $DF
d1=$(basename $dev1)
d3=$(basename $dev3)
sed "s/$d1/$d3/" "$DF.orig" |tee $DF
-lvmdevices --check 2>&1 |tee out
+not lvmdevices --check 2>&1 |tee out
grep $dev1 out
pvs -o+uuid,deviceid | grep $vg |tee out
diff --git a/tools/args.h b/tools/args.h
index 774ce33f4..9a7bf81b2 100644
--- a/tools/args.h
+++ b/tools/args.h
@@ -153,7 +153,8 @@ arg(cachesize_ARG, '\0', "cachesize", sizemb_VAL, 0, 0,
"The size of cache to use.\n")
arg(check_ARG, '\0', "check", 0, 0, 0,
- "Check the content of the devices file.\n")
+ "Checks the content of the devices file.\n"
+ "Reports incorrect device names or PVIDs for entries.\n")
arg(commandprofile_ARG, '\0', "commandprofile", string_VAL, 0, 0,
"The command profile to use for command configuration.\n"
diff --git a/tools/lvmdevices.c b/tools/lvmdevices.c
index 3f104f7de..c50c09f90 100644
--- a/tools/lvmdevices.c
+++ b/tools/lvmdevices.c
@@ -128,7 +128,6 @@ int lvmdevices(struct cmd_context *cmd, int argc, char **argv)
struct device *dev;
struct dev_use *du, *du2;
const char *deviceidtype;
- int changes = 0;
dm_list_init(&search_pvids);
dm_list_init(&found_devs);
@@ -184,8 +183,11 @@ int lvmdevices(struct cmd_context *cmd, int argc, char **argv)
if (arg_is_set(cmd, check_ARG) || arg_is_set(cmd, update_ARG)) {
int search_count = 0;
+ int update_needed = 0;
int invalid = 0;
+ unlink_searched_devnames(cmd);
+
label_scan_setup_bcache();
dm_list_iterate_items(du, &cmd->use_devices) {
@@ -225,6 +227,8 @@ int lvmdevices(struct cmd_context *cmd, int argc, char **argv)
* run just above.
*/
device_ids_validate(cmd, NULL, &invalid, 1);
+ if (invalid)
+ update_needed = 1;
/*
* Find and fix any devname entries that have moved to a
@@ -240,33 +244,24 @@ int lvmdevices(struct cmd_context *cmd, int argc, char **argv)
label_scan_invalidate(du->dev);
}
- /*
- * check du->part
- */
- dm_list_iterate_items(du, &cmd->use_devices) {
- int part = 0;
- if (!du->dev)
- continue;
- dev = du->dev;
-
- dev_get_partition_number(dev, &part);
-
- if (part != du->part) {
- log_warn("Device %s partition %u has incorrect PART in devices file (%u)",
- dev_name(dev), part, du->part);
- du->part = part;
- changes++;
- }
- }
-
if (arg_is_set(cmd, update_ARG)) {
- if (invalid || !dm_list_empty(&found_devs)) {
+ if (update_needed || !dm_list_empty(&found_devs)) {
if (!device_ids_write(cmd))
goto_bad;
log_print("Updated devices file to version %s", devices_file_version());
} else {
log_print("No update for devices file is needed.");
}
+ } else {
+ /*
+ * --check exits with an error if the devices file
+ * needs updates, i.e. running --update would make
+ * changes.
+ */
+ if (update_needed) {
+ log_error("Updates needed for devices file.");
+ goto bad;
+ }
}
goto out;
}
2 years, 3 months
main - lvmdevices check: error exit if update is needed
by David Teigland
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=a972d63c547dc9699c0...
Commit: a972d63c547dc9699c0b3664175eb96b5d89ff8f
Parent: d5a950ca67c106403054ecb847e226e8b5a7c30e
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Thu Jan 13 14:52:54 2022 -0600
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Fri Jan 14 14:59:28 2022 -0600
lvmdevices check: error exit if update is needed
. error exit means that lvmdevices --update would make a change.
. remove check of PART field from --check because it isn't used.
. unlink searched_devnames file to ensure check|update will search
---
lib/device/device_id.c | 3 ++-
test/shell/devicesfile-realdevs.sh | 8 ++++----
tools/args.h | 3 ++-
tools/lvmdevices.c | 37 ++++++++++++++++---------------------
4 files changed, 24 insertions(+), 27 deletions(-)
diff --git a/lib/device/device_id.c b/lib/device/device_id.c
index 6e9107fff..ad9694b8a 100644
--- a/lib/device/device_id.c
+++ b/lib/device/device_id.c
@@ -2278,7 +2278,8 @@ void device_ids_find_renamed_devs(struct cmd_context *cmd, struct dm_list *dev_l
continue;
}
- log_warn("Devices file PVID %s updating IDNAME to %s.", dev->pvid, devname);
+ if (!noupdate)
+ log_warn("Devices file PVID %s updating IDNAME to %s.", dev->pvid, devname);
free(du->idname);
free(du->devname);
diff --git a/test/shell/devicesfile-realdevs.sh b/test/shell/devicesfile-realdevs.sh
index 8d4aa3e67..23d4bedb4 100644
--- a/test/shell/devicesfile-realdevs.sh
+++ b/test/shell/devicesfile-realdevs.sh
@@ -423,7 +423,7 @@ sed "s/$pvid1/badpvid/" "$DF.orig" |tee $DF
not grep $pvid1 $DF
grep $did1 $DF
-lvmdevices --check 2>&1|tee out
+not lvmdevices --check 2>&1|tee out
grep $dev1 out
grep badpvid out
grep $pvid1 out
@@ -493,7 +493,7 @@ rm $DF
d1=$(basename $dev1)
d3=$(basename $dev3)
sed "s/$d1/$d3/" "$DF.orig" |tee $DF
-lvmdevices --check 2>&1 |tee out
+not lvmdevices --check 2>&1 |tee out
grep $dev1 out
lvmdevices --update
@@ -515,7 +515,7 @@ sed "s/$d1/tmp/" "$DF.orig" |tee ${DF}_1
sed "s/$d2/$d1/" "${DF}_1" |tee ${DF}_2
sed "s/tmp/$d2/" "${DF}_2" |tee $DF
rm ${DF}_1 ${DF}_2
-lvmdevices --check 2>&1 |tee out
+not lvmdevices --check 2>&1 |tee out
grep $dev1 out
grep $dev2 out
@@ -536,7 +536,7 @@ rm $DF
d1=$(basename $dev1)
d3=$(basename $dev3)
sed "s/$d1/$d3/" "$DF.orig" |tee $DF
-lvmdevices --check 2>&1 |tee out
+not lvmdevices --check 2>&1 |tee out
grep $dev1 out
pvs -o+uuid,deviceid | grep $vg |tee out
diff --git a/tools/args.h b/tools/args.h
index 2aed8afbb..3f4580b8d 100644
--- a/tools/args.h
+++ b/tools/args.h
@@ -159,7 +159,8 @@ arg(cachesize_ARG, '\0', "cachesize", sizemb_VAL, 0, 0,
"The size of cache to use.\n")
arg(check_ARG, '\0', "check", 0, 0, 0,
- "Check the content of the devices file.\n")
+ "Checks the content of the devices file.\n"
+ "Reports incorrect device names or PVIDs for entries.\n")
arg(commandprofile_ARG, '\0', "commandprofile", string_VAL, 0, 0,
"The command profile to use for command configuration.\n"
diff --git a/tools/lvmdevices.c b/tools/lvmdevices.c
index 3f104f7de..c50c09f90 100644
--- a/tools/lvmdevices.c
+++ b/tools/lvmdevices.c
@@ -128,7 +128,6 @@ int lvmdevices(struct cmd_context *cmd, int argc, char **argv)
struct device *dev;
struct dev_use *du, *du2;
const char *deviceidtype;
- int changes = 0;
dm_list_init(&search_pvids);
dm_list_init(&found_devs);
@@ -184,8 +183,11 @@ int lvmdevices(struct cmd_context *cmd, int argc, char **argv)
if (arg_is_set(cmd, check_ARG) || arg_is_set(cmd, update_ARG)) {
int search_count = 0;
+ int update_needed = 0;
int invalid = 0;
+ unlink_searched_devnames(cmd);
+
label_scan_setup_bcache();
dm_list_iterate_items(du, &cmd->use_devices) {
@@ -225,6 +227,8 @@ int lvmdevices(struct cmd_context *cmd, int argc, char **argv)
* run just above.
*/
device_ids_validate(cmd, NULL, &invalid, 1);
+ if (invalid)
+ update_needed = 1;
/*
* Find and fix any devname entries that have moved to a
@@ -240,33 +244,24 @@ int lvmdevices(struct cmd_context *cmd, int argc, char **argv)
label_scan_invalidate(du->dev);
}
- /*
- * check du->part
- */
- dm_list_iterate_items(du, &cmd->use_devices) {
- int part = 0;
- if (!du->dev)
- continue;
- dev = du->dev;
-
- dev_get_partition_number(dev, &part);
-
- if (part != du->part) {
- log_warn("Device %s partition %u has incorrect PART in devices file (%u)",
- dev_name(dev), part, du->part);
- du->part = part;
- changes++;
- }
- }
-
if (arg_is_set(cmd, update_ARG)) {
- if (invalid || !dm_list_empty(&found_devs)) {
+ if (update_needed || !dm_list_empty(&found_devs)) {
if (!device_ids_write(cmd))
goto_bad;
log_print("Updated devices file to version %s", devices_file_version());
} else {
log_print("No update for devices file is needed.");
}
+ } else {
+ /*
+ * --check exits with an error if the devices file
+ * needs updates, i.e. running --update would make
+ * changes.
+ */
+ if (update_needed) {
+ log_error("Updates needed for devices file.");
+ goto bad;
+ }
}
goto out;
}
2 years, 3 months
stable-2.03.14 - pvcreate: overwrite partition header with -f
by David Teigland
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=a5c37afdca97d6565ea...
Commit: a5c37afdca97d6565ea02bc4bc7d52f360823cd3
Parent: 4b26fb3543049f3d179b620ff937c44e922ada58
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Wed Sep 8 16:30:11 2021 -0500
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Fri Jan 14 14:35:35 2022 -0600
pvcreate: overwrite partition header with -f
$ pvcreate /dev/sdc
Cannot use /dev/sdc: device is partitioned
$ pvcreate -f /dev/sdc
Physical volume "/dev/sdc" successfully created.
---
lib/commands/toolcontext.h | 1 +
lib/filters/filter-partitioned.c | 3 +++
man/pvcreate.8_des | 7 ++++---
test/shell/test-partition.sh | 12 ++++++++++--
tools/toollib.c | 10 ++++++++++
5 files changed, 28 insertions(+), 5 deletions(-)
diff --git a/lib/commands/toolcontext.h b/lib/commands/toolcontext.h
index 356c79f8a..b83883fb8 100644
--- a/lib/commands/toolcontext.h
+++ b/lib/commands/toolcontext.h
@@ -201,6 +201,7 @@ struct cmd_context {
unsigned ignore_device_name_mismatch:1; /* skip updating devices file names */
unsigned backup_disabled:1; /* skip repeated debug message */
unsigned event_activation:1; /* whether event_activation is set */
+ unsigned filter_partitioned_skip:1; /* don't use filter-partitioned */
/*
* Devices and filtering.
diff --git a/lib/filters/filter-partitioned.c b/lib/filters/filter-partitioned.c
index 642553ef2..8f468a567 100644
--- a/lib/filters/filter-partitioned.c
+++ b/lib/filters/filter-partitioned.c
@@ -27,6 +27,9 @@ static int _passes_partitioned_filter(struct cmd_context *cmd, struct dev_filter
if (cmd->filter_nodata_only)
return 1;
+ if (cmd->filter_partitioned_skip)
+ return 1;
+
dev->filtered_flags &= ~DEV_FILTERED_PARTITIONED;
ret = dev_is_partitioned(cmd, dev);
diff --git a/man/pvcreate.8_des b/man/pvcreate.8_des
index 69bd133aa..4048eb71c 100644
--- a/man/pvcreate.8_des
+++ b/man/pvcreate.8_des
@@ -7,9 +7,10 @@ Use \fBvgcreate\fP(8) to create a new VG on the PV, or \fBvgextend\fP(8)
to add the PV to an existing VG. Use \fBpvremove\fP(8) to remove the LVM
disk label from the device.
.P
-The force option will create a PV without confirmation. Repeating the
-force option (\fB-ff\fP) will forcibly create a PV, overriding checks that
-normally prevent it, e.g. if the PV is already in a VG.
+The force option will create a PV without confirmation, and will overwrite
+partition headers. Repeating the force option (\fB-ff\fP) will override other
+checks that would normally prevent a pvcreate, e.g. if the PV is already in a
+VG.
.P
.B Metadata location, size, and alignment
.P
diff --git a/test/shell/test-partition.sh b/test/shell/test-partition.sh
index 0e92f00db..3a45f9089 100644
--- a/test/shell/test-partition.sh
+++ b/test/shell/test-partition.sh
@@ -16,7 +16,6 @@
#
-
SKIP_WITH_LVMPOLLD=1
LVM_TEST_CONFIG_DEVICES="types = [\"device-mapper\", 142]"
@@ -25,7 +24,7 @@ LVM_TEST_CONFIG_DEVICES="types = [\"device-mapper\", 142]"
which sfdisk || skip
-aux prepare_pvs 1 30
+aux prepare_pvs 2 30
pvs "$dev1"
@@ -33,3 +32,12 @@ pvs "$dev1"
echo "1 2" | sfdisk --force "$dev1"
not pvs "$dev1"
+
+wipefs -a "$dev2"
+echo "1 2" | sfdisk --force "$dev2"
+partprobe
+not pvcreate "$dev2"
+pvcreate -f "$dev2"
+pvs "$dev2"
+pvremove "$dev2"
+
diff --git a/tools/toollib.c b/tools/toollib.c
index d6f48aad2..80d3de57c 100644
--- a/tools/toollib.c
+++ b/tools/toollib.c
@@ -5243,6 +5243,10 @@ int pvcreate_each_device(struct cmd_context *cmd,
if (cmd->enable_devices_file && !pp->is_remove)
cmd->filter_deviceid_skip = 1;
+ /* pvcreate -f overwrites partitions */
+ if (pp->force && !pp->is_remove)
+ cmd->filter_partitioned_skip = 1;
+
log_debug("Scanning and filtering device args (%u).", dm_list_size(&scan_devs));
label_scan_devs(cmd, cmd->filter, &scan_devs);
@@ -5257,6 +5261,7 @@ int pvcreate_each_device(struct cmd_context *cmd,
}
}
cmd->filter_deviceid_skip = 0;
+ cmd->filter_partitioned_skip = 0;
/*
* Can the command continue if some specified devices were not found?
@@ -5469,6 +5474,9 @@ do_command:
if (cmd->enable_devices_file && !pp->is_remove)
cmd->filter_deviceid_skip = 1;
+ if (pp->force && !pp->is_remove)
+ cmd->filter_partitioned_skip = 1;
+
log_debug("Rescanning and filtering device args with exclusive open");
if (!label_scan_devs_excl(cmd, cmd->filter, &rescan_devs)) {
log_debug("Failed to rescan devs excl");
@@ -5482,7 +5490,9 @@ do_command:
dm_list_add(&pp->arg_fail, &pd->list);
}
}
+
cmd->filter_deviceid_skip = 0;
+ cmd->filter_partitioned_skip = 0;
if (dm_list_empty(&pp->arg_process) && dm_list_empty(&remove_duplicates)) {
log_debug("No devices to process.");
2 years, 3 months
main - pvcreate: overwrite partition header with -f
by David Teigland
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=d5a950ca67c10640305...
Commit: d5a950ca67c106403054ecb847e226e8b5a7c30e
Parent: 0c80ea88477b3511562036748d3bf837bf7b3e8b
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Wed Sep 8 16:30:11 2021 -0500
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Fri Jan 14 13:57:20 2022 -0600
pvcreate: overwrite partition header with -f
$ pvcreate /dev/sdc
Cannot use /dev/sdc: device is partitioned
$ pvcreate -f /dev/sdc
Physical volume "/dev/sdc" successfully created.
---
lib/commands/toolcontext.h | 1 +
lib/filters/filter-partitioned.c | 3 +++
man/pvcreate.8_des | 7 ++++---
test/shell/test-partition.sh | 12 ++++++++++--
tools/toollib.c | 10 ++++++++++
5 files changed, 28 insertions(+), 5 deletions(-)
diff --git a/lib/commands/toolcontext.h b/lib/commands/toolcontext.h
index f16322d4e..9c24559a6 100644
--- a/lib/commands/toolcontext.h
+++ b/lib/commands/toolcontext.h
@@ -204,6 +204,7 @@ struct cmd_context {
unsigned udevoutput:1;
unsigned online_vg_file_removed:1;
unsigned disable_dm_devs:1; /* temporarily disable use of dm devs cache */
+ unsigned filter_partitioned_skip:1; /* don't use filter-partitioned */
/*
* Devices and filtering.
diff --git a/lib/filters/filter-partitioned.c b/lib/filters/filter-partitioned.c
index 642553ef2..8f468a567 100644
--- a/lib/filters/filter-partitioned.c
+++ b/lib/filters/filter-partitioned.c
@@ -27,6 +27,9 @@ static int _passes_partitioned_filter(struct cmd_context *cmd, struct dev_filter
if (cmd->filter_nodata_only)
return 1;
+ if (cmd->filter_partitioned_skip)
+ return 1;
+
dev->filtered_flags &= ~DEV_FILTERED_PARTITIONED;
ret = dev_is_partitioned(cmd, dev);
diff --git a/man/pvcreate.8_des b/man/pvcreate.8_des
index 69bd133aa..4048eb71c 100644
--- a/man/pvcreate.8_des
+++ b/man/pvcreate.8_des
@@ -7,9 +7,10 @@ Use \fBvgcreate\fP(8) to create a new VG on the PV, or \fBvgextend\fP(8)
to add the PV to an existing VG. Use \fBpvremove\fP(8) to remove the LVM
disk label from the device.
.P
-The force option will create a PV without confirmation. Repeating the
-force option (\fB-ff\fP) will forcibly create a PV, overriding checks that
-normally prevent it, e.g. if the PV is already in a VG.
+The force option will create a PV without confirmation, and will overwrite
+partition headers. Repeating the force option (\fB-ff\fP) will override other
+checks that would normally prevent a pvcreate, e.g. if the PV is already in a
+VG.
.P
.B Metadata location, size, and alignment
.P
diff --git a/test/shell/test-partition.sh b/test/shell/test-partition.sh
index 0e92f00db..3a45f9089 100644
--- a/test/shell/test-partition.sh
+++ b/test/shell/test-partition.sh
@@ -16,7 +16,6 @@
#
-
SKIP_WITH_LVMPOLLD=1
LVM_TEST_CONFIG_DEVICES="types = [\"device-mapper\", 142]"
@@ -25,7 +24,7 @@ LVM_TEST_CONFIG_DEVICES="types = [\"device-mapper\", 142]"
which sfdisk || skip
-aux prepare_pvs 1 30
+aux prepare_pvs 2 30
pvs "$dev1"
@@ -33,3 +32,12 @@ pvs "$dev1"
echo "1 2" | sfdisk --force "$dev1"
not pvs "$dev1"
+
+wipefs -a "$dev2"
+echo "1 2" | sfdisk --force "$dev2"
+partprobe
+not pvcreate "$dev2"
+pvcreate -f "$dev2"
+pvs "$dev2"
+pvremove "$dev2"
+
diff --git a/tools/toollib.c b/tools/toollib.c
index f95c98f51..9b193bd2d 100644
--- a/tools/toollib.c
+++ b/tools/toollib.c
@@ -5248,6 +5248,10 @@ int pvcreate_each_device(struct cmd_context *cmd,
if (cmd->enable_devices_file && !pp->is_remove)
cmd->filter_deviceid_skip = 1;
+ /* pvcreate -f overwrites partitions */
+ if (pp->force && !pp->is_remove)
+ cmd->filter_partitioned_skip = 1;
+
log_debug("Scanning and filtering device args (%u).", dm_list_size(&scan_devs));
label_scan_devs(cmd, cmd->filter, &scan_devs);
@@ -5262,6 +5266,7 @@ int pvcreate_each_device(struct cmd_context *cmd,
}
}
cmd->filter_deviceid_skip = 0;
+ cmd->filter_partitioned_skip = 0;
/*
* Can the command continue if some specified devices were not found?
@@ -5474,6 +5479,9 @@ do_command:
if (cmd->enable_devices_file && !pp->is_remove)
cmd->filter_deviceid_skip = 1;
+ if (pp->force && !pp->is_remove)
+ cmd->filter_partitioned_skip = 1;
+
log_debug("Rescanning and filtering device args with exclusive open");
if (!label_scan_devs_excl(cmd, cmd->filter, &rescan_devs)) {
log_debug("Failed to rescan devs excl");
@@ -5487,7 +5495,9 @@ do_command:
dm_list_add(&pp->arg_fail, &pd->list);
}
}
+
cmd->filter_deviceid_skip = 0;
+ cmd->filter_partitioned_skip = 0;
if (dm_list_empty(&pp->arg_process) && dm_list_empty(&remove_duplicates)) {
log_debug("No devices to process.");
2 years, 3 months
main - remove unused variable
by David Teigland
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=0c80ea88477b3511562...
Commit: 0c80ea88477b3511562036748d3bf837bf7b3e8b
Parent: 18f451e09e943eb3d51f8394f6fe8967e1e9f565
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Thu Jan 13 11:41:09 2022 -0600
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Thu Jan 13 11:41:39 2022 -0600
remove unused variable
resulting from commit cb798ee1c102aadde93965a894c5aa59d4e76e4a
"lvmcache: remove lvmcache_update_vg_from_write"
---
lib/metadata/metadata.c | 3 ---
1 file changed, 3 deletions(-)
diff --git a/lib/metadata/metadata.c b/lib/metadata/metadata.c
index 7e5605820..db0e511ec 100644
--- a/lib/metadata/metadata.c
+++ b/lib/metadata/metadata.c
@@ -3100,7 +3100,6 @@ static int _vg_commit_mdas(struct volume_group *vg)
{
struct metadata_area *mda, *tmda;
DM_LIST_INIT(ignored);
- int failed = 0;
int good = 0;
/* Rearrange the metadata_areas_in_use so ignored mdas come first. */
@@ -3115,11 +3114,9 @@ static int _vg_commit_mdas(struct volume_group *vg)
dm_list_iterate_items(mda, &vg->fid->metadata_areas_in_use) {
if (mda->status & MDA_FAILED)
continue;
- failed = 0;
if (mda->ops->vg_commit &&
!mda->ops->vg_commit(vg->fid, vg, mda)) {
stack;
- failed = 1;
} else
good++;
}
2 years, 3 months
main - handle duplicate vgids
by David Teigland
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=18f451e09e943eb3d51...
Commit: 18f451e09e943eb3d51f8394f6fe8967e1e9f565
Parent: cb798ee1c102aadde93965a894c5aa59d4e76e4a
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Thu Jan 6 10:15:16 2022 -0600
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Thu Jan 13 10:01:24 2022 -0600
handle duplicate vgids
The approach to duplicate VGIDs has been that it is not possible
or not allowed, so the behavior has been undefined. The actual
result was unpredictable and/or broken, and generally unhelpful.
Improve this by recognizing the problem, displaying the VGs,
and printing a warning to fix the problem. Beyond this,
using VGs with duplicate VGIDs remains undefined, but should
work well enough to correct the problem with vgchange -u.
It's possible to create this condition without too much difficulty
by cloning PVs, followed by an incomplete attempt at making the two
VGs unique (vgrename and pvchange -u, but missing vgchange -u.)
---
lib/cache/lvmcache.c | 20 +++++++++++++----
test/shell/duplicate-vgid.sh | 52 ++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 68 insertions(+), 4 deletions(-)
diff --git a/lib/cache/lvmcache.c b/lib/cache/lvmcache.c
index 6569f983d..22edcfd84 100644
--- a/lib/cache/lvmcache.c
+++ b/lib/cache/lvmcache.c
@@ -354,9 +354,11 @@ static struct lvmcache_vginfo *_vginfo_lookup(const char *vgname, const char *vg
if (vgid_arg) {
if ((vginfo = dm_hash_lookup(_vgid_hash, vgid))) {
if (vgname && strcmp(vginfo->vgname, vgname)) {
- /* should never happen */
- log_error(INTERNAL_ERROR "vginfo_lookup vgid %s has two names %s %s",
- vgid, vginfo->vgname, vgname);
+ log_warn("WARNING: lookup found duplicate VGID %s for VGs %s and %s.", vgid, vginfo->vgname, vgname);
+ if ((vginfo = dm_hash_lookup(_vgname_hash, vgname))) {
+ if (!memcmp(vginfo->vgid, vgid, ID_LEN))
+ return vginfo;
+ }
return NULL;
}
return vginfo;
@@ -1884,7 +1886,17 @@ static int _lvmcache_update_vgname(struct cmd_context *cmd,
_drop_vginfo(info, info->vginfo);
- if (!(vginfo = lvmcache_vginfo_from_vgid(vgid))) {
+ vginfo = lvmcache_vginfo_from_vgid(vgid);
+ if (vginfo && strcmp(vginfo->vgname, vgname)) {
+ log_warn("WARNING: fix duplicate VGID %s for VGs %s and %s (see vgchange -u).", vgid_dashed, vgname, vginfo->vgname);
+ vginfo = lvmcache_vginfo_from_vgname(vgname, NULL);
+ if (vginfo && memcmp(vginfo->vgid, vgid, ID_LEN)) {
+ log_error("Ignoring %s with conflicting VG info %s %s.", dev_name(info->dev), vgid_dashed, vgname);
+ return_0;
+ }
+ }
+
+ if (!vginfo) {
/*
* Create a vginfo struct for this VG and put the vginfo
* into the hash table.
diff --git a/test/shell/duplicate-vgid.sh b/test/shell/duplicate-vgid.sh
new file mode 100644
index 000000000..12163c2f0
--- /dev/null
+++ b/test/shell/duplicate-vgid.sh
@@ -0,0 +1,52 @@
+#!/usr/bin/env bash
+
+# Copyright (C) 2008-2013 Red Hat, Inc. All rights reserved.
+#
+# This copyrighted material is made available to anyone wishing to use,
+# modify, copy, or redistribute it subject to the terms and conditions
+# of the GNU General Public License v.2.
+
+SKIP_WITH_LVMLOCKD=1
+SKIP_WITH_LVMPOLLD=1
+
+. lib/inittest
+
+aux prepare_devs 2
+
+vgcreate $vg1 "$dev1"
+vgchange --setautoactivation n $vg1
+UUID1=$(vgs --noheading -o vg_uuid $vg1 | xargs)
+lvcreate -l1 -an -n $lv1 $vg1
+dd if="$dev1" of="$dev2" bs=1M count=1
+aux disable_dev "$dev1"
+vgrename $vg1 $vg2
+pvchange -u "$dev2"
+aux enable_dev "$dev1"
+
+vgs -o+uuid |tee out
+grep $vg1 out | tee out1
+grep $UUID1 out1
+grep $vg2 out | tee out2
+grep $UUID1 out2
+
+vgs $vg1
+vgs $vg2
+lvs $vg1/$lv1
+lvs $vg2/$lv1
+
+lvremove $vg1/$lv1
+lvremove $vg2/$lv1
+
+lvcreate -l1 -an -n $lv2 $vg1
+lvcreate -l1 -an -n $lv3 $vg2
+
+vgchange -u $vg2
+
+vgs -o uuid $vg1 |tee out
+grep $UUID1 out
+
+vgs -o uuid $vg2 |tee out
+not grep $UUID1 out
+
+vgremove -ff $vg1
+vgremove -ff $vg2
2 years, 3 months
main - lvmcache: remove lvmcache_update_vg_from_write
by David Teigland
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=cb798ee1c102aadde93...
Commit: cb798ee1c102aadde93965a894c5aa59d4e76e4a
Parent: 5e428d22d9647a294eba65852078947df5ade48f
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Wed Jan 12 16:46:26 2022 -0600
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Thu Jan 13 10:01:16 2022 -0600
lvmcache: remove lvmcache_update_vg_from_write
After a vg_write, this function was used to attempt to
make lvmcache data match the new state written to disk.
It was not updated correctly in a many or most cases,
and the resulting lvmcache is not actually used after
vg_write, making the update unnecessary.
---
lib/cache/lvmcache.c | 44 --------------------------------------------
lib/cache/lvmcache.h | 1 -
lib/metadata/metadata.c | 7 -------
3 files changed, 52 deletions(-)
diff --git a/lib/cache/lvmcache.c b/lib/cache/lvmcache.c
index c5359f3c5..6569f983d 100644
--- a/lib/cache/lvmcache.c
+++ b/lib/cache/lvmcache.c
@@ -2239,50 +2239,6 @@ int lvmcache_update_vgname_and_id(struct cmd_context *cmd, struct lvmcache_info
return 1;
}
-/*
- * FIXME: quit trying to mirror changes that a command is making into lvmcache.
- *
- * First, it's complicated and hard to ensure it's done correctly in every case
- * (it would be much easier and safer to just toss out what's in lvmcache and
- * reread the info to recreate it from scratch instead of trying to make sure
- * every possible discrete state change is correct.)
- *
- * Second, it's unnecessary if commands just use the vg they are modifying
- * rather than also trying to get info from lvmcache. The lvmcache state
- * should be populated by label_scan, used to perform vg_read's, and then
- * ignored (or dropped so it can't be used).
- *
- * lvmcache info is already used very little after a command begins its
- * operation. The code that's supposed to keep the lvmcache in sync with
- * changes being made to disk could be half wrong and we wouldn't know it.
- * That creates a landmine for someone who might try to use a bit of it that
- * isn't being updated correctly.
- */
-
-int lvmcache_update_vg_from_write(struct volume_group *vg)
-{
- char vgid[ID_LEN + 1] __attribute__((aligned(8))) = { 0 };
- struct pv_list *pvl;
- struct lvmcache_info *info;
- struct lvmcache_vgsummary vgsummary = {
- .vgname = vg->name,
- .vgstatus = vg->status,
- .system_id = vg->system_id,
- .lock_type = vg->lock_type
- };
-
- memcpy(vgid, &vg->id, ID_LEN);
- memcpy(vgsummary.vgid, vgid, ID_LEN);
-
- dm_list_iterate_items(pvl, &vg->pvs) {
- if ((info = lvmcache_info_from_pv_id(&pvl->pv->id, pvl->pv->dev, 0)) &&
- !lvmcache_update_vgname_and_id(vg->cmd, info, &vgsummary))
- return_0;
- }
-
- return 1;
-}
-
/*
* The lvmcache representation of a VG after label_scan can be incorrect
* because the label_scan does not use the full VG metadata to construct
diff --git a/lib/cache/lvmcache.h b/lib/cache/lvmcache.h
index 4c4903136..934246274 100644
--- a/lib/cache/lvmcache.h
+++ b/lib/cache/lvmcache.h
@@ -84,7 +84,6 @@ void lvmcache_del_dev(struct device *dev);
int lvmcache_update_vgname_and_id(struct cmd_context *cmd, struct lvmcache_info *info,
struct lvmcache_vgsummary *vgsummary);
int lvmcache_update_vg_from_read(struct volume_group *vg, unsigned precommitted);
-int lvmcache_update_vg_from_write(struct volume_group *vg);
void lvmcache_lock_vgname(const char *vgname, int read_only);
void lvmcache_unlock_vgname(const char *vgname);
diff --git a/lib/metadata/metadata.c b/lib/metadata/metadata.c
index f01a0bea6..7e5605820 100644
--- a/lib/metadata/metadata.c
+++ b/lib/metadata/metadata.c
@@ -3102,7 +3102,6 @@ static int _vg_commit_mdas(struct volume_group *vg)
DM_LIST_INIT(ignored);
int failed = 0;
int good = 0;
- int cache_updated = 0;
/* Rearrange the metadata_areas_in_use so ignored mdas come first. */
dm_list_iterate_items_safe(mda, tmda, &vg->fid->metadata_areas_in_use)
@@ -3123,12 +3122,6 @@ static int _vg_commit_mdas(struct volume_group *vg)
failed = 1;
} else
good++;
-
- /* Update cache first time we succeed */
- if (!failed && !cache_updated) {
- lvmcache_update_vg_from_write(vg);
- cache_updated = 1;
- }
}
if (good)
return 1;
2 years, 3 months
main - vgsplit: don't reread vg_to
by David Teigland
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=5e428d22d9647a294eb...
Commit: 5e428d22d9647a294eba65852078947df5ade48f
Parent: 7502f78678db7c7701e543a0a7267e050850ba53
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Wed Jan 12 16:42:01 2022 -0600
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Wed Jan 12 16:42:01 2022 -0600
vgsplit: don't reread vg_to
The destination vg is first written with the EXPORTED flag,
then the source vg is written, then the destination vg is
written again without the EXPORTED flag. Remove an unnecessary
vg_read of the destination vg just before the second write.
---
tools/vgsplit.c | 24 ------------------------
1 file changed, 24 deletions(-)
diff --git a/tools/vgsplit.c b/tools/vgsplit.c
index a085ac2ba..5f113b363 100644
--- a/tools/vgsplit.c
+++ b/tools/vgsplit.c
@@ -727,30 +727,6 @@ int vgsplit(struct cmd_context *cmd, int argc, char **argv)
backup(vg_from);
}
- /*
- * Finally, remove the EXPORTED flag from the new VG and write it out.
- * We need to unlock vg_to because vg_read_for_update wants to lock it.
- */
- if (!test_mode()) {
- unlock_vg(cmd, NULL, vg_name_to);
- release_vg(vg_to);
-
- /*
- * This command uses the exported vg flag internally, but
- * exported VGs are not allowed to be split from the command
- * level, so ALLOW_EXPORTED is not set in commands.h.
- */
- cmd->include_exported_vgs = 1;
-
- vg_to = vg_read_for_update(cmd, vg_name_to, NULL, 0, 0);
-
- if (!vg_to) {
- log_error("Volume group \"%s\" became inconsistent: "
- "please fix manually", vg_name_to);
- goto bad;
- }
- }
-
vg_to->status &= ~EXPORTED_VG;
if (!vg_write(vg_to) || !vg_commit(vg_to))
2 years, 3 months
main - Revert "handle duplicate vgids"
by David Teigland
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=7502f78678db7c7701e...
Commit: 7502f78678db7c7701e543a0a7267e050850ba53
Parent: bd2baeaaa67da3885df9f06700565dc201c82861
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Tue Jan 11 16:03:07 2022 -0600
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Tue Jan 11 16:04:51 2022 -0600
Revert "handle duplicate vgids"
This reverts commit bd2baeaaa67da3885df9f06700565dc201c82861.
This commit broke vgrename because vgrename relies on old bugs
in lvmcache_update_vg_from_write and lvmcache_update_vgname
which need to be fixed first.
---
lib/cache/lvmcache.c | 20 ++++-------------
test/shell/duplicate-vgid.sh | 52 --------------------------------------------
2 files changed, 4 insertions(+), 68 deletions(-)
diff --git a/lib/cache/lvmcache.c b/lib/cache/lvmcache.c
index 9c1619b7e..c5359f3c5 100644
--- a/lib/cache/lvmcache.c
+++ b/lib/cache/lvmcache.c
@@ -354,11 +354,9 @@ static struct lvmcache_vginfo *_vginfo_lookup(const char *vgname, const char *vg
if (vgid_arg) {
if ((vginfo = dm_hash_lookup(_vgid_hash, vgid))) {
if (vgname && strcmp(vginfo->vgname, vgname)) {
- log_warn("WARNING: lookup found duplicate VGID %s for VGs %s and %s.", vgid, vginfo->vgname, vgname);
- if ((vginfo = dm_hash_lookup(_vgname_hash, vgname))) {
- if (!memcmp(vginfo->vgid, vgid, ID_LEN))
- return vginfo;
- }
+ /* should never happen */
+ log_error(INTERNAL_ERROR "vginfo_lookup vgid %s has two names %s %s",
+ vgid, vginfo->vgname, vgname);
return NULL;
}
return vginfo;
@@ -1886,17 +1884,7 @@ static int _lvmcache_update_vgname(struct cmd_context *cmd,
_drop_vginfo(info, info->vginfo);
- vginfo = lvmcache_vginfo_from_vgid(vgid);
- if (vginfo && strcmp(vginfo->vgname, vgname)) {
- log_warn("WARNING: fix duplicate VGID %s for VGs %s and %s (see vgchange -u).", vgid_dashed, vgname, vginfo->vgname);
- vginfo = lvmcache_vginfo_from_vgname(vgname, NULL);
- if (vginfo && memcmp(vginfo->vgid, vgid, ID_LEN)) {
- log_error("Ignoring %s with conflicting VG info %s %s.", dev_name(info->dev), vgid_dashed, vgname);
- return_0;
- }
- }
-
- if (!vginfo) {
+ if (!(vginfo = lvmcache_vginfo_from_vgid(vgid))) {
/*
* Create a vginfo struct for this VG and put the vginfo
* into the hash table.
diff --git a/test/shell/duplicate-vgid.sh b/test/shell/duplicate-vgid.sh
deleted file mode 100644
index 12163c2f0..000000000
--- a/test/shell/duplicate-vgid.sh
+++ /dev/null
@@ -1,52 +0,0 @@
-#!/usr/bin/env bash
-
-# Copyright (C) 2008-2013 Red Hat, Inc. All rights reserved.
-#
-# This copyrighted material is made available to anyone wishing to use,
-# modify, copy, or redistribute it subject to the terms and conditions
-# of the GNU General Public License v.2.
-
-SKIP_WITH_LVMLOCKD=1
-SKIP_WITH_LVMPOLLD=1
-
-. lib/inittest
-
-aux prepare_devs 2
-
-vgcreate $vg1 "$dev1"
-vgchange --setautoactivation n $vg1
-UUID1=$(vgs --noheading -o vg_uuid $vg1 | xargs)
-lvcreate -l1 -an -n $lv1 $vg1
-dd if="$dev1" of="$dev2" bs=1M count=1
-aux disable_dev "$dev1"
-vgrename $vg1 $vg2
-pvchange -u "$dev2"
-aux enable_dev "$dev1"
-
-vgs -o+uuid |tee out
-grep $vg1 out | tee out1
-grep $UUID1 out1
-grep $vg2 out | tee out2
-grep $UUID1 out2
-
-vgs $vg1
-vgs $vg2
-lvs $vg1/$lv1
-lvs $vg2/$lv1
-
-lvremove $vg1/$lv1
-lvremove $vg2/$lv1
-
-lvcreate -l1 -an -n $lv2 $vg1
-lvcreate -l1 -an -n $lv3 $vg2
-
-vgchange -u $vg2
-
-vgs -o uuid $vg1 |tee out
-grep $UUID1 out
-
-vgs -o uuid $vg2 |tee out
-not grep $UUID1 out
-
-vgremove -ff $vg1
-vgremove -ff $vg2
2 years, 3 months
main - handle duplicate vgids
by David Teigland
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=bd2baeaaa67da3885df...
Commit: bd2baeaaa67da3885df9f06700565dc201c82861
Parent: 42a16aa6f34d801bfea169b4f6d1fef5d89961f6
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Thu Jan 6 10:15:16 2022 -0600
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Thu Jan 6 10:15:16 2022 -0600
handle duplicate vgids
The approach to duplicate VGIDs has been that it is not possible
or not allowed, so the behavior has been undefined. The actual
result was unpredictable and/or broken, and generally unhelpful.
Improve this by recognizing the problem, displaying the VGs,
and printing a warning to fix the problem. Beyond this,
using VGs with duplicate VGIDs remains undefined, but should
work well enough to correct the problem with vgchange -u.
It's possible to create this condition without too much difficulty
by cloning PVs, followed by an incomplete attempt at making the two
VGs unique (vgrename and pvchange -u, but missing vgchange -u.)
---
lib/cache/lvmcache.c | 20 +++++++++++++----
test/shell/duplicate-vgid.sh | 52 ++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 68 insertions(+), 4 deletions(-)
diff --git a/lib/cache/lvmcache.c b/lib/cache/lvmcache.c
index c5359f3c5..9c1619b7e 100644
--- a/lib/cache/lvmcache.c
+++ b/lib/cache/lvmcache.c
@@ -354,9 +354,11 @@ static struct lvmcache_vginfo *_vginfo_lookup(const char *vgname, const char *vg
if (vgid_arg) {
if ((vginfo = dm_hash_lookup(_vgid_hash, vgid))) {
if (vgname && strcmp(vginfo->vgname, vgname)) {
- /* should never happen */
- log_error(INTERNAL_ERROR "vginfo_lookup vgid %s has two names %s %s",
- vgid, vginfo->vgname, vgname);
+ log_warn("WARNING: lookup found duplicate VGID %s for VGs %s and %s.", vgid, vginfo->vgname, vgname);
+ if ((vginfo = dm_hash_lookup(_vgname_hash, vgname))) {
+ if (!memcmp(vginfo->vgid, vgid, ID_LEN))
+ return vginfo;
+ }
return NULL;
}
return vginfo;
@@ -1884,7 +1886,17 @@ static int _lvmcache_update_vgname(struct cmd_context *cmd,
_drop_vginfo(info, info->vginfo);
- if (!(vginfo = lvmcache_vginfo_from_vgid(vgid))) {
+ vginfo = lvmcache_vginfo_from_vgid(vgid);
+ if (vginfo && strcmp(vginfo->vgname, vgname)) {
+ log_warn("WARNING: fix duplicate VGID %s for VGs %s and %s (see vgchange -u).", vgid_dashed, vgname, vginfo->vgname);
+ vginfo = lvmcache_vginfo_from_vgname(vgname, NULL);
+ if (vginfo && memcmp(vginfo->vgid, vgid, ID_LEN)) {
+ log_error("Ignoring %s with conflicting VG info %s %s.", dev_name(info->dev), vgid_dashed, vgname);
+ return_0;
+ }
+ }
+
+ if (!vginfo) {
/*
* Create a vginfo struct for this VG and put the vginfo
* into the hash table.
diff --git a/test/shell/duplicate-vgid.sh b/test/shell/duplicate-vgid.sh
new file mode 100644
index 000000000..12163c2f0
--- /dev/null
+++ b/test/shell/duplicate-vgid.sh
@@ -0,0 +1,52 @@
+#!/usr/bin/env bash
+
+# Copyright (C) 2008-2013 Red Hat, Inc. All rights reserved.
+#
+# This copyrighted material is made available to anyone wishing to use,
+# modify, copy, or redistribute it subject to the terms and conditions
+# of the GNU General Public License v.2.
+
+SKIP_WITH_LVMLOCKD=1
+SKIP_WITH_LVMPOLLD=1
+
+. lib/inittest
+
+aux prepare_devs 2
+
+vgcreate $vg1 "$dev1"
+vgchange --setautoactivation n $vg1
+UUID1=$(vgs --noheading -o vg_uuid $vg1 | xargs)
+lvcreate -l1 -an -n $lv1 $vg1
+dd if="$dev1" of="$dev2" bs=1M count=1
+aux disable_dev "$dev1"
+vgrename $vg1 $vg2
+pvchange -u "$dev2"
+aux enable_dev "$dev1"
+
+vgs -o+uuid |tee out
+grep $vg1 out | tee out1
+grep $UUID1 out1
+grep $vg2 out | tee out2
+grep $UUID1 out2
+
+vgs $vg1
+vgs $vg2
+lvs $vg1/$lv1
+lvs $vg2/$lv1
+
+lvremove $vg1/$lv1
+lvremove $vg2/$lv1
+
+lvcreate -l1 -an -n $lv2 $vg1
+lvcreate -l1 -an -n $lv3 $vg2
+
+vgchange -u $vg2
+
+vgs -o uuid $vg1 |tee out
+grep $UUID1 out
+
+vgs -o uuid $vg2 |tee out
+not grep $UUID1 out
+
+vgremove -ff $vg1
+vgremove -ff $vg2
2 years, 3 months