@samitouri / QOSamiQemu / commits / 52d50658c3

fuse: Change setup_... to mount_fuse_export()

There is no clear separation between what should go into setup_fuse_export() and what should stay in fuse_export_create(). Make it clear that setup_fuse_export() is for mounting only. Rename it, and move everything that has nothing to do with mounting up into fuse_export_create(). Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> Signed-off-by: Hanna Czenczek <hreitz@redhat.com> Message-ID: <20260309150856.26800-6-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 52d50658c3f26a19f4f0da0d024f4a904477d206
1 file changed +22 -27
block/export/fuse.c
+22 -27
@@ -72,8 +72,7 @@ static void fuse_export_delete(BlockExport *exp);
72
73 static void init_exports_table(void);
74
75 -static int setup_fuse_export(FuseExport *exp, const char *mountpoint,
76 - bool allow_other, Error **errp);
75 +static int mount_fuse_export(FuseExport *exp, Error **errp);
76 static void read_from_fuse_export(void *opaque);
77
78 static bool is_regular_file(const char *path, Error **errp);
@@ -193,23 +192,32 @@ static int fuse_export_create(BlockExport *blk_exp,
192 exp->st_gid = getgid();
193
194 if (args->allow_other == FUSE_EXPORT_ALLOW_OTHER_AUTO) {
196 - /* Ignore errors on our first attempt */
197 - ret = setup_fuse_export(exp, args->mountpoint, true, NULL);
198 - exp->allow_other = ret == 0;
195 + /* Try allow_other == true first, ignore errors */
196 + exp->allow_other = true;
197 + ret = mount_fuse_export(exp, NULL);
198 if (ret < 0) {
200 - ret = setup_fuse_export(exp, args->mountpoint, false, errp);
199 + exp->allow_other = false;
200 + ret = mount_fuse_export(exp, errp);
201 }
202 } else {
203 exp->allow_other = args->allow_other == FUSE_EXPORT_ALLOW_OTHER_ON;
204 - ret = setup_fuse_export(exp, args->mountpoint, exp->allow_other, errp);
204 + ret = mount_fuse_export(exp, errp);
205 }
206 if (ret < 0) {
207 goto fail;
208 }
209
210 + g_hash_table_insert(exports, g_strdup(exp->mountpoint), NULL);
211 +
212 + aio_set_fd_handler(exp->common.ctx,
213 + fuse_session_fd(exp->fuse_session),
214 + read_from_fuse_export, NULL, NULL, NULL, exp);
215 + exp->fd_handler_set_up = true;
216 +
217 return 0;
218
219 fail:
220 + fuse_export_shutdown(blk_exp);
221 fuse_export_delete(blk_exp);
222 return ret;
223 }
@@ -227,10 +235,10 @@ static void init_exports_table(void)
235 }
236
237 /**
230 - * Create exp->fuse_session and mount it.
238 + * Create exp->fuse_session and mount it. Expects exp->mountpoint,
239 + * exp->writable, and exp->allow_other to be set as intended for the mount.
240 */
232 -static int setup_fuse_export(FuseExport *exp, const char *mountpoint,
233 - bool allow_other, Error **errp)
241 +static int mount_fuse_export(FuseExport *exp, Error **errp)
242 {
243 const char *fuse_argv[4];
244 char *mount_opts;
@@ -243,7 +251,7 @@ static int setup_fuse_export(FuseExport *exp, const char *mountpoint,
251 */
252 mount_opts = g_strdup_printf("max_read=%zu,default_permissions%s",
253 FUSE_MAX_BOUNCE_BYTES,
246 - allow_other ? ",allow_other" : "");
254 + exp->allow_other ? ",allow_other" : "");
255
256 fuse_argv[0] = ""; /* Dummy program name */
257 fuse_argv[1] = "-o";
@@ -256,30 +264,17 @@ static int setup_fuse_export(FuseExport *exp, const char *mountpoint,
264 g_free(mount_opts);
265 if (!exp->fuse_session) {
266 error_setg(errp, "Failed to set up FUSE session");
259 - ret = -EIO;
260 - goto fail;
267 + return -EIO;
268 }
269
263 - ret = fuse_session_mount(exp->fuse_session, mountpoint);
270 + ret = fuse_session_mount(exp->fuse_session, exp->mountpoint);
271 if (ret < 0) {
272 error_setg(errp, "Failed to mount FUSE session to export");
266 - ret = -EIO;
267 - goto fail;
273 + return -EIO;
274 }
275 exp->mounted = true;
276
271 - g_hash_table_insert(exports, g_strdup(mountpoint), NULL);
272 -
273 - aio_set_fd_handler(exp->common.ctx,
274 - fuse_session_fd(exp->fuse_session),
275 - read_from_fuse_export, NULL, NULL, NULL, exp);
276 - exp->fd_handler_set_up = true;
277 -
277 return 0;
279 -
280 -fail:
281 - fuse_export_shutdown(&exp->common);
282 - return ret;
278 }
279
280 /**