public inbox for linux-fsdevel@vger.kernel.org
 help / color / mirror / Atom feed
From: Jonathan Cameron <jonathan.cameron@huawei.com>
To: John Groves <John@Groves.net>
Cc: Miklos Szeredi <miklos@szeredi.hu>,
	Dan Williams <dan.j.williams@intel.com>,
	Bernd Schubert <bschubert@ddn.com>,
	"Alison Schofield" <alison.schofield@intel.com>,
	John Groves <jgroves@micron.com>,
	Jonathan Corbet <corbet@lwn.net>,
	Vishal Verma <vishal.l.verma@intel.com>,
	Dave Jiang <dave.jiang@intel.com>,
	Matthew Wilcox <willy@infradead.org>, Jan Kara <jack@suse.cz>,
	Alexander Viro <viro@zeniv.linux.org.uk>,
	"David Hildenbrand" <david@kernel.org>,
	Christian Brauner <brauner@kernel.org>,
	"Darrick J . Wong" <djwong@kernel.org>,
	Randy Dunlap <rdunlap@infradead.org>,
	Jeff Layton <jlayton@kernel.org>,
	Amir Goldstein <amir73il@gmail.com>,
	Stefan Hajnoczi <shajnocz@redhat.com>,
	Joanne Koong <joannelkoong@gmail.com>,
	Josef Bacik <josef@toxicpanda.com>,
	Bagas Sanjaya <bagasdotme@gmail.com>,
	Chen Linxuan <chenlinxuan@uniontech.com>,
	"James Morse" <james.morse@arm.com>,
	Fuad Tabba <tabba@google.com>,
	"Sean Christopherson" <seanjc@google.com>,
	Shivank Garg <shivankg@amd.com>,
	Ackerley Tng <ackerleytng@google.com>,
	Gregory Price <gourry@gourry.net>,
	Aravind Ramesh <arramesh@micron.com>,
	Ajay Joshi <ajayjoshi@micron.com>, <venkataravis@micron.com>,
	<linux-doc@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	<nvdimm@lists.linux.dev>, <linux-cxl@vger.kernel.org>,
	<linux-fsdevel@vger.kernel.org>
Subject: Re: [PATCH V3 16/21] famfs_fuse: GET_DAXDEV message and daxdev_table
Date: Thu, 8 Jan 2026 14:45:02 +0000	[thread overview]
Message-ID: <20260108144502.000024e0@huawei.com> (raw)
In-Reply-To: <20260107153332.64727-17-john@groves.net>

On Wed,  7 Jan 2026 09:33:25 -0600
John Groves <John@Groves.net> wrote:

> * The new GET_DAXDEV message/response is added
> * The famfs.c:famfs_teardown() function is added as a primary teardown
>   function for famfs.
> * The command it triggered by the update_daxdev_table() call, if there
>   are any daxdevs in the subject fmap that are not represented in the
>   daxdev_table yet.
> * fs/namei.c: export may_open_dev()
> 
> Signed-off-by: John Groves <john@groves.net>
Hi John,

A few things inline

Thanks,

Jonathan

