aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorBernd Schubert <bschubert@ddn.com>2025-03-11 22:21:09 +0100
committerBernd Schubert <bernd@bsbernd.com>2025-03-14 12:58:14 +0100
commit1b86fe4c4de96daa4e766425193595f1c6b88a73 (patch)
tree1af3b7d46056532b928703bac44ea3810bbe3e61 /lib
parent065272a23392011ea1728c4f2d20e63cf6579e7d (diff)
downloadlibfuse-1b86fe4c4de96daa4e766425193595f1c6b88a73.tar.gz
fuse_lowlevel: Simplify se->buf_reallocable
se->buf_reallocable is true when reading /dev/fuse is handled from internal functions - we can set the variable in fuse_session_receive_buf_internal(). With that we also don't need to have it an _Atomic variable anymore. In _fuse_session_receive_buf() we can use "bool internal" to check if the buffer can be re-allocated. Signed-off-by: Bernd Schubert <bschubert@ddn.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/fuse_i.h4
-rw-r--r--lib/fuse_lowlevel.c23
-rw-r--r--lib/util.h3
3 files changed, 18 insertions, 12 deletions
diff --git a/lib/fuse_i.h b/lib/fuse_i.h
index 69ca159..bf8410f 100644
--- a/lib/fuse_i.h
+++ b/lib/fuse_i.h
@@ -79,7 +79,9 @@ struct fuse_session {
* a later version, to 'fix' it at run time.
*/
struct libfuse_version version;
- _Atomic bool buf_reallocable;
+
+ /* true if reading requests from /dev/fuse are handled internally */
+ bool buf_reallocable;
};
struct fuse_chan {
diff --git a/lib/fuse_lowlevel.c b/lib/fuse_lowlevel.c
index 0642572..1e2491b 100644
--- a/lib/fuse_lowlevel.c
+++ b/lib/fuse_lowlevel.c
@@ -3136,8 +3136,6 @@ pipe_retry:
return -ENOMEM;
}
buf->mem_size = se->bufsize;
- if (internal)
- se->buf_reallocable = true;
}
buf->size = se->bufsize;
buf->flags = 0;
@@ -3177,13 +3175,9 @@ fallback:
return -ENOMEM;
}
buf->mem_size = se->bufsize;
- if (internal)
- se->buf_reallocable = true;
}
restart:
- if (se->buf_reallocable)
- bufsize = buf->mem_size;
if (se->io != NULL) {
/* se->io->read is never NULL if se->io is not NULL as
specified by fuse_session_custom_io()*/
@@ -3197,9 +3191,10 @@ restart:
if (fuse_session_exited(se))
return 0;
if (res == -1) {
- if (err == EINVAL && se->buf_reallocable &&
- se->bufsize > buf->mem_size) {
- void *newbuf = buf_alloc(se->bufsize, internal);
+ if (err == EINVAL && internal && se->bufsize > buf->mem_size) {
+ /* FUSE_INIT might have increased the required bufsize */
+ bufsize = se->bufsize;
+ void *newbuf = buf_alloc(bufsize, internal);
if (!newbuf) {
fuse_log(
FUSE_LOG_ERR,
@@ -3208,8 +3203,7 @@ restart:
}
fuse_buf_free(buf);
buf->mem = newbuf;
- buf->mem_size = se->bufsize;
- se->buf_reallocable = true;
+ buf->mem_size = bufsize;
goto restart;
}
@@ -3251,6 +3245,13 @@ int fuse_session_receive_buf_internal(struct fuse_session *se,
struct fuse_buf *buf,
struct fuse_chan *ch)
{
+ /*
+ * if run internally thread buffers are from libfuse - we can
+ * reallocate them
+ */
+ if (unlikely(!se->got_init) && !se->buf_reallocable)
+ se->buf_reallocable = true;
+
return _fuse_session_receive_buf(se, buf, ch, true);
}
diff --git a/lib/util.h b/lib/util.h
index 74ce748..a5c5463 100644
--- a/lib/util.h
+++ b/lib/util.h
@@ -1,3 +1,6 @@
#define ROUND_UP(val, round_to) (((val) + (round_to - 1)) & ~(round_to - 1))
+#define likely(x) __builtin_expect(!!(x), 1)
+#define unlikely(x) __builtin_expect(!!(x), 0)
+
int libfuse_strtol(const char *str, long *res);