Message ID | 20240205200529.546646-5-kent.overstreet@linux.dev |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-53891-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1163931dyb; Mon, 5 Feb 2024 13:51:24 -0800 (PST) X-Google-Smtp-Source: AGHT+IFbaYVjFLWCkLWh/a9qnBnpn9UzY+rrdLiTLQ1SkqUJoIZt7mi1cOE1eRNDjmlZXfKUP13w X-Received: by 2002:a17:903:41cf:b0:1d9:a890:e72f with SMTP id u15-20020a17090341cf00b001d9a890e72fmr1112897ple.50.1707169883796; Mon, 05 Feb 2024 13:51:23 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707169883; cv=pass; d=google.com; s=arc-20160816; b=1JAJNSlJ+R5m6W0+nsWdavS+RRtbCt5Gk0DbThX4KzVHjs8xZqu9eFxtxfYkK2y2Oj aq0N2xteXbuBOezOgBcIlPwuxMlpNZIPcteRpZx0ehQFWehypqw8dQFnI9fQVfaOyolC HFTkBcM4g0hmdVjHE5LDjVIvtyxltftZ6+KtHw052NSY9mX/APheX4yx3Qsxod4JhgXO uyx9lH3pHYHdjkSu15mbYJ6cejs6HhGD0n4fYdm3fZTiwTGK8xpIwjH7/mhGAvbSItt3 816z9XPTf4n0CltI2q0BtyiKw4b5VjcaWDMPKieAm3wJmfEapak33q3fh89UxPbkmZ1L zwcQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=bL8wabdGusxxHP4HD7jQgm1B3xq2dag3vBv1kp/RjKg=; fh=rJgmugYtAQZzcYc/GXHq80jI8rMQvD++fxHHnMVstSg=; b=p3g4uhoFzm4dHRo1APpe8SZ50ae7ukEWk2nN1eeaDBQhilKMJo9oZkRh+kAnDQ2GE1 Hb59Swo1FCARkc4P9WFJFnMoEAWo/daVGZZgLIGprY+nQ2kbT7TaKERcd2LdyRXjWOTI uAgMNIvaMLr8TK6t1h5ibOh82Lh1q5M4HSPW+5H/PotasBZdZvYiCXP80T3Wvdsl6J4M Aq5U6h4wQEh0oAoRNAG0ig4vV9zCOgrvur5tJVLR9Ofys1cpfLG06Z1aJjB1vC4Muiqy g8uJ/CzqcqkwPnOzD+cqwNSwmOV01+2HCmEKyrcqqRT91um9PRha5DqOTT49khPlD4BC O4UA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=gRu95KeB; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-53891-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-53891-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev X-Forwarded-Encrypted: i=1; AJvYcCXR4sb/HrP4M9bTEE8liHA5rDLDsoEynz4oWc2NUCVPgQPcuy5Lm8vjC9TVTwQ9AelIttg8BrNspDaPunm/NV+rSstOcA== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id ei9-20020a17090ae54900b00296a3c5fb15si1904879pjb.34.2024.02.05.13.51.23 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 13:51:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-53891-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=gRu95KeB; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-53891-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-53891-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id B4DF3287386 for <ouuuleilei@gmail.com>; Mon, 5 Feb 2024 21:41:13 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3A23B12DDBA; Mon, 5 Feb 2024 20:06:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="gRu95KeB" Received: from out-182.mta0.migadu.com (out-182.mta0.migadu.com [91.218.175.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0833412BEB9 for <linux-kernel@vger.kernel.org>; Mon, 5 Feb 2024 20:06:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707163574; cv=none; b=A1WKM5hKmHCQh96ohwGbOeCQ6fzi1GF6AltCHEhR94EB+BGhzutpJUk6qhdWxNwg2Gkf3Q/uMV3uviCE89DuN6q1PTaUBE9pqIj0HPOW7wHd+6YH5RNCE4v6lR6dDQJvJ+o5r4pOOUyqft27+6gu0uUuwqO1M5AXV/cfIBHGQmI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707163574; c=relaxed/simple; bh=OdB2sC0IAQE2qn+uq4dM6SEPk8ivyay4tbCp7RxmvJM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PTcnhIJBtYEvzoZQG/L+H3BXQY022tp2pY0dN7qhr6/xqeSm18Pp0aI09wwQw0l6ewzc8zydA3Mv6rV/JsnkvXL3qdtD+fRSLA5PseTgATWHIZSQeOZo2EBiqFmzcWDYQXjf0kzVhmSXc1KdWIKI/kHoGxDRngfge5anJfiPWSQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=gRu95KeB; arc=none smtp.client-ip=91.218.175.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1707163569; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=bL8wabdGusxxHP4HD7jQgm1B3xq2dag3vBv1kp/RjKg=; b=gRu95KeBmO7sGiIbVqCYHB62tHtBwScHj+QOvvEH7lwcGJhQRU4Id4sAq77nVqqAdbHcvq WLxA7xaJjngusplfaeucaDsaWwFjXqTUcYoVvkGuf88BCvqpXeJIIR+yzYkfGRbJ+OIIvr LO2rJ4oDpy+0FUucX1pT3epb4UOcd1k= From: Kent Overstreet <kent.overstreet@linux.dev> To: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-btrfs@vger.kernel.org, linux-xfs@vger.kernel.org, linux-ext4@vger.kernel.org Cc: Kent Overstreet <kent.overstreet@linux.dev>, Christian Brauner <brauner@kernel.org>, Jan Kara <jack@suse.cz>, Dave Chinner <dchinner@redhat.com>, "Darrick J. Wong" <djwong@kernel.org>, Theodore Ts'o <tytso@mit.edu>, Josef Bacik <josef@toxicpanda.com> Subject: [PATCH 4/6] fs: FS_IOC_GETSYSFSNAME Date: Mon, 5 Feb 2024 15:05:15 -0500 Message-ID: <20240205200529.546646-5-kent.overstreet@linux.dev> In-Reply-To: <20240205200529.546646-1-kent.overstreet@linux.dev> References: <20240205200529.546646-1-kent.overstreet@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790097368007097421 X-GMAIL-MSGID: 1790097368007097421 |
Series | filesystem visibility ioctls | |
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
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 > >
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?
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.
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
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?
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
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 --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)