From: Greg Kurz <[email protected]>

Factor out duplicated code to a single helper. More users to come.

Signed-off-by: Greg Kurz <[email protected]>
Reviewed-by: Christian Schoenebeck <[email protected]>
Message-Id: <[email protected]>
Signed-off-by: Christian Schoenebeck <[email protected]>
(cherry picked from commit 4f82ce8cd94f2601fb2b2e4cfe0cf5b44131817e)
(Mjt: pick this one up so subsequent commits are applied cleanly)
Signed-off-by: Michael Tokarev <[email protected]>

diff --git a/hw/9pfs/9p-local.c b/hw/9pfs/9p-local.c
index c5309c5ba45..cba3e945f99 100644
--- a/hw/9pfs/9p-local.c
+++ b/hw/9pfs/9p-local.c
@@ -766,16 +766,19 @@ 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;
-
     if (fid_type == P9_FID_DIR) {
-        fd = dirfd(fs->dir.stream);
+        return dirfd(fs->dir.stream);
     } else {
-        fd = fs->fd;
+        return fs->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) {
@@ -1167,13 +1170,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);
-- 
2.47.3


Reply via email to