btrfs-progs: prepare helper device_is_seed

load_device_info() checks if the device is a seed device by reading
superblock::fsid and comparing it with the mount fsid, and it fails
to work if the device is missing (a RAID1 seed fs). Move this part
of the code into a new helper function device_is_seed() in
preparation to make device_is_seed() work with the new sysfs
devinfo/<devid>/fsid interface.

Reviewed-by: Josef Bacik <josef@toxicpanda.com>
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-02-13 17:37:41 +08:00 committed by David Sterba
parent 8098e6d5c1
commit bdd0ca8a9a
1 changed files with 17 additions and 3 deletions

View File

@ -700,6 +700,21 @@ out:
return ret; return ret;
} }
static int device_is_seed(const char *dev_path, const u8 *mnt_fsid)
{
u8 fsid[BTRFS_UUID_SIZE];
int ret;
ret = dev_to_fsid(dev_path, fsid);
if (ret)
return ret;
if (memcmp(mnt_fsid, fsid, BTRFS_FSID_SIZE) != 0)
return 0;
return -1;
}
/* /*
* This function loads the device_info structure and put them in an array * This function loads the device_info structure and put them in an array
*/ */
@ -710,7 +725,6 @@ static int load_device_info(int fd, struct device_info **devinfo_ret,
struct btrfs_ioctl_fs_info_args fi_args; struct btrfs_ioctl_fs_info_args fi_args;
struct btrfs_ioctl_dev_info_args dev_info; struct btrfs_ioctl_dev_info_args dev_info;
struct device_info *info; struct device_info *info;
u8 fsid[BTRFS_UUID_SIZE];
*devcount_ret = 0; *devcount_ret = 0;
*devinfo_ret = NULL; *devinfo_ret = NULL;
@ -754,8 +768,8 @@ static int load_device_info(int fd, struct device_info **devinfo_ret,
* Ignore any other error including -EACCES, which is seen when * Ignore any other error including -EACCES, which is seen when
* a non-root process calls dev_to_fsid(path)->open(path). * a non-root process calls dev_to_fsid(path)->open(path).
*/ */
ret = dev_to_fsid((const char *)dev_info.path, fsid); ret = device_is_seed((const char *)dev_info.path, fi_args.fsid);
if (!ret && memcmp(fi_args.fsid, fsid, BTRFS_FSID_SIZE) != 0) if (!ret)
continue; continue;
info[ndevs].devid = dev_info.devid; info[ndevs].devid = dev_info.devid;