btrfs-progs: track active metadata_uuid per fs_devices

When the fsid does not match the metadata_uuid, the METADATA_UUID flag
is set in the superblock.

Changing the fsid using the btrfstune -U|-u option is not possible on a
filesystem with the METADATA_UUID flag set. But we are checking the
METADATA_UUID only from the super_copy, and not from the other scanned
device.

To fix this bug, track the metadata_uuid at the fs_devices level instead
of checking it only on the specified device in the argument, and use it.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
Anand Jain 2023-08-03 07:29:45 +08:00 committed by David Sterba
parent 26f25402ff
commit 9ce233965f
3 changed files with 4 additions and 1 deletions

View File

@ -434,6 +434,8 @@ static int device_list_add(const char *path,
*/
if (changing_fsid)
fs_devices->changing_fsid = true;
if (metadata_uuid)
fs_devices->active_metadata_uuid = true;
if (found_transid > fs_devices->latest_trans) {
fs_devices->latest_devid = devid;

View File

@ -102,6 +102,7 @@ struct btrfs_fs_devices {
enum btrfs_chunk_allocation_policy chunk_alloc_policy;
bool changing_fsid;
bool active_metadata_uuid;
};
struct btrfs_bio_stripe {

View File

@ -414,7 +414,7 @@ int BOX_MAIN(btrfstune)(int argc, char *argv[])
}
if (random_fsid || (new_fsid_str && !change_metadata_uuid)) {
if (btrfs_fs_incompat(root->fs_info, METADATA_UUID)) {
if (root->fs_info->fs_devices->active_metadata_uuid) {
error(
"Cannot rewrite fsid while METADATA_UUID flag is active. \n"
"Ensure fsid and metadata_uuid match before retrying.");