diff mbox series

[4/6] fs: FS_IOC_GETSYSFSNAME

Message ID 20240205200529.546646-5-kent.overstreet@linux.dev (mailing list archive)
State Deferred, archived
Headers show
Series filesystem visibility ioctls | expand

Commit Message

Kent Overstreet Feb. 5, 2024, 8:05 p.m. UTC
Add a new ioctl for getting the sysfs name of a filesystem - the path
under /sys/fs.

This is going to let us standardize exporting data from sysfs across
filesystems, e.g. time stats.

The returned path will always be of the form "$FSTYP/$SYSFS_IDENTIFIER",
where the sysfs identifier may be a UUID (for bcachefs) or a device name
(xfs).

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
Cc: Christian Brauner <brauner@kernel.org>
Cc: Jan Kara <jack@suse.cz>
Cc: Dave Chinner <dchinner@redhat.com>
Cc: "Darrick J. Wong" <djwong@kernel.org>
Cc: Theodore Ts'o <tytso@mit.edu>
Cc: Josef Bacik <josef@toxicpanda.com>
---
 fs/ioctl.c              | 17 +++++++++++++++++
 include/linux/fs.h      |  1 +
 include/uapi/linux/fs.h |  5 +++++
 3 files changed, 23 insertions(+)

Comments

Darrick J. Wong Feb. 5, 2024, 10:27 p.m. UTC | #1
On Mon, Feb 05, 2024 at 03:05:15PM -0500, Kent Overstreet wrote:
> Add a new ioctl for getting the sysfs name of a filesystem - the path
> under /sys/fs.
> 
> This is going to let us standardize exporting data from sysfs across
> filesystems, e.g. time stats.
> 
> The returned path will always be of the form "$FSTYP/$SYSFS_IDENTIFIER",
> where the sysfs identifier may be a UUID (for bcachefs) or a device name
> (xfs).
> 
> Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
> Cc: Christian Brauner <brauner@kernel.org>
> Cc: Jan Kara <jack@suse.cz>
> Cc: Dave Chinner <dchinner@redhat.com>
> Cc: "Darrick J. Wong" <djwong@kernel.org>
> Cc: Theodore Ts'o <tytso@mit.edu>
> Cc: Josef Bacik <josef@toxicpanda.com>
> ---
>  fs/ioctl.c              | 17 +++++++++++++++++
>  include/linux/fs.h      |  1 +
>  include/uapi/linux/fs.h |  5 +++++
>  3 files changed, 23 insertions(+)
> 
> diff --git a/fs/ioctl.c b/fs/ioctl.c
> index 858801060408..cb3690811d3d 100644
> --- a/fs/ioctl.c
> +++ b/fs/ioctl.c
> @@ -776,6 +776,20 @@ static int ioctl_getfsuuid(struct file *file, void __user *argp)
>  	return copy_to_user(argp, &u, sizeof(u)) ? -EFAULT : 0;
>  }
>  
> +static int ioctl_getfssysfsname(struct file *file, void __user *argp)

ackpthspacesplease.

"ioctl_get_fs_sysfs_name"?

