Skip to content

Commit 038ccb0

Browse files
committed
btrfs-progs: replace: properly enqueue if there's another replace running
Enqueuing allows to let some operations to wait until the current one finishes. This usually means that it's waiting for another one, but in case of replace there's a check that does not allow the enqueuing to take place, as reported. Move it before that check. Issue: #645 Signed-off-by: David Sterba <dsterba@suse.com>
1 parent db4e99f commit 038ccb0

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

cmds/replace.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,14 @@ static int cmd_replace_start(const struct cmd_struct *cmd,
197197
}
198198
zoned = (feature_flags.incompat_flags & BTRFS_FEATURE_INCOMPAT_ZONED);
199199

200+
ret = check_running_fs_exclop(fdmnt, BTRFS_EXCLOP_DEV_REPLACE, enqueue);
201+
if (ret != 0) {
202+
if (ret < 0)
203+
error("unable to check status of exclusive operation: %m");
204+
close_file_or_dir(fdmnt, dirstream);
205+
goto leave_with_error;
206+
}
207+
200208
/* check for possible errors before backgrounding */
201209
status_args.cmd = BTRFS_IOCTL_DEV_REPLACE_CMD_STATUS;
202210
status_args.result = BTRFS_IOCTL_DEV_REPLACE_RESULT_NO_RESULT;
@@ -287,15 +295,6 @@ static int cmd_replace_start(const struct cmd_struct *cmd,
287295
goto leave_with_error;
288296
}
289297

290-
/* Check status before any potentially destructive operation */
291-
ret = check_running_fs_exclop(fdmnt, BTRFS_EXCLOP_DEV_REPLACE, enqueue);
292-
if (ret != 0) {
293-
if (ret < 0)
294-
error("unable to check status of exclusive operation: %m");
295-
close_file_or_dir(fdmnt, dirstream);
296-
goto leave_with_error;
297-
}
298-
299298
strncpy((char *)start_args.start.tgtdev_name, dstdev,
300299
BTRFS_DEVICE_PATH_NAME_MAX);
301300
ret = btrfs_prepare_device(fddstdev, dstdev, &dstdev_block_count, 0,

0 commit comments

Comments
 (0)