> ---
>  fs/fuse/famfs.c           | 236 ++++++++++++++++++++++++++++++++++++++
>  fs/fuse/famfs_kfmap.h     |  26 +++++
>  fs/fuse/fuse_i.h          |  13 ++-
>  fs/fuse/inode.c           |   4 +-
>  fs/namei.c                |   1 +
>  include/uapi/linux/fuse.h |  20 ++++
>  6 files changed, 298 insertions(+), 2 deletions(-)
> 
> diff --git a/fs/fuse/famfs.c b/fs/fuse/famfs.c
> index 2aabd1d589fd..b5cd1b5c1d6c 100644
> --- a/fs/fuse/famfs.c
> +++ b/fs/fuse/famfs.c
> @@ -20,6 +20,239 @@
>  #include "famfs_kfmap.h"
>  #include "fuse_i.h"
>  
> +/*
> + * famfs_teardown()
> + *
> + * Deallocate famfs metadata for a fuse_conn
> + */
> +void
> +famfs_teardown(struct fuse_conn *fc)
> +{
> +	struct famfs_dax_devlist *devlist = fc->dax_devlist;
> +	int i;
> +
> +	kfree(fc->shadow);
> +
> +	fc->dax_devlist = NULL;
> +
> +	if (!devlist)
> +		return;
> +
> +	if (!devlist->devlist)

I'm going to assume that if this is true, devlist->nslots == 0?
If so I'd skip this check and just let the rest of the code happen.

> +		goto out;
> +
> +	/* Close & release all the daxdevs in our table */
> +	for (i = 0; i < devlist->nslots; i++) {
> +		struct famfs_daxdev *dd = &devlist->devlist[i];
> +
> +		if (!dd->valid)
> +			continue;
> +
> +		/* Release reference from dax_dev_get() */
> +		if (dd->devp)
> +			put_dax(dd->devp);
> +
> +		kfree(dd->name);
> +	}
> +	kfree(devlist->devlist);
> +
> +out:
> +	kfree(devlist);
> +}

