[PATCH 1/2] btrfs-progs: prepare helper device_is_seed
From: Anand Jain <hidden>
Date: 2021-10-19 00:24:05
Subsystem:
the rest · Maintainer:
Linus Torvalds
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. Signed-off-by: Anand Jain <redacted> --- cmds/filesystem-usage.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-)
diff --git a/cmds/filesystem-usage.c b/cmds/filesystem-usage.c
index 6c0f9aa977d6..0dfc798e8dcc 100644
--- a/cmds/filesystem-usage.c
+++ b/cmds/filesystem-usage.c@@ -25,6 +25,7 @@ #include <getopt.h> #include <fcntl.h> #include <linux/limits.h> +#include <uuid/uuid.h> #include "common/utils.h" #include "kerncompat.h"
@@ -705,6 +706,21 @@ out: return ret; } +static int device_is_seed(const char *dev_path, u8 *mnt_fsid) +{ + uuid_t fsid; + int ret; + + ret = dev_to_fsid(dev_path, fsid); + if (ret) + return ret; + + if (memcmp(mnt_fsid, fsid, BTRFS_FSID_SIZE)) + return 0; + + return -1; +} + /* * This function loads the device_info structure and put them in an array */
@@ -715,7 +731,6 @@ static int load_device_info(int fd, struct device_info **device_info_ptr, struct btrfs_ioctl_fs_info_args fi_args; struct btrfs_ioctl_dev_info_args dev_info; struct device_info *info; - u8 fsid[BTRFS_UUID_SIZE]; *device_info_count = 0; *device_info_ptr = NULL;
@@ -759,8 +774,8 @@ static int load_device_info(int fd, struct device_info **device_info_ptr, * Ignore any other error including -EACCES, which is seen when * a non-root process calls dev_to_fsid(path)->open(path). */ - ret = dev_to_fsid((const char *)dev_info.path, fsid); - if (!ret && memcmp(fi_args.fsid, fsid, BTRFS_FSID_SIZE) != 0) + ret = device_is_seed((const char *)dev_info.path, fi_args.fsid); + if (!ret) continue; info[ndevs].devid = dev_info.devid;
--
2.31.1