From: "Richard Weinberger (sigma star gmbh)" <rw@kernel.org>
To: linux-mtd@lists.infradead.org
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>
Subject: [PATCH 04/10] fuse: Convert CUSE to the interface for userspace backed devices
Date: Mon, 30 Nov 2026 09:26:27 +0100 [thread overview]
Message-ID: <20261130082634.2750846-5-rw@kernel.org> (raw)
In-Reply-To: <20261130082634.2750846-1-rw@kernel.org>
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
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
next prev parent reply other threads:[~2026-11-30 8:27 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-30 8:26 [PATCH 0/10] MUSE: Userspace backed MTD v4 Richard Weinberger (sigma star gmbh)
2026-11-30 8:26 ` [PATCH 01/10] fuse: Share cuse_parse_one() as fuse_kv_parse_one() Richard Weinberger (sigma star gmbh)
2026-11-30 8:26 ` [PATCH 02/10] fuse: Add a public header for users outside of fs/fuse/ Richard Weinberger (sigma star gmbh)
2026-11-30 8:26 ` [PATCH 03/10] fuse: Add an interface for userspace backed devices Richard Weinberger (sigma star gmbh)
2026-11-30 8:26 ` Richard Weinberger (sigma star gmbh) [this message]
2026-11-30 8:26 ` [PATCH 05/10] fuse: Allow three output arguments per request Richard Weinberger (sigma star gmbh)
2026-11-30 8:26 ` [PATCH 06/10] fuse: Add MUSE specific defines to FUSE interface Richard Weinberger (sigma star gmbh)
2026-11-30 8:26 ` [PATCH 07/10] mtd: Add MTD_MUSE flag Richard Weinberger (sigma star gmbh)
2026-11-30 8:26 ` [PATCH 08/10] mtd: Allow passing a custom mtdparts string to the cmdline parser Richard Weinberger (sigma star gmbh)
2026-11-30 8:26 ` [PATCH 09/10] mtd: Implement MUSE - MTD in userspace Richard Weinberger (sigma star gmbh)
2026-11-30 8:26 ` [PATCH 10/10] MAINTAINERS: Add entry for MUSE Richard Weinberger (sigma star gmbh)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261130082634.2750846-5-rw@kernel.org \
--to=rw@kernel.org \
--cc=davem@davemloft.net \
--cc=david.oberhollenzer@sigma-star.at \
--cc=edumazet@google.com \
--cc=fuse-devel@lists.linux.dev \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-mtd@lists.infradead.org \
--cc=miklos@szeredi.hu \
--cc=miquel.raynal@bootlin.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=richard@nod.at \
--cc=upstream+linux@sigma-star.at \
--cc=vigneshr@ti.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox