@samitouri / QOSamiQemu / commits / 7e38c36558

fuse: Introduce fuse_{inc,dec}_in_flight()

This is how vduse-blk.c does it, and it does seem better to have dedicated functions for it. Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> Signed-off-by: Hanna Czenczek <hreitz@redhat.com> Message-ID: <20260309150856.26800-11-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 7e38c36558195f38398b7ad9dc4138749551f0ea
1 file changed +21 -8
block/export/fuse.c
+21 -8
@@ -78,6 +78,25 @@ static void read_from_fuse_export(void *opaque);
78 static bool is_regular_file(const char *path, Error **errp);
79
80
81 +static void fuse_inc_in_flight(FuseExport *exp)
82 +{
83 + if (qatomic_fetch_inc(&exp->in_flight) == 0) {
84 + /* Prevent export from being deleted */
85 + blk_exp_ref(&exp->common);
86 + }
87 +}
88 +
89 +static void fuse_dec_in_flight(FuseExport *exp)
90 +{
91 + if (qatomic_fetch_dec(&exp->in_flight) == 1) {
92 + /* Wake AIO_WAIT_WHILE() */
93 + aio_wait_kick();
94 +
95 + /* Now the export can be deleted */
96 + blk_exp_unref(&exp->common);
97 + }
98 +}
99 +
100 static void fuse_attach_handlers(FuseExport *exp)
101 {
102 aio_set_fd_handler(exp->common.ctx,
@@ -303,9 +322,7 @@ static void read_from_fuse_export(void *opaque)
322 FuseExport *exp = opaque;
323 int ret;
324
306 - blk_exp_ref(&exp->common);
307 -
308 - qatomic_inc(&exp->in_flight);
325 + fuse_inc_in_flight(exp);
326
327 do {
328 ret = fuse_session_receive_buf(exp->fuse_session, &exp->fuse_buf);
@@ -323,11 +340,7 @@ static void read_from_fuse_export(void *opaque)
340 fuse_session_process_buf(exp->fuse_session, &exp->fuse_buf);
341
342 out:
326 - if (qatomic_fetch_dec(&exp->in_flight) == 1) {
327 - aio_wait_kick(); /* wake AIO_WAIT_WHILE() */
328 - }
329 -
330 - blk_exp_unref(&exp->common);
343 + fuse_dec_in_flight(exp);
344 }
345
346 static void fuse_export_shutdown(BlockExport *blk_exp)