diff mbox series

[1/4] 9pfs: local : Introduce local_fid_fd() helper

Message ID 20250310171101.138380-2-groug@kaod.org (mailing list archive)
State New
Headers show
Series 9pfs: Fix ftruncate-after-unlink | expand

Commit Message

Greg Kurz March 10, 2025, 5:10 p.m. UTC
Factor out duplicated code to a single helper. More users to come.

Signed-off-by: Greg Kurz <groug@kaod.org>
---
 hw/9pfs/9p-local.c | 21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)
diff mbox series

Patch

diff --git a/hw/9pfs/9p-local.c b/hw/9pfs/9p-local.c
index 928523afcc6c..c4366c867988 100644
--- a/hw/9pfs/9p-local.c
+++ b/hw/9pfs/9p-local.c
@@ -766,10 +766,9 @@  out:
     return err;
 }
 
-static int local_fstat(FsContext *fs_ctx, int fid_type,
-                       V9fsFidOpenState *fs, struct stat *stbuf)
+static int local_fid_fd(int fid_type, V9fsFidOpenState *fs)
 {
-    int err, fd;
+    int fd;
 
     if (fid_type == P9_FID_DIR) {
         fd = dirfd(fs->dir.stream);
@@ -777,6 +776,14 @@  static int local_fstat(FsContext *fs_ctx, int fid_type,
         fd = fs->fd;
     }
 
+    return fd;
+}
+
+static int local_fstat(FsContext *fs_ctx, int fid_type,
+                       V9fsFidOpenState *fs, struct stat *stbuf)
+{
+    int err, fd = local_fid_fd(fid_type, fs);
+
     err = fstat(fd, stbuf);
     if (err) {
         return err;
@@ -1167,13 +1174,7 @@  out:
 static int local_fsync(FsContext *ctx, int fid_type,
                        V9fsFidOpenState *fs, int datasync)
 {
-    int fd;
-
-    if (fid_type == P9_FID_DIR) {
-        fd = dirfd(fs->dir.stream);
-    } else {
-        fd = fs->fd;
-    }
+    int fd = local_fid_fd(fid_type, fs);
 
     if (datasync) {
         return qemu_fdatasync(fd);