From patchwork Mon Feb 5 20:05:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Overstreet X-Patchwork-Id: 13546209 Received: from out-184.mta0.migadu.com (out-184.mta0.migadu.com [91.218.175.184]) (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 D31CA129A9E for ; Mon, 5 Feb 2024 20:06:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.184 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707163568; cv=none; b=FlG0eSFBZWCHMHHYTWrpGH5e1ok8RM5zftv8NHgn8YoPrVaiVREPgn8ehdngS9WvgUGBGVwjOgUKt6l8DqR3cPZJKHwaFa2XjEXYikbDMOzKpYg/neSZlq1R0AkiS5tLg8pbrnq04mm6dP6jWcGrXN/HKEI4XKOH/tus7P2z1as= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707163568; c=relaxed/simple; bh=sT0YhdGMz+E9RZmaN5yZSWMd1g+aYCrhSj7fqmLAo7o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=iojZrQAi08dpdEkl+Iau1yW5TSwjo7Pp1GOhe//l2BFPdMLj4NrYQE7XXZ7sEfaHQqvLOzp1n8JybIeAmeqFpTPZyBwIIY3AeoxQBUY4wUfm8IjYYFOHqYppIfq2Y+KnG2Xj76VtCVyQSzrfhzi+EpE2P7xtYOjR0a9qSFOWvMQ= 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=uob/dDzx; arc=none smtp.client-ip=91.218.175.184 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="uob/dDzx" 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=1707163564; 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=mxk7XRZEL0snESkDWwhfb1zBoSWiW2T8Lz3o6KIMn8M=; b=uob/dDzxQcIREDsMEM9g/iWBuz0YPHzPTzop+cY2f31oBhFBJpCrXqtQ7KCYfdmuorHek/ 3BdFAyeJ8xmW3cVWSpJ8jwVBKqrGw114zEAqI1kXcx6EbAAY7oyS1MVSqTQRGZeWGiMh3T 67MIwynAHlE/7CcJzvVvZxLHj5EuROc= 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 Subject: [PATCH 1/6] fs: super_block->s_uuid_len Date: Mon, 5 Feb 2024 15:05:12 -0500 Message-ID: <20240205200529.546646-2-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-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT Some weird old filesytems have UUID-like things that we wish to expose as UUIDs, but are smaller; add a length field so that the new FS_IOC_(GET|SET)UUID ioctls can handle them in generic code. Signed-off-by: Kent Overstreet --- fs/super.c | 1 + include/linux/fs.h | 1 + 2 files changed, 2 insertions(+) diff --git a/fs/super.c b/fs/super.c index d35e85295489..ed688d2a58a7 100644 --- a/fs/super.c +++ b/fs/super.c @@ -375,6 +375,7 @@ static struct super_block *alloc_super(struct file_system_type *type, int flags, s->s_time_gran = 1000000000; s->s_time_min = TIME64_MIN; s->s_time_max = TIME64_MAX; + s->s_uuid_len = sizeof(s->s_uuid); s->s_shrink = shrinker_alloc(SHRINKER_NUMA_AWARE | SHRINKER_MEMCG_AWARE, "sb-%s", type->name); diff --git a/include/linux/fs.h b/include/linux/fs.h index ed5966a70495..ff41ea6c3a9c 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1257,6 +1257,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 */ unsigned int s_max_links; From patchwork Mon Feb 5 20:05:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Overstreet X-Patchwork-Id: 13546210 Received: from out-187.mta0.migadu.com (out-187.mta0.migadu.com [91.218.175.187]) (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 95D2C12A177 for ; Mon, 5 Feb 2024 20:06:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.187 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707163570; cv=none; b=IBsyrQ6+9j8MxJZICATmfPa9bWUu+dh7PJATX7FAlTOh9mgCL6jVw3PNbzDbONi48SXtqNjfRITFX2k856QjU7DFPOuslCG0pLs3MZQc5/jVmFK9PwxZNq6yF+v8HOiN17usHOp06nxAY7joxC1zHBPW1ZnbQWPf9dYjmMX5TPs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707163570; c=relaxed/simple; bh=hPLAUyLLwUKEPrP5CZCmbgyMU8k8zrKbJNl29jrSSdk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bQ5JEngN7Vqr33HRs6puw0IAMo7UzXSJWRt7YzFpQRAdmFHwfNgUrhglmWu8OwkC2EetbejiR8rojq/+TqgjLi9j2L88TKYnQRhoNdnKP0bxLSmtz5lZoQjdU6XybjSEiuhIHo4gjxu2y01sT1sY6LaouqHfD9tUUM092/QHG2Q= 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=Wcr8U8fQ; arc=none smtp.client-ip=91.218.175.187 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="Wcr8U8fQ" 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=1707163566; 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=MqXRwSUVpxeinEtP3l48LwjODcmqmNTThZB6l3iXHHM=; b=Wcr8U8fQCqYiiXre7rQymRda8iHSMIpNPM3+OFYG4WDeLA1Xpd1jwEnMK723HJDBKRO5l0 g0554M9yp0a1oAe+iJ5UMU98kzaBHHllX6DgrX82A0VDgaLHrEBCg1qxgYvy629vbxAx40 HOhKsQ9HMoJfioY7Yt4DCYRG9xNNBNs= 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 , linux-fsdevel@vger.kernel.or Subject: [PATCH 2/6] fs: FS_IOC_GETUUID Date: Mon, 5 Feb 2024 15:05:13 -0500 Message-ID: <20240205200529.546646-3-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-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT Add a new generic ioctls for querying the filesystem UUID. These are lifted versions of the ext4 ioctls, with one change: we're not using a flexible array member, because UUIDs will never be more than 16 bytes. This patch adds a generic implementation of FS_IOC_GETFSUUID, which reads from super_block->s_uuid; FS_IOC_SETFSUUID is left for individual filesystems to implement. Signed-off-by: Kent Overstreet Cc: Christian Brauner Cc: Jan Kara Cc: Dave Chinner Cc: "Darrick J. Wong" Cc: Theodore Ts'o Cc: linux-fsdevel@vger.kernel.or Signed-off-by: Kent Overstreet --- fs/ioctl.c | 16 ++++++++++++++++ include/uapi/linux/fs.h | 16 ++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/fs/ioctl.c b/fs/ioctl.c index 76cf22ac97d7..858801060408 100644 --- a/fs/ioctl.c +++ b/fs/ioctl.c @@ -763,6 +763,19 @@ static int ioctl_fssetxattr(struct file *file, void __user *argp) return err; } +static int ioctl_getfsuuid(struct file *file, void __user *argp) +{ + struct super_block *sb = file_inode(file)->i_sb; + + if (WARN_ON(sb->s_uuid_len > sizeof(sb->s_uuid))) + sb->s_uuid_len = sizeof(sb->s_uuid); + + struct fsuuid2 u = { .fsu_len = sb->s_uuid_len, }; + memcpy(&u.fsu_uuid[0], &sb->s_uuid, sb->s_uuid_len); + + 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. @@ -845,6 +858,9 @@ static int do_vfs_ioctl(struct file *filp, unsigned int fd, case FS_IOC_FSSETXATTR: return ioctl_fssetxattr(filp, argp); + case FS_IOC_GETFSUUID: + return ioctl_getfsuuid(filp, argp); + default: if (S_ISREG(inode->i_mode)) return file_ioctl(filp, cmd, argp); diff --git a/include/uapi/linux/fs.h b/include/uapi/linux/fs.h index 48ad69f7722e..0389fea87db5 100644 --- a/include/uapi/linux/fs.h +++ b/include/uapi/linux/fs.h @@ -64,6 +64,20 @@ struct fstrim_range { __u64 minlen; }; +/* + * We include a length field because some filesystems (vfat) have an identifier + * that we do want to expose as a UUID, but doesn't have the standard length. + * + * We use a fixed size buffer beacuse this interface will, by fiat, never + * support "UUIDs" longer than 16 bytes; we don't want to force all downstream + * users to have to deal with that. + */ +struct fsuuid2 { + __u32 fsu_len; + __u32 fsu_flags; + __u8 fsu_uuid[16]; +}; + /* extent-same (dedupe) ioctls; these MUST match the btrfs ioctl definitions */ #define FILE_DEDUPE_RANGE_SAME 0 #define FILE_DEDUPE_RANGE_DIFFERS 1 @@ -215,6 +229,8 @@ struct fsxattr { #define FS_IOC_FSSETXATTR _IOW('X', 32, struct fsxattr) #define FS_IOC_GETFSLABEL _IOR(0x94, 49, char[FSLABEL_MAX]) #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) /* * Inode flags (FS_IOC_GETFLAGS / FS_IOC_SETFLAGS) From patchwork Mon Feb 5 20:05:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Overstreet X-Patchwork-Id: 13546211 Received: from out-186.mta0.migadu.com (out-186.mta0.migadu.com [91.218.175.186]) (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 80E3B4F1E9; Mon, 5 Feb 2024 20:06:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.186 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707163572; cv=none; b=bWavXltAMxGfcQMVNDlSUGrDk3xurem5hAmeAcoEmqeN5nGCeua/DD+m6n2fm8sJCuwaHY9rxX4akpmR8Lf7FcC5mOqM6BPhfPAUgGAs2/cXRQh5t94a/SuPJVwSk3A8QifJ8XSsnu/YHD7F/lSDJW23Syu+Y/vb4bwMzQ0yApA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707163572; c=relaxed/simple; bh=e2lTROAYcoM/HDLzlNIvyaAd2xWkASoCHOPzvyTKoeY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VIbVY91ZubVACPVf+IBwjGFa2/F+3cujDG21iszwN9jABXxwzxEwOISi3ry+2+q+OTPq/jWZMTHyfDHgQtR/UIYeK+Ty+QVL0qoPypDYt7ODLnleU2iFeRO8bNj8MXdzLZrW4Wbkr1WVN4CrDvFzIsIEKeV9ORheSQNpiZPMwOo= 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=Dg8R9kdj; arc=none smtp.client-ip=91.218.175.186 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="Dg8R9kdj" 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=1707163567; 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=+Y3gjAfbNTQAYItYsU5COE7+yozdE8QNyrcmsyi3W+A=; b=Dg8R9kdj58O0ZqQd8Z7H3MJ/Xo+17XcsMUPoyC294HD/6wNiULMRl/SvP5MfWcctiuI5Io t6CsU8lFKiS3p/H+xykTaZ3BnRI4WQGh1bEXwdtcL+5YOwxMPZjB8OrKC4sytClnNQmBdQ OH6F7iJCR/fZItMA4ZecGTa8HqOC7p4= 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 Subject: [PATCH 3/6] fat: Hook up sb->s_uuid Date: Mon, 5 Feb 2024 15:05:14 -0500 Message-ID: <20240205200529.546646-4-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-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT Now that we have a standard ioctl for querying the filesystem UUID, initialize sb->s_uuid so that it works. Signed-off-by: Kent Overstreet --- fs/fat/inode.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/fs/fat/inode.c b/fs/fat/inode.c index 1fac3dabf130..a3d3478442d1 100644 --- a/fs/fat/inode.c +++ b/fs/fat/inode.c @@ -1762,6 +1762,10 @@ int fat_fill_super(struct super_block *sb, void *data, int silent, int isvfat, else /* fat 16 or 12 */ sbi->vol_id = bpb.fat16_vol_id; + __le32 vol_id_le = cpu_to_le32(sbi->vol_id); + memcpy(&sb->s_uuid, &vol_id_le, sizeof(vol_id_le)); + sb->s_uuid_len = sizeof(vol_id_le); + sbi->dir_per_block = sb->s_blocksize / sizeof(struct msdos_dir_entry); sbi->dir_per_block_bits = ffs(sbi->dir_per_block) - 1; 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: 13546212 Received: from out-186.mta0.migadu.com (out-186.mta0.migadu.com [91.218.175.186]) (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 E01B112B165 for ; Mon, 5 Feb 2024 20:06:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.186 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707163572; cv=none; b=V4RToAVd4a2KPMgFIge3HLT088ze9trYwG7UN3EIpBdEkRRYlvQEvO9kvc8En8qdGRI38xqgsLYmVEeiho+WTT8ULREU+NNEhLYLXvy9/DUyKQVu1MyxCWYh6mNQJCAG/rjVxY17wD4WnU58Q20VWrRccgceL0WcCyNGNV3NJPY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707163572; c=relaxed/simple; bh=OdB2sC0IAQE2qn+uq4dM6SEPk8ivyay4tbCp7RxmvJM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZBnco59M8ju39l2VHElWCQnWP9jYImKTKMJ0vMKAbch8fDNeW2kRi7rqZ6A5Frlkob1AxFLcgbC6cc/pgIqLpM9MPczLk4/19SIKFydtmMSnfo+NdcidBmYC0GwQ7olpSNYOWwdMc5BzTFtfMQUlVrvT6ZYytfaW04Dxk9e1rh4= 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.186 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="gRu95KeB" 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-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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). 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) From patchwork Mon Feb 5 20:05:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Overstreet X-Patchwork-Id: 13546213 Received: from out-185.mta0.migadu.com (out-185.mta0.migadu.com [91.218.175.185]) (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 0239312A16C for ; Mon, 5 Feb 2024 20:06:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.185 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707163575; cv=none; b=CTPpEjtLSelIE/NlLuEUNs4SrWx6uo6ufJybnGHxhXCrYER7jm3cJRlNciUe+7KkM7mayv7lpt4uExK7LXVYVDt5ZNG3H0J82Q3YRD7KH0FuhGvQCqWT45xhjdW2z7SArq8ovw7qp+R9FmsyrMGg8eVZAnk0Qw+5OzHxzaRTny0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707163575; c=relaxed/simple; bh=SpXRXuGnMtRwA2NcE51fX/znF3QwnMp2SZRjBoEEXhY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lSDXEgc2qCmMZM96sxXegUIaDMJOJ1aXMfA/KWlv0cPJX/FNsZiH/1raQqAspr6smfp2EfBHaf0+axgn6MbXgtdE8k6asGYUuarvoSMc7KQtLHMZwBUsbYyAwAFr/cF0nD4/9UrfEB0qavxKKPi7INtnxgRKKittpNYulvNk/PA= 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=xTYaLnhM; arc=none smtp.client-ip=91.218.175.185 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="xTYaLnhM" 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=1707163570; 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=LjLLoTR+ir1vHIuy3hXsUuRK7GJSfSeb1z1mFbcs/pM=; b=xTYaLnhM62iIw9h5mlJHwn37PFD+85rp5V2iVlzDFkUm/hiGWhkq5JrHRt13ZXTLbc5Qqz cTHbzZadurpRL3NbkqdBkVzPCdxApb/tvOrNOsqUEmQ1SOFbq/dPloj4T6KJeTph2qziC+ Z0L+ka/B3oCSICX1qvb2qZpVQDiV1Zw= 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 Subject: [PATCH 5/6] xfs: add support for FS_IOC_GETSYSFSNAME Date: Mon, 5 Feb 2024 15:05:16 -0500 Message-ID: <20240205200529.546646-6-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-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT Signed-off-by: Kent Overstreet --- fs/xfs/xfs_mount.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/fs/xfs/xfs_mount.c b/fs/xfs/xfs_mount.c index aabb25dc3efa..6d16203d5c1c 100644 --- a/fs/xfs/xfs_mount.c +++ b/fs/xfs/xfs_mount.c @@ -711,6 +711,8 @@ xfs_mountfs( if (error) goto out; + strscpy(mp->m_super->s_sysfs_name, mp->m_super->s_id, sizeof(mp->m_super->m_sysfs_name)); + error = xfs_sysfs_init(&mp->m_stats.xs_kobj, &xfs_stats_ktype, &mp->m_kobj, "stats"); if (error) From patchwork Mon Feb 5 20:05:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Overstreet X-Patchwork-Id: 13546214 Received: from out-170.mta0.migadu.com (out-170.mta0.migadu.com [91.218.175.170]) (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 1B62B4F1E9 for ; Mon, 5 Feb 2024 20:06:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707163575; cv=none; b=RCs1UICglK5CxEVHFIrvFrlQHRKvaHRXaSa6Q8oOM3KjGMt2dT6uG3voncMzWvgHQ3iBtz1gespEYsVyW+y2UVGFOL5aJQxM5Uf8Hh3dFr0T2yhzYQ8fQVq3b3kZJu77JJzI52uYsE3WCm0pEuhvgA67bQ333syyDlD4FZlLxRw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707163575; c=relaxed/simple; bh=XgF3fY5kEN+vUXqGN7hKlRnAVg3Ylev2ReQ2bfeBKZI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qf1c9sxOdU4GbCHH8jIcZRqUiDGQk4ep8g8q8RXUqDZ0RvG4kBPaVzPPtNXx6LQauylVm3z45eHMGPbMub0kEkw9O4U8EQlBw7dXr1y/f9VUuBM46MN1CsvmLy0MRL6x+DQKQX173Zu10xQECIRZxPMkI+dIQFS0fScQ1ZJRT+w= 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=PvxVcBYt; arc=none smtp.client-ip=91.218.175.170 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="PvxVcBYt" 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=1707163571; 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=NLVu6z9oDG9sN6mZGh4y4P6bs4UjmMpsBscmXPUe1bU=; b=PvxVcBYt7kYfaf12e30W3x0/H8h/HJO72Cemqvu76NHpwi78k4o2zorkFCEuaYAkT9nwB1 6GHJLaLgmqy4xQSlf/Z03MErkO7mBHraWYj6eTSIwBY2/H1VmgcZXTVjvKPvB4FOGj4fZL OmdQW4FtTPe1DR1sxWKgQfbIK56J9Hk= 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 Subject: [PATCH 6/6] bcachefs: add support for FS_IOC_GETSYSFSNAME Date: Mon, 5 Feb 2024 15:05:17 -0500 Message-ID: <20240205200529.546646-7-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-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT Signed-off-by: Kent Overstreet --- fs/bcachefs/fs.c | 1 + 1 file changed, 1 insertion(+) diff --git a/fs/bcachefs/fs.c b/fs/bcachefs/fs.c index 77ea61090e91..50b2fd3ddd23 100644 --- a/fs/bcachefs/fs.c +++ b/fs/bcachefs/fs.c @@ -1947,6 +1947,7 @@ static struct dentry *bch2_mount(struct file_system_type *fs_type, sb->s_time_min = div_s64(S64_MIN, c->sb.time_units_per_sec) + 1; sb->s_time_max = div_s64(S64_MAX, c->sb.time_units_per_sec); sb->s_uuid = c->sb.user_uuid; + snprintf(sb->s_sysfs_name, sizeof(sb->s_sysfs_name), "%pU", c->sb.user_uuid.b); c->vfs_sb = sb; strscpy(sb->s_id, c->name, sizeof(sb->s_id));