Skip to content

Commit 8ed01ab

Browse files
asjkdave
authored andcommitted
btrfs: s_bdev is not null after missing replace
Yauhen reported in the ML that s_bdev is null at mount, and s_bdev gets updated to some device when missing device is replaced, as because bdev is null for missing device, things gets matched up. Fix this by checking if s_bdev is set. I didn't want to completely remove updating s_bdev because the future multi device support at vfs layer may need it. Signed-off-by: Anand Jain <[email protected]> Reported-by: Yauhen Kharuzhy <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent b525545 commit 8ed01ab

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

fs/btrfs/dev-replace.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,8 @@ static int btrfs_dev_replace_finishing(struct btrfs_fs_info *fs_info,
569569
ASSERT(list_empty(&src_device->resized_list));
570570
tgt_device->commit_total_bytes = src_device->commit_total_bytes;
571571
tgt_device->commit_bytes_used = src_device->bytes_used;
572-
if (fs_info->sb->s_bdev == src_device->bdev)
572+
if (fs_info->sb->s_bdev &&
573+
(fs_info->sb->s_bdev == src_device->bdev))
573574
fs_info->sb->s_bdev = tgt_device->bdev;
574575
if (fs_info->fs_devices->latest_bdev == src_device->bdev)
575576
fs_info->fs_devices->latest_bdev = tgt_device->bdev;

fs/btrfs/volumes.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1848,7 +1848,8 @@ int btrfs_rm_device(struct btrfs_root *root, char *device_path, u64 devid)
18481848

18491849
next_device = list_entry(root->fs_info->fs_devices->devices.next,
18501850
struct btrfs_device, dev_list);
1851-
if (device->bdev == root->fs_info->sb->s_bdev)
1851+
if (root->fs_info->sb->s_bdev &&
1852+
(root->fs_info->sb->s_bdev == device->bdev))
18521853
root->fs_info->sb->s_bdev = next_device->bdev;
18531854
if (device->bdev == root->fs_info->fs_devices->latest_bdev)
18541855
root->fs_info->fs_devices->latest_bdev = next_device->bdev;
@@ -1996,7 +1997,8 @@ void btrfs_destroy_dev_replace_tgtdev(struct btrfs_fs_info *fs_info,
19961997

19971998
next_device = list_entry(fs_info->fs_devices->devices.next,
19981999
struct btrfs_device, dev_list);
1999-
if (tgtdev->bdev == fs_info->sb->s_bdev)
2000+
if (fs_info->sb->s_bdev &&
2001+
(tgtdev->bdev == fs_info->sb->s_bdev))
20002002
fs_info->sb->s_bdev = next_device->bdev;
20012003
if (tgtdev->bdev == fs_info->fs_devices->latest_bdev)
20022004
fs_info->fs_devices->latest_bdev = next_device->bdev;

0 commit comments

Comments
 (0)