Skip to content

Commit d1a6300

Browse files
lorddoskiaskdave
authored andcommitted
btrfs: add members to fs_devices to track fsid changes
In order to gracefully handle split-brain scenario during fsid change (which are very unlikely, yet possible), two more pieces of information will be necessary: 1. The highest generation number among all devices registered to a particular btrfs_fs_devices 2. A boolean flag whether a given btrfs_fs_devices was created by a device which had the FSID_CHANGING_V2 flag set. This is a preparatory patch and just introduces the variables as well as code which sets them, their actual use is going to happen in a later patch. Signed-off-by: Nikolay Borisov <nborisov@suse.com> Reviewed-by: David Sterba <dsterba@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent fbc6fea commit d1a6300

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

fs/btrfs/volumes.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -792,6 +792,8 @@ static noinline struct btrfs_device *device_list_add(const char *path,
792792
u64 devid = btrfs_stack_device_id(&disk_super->dev_item);
793793
bool has_metadata_uuid = (btrfs_super_incompat_flags(disk_super) &
794794
BTRFS_FEATURE_INCOMPAT_METADATA_UUID);
795+
bool fsid_change_in_progress = (btrfs_super_flags(disk_super) &
796+
BTRFS_SUPER_FLAG_CHANGING_FSID_V2);
795797

796798
if (has_metadata_uuid)
797799
fs_devices = find_fsid(disk_super->fsid, disk_super->metadata_uuid);
@@ -805,6 +807,8 @@ static noinline struct btrfs_device *device_list_add(const char *path,
805807
else
806808
fs_devices = alloc_fs_devices(disk_super->fsid, NULL);
807809

810+
fs_devices->fsid_change = fsid_change_in_progress;
811+
808812
if (IS_ERR(fs_devices))
809813
return ERR_CAST(fs_devices);
810814

@@ -940,8 +944,11 @@ static noinline struct btrfs_device *device_list_add(const char *path,
940944
* it back. We need it to pick the disk with largest generation
941945
* (as above).
942946
*/
943-
if (!fs_devices->opened)
947+
if (!fs_devices->opened) {
944948
device->generation = found_transid;
949+
fs_devices->latest_generation = max_t(u64, found_transid,
950+
fs_devices->latest_generation);
951+
}
945952

946953
fs_devices->total_devices = btrfs_super_num_devices(disk_super);
947954

fs/btrfs/volumes.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ BTRFS_DEVICE_GETSET_FUNCS(bytes_used);
211211
struct btrfs_fs_devices {
212212
u8 fsid[BTRFS_FSID_SIZE]; /* FS specific uuid */
213213
u8 metadata_uuid[BTRFS_FSID_SIZE];
214+
bool fsid_change;
214215
struct list_head fs_list;
215216

216217
u64 num_devices;
@@ -219,6 +220,10 @@ struct btrfs_fs_devices {
219220
u64 missing_devices;
220221
u64 total_rw_bytes;
221222
u64 total_devices;
223+
224+
/* Highest generation number of seen devices */
225+
u64 latest_generation;
226+
222227
struct block_device *latest_bdev;
223228

224229
/* all of the devices in the FS, protected by a mutex

0 commit comments

Comments
 (0)