From nobody Sun Feb 8 10:30:08 2026 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 B24B923A9B3; Thu, 8 May 2025 08:54:14 +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=1746694454; cv=none; b=GWvMDF1JZ9HkW4EQOoDWL2Ae14pNhxPMVlUOYvWZYm6vsF5xWonYaXh//hXZf5utLrvkkA7mRhxB96Re6ENoM3jkFk0njIjiSBB2Ffl5BoSpfWsXQolDXDAa3meRas2XSjNV8oLSE1dStBZAYYifL5n9VxGrbvJg/k9W4/MTUXo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746694454; c=relaxed/simple; bh=v/JeCC0zei40yfy+D9huwYbkieCaFfFFzax9gBj3owU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=nRNAJX1gK9lgjVTgRzlfHNbxyY0r049WRzsBVnaR+K7CZmyyBHVnxU0SBNQEA8LY4mWQgvxGrIjUYwDw+7fMs1gJ5oGSs83Wst7nnZOXhaVUwWd7TXc4gmMJE7TwPYpD8Dpx60Wq1PmzyywqhEKXbsPVFXgm1xVGM/i2G5mVbi8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=mau1NM5k; 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="mau1NM5k" Received: by smtp.kernel.org (Postfix) with ESMTPS id 524B7C4CEED; Thu, 8 May 2025 08:54:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1746694454; bh=v/JeCC0zei40yfy+D9huwYbkieCaFfFFzax9gBj3owU=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=mau1NM5kA8bVVCxDFfqD3XqaHpERPiVwXINSlGKn9d5A2lb/x8CFgrJ9WOgNTY/FR tzIrBpt32sgonbEg+9e5P+jUUDoLZZiQp5aCYrNy1NJr9Nc3fIaj6Jg7vvvL+cv5+5 mdvsyQEjqDA3jeR6Ag2XQ3dSo+Ddi5eQiMCCxJYY3XIc6MniCUgTDG2M09dOYBtMrL IwKPavXsVAyHH81429bb2qYNS/zbJ1ASOdhdT6l/BteCK8NtlxI3o/CqcdkA9kyPNg CaD5wUokJTLJcVty/7/WRGZaVfXAqVUkMvGDdbb108akyKEFwqvXEoWKOcBzZAfV44 QoxQ4dplJbtNg== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 44A38C3ABC0; Thu, 8 May 2025 08:54:14 +0000 (UTC) From: Chen Linxuan via B4 Relay Date: Thu, 08 May 2025 16:53:44 +0800 Subject: [PATCH v2 1/3] fs: fuse: add const qualifier to fuse_ctl_file_conn_get() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250508-fusectl-backing-files-v2-1-62f564e76984@uniontech.com> References: <20250508-fusectl-backing-files-v2-0-62f564e76984@uniontech.com> In-Reply-To: <20250508-fusectl-backing-files-v2-0-62f564e76984@uniontech.com> To: Miklos Szeredi Cc: Amir Goldstein , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Chen Linxuan X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=867; i=chenlinxuan@uniontech.com; h=from:subject:message-id; bh=5gsZgPpE9DdgJfjYJLZW01nMHgcjhblXor/5EfeOtfc=; b=kA0DAAoBdh7mFDmZrosByyZiAGgccSyhL2I1RGp5aE6Oi7v3yNvrXxNaW2mUx61V2VhZzF26t 4kCMwQAAQoAHRYhBM7VUSUCTrF2/LRlWnYe5hQ5ma6LBQJoHHEsAAoJEHYe5hQ5ma6Llf4P+wVF AFOZayfsTWPOyAnfC7cM89rseJKs3NbylmfKz6jgD1QFtfs4pL4fZ9VN4wiz8Hv+ARcZ2gBr2O2 XS4xIS9jTrZWFVMViuBWhAmsWoAH6IAopxPBWkqVTcwjUyrE2mupldzydmGZ0dgR1ugI6ErUsTb 3OSouN+R0KAAaEey30IC9MXPCC9hfp6dD5mcg/KpNxa2TtItwyS3iXznFdmM/azcdXN8e8xjIpn z+litVFXZBw/z+dc+WHn9kqLFMBx78AXMvOZtMXbgdUr/POEduNJwvcf/QbKcn+kPy7IIK4PxIa gpzC+Ur6izsh+AuTwIoAdtadHuFVWXuJE3DPgnE680GSKy7voi4JvBqCV+M8Ppj7Nb8d1C/vG/c GoOTo6BicSToFD9PRasGtv7RQJyKKacKwarfD2rr4Y48IThLXOottiUnDs4Sy/322QmpldRVjn0 sm1LrwzjTEHg2srN1J7qD1Cfyj0Nts/Br6lJb6kIOvQdtguoJucF7oY0vRPPiXM835gCwnee81p Q/+kMAIFsi+Mvq0cdDRtcGagrJfmHbU01Vew2/pOkLLik11yrr8ZIS3jryzUzfChwRdiSmOgPS7 mRsTaWoNyyiC9peAlYF9f2WszTsbFTuDxrzvV6MiklM4KRO7CzfBSqt296oZWux+jyeeq8Cw2/V aQBIJ X-Developer-Key: i=chenlinxuan@uniontech.com; a=openpgp; fpr=D818ACDD385CAE92D4BAC01A6269794D24791D21 X-Endpoint-Received: by B4 Relay for chenlinxuan@uniontech.com/default with auth_id=380 X-Original-From: Chen Linxuan Reply-To: chenlinxuan@uniontech.com From: Chen Linxuan Add const qualifier to the file parameter in fuse_ctl_file_conn_get function to indicate that this function does not modify the passed file object. This improves code clarity and type safety by making the API contract more explicit. Signed-off-by: Chen Linxuan --- fs/fuse/control.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/fuse/control.c b/fs/fuse/control.c index 2a730d88cc3bdb50ea1f8a3185faad5f05fc6e74..f0874403b1f7c91571f38e4ae9f= 8cebe259f7dd1 100644 --- a/fs/fuse/control.c +++ b/fs/fuse/control.c @@ -20,7 +20,7 @@ */ static struct super_block *fuse_control_sb; =20 -static struct fuse_conn *fuse_ctl_file_conn_get(struct file *file) +static struct fuse_conn *fuse_ctl_file_conn_get(const struct file *file) { struct fuse_conn *fc; mutex_lock(&fuse_mutex); --=20 2.43.0 From nobody Sun Feb 8 10:30:08 2026 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 C239423E35F; Thu, 8 May 2025 08:54:14 +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=1746694454; cv=none; b=jL4SQ2alMdYbzfJtxpVXJ4Eva89LqvNFOj2AarKPJ0xIDKxkz+XLIpvrsKqwd0K3zQyRd1X6djeNaY8FDmum5mTVCB1zJN4v+E6IlattfmmybcgAcZWsQ/GKkz3oqmOoi2jAZWrDEkpwBJCUOHqp//Yrc8C4vK8W/jXjtK3Jhj0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746694454; c=relaxed/simple; bh=aeZPyyvtHWmKYFfyG8fSOBi9lfDKNm0mWBz3v98X+YA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=nMmSGuKhfxjIVg6CryYPgrj/GVxALNtG8/ErF9ZEjWUMy+PWv/Xb9c4iUbAaEZYrfUB9gmdG+R0iSrfowSk+SnTvq/rqxHGbNXhtDck15wL2uwhpRRlyvjKY+0rbsmh/t0WjMHFMDInKofC+Poc1E9BROQQB+cAZHxIsRg0qx5g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=exnMG6s6; 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="exnMG6s6" Received: by smtp.kernel.org (Postfix) with ESMTPS id 5EB9CC4CEEB; Thu, 8 May 2025 08:54:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1746694454; bh=aeZPyyvtHWmKYFfyG8fSOBi9lfDKNm0mWBz3v98X+YA=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=exnMG6s67MADw4z/6O6OIxZLxHzLJd3GTY0zO/Rv8FghMA5cBj6pjXmPk2NochDLh gSFPQN6a8J02CsTvjn8Wgmqd0n5D+bzbvjMgAxYykPxG5NGw7BIG2IrrHAYQSXh0Cg 7MUEooF+sEYTaItGd/30uqweDc+FwYPgOuTUU9G//kgFigrYPG2GqMpYImBe6PVJDK sLCHrtFHJ28JLVqtFGyBriHtWgMZuv02bIh1fbQdvxIZY8wpb8svVqKBWyxSZzPTUq uEP5tEIo2tXRxvG/nZFxN5bXCmErsBuGwcH1f4scK21M4ZeGsYhKcZP2VD0zFe1BIY w3UALKydszhRw== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 510CFC3ABC9; Thu, 8 May 2025 08:54:14 +0000 (UTC) From: Chen Linxuan via B4 Relay Date: Thu, 08 May 2025 16:53:45 +0800 Subject: [PATCH v2 2/3] fs: fuse: add backing_files control file Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250508-fusectl-backing-files-v2-2-62f564e76984@uniontech.com> References: <20250508-fusectl-backing-files-v2-0-62f564e76984@uniontech.com> In-Reply-To: <20250508-fusectl-backing-files-v2-0-62f564e76984@uniontech.com> To: Miklos Szeredi Cc: Amir Goldstein , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Chen Linxuan X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=6076; i=chenlinxuan@uniontech.com; h=from:subject:message-id; bh=id6oT8a7yC3qd46gYMaegcNojko0bpH3Ayxh7JPrSGg=; b=owEBbQKS/ZANAwAKAXYe5hQ5ma6LAcsmYgBoHHEt1CnQi/e7pwJqkt2cfNBt81LpsAuTZBz42 AhCXSVLg96JAjMEAAEKAB0WIQTO1VElAk6xdvy0ZVp2HuYUOZmuiwUCaBxxLQAKCRB2HuYUOZmu izp6D/oDY1tR3wOwTQg7lSqwVEOAwbsXdkPYA0b4xhU+k4ApVRChlwM/Ud1SnNgsxRGpI6sFu1w abACmc9gNArdAEt/1AcEEhWKdRMLQ2xS06V+++3vr8OSXzuUtLt0eCju5KxpfiEla56OmFVwuhq 1zKGzUxtpjvO31e2iLxG3zoyEyZKvBj4Od9sYP3gC+tgTTyCeeWJlvDn7SqnWnReL4SzT2m5txC VF07yYeefeb+ScTnMUrjSCFxyZYcxQJ+CIqRHGlZWizksDJFw6YxSKloXSYZfXkMJyKfGu7S6OL OyR8U9aUjtzme1RpkHd/q/Jnxyrkbdfpl5qhiX8J6uL7GXbu5oenkJ1yqIW/QePWz8Lt4CUvsc2 DSQEmjdLt9xSArjux2LMmCGCFXbhxPETDU7ivsTbPQ+NVwQbAB1X/RLmiS1WAfiZGjSt/wc1NG4 axFuGMpM0rwFtlYNgKu0WsJiOqexwwLZ1+zsM/MhxygLA1w78oH9GnXVtp13LSPxZ6YUZAFfrEy MapRw9SX6OmS+m3tJsdM8FM5RAK0IiiMdKtYDJefeEfr2EzFYgSAASiqd7g8FKR/LZ9Mfo4qldT ZqBVMH1E+9U2Jt3SaWD5tnlOZWVtno5Rl5vXAbMxM5wgRUjOVlnM7sufVI94ChQ6msnE/iD5LAq UaVvZNNEFOb8hIA== X-Developer-Key: i=chenlinxuan@uniontech.com; a=openpgp; fpr=D818ACDD385CAE92D4BAC01A6269794D24791D21 X-Endpoint-Received: by B4 Relay for chenlinxuan@uniontech.com/default with auth_id=380 X-Original-From: Chen Linxuan Reply-To: chenlinxuan@uniontech.com From: Chen Linxuan Add a new FUSE control file "/sys/fs/fuse/connections/*/backing_files" that exposes the paths of all backing files currently being used in FUSE mount points. This is particularly valuable for tracking and debugging files used in FUSE passthrough mode. This approach is similar to how fixed files in io_uring expose their status through fdinfo, providing administrators with visibility into backing file usage. By making backing files visible through the FUSE control filesystem, administrators can monitor which files are being used for passthrough operations and can force-close them if needed by aborting the connection. This exposure of backing files information is an important step towards potentially relaxing CAP_SYS_ADMIN requirements for certain passthrough operations in the future, allowing for better security analysis of passthrough usage patterns. The control file is implemented using the seq_file interface for efficient handling of potentially large numbers of backing files. Access permissions are set to read-only (0400) as this is an informational interface. FUSE_CTL_NUM_DENTRIES has been increased from 5 to 6 to accommodate the additional control file. Some related discussions can be found at links below. Link: https://lore.kernel.org/all/4b64a41c-6167-4c02-8bae-3021270ca519@fast= mail.fm/T/#mc73e04df56b8830b1d7b06b5d9f22e594fba423e Link: https://lore.kernel.org/linux-fsdevel/CAOQ4uxhAY1m7ubJ3p-A3rSufw_53Wu= DRMT1Zqe_OC0bP_Fb3Zw@mail.gmail.com/ Cc: Amir Goldstein Signed-off-by: Chen Linxuan --- fs/fuse/control.c | 136 ++++++++++++++++++++++++++++++++++++++++++++++++++= +++- fs/fuse/fuse_i.h | 2 +- 2 files changed, 136 insertions(+), 2 deletions(-) diff --git a/fs/fuse/control.c b/fs/fuse/control.c index f0874403b1f7c91571f38e4ae9f8cebe259f7dd1..d1ac934d7b8949577545ffd2053= 5c68a9c4ef90f 100644 --- a/fs/fuse/control.c +++ b/fs/fuse/control.c @@ -11,6 +11,7 @@ #include #include #include +#include =20 #define FUSE_CTL_SUPER_MAGIC 0x65735543 =20 @@ -180,6 +181,136 @@ static ssize_t fuse_conn_congestion_threshold_write(s= truct file *file, return ret; } =20 +struct fuse_backing_files_seq_state { + struct fuse_conn *fc; + int backing_id; +}; + +static void *fuse_backing_files_seq_start(struct seq_file *seq, loff_t *po= s) +{ + struct fuse_backing *fb; + struct fuse_backing_files_seq_state *state; + struct fuse_conn *fc; + int backing_id; + void *ret; + + if (*pos + 1 > INT_MAX) + return ERR_PTR(-EINVAL); + + backing_id =3D *pos + 1; + + fc =3D fuse_ctl_file_conn_get(seq->file); + if (!fc) + return ERR_PTR(-ENOTCONN); + + rcu_read_lock(); + + fb =3D idr_get_next(&fc->backing_files_map, &backing_id); + + rcu_read_unlock(); + + if (!fb) { + ret =3D NULL; + goto err; + } + + state =3D kmalloc(sizeof(*state), GFP_KERNEL); + if (!state) { + ret =3D ERR_PTR(-ENOMEM); + goto err; + } + + state->fc =3D fc; + state->backing_id =3D backing_id; + + ret =3D state; + return ret; + +err: + fuse_conn_put(fc); + return ret; +} + +static void *fuse_backing_files_seq_next(struct seq_file *seq, void *v, + loff_t *pos) +{ + struct fuse_backing_files_seq_state *state =3D v; + struct fuse_backing *fb; + + (*pos)++; + state->backing_id++; + + rcu_read_lock(); + + fb =3D idr_get_next(&state->fc->backing_files_map, &state->backing_id); + + rcu_read_unlock(); + + if (!fb) + return NULL; + + + return state; +} + +static int fuse_backing_files_seq_show(struct seq_file *seq, void *v) +{ + struct fuse_backing_files_seq_state *state =3D v; + struct fuse_conn *fc =3D state->fc; + struct fuse_backing *fb; + + rcu_read_lock(); + + fb =3D idr_find(&fc->backing_files_map, state->backing_id); + fb =3D fuse_backing_get(fb); + if (!fb) + goto out; + + if (!fb->file) + goto out_put_fb; + + seq_printf(seq, "%5u: ", state->backing_id); + seq_file_path(seq, fb->file, " \t\n\\"); + seq_puts(seq, "\n"); + +out_put_fb: + fuse_backing_put(fb); +out: + rcu_read_unlock(); + return 0; +} + +static void fuse_backing_files_seq_stop(struct seq_file *seq, void *v) +{ + struct fuse_backing_files_seq_state *state; + + if (!v) + return; + + state =3D v; + fuse_conn_put(state->fc); + kvfree(state); +} + +static const struct seq_operations fuse_backing_files_seq_ops =3D { + .start =3D fuse_backing_files_seq_start, + .next =3D fuse_backing_files_seq_next, + .stop =3D fuse_backing_files_seq_stop, + .show =3D fuse_backing_files_seq_show, +}; + +static int fuse_backing_files_seq_open(struct inode *inode, struct file *f= ile) +{ + return seq_open(file, &fuse_backing_files_seq_ops); +} + +static const struct file_operations fuse_conn_backing_files_ops =3D { + .open =3D fuse_backing_files_seq_open, + .read =3D seq_read, + .llseek =3D seq_lseek, + .release =3D seq_release, +}; + static const struct file_operations fuse_ctl_abort_ops =3D { .open =3D nonseekable_open, .write =3D fuse_conn_abort_write, @@ -270,7 +401,10 @@ int fuse_ctl_add_conn(struct fuse_conn *fc) 1, NULL, &fuse_conn_max_background_ops) || !fuse_ctl_add_dentry(parent, fc, "congestion_threshold", S_IFREG | 0600, 1, NULL, - &fuse_conn_congestion_threshold_ops)) + &fuse_conn_congestion_threshold_ops) || + !fuse_ctl_add_dentry(parent, fc, "backing_files", S_IFREG | 0400, 1, + NULL, + &fuse_conn_backing_files_ops)) goto err; =20 return 0; diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h index d56d4fd956db99ecd93052a9655428664882cb72..2830b05bb0928e9b30f9905d70f= c3ec1ef11c2a5 100644 --- a/fs/fuse/fuse_i.h +++ b/fs/fuse/fuse_i.h @@ -46,7 +46,7 @@ #define FUSE_NAME_MAX (PATH_MAX - 1) =20 /** Number of dentries for each connection in the control filesystem */ -#define FUSE_CTL_NUM_DENTRIES 5 +#define FUSE_CTL_NUM_DENTRIES 6 =20 /* Frequency (in seconds) of request timeout checks, if opted into */ #define FUSE_TIMEOUT_TIMER_FREQ 15 --=20 2.43.0 From nobody Sun Feb 8 10:30:08 2026 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 D8A44248191; Thu, 8 May 2025 08:54:14 +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=1746694454; cv=none; b=rl3kmL7gX+vxjjqLJMx1I6f5n5BPxVM5+9NegVK1c4lCwU2mf3Bkx/tA4ySFmXPo8nLVthUcTCSbsnWT+nZZRVIz1EjofPwQgbIEDo/1hUwQQjut3NUY0jcyt1ZLU2KOCPfmvj1DRY4yzaxt3VCpvAQUUhisYrymDo0E29Q79IE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746694454; c=relaxed/simple; bh=jjPID4iNZ9lsWFeGx9tgwL5daAD9QihLoIV1UwG3uHw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=GxCvd1R9c2Wt300gG0B5J+9ttf3hxH6CocC9u1BHb6dEES7uRN3RIqcEM3LxydkN/5bc6WGQhXfG83osz3xM/yOYv8/8M5q3OaAvFYgyRBxA3oXkIKC41GhLTw/UaSAopMGusc1W1wThEytzdo/2zE538FAe6+9pCh9pJyg0sY4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=IhmRAVO+; 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="IhmRAVO+" Received: by smtp.kernel.org (Postfix) with ESMTPS id 67757C4CEEF; Thu, 8 May 2025 08:54:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1746694454; bh=jjPID4iNZ9lsWFeGx9tgwL5daAD9QihLoIV1UwG3uHw=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=IhmRAVO+6nPeMGxI1wPK/u5sbsPtBPew71tY/49aGHqSPfU/HBj39abjdgOEJKSwl sKh8Ai9j1rCORd1ULKzL+7vm7JZsN4oG3SMV93+4Hz2TspafgWGYroT8A5GaoTVcWF xPVtVgG2sl4lLD0gGn1L7jjyQmECY8gAD5j6h4h1JyNzNzbWpOwNrwuDvAWdfbMErs gux6IO1F+eQsk5sPP3zprokL6TJitvkmf7CW9ySF6MKDfyvEbiyETyXV/FawX7wN+F GRHz13mLIbfcdvW1ykGR5osfxK3k4OKIfVtXHT7qUtfSwvM0PRxIZPwyCfYFDpmEp7 21HtWv4+id43g== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5D030C3ABC5; Thu, 8 May 2025 08:54:14 +0000 (UTC) From: Chen Linxuan via B4 Relay Date: Thu, 08 May 2025 16:53:46 +0800 Subject: [PATCH v2 3/3] fs: fuse: add more information to fdinfo Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250508-fusectl-backing-files-v2-3-62f564e76984@uniontech.com> References: <20250508-fusectl-backing-files-v2-0-62f564e76984@uniontech.com> In-Reply-To: <20250508-fusectl-backing-files-v2-0-62f564e76984@uniontech.com> To: Miklos Szeredi Cc: Amir Goldstein , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Chen Linxuan X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=2386; i=chenlinxuan@uniontech.com; h=from:subject:message-id; bh=0Usdqy+7Asx6fqMH6X+wT2PYlWAlDQn+W9qv/u/h9TY=; b=owEBbQKS/ZANAwAKAXYe5hQ5ma6LAcsmYgBoHHEuCjLMX1HS7YeEQWeIQNz8go3kor8PXgOov RAJI8eO2XKJAjMEAAEKAB0WIQTO1VElAk6xdvy0ZVp2HuYUOZmuiwUCaBxxLgAKCRB2HuYUOZmu i0zyD/9UEDcvVt5Xc06A8bhf2eIwwEUupq1sIcxxbaFoZPX7gZltpT9hefdEew6/RqyG3GQgzBk bICfKPwTw43zc+NDfiPsFT0nuxnXeCq3XPLWgFv9BLSUFF4wr1Yws89ErCvQAnhyAnCMBWfIN76 NH44o9vGv6BhWUh88IOIzwARwi+4NHGYEDZbz4RC0+oaF+y2I4qX134XiKGvrixDq9iK3kYR+hi kqjEVvcKGYK4HKusJGs2WrOIbUdl8XGTfjhdIsx/nJJg4+tP7GqNbNXVOvPhM1sHMGlRePTF0m5 8SqeHXrQ+FvnFcn6emtJRc7d0llydUETw37wgjpQOAbdyvzuwTeFkHIx7NYPEjYHcdTmzVjF9So 7rTSc3Dtj/Rh1jKPpR/idITbjTyH0P5FPlbXIK719IK2FLgu0O1rcfFy5tD+lFLi+cWF6MDFSdE jhAlHTuTXhVUcLA2qndYSrnv6JmiqkTNUfn49ZUS317QrWMo5tRD1yRho+7PIwLdWnrJxamO9CU nCrPB4FyLQAZi/D3VQ2XRpjzSN0fSFqxCowVRlVSV+f6sUOg95yeMkkCbfWXzH2bTIwuhxaEbpp 081h74V2r+BEJyQnDxNNnNoe30opiOehVLkUbmZb85RMiy6eyWbjzunfUfrRlnJgEl6jSan4RYY FVhMxwBmzFuGMbw== X-Developer-Key: i=chenlinxuan@uniontech.com; a=openpgp; fpr=D818ACDD385CAE92D4BAC01A6269794D24791D21 X-Endpoint-Received: by B4 Relay for chenlinxuan@uniontech.com/default with auth_id=380 X-Original-From: Chen Linxuan Reply-To: chenlinxuan@uniontech.com From: Chen Linxuan This commit add fuse connection device id and backing_id, if any, to fdinfo of opened fuse files. Related discussions can be found at links below. Link: https://lore.kernel.org/all/CAOQ4uxgS3OUy9tpphAJKCQFRAn2zTERXXa0QN_Kv= P6ZOe2KVBw@mail.gmail.com/ Cc: Amir Goldstein Signed-off-by: Chen Linxuan --- 1. I wonder if we should display fuse connection device id here. 2. I don't think using idr_for_each_entry is a good idea. But I failed to find another way to get backing_id of fuse_backing effectively. --- fs/fuse/file.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/fs/fuse/file.c b/fs/fuse/file.c index 754378dd9f7159f20fde6376962d45c4c706b868..5cfb806aa5cd22c57814168eb33= de77c6f213da0 100644 --- a/fs/fuse/file.c +++ b/fs/fuse/file.c @@ -8,6 +8,8 @@ =20 #include "fuse_i.h" =20 +#include "linux/idr.h" +#include "linux/rcupdate.h" #include #include #include @@ -3392,6 +3394,35 @@ static ssize_t fuse_copy_file_range(struct file *src= _file, loff_t src_off, return ret; } =20 +static void fuse_file_show_fdinfo(struct seq_file *m, struct file *f) +{ + struct fuse_file *ff =3D f->private_data; + struct fuse_conn *fc =3D ff->fm->fc; + struct fuse_inode *fi =3D get_fuse_inode(file_inode(f)); + + seq_printf(m, "fuse_conn:\t%u\n", fc->dev); + +#ifdef CONFIG_FUSE_PASSTHROUGH + struct fuse_backing *fb; + struct fuse_backing *backing; + int backing_id; + + if (ff->open_flags & FOPEN_PASSTHROUGH) { + fb =3D fuse_inode_backing(fi); + if (fb) { + rcu_read_lock(); + idr_for_each_entry(&fc->backing_files_map, backing, backing_id) { + if (backing =3D=3D fb) { + seq_printf(m, "fuse_backing_id:\t%d\n", backing_id); + break; + } + } + rcu_read_unlock(); + } + } +#endif +} + static const struct file_operations fuse_file_operations =3D { .llseek =3D fuse_file_llseek, .read_iter =3D fuse_file_read_iter, @@ -3411,6 +3442,9 @@ static const struct file_operations fuse_file_operati= ons =3D { .poll =3D fuse_file_poll, .fallocate =3D fuse_file_fallocate, .copy_file_range =3D fuse_copy_file_range, +#ifdef CONFIG_PROC_FS + .show_fdinfo =3D fuse_file_show_fdinfo, +#endif }; =20 static const struct address_space_operations fuse_file_aops =3D { --=20 2.43.0