Skip to content

Commit 69059ce

Browse files
committed
btrfs-progs: replace: fix an unexpected new line when replace failed
[BUG] When a device replace failed, e.g. try to replace a device on a RO mounted btrfs, the error message is incorrectly broken into two lines: [adam@btrfs-vm ~]$ sudo btrfs replace start -fB 1 /dev/test/scratch3 /mnt/btrfs/ Performing full device TRIM /dev/mapper/test-scratch3 (10.00GiB) ... ERROR: ioctl(DEV_REPLACE_START) failed on "/mnt/btrfs/": Read-only file system [adam@btrfs-vm ~]$ Note the newline after the "Read-only file system" error message. [CAUSE] Inside cmd_replace_start(), if the ioctl failed we need to handle the error messages different depeneding on start_args.result. If the result is not BTRFS_IOCTL_DEV_REPLACE_RESULT_NO_RESULT we will append extra info to the error message. But the initial error message is using error(), which implies a newline. This results the above incorrectly splitted error message. [FIX] Instead of manually appending an extra reason to the existing error message, just do different output depending on the start_args.result in the first place. Signed-off-by: Qu Wenruo <wqu@suse.com> Reviewed-by: Anand Jain <anand.jain@oracle.com>
1 parent da4c604 commit 69059ce

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

cmds/replace.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -319,12 +319,11 @@ static int cmd_replace_start(const struct cmd_struct *cmd,
319319
ret = ioctl(fdmnt, BTRFS_IOC_DEV_REPLACE, &start_args);
320320
if (do_not_background) {
321321
if (ret < 0) {
322-
error("ioctl(DEV_REPLACE_START) failed on \"%s\": %m", path);
323-
if (start_args.result != BTRFS_IOCTL_DEV_REPLACE_RESULT_NO_RESULT)
324-
pr_stderr(LOG_DEFAULT, ", %s\n",
325-
replace_dev_result2string(start_args.result));
322+
if (start_args.result == BTRFS_IOCTL_DEV_REPLACE_RESULT_NO_RESULT)
323+
error("ioctl(DEV_REPLACE_START) failed on \"%s\": %m", path);
326324
else
327-
pr_stderr(LOG_DEFAULT, "\n");
325+
error("ioctl(DEV_REPLACE_START) failed on \"%s\": %m, %s",
326+
path, replace_dev_result2string(start_args.result));
328327

329328
if (errno == EOPNOTSUPP)
330329
warning("device replace of RAID5/6 not supported with this kernel");

0 commit comments

Comments
 (0)