diff mbox series

[1/2] btrfs: add helper function find_fsid_by_disk

Message ID 46a185408cb2307eb1f94250533c7d10a3a9d62a.1695826320.git.anand.jain@oracle.com (mailing list archive)
State New, archived
Headers show
Series btrfs: support cloned-device mount capability | expand

Commit Message

Anand Jain Sept. 28, 2023, 1:09 a.m. UTC
In preparation for adding support to mount multiple single-disk
btrfs filesystems with the same FSID, wrap find_fsid() into
find_fsid_by_disk().

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
 fs/btrfs/volumes.c | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)

Comments

David Sterba Oct. 2, 2023, 11:45 a.m. UTC | #1
On Thu, Sep 28, 2023 at 09:09:46AM +0800, Anand Jain wrote:
> In preparation for adding support to mount multiple single-disk
> btrfs filesystems with the same FSID, wrap find_fsid() into
> find_fsid_by_disk().
> 
> Signed-off-by: Anand Jain <anand.jain@oracle.com>
> ---
>  fs/btrfs/volumes.c | 19 +++++++++++++++----
>  1 file changed, 15 insertions(+), 4 deletions(-)
> 
> diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
> index 298e5885ed06..39b5bc2521fb 100644
> --- a/fs/btrfs/volumes.c
> +++ b/fs/btrfs/volumes.c
> @@ -553,6 +553,20 @@ static int btrfs_free_stale_devices(dev_t devt, struct btrfs_device *skip_device
>  	return ret;
>  }
>  
> +static struct btrfs_fs_devices *find_fsid_by_disk(

A minor thing here, I think we don't want to use "disk" in the
identifiers, it's been converted to 'device' where possible but there
are still some references that could be related to on-disk structures so
these can't be changed. In new API I'd prefer 'device'.
Anand Jain Oct. 3, 2023, 12:57 a.m. UTC | #2
On 02/10/2023 19:45, David Sterba wrote:
> On Thu, Sep 28, 2023 at 09:09:46AM +0800, Anand Jain wrote:
>> In preparation for adding support to mount multiple single-disk
>> btrfs filesystems with the same FSID, wrap find_fsid() into
>> find_fsid_by_disk().
>>
>> Signed-off-by: Anand Jain <anand.jain@oracle.com>
>> ---
>>   fs/btrfs/volumes.c | 19 +++++++++++++++----
>>   1 file changed, 15 insertions(+), 4 deletions(-)
>>
>> diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
>> index 298e5885ed06..39b5bc2521fb 100644
>> --- a/fs/btrfs/volumes.c
>> +++ b/fs/btrfs/volumes.c
>> @@ -553,6 +553,20 @@ static int btrfs_free_stale_devices(dev_t devt, struct btrfs_device *skip_device
>>   	return ret;
>>   }
>>   
>> +static struct btrfs_fs_devices *find_fsid_by_disk(
> 
> A minor thing here, I think we don't want to use "disk" in the
> identifiers, it's been converted to 'device' where possible but there
> are still some references that could be related to on-disk structures so
> these can't be changed. In new API I'd prefer 'device'.

yeah. It should be device.

Thanks, Anand
diff mbox series

Patch

diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 298e5885ed06..39b5bc2521fb 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -553,6 +553,20 @@  static int btrfs_free_stale_devices(dev_t devt, struct btrfs_device *skip_device
 	return ret;
 }
 
+static struct btrfs_fs_devices *find_fsid_by_disk(
+					struct btrfs_super_block *disk_super)
+{
+	struct btrfs_fs_devices *fsid_fs_devices;
+	bool has_metadata_uuid = (btrfs_super_incompat_flags(disk_super) &
+					BTRFS_FEATURE_INCOMPAT_METADATA_UUID);
+
+	/* Find the fs_device by the usual method if found use it */
+	fsid_fs_devices = find_fsid(disk_super->fsid, has_metadata_uuid ?
+					disk_super->metadata_uuid : NULL);
+
+	return fsid_fs_devices;
+}
+
 /*
  * This is only used on mount, and we are protected from competing things
  * messing with our fs_devices by the uuid_mutex, thus we do not need the
@@ -673,10 +687,7 @@  static noinline struct btrfs_device *device_list_add(const char *path,
 		return ERR_PTR(error);
 	}
 
-	if (has_metadata_uuid)
-		fs_devices = find_fsid(disk_super->fsid, disk_super->metadata_uuid);
-	else
-		fs_devices = find_fsid(disk_super->fsid, NULL);
+	fs_devices = find_fsid_by_disk(disk_super);
 
 	if (!fs_devices) {
 		fs_devices = alloc_fs_devices(disk_super->fsid);