From d3d5ec74690fea98cdb0b761870f4baafecf46e8 Mon Sep 17 00:00:00 2001 From: David Teigland Date: Wed, 8 Sep 2021 16:30:11 -0500 Subject: [PATCH] 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 +++ tools/toollib.c | 10 ++++++++++ 3 files changed, 14 insertions(+) diff --git a/lib/commands/toolcontext.h b/lib/commands/toolcontext.h index 8f11a7714..bab84f1d4 100644 --- a/lib/commands/toolcontext.h +++ b/lib/commands/toolcontext.h @@ -197,6 +197,7 @@ struct cmd_context { unsigned check_devs_used:1; /* check devs used by LVs */ unsigned print_device_id_not_found:1; /* print devices file entries not found */ unsigned ignore_device_name_mismatch:1; /* skip updating devices file names */ + unsigned filter_partitioned_skip; /* 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/tools/toollib.c b/tools/toollib.c index 9d488c5a7..5f5420825 100644 --- a/tools/toollib.c +++ b/tools/toollib.c @@ -5336,6 +5336,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); @@ -5350,6 +5354,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? @@ -5562,6 +5567,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"); @@ -5575,7 +5583,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.");