From c65d37976995bf73f5e79d2540b1cf9a4bef0ef5 Mon Sep 17 00:00:00 2001 From: Peter Rajnoha Date: Wed, 28 Aug 2024 10:35:18 +0200 Subject: [PATCH] toollib: do not accept duplicate device name on pvcreate input --- WHATS_NEW | 1 + test/shell/pvcreate-operation.sh | 4 ++++ tools/toollib.c | 5 +++++ 3 files changed, 10 insertions(+) diff --git a/WHATS_NEW b/WHATS_NEW index 79b8a42f7..ddab5e0d7 100644 --- a/WHATS_NEW +++ b/WHATS_NEW @@ -1,5 +1,6 @@ Version 2.03.27 - ================== + Do not accept duplicate device names for pvcreate. Version 2.03.26 - 23rd August 2024 ================================== diff --git a/test/shell/pvcreate-operation.sh b/test/shell/pvcreate-operation.sh index 5cf4fd675..df46cfc13 100644 --- a/test/shell/pvcreate-operation.sh +++ b/test/shell/pvcreate-operation.sh @@ -25,6 +25,10 @@ else mdatypes='2' fi +# pvcreate fails when the same device appears twice on input +not pvcreate "$dev1" "$dev1" 2>err +grep "Duplicate device name found on input" err + for mdatype in $mdatypes do # pvcreate (lvm$mdatype) refuses to overwrite an mounted filesystem (bz168330) diff --git a/tools/toollib.c b/tools/toollib.c index 5031b2cc2..e34f1e21d 100644 --- a/tools/toollib.c +++ b/tools/toollib.c @@ -5614,6 +5614,11 @@ int pvcreate_each_device(struct cmd_context *cmd, pv_name = pp->pv_names[i]; + if (_pvcreate_list_find_name(&pp->arg_devices, pv_name)) { + log_error("Duplicate device name found on input: %s.", pv_name); + return 0; + } + if (!(pd = dm_pool_zalloc(cmd->mem, sizeof(*pd)))) { log_error("alloc failed."); return 0;