From patchwork Mon Feb 5 20:05:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Overstreet X-Patchwork-Id: 197044 Return-Path: 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 (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 ; 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 ; 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 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 , Christian Brauner , Jan Kara , Dave Chinner , "Darrick J. Wong" , Theodore Ts'o , Josef Bacik 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: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790097368007097421 X-GMAIL-MSGID: 1790097368007097421 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 Cc: Christian Brauner Cc: Jan Kara Cc: Dave Chinner Cc: "Darrick J. Wong" Cc: Theodore Ts'o Cc: Josef Bacik --- 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) +{ + 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)