> +{
> +	struct super_block *sb = file_inode(file)->i_sb;
> +
> +	if (!strlen(sb->s_sysfs_name))
> +		return -ENOIOCTLCMD;
> +
> +	struct fssysfsname u = {};
> +
> +	snprintf(u.name, sizeof(u.name), "%s/%s", sb->s_type->name, sb->s_sysfs_name);

Does this actually guarantee that there will be a trailing null in the
output?  It's really stupid that GETFSLABEL can return an unterminated
string if the label is exactly the size of the char array.

> +
> +	return copy_to_user(argp, &u, sizeof(u)) ? -EFAULT : 0;
> +}
> +
>  /*
>   * do_vfs_ioctl() is not for drivers and not intended to be EXPORT_SYMBOL()'d.
>   * It's just a simple helper for sys_ioctl and compat_sys_ioctl.
> @@ -861,6 +875,9 @@ static int do_vfs_ioctl(struct file *filp, unsigned int fd,
>  	case FS_IOC_GETFSUUID:
>  		return ioctl_getfsuuid(filp, argp);
>  
> +	case FS_IOC_GETFSSYSFSNAME:

File System Ioctl Get File System System File System Name.

Yuck.

FS_IOC_GETSYSFSPATH?

Also, do we want to establish that this works for /sys/fs and
/sys/kernel/debug at the same time?

> +		return ioctl_getfssysfsname(filp, argp);
> +
>  	default:
>  		if (S_ISREG(inode->i_mode))
>  			return file_ioctl(filp, cmd, argp);
> diff --git a/include/linux/fs.h b/include/linux/fs.h
> index ff41ea6c3a9c..7f23f593f17c 100644
> --- a/include/linux/fs.h
> +++ b/include/linux/fs.h
> @@ -1258,6 +1258,7 @@ struct super_block {
>  	char			s_id[32];	/* Informational name */
>  	uuid_t			s_uuid;		/* UUID */
>  	u8			s_uuid_len;	/* Default 16, possibly smaller for weird filesystems */
> +	char			s_sysfs_name[UUID_STRING_LEN + 1];
>  
>  	unsigned int		s_max_links;
>  
> diff --git a/include/uapi/linux/fs.h b/include/uapi/linux/fs.h
> index 0389fea87db5..6dd14a453277 100644
> --- a/include/uapi/linux/fs.h
> +++ b/include/uapi/linux/fs.h
> @@ -78,6 +78,10 @@ struct fsuuid2 {
>  	__u8        fsu_uuid[16];
>  };
>  
> +struct fssysfsname {
> +	__u8			name[64];
> +};
> +
>  /* extent-same (dedupe) ioctls; these MUST match the btrfs ioctl definitions */
>  #define FILE_DEDUPE_RANGE_SAME		0
>  #define FILE_DEDUPE_RANGE_DIFFERS	1
> @@ -231,6 +235,7 @@ struct fsxattr {
>  #define FS_IOC_SETFSLABEL		_IOW(0x94, 50, char[FSLABEL_MAX])
>  #define FS_IOC_GETFSUUID		_IOR(0x94, 51, struct fsuuid2)
>  #define FS_IOC_SETFSUUID		_IOW(0x94, 52, struct fsuuid2)
> +#define FS_IOC_GETFSSYSFSNAME		_IOR(0x94, 53, struct fssysfsname)

0x94 is btrfs, don't add things to their "name" space.

--D

>  
>  /*
>   * Inode flags (FS_IOC_GETFLAGS / FS_IOC_SETFLAGS)
> -- 
> 2.43.0
> 
>
Kent Overstreet Feb. 5, 2024, 10:43 p.m. UTC | #2
On Mon, Feb 05, 2024 at 02:27:32PM -0800, Darrick J. Wong wrote:
> On Mon, Feb 05, 2024 at 03:05:15PM -0500, Kent Overstreet wrote:
> > Add a new ioctl for getting the sysfs name of a filesystem - the path
> > under /sys/fs.
> > 
> > This is going to let us standardize exporting data from sysfs across
> > filesystems, e.g. time stats.
> > 
> > The returned path will always be of the form "$FSTYP/$SYSFS_IDENTIFIER",
> > where the sysfs identifier may be a UUID (for bcachefs) or a device name
> > (xfs).
> > 
> > Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
> > Cc: Christian Brauner <brauner@kernel.org>
> > Cc: Jan Kara <jack@suse.cz>
> > Cc: Dave Chinner <dchinner@redhat.com>
> > Cc: "Darrick J. Wong" <djwong@kernel.org>
> > Cc: Theodore Ts'o <tytso@mit.edu>
> > Cc: Josef Bacik <josef@toxicpanda.com>
> > ---
> >  fs/ioctl.c              | 17 +++++++++++++++++
> >  include/linux/fs.h      |  1 +
> >  include/uapi/linux/fs.h |  5 +++++
> >  3 files changed, 23 insertions(+)
> > 
> > diff --git a/fs/ioctl.c b/fs/ioctl.c
> > index 858801060408..cb3690811d3d 100644
> > --- a/fs/ioctl.c
> > +++ b/fs/ioctl.c
> > @@ -776,6 +776,20 @@ static int ioctl_getfsuuid(struct file *file, void __user *argp)
> >  	return copy_to_user(argp, &u, sizeof(u)) ? -EFAULT : 0;
> >  }
> >  
> > +static int ioctl_getfssysfsname(struct file *file, void __user *argp)
> 
> ackpthspacesplease.
> 
> "ioctl_get_fs_sysfs_name"?

It did feel a bit trolling writing that :)

> 
> > +{
> > +	struct super_block *sb = file_inode(file)->i_sb;
> > +
> > +	if (!strlen(sb->s_sysfs_name))
> > +		return -ENOIOCTLCMD;
> > +
> > +	struct fssysfsname u = {};
> > +
> > +	snprintf(u.name, sizeof(u.name), "%s/%s", sb->s_type->name, sb->s_sysfs_name);
> 
> Does this actually guarantee that there will be a trailing null in the
> output?  It's really stupid that GETFSLABEL can return an unterminated
> string if the label is exactly the size of the char array.

It's snprintf, so yes.

(queue another "why are we using raw char arrays everywhere in 2024"
rant, I have to double check this stuff too).

> 
> > +
> > +	return copy_to_user(argp, &u, sizeof(u)) ? -EFAULT : 0;
> > +}
> > +
> >  /*
> >   * do_vfs_ioctl() is not for drivers and not intended to be EXPORT_SYMBOL()'d.
> >   * It's just a simple helper for sys_ioctl and compat_sys_ioctl.
> > @@ -861,6 +875,9 @@ static int do_vfs_ioctl(struct file *filp, unsigned int fd,
> >  	case FS_IOC_GETFSUUID:
> >  		return ioctl_getfsuuid(filp, argp);
> >  
> > +	case FS_IOC_GETFSSYSFSNAME:
> 
> File System Ioctl Get File System System File System Name.
> 
> Yuck.
> 
> FS_IOC_GETSYSFSPATH?
> 
> Also, do we want to establish that this works for /sys/fs and
> /sys/kernel/debug at the same time?

Yeah, I'll add a comment to that effect.

> 
> > +		return ioctl_getfssysfsname(filp, argp);
> > +
> >  	default:
> >  		if (S_ISREG(inode->i_mode))
> >  			return file_ioctl(filp, cmd, argp);
> > diff --git a/include/linux/fs.h b/include/linux/fs.h
> > index ff41ea6c3a9c..7f23f593f17c 100644
> > --- a/include/linux/fs.h
> > +++ b/include/linux/fs.h
> > @@ -1258,6 +1258,7 @@ struct super_block {
> >  	char			s_id[32];	/* Informational name */
> >  	uuid_t			s_uuid;		/* UUID */
> >  	u8			s_uuid_len;	/* Default 16, possibly smaller for weird filesystems */
> > +	char			s_sysfs_name[UUID_STRING_LEN + 1];
> >  
> >  	unsigned int		s_max_links;
> >  
> > diff --git a/include/uapi/linux/fs.h b/include/uapi/linux/fs.h
> > index 0389fea87db5..6dd14a453277 100644
> > --- a/include/uapi/linux/fs.h
> > +++ b/include/uapi/linux/fs.h
> > @@ -78,6 +78,10 @@ struct fsuuid2 {
> >  	__u8        fsu_uuid[16];
> >  };
> >  
> > +struct fssysfsname {
> > +	__u8			name[64];
> > +};
> > +
> >  /* extent-same (dedupe) ioctls; these MUST match the btrfs ioctl definitions */
> >  #define FILE_DEDUPE_RANGE_SAME		0
> >  #define FILE_DEDUPE_RANGE_DIFFERS	1
> > @@ -231,6 +235,7 @@ struct fsxattr {
> >  #define FS_IOC_SETFSLABEL		_IOW(0x94, 50, char[FSLABEL_MAX])
> >  #define FS_IOC_GETFSUUID		_IOR(0x94, 51, struct fsuuid2)
> >  #define FS_IOC_SETFSUUID		_IOW(0x94, 52, struct fsuuid2)
> > +#define FS_IOC_GETFSSYSFSNAME		_IOR(0x94, 53, struct fssysfsname)
> 
> 0x94 is btrfs, don't add things to their "name" space.

Can we please document this somewhere!?

What, dare I ask, is the "namespace" I should be using?
David Sterba Feb. 6, 2024, 1:39 a.m. UTC | #3
On Mon, Feb 05, 2024 at 05:43:37PM -0500, Kent Overstreet wrote:
> On Mon, Feb 05, 2024 at 02:27:32PM -0800, Darrick J. Wong wrote:
> > On Mon, Feb 05, 2024 at 03:05:15PM -0500, Kent Overstreet wrote:
> > > @@ -231,6 +235,7 @@ struct fsxattr {
> > >  #define FS_IOC_SETFSLABEL		_IOW(0x94, 50, char[FSLABEL_MAX])
> > >  #define FS_IOC_GETFSUUID		_IOR(0x94, 51, struct fsuuid2)
> > >  #define FS_IOC_SETFSUUID		_IOW(0x94, 52, struct fsuuid2)
> > > +#define FS_IOC_GETFSSYSFSNAME		_IOR(0x94, 53, struct fssysfsname)
> > 
> > 0x94 is btrfs, don't add things to their "name" space.
> 
> Can we please document this somewhere!?
> 
> What, dare I ask, is the "namespace" I should be using?

Grep for _IOCTL_MAGIC in include/uapi:

uapi/linux/aspeed-lpc-ctrl.h:#define __ASPEED_LPC_CTRL_IOCTL_MAGIC 0xb2
uapi/linux/aspeed-p2a-ctrl.h:#define __ASPEED_P2A_CTRL_IOCTL_MAGIC 0xb3
uapi/linux/bt-bmc.h:#define __BT_BMC_IOCTL_MAGIC        0xb1
uapi/linux/btrfs.h:#define BTRFS_IOCTL_MAGIC 0x94
uapi/linux/f2fs.h:#define F2FS_IOCTL_MAGIC              0xf5
uapi/linux/ipmi_bmc.h:#define __IPMI_BMC_IOCTL_MAGIC        0xB1
uapi/linux/pfrut.h:#define PFRUT_IOCTL_MAGIC 0xEE
uapi/rdma/rdma_user_ioctl.h:#define IB_IOCTL_MAGIC RDMA_IOCTL_MAGIC
uapi/rdma/rdma_user_ioctl_cmds.h:#define RDMA_IOCTL_MAGIC       0x1b

The label ioctls inherited the 0x94 namespace for backward
compatibility but as already said, it's the private namespace of btrfs.
Randy Dunlap Feb. 6, 2024, 4:20 a.m. UTC | #4
On 2/5/24 17:39, David Sterba wrote:
> On Mon, Feb 05, 2024 at 05:43:37PM -0500, Kent Overstreet wrote:
>> On Mon, Feb 05, 2024 at 02:27:32PM -0800, Darrick J. Wong wrote:
>>> On Mon, Feb 05, 2024 at 03:05:15PM -0500, Kent Overstreet wrote:
>>>> @@ -231,6 +235,7 @@ struct fsxattr {
>>>>  #define FS_IOC_SETFSLABEL		_IOW(0x94, 50, char[FSLABEL_MAX])
>>>>  #define FS_IOC_GETFSUUID		_IOR(0x94, 51, struct fsuuid2)
>>>>  #define FS_IOC_SETFSUUID		_IOW(0x94, 52, struct fsuuid2)
>>>> +#define FS_IOC_GETFSSYSFSNAME		_IOR(0x94, 53, struct fssysfsname)
>>>
>>> 0x94 is btrfs, don't add things to their "name" space.
>>
>> Can we please document this somewhere!?
>>
>> What, dare I ask, is the "namespace" I should be using?
> 
> Grep for _IOCTL_MAGIC in include/uapi:
> 
> uapi/linux/aspeed-lpc-ctrl.h:#define __ASPEED_LPC_CTRL_IOCTL_MAGIC 0xb2
> uapi/linux/aspeed-p2a-ctrl.h:#define __ASPEED_P2A_CTRL_IOCTL_MAGIC 0xb3
> uapi/linux/bt-bmc.h:#define __BT_BMC_IOCTL_MAGIC        0xb1
> uapi/linux/btrfs.h:#define BTRFS_IOCTL_MAGIC 0x94
> uapi/linux/f2fs.h:#define F2FS_IOCTL_MAGIC              0xf5
> uapi/linux/ipmi_bmc.h:#define __IPMI_BMC_IOCTL_MAGIC        0xB1
> uapi/linux/pfrut.h:#define PFRUT_IOCTL_MAGIC 0xEE
> uapi/rdma/rdma_user_ioctl.h:#define IB_IOCTL_MAGIC RDMA_IOCTL_MAGIC
> uapi/rdma/rdma_user_ioctl_cmds.h:#define RDMA_IOCTL_MAGIC       0x1b
> 
> The label ioctls inherited the 0x94 namespace for backward
> compatibility but as already said, it's the private namespace of btrfs.
> 

or more generally, see Documentation/userspace-api/ioctl/ioctl-number.rst.

For 0x94, it says:

0x94  all    fs/btrfs/ioctl.h                                        Btrfs filesystem
             and linux/fs.h                                          some lifted to vfs/generic
Kent Overstreet Feb. 6, 2024, 4:33 a.m. UTC | #5
On Mon, Feb 05, 2024 at 08:20:10PM -0800, Randy Dunlap wrote:
> 
> 
> On 2/5/24 17:39, David Sterba wrote:
> > On Mon, Feb 05, 2024 at 05:43:37PM -0500, Kent Overstreet wrote:
> >> On Mon, Feb 05, 2024 at 02:27:32PM -0800, Darrick J. Wong wrote:
> >>> On Mon, Feb 05, 2024 at 03:05:15PM -0500, Kent Overstreet wrote:
> >>>> @@ -231,6 +235,7 @@ struct fsxattr {
> >>>>  #define FS_IOC_SETFSLABEL		_IOW(0x94, 50, char[FSLABEL_MAX])
> >>>>  #define FS_IOC_GETFSUUID		_IOR(0x94, 51, struct fsuuid2)
> >>>>  #define FS_IOC_SETFSUUID		_IOW(0x94, 52, struct fsuuid2)
> >>>> +#define FS_IOC_GETFSSYSFSNAME		_IOR(0x94, 53, struct fssysfsname)
> >>>
> >>> 0x94 is btrfs, don't add things to their "name" space.
> >>
> >> Can we please document this somewhere!?
> >>
> >> What, dare I ask, is the "namespace" I should be using?
> > 
> > Grep for _IOCTL_MAGIC in include/uapi:
> > 
> > uapi/linux/aspeed-lpc-ctrl.h:#define __ASPEED_LPC_CTRL_IOCTL_MAGIC 0xb2
> > uapi/linux/aspeed-p2a-ctrl.h:#define __ASPEED_P2A_CTRL_IOCTL_MAGIC 0xb3
> > uapi/linux/bt-bmc.h:#define __BT_BMC_IOCTL_MAGIC        0xb1
> > uapi/linux/btrfs.h:#define BTRFS_IOCTL_MAGIC 0x94
> > uapi/linux/f2fs.h:#define F2FS_IOCTL_MAGIC              0xf5
> > uapi/linux/ipmi_bmc.h:#define __IPMI_BMC_IOCTL_MAGIC        0xB1
> > uapi/linux/pfrut.h:#define PFRUT_IOCTL_MAGIC 0xEE
> > uapi/rdma/rdma_user_ioctl.h:#define IB_IOCTL_MAGIC RDMA_IOCTL_MAGIC
> > uapi/rdma/rdma_user_ioctl_cmds.h:#define RDMA_IOCTL_MAGIC       0x1b
> > 
> > The label ioctls inherited the 0x94 namespace for backward
> > compatibility but as already said, it's the private namespace of btrfs.
> > 
> 
> or more generally, see Documentation/userspace-api/ioctl/ioctl-number.rst.
> 
> For 0x94, it says:
> 
> 0x94  all    fs/btrfs/ioctl.h                                        Btrfs filesystem
>              and linux/fs.h                                          some lifted to vfs/generic

You guys keep giving the same info over and over again, instead of
anything that would be actually helpful...

Does anyone know what the proper "namespace" is for new VFS level
ioctls?

...Anyone?
Darrick J. Wong Feb. 6, 2024, 5:08 a.m. UTC | #6
On Mon, Feb 05, 2024 at 11:33:11PM -0500, Kent Overstreet wrote:
> On Mon, Feb 05, 2024 at 08:20:10PM -0800, Randy Dunlap wrote:
> > 
> > 
> > On 2/5/24 17:39, David Sterba wrote:
> > > On Mon, Feb 05, 2024 at 05:43:37PM -0500, Kent Overstreet wrote:
> > >> On Mon, Feb 05, 2024 at 02:27:32PM -0800, Darrick J. Wong wrote:
> > >>> On Mon, Feb 05, 2024 at 03:05:15PM -0500, Kent Overstreet wrote:
> > >>>> @@ -231,6 +235,7 @@ struct fsxattr {
> > >>>>  #define FS_IOC_SETFSLABEL		_IOW(0x94, 50, char[FSLABEL_MAX])
> > >>>>  #define FS_IOC_GETFSUUID		_IOR(0x94, 51, struct fsuuid2)
> > >>>>  #define FS_IOC_SETFSUUID		_IOW(0x94, 52, struct fsuuid2)
> > >>>> +#define FS_IOC_GETFSSYSFSNAME		_IOR(0x94, 53, struct fssysfsname)
> > >>>
> > >>> 0x94 is btrfs, don't add things to their "name" space.
> > >>
> > >> Can we please document this somewhere!?
> > >>
> > >> What, dare I ask, is the "namespace" I should be using?
> > > 
> > > Grep for _IOCTL_MAGIC in include/uapi:
> > > 
> > > uapi/linux/aspeed-lpc-ctrl.h:#define __ASPEED_LPC_CTRL_IOCTL_MAGIC 0xb2
> > > uapi/linux/aspeed-p2a-ctrl.h:#define __ASPEED_P2A_CTRL_IOCTL_MAGIC 0xb3
> > > uapi/linux/bt-bmc.h:#define __BT_BMC_IOCTL_MAGIC        0xb1
> > > uapi/linux/btrfs.h:#define BTRFS_IOCTL_MAGIC 0x94
> > > uapi/linux/f2fs.h:#define F2FS_IOCTL_MAGIC              0xf5
> > > uapi/linux/ipmi_bmc.h:#define __IPMI_BMC_IOCTL_MAGIC        0xB1
> > > uapi/linux/pfrut.h:#define PFRUT_IOCTL_MAGIC 0xEE
> > > uapi/rdma/rdma_user_ioctl.h:#define IB_IOCTL_MAGIC RDMA_IOCTL_MAGIC
> > > uapi/rdma/rdma_user_ioctl_cmds.h:#define RDMA_IOCTL_MAGIC       0x1b
> > > 
> > > The label ioctls inherited the 0x94 namespace for backward
> > > compatibility but as already said, it's the private namespace of btrfs.
> > > 
> > 
> > or more generally, see Documentation/userspace-api/ioctl/ioctl-number.rst.
> > 
> > For 0x94, it says:
> > 
> > 0x94  all    fs/btrfs/ioctl.h                                        Btrfs filesystem
> >              and linux/fs.h                                          some lifted to vfs/generic
> 
> You guys keep giving the same info over and over again, instead of
> anything that would be actually helpful...
> 
> Does anyone know what the proper "namespace" is for new VFS level
> ioctls?
> 
> ...Anyone?

I propose you use 0x15 (NAK) and add it to the Documentation/ as the
official VFS ioctl namespace. ;)

--D
Kent Overstreet Feb. 6, 2024, 5:13 a.m. UTC | #7
On Mon, Feb 05, 2024 at 09:08:53PM -0800, Darrick J. Wong wrote:
> On Mon, Feb 05, 2024 at 11:33:11PM -0500, Kent Overstreet wrote:
> > On Mon, Feb 05, 2024 at 08:20:10PM -0800, Randy Dunlap wrote:
> > > 
> > > 
> > > On 2/5/24 17:39, David Sterba wrote:
> > > > On Mon, Feb 05, 2024 at 05:43:37PM -0500, Kent Overstreet wrote:
> > > >> On Mon, Feb 05, 2024 at 02:27:32PM -0800, Darrick J. Wong wrote:
> > > >>> On Mon, Feb 05, 2024 at 03:05:15PM -0500, Kent Overstreet wrote:
> > > >>>> @@ -231,6 +235,7 @@ struct fsxattr {
> > > >>>>  #define FS_IOC_SETFSLABEL		_IOW(0x94, 50, char[FSLABEL_MAX])
> > > >>>>  #define FS_IOC_GETFSUUID		_IOR(0x94, 51, struct fsuuid2)
> > > >>>>  #define FS_IOC_SETFSUUID		_IOW(0x94, 52, struct fsuuid2)
> > > >>>> +#define FS_IOC_GETFSSYSFSNAME		_IOR(0x94, 53, struct fssysfsname)
> > > >>>
> > > >>> 0x94 is btrfs, don't add things to their "name" space.
> > > >>
> > > >> Can we please document this somewhere!?
> > > >>
> > > >> What, dare I ask, is the "namespace" I should be using?
> > > > 
> > > > Grep for _IOCTL_MAGIC in include/uapi:
> > > > 
> > > > uapi/linux/aspeed-lpc-ctrl.h:#define __ASPEED_LPC_CTRL_IOCTL_MAGIC 0xb2
> > > > uapi/linux/aspeed-p2a-ctrl.h:#define __ASPEED_P2A_CTRL_IOCTL_MAGIC 0xb3
> > > > uapi/linux/bt-bmc.h:#define __BT_BMC_IOCTL_MAGIC        0xb1
> > > > uapi/linux/btrfs.h:#define BTRFS_IOCTL_MAGIC 0x94
> > > > uapi/linux/f2fs.h:#define F2FS_IOCTL_MAGIC              0xf5
> > > > uapi/linux/ipmi_bmc.h:#define __IPMI_BMC_IOCTL_MAGIC        0xB1
> > > > uapi/linux/pfrut.h:#define PFRUT_IOCTL_MAGIC 0xEE
> > > > uapi/rdma/rdma_user_ioctl.h:#define IB_IOCTL_MAGIC RDMA_IOCTL_MAGIC
> > > > uapi/rdma/rdma_user_ioctl_cmds.h:#define RDMA_IOCTL_MAGIC       0x1b
> > > > 
> > > > The label ioctls inherited the 0x94 namespace for backward
> > > > compatibility but as already said, it's the private namespace of btrfs.
> > > > 
> > > 
> > > or more generally, see Documentation/userspace-api/ioctl/ioctl-number.rst.
> > > 
> > > For 0x94, it says:
> > > 
> > > 0x94  all    fs/btrfs/ioctl.h                                        Btrfs filesystem
> > >              and linux/fs.h                                          some lifted to vfs/generic
> > 
> > You guys keep giving the same info over and over again, instead of
> > anything that would be actually helpful...
> > 
> > Does anyone know what the proper "namespace" is for new VFS level
> > ioctls?
> > 
> > ...Anyone?
> 
> I propose you use 0x15 (NAK) and add it to the Documentation/ as the
> official VFS ioctl namespace. ;)

Done!
diff mbox series

Patch

diff --git a/fs/ioctl.c b/fs/ioctl.c
index 858801060408..cb3690811d3d 100644
--- a/fs/ioctl.c
+++ b/fs/ioctl.c
@@ -776,6 +776,20 @@  static int ioctl_getfsuuid(struct file *file, void __user *argp)
 	return copy_to_user(argp, &u, sizeof(u)) ? -EFAULT : 0;
 }
 
+static int ioctl_getfssysfsname(struct file *file, void __user *argp)
+{
+	struct super_block *sb = file_inode(file)->i_sb;
+
+	if (!strlen(sb->s_sysfs_name))
+		return -ENOIOCTLCMD;
+
+	struct fssysfsname u = {};
+
+	snprintf(u.name, sizeof(u.name), "%s/%s", sb->s_type->name, sb->s_sysfs_name);
+
+	return copy_to_user(argp, &u, sizeof(u)) ? -EFAULT : 0;
+}
+
 /*
  * do_vfs_ioctl() is not for drivers and not intended to be EXPORT_SYMBOL()'d.
  * It's just a simple helper for sys_ioctl and compat_sys_ioctl.
@@ -861,6 +875,9 @@  static int do_vfs_ioctl(struct file *filp, unsigned int fd,
 	case FS_IOC_GETFSUUID:
 		return ioctl_getfsuuid(filp, argp);
 
+	case FS_IOC_GETFSSYSFSNAME:
+		return ioctl_getfssysfsname(filp, argp);
+
 	default:
 		if (S_ISREG(inode->i_mode))
 			return file_ioctl(filp, cmd, argp);
diff --git a/include/linux/fs.h b/include/linux/fs.h
index ff41ea6c3a9c..7f23f593f17c 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -1258,6 +1258,7 @@  struct super_block {
 	char			s_id[32];	/* Informational name */
 	uuid_t			s_uuid;		/* UUID */
 	u8			s_uuid_len;	/* Default 16, possibly smaller for weird filesystems */
+	char			s_sysfs_name[UUID_STRING_LEN + 1];
 
 	unsigned int		s_max_links;
 
diff --git a/include/uapi/linux/fs.h b/include/uapi/linux/fs.h
index 0389fea87db5..6dd14a453277 100644
--- a/include/uapi/linux/fs.h
+++ b/include/uapi/linux/fs.h
@@ -78,6 +78,10 @@  struct fsuuid2 {
 	__u8        fsu_uuid[16];
 };
 
+struct fssysfsname {
+	__u8			name[64];
+};
+
 /* extent-same (dedupe) ioctls; these MUST match the btrfs ioctl definitions */
 #define FILE_DEDUPE_RANGE_SAME		0
 #define FILE_DEDUPE_RANGE_DIFFERS	1
@@ -231,6 +235,7 @@  struct fsxattr {
 #define FS_IOC_SETFSLABEL		_IOW(0x94, 50, char[FSLABEL_MAX])
 #define FS_IOC_GETFSUUID		_IOR(0x94, 51, struct fsuuid2)
 #define FS_IOC_SETFSUUID		_IOW(0x94, 52, struct fsuuid2)
+#define FS_IOC_GETFSSYSFSNAME		_IOR(0x94, 53, struct fssysfsname)
 
 /*
  * Inode flags (FS_IOC_GETFLAGS / FS_IOC_SETFLAGS)