[PATCH 2/2] btrfs-progs: fi: enable fi usage for filesystem top of seed device

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Currently "fi usage" (and "dev usage") cannot run for the filesystem using
seed device.

This is because FS_INFO ioctl returns the number of devices excluding
seeds, but load_device_info() tries to access valid device from devid 0
to max_id, and results in accessing seeds too (thus causing mismatching
of number of devices).

Since only the size of non-seed devices is matter, fix this by just
skipping seed device by checking device's fsid and comparing it to the fsid
obtained by FS_INFO ioctl.

Signed-off-by: Tomohiro Misono <misono.tomohiro@xxxxxxxxxxxxxx>
---
 cmds-fi-usage.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/cmds-fi-usage.c b/cmds-fi-usage.c
index a72fb4e..50c7e51 100644
--- a/cmds-fi-usage.c
+++ b/cmds-fi-usage.c
@@ -545,6 +545,7 @@ 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;
@@ -568,6 +569,7 @@ static int load_device_info(int fd, struct device_info **device_info_ptr,
 		if (ndevs >= fi_args.num_devices) {
 			error("unexpected number of devices: %d >= %llu", ndevs,
 				(unsigned long long)fi_args.num_devices);
+			error("if seed device is used, try run as root.");
 			goto out;
 		}
 		memset(&dev_info, 0, sizeof(dev_info));
@@ -580,6 +582,19 @@ static int load_device_info(int fd, struct device_info **device_info_ptr,
 			goto out;
 		}
 
+		/*
+		 * Skip seed device by cheking device's fsid (require root).
+		 * Ignore EACCES since if seed is not used this function works
+		 * correctly without root privilege.
+		 */
+		ret = dev_to_fsid((const char *)dev_info.path, fsid);
+		if (ret != -EACCES) {
+			if (ret)
+				goto out;
+			if (memcmp(fi_args.fsid, fsid, BTRFS_FSID_SIZE) != 0)
+				continue;
+		}
+
 		info[ndevs].devid = dev_info.devid;
 		if (!dev_info.path[0]) {
 			strcpy(info[ndevs].path, "missing");
-- 
2.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Filesystem Development]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux