All of lore.kernel.org
 help / color / mirror / Atom feed
* rhel-8.8.0 - vgimportdevices: fix locking when creating devices file
@ 2022-11-08 14:51 David Teigland
  0 siblings, 0 replies; 2+ messages in thread
From: David Teigland @ 2022-11-08 14:51 UTC (permalink / raw)
  To: lvm-devel

Gitweb:        https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=19093e37557ae6a94392dcf207b3566a7d3defea
Commit:        19093e37557ae6a94392dcf207b3566a7d3defea
Parent:        e5f5e2988377c0f014b30a60709685c19c6d3bf0
Author:        David Teigland <teigland@redhat.com>
AuthorDate:    Tue Aug 30 14:40:48 2022 -0500
Committer:     David Teigland <teigland@redhat.com>
CommitterDate: Wed Nov 2 13:24:18 2022 -0500

vgimportdevices: fix locking when creating devices file

Take the devices file lock before creating a new devices file.
(Was missed by the change to preemptively create the devices
file prior to setup_devices(), which was done to improve the
error path.)
---
 lib/device/dev-cache.c  |  7 +++----
 lib/device/device_id.c  |  1 +
 tools/vgimportdevices.c | 10 ++++++++--
 3 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/lib/device/dev-cache.c b/lib/device/dev-cache.c
index 65e1cb138..0c9aaf785 100644
--- a/lib/device/dev-cache.c
+++ b/lib/device/dev-cache.c
@@ -1956,10 +1956,9 @@ static int _setup_devices(struct cmd_context *cmd, int no_file_match)
 
 	if (!file_exists) {
 		/*
-		 * pvcreate/vgcreate/vgimportdevices/lvmdevices-add create
-		 * a new devices file here if it doesn't exist.
-		 * They have the create_edit_devices_file flag set.
-		 * First they create/lock-ex the devices file lockfile.
+		 * pvcreate/vgcreate create a new devices file here if it
+		 * doesn't exist.  They have create_edit_devices_file=1.
+		 * First create/lock-ex the devices file lockfile.
 		 * Other commands will not use a devices file if none exists.
 		 */
 		lock_mode = LOCK_EX;
diff --git a/lib/device/device_id.c b/lib/device/device_id.c
index c3816a66c..780e08404 100644
--- a/lib/device/device_id.c
+++ b/lib/device/device_id.c
@@ -2429,6 +2429,7 @@ static int _lock_devices_file(struct cmd_context *cmd, int mode, int nonblock, i
 
 	if (_devices_file_locked == mode) {
 		/* can happen when a command holds an ex lock and does an update in device_ids_validate */
+		/* can happen when vgimportdevices calls this directly, followed later by setup_devices */
 		if (held)
 			*held = 1;
 		return 1;
diff --git a/tools/vgimportdevices.c b/tools/vgimportdevices.c
index 9ade1b9e4..23c2718ff 100644
--- a/tools/vgimportdevices.c
+++ b/tools/vgimportdevices.c
@@ -132,8 +132,10 @@ int vgimportdevices(struct cmd_context *cmd, int argc, char **argv)
 		return ECMD_FAILED;
 
 	/*
-	 * Prepare devices file preemptively because the error path for this
-	 * case from process_each is not as clean.
+	 * Prepare/create devices file preemptively because the error path for
+	 * this case from process_each/setup_devices is not as clean.
+	 * This means that when setup_devices is called, it the devices
+	 * file steps will be redundant, and need to handle being repeated.
 	 */
 	if (!setup_devices_file(cmd)) {
 		log_error("Failed to set up devices file.");
@@ -143,6 +145,10 @@ int vgimportdevices(struct cmd_context *cmd, int argc, char **argv)
 		log_error("Devices file not enabled.");
 		return ECMD_FAILED;
 	}
+	if (!lock_devices_file(cmd, LOCK_EX)) {
+		log_error("Failed to lock the devices file.");
+		return ECMD_FAILED;
+	}
 	if (!devices_file_exists(cmd)) {
 	       	if (!devices_file_touch(cmd)) {
 			log_error("Failed to create devices file.");


^ permalink raw reply related	[flat|nested] 2+ messages in thread
* rhel-8.8.0 - vgimportdevices: fix locking when creating devices file
@ 2022-12-08 11:37 Marian Csontos
  0 siblings, 0 replies; 2+ messages in thread
From: Marian Csontos @ 2022-12-08 11:37 UTC (permalink / raw)
  To: lvm-devel

Gitweb:        https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=0b9d9963b8f15a6f12a0149a62809fa9b846c5c5
Commit:        0b9d9963b8f15a6f12a0149a62809fa9b846c5c5
Parent:        f1d8c01dff3f8839355004e5fd77e9cd521e26cb
Author:        David Teigland <teigland@redhat.com>
AuthorDate:    Tue Aug 30 14:40:48 2022 -0500
Committer:     Marian Csontos <mcsontos@redhat.com>
CommitterDate: Mon Nov 28 17:11:21 2022 +0100

vgimportdevices: fix locking when creating devices file

Take the devices file lock before creating a new devices file.
(Was missed by the change to preemptively create the devices
file prior to setup_devices(), which was done to improve the
error path.)
---
 lib/device/dev-cache.c  |  7 +++----
 lib/device/device_id.c  |  1 +
 tools/vgimportdevices.c | 10 ++++++++--
 3 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/lib/device/dev-cache.c b/lib/device/dev-cache.c
index 65e1cb138..0c9aaf785 100644
--- a/lib/device/dev-cache.c
+++ b/lib/device/dev-cache.c
@@ -1956,10 +1956,9 @@ static int _setup_devices(struct cmd_context *cmd, int no_file_match)
 
 	if (!file_exists) {
 		/*
-		 * pvcreate/vgcreate/vgimportdevices/lvmdevices-add create
-		 * a new devices file here if it doesn't exist.
-		 * They have the create_edit_devices_file flag set.
-		 * First they create/lock-ex the devices file lockfile.
+		 * pvcreate/vgcreate create a new devices file here if it
+		 * doesn't exist.  They have create_edit_devices_file=1.
+		 * First create/lock-ex the devices file lockfile.
 		 * Other commands will not use a devices file if none exists.
 		 */
 		lock_mode = LOCK_EX;
diff --git a/lib/device/device_id.c b/lib/device/device_id.c
index c3816a66c..780e08404 100644
--- a/lib/device/device_id.c
+++ b/lib/device/device_id.c
@@ -2429,6 +2429,7 @@ static int _lock_devices_file(struct cmd_context *cmd, int mode, int nonblock, i
 
 	if (_devices_file_locked == mode) {
 		/* can happen when a command holds an ex lock and does an update in device_ids_validate */
+		/* can happen when vgimportdevices calls this directly, followed later by setup_devices */
 		if (held)
 			*held = 1;
 		return 1;
diff --git a/tools/vgimportdevices.c b/tools/vgimportdevices.c
index 9ade1b9e4..23c2718ff 100644
--- a/tools/vgimportdevices.c
+++ b/tools/vgimportdevices.c
@@ -132,8 +132,10 @@ int vgimportdevices(struct cmd_context *cmd, int argc, char **argv)
 		return ECMD_FAILED;
 
 	/*
-	 * Prepare devices file preemptively because the error path for this
-	 * case from process_each is not as clean.
+	 * Prepare/create devices file preemptively because the error path for
+	 * this case from process_each/setup_devices is not as clean.
+	 * This means that when setup_devices is called, it the devices
+	 * file steps will be redundant, and need to handle being repeated.
 	 */
 	if (!setup_devices_file(cmd)) {
 		log_error("Failed to set up devices file.");
@@ -143,6 +145,10 @@ int vgimportdevices(struct cmd_context *cmd, int argc, char **argv)
 		log_error("Devices file not enabled.");
 		return ECMD_FAILED;
 	}
+	if (!lock_devices_file(cmd, LOCK_EX)) {
+		log_error("Failed to lock the devices file.");
+		return ECMD_FAILED;
+	}
 	if (!devices_file_exists(cmd)) {
 	       	if (!devices_file_touch(cmd)) {
 			log_error("Failed to create devices file.");


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-12-08 11:37 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-11-08 14:51 rhel-8.8.0 - vgimportdevices: fix locking when creating devices file David Teigland
  -- strict thread matches above, loose matches on Subject: below --
2022-12-08 11:37 Marian Csontos

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.