diff mbox

[V9fs-developer,03/13] 9p: introduce the v9fs_get_fd_fid() helper

Message ID 146702048052.5764.3687111665869095201.stgit@bahia.lan (mailing list archive)
State Superseded, archived
Headers show

Commit Message

Greg Kurz June 27, 2016, 9:41 a.m. UTC
This will be used by all file descriptor based ops.

Signed-off-by: Greg Kurz <groug@kaod.org>
---
 hw/9pfs/9p-handle.c |   12 ++----------
 hw/9pfs/9p-local.c  |   12 ++----------
 hw/9pfs/9p-proxy.c  |   12 ++----------
 hw/9pfs/9p.c        |   13 +++++++++++++
 hw/9pfs/9p.h        |    2 ++
 5 files changed, 21 insertions(+), 30 deletions(-)



------------------------------------------------------------------------------
Attend Shape: An AT&T Tech Expo July 15-16. Meet us at AT&T Park in San
Francisco, CA to explore cutting-edge tech and listen to tech luminaries
present their vision of the future. This family event has something for
everyone, including kids. Get more information and register today.
http://sdm.link/attshape
diff mbox

Patch

diff --git a/hw/9pfs/9p-handle.c b/hw/9pfs/9p-handle.c
index 3d77594f9245..2e741535df24 100644
--- a/hw/9pfs/9p-handle.c
+++ b/hw/9pfs/9p-handle.c
@@ -259,11 +259,7 @@  static int handle_fstat(FsContext *fs_ctx, int fid_type,
 {
     int fd;
 
-    if (fid_type == P9_FID_DIR) {
-        fd = dirfd(fs->dir.stream);
-    } else {
-        fd = fs->fd;
-    }
+    fd = v9fs_get_fd_fid(fid_type, fs);
     return fstat(fd, stbuf);
 }
 
@@ -406,11 +402,7 @@  static int handle_fsync(FsContext *ctx, int fid_type,
 {
     int fd;
 
-    if (fid_type == P9_FID_DIR) {
-        fd = dirfd(fs->dir.stream);
-    } else {
-        fd = fs->fd;
-    }
+    fd = v9fs_get_fd_fid(fid_type, fs);
 
     if (datasync) {
         return qemu_fdatasync(fd);
diff --git a/hw/9pfs/9p-local.c b/hw/9pfs/9p-local.c
index b363711fe2f0..6804c6558b8e 100644
--- a/hw/9pfs/9p-local.c
+++ b/hw/9pfs/9p-local.c
@@ -630,11 +630,7 @@  static int local_fstat(FsContext *fs_ctx, int fid_type,
 {
     int err, fd;
 
-    if (fid_type == P9_FID_DIR) {
-        fd = dirfd(fs->dir.stream);
-    } else {
-        fd = fs->fd;
-    }
+    fd = v9fs_get_fd_fid(fid_type, fs);
 
     err = fstat(fd, stbuf);
     if (err) {
@@ -1001,11 +997,7 @@  static int local_fsync(FsContext *ctx, int fid_type,
 {
     int fd;
 
-    if (fid_type == P9_FID_DIR) {
-        fd = dirfd(fs->dir.stream);
-    } else {
-        fd = fs->fd;
-    }
+    fd = v9fs_get_fd_fid(fid_type, fs);
 
     if (datasync) {
         return qemu_fdatasync(fd);
diff --git a/hw/9pfs/9p-proxy.c b/hw/9pfs/9p-proxy.c
index f265501eac1d..d78ff7b1bd8d 100644
--- a/hw/9pfs/9p-proxy.c
+++ b/hw/9pfs/9p-proxy.c
@@ -788,11 +788,7 @@  static int proxy_fstat(FsContext *fs_ctx, int fid_type,
 {
     int fd;
 
-    if (fid_type == P9_FID_DIR) {
-        fd = dirfd(fs->dir.stream);
-    } else {
-        fd = fs->fd;
-    }
+    fd = v9fs_get_fd_fid(fid_type, fs);
     return fstat(fd, stbuf);
 }
 
@@ -933,11 +929,7 @@  static int proxy_fsync(FsContext *ctx, int fid_type,
 {
     int fd;
 
-    if (fid_type == P9_FID_DIR) {
-        fd = dirfd(fs->dir.stream);
-    } else {
-        fd = fs->fd;
-    }
+    fd = v9fs_get_fd_fid(fid_type, fs);
 
     if (datasync) {
         return qemu_fdatasync(fd);
diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c
index 9acff9293c60..626d4aa8ebb6 100644
--- a/hw/9pfs/9p.c
+++ b/hw/9pfs/9p.c
@@ -240,6 +240,19 @@  static int v9fs_reopen_fid(V9fsPDU *pdu, V9fsFidState *f)
     return err;
 }
 
+int v9fs_get_fd_fid(int fid_type, V9fsFidOpenState *fs)
+{
+    int fd = -1;
+
+    if (fid_type == P9_FID_DIR) {
+        fd = dirfd(fs->dir.stream);
+    } else if (fid_type == P9_FID_FILE) {
+        fd = fs->fd;
+    }
+
+    return fd;
+}
+
 static V9fsFidState *get_fid(V9fsPDU *pdu, int32_t fid)
 {
     int err;
diff --git a/hw/9pfs/9p.h b/hw/9pfs/9p.h
index d2030fdf56e9..d0ccc0089771 100644
--- a/hw/9pfs/9p.h
+++ b/hw/9pfs/9p.h
@@ -202,6 +202,8 @@  union V9fsFidOpenState {
     void *private;
 };
 
+extern int v9fs_get_fd_fid(int fid_type, V9fsFidOpenState *fs);
+
 struct V9fsFidState
 {
     int fid_type;