fuse_lowlevel FUSE_INIT: Simplify the max_write/bufsize logic
authorBernd Schubert <bschubert@ddn.com>
Fri, 27 Sep 2024 18:37:51 +0000 (20:37 +0200)
committerBernd Schubert <bernd.schubert@fastmail.fm>
Sat, 28 Sep 2024 14:24:22 +0000 (16:24 +0200)
max_write can be limited by se->op.init() and by the buffer size,
we use the minimum of these two.
Required se->bufsize is then set according to the determined
max_write. The current thread will have the old buffer size,
though, as it already had to the allocation to handle the
FUSE_INIT call (unless splice is used and ths variable
and related buffer is not used at all).

The given bufsize is just a hint for minimum size, allocation
could be actually larger (for example to get huge pages).

lib/fuse_i.h
lib/fuse_lowlevel.c

index 2815a8a28c426ab8750a1630445f7999c87dd928..f7924ebcac6c5d073df2c373f608e926b496fbe7 100644 (file)
@@ -9,6 +9,13 @@
 #include "fuse.h"
 #include "fuse_lowlevel.h"
 
+#define MIN(a, b) \
+({                                                                     \
+       typeof(a) _a = (a);                                             \
+       typeof(b) _b = (b);                                             \
+       _a < _b ? _a : _b;                                              \
+})
+
 struct mount_opts;
 
 struct fuse_req {
index 84185d5b546e8189b1c40a5c77a710807e40b382..a505552f59a55af44d8a6c7e6e7eab072cdee0ab 100644 (file)
@@ -2146,11 +2146,8 @@ void do_init(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
                bufsize = FUSE_MIN_READ_BUFFER;
        }
 
-       if (se->conn.max_write > bufsize - FUSE_BUFFER_HEADER_SIZE)
-               se->conn.max_write = bufsize - FUSE_BUFFER_HEADER_SIZE;
-       if (se->conn.max_write < bufsize - FUSE_BUFFER_HEADER_SIZE)
-               bufsize = se->conn.max_write + FUSE_BUFFER_HEADER_SIZE;
-       se->bufsize = bufsize;
+       se->conn.max_write = MIN(se->conn.max_write, bufsize - FUSE_BUFFER_HEADER_SIZE);
+       se->bufsize = se->conn.max_write + FUSE_BUFFER_HEADER_SIZE;
 
        if (arg->flags & FUSE_MAX_PAGES) {
                outarg.flags |= FUSE_MAX_PAGES;