diff mbox series

[1/7] btrfs: add a helper to read the superblock metadata_uuid

Message ID 1cd0b6f911758c85fd135c24d88c3b0b9f0f85a4.1690792823.git.anand.jain@oracle.com (mailing list archive)
State New, archived
Headers show
Series metadata_uuid misc cleanup and fixes part2 | expand

Commit Message

Anand Jain July 31, 2023, 11:16 a.m. UTC
In some cases, we need to read the FSID from the superblock when the
metadata_uuid is not set, and otherwise, read the metadata_uuid. So,
add a helper.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
 fs/btrfs/volumes.c | 8 ++++++++
 fs/btrfs/volumes.h | 1 +
 2 files changed, 9 insertions(+)

Comments

Johannes Thumshirn Aug. 1, 2023, 1:16 p.m. UTC | #1
On 31.07.23 13:18, Anand Jain wrote:
> +u8 *btrfs_sb_fsid_ptr(struct btrfs_super_block *sb)
> +{
> +	bool has_metadata_uuid = (btrfs_super_incompat_flags(sb) &
> +				  BTRFS_FEATURE_INCOMPAT_METADATA_UUID);
> +
> +	return has_metadata_uuid ? sb->metadata_uuid : sb->fsid;
> +}

Not a huge fan of the overly long variable name and first line, but the 
concept looks good:
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
David Sterba Aug. 11, 2023, 3:18 p.m. UTC | #2
On Tue, Aug 01, 2023 at 01:16:42PM +0000, Johannes Thumshirn wrote:
> On 31.07.23 13:18, Anand Jain wrote:
> > +u8 *btrfs_sb_fsid_ptr(struct btrfs_super_block *sb)
> > +{
> > +	bool has_metadata_uuid = (btrfs_super_incompat_flags(sb) &
> > +				  BTRFS_FEATURE_INCOMPAT_METADATA_UUID);
> > +
> > +	return has_metadata_uuid ? sb->metadata_uuid : sb->fsid;
> > +}
> 
> Not a huge fan of the overly long variable name and first line, but the 
> concept looks good:

For the incompat bit checks (btrfs_fs_incompat & co) we have the macros
that glue the prefix of the bit name but that's for the fs_info data.
For raw buffers of super block we use the unpreprocessed helpers/macros,
there are like 3 in total so that's probably not worth a helper.
diff mbox series

Patch

diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 70d69d4b44d2..2020b1fac764 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -681,6 +681,14 @@  static int btrfs_open_one_device(struct btrfs_fs_devices *fs_devices,
 	return -EINVAL;
 }
 
+u8 *btrfs_sb_fsid_ptr(struct btrfs_super_block *sb)
+{
+	bool has_metadata_uuid = (btrfs_super_incompat_flags(sb) &
+				  BTRFS_FEATURE_INCOMPAT_METADATA_UUID);
+
+	return has_metadata_uuid ? sb->metadata_uuid : sb->fsid;
+}
+
 /*
  * Handle scanned device having its CHANGING_FSID_V2 flag set and the fs_devices
  * being created with a disk that has already completed its fsid change. Such
diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h
index b8c51f16ba86..0f87057bb575 100644
--- a/fs/btrfs/volumes.h
+++ b/fs/btrfs/volumes.h
@@ -749,5 +749,6 @@  int btrfs_verify_dev_extents(struct btrfs_fs_info *fs_info);
 bool btrfs_repair_one_zone(struct btrfs_fs_info *fs_info, u64 logical);
 
 bool btrfs_pinned_by_swapfile(struct btrfs_fs_info *fs_info, void *ptr);
+u8 *btrfs_sb_fsid_ptr(struct btrfs_super_block *sb);
 
 #endif