> +/**
> + * famfs_fuse_get_daxdev() - Retrieve info for a DAX device from fuse server
> + *
> + * Send a GET_DAXDEV message to the fuse server to retrieve info on a
> + * dax device.
> + *
> + * @fm:     fuse_mount
> + * @index:  the index of the dax device; daxdevs are referred to by index
> + *          in fmaps, and the server resolves the index to a particular daxdev
> + *
> + * Returns: 0=success
> + *          -errno=failure
> + */
> +static int
> +famfs_fuse_get_daxdev(struct fuse_mount *fm, const u64 index)
> +{
> +	struct fuse_daxdev_out daxdev_out = { 0 };
> +	struct fuse_conn *fc = fm->fc;
> +	struct famfs_daxdev *daxdev;
> +	int err = 0;
Always set before use so no need to init.

> +
> +	FUSE_ARGS(args);
> +
> +	/* Store the daxdev in our table */
> +	if (index >= fc->dax_devlist->nslots) {
> +		pr_err("%s: index(%lld) > nslots(%d)\n",
> +		       __func__, index, fc->dax_devlist->nslots);
> +		err = -EINVAL;
> +		goto out;

I'd return here as nothing to do.

> +	}
> +
> +	args.opcode = FUSE_GET_DAXDEV;
> +	args.nodeid = index;
> +
> +	args.in_numargs = 0;
> +
> +	args.out_numargs = 1;
> +	args.out_args[0].size = sizeof(daxdev_out);
> +	args.out_args[0].value = &daxdev_out;
> +
> +	/* Send GET_DAXDEV command */
> +	err = fuse_simple_request(fm, &args);
> +	if (err) {
> +		pr_err("%s: err=%d from fuse_simple_request()\n",
> +		       __func__, err);
> +		/*

I'm not sure what local comment style is, but be consistent of
whether there is a blank line or not.

> +		 * Error will be that the payload is smaller than FMAP_BUFSIZE,
> +		 * which is the max we can handle. Empty payload handled below.
> +		 */
> +		goto out;
return here is probably simpler.

> +	}
> +
> +	down_write(&fc->famfs_devlist_sem);
> +
> +	daxdev = &fc->dax_devlist->devlist[index];
> +
> +	/* Abort if daxdev is now valid (race - another thread got it first) */
> +	if (daxdev->valid) {
> +		up_write(&fc->famfs_devlist_sem);
> +		/* We already have a valid entry at this index */
> +		pr_debug("%s: daxdev already known\n", __func__);
> +		goto out;
> +	}
> +
> +	/* Verify that the dev is valid and can be opened and gets the devno */
> +	err = famfs_verify_daxdev(daxdev_out.name, &daxdev->devno);
> +	if (err) {
> +		up_write(&fc->famfs_devlist_sem);
> +		pr_err("%s: err=%d from famfs_verify_daxdev()\n", __func__, err);
> +		goto out;
> +	}
> +
> +	/* This will fail if it's not a dax device */
> +	daxdev->devp = dax_dev_get(daxdev->devno);
> +	if (!daxdev->devp) {
> +		up_write(&fc->famfs_devlist_sem);

Move the label before the up_write, so you don't need to do it in each
error case or use a guard()

> +		pr_warn("%s: device %s not found or not dax\n",
> +			__func__, daxdev_out.name);
> +		err = -ENODEV;
> +		goto out;
> +	}
> +
> +	daxdev->name = kstrdup(daxdev_out.name, GFP_KERNEL);
Can fail.

> +	wmb(); /* all daxdev fields must be visible before marking it valid */
> +	daxdev->valid = 1;
> +
> +	up_write(&fc->famfs_devlist_sem);
> +
> +out:
> +	return err;
> +}
> +
> +/**
> + * famfs_update_daxdev_table() - Update the daxdev table
> + * @fm   - fuse_mount
> + * @meta - famfs_file_meta, in-memory format, built from a GET_FMAP response
> + *
> + * This function is called for each new file fmap, to verify whether all
> + * referenced daxdevs are already known (i.e. in the table). Any daxdev
> + * indices referenced in @meta but not in the table will be retrieved via
> + * famfs_fuse_get_daxdev() and added to the table
> + *
> + * Return: 0=success
> + *         -errno=failure
> + */
> +static int
> +famfs_update_daxdev_table(
> +	struct fuse_mount *fm,
> +	const struct famfs_file_meta *meta)
> +{
> +	struct famfs_dax_devlist *local_devlist;
> +	struct fuse_conn *fc = fm->fc;
> +	int err;
> +	int i;

Might as well put those on one line or move i down to the loop init.

> +
> +	/* First time through we will need to allocate the dax_devlist */
> +	if (unlikely(!fc->dax_devlist)) {

I'd avoid unlikely markings unless you have good evidence they are needed.
Let the branch predictors figure it out.

> +		local_devlist = kcalloc(1, sizeof(*fc->dax_devlist), GFP_KERNEL);
> +		if (!local_devlist)
> +			return -ENOMEM;
> +
> +		local_devlist->nslots = MAX_DAXDEVS;
> +
> +		local_devlist->devlist = kcalloc(MAX_DAXDEVS,
> +						 sizeof(struct famfs_daxdev),
> +						 GFP_KERNEL);
> +		if (!local_devlist->devlist) {
> +			kfree(local_devlist);
> +			return -ENOMEM;
> +		}
> +
> +		/* We don't need famfs_devlist_sem here because we use cmpxchg */
> +		if (cmpxchg(&fc->dax_devlist, NULL, local_devlist) != NULL) {
> +			kfree(local_devlist->devlist);
> +			kfree(local_devlist); /* another thread beat us to it */
> +		}
> +	}
> +
> +	down_read(&fc->famfs_devlist_sem);
> +	for (i = 0; i < fc->dax_devlist->nslots; i++) {
> +		if (!(meta->dev_bitmap & (1ULL << i)))

Could you do for_each_set_bit() on that bitmap?
Might end up clearer.

> +			continue;
> +
> +		/* This file meta struct references devindex i
> +		 * if devindex i isn't in the table; get it...
> +		 */
> +		if (!(fc->dax_devlist->devlist[i].valid)) {

Maybe flip logic and do a continue as you do with the condition above.

> +			up_read(&fc->famfs_devlist_sem);
> +
> +			err = famfs_fuse_get_daxdev(fm, i);
> +			if (err)
> +				pr_err("%s: failed to get daxdev=%d\n",
> +				       __func__, i);
> +
> +			down_read(&fc->famfs_devlist_sem);
> +		}
> +	}
> +	up_read(&fc->famfs_devlist_sem);
> +
> +	return 0;
> +}

  reply	other threads:[~2026-01-08 14:45 UTC|newest]

