Article View: linux.kernel.netdev
Article #24480[PATCH 03/10] fuse: Add an interface for userspace backed devices
From: "Richard Weinberger (sigma star ...
Date: Mon, 30 Nov 2026 08:26
Date: Mon, 30 Nov 2026 08:26
244 lines
15597 bytes
15597 bytes
From: Richard Weinberger <richard@nod.at>
CUSE embeds struct fuse_conn and struct fuse_mount and therefore has to
live next to the FUSE core. A driver outside of fs/fuse/ shall not see
these structures.
Add a small interface on top of the opaque struct fuse_conn:
fuse_conn_new_dev() allocates a connection together with its dummy
mount and its channel, and takes a release callback and a private
pointer of the caller.
fuse_conn_priv() returns that private pointer.
fuse_conn_install_dev() attaches the connection to the just opened
control device and makes it accept requests.
fuse_conn_from_file() returns the connection of an open control device.
fuse_conn_send() and fuse_conn_send_bg() send a request, like
fuse_simple_request() and fuse_simple_background() do.
fuse_conn_abort() aborts the connection.
Signed-off-by: Richard Weinberger <richard@nod.at>
---
fs/fuse/helper.c | 161 ++++++++++++++++++++++++++++++++++++++++++++-
include/net/fuse.h | 17 ++++-
2 files changed, 175 insertions(+), 3 deletions(-)
diff --git a/fs/fuse/helper.c b/fs/fuse/helper.c
index 29db362d930c..5266c4e47eeb 100644
--- a/fs/fuse/helper.c
+++ b/fs/fuse/helper.c
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: GPL-2.0-only
/*
- * Helper functions used by CUSE and MUSE
+ * Helper functions used by userspace backed devices like CUSE and MUSE
*
* Copyright (C) 2008-2009 SUSE Linux Products GmbH
* Copyright (C) 2008-2009 Tejun Heo <tj@kernel.org>
@@ -11,9 +11,168 @@
#include <linux/export.h>
#include <linux/printk.h>
+#include <linux/slab.h>
#include <linux/string.h>
+#include "dev.h"
#include "fuse_i.h"
+#include "fuse_dev_i.h"
+
+/*
+ * A connection which does not belong to a filesystem but to a device which
+ * is implemented by a userspace server. The device driver sees only an
+ * opaque struct fuse_conn, see <net/fuse.h>.
+ */
+struct fuse_dev_conn {
+ struct fuse_conn fc;
+ struct fuse_mount fm; /* Dummy mount referencing fc */
+ void (*release)(void *priv);
+ void *priv;
+};
+
+static struct fuse_dev_conn *to_dev_conn(struct fuse_conn *fc)
+{
+ return container_of(fc, struct fuse_dev_conn, fc);
+}
+
+static void fuse_dev_conn_release(struct fuse_conn *fc)
+{
+ struct fuse_dev_conn *dc = to_dev_conn(fc);
+
+ if (dc->release)
+ dc->release(dc->priv);
+ kfree(dc);
+}
+
+/**
+ * fuse_conn_new_dev - create a connection for a userspace backed device
+ * @user_ns: user namespace of the connection
+ * @release: called when the last reference to the connection is dropped,
+ * can be NULL
+ * @priv: private data of the caller, see fuse_conn_priv()
+ *
+ * The caller owns the returned reference and drops it with fuse_conn_put().
+ * @release is called from an RCU callback. A module which passes one has to
+ * call rcu_barrier() before it goes away.
+ *
+ * RETURNS:
+ * The new connection or NULL if out of memory.
+ */
+struct fuse_conn *fuse_conn_new_dev(struct user_namespace *user_ns,
+ void (*release)(void *priv), void *priv)
+{
+ struct fuse_chan *fch __free(fuse_chan_free) = fuse_dev_chan_new();
+ struct fuse_dev_conn *dc;
+
+ if (!fch)
+ return NULL;
+
+ dc = kzalloc_obj(*dc);
+ if (!dc)
+ return NULL;
+
+ fuse_conn_init(&dc->fc, &dc->fm, user_ns, no_free_ptr(fch));
+ dc->fc.release = fuse_dev_conn_release;
+ dc->release = release;
+ dc->priv = priv;
+
+ return &dc->fc;
+}
+EXPORT_SYMBOL_GPL(fuse_conn_new_dev);
+
+/**
+ * fuse_conn_priv - private data of a connection
+ * @fc: connection created by fuse_conn_new_dev()
+ *
+ * RETURNS:
+ * The @priv pointer passed to fuse_conn_new_dev().
+ */
+void *fuse_conn_priv(struct fuse_conn *fc)
+{
+ return to_dev_conn(fc)->priv;
+}
+EXPORT_SYMBOL_GPL(fuse_conn_priv);
+
+/**
+ * fuse_conn_install_dev - attach a connection to its control device
+ * @fc: connection created by fuse_conn_new_dev()
+ *
+ * To be called from the open method of the control device. On success the
+ * connection accepts requests. Store the result in file->private_data,
+ * fuse_dev_operations and fuse_dev_release() take it from there. If open
+ * fails later, drop it with fuse_dev_put().
+ *
+ * RETURNS:
+ * The FUSE device or NULL if out of memory.
+ */
+struct fuse_dev *fuse_conn_install_dev(struct fuse_conn *fc)
+{
+ struct fuse_dev *fud;
+
+ fud = fuse_dev_alloc_install(fc->chan);
+ if (!fud)
+ return NULL;
+
+ /* Pairs with smp_load_acquire() readers of fch->initialized */
+ smp_store_release(&fc->chan->initialized, 1);
+
+ return fud;
+}
+EXPORT_SYMBOL_GPL(fuse_conn_install_dev);
+
+/**
+ * fuse_conn_from_file - connection of an open control device
+ * @file: file with the result of fuse_conn_install_dev() as private data
+ *
+ * RETURNS:
+ * The connection, valid until fuse_dev_release() got called for @file.
+ */
+struct fuse_conn *fuse_conn_from_file(struct file *file)
+{
+ return fuse_dev_chan_get(fuse_file_to_fud(file))->conn;
+}
+EXPORT_SYMBOL_GPL(fuse_conn_from_file);
+
+/**
+ * fuse_conn_send - send a request and wait for the reply
+ * @fc: connection created by fuse_conn_new_dev()
+ * @args: the request
+ *
+ * RETURNS:
+ * A negative error code if the request failed. Otherwise 0, or the size of
+ * the last output argument if @args->out_argvar is set.
+ */
+ssize_t fuse_conn_send(struct fuse_conn *fc, struct fuse_args *args)
+{
+ return fuse_simple_request(&to_dev_conn(fc)->fm, args);
+}
+EXPORT_SYMBOL_GPL(fuse_conn_send);
+
+/**
+ * fuse_conn_send_bg - send a request without waiting for the reply
+ * @fc: connection created by fuse_conn_new_dev()
+ * @args: the request, @args->end is called when it is done
+ * @gfp_flags: allocation flags
+ *
+ * RETURNS:
+ * 0 if the request got queued, -errno otherwise.
+ */
+int fuse_conn_send_bg(struct fuse_conn *fc, struct fuse_args *args,
+ gfp_t gfp_flags)
+{
+ return fuse_simple_background(&to_dev_conn(fc)->fm, args, gfp_flags);
+}
+EXPORT_SYMBOL_GPL(fuse_conn_send_bg);
+
+/**
+ * fuse_conn_abort - abort all requests and refuse new ones
+ * @fc: connection created by fuse_conn_new_dev()
+ */
+void fuse_conn_abort(struct fuse_conn *fc)
+{
+ fuse_chan_abort(fc->chan, false);
+}
+EXPORT_SYMBOL_GPL(fuse_conn_abort);
/**
* fuse_kv_parse_one - parse one key=value pair
diff --git a/include/net/fuse.h b/include/net/fuse.h
index 206193f4653a..30155f2ed17c 100644
--- a/include/net/fuse.h
+++ b/include/net/fuse.h
@@ -3,7 +3,10 @@
* FUSE transport interface for users outside of fs/fuse/.
*
* This is the bare minimum a driver needs to implement a device which is
- * backed by a userspace server.
+ * backed by a userspace server, like MUSE does for MTD. Such a driver owns a
+ * control device (a clone of fuse_dev_operations). Every open of it creates
+ * a FUSE connection the driver uses to send requests to the server which
+ * opened the control device.
*/
#ifndef _NET_FUSE_H
@@ -79,7 +82,17 @@ struct fuse_conn *fuse_conn_get(struct fuse_conn *fc);
*/
void fuse_conn_put(struct fuse_conn *fc);
-/* Helpers for userspace backed devices, see fs/fuse/helper.c */
+/* Connections of userspace backed devices, see fs/fuse/helper.c */
+struct fuse_conn *fuse_conn_new_dev(struct user_namespace *user_ns,
+ void (*release)(void *priv), void *priv);
+void *fuse_conn_priv(struct fuse_conn *fc);
+struct fuse_dev *fuse_conn_install_dev(struct fuse_conn *fc);
+struct fuse_conn *fuse_conn_from_file(struct file *file);
+ssize_t fuse_conn_send(struct fuse_conn *fc, struct fuse_args *args);
+int fuse_conn_send_bg(struct fuse_conn *fc, struct fuse_args *args,
+ gfp_t gfp_flags);
+void fuse_conn_abort(struct fuse_conn *fc);
+
int fuse_kv_parse_one(char **pp, char *end, char **keyp, char **valp);
#endif /* _NET_FUSE_H */
--
2.55.0
Technical Details
Message-ID:
<20261130082634.2750846-4-rw@kernel.org>Path:
mbox-mo1.pugleaf.net!news-can.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-374010-linux-kernel-netdev=dewy.ruReferences:
<20261130082634.2750846-1-rw@kernel.org>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-can.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-374010-linux-kernel-netdev=dewy.ru
From: rw@kernel.org ("Richard Weinberger (sigma star gmbh)")
Newsgroups: linux.kernel.netdev
Subject: [PATCH 03/10] fuse: Add an interface for userspace backed devices
Date: Mon, 30 Nov 2026 09:26:26 +0100
Organization: Usenet Network
Message-ID: <20261130082634.2750846-4-rw@kernel.org>
References: <20261130082634.2750846-1-rw@kernel.org>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
logging-data="1375970"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:dvshjLSgundFuQGaZhjVsbuLcsw= sha256:5g39LK0IPzWrimDhO2lCYL+SNdWncOj5oHLhYa7Y8ho=
sha1:uC45AdZBMSfig41ugmHWPpOGfH4= sha256:WsrwUdU/GlxDWgFZk3gkttzP2aGL8aHETdJJKMz8QlM=
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 17294125FCF; Mon, 30 Nov 2026 11:27:14 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.501
X-Spam-Status: No, score=-3.501 tagged_above=-9999 required=6.31
tests=[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 IpC7dREOGeUS;
Mon, 30 Nov 2026 11:27:11 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-374010-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 tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114])
by mail.dewy.ru (Postfix) with ESMTPS id E2121125FCE; Mon, 30 Nov 2026 11:27:02 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
by tor.lore.kernel.org (Postfix) with ESMTP id F389B250AF; Mon, 30 Nov 2026 08:27:00 +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=1796027220;
b=jrFrHd+SBTUwZw9fquBKq07rWqdCVtd1ztK8szULSytr7HkYb49NP4VxBVGyOHES5M51
F7znIw2ycKFyxzJnTW4tWXtARBiE0aFldAUlPEDxSWWkhEeY66W+aEB76VAbu2tUv+lld
nDx0j7VcsS6WJ3zW+G7pgLnX+ioaE0JMVfDYrhKcfYDPcbi8Fpg6Fz3HOh/Vrl+adXY7U
bu3jVwuSLXz3zqcNOWrgB3anTvi7F/cVvT2i0myfuDGccHhMlpUdd9m1UVXYXP/FBEtUd
CQd0SVeHGNX6iQGbP40swBtyzqK5OuaOi1aXxNNQxL7/VW1CG0wV7N/wOoyR5ovpYFA==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1796027220;
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=xNZ44ZPXdkwQ8xHbnjGYf7jhbaJ4uaEgaQHmUjSk00M=;
b=WdaLnuSR+LG5UNNqQz5pgd0qIWI/o+wQHrRh20i3upw5HXKzdJYvcasqwtr7NQsUgLsq
IKe5glMk3Y/HZVlWFECejzVjc8hiJ57leKeBTIpMUXWHsOXd+3+YqTdAFDEpbmg9b9AtZ
aOUREkPfhDcL2/09a1J0E4xgvklDCH5K9uvlrd8nldGNKL3WyA79961UKT8qBUJMtpyUE
8MRhwwviBDoWkOFJLZK8aRq8JFB3FncdIX8ZQRA70OZgV07BATSmdhDM7I+07xFXYvE+7
wRq2JaBMkKnqU6OREQ9KW6xo3/upaJGzZKuqtFkyHy6zkad6/hv7KJhK6SAguizSF2w==
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=At2F3z97;
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 ACEBA606A32E;
Mon, 30 Nov 2026 08:27:00 +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=At2F3z97
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=1796027219;
b=vAf+skzYqc7fdqYH7awHphsjlHHNW64azxamZg2Q15sTKsfEkUkD913bkKn05poIifsz
E82P3H9xJAa4VwbKzDOkivfqSl6Z2Trnv9LQkMkE4SHAJgvce2H6W6Gq7HalUL0vdPeuN
vSBUuMEKsxIOb7VSAjngqLjnFsgt/zBXWS4dPi8Xwl4x97AQwZudoTsXH6vxK67jCbvNN
bQfIFjbjr4sheKo+Wdghxjcc2o7c/etPG0MGCguyFGkrHyA9d+jPS9O4BqWAP+fj0agpt
xAJyqv2XKwCQBEMG+RwI1C7oHmIJSppt/INicFfBSB2g1yu4kfIvh78w4VxdaIS2JlA==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1796027219;
h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer:
In-Reply-To:References:MIME-Version:Content-Transfer-Encoding;
bh=xNZ44ZPXdkwQ8xHbnjGYf7jhbaJ4uaEgaQHmUjSk00M=;
b=vqt1Nw3F1+7HJ/H70v9wvnRqCeZ3Dr3qdkuwqrwIUWFQ+oaBuzk74+xjytsZhSodHZtj
TrG8dJSebpu+nHG+pv9nJxGsy6T0+rF9Kysm/wRsAzINTTBSlR+p7R7/EYzKxSHRSCCOO
8x/zwPZ9w7cvPjq2XotXbbxVcGk+DGD7M6s1Lv8byLbiYkPUquwEoTdeA8FDNoWGNM2h0
VWNr3HVohXJOkE7YlW6SqSkRGmuuAwGmZIYP3Wp1GCpWNdvZBXBqWIeuE2YHigAPqsWOm
c0A8+VKAZS6u3QmYFXF55frwEQD9xhV1LECeUcb/VdZLe2HZnc+KEt3CyVcfEgwSnwA==
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=At2F3z97;
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 CCA5D606A320;
Mon, 30 Nov 2026 08:26:59 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id C2A051F00896;
Mon, 30 Nov 2026 08:26:54 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
s=k20260515; t=1796027218;
bh=xNZ44ZPXdkwQ8xHbnjGYf7jhbaJ4uaEgaQHmUjSk00M=;
h=From:To:Cc:Subject:Date:In-Reply-To:References;
b=At2F3z973VxUI6QxQFMoqXTi/eS3vytH1eEPlCB3qNl/KYvcM1DnS0B37wAvEbXvl
d54w4MJRHGjvPwo/k1vl+YAvi3t3+wFBgVaWLCcDNRIPGoC55BrIQMZZyRsyfgA2qf
KDdQPsrkzrvG9oi3HKluSvYfU3QNDOq398c7uQ9F5aTHO8kkN+O5w2w31WbmpDOGr7
Pb2ml2lmdCZqLAlHcBCkeQ80q1aaRiRK4pXP9otloHnFnIId+ZNk51Fk75/imcbpYs
oPzU98GBV6ySOUP4G5evIch1eK7ucXUHNSEe7jgtEVGkxcByE/dOKecNFintfxjumZ
EV+dSsumKGbsA==
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