Linux Btrfs filesystem development
 help / color / mirror / Atom feed
From: Josef Bacik <josef@toxicpanda.com>
To: Anand Jain <anand.jain@oracle.com>
Cc: linux-btrfs@vger.kernel.org
Subject: Re: [PATCH 2/2] btrfs-progs: read fsid from the sysfs in device_is_seed
Date: Wed, 20 Oct 2021 09:47:03 -0400	[thread overview]
Message-ID: <YXAd15erkjF+r+tG@localhost.localdomain> (raw)
In-Reply-To: <61915dee-0878-a170-87d5-a3d611af6810@oracle.com>

On Wed, Oct 20, 2021 at 10:40:14AM +0800, Anand Jain wrote:
> 
> 
> On 19/10/2021 22:03, Josef Bacik wrote:
> > On Tue, Oct 19, 2021 at 08:23:45AM +0800, Anand Jain wrote:
> > > The kernel patch [1] added a sysfs interface to read the device fsid from
> > > the kernel, which is a better way to know the fsid of the device (rather
> > > than reading the superblock). It also works if in case the device is
> > > missing. Furthermore, the sysfs interface is readable from the non-root
> > > user.
> > > 
> > > So use this new sysfs interface here to read the fsid.
> > > 
> > > [1]
> > > btrfs: sysfs add devinfo/fsid to retrieve fsid from the device
> > > 
> > > Signed-off-by: Anand Jain <anand.jain@oracle.com>
> > > ---
> > >   cmds/filesystem-usage.c | 38 ++++++++++++++++++++++++++++++--------
> > >   1 file changed, 30 insertions(+), 8 deletions(-)
> > > 
> > > diff --git a/cmds/filesystem-usage.c b/cmds/filesystem-usage.c
> > > index 0dfc798e8dcc..f658c27b9609 100644
> > > --- a/cmds/filesystem-usage.c
> > > +++ b/cmds/filesystem-usage.c
> > > @@ -40,6 +40,7 @@
> > >   #include "common/help.h"
> > >   #include "common/device-utils.h"
> > >   #include "common/open-utils.h"
> > > +#include "common/path-utils.h"
> > >   /*
> > >    * Add the chunk info to the chunk_info list
> > > @@ -706,14 +707,33 @@ out:
> > >   	return ret;
> > >   }
> > > -static int device_is_seed(const char *dev_path, u8 *mnt_fsid)
> > > +static int device_is_seed(int fd, const char *dev_path, u64 devid, u8 *mnt_fsid)
> > >   {
> > > +	char fsidparse[BTRFS_UUID_UNPARSED_SIZE];
> > > +	char fsid_path[PATH_MAX];
> > > +	char devid_str[20];
> > >   	uuid_t fsid;
> > > -	int ret;
> > > +	int ret = -1;
> > > +	int sysfs_fd;
> > > +
> > > +	snprintf(devid_str, 20, "%llu", devid);
> > > +	/* devinfo/<devid>/fsid */
> > > +	path_cat3_out(fsid_path, "devinfo", devid_str, "fsid");
> > > +
> > > +	/* /sys/fs/btrfs/<fsid>/devinfo/<devid>/fsid */
> > > +	sysfs_fd = sysfs_open_fsid_file(fd, fsid_path);
> > > +	if (sysfs_fd >= 0) {
> > > +		sysfs_read_file(sysfs_fd, fsidparse, BTRFS_UUID_UNPARSED_SIZE);
> > > +		fsidparse[BTRFS_UUID_UNPARSED_SIZE - 1] = 0;
> > > +		ret = uuid_parse(fsidparse, fsid);
> > > +		close(sysfs_fd);
> > > +	}
> > > -	ret = dev_to_fsid(dev_path, fsid);
> > 
> > Why not just have dev_to_fsid() use the sysfs thing so all callers can benefit
> > from it, and then have it fall back to the reading of the super block?  Thanks,
> 
> If we are using sysfs to read fsid it means the device is mounted.
> 
> cmd_filesystem_show() uses dev_to_fsid() only if the device is unmounted. So
> we can't use fsid by sysfs here.
> 
> There is no other user of dev_to_fsid().
> 

Ah ok that's reasonable then, you can add

Reviewed-by: Josef Bacik <josef@toxicpanda.com>

to the series then.  Thanks,

Josef

  reply	other threads:[~2021-10-20 13:47 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-19  0:23 [PATCH 0/2] btrfs-progs: read device fsid from the sysfs Anand Jain
2021-10-19  0:23 ` [PATCH 1/2] btrfs-progs: prepare helper device_is_seed Anand Jain
2021-10-19  0:23 ` [PATCH 2/2] btrfs-progs: read fsid from the sysfs in device_is_seed Anand Jain
2021-10-19 14:03   ` Josef Bacik
2021-10-20  2:40     ` Anand Jain
2021-10-20 13:47       ` Josef Bacik [this message]
2021-10-19 14:04 ` [PATCH 0/2] btrfs-progs: read device fsid from the sysfs Josef Bacik
2021-10-20  2:41   ` Anand Jain
2022-01-06  0:04 ` Anand Jain
2022-01-11 15:19   ` Nikolay Borisov
2022-01-21  9:29     ` Anand Jain
2022-08-26  0:14       ` Wang Yugui
2022-08-26 10:18         ` Anand Jain
2022-08-27  0:52           ` Wang Yugui
2022-08-10 10:18 ` Qu Wenruo
2022-08-10 11:18   ` Anand Jain
2022-08-10 11:43     ` Qu Wenruo
  -- strict thread matches above, loose matches on Subject: below --
2023-02-13  9:37 [PATCH v2 " Anand Jain
2023-02-13  9:37 ` [PATCH 2/2] btrfs-progs: read fsid from the sysfs in device_is_seed Anand Jain
2023-02-21 23:17   ` David Sterba

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YXAd15erkjF+r+tG@localhost.localdomain \
    --to=josef@toxicpanda.com \
    --cc=anand.jain@oracle.com \
    --cc=linux-btrfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox