Article View: linux.kernel.netdev
Article #24481[PATCH 04/10] fuse: Convert CUSE to the interface for userspace backed devices
From: "Richard Weinberger (sigma star ...
Date: Mon, 30 Nov 2026 08:26
Date: Mon, 30 Nov 2026 08:26
234 lines
15264 bytes
15264 bytes
From: Richard Weinberger <richard@nod.at>
CUSE embeds struct fuse_conn and struct fuse_mount in struct cuse_conn
and sets up the connection, its channel and its device on its own.
fuse_conn_new_dev() and fuse_conn_install_dev() do the very same.
Use them, and fuse_conn_from_file(), fuse_conn_send_bg() and
fuse_conn_abort() too. struct cuse_conn becomes the private data of the
connection and is freed by the release callback.
CUSE opens files on the dummy mount of its connection. Add
fuse_conn_dev_mount() for that, it is not part of <net/fuse.h>.
Signed-off-by: Richard Weinberger <richard@nod.at>
---
fs/fuse/cuse.c | 56 ++++++++++++++++++++++--------------------------
fs/fuse/fuse_i.h | 3 +++
fs/fuse/helper.c | 10 +++++++++
3 files changed, 39 insertions(+), 30 deletions(-)
diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
index 73512b26da10..c77cc85513e0 100644
--- a/fs/fuse/cuse.c
+++ b/fs/fuse/cuse.c
@@ -13,7 +13,7 @@
*
* A CUSE instance involves the following objects.
*
- * cuse_conn : contains fuse_conn and serves as bonding structure
+ * cuse_conn : private data of the fuse_conn, serves as bonding structure
* channel : file handle connected to the userland CUSE server
* cdev : the implemented character device
* dev : generic device for cdev
@@ -59,8 +59,7 @@
struct cuse_conn {
struct list_head list; /* linked on cuse_conntbl */
- struct fuse_mount fm; /* Dummy mount referencing fc */
- struct fuse_conn fc; /* fuse connection */
+ struct fuse_conn *fc; /* fuse connection */
struct cdev *cdev; /* associated character device */
struct device *dev; /* device representing @cdev */
@@ -74,7 +73,7 @@ static struct class *cuse_class;
static struct cuse_conn *fc_to_cc(struct fuse_conn *fc)
{
- return container_of(fc, struct cuse_conn, fc);
+ return fuse_conn_priv(fc);
}
static struct list_head *cuse_conntbl_head(dev_t devt)
@@ -123,7 +122,7 @@ static int cuse_open(struct inode *inode, struct file *file)
mutex_lock(&cuse_lock);
list_for_each_entry(pos, cuse_conntbl_head(devt), list)
if (pos->dev->devt == devt) {
- fuse_conn_get(&pos->fc);
+ fuse_conn_get(pos->fc);
cc = pos;
break;
}
@@ -137,9 +136,9 @@ static int cuse_open(struct inode *inode, struct file *file)
* Generic permission check is already done against the chrdev
* file, proceed to open.
*/
- rc = fuse_do_open(&cc->fm, 0, file, 0);
+ rc = fuse_do_open(fuse_conn_dev_mount(cc->fc), 0, file, 0);
if (rc)
- fuse_conn_put(&cc->fc);
+ fuse_conn_put(cc->fc);
return rc;
}
@@ -370,7 +369,7 @@ static void cuse_process_init_reply(struct fuse_args *args, int error)
err_region:
unregister_chrdev_region(devt, 1);
err:
- fuse_chan_abort(fc->chan, false);
+ fuse_conn_abort(fc);
goto out;
}
@@ -378,7 +377,6 @@ static int cuse_send_init(struct cuse_conn *cc)
{
int rc;
struct folio *folio;
- struct fuse_mount *fm = &cc->fm;
struct cuse_init_args *ia;
struct fuse_args_pages *ap;
@@ -413,10 +411,10 @@ static int cuse_send_init(struct cuse_conn *cc)
ap->descs = &ia->desc;
ia->folio = folio;
ia->desc.length = ap->args.out_args[1].size;
- ia->fc = &cc->fc;
+ ia->fc = cc->fc;
ap->args.end = cuse_process_init_reply;
- rc = fuse_simple_background(fm, &ap->args, GFP_KERNEL);
+ rc = fuse_conn_send_bg(cc->fc, &ap->args, GFP_KERNEL);
if (rc) {
kfree(ia);
err_free_folio:
@@ -426,9 +424,9 @@ static int cuse_send_init(struct cuse_conn *cc)
return rc;
}
-static void cuse_fc_release(struct fuse_conn *fc)
+static void cuse_conn_release(void *priv)
{
- kfree(fc_to_cc(fc));
+ kfree(priv);
}
/**
@@ -450,32 +448,31 @@ static int cuse_channel_open(struct inode *inode, struct file *file)
{
struct fuse_dev *fud;
struct cuse_conn *cc;
- struct fuse_chan *fch __free(fuse_chan_free) = fuse_dev_chan_new();
int rc;
- if (!fch)
- return -ENOMEM;
-
/* set up cuse_conn */
cc = kzalloc_obj(*cc);
if (!cc)
return -ENOMEM;
+ INIT_LIST_HEAD(&cc->list);
+
/*
* Limit the cuse channel to requests that can
* be represented in file->f_cred->user_ns.
*/
- fuse_conn_init(&cc->fc, &cc->fm, file->f_cred->user_ns, no_free_ptr(fch));
- cc->fc.release = cuse_fc_release;
- fud = fuse_dev_alloc_install(cc->fc.chan);
- fuse_conn_put(&cc->fc);
- if (!fud)
+ cc->fc = fuse_conn_new_dev(file->f_cred->user_ns, cuse_conn_release, cc);
+ if (!cc->fc) {
+ kfree(cc);
return -ENOMEM;
+ }
- INIT_LIST_HEAD(&cc->list);
+ /* From now on the channel holds the connection, and with it cc */
+ fud = fuse_conn_install_dev(cc->fc);
+ fuse_conn_put(cc->fc);
+ if (!fud)
+ return -ENOMEM;
- /* Pairs with smp_load_acquire() readers of fch->initialized */
- smp_store_release(&cc->fc.chan->initialized, 1);
rc = cuse_send_init(cc);
if (rc) {
fuse_dev_put(fud);
@@ -499,8 +496,7 @@ static int cuse_channel_open(struct inode *inode, struct file *file)
*/
static int cuse_channel_release(struct inode *inode, struct file *file)
{
- struct fuse_dev *fud = __fuse_get_dev(file);
- struct cuse_conn *cc = fc_to_cc(fud->chan->conn);
+ struct cuse_conn *cc = fc_to_cc(fuse_conn_from_file(file));
/* remove from the conntbl, no more access from this point on */
mutex_lock(&cuse_lock);
@@ -532,7 +528,7 @@ static ssize_t cuse_class_waiting_show(struct device *dev,
{
struct cuse_conn *cc = dev_get_drvdata(dev);
- return sprintf(buf, "%d\n", atomic_read(&cc->fc.chan->num_waiting));
+ return sprintf(buf, "%d\n", atomic_read(&cc->fc->chan->num_waiting));
}
static DEVICE_ATTR(waiting, 0400, cuse_class_waiting_show, NULL);
@@ -542,7 +538,7 @@ static ssize_t cuse_class_abort_store(struct device *dev,
{
struct cuse_conn *cc = dev_get_drvdata(dev);
- fuse_chan_abort(cc->fc.chan, false);
+ fuse_conn_abort(cc->fc);
return count;
}
static DEVICE_ATTR(abort, 0200, NULL, cuse_class_abort_store);
@@ -600,7 +596,7 @@ static void __exit cuse_exit(void)
class_destroy(cuse_class);
/*
* Wait for pending call_rcu() callbacks that call back into
- * this module via fc->release (cuse_fc_release).
+ * this module (cuse_conn_release).
*/
rcu_barrier();
}
diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h
index 8bceab59c1ca..a90ac46f1837 100644
--- a/fs/fuse/fuse_i.h
+++ b/fs/fuse/fuse_i.h
@@ -1117,6 +1117,9 @@ void fuse_dentry_set_epoch(struct dentry *dentry, u64 epoch);
void fuse_conn_init(struct fuse_conn *fc, struct fuse_mount *fm,
struct user_namespace *user_ns, struct fuse_chan *fch);
+/* The dummy mount of a connection made by fuse_conn_new_dev() */
+struct fuse_mount *fuse_conn_dev_mount(struct fuse_conn *fc);
+
int fuse_send_init(struct fuse_mount *fm);
/**
diff --git a/fs/fuse/helper.c b/fs/fuse/helper.c
index 5266c4e47eeb..1e389b4f5df9 100644
--- a/fs/fuse/helper.c
+++ b/fs/fuse/helper.c
@@ -93,6 +93,16 @@ void *fuse_conn_priv(struct fuse_conn *fc)
}
EXPORT_SYMBOL_GPL(fuse_conn_priv);
+/*
+ * For CUSE, which opens files on the dummy mount of its connection. Not part
+ * of the interface for users outside of fs/fuse/.
+ */
+struct fuse_mount *fuse_conn_dev_mount(struct fuse_conn *fc)
+{
+ return &to_dev_conn(fc)->fm;
+}
+EXPORT_SYMBOL_GPL(fuse_conn_dev_mount);
+
/**
* fuse_conn_install_dev - attach a connection to its control device
* @fc: connection created by fuse_conn_new_dev()
--
2.55.0
Technical Details
Message-ID:
<20261130082634.2750846-5-rw@kernel.org>Path:
mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!2.eu.feeder.erje.net!feeder.erje.net!feeder1.feed.ams11.usenet.farm!feed.usenet.farm!peer01.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!feeder.usenetexpress.com!tr3.eu1.usenetexpress.com!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-374011-linux-kernel-netdev=dewy.ruReferences:
<20261130082634.2750846-1-rw@kernel.org>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!2.eu.feeder.erje.net!feeder.erje.net!feeder1.feed.ams11.usenet.farm!feed.usenet.farm!peer01.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!feeder.usenetexpress.com!tr3.eu1.usenetexpress.com!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-374011-linux-kernel-netdev=dewy.ru
From: rw@kernel.org ("Richard Weinberger (sigma star gmbh)")
Newsgroups: linux.kernel.netdev
Subject: [PATCH 04/10] fuse: Convert CUSE to the interface for userspace backed devices
Date: Mon, 30 Nov 2026 09:26:27 +0100
Organization: Usenet Network
Message-ID: <20261130082634.2750846-5-rw@kernel.org>
References: <20261130082634.2750846-1-rw@kernel.org>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network; logging-data="1376024"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:09i6BzvLITadhHC6vBpLz4viIfM= sha256:HWdu8iEXG6dMm/f1z2NFG4AFGattf4WGiG28cfPv/eg= sha1:ZsX+Die6Wpj/s+qFMt0ehGp8v9c= sha256:q0c3P+hncW1UKrBrj7KyX5yOuLK7z7J3khLzcr5cfgs=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1]) by mail.dewy.ru (Postfix) with ESMTP id A6040125FCE; Mon, 30 Nov 2026 11:27:18 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.401
X-Spam-Status: No, score=-3.401 tagged_above=-9999 required=6.31 tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key) header.d=kernel.org
X-Received: from mail.dewy.ru ([127.0.0.1]) by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id S-e2Gy0ZaTDx; Mon, 30 Nov 2026 11:27:15 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-374011-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN>
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10]) by mail.dewy.ru (Postfix) with ESMTPS id 97EC8125FCD; Mon, 30 Nov 2026 11:27:07 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sea.lore.kernel.org (Postfix) with ESMTP id EA56E25F92; Mon, 30 Nov 2026 08:27:05 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796027225; b=mUZ18KQ868IHJHcQigbTUshKo040tBl6HB5gcERzQZxmg32AzUlr7vm/MM9IjmSK7RYL lvyS+U0Vzm8Q9POGj7Vg6jeMrcq9P3D2Hh1I1qqhknkwIyXbRhKltKah2/uo+GplaIx4x 4NOPYnvM5vdBRXXTCZ9hrO+G6+xXCe1ZwY6lQpSJAHvUZiGW7ZmBG+L26QPQ//pSZNpXo +Ec+51RTNbUVwolg4dbRlTgqcGlNy3PRTGHffSlruDFnf1Q/Yv2TxM/cvhJzj3Osk3hpH 7U+mAowj6waJ8A1q5bDQGczDzZw4DbmBNH6BeiSkZzo5FVD+yhJqXIKznDQHoRuEkKA==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796027225; h=X-Original-To:Received:Received:DKIM-Signature:From:To:Cc:Subject: Date:Message-ID:X-Mailer:In-Reply-To:References:X-Mailing-List: List-Id:List-Post:List-Help:List-Subscribe:List-Unsubscribe: List-Owner:Precedence:MIME-Version:Content-Transfer-Encoding; bh=dcicYtM4CXREuCjSkCy3tm2qMSQgS8afAavJazwGu+Q=; b=P2qbc7QNF6JQLHMxY8tjP/sdUI0sS7xmhIaDJnGAsWI5fyLAYSdREhoOX125rFSllTi3 Yba6y5z1KsYVNKTqAE8r/+8fanGOLaVUrIG981o3dHUclg0dx9aiXbaFr2eiD+cSyR7C4 6XqxyuI/RpeSSZx2yzmKxiYHu1fBzE6a8cdLTGuPruiweRilXu68hjK5p+/PRLS+WNwBH HTIDUHlJPiFe6Fv7Q1Tpt3iZiNwBTOU1GijAC+ERTg3dlYk1D0akN/WTPESDqRoykLrKt fHIiSDLhUXXORXOuYyoPLTw/8TaPoQEEZEyMFHRrV/gOfdRhQE1pRQDd3jzJaKyn0tQ==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=JpT2fOok; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C2719606A32F; Mon, 30 Nov 2026 08:27:05 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=JpT2fOok
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796027225; b=YJ3/vfxO3kBSJ+SelptqoXYDItEHJ4bzfjLuXNZo0OQNBMTS00gm2t6DcIHJ57whjaNV U9131Fci8hNlRRfVsnb1ICUdMNrXtftsPA6+NXN6KE3MREInTyHThRNF8uUi9T3/VtOen uo59FW+hJvp3eDD8ywqmFjbjneT2/LijtZ83TePAs1UH1asNoAJY//U5I7R/Vk/xCnAdQ T6bpGEN0ZyBySBv7bH18Wl/lzRpYUurAYc0Jhl5/qBoL2GROXUwCoq/UGFuUvPVWFK95C 80nvmj0w9Lcm+nrSMKXp92EkqbGH/LoRo2R38AV/nb5jY1VtmHJTr7GOWuNGGvJyEdg==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796027225; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=dcicYtM4CXREuCjSkCy3tm2qMSQgS8afAavJazwGu+Q=; b=HJDc5oood0S09VXIyYbCZaw8zu/J/IDfJsTRy30SJQ/wJ7O3+OoMF0jTg7rEAE3GKGvA oIF0erSmO9/m7sGMTi4IaUl95J3JvFlTWZl8BoN37CmK72LSheP924s0ngELtaFTZhcdM fI3rcXALMsaLrUU5bxryT3srvY+xolY2tTnRH1fUnWw+6Rr/3e3D20kUPZAIRiRpbiJwI dpwZklhxZ2rLo9XRuwfr1deDsL4Hij0WdgV8APUjd9NwhKRIHmstGSot66ldMzVgY3X0c neilGMUsVQzho0oeQcwPajAbvzn89flFbMOcakbFWn8A4WvmKsYxBOT2hXg1G/Asmkg==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=JpT2fOok; arc=none smtp.remote-ip=100.103.45.18
X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E22DF606A31C; Mon, 30 Nov 2026 08:27:04 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0544B1F000C1; Mon, 30 Nov 2026 08:26:59 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796027224; bh=dcicYtM4CXREuCjSkCy3tm2qMSQgS8afAavJazwGu+Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=JpT2fOokwGzKC+vMwbSsengWLu+KrOdsatZo7niaBch3lmIZs5Q9FCKr1EQ9JAQNU JOTBd9AgigXKviwyrHUsD/3L3hXZuBs/JTLBD5b0bKaLzr9fW3A8yachrUfLokqxFp 79Egzd1dWF/ObC3rg+To9ocSkCC18FQQbQ6x4F10dTAktwwEocrbV7Y142DmQQGK3K JocLy09TRCdqsZtzjuBeJNDhTANclTXe3/YO8C2QWaEk5zbUA5beqFj9RBTjhk25BW 3zGPbbNq8kCo3PhLVwXMmnLP9X4bVNEYAJIflzhjSQEqaRvVVkAOfEon8avwowGdQG tTscjDybSqa7g==
X-Cc: fuse-devel@lists.linux.dev, netdev@vger.kernel.org, horms@kernel.org, pabeni@redhat.com, kuba@kernel.org, edumazet@google.com, davem@davemloft.net, miklos@szeredi.hu, vigneshr@ti.com, miquel.raynal@bootlin.com, david.oberhollenzer@sigma-star.at, upstream+linux@sigma-star.at, Richard Weinberger <richard@nod.at>
X-Mailer: git-send-email 2.55.0
X-In-Reply-To: <20261130082634.2750846-1-rw@kernel.org>
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list
X-Received-Bytes: 15005