On 26/01/08 12:49PM, Jonathan Cameron wrote:
> On Wed,  7 Jan 2026 09:33:23 -0600
> John Groves <[email protected]> wrote:
> 
> > Upon completion of an OPEN, if we're in famfs-mode we do a GET_FMAP to
> > retrieve and cache up the file-to-dax map in the kernel. If this
> > succeeds, read/write/mmap are resolved direct-to-dax with no upcalls.
> > 
> > Signed-off-by: John Groves <[email protected]>
> A few things inline.
> 
> J
> 
> > diff --git a/fs/fuse/famfs.c b/fs/fuse/famfs.c
> > new file mode 100644
> > index 000000000000..0f7e3f00e1e7
> > --- /dev/null
> > +++ b/fs/fuse/famfs.c
> > @@ -0,0 +1,74 @@
> > +// SPDX-License-Identifier: GPL-2.0
> > +/*
> > + * famfs - dax file system for shared fabric-attached memory
> > + *
> > + * Copyright 2023-2025 Micron Technology, Inc.
> > + *
> > + * This file system, originally based on ramfs the dax support from xfs,
> > + * is intended to allow multiple host systems to mount a common file system
> > + * view of dax files that map to shared memory.
> > + */
> > +
> > +#include <linux/fs.h>
> > +#include <linux/mm.h>
> > +#include <linux/dax.h>
> > +#include <linux/iomap.h>
> > +#include <linux/path.h>
> > +#include <linux/namei.h>
> > +#include <linux/string.h>
> > +
> > +#include "fuse_i.h"
> > +
> > +
> > +#define FMAP_BUFSIZE PAGE_SIZE
> > +
> > +int
> > +fuse_get_fmap(struct fuse_mount *fm, struct inode *inode)
> > +{
> > +   struct fuse_inode *fi = get_fuse_inode(inode);
> > +   size_t fmap_bufsize = FMAP_BUFSIZE;
> > +   u64 nodeid = get_node_id(inode);
> > +   ssize_t fmap_size;
> > +   void *fmap_buf;
> > +   int rc;
> > +
> > +   FUSE_ARGS(args);
> > +
> > +   /* Don't retrieve if we already have the famfs metadata */
> > +   if (fi->famfs_meta)
> > +           return 0;
> > +
> > +   fmap_buf = kcalloc(1, FMAP_BUFSIZE, GFP_KERNEL);
> 
> If there is only ever 1, does kcalloc() make sense over kzalloc()?

Muscle memory? Good call, done.

> 
> > +   if (!fmap_buf)
> > +           return -EIO;
> > +
> > +   args.opcode = FUSE_GET_FMAP;
> > +   args.nodeid = nodeid;
> > +
> > +   /* Variable-sized output buffer
> > +    * this causes fuse_simple_request() to return the size of the
> > +    * output payload
> > +    */
> > +   args.out_argvar = true;
> > +   args.out_numargs = 1;
> > +   args.out_args[0].size = fmap_bufsize;
> > +   args.out_args[0].value = fmap_buf;
> > +
> > +   /* Send GET_FMAP command */
> > +   rc = fuse_simple_request(fm, &args);
> > +   if (rc < 0) {
> > +           pr_err("%s: err=%d from fuse_simple_request()\n",
> > +                  __func__, rc);
> 
> Leaks the fmap_buf?  Maybe use a __free() so no need to keep track of htat.

Another good one - done.

> 
> 
> > +           return rc;
> > +   }
> > +   fmap_size = rc;
> > +
> > +   /* We retrieved the "fmap" (the file's map to memory), but
> > +    * we haven't used it yet. A call to famfs_file_init_dax() will be added
> > +    * here in a subsequent patch, when we add the ability to attach
> > +    * fmaps to files.
> > +    */
> > +
> > +   kfree(fmap_buf);
> > +   return 0;
> > +}
> 
> > diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h
> > index 84d0ee2a501d..691c7850cf4e 100644
> > --- a/fs/fuse/fuse_i.h
> > +++ b/fs/fuse/fuse_i.h
> > @@ -223,6 +223,14 @@ struct fuse_inode {
> 
> >  
> > +static inline struct fuse_backing *famfs_meta_set(struct fuse_inode *fi,
> > +                                                  void *meta)
> > +{
> > +#if IS_ENABLED(CONFIG_FUSE_FAMFS_DAX)
> > +   return xchg(&fi->famfs_meta, meta);
> > +#else
> > +   return NULL;
> > +#endif
> > +}
> > +
> > +static inline void famfs_meta_free(struct fuse_inode *fi)
> > +{
> > +   /* Stub wil be connected in a subsequent commit */
> > +}
> > +
> > +static inline int fuse_file_famfs(struct fuse_inode *fi)
> > +{
> > +#if IS_ENABLED(CONFIG_FUSE_FAMFS_DAX)
> > +   return (READ_ONCE(fi->famfs_meta) != NULL);
> > +#else
> > +   return 0;
> > +#endif
> > +}
> > +
> > +#if IS_ENABLED(CONFIG_FUSE_FAMFS_DAX)
> > +int fuse_get_fmap(struct fuse_mount *fm, struct inode *inode);
> > +#else
> > +static inline int
> > +fuse_get_fmap(struct fuse_mount *fm, struct inode *inode)
> > +{
> > +   return 0;
> > +}
> > +#endif
> I'd do a single block under one if IS_ENABLED() and then use an else
> for the stubs.   Should end up more readable.

OK, this sounds good, but it's rebase hell (oh, the humanity! :D). Multiple 
additional commits flesh out this stuff, and for now I'm giving up on that
rebase. I tried the flip, but I don't have all night (tonight), so I'm 
leaving it alone. 

I'll happily clean this up after the series is complete.

Thanks!
John


Reply via email to