@samitouri / QOSamiQemu / commits / 771b799bfb

fuse: Add halted flag

This is a flag that we will want when processing FUSE requests ourselves: When the kernel sends us e.g. a truncated request (i.e. we receive less data than the request's indicated length), we cannot rely on subsequent data to be valid. Then, we are going to set this flag, halting all FUSE request processing. We plan to only use this flag in cases that would effectively be kernel bugs. While not necessary yet, access the flag atomically so that it will be safe to use once we introduce multi-threading. (Right now, the flag is unused because libfuse still does our request processing.) Signed-off-by: Hanna Czenczek <hreitz@redhat.com> Message-ID: <20260309150856.26800-12-hreitz@redhat.com> Reviewed-by: Kevin Wolf <kwolf@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>

Hanna Czenczek committed Mar 9, 2026 at 16:08 UTC 771b799bfb5a6054cad338881d21cc4737abe689
1 file changed +30
block/export/fuse.c
+30
@@ -53,6 +53,13 @@ typedef struct FuseExport {
53 unsigned int in_flight; /* atomic */
54 bool mounted, fd_handler_set_up;
55
56 + /*
57 + * Set when there was an unrecoverable error and no requests should be read
58 + * from the device anymore (basically only in case of something we would
59 + * consider a kernel bug). Access atomically.
60 + */
61 + bool halted;
62 +
63 char *mountpoint;
64 bool writable;
65 bool growable;
@@ -69,6 +76,7 @@ static const struct fuse_lowlevel_ops fuse_ops;
76
77 static void fuse_export_shutdown(BlockExport *exp);
78 static void fuse_export_delete(BlockExport *exp);
79 +static void fuse_export_halt(FuseExport *exp) G_GNUC_UNUSED;
80
81 static void init_exports_table(void);
82
@@ -99,6 +107,10 @@ static void fuse_dec_in_flight(FuseExport *exp)
107
108 static void fuse_attach_handlers(FuseExport *exp)
109 {
110 + if (qatomic_read(&exp->halted)) {
111 + return;
112 + }
113 +
114 aio_set_fd_handler(exp->common.ctx,
115 fuse_session_fd(exp->fuse_session),
116 read_from_fuse_export, NULL, NULL, NULL, exp);
@@ -322,6 +334,10 @@ static void read_from_fuse_export(void *opaque)
334 FuseExport *exp = opaque;
335 int ret;
336
337 + if (unlikely(qatomic_read(&exp->halted))) {
338 + return;
339 + }
340 +
341 fuse_inc_in_flight(exp);
342
343 do {
@@ -380,6 +396,20 @@ static void fuse_export_delete(BlockExport *blk_exp)
396 g_free(exp->mountpoint);
397 }
398
399 +/**
400 + * Halt the export: Detach FD handlers, and set exp->halted to true, preventing
401 + * fuse_attach_handlers() from re-attaching them, therefore stopping all further
402 + * request processing.
403 + *
404 + * Call this function when an unrecoverable error happens that makes processing
405 + * all future requests unreliable.
406 + */
407 +static void fuse_export_halt(FuseExport *exp)
408 +{
409 + qatomic_set(&exp->halted, true);
410 + fuse_detach_handlers(exp);
411 +}
412 +
413 /**
414 * Check whether @path points to a regular file. If not, put an
415 * appropriate message into *errp.