]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
fuse-uring: refactor setting up copy state for payload copying
authorJoanne Koong <joannelkoong@gmail.com>
Fri, 12 Jun 2026 21:05:08 +0000 (14:05 -0700)
committerMiklos Szeredi <mszeredi@redhat.com>
Mon, 15 Jun 2026 12:06:20 +0000 (14:06 +0200)
Add a new helper function setup_fuse_copy_state() to contain the logic
for setting up the copy state for payload copying.

Reviewed-by: Bernd Schubert <bschubert@ddn.com>
Reviewed-by: Jeff Layton <jlayton@kernel.org>
Reviewed-by: Baokun Li <libaokun@linux.alibaba.com>
Signed-off-by: Joanne Koong <joannelkoong@gmail.com>
Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
fs/fuse/dev_uring.c

index 58e19e8f537c33df57fad752bbe8f846f6106d13..0867799e1a3f1da49b5324e57ee5a144977e1454 100644 (file)
@@ -642,6 +642,27 @@ static int copy_header_from_ring(struct fuse_ring_ent *ent,
        return 0;
 }
 
+static int setup_fuse_copy_state(struct fuse_copy_state *cs,
+                                struct fuse_ring *ring, struct fuse_req *req,
+                                struct fuse_ring_ent *ent, int dir,
+                                struct iov_iter *iter)
+{
+       int err;
+
+       err = import_ubuf(dir, ent->payload, ring->max_payload_sz, iter);
+       if (err) {
+               pr_info_ratelimited("fuse: Import of user buffer failed\n");
+               return err;
+       }
+
+       fuse_copy_init(cs, dir == ITER_DEST, iter);
+
+       cs->is_uring = true;
+       cs->req = req;
+
+       return 0;
+}
+
 static int fuse_uring_copy_from_ring(struct fuse_ring *ring,
                                     struct fuse_req *req,
                                     struct fuse_ring_ent *ent)
@@ -657,15 +678,10 @@ static int fuse_uring_copy_from_ring(struct fuse_ring *ring,
        if (err)
                return err;
 
-       err = import_ubuf(ITER_SOURCE, ent->payload, ring->max_payload_sz,
-                         &iter);
+       err = setup_fuse_copy_state(&cs, ring, req, ent, ITER_SOURCE, &iter);
        if (err)
                return err;
 
-       fuse_copy_init(&cs, false, &iter);
-       cs.is_uring = true;
-       cs.req = req;
-
        err = fuse_copy_out_args(&cs, args, ring_in_out.payload_sz);
        fuse_copy_finish(&cs);
        return err;
@@ -688,15 +704,9 @@ static int fuse_uring_args_to_ring(struct fuse_ring *ring, struct fuse_req *req,
                .commit_id = req->in.h.unique,
        };
 
-       err = import_ubuf(ITER_DEST, ent->payload, ring->max_payload_sz, &iter);
-       if (err) {
-               pr_info_ratelimited("fuse: Import of user buffer failed\n");
+       err = setup_fuse_copy_state(&cs, ring, req, ent, ITER_DEST, &iter);
+       if (err)
                return err;
-       }
-
-       fuse_copy_init(&cs, true, &iter);
-       cs.is_uring = true;
-       cs.req = req;
 
        if (num_args > 0) {
                /*