linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] btrfs-progs: when unable to find out fsid of a dev just skip
@ 2017-10-27  7:28 Anand Jain
  2017-10-27 14:13 ` David Sterba
  0 siblings, 1 reply; 2+ messages in thread
From: Anand Jain @ 2017-10-27  7:28 UTC (permalink / raw)
  To: linux-btrfs; +Cc: misono.tomohiro

%fi_args.num_devices provides number of devices excluding the
seed device. So when looping through the device list for a
given fsid, determine if the given device is a seed device
by reading its superblock and then skip it if its a seed device.
Reading of the superblock is done by the function dev_to_fsid()
which can fail if the user is not root OR if the device has media
errors as well. So skip the seed check altogether if we fail to
know the device superblock and thus the fsid.

With this now we are able to view the btrfs fi usage when the
device is bad.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
cc: misono.tomohiro@jp.fujitsu.com
Fixes:
  btrfs-progs: fi: enable fi usage for filesystem top of seed device
---
 cmds-fi-usage.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/cmds-fi-usage.c b/cmds-fi-usage.c
index 50c7e5170678..e71792c2dfd2 100644
--- a/cmds-fi-usage.c
+++ b/cmds-fi-usage.c
@@ -584,16 +584,15 @@ static int load_device_info(int fd, struct device_info **device_info_ptr,
 
 		/*
 		 * 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.
+		 * And we will skip only if dev_to_fsid() is successful
+		 * and dev is a seed device.
+		 * Ignore any other error including -EACCES (-EACCES is seen
+		 * when a non root thread calls dev_to_fsid(path)->open(path)
+		 * it will end up with -EACCES)
 		 */
 		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;
-		}
+		if (!ret && memcmp(fi_args.fsid, fsid, BTRFS_FSID_SIZE) != 0)
+			continue;
 
 		info[ndevs].devid = dev_info.devid;
 		if (!dev_info.path[0]) {
-- 
2.13.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] btrfs-progs: when unable to find out fsid of a dev just skip
  2017-10-27  7:28 [PATCH] btrfs-progs: when unable to find out fsid of a dev just skip Anand Jain
@ 2017-10-27 14:13 ` David Sterba
  0 siblings, 0 replies; 2+ messages in thread
From: David Sterba @ 2017-10-27 14:13 UTC (permalink / raw)
  To: Anand Jain; +Cc: linux-btrfs, misono.tomohiro

On Fri, Oct 27, 2017 at 03:28:48PM +0800, Anand Jain wrote:
> %fi_args.num_devices provides number of devices excluding the
> seed device. So when looping through the device list for a
> given fsid, determine if the given device is a seed device
> by reading its superblock and then skip it if its a seed device.
> Reading of the superblock is done by the function dev_to_fsid()
> which can fail if the user is not root OR if the device has media
> errors as well. So skip the seed check altogether if we fail to
> know the device superblock and thus the fsid.
> 
> With this now we are able to view the btrfs fi usage when the
> device is bad.
> 
> Signed-off-by: Anand Jain <anand.jain@oracle.com>
> cc: misono.tomohiro@jp.fujitsu.com
> Fixes:
>   btrfs-progs: fi: enable fi usage for filesystem top of seed device

Thanks, the misc-test/023 fails due to that on my machine, but not in
the CI. I'd like to keep the tree bisectable, so I'll merge the two
patches together.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-10-27 14:15 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-10-27  7:28 [PATCH] btrfs-progs: when unable to find out fsid of a dev just skip Anand Jain
2017-10-27 14:13 ` David Sterba

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).