summaryrefslogtreecommitdiff
path: root/tools/vgimportdevices.c
diff options
context:
space:
mode:
authorDavid Teigland <teigland@redhat.com>2022-08-30 14:40:48 -0500
committerDavid Teigland <teigland@redhat.com>2022-08-30 14:52:00 -0500
commit0eebd9d7802c724ee71b6ebb80940ea6007f9c7a (patch)
tree13e5da72d7626b5b6366ea43b7fa418fc72703e6 /tools/vgimportdevices.c
parent3c49a2e43ccfbad720a3134484c7870a14b1135b (diff)
downloadlvm2-0eebd9d7802c724ee71b6ebb80940ea6007f9c7a.tar.gz
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.)
Diffstat (limited to 'tools/vgimportdevices.c')
-rw-r--r--tools/vgimportdevices.c10
1 files changed, 8 insertions, 2 deletions
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.");