[PATCH v7 2/4] fuse: create helper functions for filling in fuse args for open and getattr
From: Horst Birthelmer
Date: Thu Jun 04 2026 - 05:53:01 EST
From: Horst Birthelmer <hbirthelmer@xxxxxxx>
create fuse_getattr_args_fill() and fuse_open_args_fill() to fill in
the parameters for the open and getattr calls.
This is in preparation for implementing open+getattr and does not
represent any functional change.
Suggested-by: Joanne Koong <joannelkoong@xxxxxxxxx>
Signed-off-by: Horst Birthelmer <hbirthelmer@xxxxxxx>
---
fs/fuse/dir.c | 26 ++++++++++++++++++--------
fs/fuse/file.c | 44 ++++++++++++++++++++++++++++----------------
fs/fuse/fuse_i.h | 6 ++++++
3 files changed, 52 insertions(+), 24 deletions(-)
diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
index b658b6baf72f..b3406c33abd2 100644
--- a/fs/fuse/dir.c
+++ b/fs/fuse/dir.c
@@ -1475,6 +1475,23 @@ static int fuse_do_statx(struct mnt_idmap *idmap, struct inode *inode,
return 0;
}
+/*
+ * Helper function to initialize fuse_args for GETATTR operations
+ */
+void fuse_getattr_args_fill(struct fuse_args *args, u64 nodeid,
+ struct fuse_getattr_in *inarg,
+ struct fuse_attr_out *outarg)
+{
+ args->opcode = FUSE_GETATTR;
+ args->nodeid = nodeid;
+ args->in_numargs = 1;
+ args->in_args[0].size = sizeof(*inarg);
+ args->in_args[0].value = inarg;
+ args->out_numargs = 1;
+ args->out_args[0].size = sizeof(*outarg);
+ args->out_args[0].value = outarg;
+}
+
static int fuse_do_getattr(struct mnt_idmap *idmap, struct inode *inode,
struct kstat *stat, struct file *file)
{
@@ -1496,14 +1513,7 @@ static int fuse_do_getattr(struct mnt_idmap *idmap, struct inode *inode,
inarg.getattr_flags |= FUSE_GETATTR_FH;
inarg.fh = ff->fh;
}
- args.opcode = FUSE_GETATTR;
- args.nodeid = get_node_id(inode);
- args.in_numargs = 1;
- args.in_args[0].size = sizeof(inarg);
- args.in_args[0].value = &inarg;
- args.out_numargs = 1;
- args.out_args[0].size = sizeof(outarg);
- args.out_args[0].value = &outarg;
+ fuse_getattr_args_fill(&args, get_node_id(inode), &inarg, &outarg);
err = fuse_simple_request(fm, &args);
if (!err) {
if (fuse_invalid_attr(&outarg.attr) ||
diff --git a/fs/fuse/file.c b/fs/fuse/file.c
index f94f3dc082c6..a7d602225f45 100644
--- a/fs/fuse/file.c
+++ b/fs/fuse/file.c
@@ -23,6 +23,33 @@
#include <linux/task_io_accounting_ops.h>
#include <linux/iomap.h>
+/*
+ * Helper function to initialize fuse_args for OPEN/OPENDIR operations
+ */
+static void fuse_open_args_fill(struct fuse_mount *fm, struct fuse_args *args,
+ u64 nodeid, int opcode, unsigned int open_flags,
+ struct fuse_open_in *inarg,
+ struct fuse_open_out *outarg)
+{
+ inarg->flags = open_flags & ~(O_CREAT | O_EXCL | O_NOCTTY);
+
+ if (!fm->fc->atomic_o_trunc)
+ inarg->flags &= ~O_TRUNC;
+
+ if (fm->fc->handle_killpriv_v2 &&
+ (inarg->flags & O_TRUNC) && !capable(CAP_FSETID))
+ inarg->open_flags |= FUSE_OPEN_KILL_SUIDGID;
+
+ args->opcode = opcode;
+ args->nodeid = nodeid;
+ args->in_numargs = 1;
+ args->in_args[0].size = sizeof(*inarg);
+ args->in_args[0].value = inarg;
+ args->out_numargs = 1;
+ args->out_args[0].size = sizeof(*outarg);
+ args->out_args[0].value = outarg;
+}
+
static int fuse_send_open(struct fuse_mount *fm, u64 nodeid,
unsigned int open_flags, int opcode,
struct fuse_open_out *outargp)
@@ -31,23 +58,8 @@ static int fuse_send_open(struct fuse_mount *fm, u64 nodeid,
FUSE_ARGS(args);
memset(&inarg, 0, sizeof(inarg));
- inarg.flags = open_flags & ~(O_CREAT | O_EXCL | O_NOCTTY);
- if (!fm->fc->atomic_o_trunc)
- inarg.flags &= ~O_TRUNC;
-
- if (fm->fc->handle_killpriv_v2 &&
- (inarg.flags & O_TRUNC) && !capable(CAP_FSETID)) {
- inarg.open_flags |= FUSE_OPEN_KILL_SUIDGID;
- }
- args.opcode = opcode;
- args.nodeid = nodeid;
- args.in_numargs = 1;
- args.in_args[0].size = sizeof(inarg);
- args.in_args[0].value = &inarg;
- args.out_numargs = 1;
- args.out_args[0].size = sizeof(*outargp);
- args.out_args[0].value = outargp;
+ fuse_open_args_fill(fm, &args, nodeid, opcode, open_flags, &inarg, outargp);
return fuse_simple_request(fm, &args);
}
diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h
index af4ea2af19d1..219312d5f21e 100644
--- a/fs/fuse/fuse_i.h
+++ b/fs/fuse/fuse_i.h
@@ -1181,6 +1181,12 @@ struct fuse_io_args {
void fuse_read_args_fill(struct fuse_io_args *ia, struct file *file, loff_t pos,
size_t count, int opcode);
+/*
+ * Helper functions to initialize fuse_args for common operations
+ */
+void fuse_getattr_args_fill(struct fuse_args *args, u64 nodeid,
+ struct fuse_getattr_in *inarg,
+ struct fuse_attr_out *outarg);
struct fuse_file *fuse_file_alloc(struct fuse_mount *fm, bool release);
void fuse_file_free(struct fuse_file *ff);
--
2.54.0