Received: by 2002:a05:7412:bbc7:b0:fc:a2b0:25d7 with SMTP id kh7csp3275290rdb; Tue, 6 Feb 2024 12:20:51 -0800 (PST) X-Google-Smtp-Source: AGHT+IHxZRNhBDmgCD8p/Zb1ih40oZ6Ib6+39UTW7Rgw1j+SbbbaEqgzkZXxdkWcxP2+m5JuhNAv X-Received: by 2002:ad4:5def:0:b0:68c:7903:827b with SMTP id jn15-20020ad45def000000b0068c7903827bmr3241060qvb.62.1707250851445; Tue, 06 Feb 2024 12:20:51 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707250851; cv=pass; d=google.com; s=arc-20160816; b=MstQ57IlTpiSMSmAmqwFkgxdK4jo3msLAee4GFUFlG5tdy1CqGT7PNEosLcVhJfEvl Gf7jUCHGrhS9woD0Q6+KJqdayH6eQg8tRQzNsT+OQW0oDT6QtQnN3KyDH3zYhwJiNSFE 9te0ZmLzQsdyJ6kGJIN9pxa3yDID9gQ8852qRBVE+JB//Ax5lBtgmQHeHoKxMcY5zpYE UMS610BiuIQUh74y2W3cSfelv3Fx/jtlTz5duMR8nOFazXQUn15bYsL7EOWvFqqa2uSg D4gzA32SxRYEwZ5u/DB+HvBXmDGz+8NKKeNhSO2ykb1PI5rdribTZW1vtfZ5SmTxAQ47 1uhA== 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=U5UKikkbz3B10HTdfRNgs+6hFZMwivfpqO0QgbQgukg=; b=Lboz12uTDXr6zufwI5+fu7US9wbc/xD/fL/mzMuYPMYfvu14XYvPVaTCtjI4pmVHhZ GUKbHP7t5NasG19W/54bkWEzG3sfF/DaYG7LJ9lDmsZs7Gv6/8GghMsElCOOYpemhXOa /lz1h76+jXXXzBWxnjFAyVvW0PCvDOX2uRx39mLSFxoADBoEqjj+ir0YWv3mCZ7OAKyQ nDku77wGGlx88KX18uNFq3Z0/gefLRh9UemHzYMRRfCvxiKcuWtK5ENE/gnntTxUyBj0 buABJi2Gzw+31Wrfc2+m8wqqhzhuz3+HRjSgFMc60q933Wlo3n35NpKrHzUkOZYTUa1u jonA==; 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-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-55586-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev X-Forwarded-Encrypted: i=1; AJvYcCW8pIrrWT/9oLgfvCyZ5DaK0GOrqjCOqd1Z03fs5znrIGm7FFxZBRFuy4juxvcKPIXwsc9QkZ4Sq6DBBwT9bcIFny4jMS3l13U7ghH8jA== Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id q15-20020ad45caf000000b0068c7a5e268bsi3657826qvh.178.2024.02.06.12.20.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 12:20:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-55586-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::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-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-55586-linux.lists.archive=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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 159C01C22786 for ; Tue, 6 Feb 2024 20:20:51 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7EB911C69D; Tue, 6 Feb 2024 20:19:17 +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 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT 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 */ -- 2.43.0