From patchwork Tue Feb 6 20:18:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Overstreet X-Patchwork-Id: 197634 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1799754dyb; Tue, 6 Feb 2024 12:21:28 -0800 (PST) X-Google-Smtp-Source: AGHT+IGNoW83Kqkkz2QMQdVKWWD/kW1yFb7Y8iSSlASmaaBr6F6izpkF7tMZwdq6QwQpx7UZfFY/ X-Received: by 2002:a05:6870:7251:b0:218:5f59:2a84 with SMTP id y17-20020a056870725100b002185f592a84mr4081241oaf.53.1707250888172; Tue, 06 Feb 2024 12:21:28 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707250888; cv=pass; d=google.com; s=arc-20160816; b=dojVvSD6AMA9NYKvrZgTQl5K+1k0tVNqro+JEPIrrCqVIjsanHikIDtJuS82qGF5UR /8qLhOmV6nnQU3twsqdm/CdfN5Ch0ucNGgTCPgcWvcxKBPLgD/+/pC8Q1FK0d0gktefV Oz47SpA7VarKRi7IyLRDZRExGMaymXPOxLXoqrRkjo9uBjDLltHyQ0rRrfbJIazbDgdN 0MC6IRztwzXz7YFNLfj7ePaTpFl/of4LKcq/3qb8C5Fo8t0jl3VggUtTeFRZQsZzTjO3 KgGZ82lGCIC49amiJowH7Ojxi5saNmEGIb+XZVDS5DWdYpGKN+D1js3hDVeRSOuxEy1Q HF2Q== 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=ItugtweJECqHs1CmLKyw1iHGhu+1pYozy9UbRerZ1b8=; fh=AChkNG47gCq2S3JEGeNRoKv7oD8JZhp3uhQXtHOp5AM=; b=ZmkCxi8s/yO4758QzgIuccuw63NHeKJ6yY5gJF5Iff8TLSlz02vb8y0jvjgoXXYw9O loV4svD8Mco6ZaZMz1FGEI3LoT2rjmbd8AWB2IBR/Kg28dYvYLl/6nfmK9f1wyukVzvd +h+MRImsJMRE8ioejRxNE2ElaMKxFNzubLv9Hv8AUcmVKfvgK4D7bBDpr0MZH2S3FVJi HNmRZLmTpUb8DCEXOUfminGILVe5wuapXzp8gZI8x6L4iQwlG83Ky32REgTKucmE+zl/ uJfR5KC4ZT1Wyzrf4OrLhOs1w3cOT8qzXUtVaGdk3Gs5vUPQqTr0MmfGfOMS/PmViiL7 lCwg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=DKSKc9Qu; 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-55586-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-55586-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev X-Forwarded-Encrypted: i=1; AJvYcCXf1XzRGFUbrHDoxzw5BQjkXBgxMzqZxpGpmUER0z+2yZ3svbLCu0jJoCjxCux6DdzWP939Y50dNn6iAzUGdUS7cRr+nA== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id x21-20020a634a15000000b005dbddc1aeb6si2080981pga.514.2024.02.06.12.21.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 12:21:28 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-55586-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=DKSKc9Qu; 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-55586-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-55586-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 E5CD22878E8 for ; Tue, 6 Feb 2024 20:21:27 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 891111CD33; Tue, 6 Feb 2024 20:19:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="DKSKc9Qu" Received: from out-183.mta0.migadu.com (out-183.mta0.migadu.com [91.218.175.183]) (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 EFEBE1B947 for ; Tue, 6 Feb 2024 20:19:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.183 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707250756; cv=none; b=GuuO52oEIkwKi88ZBnFmfKuLw7PI3+OmUePRXtEZzmOaJkemPsdQ00NQBJFqst+d/yrbZTS4BsntpEPdvHU6JgV1xVD9/zqELVeUl1AKZSQkLOJeIcKe9kyyFw6HT5UvTjl6U/+caLtoCGDFSzrhYgnXSw3gv4DrL9sU0JoVt8Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707250756; c=relaxed/simple; bh=ihVywjsRPaRNHRnt5rdgpKCQd+dwFydgn6siSAIZffg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GjPyJkwwFjrook2OzIpZ0x/s7EbXSoFRPx1egOjkPK+q9jMjzE9MpcMmU6h1sFqqd2UhExOC68TN9Ycdo4dLAFkcOuh/WJibztcF9RyFVwR7d23txI0NYcjXdc1l6eI4HK/fW8cGP10wmgSUbStC4L8em5Yr+QZTEwearHe9D0A= 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=DKSKc9Qu; arc=none smtp.client-ip=91.218.175.183 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=1707250753; 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=ItugtweJECqHs1CmLKyw1iHGhu+1pYozy9UbRerZ1b8=; b=DKSKc9QueSrA93ArB5oPwxfyFK2m+WBscYd1Ghb0bw+a38mdK+rp6SEpyQ5H5sEyXc47tJ 1lSieGlvpOwAuUV5wMDjp1IUIIENjvGsMXu08c/BO/IUoy1qzVPM+rLzftUJ5sKLRcmN+p WxIEql9iBhVS8q97qUtyqkAtYTn5QkY= From: Kent Overstreet To: brauner@kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Kent Overstreet , Jan Kara , Dave Chinner , "Darrick J. Wong" , Theodore Ts'o , Josef Bacik Subject: [PATCH v2 5/7] fs: FS_IOC_GETSYSFSNAME Date: Tue, 6 Feb 2024 15:18:53 -0500 Message-ID: <20240206201858.952303-6-kent.overstreet@linux.dev> In-Reply-To: <20240206201858.952303-1-kent.overstreet@linux.dev> References: <20240206201858.952303-1-kent.overstreet@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790182307175006313 X-GMAIL-MSGID: 1790182307175006313 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). Cc: Christian Brauner Cc: Jan Kara Cc: Dave Chinner Cc: "Darrick J. Wong" Cc: Theodore Ts'o Cc: Josef Bacik Signed-off-by: Kent Overstreet --- fs/ioctl.c | 17 +++++++++++++++++ include/linux/fs.h | 1 + include/uapi/linux/fs.h | 10 ++++++++++ 3 files changed, 28 insertions(+) diff --git a/fs/ioctl.c b/fs/ioctl.c index 046c30294a82..7c37765bd04e 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_get_fs_sysfs_path(struct file *file, void __user *argp) +{ + struct super_block *sb = file_inode(file)->i_sb; + + if (!strlen(sb->s_sysfs_name)) + return -ENOIOCTLCMD; + + struct fssysfspath 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_GETFSSYSFSPATH: + return ioctl_get_fs_sysfs_path(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 acdc56987cb1..b96c1d009718 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 16a6ecadfd8d..c0f7bd4b6350 100644 --- a/include/uapi/linux/fs.h +++ b/include/uapi/linux/fs.h @@ -77,6 +77,10 @@ struct fsuuid2 { __u8 uuid[16]; }; +struct fssysfspath { + __u8 name[128]; +}; + /* extent-same (dedupe) ioctls; these MUST match the btrfs ioctl definitions */ #define FILE_DEDUPE_RANGE_SAME 0 #define FILE_DEDUPE_RANGE_DIFFERS 1 @@ -206,6 +210,12 @@ struct fsxattr { /* Returns the external filesystem UUID, the same one blkid returns */ #define FS_IOC_GETFSUUID _IOR(0x12, 142, struct fsuuid2) +/* + * Returns the path component under /sys/fs/ that refers to this filesystem; + * also /sys/kernel/debug/ for filesystems with debugfs exports + */ +#define FS_IOC_GETFSSYSFSPATH _IOR(0x12, 143, struct fssysfspath) + #define BMAP_IOCTL 1 /* obsolete - kept for compatibility */ #define FIBMAP _IO(0x00,1) /* bmap access */ #define FIGETBSZ _IO(0x00,2) /* get the block size used for bmap */