1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-21 13:34:40 +03:00

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.)
This commit is contained in:
David Teigland 2022-08-30 14:40:48 -05:00
parent 3c49a2e43c
commit 0eebd9d780
3 changed files with 12 additions and 6 deletions

View File

@ -1937,10 +1937,9 @@ int setup_devices(struct cmd_context *cmd)
if (!file_exists) { if (!file_exists) {
/* /*
* pvcreate/vgcreate/vgimportdevices/lvmdevices-add create * pvcreate/vgcreate create a new devices file here if it
* a new devices file here if it doesn't exist. * doesn't exist. They have create_edit_devices_file=1.
* They have the create_edit_devices_file flag set. * First create/lock-ex the devices file lockfile.
* First they create/lock-ex the devices file lockfile.
* Other commands will not use a devices file if none exists. * Other commands will not use a devices file if none exists.
*/ */
lock_mode = LOCK_EX; lock_mode = LOCK_EX;

View File

@ -2468,6 +2468,7 @@ static int _lock_devices_file(struct cmd_context *cmd, int mode, int nonblock, i
if (_devices_file_locked == mode) { 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 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) if (held)
*held = 1; *held = 1;
return 1; return 1;

View File

@ -132,8 +132,10 @@ int vgimportdevices(struct cmd_context *cmd, int argc, char **argv)
return ECMD_FAILED; return ECMD_FAILED;
/* /*
* Prepare devices file preemptively because the error path for this * Prepare/create devices file preemptively because the error path for
* case from process_each is not as clean. * 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)) { if (!setup_devices_file(cmd)) {
log_error("Failed to set up devices file."); 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."); log_error("Devices file not enabled.");
return ECMD_FAILED; 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_exists(cmd)) {
if (!devices_file_touch(cmd)) { if (!devices_file_touch(cmd)) {
log_error("Failed to create devices file."); log_error("Failed to create devices file.");