Thread overview: 74+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-07 15:32 [PATCH BUNDLE] famfs: Fabric-Attached Memory File System John Groves
2026-01-07 15:33 ` [PATCH V3 00/21] famfs: port into fuse John Groves
2026-01-07 15:33   ` [PATCH V3 01/21] dax: move dax_pgoff_to_phys from [drivers/dax/] device.c to bus.c John Groves
2026-01-08 10:43     ` Jonathan Cameron
2026-01-08 13:25       ` John Groves
2026-01-08 15:20         ` Jonathan Cameron
2026-01-07 15:33   ` [PATCH V3 02/21] dax: add fsdev.c driver for fs-dax on character dax John Groves
2026-01-08 11:31     ` Jonathan Cameron
2026-01-08 14:32       ` John Groves
2026-01-08 15:12       ` John Groves
2026-01-08 21:15         ` John Groves
2026-01-08 23:25           ` Gregory Price
2026-01-07 15:33   ` [PATCH V3 03/21] dax: Save the kva from memremap John Groves
2026-01-08 11:32     ` Jonathan Cameron
2026-01-08 15:15       ` John Groves
2026-01-07 15:33   ` [PATCH V3 04/21] dax: Add dax_operations for use by fs-dax on fsdev dax John Groves
2026-01-08 11:50     ` Jonathan Cameron
2026-01-08 15:59       ` John Groves
2026-01-08 16:10         ` Jonathan Cameron
2026-01-07 15:33   ` [PATCH V3 05/21] dax: Add dax_set_ops() for setting dax_operations at bind time John Groves
2026-01-08 12:06     ` Jonathan Cameron
2026-01-08 16:20       ` John Groves
2026-01-07 15:33   ` [PATCH V3 06/21] dax: Add fs_dax_get() func to prepare dax for fs-dax usage John Groves
2026-01-08 12:27     ` Jonathan Cameron
2026-01-08 16:45       ` John Groves
2026-01-07 15:33   ` [PATCH V3 07/21] dax: prevent driver unbind while filesystem holds device John Groves
2026-01-08 12:34     ` Jonathan Cameron
2026-01-08 18:08       ` John Groves
2026-01-12 18:55     ` John Groves
2026-01-07 15:33   ` [PATCH V3 08/21] dax: export dax_dev_get() John Groves
2026-01-07 15:33   ` [PATCH V3 09/21] famfs_fuse: magic.h: Add famfs magic numbers John Groves
2026-01-07 15:33   ` [PATCH V3 10/21] famfs_fuse: Kconfig John Groves
2026-01-08 12:36     ` Jonathan Cameron
2026-01-12 16:46       ` John Groves
2026-01-07 15:33   ` [PATCH V3 11/21] famfs_fuse: Update macro s/FUSE_IS_DAX/FUSE_IS_VIRTIO_DAX/ John Groves
2026-01-09 18:16     ` Joanne Koong
2026-01-09 22:15       ` [PATCH V3 11/21] famfs_fuse: Update macro s/FUSE_IS_DAX/FUSE_IS_VIRTIO_DAX John Groves
2026-01-07 15:33   ` [PATCH V3 12/21] famfs_fuse: Basic fuse kernel ABI enablement for famfs John Groves
2026-01-09 18:29     ` Joanne Koong
2026-01-09 22:58       ` John Groves
2026-01-07 15:33   ` [PATCH V3 13/21] famfs_fuse: Famfs mount opt: -o shadow=<shadowpath> John Groves
2026-01-09 19:22     ` Joanne Koong
2026-01-10  0:38       ` John Groves
2026-01-11 18:20         ` John Groves
2026-01-07 15:33   ` [PATCH V3 14/21] famfs_fuse: Plumb the GET_FMAP message/response John Groves
2026-01-08 12:49     ` Jonathan Cameron
2026-01-09  2:12       ` John Groves
2026-01-07 15:33   ` [PATCH V3 15/21] famfs_fuse: Create files with famfs fmaps John Groves
2026-01-07 21:30     ` John Groves
2026-01-08 13:14     ` Jonathan Cameron
2026-01-09 14:30       ` John Groves
2026-01-07 15:33   ` [PATCH V3 16/21] famfs_fuse: GET_DAXDEV message and daxdev_table John Groves
2026-01-08 14:45     ` Jonathan Cameron [this message]
2026-01-07 15:33   ` [PATCH V3 17/21] famfs_fuse: Plumb dax iomap and fuse read/write/mmap John Groves
2026-01-08 15:13     ` Jonathan Cameron
2026-01-09 17:44       ` John Groves
2026-01-07 15:33   ` [PATCH V3 18/21] famfs_fuse: Add holder_operations for dax notify_failure() John Groves
2026-01-08 15:17     ` Jonathan Cameron
2026-01-09 21:00       ` John Groves
2026-01-07 15:33   ` [PATCH V3 19/21] famfs_fuse: Add DAX address_space_operations with noop_dirty_folio John Groves
2026-01-07 15:33   ` [PATCH V3 20/21] famfs_fuse: Add famfs fmap metadata documentation John Groves
2026-01-07 15:33   ` [PATCH V3 21/21] famfs_fuse: Add documentation John Groves
2026-01-08 15:27     ` Jonathan Cameron
2026-01-11 18:53       ` John Groves
2026-01-07 15:34 ` [PATCH V3 0/4] libfuse: add basic famfs support to libfuse John Groves
2026-01-07 15:34   ` [PATCH V3 1/4] fuse_kernel.h: bring up to baseline 6.19 John Groves
2026-01-07 15:34   ` [PATCH V3 2/4] fuse_kernel.h: add famfs DAX fmap protocol definitions John Groves
2026-01-07 15:34   ` [PATCH V3 3/4] fuse: add API to set kernel mount options John Groves
2026-01-07 15:34   ` [PATCH V3 4/4] fuse: add famfs DAX fmap support John Groves
2026-01-08 15:31     ` Jonathan Cameron
2026-01-11 18:24       ` John Groves
2026-01-07 15:34 ` [PATCH 0/2] ndctl: Add daxctl support for the new "famfs" mode of devdax John Groves
2026-01-07 15:34   ` [PATCH 1/2] daxctl: Add support for famfs mode John Groves
2026-01-07 15:34   ` [PATCH 2/2] Add test/daxctl-famfs.sh to test famfs mode transitions: John Groves

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=20260108144502.000024e0@huawei.com \
    --to=jonathan.cameron@huawei.com \
    --cc=John@Groves.net \
    --cc=ackerleytng@google.com \
    --cc=ajayjoshi@micron.com \
    --cc=alison.schofield@intel.com \
    --cc=amir73il@gmail.com \
    --cc=arramesh@micron.com \
    --cc=bagasdotme@gmail.com \
    --cc=brauner@kernel.org \
    --cc=bschubert@ddn.com \
    --cc=chenlinxuan@uniontech.com \
    --cc=corbet@lwn.net \
    --cc=dan.j.williams@intel.com \
    --cc=dave.jiang@intel.com \
    --cc=david@kernel.org \
    --cc=djwong@kernel.org \
    --cc=gourry@gourry.net \
    --cc=jack@suse.cz \
    --cc=james.morse@arm.com \
    --cc=jgroves@micron.com \
    --cc=jlayton@kernel.org \
    --cc=joannelkoong@gmail.com \
    --cc=josef@toxicpanda.com \
    --cc=linux-cxl@vger.kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=miklos@szeredi.hu \
    --cc=nvdimm@lists.linux.dev \
    --cc=rdunlap@infradead.org \
    --cc=seanjc@google.com \
    --cc=shajnocz@redhat.com \
    --cc=shivankg@amd.com \
    --cc=tabba@google.com \
    --cc=venkataravis@micron.com \
    --cc=viro@zeniv.linux.org.uk \
    --cc=vishal.l.verma@intel.com \
    --cc=willy@infradead.org \
    /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