From: Christian Brauner <brauner@kernel.org>
To: Christoph Hellwig <hch@infradead.org>
Cc: Aleksa Sarai <cyphar@cyphar.com>,
Alexander Viro <viro@zeniv.linux.org.uk>,
Jan Kara <jack@suse.cz>, Chuck Lever <chuck.lever@oracle.com>,
Jeff Layton <jlayton@kernel.org>,
Amir Goldstein <amir73il@gmail.com>,
Alexander Aring <alex.aring@gmail.com>,
linux-fsdevel@vger.kernel.org, linux-nfs@vger.kernel.org,
linux-kernel@vger.kernel.org, linux-api@vger.kernel.org
Subject: Re: [PATCH RFC v2] fhandle: expose u64 mount id to name_to_handle_at(2)
Date: Mon, 27 May 2024 15:17:13 +0200 [thread overview]
Message-ID: <20240527-raufen-skorpion-fa81805b3273@brauner> (raw)
In-Reply-To: <20240527-hagel-thunfisch-75781b0cf75d@brauner>
On Mon, May 27, 2024 at 02:29:02PM +0200, Christian Brauner wrote:
> On Mon, May 27, 2024 at 04:47:56AM -0700, Christoph Hellwig wrote:
> > On Sun, May 26, 2024 at 12:01:08PM -0700, Aleksa Sarai wrote:
> > > The existing interface already provides a mount ID which is not even
> > > safe without rebooting.
> >
> > And that seems to be a big part of the problem where the Linux by handle
> > syscall API deviated from all know precedence for no good reason. NFS
> > file handles which were the start of this do (and have to) encode a
> > persistent file system identifier. As do the xfs handles (although they
> > do the decoding in the userspace library on Linux for historic reasons),
> > as do the FreeBSD equivalents to these syscalls.
> >
> > > An alternative would be to return something unique to the filesystem
> > > superblock, but as far as I can tell there is no guarantee that every
> > > Linux filesystem's fsid is sufficiently unique to act as a globally
> > > unique identifier. At least with a 64-bit mount ID and statmount(2),
> > > userspace can decide what information is needed to get sufficiently
> > > unique information about the source filesystem.
> >
> > Well, every file system that supports export ops already needs a
> > globally unique ID for NFS to work properly. We might not have good
> > enough interfaces for that, but that shouldn't be too hard.
>
> I see not inherent problem with exposing the 64 bit mount id through
> name_to_handle_at() as we already to expose the old one anyway.
>
> But I agree that it is useful if we had the guarantee that file handles
> are unique in the way you describe. As it currently stands that doesn't
> seem to be the case and userspace doesn't seem to have a way of figuring
> out if the handle provided by name_to_handle_at() is indeed unique as
> you describe and can be reliably passed to open_by_handle_at().
>
> Yes, we should fix it but that's really orthogonal to the mount id. It
> is separately useful and we already do expose it anyway.
Put another way, name_to_handle_at(2) currently states:
Obtaining a persistent filesystem ID
The mount IDs in /proc/self/mountinfo can be reused as
filesystems are unmounted and mounted. Therefore, the mount ID
returned by name_to_handle_at() (in *mount_id) should not be
treated as a persistent identifier for the corresponding
mounted filesystem. However, an application can use the
information in the mountinfo record that corresponds to the mount
ID to derive a persistent identifier.
For example, one can use the device name in the fifth field of
the mountinfo record to search for the corresponding device UUID
via the symbolic links in /dev/disks/by-uuid. (A more
comfortable way of obtaining the UUID is to use the libblkid(3)
library.) That process can then be reversed, using the UUID to
look up the device name, and then obtaining the corre‐ sponding
mount point, in order to produce the mount_fd argument used by
open_by_handle_at().
Returning the 64bit mount id makes this race-free because we now have
statmount():
u64 mnt_id = 0;
name_to_handle_at(AT_FDCWD, "/path/to/file", &handle, &mnt_id, 0);
statmount(mnt_id);
Which gets you the device number which one can use to figure out the
uuid without ever having to open a single file (We could even expose the
UUID of the filesystem through statmount() if we wanted to.).
next prev parent reply other threads:[~2024-05-27 13:17 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-23 20:57 [PATCH RFC v2] fhandle: expose u64 mount id to name_to_handle_at(2) Aleksa Sarai
2024-05-24 4:58 ` Amir Goldstein
2024-05-26 9:25 ` Christoph Hellwig
2024-05-26 19:01 ` Aleksa Sarai
2024-05-27 11:47 ` Christoph Hellwig
2024-05-27 12:29 ` Christian Brauner
2024-05-27 13:17 ` Christian Brauner [this message]
2024-05-27 15:47 ` Trond Myklebust
2024-05-28 7:05 ` Christian Brauner
2024-05-27 16:18 ` Christoph Hellwig
2024-05-27 13:34 ` Jan Kara
2024-05-27 16:24 ` Christoph Hellwig
2024-05-28 8:20 ` Christian Brauner
2024-05-28 8:28 ` Christoph Hellwig
2024-05-28 9:17 ` Christian Brauner
2024-05-28 10:55 ` Christoph Hellwig
2024-05-28 12:04 ` Christian Brauner
2024-05-28 13:22 ` Christoph Hellwig
2024-05-28 13:28 ` Miklos Szeredi
2024-05-29 6:34 ` Christoph Hellwig
2024-06-01 8:12 ` Aleksa Sarai
2024-06-03 10:30 ` Jan Kara
2024-06-04 5:22 ` Christoph Hellwig
2024-05-29 7:40 ` Christian Brauner
2024-05-31 8:14 ` Christoph Hellwig
2024-05-31 10:28 ` Christian Brauner
2024-05-26 22:32 ` Trond Myklebust
2024-05-27 11:49 ` hch
2024-05-27 15:38 ` Trond Myklebust
2024-05-27 16:29 ` hch
2024-05-28 7:12 ` Christian Brauner
2024-05-28 7:15 ` hch
2024-05-28 10:11 ` Jan Kara
2024-05-28 10:56 ` hch
2024-05-28 23:25 ` Dave Chinner
2024-05-29 6:24 ` hch
2024-05-29 7:23 ` Amir Goldstein
2024-05-27 12:22 ` Christian Brauner
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=20240527-raufen-skorpion-fa81805b3273@brauner \
--to=brauner@kernel.org \
--cc=alex.aring@gmail.com \
--cc=amir73il@gmail.com \
--cc=chuck.lever@oracle.com \
--cc=cyphar@cyphar.com \
--cc=hch@infradead.org \
--cc=jack@suse.cz \
--cc=jlayton@kernel.org \
--cc=linux-api@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-nfs@vger.kernel.org \
--cc=viro@zeniv.linux.org.uk \
/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