Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit 2f1aeab

Browse files
asjkdave
authored andcommitted
btrfs: return accurate error code on open failure in open_fs_devices()
When attempting to exclusive open a device which has no exclusive open permission, such as a physical device associated with the flakey dm device, the open operation will fail, resulting in a mount failure. In this particular scenario, we erroneously return -EINVAL instead of the correct error code provided by the bdev_open_by_path() function, which is -EBUSY. Fix this, by returning error code from the bdev_open_by_path() function. With this correction, the mount error message will align with that of ext4 and xfs. Reviewed-by: Boris Burkov <boris@bur.io> Signed-off-by: Anand Jain <anand.jain@oracle.com> Reviewed-by: David Sterba <dsterba@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent a8b70c7 commit 2f1aeab

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

fs/btrfs/volumes.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1184,23 +1184,30 @@ static int open_fs_devices(struct btrfs_fs_devices *fs_devices,
11841184
struct btrfs_device *device;
11851185
struct btrfs_device *latest_dev = NULL;
11861186
struct btrfs_device *tmp_device;
1187+
int ret = 0;
11871188

11881189
list_for_each_entry_safe(device, tmp_device, &fs_devices->devices,
11891190
dev_list) {
1190-
int ret;
1191+
int ret2;
11911192

1192-
ret = btrfs_open_one_device(fs_devices, device, flags, holder);
1193-
if (ret == 0 &&
1193+
ret2 = btrfs_open_one_device(fs_devices, device, flags, holder);
1194+
if (ret2 == 0 &&
11941195
(!latest_dev || device->generation > latest_dev->generation)) {
11951196
latest_dev = device;
1196-
} else if (ret == -ENODATA) {
1197+
} else if (ret2 == -ENODATA) {
11971198
fs_devices->num_devices--;
11981199
list_del(&device->dev_list);
11991200
btrfs_free_device(device);
12001201
}
1202+
if (ret == 0 && ret2 != 0)
1203+
ret = ret2;
12011204
}
1202-
if (fs_devices->open_devices == 0)
1205+
1206+
if (fs_devices->open_devices == 0) {
1207+
if (ret)
1208+
return ret;
12031209
return -EINVAL;
1210+
}
12041211

12051212
fs_devices->opened = 1;
12061213
fs_devices->latest_dev = latest_dev;

0 commit comments

Comments
 (0)