From patchwork Mon Nov 11 15:09:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13870894 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 5086E1A0AF1; Mon, 11 Nov 2024 15:10:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731337822; cv=none; b=IpiQBWp05nfSU9lquqPyS391uiHWnhW1RuMFVGxDmfgF406gervzn4tDwR5/fB7SM6pl5n7rlOFl3+7Dma+SdlQXNL5eicKAwQ5By87RBhYz5RWlnGXpcQMWbrK5Bs0UYISDGioXf1zTqt4N1NbManc9iW0qX+eh1YeXoAiM2vU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731337822; c=relaxed/simple; bh=X9Af+k53SC3pvggsk6PSnlpJHVzsDieYt3NpVr0tWwA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=L/YS3WZSb5CBL44A37RJkJg1BNiC9YDbYdY6NZ7laaubs1ng6xgm8/sl8PqIqApGRTGbCis1v9sHsZC6YyWv+sksel4dCDoZStMUPbXOiSZpnZlqA74Acn4GZKXDeJrRsRKfmdfwQMEksEU520wUpS8STBhJwOzQK4Dxt+gbVbo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=St0tImYN; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="St0tImYN" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 34AD2C4CED5; Mon, 11 Nov 2024 15:10:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1731337821; bh=X9Af+k53SC3pvggsk6PSnlpJHVzsDieYt3NpVr0tWwA=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=St0tImYNtLAGmFvdFBA5ALrWoHLKF9hTyIplyzGB3tR7/PjUcP1GZQs9IMIwTAInA rYq/jrsp3Hm1bLREVBBzHdtDL3nA7DrAa39r2Sy75GbEVJAL8cFEZVxeO/5KY1RFrk fvVp1trh4NXhwlM61npJrepJW/+sKVVxLA0EeAlwUYdLIIWmSz3sDHTc+BTIs1+1JU qOE6mm2+kN4KoUxipZF7QJXaotjJQok9W5/Fm+PpsNIBp4V6pKdZY2Ax72TgbXPvdv vYIIJsQBbWyCdprfj54hppPVXark7OKIF17hejnlK9VRUtk+xIYcfgv1khvJJPPc53 u1rFPZ+ibo/+g== From: Jeff Layton Date: Mon, 11 Nov 2024 10:09:55 -0500 Subject: [PATCH v4 1/3] fs: don't let statmount return empty strings Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241111-statmount-v4-1-2eaf35d07a80@kernel.org> References: <20241111-statmount-v4-0-2eaf35d07a80@kernel.org> In-Reply-To: <20241111-statmount-v4-0-2eaf35d07a80@kernel.org> To: Alexander Viro , Christian Brauner , Jan Kara Cc: Miklos Szeredi , Ian Kent , Josef Bacik , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Jeff Layton X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=1937; i=jlayton@kernel.org; h=from:subject:message-id; bh=X9Af+k53SC3pvggsk6PSnlpJHVzsDieYt3NpVr0tWwA=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBnMh5bgI0HS4izak8RGZ4OBcDOOn9z7xZmmT8Hs Gn1JqWyH5WJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZzIeWwAKCRAADmhBGVaC FUw2D/9Z3AuWcVoFp3Y03tOJUH7+0Ozn6zpDoO/+HnaiqzcRKLxszJHhbcwzSYUGObVthrNykXd sREgrNmdOfnOZaC27VAmTjQSuHyCnxNOHM0unqcDnjquyMemWyoqkgbYY0tRYj9extHQLnoMlAn QeDl318Rx8wrQG185gHM2uM2K+7C0Q5im+KgE8MvHKYHTXQTzlfy/9QEhwxpBW6SaJfvKQ5vPJD wvEFIQiJG6xGlBIcxfA/VCSfvKof61wA1S/A3ZC/n4RA6P3Q77x01VgUZGo6T08FyloTYF1XIgJ yAiXY1ixIoDOyOoDbUCK/PFOc02QgRI3XucG4xBhM+5/qk3oFM27r0q59mubfDswY9jO3zLYhnb XLGwet2zbNvLiIbpgUNCVq/lIuXVPlgPGjgOqwkp0REfzgnPvxYDZggVjFMbe9P4178JW3M3bFD rBzZr3uZzBLFTVObC+jPTof+Ai8I2oUZXr8RBCw6sUgG39GKJ4kmB4ZNFurEd563ON2Nk2RZGyL 8wfP3lCwZandhSo74DmhvbJEtYns1URUIQhddNXvm4KzmhX8/X2wADLmd4ycvZ/RgWyuemPL152 PErtA9/EP/cNBUdTuA6MqDMoIeRuIuligjRn2V1zZeYtb70f4AtWo+qzXPpQe+pzCYArXwdAMmW X9/dHGiE27RR7uA== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 When one of the statmount_string() handlers doesn't emit anything to seq, the kernel currently sets the corresponding flag and emits an empty string. Given that statmount() returns a mask of accessible fields, just leave the bit unset in this case, and skip any NULL termination. If nothing was emitted to the seq, then the EOVERFLOW and EAGAIN cases aren't applicable and the function can just return immediately. Signed-off-by: Jeff Layton Reviewed-by: Jan Kara --- fs/namespace.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/fs/namespace.c b/fs/namespace.c index ba77ce1c6788dfe461814b5826fcbb3aab68fad4..28ad153b1fb6f49653c0a85d12da457c4650a87e 100644 --- a/fs/namespace.c +++ b/fs/namespace.c @@ -5046,22 +5046,23 @@ static int statmount_string(struct kstatmount *s, u64 flag) size_t kbufsize; struct seq_file *seq = &s->seq; struct statmount *sm = &s->sm; + u32 start = seq->count; switch (flag) { case STATMOUNT_FS_TYPE: - sm->fs_type = seq->count; + sm->fs_type = start; ret = statmount_fs_type(s, seq); break; case STATMOUNT_MNT_ROOT: - sm->mnt_root = seq->count; + sm->mnt_root = start; ret = statmount_mnt_root(s, seq); break; case STATMOUNT_MNT_POINT: - sm->mnt_point = seq->count; + sm->mnt_point = start; ret = statmount_mnt_point(s, seq); break; case STATMOUNT_MNT_OPTS: - sm->mnt_opts = seq->count; + sm->mnt_opts = start; ret = statmount_mnt_opts(s, seq); break; default: @@ -5069,6 +5070,12 @@ static int statmount_string(struct kstatmount *s, u64 flag) return -EINVAL; } + /* + * If nothing was emitted, return to avoid setting the flag + * and terminating the buffer. + */ + if (seq->count == start) + return ret; if (unlikely(check_add_overflow(sizeof(*sm), seq->count, &kbufsize))) return -EOVERFLOW; if (kbufsize >= s->bufsize) From patchwork Mon Nov 11 15:09:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13870895 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 4CAC01A2574; Mon, 11 Nov 2024 15:10:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731337823; cv=none; b=hi5qRJy5rDpgLT838+l/xmDMJAdTLum9cQbe9K+cfks0jfSIrQkUJ8mFVGoiPLWYZxWJzUR3B3tOMWJGVwJ1b1DX1sThVlmwEPLtwqkJmOfYFFd/accIjJc/ghkBeI6ZuiM5L4AwiXQx5J3FOTsVJHFxHcmuewSNAKC9+ekCE0c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731337823; c=relaxed/simple; bh=xzZstM9rrNdRWFzLRzn/IgGA24psf+YZc9e31THx3tU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=jF5mbwnfGGe0LHgxtlRs3EtH47gjpYhHFPL7sCN03Z/R0Rc9AhGwA6g3kq7PljRquX/bIAGz8FkWB/r6zw7G7n4cJWvEXubb650QvvCszoNdZvFMJcif04q5MzlZpVY5gdUTz+p0h4O0VIdR7eP9fDNgJHNS2NCTPSyFdICa8Ws= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=d0vxevoL; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="d0vxevoL" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3053DC4CED8; Mon, 11 Nov 2024 15:10:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1731337822; bh=xzZstM9rrNdRWFzLRzn/IgGA24psf+YZc9e31THx3tU=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=d0vxevoL0sFrmbm6iiPcWv8xBAYWMs+wZR+SMQkeR4MjTsG8KBNeR400cRGoDkm4m rosFj471Ku8TnUTF1+Ks3qMpejqDGhvG68OQDBuQ3DAHfAV2c8BGWZm6OyHydQMhp0 guEwiO25jep5Pjx0xIVatT6Iohj9/FYuhGDCj3uWekBlHdb6SNJEv6tEDeHHLeiAZX /azRfQyjHOQ/f6h6pjIVsFz3cUdM4VQaSe1VKbc1wReK6r4DqLCOB+SItfTphYKIpU NQRG3hbeubzrN/KQXaW675di9GkjyazyX5Oex40wQbnmHXTNVkHHGmdh4fdjkCORsp +gnd5CNsEidTA== From: Jeff Layton Date: Mon, 11 Nov 2024 10:09:56 -0500 Subject: [PATCH v4 2/3] fs: add the ability for statmount() to report the fs_subtype Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241111-statmount-v4-2-2eaf35d07a80@kernel.org> References: <20241111-statmount-v4-0-2eaf35d07a80@kernel.org> In-Reply-To: <20241111-statmount-v4-0-2eaf35d07a80@kernel.org> To: Alexander Viro , Christian Brauner , Jan Kara Cc: Miklos Szeredi , Ian Kent , Josef Bacik , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Jeff Layton X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=3670; i=jlayton@kernel.org; h=from:subject:message-id; bh=xzZstM9rrNdRWFzLRzn/IgGA24psf+YZc9e31THx3tU=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBnMh5bKuHay+6NBy6slkGZMmD2akFNDgU8Siygz 5kZtwFxHWiJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZzIeWwAKCRAADmhBGVaC FUk1D/90TCQbHLDKPd1twJ0sTsEOzqZfsxsUrbhh5ypOtykGdEt4ucHv2BkizGA4hQ4Xl8C3isl mDFBRPhvXGlC9z5Kv7HbVGe9IxvXAk9rg/6zYN+/9xlOD+NeFAjVuUfjgdBfWFoPRHtGI8oZFSw DVMSNpc1r6QZZZEfwWdHsWQ662bCrkditr7Il+L8OvBkWV7ppDZz0hGfxAf5WiF8NKKW1jed+2P q2q4z6iaqXUNY6FaHzsUSCRK/XvsrzBaXQGc/vvfxUBsBrsZhKJx89cn52CjYDDaEdq32fSJpEo lmJrgyF171514f9f6TkiI/F8nlhKiKYbi00hmmwz5bTE3Txhj/pflxNAQkuXLR4oOwqKT+h9wed h+cTVamgJ5oYjKAn4HlXEOheW3fTe7I//Jc/SfR9ltL5aCGVLhc+Hx+t+/L71KvV76WVbtzgcXs ezxeTsFlLh9OdEgdaX5lHdbnG6RKLWqmETySrqhLYC2GYIzmA7ztytngoujzjXG/LDZMqyhdVg1 Z8FEJ7T9aTzh2u4trGpDU8zJaNGOG6wH27CDGU9RT78Xci0MZ80jJ2Y0RRa4CgN4bpZIDfacKOI V5Sv20lZjT2zgIgZrmC8kWdXtuYySKiT97qC7mXSdbqqVwyHi2QoaQ8qnsEH2t1tD3MyMv9LUBX uk60arePSEUO5KA== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 /proc/self/mountinfo prints out the sb->s_subtype after the type. This is particularly useful for disambiguating FUSE mounts (at least when the userland driver bothers to set it). Add STATMOUNT_FS_SUBTYPE and claim one of the __spare2 fields to point to the offset into the str[] array. Reviewed-by: Jan Kara Reviewed-by: Ian Kent Signed-off-by: Jeff Layton --- fs/namespace.c | 19 +++++++++++++++++-- include/uapi/linux/mount.h | 5 ++++- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/fs/namespace.c b/fs/namespace.c index 28ad153b1fb6f49653c0a85d12da457c4650a87e..fc4f81891d544305caf863904c0a6e16562fab49 100644 --- a/fs/namespace.c +++ b/fs/namespace.c @@ -5006,6 +5006,14 @@ static int statmount_fs_type(struct kstatmount *s, struct seq_file *seq) return 0; } +static void statmount_fs_subtype(struct kstatmount *s, struct seq_file *seq) +{ + struct super_block *sb = s->mnt->mnt_sb; + + if (sb->s_subtype) + seq_puts(seq, sb->s_subtype); +} + static void statmount_mnt_ns_id(struct kstatmount *s, struct mnt_namespace *ns) { s->sm.mask |= STATMOUNT_MNT_NS_ID; @@ -5042,7 +5050,7 @@ static int statmount_mnt_opts(struct kstatmount *s, struct seq_file *seq) static int statmount_string(struct kstatmount *s, u64 flag) { - int ret; + int ret = 0; size_t kbufsize; struct seq_file *seq = &s->seq; struct statmount *sm = &s->sm; @@ -5065,6 +5073,10 @@ static int statmount_string(struct kstatmount *s, u64 flag) sm->mnt_opts = start; ret = statmount_mnt_opts(s, seq); break; + case STATMOUNT_FS_SUBTYPE: + sm->fs_subtype = start; + statmount_fs_subtype(s, seq); + break; default: WARN_ON_ONCE(true); return -EINVAL; @@ -5210,6 +5222,9 @@ static int do_statmount(struct kstatmount *s, u64 mnt_id, u64 mnt_ns_id, if (!err && s->mask & STATMOUNT_MNT_OPTS) err = statmount_string(s, STATMOUNT_MNT_OPTS); + if (!err && s->mask & STATMOUNT_FS_SUBTYPE) + err = statmount_string(s, STATMOUNT_FS_SUBTYPE); + if (!err && s->mask & STATMOUNT_MNT_NS_ID) statmount_mnt_ns_id(s, ns); @@ -5231,7 +5246,7 @@ static inline bool retry_statmount(const long ret, size_t *seq_size) } #define STATMOUNT_STRING_REQ (STATMOUNT_MNT_ROOT | STATMOUNT_MNT_POINT | \ - STATMOUNT_FS_TYPE | STATMOUNT_MNT_OPTS) + STATMOUNT_FS_TYPE | STATMOUNT_MNT_OPTS | STATMOUNT_FS_SUBTYPE) static int prepare_kstatmount(struct kstatmount *ks, struct mnt_id_req *kreq, struct statmount __user *buf, size_t bufsize, diff --git a/include/uapi/linux/mount.h b/include/uapi/linux/mount.h index 225bc366ffcbf0319929e2f55f1fbea88e4d7b81..2e939dddf9cbabe574dafdb6cff9ad4cf9298a74 100644 --- a/include/uapi/linux/mount.h +++ b/include/uapi/linux/mount.h @@ -173,7 +173,9 @@ struct statmount { __u32 mnt_root; /* [str] Root of mount relative to root of fs */ __u32 mnt_point; /* [str] Mountpoint relative to current root */ __u64 mnt_ns_id; /* ID of the mount namespace */ - __u64 __spare2[49]; + __u32 fs_subtype; /* [str] Subtype of fs_type (if any) */ + __u32 __spare1[1]; + __u64 __spare2[48]; char str[]; /* Variable size part containing strings */ }; @@ -207,6 +209,7 @@ struct mnt_id_req { #define STATMOUNT_FS_TYPE 0x00000020U /* Want/got fs_type */ #define STATMOUNT_MNT_NS_ID 0x00000040U /* Want/got mnt_ns_id */ #define STATMOUNT_MNT_OPTS 0x00000080U /* Want/got mnt_opts */ +#define STATMOUNT_FS_SUBTYPE 0x00000100U /* Want/got fs_subtype */ /* * Special @mnt_id values that can be passed to listmount From patchwork Mon Nov 11 15:09:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13870896 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 462561A302E; Mon, 11 Nov 2024 15:10:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731337824; cv=none; b=IgbqyrFGw1H8RD/b1hPwgki/DmlFtqPiM8HIU04i6xLjyw0cg5Y7suvCKyJR/Z1y4iH3KVn62bX47v1GX0J63Kgz9tEGXGJUFInLtHzB+PaV4IcLP6EAy4XyhuXWdsafFdIb/+M/l24hgOFs68kxv/LkTcKCuF1V1Y9eRYX8S+M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731337824; c=relaxed/simple; bh=gPPD2BzNbmDa/kJNcw+8GmA/BYpbtW9RM+xKs4INiH8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=KZtwrlwWAsEmJ+iimVB5RLdv1P3IGjOzNUxlf4mH3i8sP/radjMa32UZGaxlNtV52ZRfe/0zSw6fdiw9nHhhxGU2urlh5U6g9GMGg8TCxU62/7JMjgTeyc3OTzbfgly0wMYJmRqMBy9x2oU2BCzWMe1N18DVjLxZXB2B1RKwDfQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=HoauzZUb; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="HoauzZUb" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2BB85C4CED5; Mon, 11 Nov 2024 15:10:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1731337823; bh=gPPD2BzNbmDa/kJNcw+8GmA/BYpbtW9RM+xKs4INiH8=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=HoauzZUb+Az66CkddaEXEDshdWfDHM4Rlb/24Vvglq1yDr6MqkPut/z7sWd1a2aq6 0tuG+aepmB3Ihnf/WHWmTK3v8PMUBHKPzZf/wZ4avKh47/kLwvtH8ljKV5xsDRcODa +P3n32Rq6fx4liNCKMDxaDlFMOLPI7V482n3P06SWisy5BMXNoivFYwmgXBVY6NPXe hGj7snJnfhvvaJG/11fuPCHSPGw9r6h3QR72N/3YGRAa3NhtSp2W/93DwgtluJi5Um KwOXf2L6gn6rK/rEMi5Hxzqxy7wgE+FV3E6jH185qoApSaa6OMYFu2Eg6kWJM9zMcf 9Y6gcP60TbDLA== From: Jeff Layton Date: Mon, 11 Nov 2024 10:09:57 -0500 Subject: [PATCH v4 3/3] fs: add the ability for statmount() to report the sb_source Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241111-statmount-v4-3-2eaf35d07a80@kernel.org> References: <20241111-statmount-v4-0-2eaf35d07a80@kernel.org> In-Reply-To: <20241111-statmount-v4-0-2eaf35d07a80@kernel.org> To: Alexander Viro , Christian Brauner , Jan Kara Cc: Miklos Szeredi , Ian Kent , Josef Bacik , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Jeff Layton X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=3821; i=jlayton@kernel.org; h=from:subject:message-id; bh=gPPD2BzNbmDa/kJNcw+8GmA/BYpbtW9RM+xKs4INiH8=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBnMh5bC+36IFMy/IY4fO1U7YQ3Z2X80uXPRqNmn aWSzELY6u+JAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZzIeWwAKCRAADmhBGVaC FdMrD/9WjfGM+KT3BQKEN/XQbKKdz9LFvJGdDNs3A0E/h+uRXyCfJ7n0Q3xq7WbLkeHg1JU6qZF Adb43CjW+Pe1GSa7UYMSBKNNtE0ocgwyDB8oNzMxwR9h2yS7DCztrjG7ilHSMkjA27Uk7i+/nYv ZCKYuocjrbNsMGrgRLRc5ZmxdOJ6oF1XMBGWEFyyOTi1mcgiNd8G5dB4U2Tbdw4WINRa5aj/YS2 jP9AdGr3f53mLgaqD//gERSXvOyt1W9YdFMKFFxV8c5a+xc7uU8qJIysEuhf335FL3wgpIHobi7 IrfEmGigBdX+HdWcylTMuDwxbHpAyNdLmVtZZRO4JCm55mTmcQJf/gAoi3A5t10+ynzLjf7qXsd zbq3H3Da7vFQ06j5Qz1uPn9rFIatNvCXWaxEBC96hH0J3lqB7YF/OzZ4TOpG0TPYfRxEEV57EFb 2+meIWYy7A3ed61kx/EcPmFhwKzrQY0R8Z3nnYE8bBmLwyFYHTFX2/UdK3jRMRRVneqdC+dyuBr J3A//TBeDxkXxYvcCQtnivJQHuV6SPZ7saY+zle+mdM+GtTe16ZjO5jlp2pedImhxNQW5vImFOO JoKGxYVmGLphv+85fMLg62Tedzl0Yd3Z0MxjfjF6z03HHAT8m1avl6d6w/jg67Q4cYsW0jcjK/A skdPHKCQAoxQtwQ== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 /proc/self/mountinfo displays the source for the mount, but statmount() doesn't yet have a way to return it. Add a new STATMOUNT_SB_SOURCE flag, claim the 32-bit __spare1 field to hold the offset into the str[] array. Reviewed-by: Jan Kara Signed-off-by: Jeff Layton --- fs/namespace.c | 36 +++++++++++++++++++++++++++++++++++- include/uapi/linux/mount.h | 3 ++- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/fs/namespace.c b/fs/namespace.c index fc4f81891d544305caf863904c0a6e16562fab49..4f034dba5884ce3641b8e4048e21879e4bda896c 100644 --- a/fs/namespace.c +++ b/fs/namespace.c @@ -5014,6 +5014,32 @@ static void statmount_fs_subtype(struct kstatmount *s, struct seq_file *seq) seq_puts(seq, sb->s_subtype); } +static int statmount_sb_source(struct kstatmount *s, struct seq_file *seq) +{ + struct super_block *sb = s->mnt->mnt_sb; + struct mount *r = real_mount(s->mnt); + + if (sb->s_op->show_devname) { + size_t start = seq->count; + int ret; + + ret = sb->s_op->show_devname(seq, s->mnt->mnt_root); + if (ret) + return ret; + + if (unlikely(seq_has_overflowed(seq))) + return -EAGAIN; + + /* Unescape the result */ + seq->buf[seq->count] = '\0'; + seq->count = start; + seq_commit(seq, string_unescape_inplace(seq->buf + start, UNESCAPE_OCTAL)); + } else if (r->mnt_devname) { + seq_puts(seq, r->mnt_devname); + } + return 0; +} + static void statmount_mnt_ns_id(struct kstatmount *s, struct mnt_namespace *ns) { s->sm.mask |= STATMOUNT_MNT_NS_ID; @@ -5077,6 +5103,10 @@ static int statmount_string(struct kstatmount *s, u64 flag) sm->fs_subtype = start; statmount_fs_subtype(s, seq); break; + case STATMOUNT_SB_SOURCE: + sm->sb_source = seq->count; + ret = statmount_sb_source(s, seq); + break; default: WARN_ON_ONCE(true); return -EINVAL; @@ -5225,6 +5255,9 @@ static int do_statmount(struct kstatmount *s, u64 mnt_id, u64 mnt_ns_id, if (!err && s->mask & STATMOUNT_FS_SUBTYPE) err = statmount_string(s, STATMOUNT_FS_SUBTYPE); + if (!err && s->mask & STATMOUNT_SB_SOURCE) + err = statmount_string(s, STATMOUNT_SB_SOURCE); + if (!err && s->mask & STATMOUNT_MNT_NS_ID) statmount_mnt_ns_id(s, ns); @@ -5246,7 +5279,8 @@ static inline bool retry_statmount(const long ret, size_t *seq_size) } #define STATMOUNT_STRING_REQ (STATMOUNT_MNT_ROOT | STATMOUNT_MNT_POINT | \ - STATMOUNT_FS_TYPE | STATMOUNT_MNT_OPTS | STATMOUNT_FS_SUBTYPE) + STATMOUNT_FS_TYPE | STATMOUNT_MNT_OPTS | \ + STATMOUNT_FS_SUBTYPE | STATMOUNT_SB_SOURCE) static int prepare_kstatmount(struct kstatmount *ks, struct mnt_id_req *kreq, struct statmount __user *buf, size_t bufsize, diff --git a/include/uapi/linux/mount.h b/include/uapi/linux/mount.h index 2e939dddf9cbabe574dafdb6cff9ad4cf9298a74..2b49e9131d77165899d8e3c17366c6afaa8b7795 100644 --- a/include/uapi/linux/mount.h +++ b/include/uapi/linux/mount.h @@ -174,7 +174,7 @@ struct statmount { __u32 mnt_point; /* [str] Mountpoint relative to current root */ __u64 mnt_ns_id; /* ID of the mount namespace */ __u32 fs_subtype; /* [str] Subtype of fs_type (if any) */ - __u32 __spare1[1]; + __u32 sb_source; /* [str] Source string of the mount */ __u64 __spare2[48]; char str[]; /* Variable size part containing strings */ }; @@ -210,6 +210,7 @@ struct mnt_id_req { #define STATMOUNT_MNT_NS_ID 0x00000040U /* Want/got mnt_ns_id */ #define STATMOUNT_MNT_OPTS 0x00000080U /* Want/got mnt_opts */ #define STATMOUNT_FS_SUBTYPE 0x00000100U /* Want/got fs_subtype */ +#define STATMOUNT_SB_SOURCE 0x00000200U /* Want/got sb_source */ /* * Special @mnt_id values that can be passed to listmount