Commit d1a63002 authored by Nikolay Borisov's avatar Nikolay Borisov Committed by David Sterba

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: default avatarNikolay Borisov <nborisov@suse.com>
Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent fbc6feae
...@@ -792,6 +792,8 @@ static noinline struct btrfs_device *device_list_add(const char *path, ...@@ -792,6 +792,8 @@ static noinline struct btrfs_device *device_list_add(const char *path,
u64 devid = btrfs_stack_device_id(&disk_super->dev_item); u64 devid = btrfs_stack_device_id(&disk_super->dev_item);
bool has_metadata_uuid = (btrfs_super_incompat_flags(disk_super) & bool has_metadata_uuid = (btrfs_super_incompat_flags(disk_super) &
BTRFS_FEATURE_INCOMPAT_METADATA_UUID); BTRFS_FEATURE_INCOMPAT_METADATA_UUID);
bool fsid_change_in_progress = (btrfs_super_flags(disk_super) &
BTRFS_SUPER_FLAG_CHANGING_FSID_V2);
if (has_metadata_uuid) if (has_metadata_uuid)
fs_devices = find_fsid(disk_super->fsid, disk_super->metadata_uuid); 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, ...@@ -805,6 +807,8 @@ static noinline struct btrfs_device *device_list_add(const char *path,
else else
fs_devices = alloc_fs_devices(disk_super->fsid, NULL); fs_devices = alloc_fs_devices(disk_super->fsid, NULL);
fs_devices->fsid_change = fsid_change_in_progress;
if (IS_ERR(fs_devices)) if (IS_ERR(fs_devices))
return ERR_CAST(fs_devices); return ERR_CAST(fs_devices);
...@@ -940,8 +944,11 @@ static noinline struct btrfs_device *device_list_add(const char *path, ...@@ -940,8 +944,11 @@ static noinline struct btrfs_device *device_list_add(const char *path,
* it back. We need it to pick the disk with largest generation * it back. We need it to pick the disk with largest generation
* (as above). * (as above).
*/ */
if (!fs_devices->opened) if (!fs_devices->opened) {
device->generation = found_transid; device->generation = found_transid;
fs_devices->latest_generation = max_t(u64, found_transid,
fs_devices->latest_generation);
}
fs_devices->total_devices = btrfs_super_num_devices(disk_super); fs_devices->total_devices = btrfs_super_num_devices(disk_super);
......
...@@ -211,6 +211,7 @@ BTRFS_DEVICE_GETSET_FUNCS(bytes_used); ...@@ -211,6 +211,7 @@ BTRFS_DEVICE_GETSET_FUNCS(bytes_used);
struct btrfs_fs_devices { struct btrfs_fs_devices {
u8 fsid[BTRFS_FSID_SIZE]; /* FS specific uuid */ u8 fsid[BTRFS_FSID_SIZE]; /* FS specific uuid */
u8 metadata_uuid[BTRFS_FSID_SIZE]; u8 metadata_uuid[BTRFS_FSID_SIZE];
bool fsid_change;
struct list_head fs_list; struct list_head fs_list;
u64 num_devices; u64 num_devices;
...@@ -219,6 +220,10 @@ struct btrfs_fs_devices { ...@@ -219,6 +220,10 @@ struct btrfs_fs_devices {
u64 missing_devices; u64 missing_devices;
u64 total_rw_bytes; u64 total_rw_bytes;
u64 total_devices; u64 total_devices;
/* Highest generation number of seen devices */
u64 latest_generation;
struct block_device *latest_bdev; struct block_device *latest_bdev;
/* all of the devices in the FS, protected by a mutex /* all of the devices in the FS, protected by a mutex
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment