Skip to contentSkip to conversation

9pfs: disentangling virtio and generic code

PATCH Superseded Wei Liu 5 participants 46 messages Jan 5, 2016 – Jan 7, 2016 Kbuild

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Wei Liu

author
#0 lore raw

cover 9pfs: disentangling virtio and generic code

Hi all

Back in 2015 summer one of our OPW interns Linda Jacobson explored the possibility of making 9pfs work on Xen. It turned out lots of code in QEMU can be reused.

This series refactors 9pfs related code:

1. Rename a bunch of files and functions to make clear they are generic.
2. Only export two functions (marshal and unmarshal) from transport to generic code.
3. disentangle virtio transport code and generic 9pfs code.
4. Some function name clean-up.

To make sure this series doesn't break compilation a rune is use to compile every commit.

$ git rebase -i origin/master --exec "make -j16 clean; ./configure --target-list=x86_64-softmmu --enable-virtfs --enable-kvm; make -j16 && echo ok."

Three use cases are tested:

1. Local file system driver with passthrough security policy
./qemu-system-x86_64 -L . -hda /dev/DATA/jessie -vnc 0.0.0.0:0,to=99 -fsdev local,path=/root/qemu,security_model=passthrough,id=fs1 -device virtio-9p-pci,fsdev=fs1,mount_tag=qemu &

2. Local file system driver with mapped security policy
./qemu-system-x86_64 -L . -hda /dev/DATA/jessie -vnc 0.0.0.0:0,to=99 -fsdev local,path=/root/qemu,security_model=mapped,id=fs1 -device virtio-9p-pci,fsdev=fs1,mount_tag=qemu &

3. Proxy file system driver
./virtfs-proxy-helper -p /root/qemu -n -s virtfs-helper-sock -u 0 -g 0 &
./qemu-system-x86_64 -L . -hda /dev/DATA/jessie -vnc 0.0.0.0:0,to=99 -fsdev proxy,socket=virtfs-helper-sock,id=fs1 -device virtio-9p-pci,fsdev=fs1,mount_tag=qemu &

During each of the tests, mounting, unmounting, read and write operations are performed. In "mapped" test, getfattr in host was used to inspect the attributes.

Let me know if you would like to see more tests.

Xen transport is still under development. I figure it would be better to post this series as soon as possible because rebasing such huge series from time to time is prone to error.

Comments are welcome. Thanks!

Wei.
---
Cc: "Aneesh Kumar K.V" <[email protected]>
Cc: Greg Kurz <[email protected]>
Cc: "Michael S. Tsirkin" <[email protected]>
Cc: Stefano Stabellini <[email protected]>
---

Wei Liu (22):
9pfs: rename virtio-9p-coth.{c,h} to coth.{c,h}
9pfs: rename virtio-9p-handle.c to 9p-handle.c
9pfs: rename virtio-9p-handle.c to 9p-handle.c
9pfs: rename virtio-9p-posix-acl.c to 9p-posix-acl.c 9pfs: rename virtio-9p-proxy.{c,h} to 9p-proxy.{c,h} 9pfs: rename virtio-9p-synth.{c,h} to 9p-synth.{c,h} 9pfs: rename virtio-9p-xattr{,-user}.{c,h} to 9p-xattr{,-user}.{c,h} 9pfs: merge hw/virtio/virtio-9p.h into hw/9pfs/virtio-9p.h 9pfs: remove dead code
fsdev: break out 9p-marshal.{c,h} from virtio-9p-marshal.{c,h}
fsdev: 9p-marshal: introduce V9fsBlob
9pfs: use V9fsBlob to transmit xattr
fsdev: rename virtio-9p-marshal.{c,h} to 9p-iov-marshal.{c,h} 9pfs: PDU processing functions don't need to take V9fsState as
argument
9pfs: PDU processing functions should start pdu_ prefix 9pfs: make pdu_{,un}marshal proper functions
9pfs: factor out virtio_pdu_{,un}marshal
9pfs: factor out pdu_push_and_notify
9pfs: break out virtio_init_iov_from_pdu
9pfs: break out generic code from virtio-9p.{c,h}
9pfs: factor out v9fs_device_{,un}realize_common
9pfs: disentangle V9fsState

 Makefile                                           |   2 +-
 fsdev/{virtio-9p-marshal.c => 9p-iov-marshal.c}    | 205 ++++++-----
 fsdev/9p-iov-marshal.h                             |  15 +
 fsdev/9p-marshal.c                                 |  64 ++++
 fsdev/{virtio-9p-marshal.h => 9p-marshal.h}        |  26 +-
 fsdev/Makefile.objs                                |   2 +-
 fsdev/virtfs-proxy-helper.c                        |   6 +-
 hw/9pfs/{virtio-9p-handle.c => 9p-handle.c}        |   7 +-
 hw/9pfs/{virtio-9p-local.c => 9p-local.c}          |   7 +-
 hw/9pfs/{virtio-9p-posix-acl.c => 9p-posix-acl.c}  |   7 +-
 hw/9pfs/{virtio-9p-proxy.c => 9p-proxy.c}          |   7 +-
 hw/9pfs/{virtio-9p-proxy.h => 9p-proxy.h}          |  10 +-
 hw/9pfs/{virtio-9p-synth.c => 9p-synth.c}          |   6 +-
 hw/9pfs/{virtio-9p-synth.h => 9p-synth.h}          |   6 +-
 .../{virtio-9p-xattr-user.c => 9p-xattr-user.c}    |   7 +-
 hw/9pfs/{virtio-9p-xattr.c => 9p-xattr.c}          |   7 +-
 hw/9pfs/{virtio-9p-xattr.h => 9p-xattr.h}          |   6 +-
 hw/9pfs/{virtio-9p.c => 9p.c}                      | 301 ++++++++++------
 hw/9pfs/9p.h                                       | 335 ++++++++++++++++++
 hw/9pfs/Makefile.objs                              |  14 +-
 hw/9pfs/codir.c                                    |   2 +-
 hw/9pfs/cofile.c                                   |   2 +-
 hw/9pfs/cofs.c                                     |   2 +-
 hw/9pfs/{virtio-9p-coth.c => coth.c}               |   4 +-
 hw/9pfs/{virtio-9p-coth.h => coth.h}               |  15 +-
 hw/9pfs/coxattr.c                                  |   2 +-
 hw/9pfs/virtio-9p-device.c                         | 196 ++++++-----
 hw/9pfs/virtio-9p.h                                | 391 +--------------------
 hw/s390x/virtio-ccw.h                              |   2 +-
 hw/virtio/virtio-pci.h                             |   4 +-
 include/hw/virtio/virtio-9p.h                      |  24 --
 31 files changed, 927 insertions(+), 757 deletions(-)
 rename fsdev/{virtio-9p-marshal.c => 9p-iov-marshal.c} (53%)
 create mode 100644 fsdev/9p-iov-marshal.h
 create mode 100644 fsdev/9p-marshal.c
 rename fsdev/{virtio-9p-marshal.h => 9p-marshal.h} (78%)
 rename hw/9pfs/{virtio-9p-handle.c => 9p-handle.c} (99%)
 rename hw/9pfs/{virtio-9p-local.c => 9p-local.c} (99%)
 rename hw/9pfs/{virtio-9p-posix-acl.c => 9p-posix-acl.c} (97%)
 rename hw/9pfs/{virtio-9p-proxy.c => 9p-proxy.c} (99%)
 rename hw/9pfs/{virtio-9p-proxy.h => 9p-proxy.h} (89%)
 rename hw/9pfs/{virtio-9p-synth.c => 9p-synth.c} (99%)
 rename hw/9pfs/{virtio-9p-synth.h => 9p-synth.h} (94%)
 rename hw/9pfs/{virtio-9p-xattr-user.c => 9p-xattr-user.c} (96%)
 rename hw/9pfs/{virtio-9p-xattr.c => 9p-xattr.c} (97%)
 rename hw/9pfs/{virtio-9p-xattr.h => 9p-xattr.h} (97%)
 rename hw/9pfs/{virtio-9p.c => 9p.c} (93%)
 create mode 100644 hw/9pfs/9p.h
 rename hw/9pfs/{virtio-9p-coth.c => coth.c} (95%)
 rename hw/9pfs/{virtio-9p-coth.h => coth.h} (96%)
 delete mode 100644 include/hw/virtio/virtio-9p.h
Signature · 1 line
2.1.4
author
#1 lore raw

PATCH 1/22 9pfs: rename virtio-9p-coth.{c, h} to coth.{c, h}

Those two files are not virtio specific. Rename them to use generic names.

Fix includes in various C files. Change define guards and comments in header files.

---
 hw/9pfs/Makefile.objs                | 2 +-
 hw/9pfs/codir.c                      | 2 +-
 hw/9pfs/cofile.c                     | 2 +-
 hw/9pfs/cofs.c                       | 2 +-
 hw/9pfs/{virtio-9p-coth.c => coth.c} | 4 ++--
 hw/9pfs/{virtio-9p-coth.h => coth.h} | 6 +++---
 hw/9pfs/coxattr.c                    | 2 +-
 hw/9pfs/virtio-9p-device.c           | 2 +-
 hw/9pfs/virtio-9p.c                  | 2 +-
 9 files changed, 12 insertions(+), 12 deletions(-)
 rename hw/9pfs/{virtio-9p-coth.c => coth.c} (95%)
 rename hw/9pfs/{virtio-9p-coth.h => coth.h} (98%)
hw/9pfs/Makefile.objs +1 -1
index 1e9b595..76dadbe 100644
@@ -1,7 +1,7 @@
 common-obj-y  = virtio-9p.o
 common-obj-y += virtio-9p-local.o virtio-9p-xattr.o
 common-obj-y += virtio-9p-xattr-user.o virtio-9p-posix-acl.o
-common-obj-y += virtio-9p-coth.o cofs.o codir.o cofile.o
+common-obj-y += coth.o cofs.o codir.o cofile.o
 common-obj-y += coxattr.o virtio-9p-synth.o
 common-obj-$(CONFIG_OPEN_BY_HANDLE) +=  virtio-9p-handle.o
 common-obj-y += virtio-9p-proxy.o
hw/9pfs/codir.c +1 -1
index ec9cc7f..5a4f74d 100644
@@ -15,7 +15,7 @@
 #include "fsdev/qemu-fsdev.h"
 #include "qemu/thread.h"
 #include "qemu/coroutine.h"
-#include "virtio-9p-coth.h"
+#include "coth.h"
 
 int v9fs_co_readdir_r(V9fsPDU *pdu, V9fsFidState *fidp, struct dirent *dent,
                       struct dirent **result)
hw/9pfs/cofile.c +1 -1
index 7cb55ee..893df2c 100644
@@ -15,7 +15,7 @@
 #include "fsdev/qemu-fsdev.h"
 #include "qemu/thread.h"
 #include "qemu/coroutine.h"
-#include "virtio-9p-coth.h"
+#include "coth.h"
 
 int v9fs_co_st_gen(V9fsPDU *pdu, V9fsPath *path, mode_t st_mode,
                    V9fsStatDotl *v9stat)
hw/9pfs/cofs.c +1 -1
index e1953a9..7b4202b 100644
@@ -15,7 +15,7 @@
 #include "fsdev/qemu-fsdev.h"
 #include "qemu/thread.h"
 #include "qemu/coroutine.h"
-#include "virtio-9p-coth.h"
+#include "coth.h"
 
 static ssize_t __readlink(V9fsState *s, V9fsPath *path, V9fsString *buf)
 {
hw/9pfs/coth.c renamed from hw/9pfs/virtio-9p-coth.c +2 -2
similarity index 95%
rename from hw/9pfs/virtio-9p-coth.c
rename to hw/9pfs/coth.c
index ab9425c..56772d6 100644
@@ -1,5 +1,5 @@
 /*
- * Virtio 9p backend
+ * 9p backend
  *
  * Copyright IBM, Corp. 2010
  *
@@ -16,7 +16,7 @@
 #include "block/thread-pool.h"
 #include "qemu/coroutine.h"
 #include "qemu/main-loop.h"
-#include "virtio-9p-coth.h"
+#include "coth.h"
 
 /* Called from QEMU I/O thread.  */
 static void coroutine_enter_cb(void *opaque, int ret)
hw/9pfs/coth.h renamed from hw/9pfs/virtio-9p-coth.h +3 -3
similarity index 98%
rename from hw/9pfs/virtio-9p-coth.h
rename to hw/9pfs/coth.h
index 4ac1aaf..209fc6a 100644
@@ -1,5 +1,5 @@
 /*
- * Virtio 9p backend
+ * 9p backend
  *
  * Copyright IBM, Corp. 2010
  *
@@ -12,8 +12,8 @@
  *
  */
 
-#ifndef _QEMU_VIRTIO_9P_COTH_H
-#define _QEMU_VIRTIO_9P_COTH_H
+#ifndef _QEMU_9P_COTH_H
+#define _QEMU_9P_COTH_H
 
 #include "qemu/thread.h"
 #include "qemu/coroutine.h"
hw/9pfs/coxattr.c +1 -1
index 55c0d23..0590cbf 100644
@@ -15,7 +15,7 @@
 #include "fsdev/qemu-fsdev.h"
 #include "qemu/thread.h"
 #include "qemu/coroutine.h"
-#include "virtio-9p-coth.h"
+#include "coth.h"
 
 int v9fs_co_llistxattr(V9fsPDU *pdu, V9fsPath *path, void *value, size_t size)
 {
hw/9pfs/virtio-9p-device.c +1 -1
index b42d3b3..667b54a 100644
@@ -18,7 +18,7 @@
 #include "virtio-9p.h"
 #include "fsdev/qemu-fsdev.h"
 #include "virtio-9p-xattr.h"
-#include "virtio-9p-coth.h"
+#include "coth.h"
 #include "hw/virtio/virtio-access.h"
 
 static uint64_t virtio_9p_get_features(VirtIODevice *vdev, uint64_t features,
hw/9pfs/virtio-9p.c +1 -1
index f972731..0f178de 100644
@@ -19,7 +19,7 @@
 #include "virtio-9p.h"
 #include "fsdev/qemu-fsdev.h"
 #include "virtio-9p-xattr.h"
-#include "virtio-9p-coth.h"
+#include "coth.h"
 #include "trace.h"
 #include "migration/migration.h"
 
Signature · 1 line
2.1.4
author
#2 lore raw

PATCH 2/22 9pfs: rename virtio-9p-handle.c to 9p-handle.c

In reply to Wei Liu

This file is not virtio specific. Rename it to use generic name.

Fix comment and remove unneeded inclusion of virtio.h.

---
 hw/9pfs/{virtio-9p-handle.c => 9p-handle.c} | 3 +--
 hw/9pfs/Makefile.objs                       | 2 +-
 2 files changed, 2 insertions(+), 3 deletions(-)
 rename hw/9pfs/{virtio-9p-handle.c => 9p-handle.c} (99%)
hw/9pfs/9p-handle.c renamed from hw/9pfs/virtio-9p-handle.c +1 -2
similarity index 99%
rename from hw/9pfs/virtio-9p-handle.c
rename to hw/9pfs/9p-handle.c
index 13eabb9..a48dbc9 100644
@@ -1,5 +1,5 @@
 /*
- * Virtio 9p handle callback
+ * 9p handle callback
  *
  * Copyright IBM, Corp. 2011
  *
@@ -11,7 +11,6 @@
  *
  */
 
-#include "hw/virtio/virtio.h"
 #include "virtio-9p.h"
 #include "virtio-9p-xattr.h"
 #include <arpa/inet.h>
hw/9pfs/Makefile.objs +1 -1
index 76dadbe..9fdd8a4 100644
@@ -3,7 +3,7 @@ common-obj-y += virtio-9p-local.o virtio-9p-xattr.o
 common-obj-y += virtio-9p-xattr-user.o virtio-9p-posix-acl.o
 common-obj-y += coth.o cofs.o codir.o cofile.o
 common-obj-y += coxattr.o virtio-9p-synth.o
-common-obj-$(CONFIG_OPEN_BY_HANDLE) +=  virtio-9p-handle.o
+common-obj-$(CONFIG_OPEN_BY_HANDLE) +=  9p-handle.o
 common-obj-y += virtio-9p-proxy.o
 
 obj-y += virtio-9p-device.o
Signature · 1 line
2.1.4
author
#3 lore raw

PATCH 3/22 9pfs: rename virtio-9p-handle.c to 9p-handle.c

In reply to Wei Liu

This file is not virtio specific. Rename it to use generic name.

Fix comment and remove unneeded inclusion of virtio.h.

---
 hw/9pfs/{virtio-9p-local.c => 9p-local.c} | 3 +--
 hw/9pfs/Makefile.objs                     | 2 +-
 2 files changed, 2 insertions(+), 3 deletions(-)
 rename hw/9pfs/{virtio-9p-local.c => 9p-local.c} (99%)
hw/9pfs/9p-local.c renamed from hw/9pfs/virtio-9p-local.c +1 -2
similarity index 99%
rename from hw/9pfs/virtio-9p-local.c
rename to hw/9pfs/9p-local.c
index f1f2e25..877ad86 100644
@@ -1,5 +1,5 @@
 /*
- * Virtio 9p Posix callback
+ * 9p Posix callback
  *
  * Copyright IBM, Corp. 2010
  *
@@ -11,7 +11,6 @@
  *
  */
 
-#include "hw/virtio/virtio.h"
 #include "virtio-9p.h"
 #include "virtio-9p-xattr.h"
 #include "fsdev/qemu-fsdev.h"   /* local_ops */
hw/9pfs/Makefile.objs +1 -1
index 9fdd8a4..5059681 100644
@@ -1,5 +1,5 @@
 common-obj-y  = virtio-9p.o
-common-obj-y += virtio-9p-local.o virtio-9p-xattr.o
+common-obj-y += 9p-local.o virtio-9p-xattr.o
 common-obj-y += virtio-9p-xattr-user.o virtio-9p-posix-acl.o
 common-obj-y += coth.o cofs.o codir.o cofile.o
 common-obj-y += coxattr.o virtio-9p-synth.o
Signature · 1 line
2.1.4
author
#6 lore raw

PATCH 4/22 9pfs: rename virtio-9p-posix-acl.c to 9p-posix-acl.c

In reply to Wei Liu

This file is not virtio specific. Rename it to use generic name.

Fix comment and remove unneeded inclusion of virtio.h.

---
 hw/9pfs/{virtio-9p-posix-acl.c => 9p-posix-acl.c} | 3 +--
 hw/9pfs/Makefile.objs                             | 2 +-
 2 files changed, 2 insertions(+), 3 deletions(-)
 rename hw/9pfs/{virtio-9p-posix-acl.c => 9p-posix-acl.c} (98%)
hw/9pfs/9p-posix-acl.c renamed from hw/9pfs/virtio-9p-posix-acl.c +1 -2
similarity index 98%
rename from hw/9pfs/virtio-9p-posix-acl.c
rename to hw/9pfs/9p-posix-acl.c
index 09dad07..1ee7bdc 100644
@@ -1,5 +1,5 @@
 /*
- * Virtio 9p system.posix* xattr callback
+ * 9p system.posix* xattr callback
  *
  * Copyright IBM, Corp. 2010
  *
@@ -13,7 +13,6 @@
 
 #include <sys/types.h>
 #include "qemu/xattr.h"
-#include "hw/virtio/virtio.h"
 #include "virtio-9p.h"
 #include "fsdev/file-op-9p.h"
 #include "virtio-9p-xattr.h"
hw/9pfs/Makefile.objs +1 -1
index 5059681..0721462 100644
@@ -1,6 +1,6 @@
 common-obj-y  = virtio-9p.o
 common-obj-y += 9p-local.o virtio-9p-xattr.o
-common-obj-y += virtio-9p-xattr-user.o virtio-9p-posix-acl.o
+common-obj-y += virtio-9p-xattr-user.o 9p-posix-acl.o
 common-obj-y += coth.o cofs.o codir.o cofile.o
 common-obj-y += coxattr.o virtio-9p-synth.o
 common-obj-$(CONFIG_OPEN_BY_HANDLE) +=  9p-handle.o
Signature · 1 line
2.1.4
author
#7 lore raw

PATCH 5/22 9pfs: rename virtio-9p-proxy.{c, h} to 9p-proxy.{c, h}

In reply to Wei Liu

Those two files are not virtio specific. Rename them to use generic names.

Fix includes in various C files. Change define guards and comments in header files.

---
 fsdev/virtfs-proxy-helper.c               | 2 +-
 hw/9pfs/{virtio-9p-proxy.c => 9p-proxy.c} | 5 ++---
 hw/9pfs/{virtio-9p-proxy.h => 9p-proxy.h} | 6 +++---
 hw/9pfs/Makefile.objs                     | 2 +-
 4 files changed, 7 insertions(+), 8 deletions(-)
 rename hw/9pfs/{virtio-9p-proxy.c => 9p-proxy.c} (99%)
 rename hw/9pfs/{virtio-9p-proxy.h => 9p-proxy.h} (95%)
fsdev/virtfs-proxy-helper.c +1 -1
index ad1da0d..7753654 100644
@@ -24,7 +24,7 @@
 #include "qemu/sockets.h"
 #include "qemu/xattr.h"
 #include "virtio-9p-marshal.h"
-#include "hw/9pfs/virtio-9p-proxy.h"
+#include "hw/9pfs/9p-proxy.h"
 #include "fsdev/virtio-9p-marshal.h"
 
 #define PROGNAME "virtfs-proxy-helper"
hw/9pfs/9p-proxy.c renamed from hw/9pfs/virtio-9p-proxy.c +2 -3
similarity index 99%
rename from hw/9pfs/virtio-9p-proxy.c
rename to hw/9pfs/9p-proxy.c
index 1bc7881..67c1fb9 100644
@@ -1,5 +1,5 @@
 /*
- * Virtio 9p Proxy callback
+ * 9p Proxy callback
  *
  * Copyright IBM, Corp. 2011
  *
@@ -11,11 +11,10 @@
  */
 #include <sys/socket.h>
 #include <sys/un.h>
-#include "hw/virtio/virtio.h"
 #include "virtio-9p.h"
 #include "qemu/error-report.h"
 #include "fsdev/qemu-fsdev.h"
-#include "virtio-9p-proxy.h"
+#include "9p-proxy.h"
 
 typedef struct V9fsProxy {
     int sockfd;
hw/9pfs/9p-proxy.h renamed from hw/9pfs/virtio-9p-proxy.h +3 -3
similarity index 95%
rename from hw/9pfs/virtio-9p-proxy.h
rename to hw/9pfs/9p-proxy.h
index 005c1ad..56150b9 100644
@@ -1,5 +1,5 @@
 /*
- * Virtio 9p Proxy callback
+ * 9p Proxy callback
  *
  * Copyright IBM, Corp. 2011
  *
@@ -9,8 +9,8 @@
  * This work is licensed under the terms of the GNU GPL, version 2.  See
  * the COPYING file in the top-level directory.
  */
-#ifndef _QEMU_VIRTIO_9P_PROXY_H
-#define _QEMU_VIRTIO_9P_PROXY_H
+#ifndef _QEMU_9P_PROXY_H
+#define _QEMU_9P_PROXY_H
 
 #define PROXY_MAX_IO_SZ (64 * 1024)
 #define V9FS_FD_VALID INT_MAX
hw/9pfs/Makefile.objs +1 -1
index 0721462..cd5d146 100644
@@ -4,6 +4,6 @@ common-obj-y += virtio-9p-xattr-user.o 9p-posix-acl.o
 common-obj-y += coth.o cofs.o codir.o cofile.o
 common-obj-y += coxattr.o virtio-9p-synth.o
 common-obj-$(CONFIG_OPEN_BY_HANDLE) +=  9p-handle.o
-common-obj-y += virtio-9p-proxy.o
+common-obj-y += 9p-proxy.o
 
 obj-y += virtio-9p-device.o
Signature · 1 line
2.1.4
author
#8 lore raw

PATCH 6/22 9pfs: rename virtio-9p-synth.{c, h} to 9p-synth.{c, h}

In reply to Wei Liu

These two files are not virtio specific. Rename them to use generic names.

Fix includes in various C files. Change define guards and comments in header files.

---
 hw/9pfs/{virtio-9p-synth.c => 9p-synth.c} | 2 +-
 hw/9pfs/{virtio-9p-synth.h => 9p-synth.h} | 6 +++---
 hw/9pfs/Makefile.objs                     | 2 +-
 3 files changed, 5 insertions(+), 5 deletions(-)
 rename hw/9pfs/{virtio-9p-synth.c => 9p-synth.c} (99%)
 rename hw/9pfs/{virtio-9p-synth.h => 9p-synth.h} (94%)
hw/9pfs/9p-synth.c renamed from hw/9pfs/virtio-9p-synth.c +1 -1
similarity index 99%
rename from hw/9pfs/virtio-9p-synth.c
rename to hw/9pfs/9p-synth.c
index a0ab9a8..6d34b89 100644
@@ -16,7 +16,7 @@
 #include "virtio-9p.h"
 #include "virtio-9p-xattr.h"
 #include "fsdev/qemu-fsdev.h"
-#include "virtio-9p-synth.h"
+#include "9p-synth.h"
 #include "qemu/rcu.h"
 #include "qemu/rcu_queue.h"
 #include <sys/stat.h>
hw/9pfs/9p-synth.h renamed from hw/9pfs/virtio-9p-synth.h +3 -3
similarity index 94%
rename from hw/9pfs/virtio-9p-synth.h
rename to hw/9pfs/9p-synth.h
index ab05a8e..eaf5a0c 100644
@@ -1,5 +1,5 @@
 /*
- * Virtio 9p
+ * 9p
  *
  * Copyright IBM, Corp. 2011
  *
@@ -10,8 +10,8 @@
  * the COPYING file in the top-level directory.
  *
  */
-#ifndef HW_9PFS_VIRTIO9P_SYNTH_H
-#define HW_9PFS_VIRTIO9P_SYNTH_H 1
+#ifndef HW_9PFS_SYNTH_H
+#define HW_9PFS_SYNTH_H 1
 
 #include <unistd.h>
 #include <sys/types.h>
hw/9pfs/Makefile.objs +1 -1
index cd5d146..ba62571 100644
@@ -2,7 +2,7 @@ common-obj-y  = virtio-9p.o
 common-obj-y += 9p-local.o virtio-9p-xattr.o
 common-obj-y += virtio-9p-xattr-user.o 9p-posix-acl.o
 common-obj-y += coth.o cofs.o codir.o cofile.o
-common-obj-y += coxattr.o virtio-9p-synth.o
+common-obj-y += coxattr.o 9p-synth.o
 common-obj-$(CONFIG_OPEN_BY_HANDLE) +=  9p-handle.o
 common-obj-y += 9p-proxy.o
 
Signature · 1 line
2.1.4
author
#9 lore raw

PATCH 7/22 9pfs: rename virtio-9p-xattr{, -user}.{c, h} to 9p-xattr{, -user}.{c, h}

In reply to Wei Liu

These three files are not virtio specific. Rename them to generic names.

Fix comments and header inclusion in various files.

---
 hw/9pfs/9p-handle.c                                 | 2 +-
 hw/9pfs/9p-local.c                                  | 2 +-
 hw/9pfs/9p-posix-acl.c                              | 2 +-
 hw/9pfs/9p-synth.c                                  | 2 +-
 hw/9pfs/{virtio-9p-xattr-user.c => 9p-xattr-user.c} | 5 ++---
 hw/9pfs/{virtio-9p-xattr.c => 9p-xattr.c}           | 5 ++---
 hw/9pfs/{virtio-9p-xattr.h => 9p-xattr.h}           | 6 +++---
 hw/9pfs/Makefile.objs                               | 4 ++--
 hw/9pfs/virtio-9p-device.c                          | 2 +-
 hw/9pfs/virtio-9p.c                                 | 2 +-
 10 files changed, 15 insertions(+), 17 deletions(-)
 rename hw/9pfs/{virtio-9p-xattr-user.c => 9p-xattr-user.c} (97%)
 rename hw/9pfs/{virtio-9p-xattr.c => 9p-xattr.c} (97%)
 rename hw/9pfs/{virtio-9p-xattr.h => 9p-xattr.h} (97%)
hw/9pfs/9p-handle.c +1 -1
index a48dbc9..51a9d15 100644
@@ -12,7 +12,7 @@
  */
 
 #include "virtio-9p.h"
-#include "virtio-9p-xattr.h"
+#include "9p-xattr.h"
 #include <arpa/inet.h>
 #include <pwd.h>
 #include <grp.h>
hw/9pfs/9p-local.c +1 -1
index 877ad86..ac553e0 100644
@@ -12,7 +12,7 @@
  */
 
 #include "virtio-9p.h"
-#include "virtio-9p-xattr.h"
+#include "9p-xattr.h"
 #include "fsdev/qemu-fsdev.h"   /* local_ops */
 #include <arpa/inet.h>
 #include <pwd.h>
hw/9pfs/9p-posix-acl.c +1 -1
index 1ee7bdc..073af39 100644
@@ -15,7 +15,7 @@
 #include "qemu/xattr.h"
 #include "virtio-9p.h"
 #include "fsdev/file-op-9p.h"
-#include "virtio-9p-xattr.h"
+#include "9p-xattr.h"
 
 #define MAP_ACL_ACCESS "user.virtfs.system.posix_acl_access"
 #define MAP_ACL_DEFAULT "user.virtfs.system.posix_acl_default"
hw/9pfs/9p-synth.c +1 -1
index 6d34b89..b1064e3 100644
@@ -14,7 +14,7 @@
 
 #include "hw/virtio/virtio.h"
 #include "virtio-9p.h"
-#include "virtio-9p-xattr.h"
+#include "9p-xattr.h"
 #include "fsdev/qemu-fsdev.h"
 #include "9p-synth.h"
 #include "qemu/rcu.h"
hw/9pfs/9p-xattr-user.c renamed from hw/9pfs/virtio-9p-xattr-user.c +2 -3
similarity index 97%
rename from hw/9pfs/virtio-9p-xattr-user.c
rename to hw/9pfs/9p-xattr-user.c
index 46133e0..163b158 100644
@@ -1,5 +1,5 @@
 /*
- * Virtio 9p user. xattr callback
+ * 9p user. xattr callback
  *
  * Copyright IBM, Corp. 2010
  *
@@ -12,10 +12,9 @@
  */
 
 #include <sys/types.h>
-#include "hw/virtio/virtio.h"
 #include "virtio-9p.h"
 #include "fsdev/file-op-9p.h"
-#include "virtio-9p-xattr.h"
+#include "9p-xattr.h"
 
 
 static ssize_t mp_user_getxattr(FsContext *ctx, const char *path,
hw/9pfs/9p-xattr.c renamed from hw/9pfs/virtio-9p-xattr.c +2 -3
similarity index 97%
rename from hw/9pfs/virtio-9p-xattr.c
rename to hw/9pfs/9p-xattr.c
index 0718388..1d7861b 100644
@@ -1,5 +1,5 @@
 /*
- * Virtio 9p  xattr callback
+ * 9p  xattr callback
  *
  * Copyright IBM, Corp. 2010
  *
@@ -11,10 +11,9 @@
  *
  */
 
-#include "hw/virtio/virtio.h"
 #include "virtio-9p.h"
 #include "fsdev/file-op-9p.h"
-#include "virtio-9p-xattr.h"
+#include "9p-xattr.h"
 
 
 static XattrOperations *get_xattr_operations(XattrOperations **h,
hw/9pfs/9p-xattr.h renamed from hw/9pfs/virtio-9p-xattr.h +3 -3
similarity index 97%
rename from hw/9pfs/virtio-9p-xattr.h
rename to hw/9pfs/9p-xattr.h
index 327b32b..4d39a20 100644
@@ -1,5 +1,5 @@
 /*
- * Virtio 9p
+ * 9p
  *
  * Copyright IBM, Corp. 2010
  *
@@ -10,8 +10,8 @@
  * the COPYING file in the top-level directory.
  *
  */
-#ifndef _QEMU_VIRTIO_9P_XATTR_H
-#define _QEMU_VIRTIO_9P_XATTR_H
+#ifndef _QEMU_9P_XATTR_H
+#define _QEMU_9P_XATTR_H
 
 #include "qemu/xattr.h"
 
hw/9pfs/Makefile.objs +2 -2
index ba62571..838c5e1 100644
@@ -1,6 +1,6 @@
 common-obj-y  = virtio-9p.o
-common-obj-y += 9p-local.o virtio-9p-xattr.o
-common-obj-y += virtio-9p-xattr-user.o 9p-posix-acl.o
+common-obj-y += 9p-local.o 9p-xattr.o
+common-obj-y += 9p-xattr-user.o 9p-posix-acl.o
 common-obj-y += coth.o cofs.o codir.o cofile.o
 common-obj-y += coxattr.o 9p-synth.o
 common-obj-$(CONFIG_OPEN_BY_HANDLE) +=  9p-handle.o
hw/9pfs/virtio-9p-device.c +1 -1
index 667b54a..92ac19b 100644
@@ -17,7 +17,7 @@
 #include "qemu/sockets.h"
 #include "virtio-9p.h"
 #include "fsdev/qemu-fsdev.h"
-#include "virtio-9p-xattr.h"
+#include "9p-xattr.h"
 #include "coth.h"
 #include "hw/virtio/virtio-access.h"
 
hw/9pfs/virtio-9p.c +1 -1
index 0f178de..30ff828 100644
@@ -18,7 +18,7 @@
 #include "qemu/sockets.h"
 #include "virtio-9p.h"
 #include "fsdev/qemu-fsdev.h"
-#include "virtio-9p-xattr.h"
+#include "9p-xattr.h"
 #include "coth.h"
 #include "trace.h"
 #include "migration/migration.h"
Signature · 1 line
2.1.4
author
#10 lore raw

PATCH 8/22 9pfs: merge hw/virtio/virtio-9p.h into hw/9pfs/virtio-9p.h

In reply to Wei Liu

The deleted file only contained V9fsConf which wasn't virtio specific. Merge that to the general header of 9pfs.

Fixed header inclusions as I went along.

---
 hw/9pfs/virtio-9p-device.c    |  1 -
 hw/9pfs/virtio-9p.h           |  8 +++++++-
 hw/virtio/virtio-pci.h        |  1 -
 include/hw/virtio/virtio-9p.h | 24 ------------------------
 4 files changed, 7 insertions(+), 27 deletions(-)
 delete mode 100644 include/hw/virtio/virtio-9p.h
hw/9pfs/virtio-9p-device.c +0 -1
index 92ac19b..885b940 100644
@@ -12,7 +12,6 @@
  */
 
 #include "hw/virtio/virtio.h"
-#include "hw/virtio/virtio-9p.h"
 #include "hw/i386/pc.h"
 #include "qemu/sockets.h"
 #include "virtio-9p.h"
hw/9pfs/virtio-9p.h +7 -1
index d7a4dc1..ac4cb00 100644
@@ -9,7 +9,6 @@
 #include <glib.h>
 #include "standard-headers/linux/virtio_9p.h"
 #include "hw/virtio/virtio.h"
-#include "hw/virtio/virtio-9p.h"
 #include "fsdev/file-op-9p.h"
 #include "fsdev/virtio-9p-marshal.h"
 #include "qemu/thread.h"
@@ -156,6 +155,13 @@ enum {
     P9_FID_XATTR,
 };
 
+typedef struct V9fsConf
+{
+    /* tag name for the device */
+    char *tag;
+    char *fsdev_id;
+} V9fsConf;
+
 typedef struct V9fsXattr
 {
     int64_t copied_len;
hw/virtio/virtio-pci.h +0 -1
index a104ff2..7cf5974 100644
@@ -23,7 +23,6 @@
 #include "hw/virtio/virtio-scsi.h"
 #include "hw/virtio/virtio-balloon.h"
 #include "hw/virtio/virtio-bus.h"
-#include "hw/virtio/virtio-9p.h"
 #include "hw/virtio/virtio-input.h"
 #include "hw/virtio/virtio-gpu.h"
 #ifdef CONFIG_VIRTFS
include/hw/virtio/virtio-9p.h deleted +0 -24
deleted file mode 100644
index 65789db..0000000
@@ -1,24 +0,0 @@
-/*
- * Virtio 9p
- *
- * Copyright IBM, Corp. 2010
- *
- * Authors:
- *  Aneesh Kumar K.V <[email protected]>
- *
- * This work is licensed under the terms of the GNU GPL, version 2.  See
- * the COPYING file in the top-level directory.
- *
- */
-
-#ifndef QEMU_VIRTIO_9P_DEVICE_H
-#define QEMU_VIRTIO_9P_DEVICE_H
-
-typedef struct V9fsConf
-{
-    /* tag name for the device */
-    char *tag;
-    char *fsdev_id;
-} V9fsConf;
-
-#endif
Signature · 1 line
2.1.4
author
#11 lore raw

PATCH 9/22 9pfs: remove dead code

In reply to Wei Liu

Some structures virtio-9p.h have been unused since 2011 when relevant functions switched to use coroutines.

The declaration of pdu_packunpack and function do_pdu_unpack are useless.

The function virtio_9p_set_fd_limit is unused.

---
 hw/9pfs/virtio-9p.c | 11 ---------
 hw/9pfs/virtio-9p.h | 68 -----------------------------------------------------
 2 files changed, 79 deletions(-)
hw/9pfs/virtio-9p.c +0 -11
index 30ff828..084fa6a 100644
@@ -3287,14 +3287,3 @@ void handle_9p_output(VirtIODevice *vdev, VirtQueue *vq)
     }
     free_pdu(s, pdu);
 }
-
-static void __attribute__((__constructor__)) virtio_9p_set_fd_limit(void)
-{
-    struct rlimit rlim;
-    if (getrlimit(RLIMIT_NOFILE, &rlim) < 0) {
-        fprintf(stderr, "Failed to get the resource limit\n");
-        exit(1);
-    }
-    open_fd_hw = rlim.rlim_cur - MIN(400, rlim.rlim_cur/3);
-    open_fd_rc = rlim.rlim_cur/2;
-}
hw/9pfs/virtio-9p.h +0 -68

80 lines not on this page · raw message

Signature · 1 line
2.1.4
author
#18 lore raw

PATCH 11/22 fsdev: 9p-marshal: introduce V9fsBlob

In reply to Wei Liu

Introduce a concept of blob. It will be used to pack / unpack xattr value.

With this change there is no need to expose v9fs_pack to device code anymore.

---
 fsdev/9p-marshal.c        |  7 +++++++
 fsdev/9p-marshal.h        | 14 ++++++++++++++
 fsdev/virtio-9p-marshal.c | 26 ++++++++++++++++++++++++++
 3 files changed, 47 insertions(+)
fsdev/9p-marshal.c +7 -0
index 610978e..b457d49 100644
@@ -55,3 +55,10 @@ void v9fs_string_copy(V9fsString *lhs, V9fsString *rhs)
     v9fs_string_free(lhs);
     v9fs_string_sprintf(lhs, "%s", rhs->data);
 }
+
+void v9fs_blob_free(V9fsBlob *blob)
+{
+    g_free(blob->data);
+    blob->data = NULL;
+    blob->size = 0;
+}
fsdev/9p-marshal.h +14 -0
index e91b24e..5a0150b 100644
@@ -7,6 +7,12 @@ typedef struct V9fsString
     char *data;
 } V9fsString;
 
+typedef struct V9fsBlob
+{
+    uint16_t size;
+    void *data;
+} V9fsBlob;
+
 typedef struct V9fsQID
 {
     int8_t type;
@@ -81,4 +87,12 @@ extern void v9fs_string_null(V9fsString *str);
 extern void v9fs_string_sprintf(V9fsString *str, const char *fmt, ...);
 extern void v9fs_string_copy(V9fsString *lhs, V9fsString *rhs);
 
+static inline void v9fs_blob_init(V9fsBlob *blob)
+{
+    blob->data = NULL;
+    blob->size = 0;
+}
+
+extern void v9fs_blob_free(V9fsBlob *blob);
+
 #endif
fsdev/virtio-9p-marshal.c +26 -0
index f236bab..c3ac316 100644
@@ -142,6 +142,21 @@ ssize_t v9fs_unmarshal(struct iovec *out_sg, int out_num, size_t offset,
             }
             break;
         }
+        case 'B': {
+            V9fsBlob *blob = va_arg(ap, V9fsBlob *);
+            copied = v9fs_unmarshal(out_sg, out_num, offset, bswap,
+                                    "w", &blob->size);
+            if (copied > 0) {
+                offset += copied;
+                blob->data = g_malloc(blob->size);
+                copied = v9fs_unpack(blob->data, out_sg, out_num, offset,
+                                     blob->size);
+                if (copied < 0) {
+                    v9fs_blob_free(blob);
+                }
+            }
+            break;
+        }
         case 'Q': {
             V9fsQID *qidp = va_arg(ap, V9fsQID *);
             copied = v9fs_unmarshal(out_sg, out_num, offset, bswap, "bdq",
@@ -241,6 +256,17 @@ ssize_t v9fs_marshal(struct iovec *in_sg, int in_num, size_t offset,
             }
             break;
         }
+        case 'B': {
+            V9fsBlob *blob = va_arg(ap, V9fsBlob *);
+            copied = v9fs_marshal(in_sg, in_num, offset, bswap,
+                                  "w", blob->size);
+            if (copied > 0) {
+                offset += copied;
+                copied = v9fs_pack(in_sg, in_num, offset, blob->data,
+                                   blob->size);
+            }
+            break;
+        }
         case 'Q': {
             V9fsQID *qidp = va_arg(ap, V9fsQID *);
             copied = v9fs_marshal(in_sg, in_num, offset, bswap, "bdq",
Signature · 1 line
2.1.4
author
#15 lore raw

PATCH 10/22 fsdev: break out 9p-marshal.{c, h} from virtio-9p-marshal.{c, h}

In reply to Wei Liu

Break out some generic functions for marshaling 9p state. Pure code motion plus minor fixes for build system.

---
 Makefile                  |  2 +-
 fsdev/9p-marshal.c        | 57 ++++++++++++++++++++++++++++++++
 fsdev/9p-marshal.h        | 84 +++++++++++++++++++++++++++++++++++++++++++++++
 fsdev/Makefile.objs       |  2 +-
 fsdev/virtio-9p-marshal.c | 31 -----------------
 fsdev/virtio-9p-marshal.h | 79 +-------------------------------------------
 6 files changed, 144 insertions(+), 111 deletions(-)
 create mode 100644 fsdev/9p-marshal.c
 create mode 100644 fsdev/9p-marshal.h
Makefile +1 -1
index 82b2fc8..7e881d8 100644
@@ -240,7 +240,7 @@ qemu-io$(EXESUF): qemu-io.o $(block-obj-y) $(crypto-obj-y) $(qom-obj-y) libqemuu
 
 qemu-bridge-helper$(EXESUF): qemu-bridge-helper.o
 
-fsdev/virtfs-proxy-helper$(EXESUF): fsdev/virtfs-proxy-helper.o fsdev/virtio-9p-marshal.o libqemuutil.a libqemustub.a
+fsdev/virtfs-proxy-helper$(EXESUF): fsdev/virtfs-proxy-helper.o fsdev/9p-marshal.o fsdev/virtio-9p-marshal.o libqemuutil.a libqemustub.a
 fsdev/virtfs-proxy-helper$(EXESUF): LIBS += -lcap
 
 qemu-img-cmds.h: $(SRC_PATH)/qemu-img-cmds.hx
fsdev/9p-marshal.c new file +57 -0

57 lines not on this page · raw message

fsdev/9p-marshal.h new file +84 -0

84 lines not on this page · raw message

fsdev/Makefile.objs +1 -1
index c27dad3..8357851 100644
@@ -1,7 +1,7 @@
 ifeq ($(CONFIG_VIRTIO)$(CONFIG_VIRTFS)$(CONFIG_PCI),yyy)
 # Lots of the fsdev/9pcode is pulled in by vl.c via qemu_fsdev_add.
 # only pull in the actual virtio-9p device if we also enabled virtio.
-common-obj-y = qemu-fsdev.o virtio-9p-marshal.o
+common-obj-y = qemu-fsdev.o 9p-marshal.o virtio-9p-marshal.o
 else
 common-obj-y = qemu-fsdev-dummy.o
 endif
fsdev/virtio-9p-marshal.c +0 -31
index 7748d32..f236bab 100644
@@ -25,37 +25,6 @@
 #include "virtio-9p-marshal.h"
 #include "qemu/bswap.h"
 
-void v9fs_string_free(V9fsString *str)
-{
-    g_free(str->data);
-    str->data = NULL;
-    str->size = 0;
-}
-
-void v9fs_string_null(V9fsString *str)
-{
-    v9fs_string_free(str);
-}
-
-void GCC_FMT_ATTR(2, 3)
-v9fs_string_sprintf(V9fsString *str, const char *fmt, ...)
-{
-    va_list ap;
-
-    v9fs_string_free(str);
-
-    va_start(ap, fmt);
-    str->size = g_vasprintf(&str->data, fmt, ap);
-    va_end(ap);
-}
-
-void v9fs_string_copy(V9fsString *lhs, V9fsString *rhs)
-{
-    v9fs_string_free(lhs);
-    v9fs_string_sprintf(lhs, "%s", rhs->data);
-}
-
-
 static ssize_t v9fs_packunpack(void *addr, struct iovec *sg, int sg_count,
                                size_t offset, size_t size, int pack)
 {
fsdev/virtio-9p-marshal.h +1 -78

86 lines not on this page · raw message

Signature · 1 line
2.1.4
author
#24 lore raw

PATCH 15/22 9pfs: PDU processing functions should start pdu_ prefix

In reply to Wei Liu

This matches naming convention of pdu_marshal and pdu_unmarshal.

---
This patch can be squashed if necessary.

---
 hw/9pfs/virtio-9p.c | 88 ++++++++++++++++++++++++++---------------------------
 1 file changed, 44 insertions(+), 44 deletions(-)
hw/9pfs/virtio-9p.c +44 -44
index f605895..07e5eff 100644
@@ -563,7 +563,7 @@ static int fid_to_qid(V9fsPDU *pdu, V9fsFidState *fidp, V9fsQID *qidp)
     return 0;
 }
 
-static V9fsPDU *alloc_pdu(V9fsState *s)
+static V9fsPDU *pdu_alloc(V9fsState *s)
 {
     V9fsPDU *pdu = NULL;
 
@@ -575,7 +575,7 @@ static V9fsPDU *alloc_pdu(V9fsState *s)
     return pdu;
 }
 
-static void free_pdu(V9fsPDU *pdu)
+static void pdu_free(V9fsPDU *pdu)
 {
     if (pdu) {
         V9fsState *s = pdu->s;
@@ -595,7 +595,7 @@ static void free_pdu(V9fsPDU *pdu)
  * because we always expect to have enough space to encode
  * error details
  */
-static void complete_pdu(V9fsPDU *pdu, ssize_t len)
+static void pdu_complete(V9fsPDU *pdu, ssize_t len)
 {
     int8_t id = pdu->id + 1; /* Response */
     V9fsState *s = pdu->s;
@@ -638,7 +638,7 @@ static void complete_pdu(V9fsPDU *pdu, ssize_t len)
     /* Now wakeup anybody waiting in flush for this request */
     qemu_co_queue_next(&pdu->complete);
 
-    free_pdu(pdu);
+    pdu_free(pdu);
 }
 
 static mode_t v9mode_to_mode(uint32_t mode, V9fsString *extension)
@@ -933,7 +933,7 @@ static void v9fs_version(void *opaque)
     offset += err;
     trace_v9fs_version_return(pdu->tag, pdu->id, s->msize, version.data);
 out:
-    complete_pdu(pdu, offset);
+    pdu_complete(pdu, offset);
     v9fs_string_free(&version);
 }
 
@@ -997,7 +997,7 @@ static void v9fs_attach(void *opaque)
 out:
     put_fid(pdu, fidp);
 out_nofid:
-    complete_pdu(pdu, err);
+    pdu_complete(pdu, err);
     v9fs_string_free(&uname);
     v9fs_string_free(&aname);
 }
@@ -1043,7 +1043,7 @@ static void v9fs_stat(void *opaque)
 out:
     put_fid(pdu, fidp);
 out_nofid:
-    complete_pdu(pdu, err);
+    pdu_complete(pdu, err);
 }
 
 static void v9fs_getattr(void *opaque)
@@ -1106,7 +1106,7 @@ static void v9fs_getattr(void *opaque)
 out:
     put_fid(pdu, fidp);
 out_nofid:
-    complete_pdu(pdu, retval);
+    pdu_complete(pdu, retval);
 }
 
 /* Attribute flags */
@@ -1203,7 +1203,7 @@ static void v9fs_setattr(void *opaque)
 out:
     put_fid(pdu, fidp);
 out_nofid:
-    complete_pdu(pdu, err);
+    pdu_complete(pdu, err);
 }
 
 static int v9fs_walk_marshal(V9fsPDU *pdu, uint16_t nwnames, V9fsQID *qids)
@@ -1245,7 +1245,7 @@ static void v9fs_walk(void *opaque)
 
     err = pdu_unmarshal(pdu, offset, "ddw", &fid, &newfid, &nwnames);
     if (err < 0) {
-        complete_pdu(pdu, err);
+        pdu_complete(pdu, err);
         return ;
     }
     offset += err;
@@ -1313,7 +1313,7 @@ out:
     v9fs_path_free(&dpath);
     v9fs_path_free(&path);
 out_nofid:
-    complete_pdu(pdu, err);
+    pdu_complete(pdu, err);
     if (nwnames && nwnames <= P9_MAXWELEM) {
         for (name_idx = 0; name_idx < nwnames; name_idx++) {
             v9fs_string_free(&wnames[name_idx]);
@@ -1430,7 +1430,7 @@ static void v9fs_open(void *opaque)
 out:
     put_fid(pdu, fidp);
 out_nofid:
-    complete_pdu(pdu, err);
+    pdu_complete(pdu, err);
 }
 
 static void v9fs_lcreate(void *opaque)
@@ -1487,7 +1487,7 @@ static void v9fs_lcreate(void *opaque)
 out:
     put_fid(pdu, fidp);
 out_nofid:
-    complete_pdu(pdu, err);
+    pdu_complete(pdu, err);
     v9fs_string_free(&name);
 }
 
@@ -1517,7 +1517,7 @@ static void v9fs_fsync(void *opaque)
     }
     put_fid(pdu, fidp);
 out_nofid:
-    complete_pdu(pdu, err);
+    pdu_complete(pdu, err);
 }
 
 static void v9fs_clunk(void *opaque)
@@ -1550,7 +1550,7 @@ static void v9fs_clunk(void *opaque)
         err = offset;
     }
 out_nofid:
-    complete_pdu(pdu, err);
+    pdu_complete(pdu, err);
 }
 
 static int v9fs_xattr_read(V9fsState *s, V9fsPDU *pdu, V9fsFidState *fidp,
@@ -1765,7 +1765,7 @@ static void v9fs_read(void *opaque)
 out:
     put_fid(pdu, fidp);
 out_nofid:
-    complete_pdu(pdu, err);
+    pdu_complete(pdu, err);
 }
 
 static size_t v9fs_readdir_data_size(V9fsString *name)
@@ -1888,7 +1888,7 @@ static void v9fs_readdir(void *opaque)
 out:
     put_fid(pdu, fidp);
 out_nofid:
-    complete_pdu(pdu, retval);
+    pdu_complete(pdu, retval);
 }
 
 static int v9fs_xattr_write(V9fsState *s, V9fsPDU *pdu, V9fsFidState *fidp,
@@ -1955,7 +1955,7 @@ static void v9fs_write(void *opaque)
 
     err = pdu_unmarshal(pdu, offset, "dqd", &fid, &off, &count);
     if (err < 0) {
-        complete_pdu(pdu, err);
+        pdu_complete(pdu, err);
         return;
     }
     offset += err;
@@ -2018,7 +2018,7 @@ out:
     put_fid(pdu, fidp);
 out_nofid:
     qemu_iovec_destroy(&qiov_full);
-    complete_pdu(pdu, err);
+    pdu_complete(pdu, err);
 }
 
 static void v9fs_create(void *opaque)
@@ -2185,7 +2185,7 @@ static void v9fs_create(void *opaque)
 out:
     put_fid(pdu, fidp);
 out_nofid:
-   complete_pdu(pdu, err);
+   pdu_complete(pdu, err);
    v9fs_string_free(&name);
    v9fs_string_free(&extension);
    v9fs_path_free(&path);
@@ -2232,7 +2232,7 @@ static void v9fs_symlink(void *opaque)
 out:
     put_fid(pdu, dfidp);
 out_nofid:
-    complete_pdu(pdu, err);
+    pdu_complete(pdu, err);
     v9fs_string_free(&name);
     v9fs_string_free(&symname);
 }
@@ -2248,7 +2248,7 @@ static void v9fs_flush(void *opaque)
 
     err = pdu_unmarshal(pdu, offset, "w", &tag);
     if (err < 0) {
-        complete_pdu(pdu, err);
+        pdu_complete(pdu, err);
         return;
     }
     trace_v9fs_flush(pdu->tag, pdu->id, tag);
@@ -2265,9 +2265,9 @@ static void v9fs_flush(void *opaque)
          */
         qemu_co_queue_wait(&cancel_pdu->complete);
         cancel_pdu->cancelled = 0;
-        free_pdu(cancel_pdu);
+        pdu_free(cancel_pdu);
     }
-    complete_pdu(pdu, 7);
+    pdu_complete(pdu, 7);
 }
 
 static void v9fs_link(void *opaque)
@@ -2305,7 +2305,7 @@ out:
     put_fid(pdu, dfidp);
 out_nofid:
     v9fs_string_free(&name);
-    complete_pdu(pdu, err);
+    pdu_complete(pdu, err);
 }
 
 /* Only works with path name based fid */
@@ -2350,7 +2350,7 @@ out_err:
     clunk_fid(pdu->s, fidp->fid);
     put_fid(pdu, fidp);
 out_nofid:
-    complete_pdu(pdu, err);
+    pdu_complete(pdu, err);
 }
 
 static void v9fs_unlinkat(void *opaque)
@@ -2394,7 +2394,7 @@ out_err:
     put_fid(pdu, dfidp);
     v9fs_path_free(&path);
 out_nofid:
-    complete_pdu(pdu, err);
+    pdu_complete(pdu, err);
     v9fs_string_free(&name);
 }
 
@@ -2494,7 +2494,7 @@ static void v9fs_rename(void *opaque)
 out:
     put_fid(pdu, fidp);
 out_nofid:
-    complete_pdu(pdu, err);
+    pdu_complete(pdu, err);
     v9fs_string_free(&name);
 }
 
@@ -2595,7 +2595,7 @@ static void v9fs_renameat(void *opaque)
     }
 
 out_err:
-    complete_pdu(pdu, err);
+    pdu_complete(pdu, err);
     v9fs_string_free(&old_name);
     v9fs_string_free(&new_name);
 }
@@ -2691,7 +2691,7 @@ out:
     put_fid(pdu, fidp);
 out_nofid:
     v9fs_stat_free(&v9stat);
-    complete_pdu(pdu, err);
+    pdu_complete(pdu, err);
 }
 
 static int v9fs_fill_statfs(V9fsState *s, V9fsPDU *pdu, struct statfs *stbuf)
@@ -2770,7 +2770,7 @@ static void v9fs_statfs(void *opaque)
 out:
     put_fid(pdu, fidp);
 out_nofid:
-    complete_pdu(pdu, retval);
+    pdu_complete(pdu, retval);
 }
 
 static void v9fs_mknod(void *opaque)
@@ -2817,7 +2817,7 @@ static void v9fs_mknod(void *opaque)
 out:
     put_fid(pdu, fidp);
 out_nofid:
-    complete_pdu(pdu, err);
+    pdu_complete(pdu, err);
     v9fs_string_free(&name);
 }
 
@@ -2874,7 +2874,7 @@ out_nofid:
         err += offset;
     }
     trace_v9fs_lock_return(pdu->tag, pdu->id, status);
-    complete_pdu(pdu, err);
+    pdu_complete(pdu, err);
     v9fs_string_free(&flock.client_id);
 }
 
@@ -2923,7 +2923,7 @@ static void v9fs_getlock(void *opaque)
 out:
     put_fid(pdu, fidp);
 out_nofid:
-    complete_pdu(pdu, err);
+    pdu_complete(pdu, err);
     v9fs_string_free(&glock.client_id);
 }
 
@@ -2967,7 +2967,7 @@ static void v9fs_mkdir(void *opaque)
 out:
     put_fid(pdu, fidp);
 out_nofid:
-    complete_pdu(pdu, err);
+    pdu_complete(pdu, err);
     v9fs_string_free(&name);
 }
 
@@ -3073,7 +3073,7 @@ out:
         put_fid(pdu, xattr_fidp);
     }
 out_nofid:
-    complete_pdu(pdu, err);
+    pdu_complete(pdu, err);
     v9fs_string_free(&name);
 }
 
@@ -3113,7 +3113,7 @@ static void v9fs_xattrcreate(void *opaque)
     err = offset;
     put_fid(pdu, file_fidp);
 out_nofid:
-    complete_pdu(pdu, err);
+    pdu_complete(pdu, err);
     v9fs_string_free(&name);
 }
 
@@ -3153,7 +3153,7 @@ static void v9fs_readlink(void *opaque)
 out:
     put_fid(pdu, fidp);
 out_nofid:
-    complete_pdu(pdu, err);
+    pdu_complete(pdu, err);
 }
 
 static CoroutineEntry *pdu_co_handlers[] = {
@@ -3196,13 +3196,13 @@ static CoroutineEntry *pdu_co_handlers[] = {
 static void v9fs_op_not_supp(void *opaque)
 {
     V9fsPDU *pdu = opaque;
-    complete_pdu(pdu, -EOPNOTSUPP);
+    pdu_complete(pdu, -EOPNOTSUPP);
 }
 
 static void v9fs_fs_ro(void *opaque)
 {
     V9fsPDU *pdu = opaque;
-    complete_pdu(pdu, -EROFS);
+    pdu_complete(pdu, -EROFS);
 }
 
 static inline bool is_read_only_op(V9fsPDU *pdu)
@@ -3232,7 +3232,7 @@ static inline bool is_read_only_op(V9fsPDU *pdu)
     }
 }
 
-static void submit_pdu(V9fsPDU *pdu)
+static void pdu_submit(V9fsPDU *pdu)
 {
     Coroutine *co;
     CoroutineEntry *handler;
@@ -3258,7 +3258,7 @@ void handle_9p_output(VirtIODevice *vdev, VirtQueue *vq)
     V9fsPDU *pdu;
     ssize_t len;
 
-    while ((pdu = alloc_pdu(s)) &&
+    while ((pdu = pdu_alloc(s)) &&
             (len = virtqueue_pop(vq, &pdu->elem)) != 0) {
         struct {
             uint32_t size_le;
@@ -3280,7 +3280,7 @@ void handle_9p_output(VirtIODevice *vdev, VirtQueue *vq)
         pdu->tag = le16_to_cpu(out.tag_le);
 
         qemu_co_queue_init(&pdu->complete);
-        submit_pdu(pdu);
+        pdu_submit(pdu);
     }
-    free_pdu(pdu);
+    pdu_free(pdu);
 }
Signature · 1 line
2.1.4
author
#37 lore raw

PATCH 22/22 9pfs: disentangle V9fsState

In reply to Wei Liu

V9fsState now only contains generic fields. Introduce V9fsVirtioState for virtio transport. Change virtio-pci and virtio-ccw to use V9fsVirtioState. Handle transport enumeration in generic routines.

---
 hw/9pfs/9p.c               | 41 +++++++++++++++++++-----
 hw/9pfs/9p.h               | 19 +++++++----
 hw/9pfs/virtio-9p-device.c | 80 +++++++++++++++++++++++++++++-----------------
 hw/9pfs/virtio-9p.h        | 13 +++++++-
 hw/s390x/virtio-ccw.h      |  2 +-
 hw/virtio/virtio-pci.h     |  2 +-
 6 files changed, 109 insertions(+), 48 deletions(-)
hw/9pfs/9p.c +33 -8
index 4f2defd..f9c5451 100644
@@ -46,7 +46,13 @@ ssize_t pdu_marshal(V9fsPDU *pdu, size_t offset, const char *fmt, ...)
     va_list ap;
 
     va_start(ap, fmt);
-    ret = virtio_pdu_vmarshal(pdu, offset, fmt, ap);
+    switch (pdu->transport) {
+    case VIRTIO:
+        ret = virtio_pdu_vmarshal(pdu, offset, fmt, ap);
+        break;
+    default:
+        ret = -1;
+    }
     va_end(ap);
 
     return ret;
@@ -58,7 +64,13 @@ ssize_t pdu_unmarshal(V9fsPDU *pdu, size_t offset, const char *fmt, ...)
     va_list ap;
 
     va_start(ap, fmt);
-    ret = virtio_pdu_vunmarshal(pdu, offset, fmt, ap);
+    switch (pdu->transport) {
+    case VIRTIO:
+        ret = virtio_pdu_vunmarshal(pdu, offset, fmt, ap);
+        break;
+    default:
+        ret = -1;
+    }
     va_end(ap);
 
     return ret;
@@ -66,7 +78,11 @@ ssize_t pdu_unmarshal(V9fsPDU *pdu, size_t offset, const char *fmt, ...)
 
 static void pdu_push_and_notify(V9fsPDU *pdu)
 {
-    virtio_9p_push_and_notify(pdu);
+    switch (pdu->transport) {
+    case VIRTIO:
+        virtio_9p_push_and_notify(pdu);
+        break;
+    }
 }
 
 static int omode_to_uflags(int8_t mode)
@@ -1697,7 +1713,11 @@ static void v9fs_init_qiov_from_pdu(QEMUIOVector *qiov, V9fsPDU *pdu,
     struct iovec *iov;
     unsigned int niov;
 
-    virtio_init_iov_from_pdu(pdu, &iov, &niov, is_write);
+    switch (pdu->transport) {
+    case VIRTIO:
+        virtio_init_iov_from_pdu(pdu, &iov, &niov, is_write);
+        break;
+    }
 
     qemu_iovec_init_external(&elem, iov, niov);
     qemu_iovec_init(qiov, niov);
@@ -3273,8 +3293,10 @@ void pdu_submit(V9fsPDU *pdu)
 }
 
 /* Returns 0 on success, 1 on failure. */
-int v9fs_device_realize_common(V9fsState *s, Error **errp)
+int v9fs_device_realize_common(V9fsState *s, enum p9_transport transport,
+                               Error **errp)
 {
+    V9fsVirtioState *v = container_of(s, V9fsVirtioState, state);
     int i, len;
     struct stat stat;
     FsDriverEntry *fse;
@@ -3285,8 +3307,10 @@ int v9fs_device_realize_common(V9fsState *s, Error **errp)
     QLIST_INIT(&s->free_list);
     QLIST_INIT(&s->active_list);
     for (i = 0; i < (MAX_REQ - 1); i++) {
-        QLIST_INSERT_HEAD(&s->free_list, &s->pdus[i], next);
-        s->pdus[i].s = s;
+        QLIST_INSERT_HEAD(&s->free_list, &v->pdus[i], next);
+        v->pdus[i].s = s;
+        v->pdus[i].idx = i;
+        v->pdus[i].transport = transport;
     }
 
     v9fs_path_init(&path);
@@ -3361,7 +3385,8 @@ out:
     return rc;
 }
 
-void v9fs_device_unrealize_common(V9fsState *s, Error **errp)
+void v9fs_device_unrealize_common(V9fsState *s, enum p9_transport transport,
+                                  Error **errp)
 {
     g_free(s->ctx.fs_root);
     g_free(s->tag);
hw/9pfs/9p.h +12 -7
index 76c7cec..c36a02b 100644
@@ -14,6 +14,10 @@
 #include "qemu/thread.h"
 #include "qemu/coroutine.h"
 
+enum p9_transport {
+    VIRTIO = 0x1,
+};
+
 enum {
     P9_TLERROR = 6,
     P9_RLERROR,
@@ -131,9 +135,10 @@ struct V9fsPDU
     uint8_t id;
     uint8_t cancelled;
     CoQueue complete;
-    VirtQueueElement elem;
     struct V9fsState *s;
     QLIST_ENTRY(V9fsPDU) next;
+    uint32_t idx; /* index inside the array */
+    enum p9_transport transport;
 };
 
 
@@ -205,16 +210,12 @@ struct V9fsFidState
 
 typedef struct V9fsState
 {
-    VirtIODevice parent_obj;
-    VirtQueue *vq;
-    V9fsPDU pdus[MAX_REQ];
     QLIST_HEAD(, V9fsPDU) free_list;
     QLIST_HEAD(, V9fsPDU) active_list;
     V9fsFidState *fid_list;
     FileOperations *ops;
     FsContext ctx;
     char *tag;
-    size_t config_size;
     enum p9_proto_version proto_version;
     int32_t msize;
     /*
@@ -318,8 +319,12 @@ extern void v9fs_path_free(V9fsPath *path);
 extern void v9fs_path_copy(V9fsPath *lhs, V9fsPath *rhs);
 extern int v9fs_name_to_path(V9fsState *s, V9fsPath *dirpath,
                              const char *name, V9fsPath *path);
-extern int v9fs_device_realize_common(V9fsState *s, Error **errp);
-extern void v9fs_device_unrealize_common(V9fsState *s, Error **errp);
+
+extern int v9fs_device_realize_common(V9fsState *s, enum p9_transport transport,
+                                      Error **errp);
+extern void v9fs_device_unrealize_common(V9fsState *s,
+                                         enum p9_transport transport,
+                                         Error **errp);
 
 ssize_t pdu_marshal(V9fsPDU *pdu, size_t offset, const char *fmt, ...);
 ssize_t pdu_unmarshal(V9fsPDU *pdu, size_t offset, const char *fmt, ...);
hw/9pfs/virtio-9p-device.c +50 -30

170 lines not on this page · raw message

hw/9pfs/virtio-9p.h +12 -1
index 57c731f..1cdf0a2 100644
@@ -3,6 +3,17 @@
 
 #include "standard-headers/linux/virtio_9p.h"
 #include "hw/virtio/virtio.h"
+#include "9p.h"
+
+typedef struct V9fsVirtioState
+{
+    VirtIODevice parent_obj;
+    VirtQueue *vq;
+    size_t config_size;
+    V9fsPDU pdus[MAX_REQ];
+    VirtQueueElement elems[MAX_REQ];
+    V9fsState state;
+} V9fsVirtioState;
 
 extern void virtio_9p_push_and_notify(V9fsPDU *pdu);
 
@@ -15,6 +26,6 @@ void virtio_init_iov_from_pdu(V9fsPDU *pdu, struct iovec **piov,
 
 #define TYPE_VIRTIO_9P "virtio-9p-device"
 #define VIRTIO_9P(obj) \
-        OBJECT_CHECK(V9fsState, (obj), TYPE_VIRTIO_9P)
+        OBJECT_CHECK(V9fsVirtioState, (obj), TYPE_VIRTIO_9P)
 
 #endif
hw/s390x/virtio-ccw.h +1 -1
index 7ab8367..a526d2f 100644
@@ -210,7 +210,7 @@ VirtIODevice *virtio_ccw_get_vdev(SubchDev *sch);
 
 typedef struct V9fsCCWState {
     VirtioCcwDevice parent_obj;
-    V9fsState vdev;
+    V9fsVirtioState vdev;
 } V9fsCCWState;
 
 #endif /* CONFIG_VIRTFS */
hw/virtio/virtio-pci.h +1 -1
index 629b997..2f3164b 100644
@@ -243,7 +243,7 @@ struct VirtIONetPCI {
 
 typedef struct V9fsPCIState {
     VirtIOPCIProxy parent_obj;
-    V9fsState vdev;
+    V9fsVirtioState vdev;
 } V9fsPCIState;
 
 #endif
Signature · 1 line
2.1.4
author
#27 lore raw

PATCH 18/22 9pfs: factor out pdu_push_and_notify

In reply to Wei Liu
---
 hw/9pfs/virtio-9p.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)
hw/9pfs/virtio-9p.c +12 -5
index db79a48..5475f29 100644
@@ -63,6 +63,17 @@ ssize_t pdu_unmarshal(V9fsPDU *pdu, size_t offset, const char *fmt, ...)
     return ret;
 }
 
+static void pdu_push_and_notify(V9fsPDU *pdu)
+{
+    V9fsState *s = pdu->s;
+
+    /* push onto queue and notify */
+    virtqueue_push(s->vq, &pdu->elem, pdu->size);
+
+    /* FIXME: we should batch these completions */
+    virtio_notify(VIRTIO_DEVICE(s), s->vq);
+}
+
 static int omode_to_uflags(int8_t mode)
 {
     int ret = 0;
@@ -653,11 +664,7 @@ static void pdu_complete(V9fsPDU *pdu, ssize_t len)
     pdu->size = len;
     pdu->id = id;
 
-    /* push onto queue and notify */
-    virtqueue_push(s->vq, &pdu->elem, len);
-
-    /* FIXME: we should batch these completions */
-    virtio_notify(VIRTIO_DEVICE(s), s->vq);
+    pdu_push_and_notify(pdu);
 
     /* Now wakeup anybody waiting in flush for this request */
     qemu_co_queue_next(&pdu->complete);
Signature · 1 line
2.1.4
author
#36 lore raw

PATCH 21/22 9pfs: factor out v9fs_device_{, un}realize_common

In reply to Wei Liu
---
 hw/9pfs/9p.c               | 95 ++++++++++++++++++++++++++++++++++++++++++++++
 hw/9pfs/9p.h               |  2 +
 hw/9pfs/virtio-9p-device.c | 90 ++++---------------------------------------
 3 files changed, 104 insertions(+), 83 deletions(-)
hw/9pfs/9p.c +95 -0
index 2e9982f..4f2defd 100644
@@ -3271,3 +3271,98 @@ void pdu_submit(V9fsPDU *pdu)
     co = qemu_coroutine_create(handler);
     qemu_coroutine_enter(co, pdu);
 }
+
+/* Returns 0 on success, 1 on failure. */
+int v9fs_device_realize_common(V9fsState *s, Error **errp)
+{
+    int i, len;
+    struct stat stat;
+    FsDriverEntry *fse;
+    V9fsPath path;
+    int rc = 1;
+
+    /* initialize pdu allocator */
+    QLIST_INIT(&s->free_list);
+    QLIST_INIT(&s->active_list);
+    for (i = 0; i < (MAX_REQ - 1); i++) {
+        QLIST_INSERT_HEAD(&s->free_list, &s->pdus[i], next);
+        s->pdus[i].s = s;
+    }
+
+    v9fs_path_init(&path);
+
+    fse = get_fsdev_fsentry(s->fsconf.fsdev_id);
+
+    if (!fse) {
+        /* We don't have a fsdev identified by fsdev_id */
+        error_setg(errp, "9pfs device couldn't find fsdev with the "
+                   "id = %s",
+                   s->fsconf.fsdev_id ? s->fsconf.fsdev_id : "NULL");
+        goto out;
+    }
+
+    if (!s->fsconf.tag) {
+        /* we haven't specified a mount_tag */
+        error_setg(errp, "fsdev with id %s needs mount_tag arguments",
+                   s->fsconf.fsdev_id);
+        goto out;
+    }
+
+    s->ctx.export_flags = fse->export_flags;
+    s->ctx.fs_root = g_strdup(fse->path);
+    s->ctx.exops.get_st_gen = NULL;
+    len = strlen(s->fsconf.tag);
+    if (len > MAX_TAG_LEN - 1) {
+        error_setg(errp, "mount tag '%s' (%d bytes) is longer than "
+                   "maximum (%d bytes)", s->fsconf.tag, len, MAX_TAG_LEN - 1);
+        goto out;
+    }
+
+    s->tag = g_strdup(s->fsconf.tag);
+    s->ctx.uid = -1;
+
+    s->ops = fse->ops;
+
+    s->fid_list = NULL;
+    qemu_co_rwlock_init(&s->rename_lock);
+
+    if (s->ops->init(&s->ctx) < 0) {
+        error_setg(errp, "9pfs Failed to initialize fs-driver with id:%s"
+                   " and export path:%s", s->fsconf.fsdev_id, s->ctx.fs_root);
+        goto out;
+    }
+
+    /*
+     * Check details of export path, We need to use fs driver
+     * call back to do that. Since we are in the init path, we don't
+     * use co-routines here.
+     */
+    if (s->ops->name_to_path(&s->ctx, NULL, "/", &path) < 0) {
+        error_setg(errp,
+                   "error in converting name to path %s", strerror(errno));
+        goto out;
+    }
+    if (s->ops->lstat(&s->ctx, &path, &stat)) {
+        error_setg(errp, "share path %s does not exist", fse->path);
+        goto out;
+    } else if (!S_ISDIR(stat.st_mode)) {
+        error_setg(errp, "share path %s is not a directory", fse->path);
+        goto out;
+    }
+    v9fs_path_free(&path);
+
+    rc = 0;
+out:
+    if (rc) {
+        g_free(s->ctx.fs_root);
+        g_free(s->tag);
+        v9fs_path_free(&path);
+    }
+    return rc;
+}
+
+void v9fs_device_unrealize_common(V9fsState *s, Error **errp)
+{
+    g_free(s->ctx.fs_root);
+    g_free(s->tag);
+}
hw/9pfs/9p.h +2 -0
index 6ed2f1b..76c7cec 100644
@@ -318,6 +318,8 @@ extern void v9fs_path_free(V9fsPath *path);
 extern void v9fs_path_copy(V9fsPath *lhs, V9fsPath *rhs);
 extern int v9fs_name_to_path(V9fsState *s, V9fsPath *dirpath,
                              const char *name, V9fsPath *path);
+extern int v9fs_device_realize_common(V9fsState *s, Error **errp);
+extern void v9fs_device_unrealize_common(V9fsState *s, Error **errp);
 
 ssize_t pdu_marshal(V9fsPDU *pdu, size_t offset, const char *fmt, ...);
 ssize_t pdu_unmarshal(V9fsPDU *pdu, size_t offset, const char *fmt, ...);
hw/9pfs/virtio-9p-device.c +7 -83

108 lines not on this page · raw message

Signature · 1 line
2.1.4
author
#28 lore raw

PATCH 19/22 9pfs: break out virtio_init_iov_from_pdu

In reply to Wei Liu
---
 hw/9pfs/virtio-9p-device.c | 12 ++++++++++++
 hw/9pfs/virtio-9p.c        |  8 +-------
 hw/9pfs/virtio-9p.h        |  2 ++
 3 files changed, 15 insertions(+), 7 deletions(-)
hw/9pfs/virtio-9p-device.c +12 -0
index d77247f..5cad654 100644
@@ -170,6 +170,18 @@ ssize_t virtio_pdu_vunmarshal(V9fsPDU *pdu, size_t offset,
                                offset, 1, fmt, ap);
 }
 
+void virtio_init_iov_from_pdu(V9fsPDU *pdu, struct iovec **piov,
+                              unsigned int *pniov, bool is_write)
+{
+    if (is_write) {
+        *piov = pdu->elem.out_sg;
+        *pniov = pdu->elem.out_num;
+    } else {
+        *piov = pdu->elem.in_sg;
+        *pniov = pdu->elem.in_num;
+    }
+}
+
 /* virtio-9p device */
 
 static Property virtio_9p_properties[] = {
hw/9pfs/virtio-9p.c +1 -7
index 5475f29..d6850ba 100644
@@ -1702,13 +1702,7 @@ static void v9fs_init_qiov_from_pdu(QEMUIOVector *qiov, V9fsPDU *pdu,
     struct iovec *iov;
     unsigned int niov;
 
-    if (is_write) {
-        iov = pdu->elem.out_sg;
-        niov = pdu->elem.out_num;
-    } else {
-        iov = pdu->elem.in_sg;
-        niov = pdu->elem.in_num;
-    }
+    virtio_init_iov_from_pdu(pdu, &iov, &niov, is_write);
 
     qemu_iovec_init_external(&elem, iov, niov);
     qemu_iovec_init(qiov, niov);
hw/9pfs/virtio-9p.h +2 -0
index e298949..5024ad0 100644
@@ -327,6 +327,8 @@ ssize_t virtio_pdu_vmarshal(V9fsPDU *pdu, size_t offset,
                             const char *fmt, va_list ap);
 ssize_t virtio_pdu_vunmarshal(V9fsPDU *pdu, size_t offset,
                               const char *fmt, va_list ap);
+void virtio_init_iov_from_pdu(V9fsPDU *pdu, struct iovec **piov,
+                              unsigned int *pniov, bool is_write);
 
 #define TYPE_VIRTIO_9P "virtio-9p-device"
 #define VIRTIO_9P(obj) \
Signature · 1 line
2.1.4
author
#25 lore raw

PATCH 16/22 9pfs: make pdu_{, un}marshal proper functions

In reply to Wei Liu

Factor out v9fs_iov_v{,un}marshal. Implement pdu_{,un}marshal with those functions.

---
 fsdev/9p-iov-marshal.c | 42 ++++++++++++++++++++++++++++++------------
 fsdev/9p-iov-marshal.h |  5 +++++
 hw/9pfs/virtio-9p.c    | 26 ++++++++++++++++++++++++++
 hw/9pfs/virtio-9p.h    |  6 ++----
 4 files changed, 63 insertions(+), 16 deletions(-)
fsdev/9p-iov-marshal.c +30 -12
index d17983e..4db7133 100644
@@ -76,15 +76,13 @@ static ssize_t v9fs_pack(struct iovec *in_sg, int in_num, size_t offset,
     return v9fs_packunpack((void *)src, in_sg, in_num, offset, size, 1);
 }
 
-ssize_t v9fs_iov_unmarshal(struct iovec *out_sg, int out_num, size_t offset,
-                           int bswap, const char *fmt, ...)
+ssize_t v9fs_iov_vunmarshal(struct iovec *out_sg, int out_num, size_t offset,
+                            int bswap, const char *fmt, va_list ap)
 {
     int i;
-    va_list ap;
     ssize_t copied = 0;
     size_t old_offset = offset;
 
-    va_start(ap, fmt);
     for (i = 0; fmt[i]; i++) {
         switch (fmt[i]) {
         case 'b': {
@@ -195,25 +193,34 @@ ssize_t v9fs_iov_unmarshal(struct iovec *out_sg, int out_num, size_t offset,
             break;
         }
         if (copied < 0) {
-            va_end(ap);
             return copied;
         }
         offset += copied;
     }
-    va_end(ap);
 
     return offset - old_offset;
 }
 
-ssize_t v9fs_iov_marshal(struct iovec *in_sg, int in_num, size_t offset,
-                         int bswap, const char *fmt, ...)
+ssize_t v9fs_iov_unmarshal(struct iovec *out_sg, int out_num, size_t offset,
+                           int bswap, const char *fmt, ...)
 {
-    int i;
+    ssize_t ret;
     va_list ap;
+
+    va_start(ap, fmt);
+    ret = v9fs_iov_vunmarshal(out_sg, out_num, offset, bswap, fmt, ap);
+    va_end(ap);
+
+    return ret;
+}
+
+ssize_t v9fs_iov_vmarshal(struct iovec *in_sg, int in_num, size_t offset,
+                          int bswap, const char *fmt, va_list ap)
+{
+    int i;
     ssize_t copied = 0;
     size_t old_offset = offset;
 
-    va_start(ap, fmt);
     for (i = 0; fmt[i]; i++) {
         switch (fmt[i]) {
         case 'b': {
@@ -316,12 +323,23 @@ ssize_t v9fs_iov_marshal(struct iovec *in_sg, int in_num, size_t offset,
             break;
         }
         if (copied < 0) {
-            va_end(ap);
             return copied;
         }
         offset += copied;
     }
-    va_end(ap);
 
     return offset - old_offset;
 }
+
+ssize_t v9fs_iov_marshal(struct iovec *in_sg, int in_num, size_t offset,
+                         int bswap, const char *fmt, ...)
+{
+    ssize_t ret;
+    va_list ap;
+
+    va_start(ap, fmt);
+    ret = v9fs_iov_vmarshal(in_sg, in_num, offset, bswap, fmt, ap);
+    va_end(ap);
+
+    return ret;
+}
fsdev/9p-iov-marshal.h +5 -0
index 72c0cb3..410a1ea 100644
@@ -7,4 +7,9 @@ ssize_t v9fs_iov_unmarshal(struct iovec *out_sg, int out_num, size_t offset,
                            int bswap, const char *fmt, ...);
 ssize_t v9fs_iov_marshal(struct iovec *in_sg, int in_num, size_t offset,
                          int bswap, const char *fmt, ...);
+
+ssize_t v9fs_iov_vunmarshal(struct iovec *out_sg, int out_num, size_t offset,
+                            int bswap, const char *fmt, va_list ap);
+ssize_t v9fs_iov_vmarshal(struct iovec *in_sg, int in_num, size_t offset,
+                          int bswap, const char *fmt, va_list ap);
 #endif
hw/9pfs/virtio-9p.c +26 -0
index 07e5eff..780c398 100644
@@ -39,6 +39,32 @@ enum {
     Oappend = 0x80,
 };
 
+ssize_t pdu_marshal(V9fsPDU *pdu, size_t offset, const char *fmt, ...)
+{
+    ssize_t ret;
+    va_list ap;
+
+    va_start(ap, fmt);
+    ret = v9fs_iov_vmarshal(pdu->elem.in_sg, pdu->elem.in_num,
+                            offset, 1, fmt, ap);
+    va_end(ap);
+
+    return ret;
+}
+
+ssize_t pdu_unmarshal(V9fsPDU *pdu, size_t offset, const char *fmt, ...)
+{
+    ssize_t ret;
+    va_list ap;
+
+    va_start(ap, fmt);
+    ret = v9fs_iov_vunmarshal(pdu->elem.out_sg, pdu->elem.out_num,
+                              offset, 1, fmt, ap);
+    va_end(ap);
+
+    return ret;
+}
+
 static int omode_to_uflags(int8_t mode)
 {
     int ret = 0;
hw/9pfs/virtio-9p.h +2 -4
index 3a7e136..d6f3ac0 100644
@@ -320,10 +320,8 @@ extern void v9fs_path_copy(V9fsPath *lhs, V9fsPath *rhs);
 extern int v9fs_name_to_path(V9fsState *s, V9fsPath *dirpath,
                              const char *name, V9fsPath *path);
 
-#define pdu_marshal(pdu, offset, fmt, args...)  \
-    v9fs_iov_marshal(pdu->elem.in_sg, pdu->elem.in_num, offset, 1, fmt, ##args)
-#define pdu_unmarshal(pdu, offset, fmt, args...)  \
-    v9fs_iov_unmarshal(pdu->elem.out_sg, pdu->elem.out_num, offset, 1, fmt, ##args)
+ssize_t pdu_marshal(V9fsPDU *pdu, size_t offset, const char *fmt, ...);
+ssize_t pdu_unmarshal(V9fsPDU *pdu, size_t offset, const char *fmt, ...);
 
 #define TYPE_VIRTIO_9P "virtio-9p-device"
 #define VIRTIO_9P(obj) \
Signature · 1 line
2.1.4
author
#29 lore raw

PATCH 20/22 9pfs: break out generic code from virtio-9p.{c, h}

In reply to Wei Liu

The vast majority of code in virtio-9p.c is actually generic code. Rename that file to 9p.c and move virtio specific code to virtio-9p-device.c. Rename virtio-9p.h to 9p.h and split out virtio specific code to new virtio-9p.h.

Finally fix up virtio-pci.h header file inclusion.

Note that V9fsState and V9fsPDU are still tied to virtio at the moment. They will be handled later.

---
 hw/9pfs/9p-handle.c           |   2 +-
 hw/9pfs/9p-local.c            |   2 +-
 hw/9pfs/9p-posix-acl.c        |   2 +-
 hw/9pfs/9p-proxy.c            |   2 +-
 hw/9pfs/9p-synth.c            |   2 +-
 hw/9pfs/9p-xattr-user.c       |   2 +-
 hw/9pfs/9p-xattr.c            |   2 +-
 hw/9pfs/{virtio-9p.c => 9p.c} |  48 +------
 hw/9pfs/9p.h                  | 328 ++++++++++++++++++++++++++++++++++++++++++
 hw/9pfs/Makefile.objs         |   2 +-
 hw/9pfs/coth.h                |   9 +-
 hw/9pfs/virtio-9p-device.c    |  48 +++++++
 hw/9pfs/virtio-9p.h           | 319 +---------------------------------------
 hw/virtio/virtio-pci.h        |   1 +
 14 files changed, 399 insertions(+), 370 deletions(-)
 rename hw/9pfs/{virtio-9p.c => 9p.c} (98%)
 create mode 100644 hw/9pfs/9p.h
hw/9pfs/9p-handle.c +1 -1
index 51a9d15..58b77b4 100644
@@ -11,7 +11,7 @@
  *
  */
 
-#include "virtio-9p.h"
+#include "9p.h"
 #include "9p-xattr.h"
 #include <arpa/inet.h>
 #include <pwd.h>
hw/9pfs/9p-local.c +1 -1
index ac553e0..bf63eab 100644
@@ -11,7 +11,7 @@
  *
  */
 
-#include "virtio-9p.h"
+#include "9p.h"
 #include "9p-xattr.h"
 #include "fsdev/qemu-fsdev.h"   /* local_ops */
 #include <arpa/inet.h>
hw/9pfs/9p-posix-acl.c +1 -1
index 073af39..8df8228 100644
@@ -13,7 +13,7 @@
 
 #include <sys/types.h>
 #include "qemu/xattr.h"
-#include "virtio-9p.h"
+#include "9p.h"
 #include "fsdev/file-op-9p.h"
 #include "9p-xattr.h"
 
hw/9pfs/9p-proxy.c +1 -1
index 67c1fb9..73d00dd 100644
@@ -11,7 +11,7 @@
  */
 #include <sys/socket.h>
 #include <sys/un.h>
-#include "virtio-9p.h"
+#include "9p.h"
 #include "qemu/error-report.h"
 #include "fsdev/qemu-fsdev.h"
 #include "9p-proxy.h"
hw/9pfs/9p-synth.c +1 -1
index b1064e3..090ae0c 100644
@@ -13,7 +13,7 @@
  */
 
 #include "hw/virtio/virtio.h"
-#include "virtio-9p.h"
+#include "9p.h"
 #include "9p-xattr.h"
 #include "fsdev/qemu-fsdev.h"
 #include "9p-synth.h"
hw/9pfs/9p-xattr-user.c +1 -1
index 163b158..c490ec3 100644
@@ -12,7 +12,7 @@
  */
 
 #include <sys/types.h>
-#include "virtio-9p.h"
+#include "9p.h"
 #include "fsdev/file-op-9p.h"
 #include "9p-xattr.h"
 
hw/9pfs/9p-xattr.c +1 -1
index 1d7861b..741dd03 100644
@@ -11,7 +11,7 @@
  *
  */
 
-#include "virtio-9p.h"
+#include "9p.h"
 #include "fsdev/file-op-9p.h"
 #include "9p-xattr.h"
 
hw/9pfs/9p.c renamed from hw/9pfs/virtio-9p.c +5 -43

81 lines not on this page · raw message

hw/9pfs/9p.h new file +328 -0

328 lines not on this page · raw message

hw/9pfs/Makefile.objs +1 -1
index 838c5e1..da0ae0c 100644
@@ -1,4 +1,4 @@
-common-obj-y  = virtio-9p.o
+common-obj-y  = 9p.o
 common-obj-y += 9p-local.o 9p-xattr.o
 common-obj-y += 9p-xattr-user.o 9p-posix-acl.o
 common-obj-y += coth.o cofs.o codir.o cofile.o
hw/9pfs/coth.h +8 -1
index 209fc6a..d048a31 100644
@@ -17,7 +17,14 @@
 
 #include "qemu/thread.h"
 #include "qemu/coroutine.h"
-#include "virtio-9p.h"
+#include "9p.h"
+
+typedef struct V9fsThPool {
+    EventNotifier e;
+
+    GThreadPool *pool;
+    GAsyncQueue *completed;
+} V9fsThPool;
 
 /*
  * we want to use bottom half because we want to make sure the below
hw/9pfs/virtio-9p-device.c +48 -0

65 lines not on this page · raw message

hw/9pfs/virtio-9p.h +1 -318

328 lines not on this page · raw message

hw/virtio/virtio-pci.h +1 -0
index 7cf5974..629b997 100644
@@ -26,6 +26,7 @@
 #include "hw/virtio/virtio-input.h"
 #include "hw/virtio/virtio-gpu.h"
 #ifdef CONFIG_VIRTFS
+#include "hw/9pfs/9p.h"
 #include "hw/9pfs/virtio-9p.h"
 #endif
 #ifdef CONFIG_VHOST_SCSI
Signature · 1 line
2.1.4
author
#19 lore raw

PATCH 12/22 9pfs: use V9fsBlob to transmit xattr

In reply to Wei Liu

And make v9fs_pack static function. Now we only need to export v9fs_{,un}marshal to device.

---
 fsdev/virtio-9p-marshal.c |  4 ++--
 fsdev/virtio-9p-marshal.h |  3 ---
 hw/9pfs/virtio-9p.c       | 21 +++++++++++++--------
 3 files changed, 15 insertions(+), 13 deletions(-)
fsdev/virtio-9p-marshal.c +2 -2
index c3ac316..d120bd2 100644
@@ -70,8 +70,8 @@ static ssize_t v9fs_unpack(void *dst, struct iovec *out_sg, int out_num,
     return v9fs_packunpack(dst, out_sg, out_num, offset, size, 0);
 }
 
-ssize_t v9fs_pack(struct iovec *in_sg, int in_num, size_t offset,
-                  const void *src, size_t size)
+static ssize_t v9fs_pack(struct iovec *in_sg, int in_num, size_t offset,
+                         const void *src, size_t size)
 {
     return v9fs_packunpack((void *)src, in_sg, in_num, offset, size, 1);
 }
fsdev/virtio-9p-marshal.h +0 -3
index 0709bcd..766a48e 100644
@@ -3,9 +3,6 @@
 
 #include "9p-marshal.h"
 
-
-ssize_t v9fs_pack(struct iovec *in_sg, int in_num, size_t offset,
-                  const void *src, size_t size);
 ssize_t v9fs_unmarshal(struct iovec *out_sg, int out_num, size_t offset,
                        int bswap, const char *fmt, ...);
 ssize_t v9fs_marshal(struct iovec *in_sg, int in_num, size_t offset,
hw/9pfs/virtio-9p.c +13 -8
index 084fa6a..5da25ec 100644
@@ -1561,6 +1561,7 @@ static int v9fs_xattr_read(V9fsState *s, V9fsPDU *pdu, V9fsFidState *fidp,
     size_t offset = 7;
     int read_count;
     int64_t xattr_len;
+    V9fsBlob blob;
 
     xattr_len = fidp->fs.xattr.len;
     read_count = xattr_len - off;
@@ -1572,14 +1573,18 @@ static int v9fs_xattr_read(V9fsState *s, V9fsPDU *pdu, V9fsFidState *fidp,
          */
         read_count = 0;
     }
-    err = pdu_marshal(pdu, offset, "d", read_count);
-    if (err < 0) {
-        return err;
-    }
-    offset += err;
-    err = v9fs_pack(pdu->elem.in_sg, pdu->elem.in_num, offset,
-                    ((char *)fidp->fs.xattr.value) + off,
-                    read_count);
+
+    v9fs_blob_init(&blob);
+
+    blob.data = g_malloc(read_count);
+    memcpy(blob.data, ((char *)fidp->fs.xattr.value) + off,
+           read_count);
+    blob.size = read_count;
+
+    err = pdu_marshal(pdu, offset, "dB", read_count, &blob);
+
+    v9fs_blob_free(&blob);
+
     if (err < 0) {
         return err;
     }
Signature · 1 line
2.1.4
author
#22 lore raw

PATCH 13/22 fsdev: rename virtio-9p-marshal.{c, h} to 9p-iov-marshal.{c, h}

In reply to Wei Liu

And rename v9fs_marshal to v9fs_iov_marshal, v9fs_unmarshal to v9fs_iov_unmarshal.

The rationale behind this change is that, this marshalling interface is used both by virtio and proxy helper. Renaming files and functions to reflect the true nature of this interface.

Xen transport is going to have its own marshalling interface.

---
 Makefile                                        |   2 +-
 fsdev/{virtio-9p-marshal.c => 9p-iov-marshal.c} | 118 +++++++++++++-----------
 fsdev/9p-iov-marshal.h                          |  10 ++
 fsdev/Makefile.objs                             |   2 +-
 fsdev/virtfs-proxy-helper.c                     |   4 +-
 fsdev/virtio-9p-marshal.h                       |  10 --
 hw/9pfs/9p-proxy.h                              |   4 +-
 hw/9pfs/virtio-9p.h                             |   6 +-
 8 files changed, 83 insertions(+), 73 deletions(-)
 rename fsdev/{virtio-9p-marshal.c => 9p-iov-marshal.c} (63%)
 create mode 100644 fsdev/9p-iov-marshal.h
 delete mode 100644 fsdev/virtio-9p-marshal.h
Makefile +1 -1
index 7e881d8..d0de2d4 100644
@@ -240,7 +240,7 @@ qemu-io$(EXESUF): qemu-io.o $(block-obj-y) $(crypto-obj-y) $(qom-obj-y) libqemuu
 
 qemu-bridge-helper$(EXESUF): qemu-bridge-helper.o
 
-fsdev/virtfs-proxy-helper$(EXESUF): fsdev/virtfs-proxy-helper.o fsdev/9p-marshal.o fsdev/virtio-9p-marshal.o libqemuutil.a libqemustub.a
+fsdev/virtfs-proxy-helper$(EXESUF): fsdev/virtfs-proxy-helper.o fsdev/9p-marshal.o fsdev/9p-iov-marshal.o libqemuutil.a libqemustub.a
 fsdev/virtfs-proxy-helper$(EXESUF): LIBS += -lcap
 
 qemu-img-cmds.h: $(SRC_PATH)/qemu-img-cmds.hx
fsdev/9p-iov-marshal.c renamed from fsdev/virtio-9p-marshal.c +64 -54

192 lines not on this page · raw message

fsdev/9p-iov-marshal.h new file +10 -0
new file mode 100644
index 0000000..72c0cb3
@@ -0,0 +1,10 @@
+#ifndef _QEMU_9P_IOV_MARSHAL_H
+#define _QEMU_9P_IOV_MARSHAL_H
+
+#include "9p-marshal.h"
+
+ssize_t v9fs_iov_unmarshal(struct iovec *out_sg, int out_num, size_t offset,
+                           int bswap, const char *fmt, ...);
+ssize_t v9fs_iov_marshal(struct iovec *in_sg, int in_num, size_t offset,
+                         int bswap, const char *fmt, ...);
+#endif
fsdev/Makefile.objs +1 -1
index 8357851..1b120a4 100644
@@ -1,7 +1,7 @@
 ifeq ($(CONFIG_VIRTIO)$(CONFIG_VIRTFS)$(CONFIG_PCI),yyy)
 # Lots of the fsdev/9pcode is pulled in by vl.c via qemu_fsdev_add.
 # only pull in the actual virtio-9p device if we also enabled virtio.
-common-obj-y = qemu-fsdev.o 9p-marshal.o virtio-9p-marshal.o
+common-obj-y = qemu-fsdev.o 9p-marshal.o 9p-iov-marshal.o
 else
 common-obj-y = qemu-fsdev-dummy.o
 endif
fsdev/virtfs-proxy-helper.c +2 -2
index 7753654..44c7d88 100644
@@ -23,9 +23,9 @@
 #include "qemu-common.h"
 #include "qemu/sockets.h"
 #include "qemu/xattr.h"
-#include "virtio-9p-marshal.h"
+#include "9p-iov-marshal.h"
 #include "hw/9pfs/9p-proxy.h"
-#include "fsdev/virtio-9p-marshal.h"
+#include "fsdev/9p-iov-marshal.h"
 
 #define PROGNAME "virtfs-proxy-helper"
 
fsdev/virtio-9p-marshal.h deleted +0 -10
deleted file mode 100644
index 766a48e..0000000
@@ -1,10 +0,0 @@
-#ifndef _QEMU_VIRTIO_9P_MARSHAL_H
-#define _QEMU_VIRTIO_9P_MARSHAL_H
-
-#include "9p-marshal.h"
-
-ssize_t v9fs_unmarshal(struct iovec *out_sg, int out_num, size_t offset,
-                       int bswap, const char *fmt, ...);
-ssize_t v9fs_marshal(struct iovec *in_sg, int in_num, size_t offset,
-                     int bswap, const char *fmt, ...);
-#endif
hw/9pfs/9p-proxy.h +2 -2
index 56150b9..ba9ca20 100644
@@ -20,9 +20,9 @@
  * marsha/unmarshal doesn't do little endian conversion.
  */
 #define proxy_unmarshal(in_sg, offset, fmt, args...) \
-    v9fs_unmarshal(in_sg, 1, offset, 0, fmt, ##args)
+    v9fs_iov_unmarshal(in_sg, 1, offset, 0, fmt, ##args)
 #define proxy_marshal(out_sg, offset, fmt, args...) \
-    v9fs_marshal(out_sg, 1, offset, 0, fmt, ##args)
+    v9fs_iov_marshal(out_sg, 1, offset, 0, fmt, ##args)
 
 union MsgControl {
     struct cmsghdr cmsg;
hw/9pfs/virtio-9p.h +3 -3
index 3c78d3c..3a7e136 100644
@@ -10,7 +10,7 @@
 #include "standard-headers/linux/virtio_9p.h"
 #include "hw/virtio/virtio.h"
 #include "fsdev/file-op-9p.h"
-#include "fsdev/virtio-9p-marshal.h"
+#include "fsdev/9p-iov-marshal.h"
 #include "qemu/thread.h"
 #include "qemu/coroutine.h"
 
@@ -321,9 +321,9 @@ extern int v9fs_name_to_path(V9fsState *s, V9fsPath *dirpath,
                              const char *name, V9fsPath *path);
 
 #define pdu_marshal(pdu, offset, fmt, args...)  \
-    v9fs_marshal(pdu->elem.in_sg, pdu->elem.in_num, offset, 1, fmt, ##args)
+    v9fs_iov_marshal(pdu->elem.in_sg, pdu->elem.in_num, offset, 1, fmt, ##args)
 #define pdu_unmarshal(pdu, offset, fmt, args...)  \
-    v9fs_unmarshal(pdu->elem.out_sg, pdu->elem.out_num, offset, 1, fmt, ##args)
+    v9fs_iov_unmarshal(pdu->elem.out_sg, pdu->elem.out_num, offset, 1, fmt, ##args)
 
 #define TYPE_VIRTIO_9P "virtio-9p-device"
 #define VIRTIO_9P(obj) \
Signature · 1 line
2.1.4
author
#23 lore raw

PATCH 14/22 9pfs: PDU processing functions don't need to take V9fsState as argument

In reply to Wei Liu

V9fsState can be referenced by pdu->s. Initialise that in device realization function.

---
 hw/9pfs/virtio-9p-device.c |  1 +
 hw/9pfs/virtio-9p.c        | 98 +++++++++++++++++++++-------------------------
 2 files changed, 46 insertions(+), 53 deletions(-)
hw/9pfs/virtio-9p-device.c +1 -0
index 885b940..f3091cc 100644
@@ -69,6 +69,7 @@ static void virtio_9p_device_realize(DeviceState *dev, Error **errp)
     QLIST_INIT(&s->active_list);
     for (i = 0; i < (MAX_REQ - 1); i++) {
         QLIST_INSERT_HEAD(&s->free_list, &s->pdus[i], next);
+        s->pdus[i].s = s;
     }
 
     s->vq = virtio_add_queue(vdev, MAX_REQ, handle_9p_output);
hw/9pfs/virtio-9p.c +45 -53

409 lines not on this page · raw message

Signature · 1 line
2.1.4
author
#26 lore raw

PATCH 17/22 9pfs: factor out virtio_pdu_{, un}marshal

In reply to Wei Liu
---
 hw/9pfs/virtio-9p-device.c | 14 ++++++++++++++
 hw/9pfs/virtio-9p.c        |  6 ++----
 hw/9pfs/virtio-9p.h        |  5 +++++
 3 files changed, 21 insertions(+), 4 deletions(-)
hw/9pfs/virtio-9p-device.c +14 -0
index f3091cc..d77247f 100644
@@ -156,6 +156,20 @@ static void virtio_9p_device_unrealize(DeviceState *dev, Error **errp)
     g_free(s->tag);
 }
 
+ssize_t virtio_pdu_vmarshal(V9fsPDU *pdu, size_t offset,
+                            const char *fmt, va_list ap)
+{
+    return v9fs_iov_vmarshal(pdu->elem.in_sg, pdu->elem.in_num,
+                             offset, 1, fmt, ap);
+}
+
+ssize_t virtio_pdu_vunmarshal(V9fsPDU *pdu, size_t offset,
+                              const char *fmt, va_list ap)
+{
+    return v9fs_iov_vunmarshal(pdu->elem.out_sg, pdu->elem.out_num,
+                               offset, 1, fmt, ap);
+}
+
 /* virtio-9p device */
 
 static Property virtio_9p_properties[] = {
hw/9pfs/virtio-9p.c +2 -4
index 780c398..db79a48 100644
@@ -45,8 +45,7 @@ ssize_t pdu_marshal(V9fsPDU *pdu, size_t offset, const char *fmt, ...)
     va_list ap;
 
     va_start(ap, fmt);
-    ret = v9fs_iov_vmarshal(pdu->elem.in_sg, pdu->elem.in_num,
-                            offset, 1, fmt, ap);
+    ret = virtio_pdu_vmarshal(pdu, offset, fmt, ap);
     va_end(ap);
 
     return ret;
@@ -58,8 +57,7 @@ ssize_t pdu_unmarshal(V9fsPDU *pdu, size_t offset, const char *fmt, ...)
     va_list ap;
 
     va_start(ap, fmt);
-    ret = v9fs_iov_vunmarshal(pdu->elem.out_sg, pdu->elem.out_num,
-                              offset, 1, fmt, ap);
+    ret = virtio_pdu_vunmarshal(pdu, offset, fmt, ap);
     va_end(ap);
 
     return ret;
hw/9pfs/virtio-9p.h +5 -0
index d6f3ac0..e298949 100644
@@ -323,6 +323,11 @@ extern int v9fs_name_to_path(V9fsState *s, V9fsPath *dirpath,
 ssize_t pdu_marshal(V9fsPDU *pdu, size_t offset, const char *fmt, ...);
 ssize_t pdu_unmarshal(V9fsPDU *pdu, size_t offset, const char *fmt, ...);
 
+ssize_t virtio_pdu_vmarshal(V9fsPDU *pdu, size_t offset,
+                            const char *fmt, va_list ap);
+ssize_t virtio_pdu_vunmarshal(V9fsPDU *pdu, size_t offset,
+                              const char *fmt, va_list ap);
+
 #define TYPE_VIRTIO_9P "virtio-9p-device"
 #define VIRTIO_9P(obj) \
         OBJECT_CHECK(V9fsState, (obj), TYPE_VIRTIO_9P)
Signature · 1 line
2.1.4
#4 lore raw

Re: [Qemu-devel] [PATCH 03/22] 9pfs: rename virtio-9p-handle.c to 9p-handle.c

In reply to Wei Liu

Wrong subject line: you are renaming virtio-9p-local.c

Quoted 48 lines · Wei Liu

This file is not virtio specific. Rename it to use generic name.

Fix comment and remove unneeded inclusion of virtio.h.

---
 hw/9pfs/{virtio-9p-local.c => 9p-local.c} | 3 +--
 hw/9pfs/Makefile.objs                     | 2 +-
 2 files changed, 2 insertions(+), 3 deletions(-)
 rename hw/9pfs/{virtio-9p-local.c => 9p-local.c} (99%)
hw/9pfs/9p-local.c renamed from hw/9pfs/virtio-9p-local.c +1 -2
similarity index 99%
rename from hw/9pfs/virtio-9p-local.c
rename to hw/9pfs/9p-local.c
index f1f2e25..877ad86 100644
@@ -1,5 +1,5 @@
 /*
- * Virtio 9p Posix callback
+ * 9p Posix callback
  *
  * Copyright IBM, Corp. 2010
  *
@@ -11,7 +11,6 @@
  *
  */
 
-#include "hw/virtio/virtio.h"
 #include "virtio-9p.h"
 #include "virtio-9p-xattr.h"
 #include "fsdev/qemu-fsdev.h"   /* local_ops */
hw/9pfs/Makefile.objs +1 -1
index 9fdd8a4..5059681 100644
@@ -1,5 +1,5 @@
 common-obj-y  = virtio-9p.o
-common-obj-y += virtio-9p-local.o virtio-9p-xattr.o
+common-obj-y += 9p-local.o virtio-9p-xattr.o
 common-obj-y += virtio-9p-xattr-user.o virtio-9p-posix-acl.o
 common-obj-y += coth.o cofs.o codir.o cofile.o
 common-obj-y += coxattr.o virtio-9p-synth.o
Signature · 1 line
2.1.4
author
#5 lore raw

Re: [Qemu-devel] [PATCH 03/22] 9pfs: rename virtio-9p-handle.c to 9p-handle.c

Quoted 2 lines · Stefano Stabellini

Wrong subject line: you are renaming virtio-9p-local.c

Oops, yes.

I will fix this.

Wei.

#38 lore raw
In reply to Wei Liu
Quoted 6 lines · Wei Liu

Hi all

Back in 2015 summer one of our OPW interns Linda Jacobson explored the possibility of making 9pfs work on Xen. It turned out lots of code in QEMU can be reused.

Quoted 7 lines

This series refactors 9pfs related code:

1. Rename a bunch of files and functions to make clear they are generic.
2. Only export two functions (marshal and unmarshal) from transport to generic code.
3. disentangle virtio transport code and generic 9pfs code.
4. Some function name clean-up.

The series looks pretty good and it looks like a clean improvement over the current code base.

Quoted 117 lines

To make sure this series doesn't break compilation a rune is use to compile every commit.

$ git rebase -i origin/master --exec "make -j16 clean; ./configure --target-list=x86_64-softmmu --enable-virtfs --enable-kvm; make -j16 && echo ok."

Three use cases are tested:

1. Local file system driver with passthrough security policy
./qemu-system-x86_64 -L . -hda /dev/DATA/jessie -vnc 0.0.0.0:0,to=99 -fsdev local,path=/root/qemu,security_model=passthrough,id=fs1 -device virtio-9p-pci,fsdev=fs1,mount_tag=qemu &

2. Local file system driver with mapped security policy
./qemu-system-x86_64 -L . -hda /dev/DATA/jessie -vnc 0.0.0.0:0,to=99 -fsdev local,path=/root/qemu,security_model=mapped,id=fs1 -device virtio-9p-pci,fsdev=fs1,mount_tag=qemu &

3. Proxy file system driver
./virtfs-proxy-helper -p /root/qemu -n -s virtfs-helper-sock -u 0 -g 0 &
./qemu-system-x86_64 -L . -hda /dev/DATA/jessie -vnc 0.0.0.0:0,to=99 -fsdev proxy,socket=virtfs-helper-sock,id=fs1 -device virtio-9p-pci,fsdev=fs1,mount_tag=qemu &

During each of the tests, mounting, unmounting, read and write operations are performed. In "mapped" test, getfattr in host was used to inspect the attributes.

Let me know if you would like to see more tests.

Xen transport is still under development. I figure it would be better to post this series as soon as possible because rebasing such huge series from time to time is prone to error.

Comments are welcome. Thanks!

Wei.
---
Cc: "Aneesh Kumar K.V" <[email protected]>
Cc: Greg Kurz <[email protected]>
Cc: "Michael S. Tsirkin" <[email protected]>
Cc: Stefano Stabellini <[email protected]>
---

Wei Liu (22):
9pfs: rename virtio-9p-coth.{c,h} to coth.{c,h}
9pfs: rename virtio-9p-handle.c to 9p-handle.c
9pfs: rename virtio-9p-handle.c to 9p-handle.c
9pfs: rename virtio-9p-posix-acl.c to 9p-posix-acl.c 9pfs: rename virtio-9p-proxy.{c,h} to 9p-proxy.{c,h} 9pfs: rename virtio-9p-synth.{c,h} to 9p-synth.{c,h} 9pfs: rename virtio-9p-xattr{,-user}.{c,h} to 9p-xattr{,-user}.{c,h} 9pfs: merge hw/virtio/virtio-9p.h into hw/9pfs/virtio-9p.h 9pfs: remove dead code
fsdev: break out 9p-marshal.{c,h} from virtio-9p-marshal.{c,h}
fsdev: 9p-marshal: introduce V9fsBlob
9pfs: use V9fsBlob to transmit xattr
fsdev: rename virtio-9p-marshal.{c,h} to 9p-iov-marshal.{c,h} 9pfs: PDU processing functions don't need to take V9fsState as
argument
9pfs: PDU processing functions should start pdu_ prefix 9pfs: make pdu_{,un}marshal proper functions
9pfs: factor out virtio_pdu_{,un}marshal
9pfs: factor out pdu_push_and_notify
9pfs: break out virtio_init_iov_from_pdu
9pfs: break out generic code from virtio-9p.{c,h}
9pfs: factor out v9fs_device_{,un}realize_common
9pfs: disentangle V9fsState

 Makefile                                           |   2 +-
 fsdev/{virtio-9p-marshal.c => 9p-iov-marshal.c}    | 205 ++++++-----
 fsdev/9p-iov-marshal.h                             |  15 +
 fsdev/9p-marshal.c                                 |  64 ++++
 fsdev/{virtio-9p-marshal.h => 9p-marshal.h}        |  26 +-
 fsdev/Makefile.objs                                |   2 +-
 fsdev/virtfs-proxy-helper.c                        |   6 +-
 hw/9pfs/{virtio-9p-handle.c => 9p-handle.c}        |   7 +-
 hw/9pfs/{virtio-9p-local.c => 9p-local.c}          |   7 +-
 hw/9pfs/{virtio-9p-posix-acl.c => 9p-posix-acl.c}  |   7 +-
 hw/9pfs/{virtio-9p-proxy.c => 9p-proxy.c}          |   7 +-
 hw/9pfs/{virtio-9p-proxy.h => 9p-proxy.h}          |  10 +-
 hw/9pfs/{virtio-9p-synth.c => 9p-synth.c}          |   6 +-
 hw/9pfs/{virtio-9p-synth.h => 9p-synth.h}          |   6 +-
 .../{virtio-9p-xattr-user.c => 9p-xattr-user.c}    |   7 +-
 hw/9pfs/{virtio-9p-xattr.c => 9p-xattr.c}          |   7 +-
 hw/9pfs/{virtio-9p-xattr.h => 9p-xattr.h}          |   6 +-
 hw/9pfs/{virtio-9p.c => 9p.c}                      | 301 ++++++++++------
 hw/9pfs/9p.h                                       | 335 ++++++++++++++++++
 hw/9pfs/Makefile.objs                              |  14 +-
 hw/9pfs/codir.c                                    |   2 +-
 hw/9pfs/cofile.c                                   |   2 +-
 hw/9pfs/cofs.c                                     |   2 +-
 hw/9pfs/{virtio-9p-coth.c => coth.c}               |   4 +-
 hw/9pfs/{virtio-9p-coth.h => coth.h}               |  15 +-
 hw/9pfs/coxattr.c                                  |   2 +-
 hw/9pfs/virtio-9p-device.c                         | 196 ++++++-----
 hw/9pfs/virtio-9p.h                                | 391 +--------------------
 hw/s390x/virtio-ccw.h                              |   2 +-
 hw/virtio/virtio-pci.h                             |   4 +-
 include/hw/virtio/virtio-9p.h                      |  24 --
 31 files changed, 927 insertions(+), 757 deletions(-)
 rename fsdev/{virtio-9p-marshal.c => 9p-iov-marshal.c} (53%)
 create mode 100644 fsdev/9p-iov-marshal.h
 create mode 100644 fsdev/9p-marshal.c
 rename fsdev/{virtio-9p-marshal.h => 9p-marshal.h} (78%)
 rename hw/9pfs/{virtio-9p-handle.c => 9p-handle.c} (99%)
 rename hw/9pfs/{virtio-9p-local.c => 9p-local.c} (99%)
 rename hw/9pfs/{virtio-9p-posix-acl.c => 9p-posix-acl.c} (97%)
 rename hw/9pfs/{virtio-9p-proxy.c => 9p-proxy.c} (99%)
 rename hw/9pfs/{virtio-9p-proxy.h => 9p-proxy.h} (89%)
 rename hw/9pfs/{virtio-9p-synth.c => 9p-synth.c} (99%)
 rename hw/9pfs/{virtio-9p-synth.h => 9p-synth.h} (94%)
 rename hw/9pfs/{virtio-9p-xattr-user.c => 9p-xattr-user.c} (96%)
 rename hw/9pfs/{virtio-9p-xattr.c => 9p-xattr.c} (97%)
 rename hw/9pfs/{virtio-9p-xattr.h => 9p-xattr.h} (97%)
 rename hw/9pfs/{virtio-9p.c => 9p.c} (93%)
 create mode 100644 hw/9pfs/9p.h
 rename hw/9pfs/{virtio-9p-coth.c => coth.c} (95%)
 rename hw/9pfs/{virtio-9p-coth.h => coth.h} (96%)
 delete mode 100644 include/hw/virtio/virtio-9p.h
Signature · 1 line
2.1.4
#39 lore raw
Quoted 9 lines · On Thu, 7 Jan 2016 11:59:22 +0000 Stefano Stabellini…
Quoted 8 lines · Wei Liu

Hi all

Back in 2015 summer one of our OPW interns Linda Jacobson explored the possibility of making 9pfs work on Xen. It turned out lots of code in QEMU can be reused.

This series refactors 9pfs related code:

Quoted 9 lines
Quoted 5 lines

1. Rename a bunch of files and functions to make clear they are generic.
2. Only export two functions (marshal and unmarshal) from transport to generic code.
3. disentangle virtio transport code and generic 9pfs code.
4. Some function name clean-up.

The series looks pretty good and it looks like a clean improvement over the current code base.

I agree Wei did a great job. I'll fix the title in patch 3 and push it to my tree next week.

Thanks.

--
Greg

Quoted 120 lines
Quoted 119 lines

To make sure this series doesn't break compilation a rune is use to compile every commit.

$ git rebase -i origin/master --exec "make -j16 clean; ./configure --target-list=x86_64-softmmu --enable-virtfs --enable-kvm; make -j16 && echo ok."

Three use cases are tested:

1. Local file system driver with passthrough security policy
./qemu-system-x86_64 -L . -hda /dev/DATA/jessie -vnc 0.0.0.0:0,to=99 -fsdev local,path=/root/qemu,security_model=passthrough,id=fs1 -device virtio-9p-pci,fsdev=fs1,mount_tag=qemu &

2. Local file system driver with mapped security policy
./qemu-system-x86_64 -L . -hda /dev/DATA/jessie -vnc 0.0.0.0:0,to=99 -fsdev local,path=/root/qemu,security_model=mapped,id=fs1 -device virtio-9p-pci,fsdev=fs1,mount_tag=qemu &

3. Proxy file system driver
./virtfs-proxy-helper -p /root/qemu -n -s virtfs-helper-sock -u 0 -g 0 &
./qemu-system-x86_64 -L . -hda /dev/DATA/jessie -vnc 0.0.0.0:0,to=99 -fsdev proxy,socket=virtfs-helper-sock,id=fs1 -device virtio-9p-pci,fsdev=fs1,mount_tag=qemu &

During each of the tests, mounting, unmounting, read and write operations are performed. In "mapped" test, getfattr in host was used to inspect the attributes.

Let me know if you would like to see more tests.

Xen transport is still under development. I figure it would be better to post this series as soon as possible because rebasing such huge series from time to time is prone to error.

Comments are welcome. Thanks!

Wei.
---
Cc: "Aneesh Kumar K.V" <[email protected]>
Cc: Greg Kurz <[email protected]>
Cc: "Michael S. Tsirkin" <[email protected]>
Cc: Stefano Stabellini <[email protected]>
---

Wei Liu (22):
9pfs: rename virtio-9p-coth.{c,h} to coth.{c,h}
9pfs: rename virtio-9p-handle.c to 9p-handle.c
9pfs: rename virtio-9p-handle.c to 9p-handle.c
9pfs: rename virtio-9p-posix-acl.c to 9p-posix-acl.c 9pfs: rename virtio-9p-proxy.{c,h} to 9p-proxy.{c,h} 9pfs: rename virtio-9p-synth.{c,h} to 9p-synth.{c,h} 9pfs: rename virtio-9p-xattr{,-user}.{c,h} to 9p-xattr{,-user}.{c,h} 9pfs: merge hw/virtio/virtio-9p.h into hw/9pfs/virtio-9p.h 9pfs: remove dead code
fsdev: break out 9p-marshal.{c,h} from virtio-9p-marshal.{c,h}
fsdev: 9p-marshal: introduce V9fsBlob
9pfs: use V9fsBlob to transmit xattr
fsdev: rename virtio-9p-marshal.{c,h} to 9p-iov-marshal.{c,h} 9pfs: PDU processing functions don't need to take V9fsState as
argument
9pfs: PDU processing functions should start pdu_ prefix 9pfs: make pdu_{,un}marshal proper functions
9pfs: factor out virtio_pdu_{,un}marshal
9pfs: factor out pdu_push_and_notify
9pfs: break out virtio_init_iov_from_pdu
9pfs: break out generic code from virtio-9p.{c,h}
9pfs: factor out v9fs_device_{,un}realize_common
9pfs: disentangle V9fsState

 Makefile                                           |   2 +-
 fsdev/{virtio-9p-marshal.c => 9p-iov-marshal.c}    | 205 ++++++-----
 fsdev/9p-iov-marshal.h                             |  15 +
 fsdev/9p-marshal.c                                 |  64 ++++
 fsdev/{virtio-9p-marshal.h => 9p-marshal.h}        |  26 +-
 fsdev/Makefile.objs                                |   2 +-
 fsdev/virtfs-proxy-helper.c                        |   6 +-
 hw/9pfs/{virtio-9p-handle.c => 9p-handle.c}        |   7 +-
 hw/9pfs/{virtio-9p-local.c => 9p-local.c}          |   7 +-
 hw/9pfs/{virtio-9p-posix-acl.c => 9p-posix-acl.c}  |   7 +-
 hw/9pfs/{virtio-9p-proxy.c => 9p-proxy.c}          |   7 +-
 hw/9pfs/{virtio-9p-proxy.h => 9p-proxy.h}          |  10 +-
 hw/9pfs/{virtio-9p-synth.c => 9p-synth.c}          |   6 +-
 hw/9pfs/{virtio-9p-synth.h => 9p-synth.h}          |   6 +-
 .../{virtio-9p-xattr-user.c => 9p-xattr-user.c}    |   7 +-
 hw/9pfs/{virtio-9p-xattr.c => 9p-xattr.c}          |   7 +-
 hw/9pfs/{virtio-9p-xattr.h => 9p-xattr.h}          |   6 +-
 hw/9pfs/{virtio-9p.c => 9p.c}                      | 301 ++++++++++------
 hw/9pfs/9p.h                                       | 335 ++++++++++++++++++
 hw/9pfs/Makefile.objs                              |  14 +-
 hw/9pfs/codir.c                                    |   2 +-
 hw/9pfs/cofile.c                                   |   2 +-
 hw/9pfs/cofs.c                                     |   2 +-
 hw/9pfs/{virtio-9p-coth.c => coth.c}               |   4 +-
 hw/9pfs/{virtio-9p-coth.h => coth.h}               |  15 +-
 hw/9pfs/coxattr.c                                  |   2 +-
 hw/9pfs/virtio-9p-device.c                         | 196 ++++++-----
 hw/9pfs/virtio-9p.h                                | 391 +--------------------
 hw/s390x/virtio-ccw.h                              |   2 +-
 hw/virtio/virtio-pci.h                             |   4 +-
 include/hw/virtio/virtio-9p.h                      |  24 --
 31 files changed, 927 insertions(+), 757 deletions(-)
 rename fsdev/{virtio-9p-marshal.c => 9p-iov-marshal.c} (53%)
 create mode 100644 fsdev/9p-iov-marshal.h
 create mode 100644 fsdev/9p-marshal.c
 rename fsdev/{virtio-9p-marshal.h => 9p-marshal.h} (78%)
 rename hw/9pfs/{virtio-9p-handle.c => 9p-handle.c} (99%)
 rename hw/9pfs/{virtio-9p-local.c => 9p-local.c} (99%)
 rename hw/9pfs/{virtio-9p-posix-acl.c => 9p-posix-acl.c} (97%)
 rename hw/9pfs/{virtio-9p-proxy.c => 9p-proxy.c} (99%)
 rename hw/9pfs/{virtio-9p-proxy.h => 9p-proxy.h} (89%)
 rename hw/9pfs/{virtio-9p-synth.c => 9p-synth.c} (99%)
 rename hw/9pfs/{virtio-9p-synth.h => 9p-synth.h} (94%)
 rename hw/9pfs/{virtio-9p-xattr-user.c => 9p-xattr-user.c} (96%)
 rename hw/9pfs/{virtio-9p-xattr.c => 9p-xattr.c} (97%)
 rename hw/9pfs/{virtio-9p-xattr.h => 9p-xattr.h} (97%)
 rename hw/9pfs/{virtio-9p.c => 9p.c} (93%)
 create mode 100644 hw/9pfs/9p.h
 rename hw/9pfs/{virtio-9p-coth.c => coth.c} (95%)
 rename hw/9pfs/{virtio-9p-coth.h => coth.h} (96%)
 delete mode 100644 include/hw/virtio/virtio-9p.h
Signature · 1 line
2.1.4
#40 lore raw
Quoted 18 lines · On Thu, 7 Jan 2016 13:32:43 +0100 Greg Kurz <[email protected]> wrote:
Quoted 15 lines · On Thu, 7 Jan 2016 11:59:22 +0000 Stefano Stabellini…
Quoted 13 lines · Wei Liu

Hi all

Back in 2015 summer one of our OPW interns Linda Jacobson explored the possibility of making 9pfs work on Xen. It turned out lots of code in QEMU can be reused.

This series refactors 9pfs related code:

1. Rename a bunch of files and functions to make clear they are generic.
2. Only export two functions (marshal and unmarshal) from transport to generic code.
3. disentangle virtio transport code and generic 9pfs code.
4. Some function name clean-up.

Quoted 3 lines
Quoted 3 lines

The series looks pretty good and it looks like a clean improvement over the current code base.

Stefano,

Can I add your Reviewed-by to the patches ?

--
Greg

Quoted 131 lines

I agree Wei did a great job. I'll fix the title in patch 3 and push it to my tree next week.

Thanks.

--
Greg

Quoted 120 lines
Quoted 119 lines

To make sure this series doesn't break compilation a rune is use to compile every commit.

$ git rebase -i origin/master --exec "make -j16 clean; ./configure --target-list=x86_64-softmmu --enable-virtfs --enable-kvm; make -j16 && echo ok."

Three use cases are tested:

1. Local file system driver with passthrough security policy
./qemu-system-x86_64 -L . -hda /dev/DATA/jessie -vnc 0.0.0.0:0,to=99 -fsdev local,path=/root/qemu,security_model=passthrough,id=fs1 -device virtio-9p-pci,fsdev=fs1,mount_tag=qemu &

2. Local file system driver with mapped security policy
./qemu-system-x86_64 -L . -hda /dev/DATA/jessie -vnc 0.0.0.0:0,to=99 -fsdev local,path=/root/qemu,security_model=mapped,id=fs1 -device virtio-9p-pci,fsdev=fs1,mount_tag=qemu &

3. Proxy file system driver
./virtfs-proxy-helper -p /root/qemu -n -s virtfs-helper-sock -u 0 -g 0 &
./qemu-system-x86_64 -L . -hda /dev/DATA/jessie -vnc 0.0.0.0:0,to=99 -fsdev proxy,socket=virtfs-helper-sock,id=fs1 -device virtio-9p-pci,fsdev=fs1,mount_tag=qemu &

During each of the tests, mounting, unmounting, read and write operations are performed. In "mapped" test, getfattr in host was used to inspect the attributes.

Let me know if you would like to see more tests.

Xen transport is still under development. I figure it would be better to post this series as soon as possible because rebasing such huge series from time to time is prone to error.

Comments are welcome. Thanks!

Wei.
---
Cc: "Aneesh Kumar K.V" <[email protected]>
Cc: Greg Kurz <[email protected]>
Cc: "Michael S. Tsirkin" <[email protected]>
Cc: Stefano Stabellini <[email protected]>
---

Wei Liu (22):
9pfs: rename virtio-9p-coth.{c,h} to coth.{c,h}
9pfs: rename virtio-9p-handle.c to 9p-handle.c
9pfs: rename virtio-9p-handle.c to 9p-handle.c
9pfs: rename virtio-9p-posix-acl.c to 9p-posix-acl.c 9pfs: rename virtio-9p-proxy.{c,h} to 9p-proxy.{c,h} 9pfs: rename virtio-9p-synth.{c,h} to 9p-synth.{c,h} 9pfs: rename virtio-9p-xattr{,-user}.{c,h} to 9p-xattr{,-user}.{c,h} 9pfs: merge hw/virtio/virtio-9p.h into hw/9pfs/virtio-9p.h 9pfs: remove dead code
fsdev: break out 9p-marshal.{c,h} from virtio-9p-marshal.{c,h}
fsdev: 9p-marshal: introduce V9fsBlob
9pfs: use V9fsBlob to transmit xattr
fsdev: rename virtio-9p-marshal.{c,h} to 9p-iov-marshal.{c,h} 9pfs: PDU processing functions don't need to take V9fsState as
argument
9pfs: PDU processing functions should start pdu_ prefix 9pfs: make pdu_{,un}marshal proper functions
9pfs: factor out virtio_pdu_{,un}marshal
9pfs: factor out pdu_push_and_notify
9pfs: break out virtio_init_iov_from_pdu
9pfs: break out generic code from virtio-9p.{c,h}
9pfs: factor out v9fs_device_{,un}realize_common
9pfs: disentangle V9fsState

 Makefile                                           |   2 +-
 fsdev/{virtio-9p-marshal.c => 9p-iov-marshal.c}    | 205 ++++++-----
 fsdev/9p-iov-marshal.h                             |  15 +
 fsdev/9p-marshal.c                                 |  64 ++++
 fsdev/{virtio-9p-marshal.h => 9p-marshal.h}        |  26 +-
 fsdev/Makefile.objs                                |   2 +-
 fsdev/virtfs-proxy-helper.c                        |   6 +-
 hw/9pfs/{virtio-9p-handle.c => 9p-handle.c}        |   7 +-
 hw/9pfs/{virtio-9p-local.c => 9p-local.c}          |   7 +-
 hw/9pfs/{virtio-9p-posix-acl.c => 9p-posix-acl.c}  |   7 +-
 hw/9pfs/{virtio-9p-proxy.c => 9p-proxy.c}          |   7 +-
 hw/9pfs/{virtio-9p-proxy.h => 9p-proxy.h}          |  10 +-
 hw/9pfs/{virtio-9p-synth.c => 9p-synth.c}          |   6 +-
 hw/9pfs/{virtio-9p-synth.h => 9p-synth.h}          |   6 +-
 .../{virtio-9p-xattr-user.c => 9p-xattr-user.c}    |   7 +-
 hw/9pfs/{virtio-9p-xattr.c => 9p-xattr.c}          |   7 +-
 hw/9pfs/{virtio-9p-xattr.h => 9p-xattr.h}          |   6 +-
 hw/9pfs/{virtio-9p.c => 9p.c}                      | 301 ++++++++++------
 hw/9pfs/9p.h                                       | 335 ++++++++++++++++++
 hw/9pfs/Makefile.objs                              |  14 +-
 hw/9pfs/codir.c                                    |   2 +-
 hw/9pfs/cofile.c                                   |   2 +-
 hw/9pfs/cofs.c                                     |   2 +-
 hw/9pfs/{virtio-9p-coth.c => coth.c}               |   4 +-
 hw/9pfs/{virtio-9p-coth.h => coth.h}               |  15 +-
 hw/9pfs/coxattr.c                                  |   2 +-
 hw/9pfs/virtio-9p-device.c                         | 196 ++++++-----
 hw/9pfs/virtio-9p.h                                | 391 +--------------------
 hw/s390x/virtio-ccw.h                              |   2 +-
 hw/virtio/virtio-pci.h                             |   4 +-
 include/hw/virtio/virtio-9p.h                      |  24 --
 31 files changed, 927 insertions(+), 757 deletions(-)
 rename fsdev/{virtio-9p-marshal.c => 9p-iov-marshal.c} (53%)
 create mode 100644 fsdev/9p-iov-marshal.h
 create mode 100644 fsdev/9p-marshal.c
 rename fsdev/{virtio-9p-marshal.h => 9p-marshal.h} (78%)
 rename hw/9pfs/{virtio-9p-handle.c => 9p-handle.c} (99%)
 rename hw/9pfs/{virtio-9p-local.c => 9p-local.c} (99%)
 rename hw/9pfs/{virtio-9p-posix-acl.c => 9p-posix-acl.c} (97%)
 rename hw/9pfs/{virtio-9p-proxy.c => 9p-proxy.c} (99%)
 rename hw/9pfs/{virtio-9p-proxy.h => 9p-proxy.h} (89%)
 rename hw/9pfs/{virtio-9p-synth.c => 9p-synth.c} (99%)
 rename hw/9pfs/{virtio-9p-synth.h => 9p-synth.h} (94%)
 rename hw/9pfs/{virtio-9p-xattr-user.c => 9p-xattr-user.c} (96%)
 rename hw/9pfs/{virtio-9p-xattr.c => 9p-xattr.c} (97%)
 rename hw/9pfs/{virtio-9p-xattr.h => 9p-xattr.h} (97%)
 rename hw/9pfs/{virtio-9p.c => 9p.c} (93%)
 create mode 100644 hw/9pfs/9p.h
 rename hw/9pfs/{virtio-9p-coth.c => coth.c} (95%)
 rename hw/9pfs/{virtio-9p-coth.h => coth.h} (96%)
 delete mode 100644 include/hw/virtio/virtio-9p.h
Signature · 1 line
2.1.4
#41 lore raw
Quoted 21 lines · Greg Kurz
Quoted 18 lines · On Thu, 7 Jan 2016 13:32:43 +0100 Greg Kurz <[email protected]> wrote:
Quoted 15 lines · On Thu, 7 Jan 2016 11:59:22 +0000 Stefano Stabellini…
Quoted 13 lines · Wei Liu

Hi all

Back in 2015 summer one of our OPW interns Linda Jacobson explored the possibility of making 9pfs work on Xen. It turned out lots of code in QEMU can be reused.

This series refactors 9pfs related code:

1. Rename a bunch of files and functions to make clear they are generic.
2. Only export two functions (marshal and unmarshal) from transport to generic code.
3. disentangle virtio transport code and generic 9pfs code.
4. Some function name clean-up.

Quoted 7 lines
Quoted 3 lines
Quoted 3 lines

The series looks pretty good and it looks like a clean improvement over the current code base.

Stefano,

Can I add your Reviewed-by to the patches ?

Yes, go ahead, thanks.

Quoted 131 lines
Quoted 130 lines

I agree Wei did a great job. I'll fix the title in patch 3 and push it to my tree next week.

Thanks.

--
Greg

Quoted 120 lines
Quoted 119 lines

To make sure this series doesn't break compilation a rune is use to compile every commit.

$ git rebase -i origin/master --exec "make -j16 clean; ./configure --target-list=x86_64-softmmu --enable-virtfs --enable-kvm; make -j16 && echo ok."

Three use cases are tested:

1. Local file system driver with passthrough security policy
./qemu-system-x86_64 -L . -hda /dev/DATA/jessie -vnc 0.0.0.0:0,to=99 -fsdev local,path=/root/qemu,security_model=passthrough,id=fs1 -device virtio-9p-pci,fsdev=fs1,mount_tag=qemu &

2. Local file system driver with mapped security policy
./qemu-system-x86_64 -L . -hda /dev/DATA/jessie -vnc 0.0.0.0:0,to=99 -fsdev local,path=/root/qemu,security_model=mapped,id=fs1 -device virtio-9p-pci,fsdev=fs1,mount_tag=qemu &

3. Proxy file system driver
./virtfs-proxy-helper -p /root/qemu -n -s virtfs-helper-sock -u 0 -g 0 &
./qemu-system-x86_64 -L . -hda /dev/DATA/jessie -vnc 0.0.0.0:0,to=99 -fsdev proxy,socket=virtfs-helper-sock,id=fs1 -device virtio-9p-pci,fsdev=fs1,mount_tag=qemu &

During each of the tests, mounting, unmounting, read and write operations are performed. In "mapped" test, getfattr in host was used to inspect the attributes.

Let me know if you would like to see more tests.

Xen transport is still under development. I figure it would be better to post this series as soon as possible because rebasing such huge series from time to time is prone to error.

Comments are welcome. Thanks!

Wei.
---
Cc: "Aneesh Kumar K.V" <[email protected]>
Cc: Greg Kurz <[email protected]>
Cc: "Michael S. Tsirkin" <[email protected]>
Cc: Stefano Stabellini <[email protected]>
---

Wei Liu (22):
9pfs: rename virtio-9p-coth.{c,h} to coth.{c,h}
9pfs: rename virtio-9p-handle.c to 9p-handle.c
9pfs: rename virtio-9p-handle.c to 9p-handle.c
9pfs: rename virtio-9p-posix-acl.c to 9p-posix-acl.c 9pfs: rename virtio-9p-proxy.{c,h} to 9p-proxy.{c,h} 9pfs: rename virtio-9p-synth.{c,h} to 9p-synth.{c,h} 9pfs: rename virtio-9p-xattr{,-user}.{c,h} to 9p-xattr{,-user}.{c,h} 9pfs: merge hw/virtio/virtio-9p.h into hw/9pfs/virtio-9p.h 9pfs: remove dead code
fsdev: break out 9p-marshal.{c,h} from virtio-9p-marshal.{c,h}
fsdev: 9p-marshal: introduce V9fsBlob
9pfs: use V9fsBlob to transmit xattr
fsdev: rename virtio-9p-marshal.{c,h} to 9p-iov-marshal.{c,h} 9pfs: PDU processing functions don't need to take V9fsState as
argument
9pfs: PDU processing functions should start pdu_ prefix 9pfs: make pdu_{,un}marshal proper functions
9pfs: factor out virtio_pdu_{,un}marshal
9pfs: factor out pdu_push_and_notify
9pfs: break out virtio_init_iov_from_pdu
9pfs: break out generic code from virtio-9p.{c,h}
9pfs: factor out v9fs_device_{,un}realize_common
9pfs: disentangle V9fsState

 Makefile                                           |   2 +-
 fsdev/{virtio-9p-marshal.c => 9p-iov-marshal.c}    | 205 ++++++-----
 fsdev/9p-iov-marshal.h                             |  15 +
 fsdev/9p-marshal.c                                 |  64 ++++
 fsdev/{virtio-9p-marshal.h => 9p-marshal.h}        |  26 +-
 fsdev/Makefile.objs                                |   2 +-
 fsdev/virtfs-proxy-helper.c                        |   6 +-
 hw/9pfs/{virtio-9p-handle.c => 9p-handle.c}        |   7 +-
 hw/9pfs/{virtio-9p-local.c => 9p-local.c}          |   7 +-
 hw/9pfs/{virtio-9p-posix-acl.c => 9p-posix-acl.c}  |   7 +-
 hw/9pfs/{virtio-9p-proxy.c => 9p-proxy.c}          |   7 +-
 hw/9pfs/{virtio-9p-proxy.h => 9p-proxy.h}          |  10 +-
 hw/9pfs/{virtio-9p-synth.c => 9p-synth.c}          |   6 +-
 hw/9pfs/{virtio-9p-synth.h => 9p-synth.h}          |   6 +-
 .../{virtio-9p-xattr-user.c => 9p-xattr-user.c}    |   7 +-
 hw/9pfs/{virtio-9p-xattr.c => 9p-xattr.c}          |   7 +-
 hw/9pfs/{virtio-9p-xattr.h => 9p-xattr.h}          |   6 +-
 hw/9pfs/{virtio-9p.c => 9p.c}                      | 301 ++++++++++------
 hw/9pfs/9p.h                                       | 335 ++++++++++++++++++
 hw/9pfs/Makefile.objs                              |  14 +-
 hw/9pfs/codir.c                                    |   2 +-
 hw/9pfs/cofile.c                                   |   2 +-
 hw/9pfs/cofs.c                                     |   2 +-
 hw/9pfs/{virtio-9p-coth.c => coth.c}               |   4 +-
 hw/9pfs/{virtio-9p-coth.h => coth.h}               |  15 +-
 hw/9pfs/coxattr.c                                  |   2 +-
 hw/9pfs/virtio-9p-device.c                         | 196 ++++++-----
 hw/9pfs/virtio-9p.h                                | 391 +--------------------
 hw/s390x/virtio-ccw.h                              |   2 +-
 hw/virtio/virtio-pci.h                             |   4 +-
 include/hw/virtio/virtio-9p.h                      |  24 --
 31 files changed, 927 insertions(+), 757 deletions(-)
 rename fsdev/{virtio-9p-marshal.c => 9p-iov-marshal.c} (53%)
 create mode 100644 fsdev/9p-iov-marshal.h
 create mode 100644 fsdev/9p-marshal.c
 rename fsdev/{virtio-9p-marshal.h => 9p-marshal.h} (78%)
 rename hw/9pfs/{virtio-9p-handle.c => 9p-handle.c} (99%)
 rename hw/9pfs/{virtio-9p-local.c => 9p-local.c} (99%)
 rename hw/9pfs/{virtio-9p-posix-acl.c => 9p-posix-acl.c} (97%)
 rename hw/9pfs/{virtio-9p-proxy.c => 9p-proxy.c} (99%)
 rename hw/9pfs/{virtio-9p-proxy.h => 9p-proxy.h} (89%)
 rename hw/9pfs/{virtio-9p-synth.c => 9p-synth.c} (99%)
 rename hw/9pfs/{virtio-9p-synth.h => 9p-synth.h} (94%)
 rename hw/9pfs/{virtio-9p-xattr-user.c => 9p-xattr-user.c} (96%)
 rename hw/9pfs/{virtio-9p-xattr.c => 9p-xattr.c} (97%)
 rename hw/9pfs/{virtio-9p-xattr.h => 9p-xattr.h} (97%)
 rename hw/9pfs/{virtio-9p.c => 9p.c} (93%)
 create mode 100644 hw/9pfs/9p.h
 rename hw/9pfs/{virtio-9p-coth.c => coth.c} (95%)
 rename hw/9pfs/{virtio-9p-coth.h => coth.h} (96%)
 delete mode 100644 include/hw/virtio/virtio-9p.h
Signature · 1 line
2.1.4
#12 lore raw

Re: [Qemu-devel] [PATCH 09/22] 9pfs: remove dead code

In reply to Wei Liu
Quoted 23 lines · Wei Liu

Some structures virtio-9p.h have been unused since 2011 when relevant functions switched to use coroutines.

The declaration of pdu_packunpack and function do_pdu_unpack are useless.

The function virtio_9p_set_fd_limit is unused.

---
 hw/9pfs/virtio-9p.c | 11 ---------
 hw/9pfs/virtio-9p.h | 68 -----------------------------------------------------
 2 files changed, 79 deletions(-)
hw/9pfs/virtio-9p.c +0 -1
index 30ff828..084fa6a 100644
@@ -3287,14 +3287,3 @@ void handle_9p_output(VirtIODevice *vdev, VirtQueue *vq)
     }
     free_pdu(s, pdu);
 }
-

hw/9pfs/virtio-9p.c void handle_9p_output(VirtIODevice *vdev, VirtQueue *vq) · line 3300

Quoted 10 lines
hw/9pfs/virtio-9p.c +0 -10
-static void __attribute__((__constructor__)) virtio_9p_set_fd_limit(void)
-{
-    struct rlimit rlim;
-    if (getrlimit(RLIMIT_NOFILE, &rlim) < 0) {
-        fprintf(stderr, "Failed to get the resource limit\n");
-        exit(1);
-    }
-    open_fd_hw = rlim.rlim_cur - MIN(400, rlim.rlim_cur/3);
-    open_fd_rc = rlim.rlim_cur/2;
-}

I am looking at when we stopped using that. We still do file descriptor reclaim. If we do that we need to set the open_fd_hw/rc.

Quoted 7 lines
hw/9pfs/virtio-9p.h +0 -0
index ac4cb00..3c78d3c 100644
@@ -227,65 +227,6 @@ typedef struct V9fsState
     V9fsConf fsconf;

2.1.4

-aneesh

#16 lore raw

Re: [Qemu-devel] [PATCH 10/22] fsdev: break out 9p-marshal.{c, h} from virtio-9p-marshal.{c, h}

In reply to Wei Liu
Quoted 34 lines · Wei Liu

Break out some generic functions for marshaling 9p state. Pure code motion plus minor fixes for build system.

---
 Makefile                  |  2 +-
 fsdev/9p-marshal.c        | 57 ++++++++++++++++++++++++++++++++
 fsdev/9p-marshal.h        | 84 +++++++++++++++++++++++++++++++++++++++++++++++
 fsdev/Makefile.objs       |  2 +-
 fsdev/virtio-9p-marshal.c | 31 -----------------
 fsdev/virtio-9p-marshal.h | 79 +-------------------------------------------
 6 files changed, 144 insertions(+), 111 deletions(-)
 create mode 100644 fsdev/9p-marshal.c
 create mode 100644 fsdev/9p-marshal.h
Makefile +1 -1
index 82b2fc8..7e881d8 100644
@@ -240,7 +240,7 @@ qemu-io$(EXESUF): qemu-io.o $(block-obj-y) $(crypto-obj-y) $(qom-obj-y) libqemuu
 
 qemu-bridge-helper$(EXESUF): qemu-bridge-helper.o
 
-fsdev/virtfs-proxy-helper$(EXESUF): fsdev/virtfs-proxy-helper.o fsdev/virtio-9p-marshal.o libqemuutil.a libqemustub.a
+fsdev/virtfs-proxy-helper$(EXESUF): fsdev/virtfs-proxy-helper.o fsdev/9p-marshal.o fsdev/virtio-9p-marshal.o libqemuutil.a libqemustub.a
 fsdev/virtfs-proxy-helper$(EXESUF): LIBS += -lcap
 
 qemu-img-cmds.h: $(SRC_PATH)/qemu-img-cmds.hx
fsdev/9p-marshal.c new file +0 -0
new file mode 100644
index 0000000..610978e

fsdev/9p-marshal.c line 8

Quoted 8 lines
fsdev/9p-marshal.c new file +8 -0
@@ -0,0 +1,57 @@
+/*
+ * 9p backend
+ *
+ * Copyright IBM, Corp. 2010
+ *
+ * Authors:
+ *  Anthony Liguori   <[email protected]>
+ *  Wei Liu <[email protected]>

If it is just code movement just retain the authors as it is ?

fsdev/9p-marshal.c line 14

Quoted 6 lines
fsdev/9p-marshal.c new file +6 -0
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.  See
+ * the COPYING file in the top-level directory.
+ *
+ */
+

-aneesh

#20 lore raw

Re: [Qemu-devel] [PATCH 12/22] 9pfs: use V9fsBlob to transmit xattr

In reply to Wei Liu
Quoted 2 lines · Wei Liu

And make v9fs_pack static function. Now we only need to export v9fs_{,un}marshal to device.

Any advantage of doing this ? compared to v9fs_pack ?. Trying to understand if i am missing something here

Quoted 78 lines
---
 fsdev/virtio-9p-marshal.c |  4 ++--
 fsdev/virtio-9p-marshal.h |  3 ---
 hw/9pfs/virtio-9p.c       | 21 +++++++++++++--------
 3 files changed, 15 insertions(+), 13 deletions(-)
fsdev/virtio-9p-marshal.c +2 -2
index c3ac316..d120bd2 100644
@@ -70,8 +70,8 @@ static ssize_t v9fs_unpack(void *dst, struct iovec *out_sg, int out_num,
     return v9fs_packunpack(dst, out_sg, out_num, offset, size, 0);
 }
 
-ssize_t v9fs_pack(struct iovec *in_sg, int in_num, size_t offset,
-                  const void *src, size_t size)
+static ssize_t v9fs_pack(struct iovec *in_sg, int in_num, size_t offset,
+                         const void *src, size_t size)
 {
     return v9fs_packunpack((void *)src, in_sg, in_num, offset, size, 1);
 }
fsdev/virtio-9p-marshal.h +0 -3
index 0709bcd..766a48e 100644
@@ -3,9 +3,6 @@
 
 #include "9p-marshal.h"
 
-
-ssize_t v9fs_pack(struct iovec *in_sg, int in_num, size_t offset,
-                  const void *src, size_t size);
 ssize_t v9fs_unmarshal(struct iovec *out_sg, int out_num, size_t offset,
                        int bswap, const char *fmt, ...);
 ssize_t v9fs_marshal(struct iovec *in_sg, int in_num, size_t offset,
hw/9pfs/virtio-9p.c +13 -8
index 084fa6a..5da25ec 100644
@@ -1561,6 +1561,7 @@ static int v9fs_xattr_read(V9fsState *s, V9fsPDU *pdu, V9fsFidState *fidp,
     size_t offset = 7;
     int read_count;
     int64_t xattr_len;
+    V9fsBlob blob;
 
     xattr_len = fidp->fs.xattr.len;
     read_count = xattr_len - off;
@@ -1572,14 +1573,18 @@ static int v9fs_xattr_read(V9fsState *s, V9fsPDU *pdu, V9fsFidState *fidp,
          */
         read_count = 0;
     }
-    err = pdu_marshal(pdu, offset, "d", read_count);
-    if (err < 0) {
-        return err;
-    }
-    offset += err;
-    err = v9fs_pack(pdu->elem.in_sg, pdu->elem.in_num, offset,
-                    ((char *)fidp->fs.xattr.value) + off,
-                    read_count);
+
+    v9fs_blob_init(&blob);
+
+    blob.data = g_malloc(read_count);
+    memcpy(blob.data, ((char *)fidp->fs.xattr.value) + off,
+           read_count);
+    blob.size = read_count;
+
+    err = pdu_marshal(pdu, offset, "dB", read_count, &blob);
+
+    v9fs_blob_free(&blob);
+
     if (err < 0) {
         return err;
     }
Signature · 1 line
2.1.4
#13 lore raw

Re: [Qemu-devel] [PATCH 09/22] 9pfs: remove dead code

In reply to Aneesh Kumar K.V
Quoted 1 line · Aneesh Kumar K.V
Quoted 1 line
Quoted 1 line

The function virtio_9p_set_fd_limit is unused.

It's not, it's called at startup by libc.

Paolo

Quoted 30 lines
Quoted 17 lines
Quoted 17 lines
---
 hw/9pfs/virtio-9p.c | 11 ---------
 hw/9pfs/virtio-9p.h | 68 -----------------------------------------------------
 2 files changed, 79 deletions(-)
hw/9pfs/virtio-9p.c +0 -3
index 30ff828..084fa6a 100644
@@ -3287,14 +3287,3 @@ void handle_9p_output(VirtIODevice *vdev, VirtQueue *vq)
     }
     free_pdu(s, pdu);
 }
-
-static void __attribute__((__constructor__)) virtio_9p_set_fd_limit(void)
-{
Quoted 8 lines

hw/9pfs/virtio-9p.c void handle_9p_output(VirtIODevice *vdev, VirtQueue *vq) · line 3300

Quoted 8 lines
hw/9pfs/virtio-9p.c +0 -8
-    struct rlimit rlim;
-    if (getrlimit(RLIMIT_NOFILE, &rlim) < 0) {
-        fprintf(stderr, "Failed to get the resource limit\n");
-        exit(1);
-    }
-    open_fd_hw = rlim.rlim_cur - MIN(400, rlim.rlim_cur/3);
-    open_fd_rc = rlim.rlim_cur/2;
-}

I am looking at when we stopped using that. We still do file descriptor reclaim. If we do that we need to set the open_fd_hw/rc.

#30 lore raw

Re: [Qemu-devel] [PATCH 20/22] 9pfs: break out generic code from virtio-9p.{c, h}

In reply to Wei Liu
Quoted 9 lines · Wei Liu

The vast majority of code in virtio-9p.c is actually generic code. Rename that file to 9p.c and move virtio specific code to virtio-9p-device.c. Rename virtio-9p.h to 9p.h and split out virtio specific code to new virtio-9p.h.

Finally fix up virtio-pci.h header file inclusion.

Note that V9fsState and V9fsPDU are still tied to virtio at the moment. They will be handled later.

Can you split this to smaller patches as done for others.

Quoted 2 lines

-aneesh

#14 lore raw

Re: [Qemu-devel] [PATCH 09/22] 9pfs: remove dead code

In reply to Aneesh Kumar K.V
Quoted 30 lines · On Thu, 07 Jan 2016 22:11:11 +0530 "Aneesh Kumar K.V"…
Quoted 28 lines · Wei Liu

Some structures virtio-9p.h have been unused since 2011 when relevant functions switched to use coroutines.

The declaration of pdu_packunpack and function do_pdu_unpack are useless.

The function virtio_9p_set_fd_limit is unused.

---
 hw/9pfs/virtio-9p.c | 11 ---------
 hw/9pfs/virtio-9p.h | 68 -----------------------------------------------------
 2 files changed, 79 deletions(-)
hw/9pfs/virtio-9p.c +0 -6
index 30ff828..084fa6a 100644
@@ -3287,14 +3287,3 @@ void handle_9p_output(VirtIODevice *vdev, VirtQueue *vq)
     }
     free_pdu(s, pdu);
 }
-
-static void __attribute__((__constructor__)) virtio_9p_set_fd_limit(void)
-{
-    struct rlimit rlim;
-    if (getrlimit(RLIMIT_NOFILE, &rlim) < 0) {
-        fprintf(stderr, "Failed to get the resource limit\n");
Quoted 9 lines

hw/9pfs/virtio-9p.c void handle_9p_output(VirtIODevice *vdev, VirtQueue *vq) · line 3300

Quoted 5 lines
hw/9pfs/virtio-9p.c +0 -5
-        exit(1);
-    }
-    open_fd_hw = rlim.rlim_cur - MIN(400, rlim.rlim_cur/3);
-    open_fd_rc = rlim.rlim_cur/2;
-}

I am looking at when we stopped using that. We still do file descriptor reclaim. If we do that we need to set the open_fd_hw/rc.

Indeed this function has no explicit caller but it is not dead code. We must keep it.

Wei, no need to repost, I'll fix this in my tree.

Quoted 11 lines
Quoted 9 lines
hw/9pfs/virtio-9p.h +0 -0
index ac4cb00..3c78d3c 100644
@@ -227,65 +227,6 @@ typedef struct V9fsState
     V9fsConf fsconf;

2.1.4

-aneesh

Thanks Aneesh !

--
Greg

author
#21 lore raw

Re: [Qemu-devel] [PATCH 12/22] 9pfs: use V9fsBlob to transmit xattr

In reply to Aneesh Kumar K.V
Quoted 9 lines · Aneesh Kumar K.V
Quoted 2 lines · Wei Liu

And make v9fs_pack static function. Now we only need to export v9fs_{,un}marshal to device.

Any advantage of doing this ? compared to v9fs_pack ?. Trying to understand if i am missing something here

The reason for exporting v9fs_pack is because there is no abstraction of blob in marshalling interface. We should fix marshalling functions instead of leaking v9fs_pack to device.

As said in the commit message, with this change now we only need to export v9fs_marshal and v9fs_unmarshal to device. That's a much cleaner interface.

Wei.

#44 lore raw
In reply to Wei Liu
Quoted 31 lines · Wei Liu

Hi all

Back in 2015 summer one of our OPW interns Linda Jacobson explored the possibility of making 9pfs work on Xen. It turned out lots of code in QEMU can be reused.

This series refactors 9pfs related code:

1. Rename a bunch of files and functions to make clear they are generic.
2. Only export two functions (marshal and unmarshal) from transport to generic code.
3. disentangle virtio transport code and generic 9pfs code.
4. Some function name clean-up.

To make sure this series doesn't break compilation a rune is use to compile every commit.

$ git rebase -i origin/master --exec "make -j16 clean; ./configure --target-list=x86_64-softmmu --enable-virtfs --enable-kvm; make -j16 && echo ok."

Three use cases are tested:

1. Local file system driver with passthrough security policy
./qemu-system-x86_64 -L . -hda /dev/DATA/jessie -vnc 0.0.0.0:0,to=99 -fsdev local,path=/root/qemu,security_model=passthrough,id=fs1 -device virtio-9p-pci,fsdev=fs1,mount_tag=qemu &

2. Local file system driver with mapped security policy
./qemu-system-x86_64 -L . -hda /dev/DATA/jessie -vnc 0.0.0.0:0,to=99 -fsdev local,path=/root/qemu,security_model=mapped,id=fs1 -device virtio-9p-pci,fsdev=fs1,mount_tag=qemu &

3. Proxy file system driver
./virtfs-proxy-helper -p /root/qemu -n -s virtfs-helper-sock -u 0 -g 0 &
./qemu-system-x86_64 -L . -hda /dev/DATA/jessie -vnc 0.0.0.0:0,to=99 -fsdev proxy,socket=virtfs-helper-sock,id=fs1 -device virtio-9p-pci,fsdev=fs1,mount_tag=qemu &

Quoted 5 lines

During each of the tests, mounting, unmounting, read and write operations are performed. In "mapped" test, getfattr in host was used to inspect the attributes.

Let me know if you would like to see more tests.

you can also try this http://www.tuxera.com/community/posix-test-suite/
with the xen transport. Are you looking at getting this merged before the xen transport is done or are we expecting further changes to this as you make progress with Xen transport ?

W.r.t posix test suite with upstream we have one expected failure in the acl test. You can ignore that. I will also try to get some test run going here.

Quoted 6 lines

Xen transport is still under development. I figure it would be better to post this series as soon as possible because rebasing such huge series from time to time is prone to error.

Comments are welcome. Thanks!

Good series with some nice cleanups.

-aneesh

#42 lore raw
In reply to Greg Kurz
Quoted 18 lines · Greg Kurz
Quoted 15 lines · On Thu, 7 Jan 2016 11:59:22 +0000 Stefano Stabellini…
Quoted 13 lines · Wei Liu

Hi all

Back in 2015 summer one of our OPW interns Linda Jacobson explored the possibility of making 9pfs work on Xen. It turned out lots of code in QEMU can be reused.

This series refactors 9pfs related code:

1. Rename a bunch of files and functions to make clear they are generic.
2. Only export two functions (marshal and unmarshal) from transport to generic code.
3. disentangle virtio transport code and generic 9pfs code.
4. Some function name clean-up.

Quoted 7 lines
Quoted 3 lines

The series looks pretty good and it looks like a clean improvement over the current code base.

I agree Wei did a great job. I'll fix the title in patch 3 and push it to my tree next week.

I will like to push this myself. I will need some time to get some testing done with the changes. We also need some fixup with respect to fd reclaim.

-aneesh

author
#17 lore raw

Re: [Qemu-devel] [PATCH 10/22] fsdev: break out 9p-marshal.{c, h} from virtio-9p-marshal.{c, h}

In reply to Aneesh Kumar K.V
Quoted 39 lines · Aneesh Kumar K.V
Quoted 37 lines · Wei Liu

Break out some generic functions for marshaling 9p state. Pure code motion plus minor fixes for build system.

---
 Makefile                  |  2 +-
 fsdev/9p-marshal.c        | 57 ++++++++++++++++++++++++++++++++
 fsdev/9p-marshal.h        | 84 +++++++++++++++++++++++++++++++++++++++++++++++
 fsdev/Makefile.objs       |  2 +-
 fsdev/virtio-9p-marshal.c | 31 -----------------
 fsdev/virtio-9p-marshal.h | 79 +-------------------------------------------
 6 files changed, 144 insertions(+), 111 deletions(-)
 create mode 100644 fsdev/9p-marshal.c
 create mode 100644 fsdev/9p-marshal.h
Makefile +1 -1
index 82b2fc8..7e881d8 100644
@@ -240,7 +240,7 @@ qemu-io$(EXESUF): qemu-io.o $(block-obj-y) $(crypto-obj-y) $(qom-obj-y) libqemuu
 
 qemu-bridge-helper$(EXESUF): qemu-bridge-helper.o
 
-fsdev/virtfs-proxy-helper$(EXESUF): fsdev/virtfs-proxy-helper.o fsdev/virtio-9p-marshal.o libqemuutil.a libqemustub.a
+fsdev/virtfs-proxy-helper$(EXESUF): fsdev/virtfs-proxy-helper.o fsdev/9p-marshal.o fsdev/virtio-9p-marshal.o libqemuutil.a libqemustub.a
 fsdev/virtfs-proxy-helper$(EXESUF): LIBS += -lcap
 
 qemu-img-cmds.h: $(SRC_PATH)/qemu-img-cmds.hx
fsdev/9p-marshal.c new file +3 -0
new file mode 100644
index 0000000..610978e
@@ -0,0 +1,57 @@
+/*
+ * 9p backend
+ *
Quoted 9 lines

fsdev/9p-marshal.c line 8

Quoted 5 lines
fsdev/9p-marshal.c new file +5 -0
+ * Copyright IBM, Corp. 2010
+ *
+ * Authors:
+ *  Anthony Liguori   <[email protected]>
+ *  Wei Liu <[email protected]>

If it is just code movement just retain the authors as it is ?

I think this is residual of rebasing. I will remove this.

Wei.

Quoted 9 lines

fsdev/9p-marshal.c line 14

Quoted 6 lines
fsdev/9p-marshal.c new file +6 -0
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.  See
+ * the COPYING file in the top-level directory.
+ *
+ */
+

-aneesh

#43 lore raw
In reply to Aneesh Kumar K.V
Quoted 28 lines · On Thu, 07 Jan 2016 22:36:02 +0530 "Aneesh Kumar K.V"…
Quoted 18 lines · Greg Kurz
Quoted 15 lines · On Thu, 7 Jan 2016 11:59:22 +0000 Stefano Stabellini…
Quoted 13 lines · Wei Liu

Hi all

Back in 2015 summer one of our OPW interns Linda Jacobson explored the possibility of making 9pfs work on Xen. It turned out lots of code in QEMU can be reused.

This series refactors 9pfs related code:

1. Rename a bunch of files and functions to make clear they are generic.
2. Only export two functions (marshal and unmarshal) from transport to generic code.
3. disentangle virtio transport code and generic 9pfs code.
4. Some function name clean-up.

Quoted 7 lines
Quoted 3 lines

The series looks pretty good and it looks like a clean improvement over the current code base.

I agree Wei did a great job. I'll fix the title in patch 3 and push it to my tree next week.

Quoted 5 lines

I will like to push this myself. I will need some time to get some testing done with the changes. We also need some fixup with respect to fd reclaim.

-aneesh

Sure ! Please go ahead.

--
Greg

author
#31 lore raw

Re: [Qemu-devel] [PATCH 20/22] 9pfs: break out generic code from virtio-9p.{c, h}

In reply to Aneesh Kumar K.V
Quoted 7 lines · Aneesh Kumar K.V
Quoted 5 lines · Wei Liu

The vast majority of code in virtio-9p.c is actually generic code. Rename that file to 9p.c and move virtio specific code to virtio-9p-device.c. Rename virtio-9p.h to 9p.h and split out virtio specific code to new virtio-9p.h.

Quoted 7 lines
Quoted 4 lines

Finally fix up virtio-pci.h header file inclusion.

Note that V9fsState and V9fsPDU are still tied to virtio at the moment. They will be handled later.

Can you split this to smaller patches as done for others.

I'm not sure what you're asking for. IMHO splitting out C and header file is better done in one single commit.

Wei.

Quoted 5 lines
Quoted 2 lines

-aneesh

#32 lore raw

Re: [Qemu-devel] [PATCH 20/22] 9pfs: break out generic code from virtio-9p.{c, h}

Quoted 10 lines · Wei Liu
Quoted 9 lines · Aneesh Kumar K.V
Quoted 7 lines · Wei Liu

The vast majority of code in virtio-9p.c is actually generic code. Rename that file to 9p.c and move virtio specific code to virtio-9p-device.c. Rename virtio-9p.h to 9p.h and split out virtio specific code to new virtio-9p.h.

Finally fix up virtio-pci.h header file inclusion.

Quoted 9 lines
Quoted 5 lines
Quoted 2 lines

Note that V9fsState and V9fsPDU are still tied to virtio at the moment. They will be handled later.

Can you split this to smaller patches as done for others.

I'm not sure what you're asking for. IMHO splitting out C and header file is better done in one single commit.

virtio-9p.h -> 9p.h one patch virtio_p9_push_and_notify . There is one other instance of that conversion in the next patch
handle_p9_output movement
V9fsThPool, what is that ?

-aneesh

#33 lore raw

Re: [Qemu-devel] [PATCH 20/22] 9pfs: break out generic code from virtio-9p.{c, h}

Quoted 22 lines · On Thu, 07 Jan 2016 22:58:28 +0530 "Aneesh Kumar K.V"…
Quoted 10 lines · Wei Liu
Quoted 9 lines · Aneesh Kumar K.V
Quoted 7 lines · Wei Liu

The vast majority of code in virtio-9p.c is actually generic code. Rename that file to 9p.c and move virtio specific code to virtio-9p-device.c. Rename virtio-9p.h to 9p.h and split out virtio specific code to new virtio-9p.h.

Finally fix up virtio-pci.h header file inclusion.

Quoted 9 lines
Quoted 5 lines
Quoted 2 lines

Note that V9fsState and V9fsPDU are still tied to virtio at the moment. They will be handled later.

Can you split this to smaller patches as done for others.

I'm not sure what you're asking for. IMHO splitting out C and header file is better done in one single commit.

Quoted 6 lines

virtio-9p.h -> 9p.h one patch virtio_p9_push_and_notify . There is one other instance of that conversion in the next patch
handle_p9_output movement
V9fsThPool, what is that ?

Indeed we no longer have that. It looks like this patch was crafted before:

ebac1202c95a4f1b76b6ef3f0f63926fa76e753e virtio-9p: use QEMU thread pool

Quoted 1 line

-aneesh

--
Greg

author
#34 lore raw

Re: [Qemu-devel] [PATCH 20/22] 9pfs: break out generic code from virtio-9p.{c, h}

In reply to Aneesh Kumar K.V
Quoted 15 lines · Aneesh Kumar K.V
Quoted 13 lines · Wei Liu
Quoted 12 lines · Aneesh Kumar K.V
Quoted 9 lines · Wei Liu

The vast majority of code in virtio-9p.c is actually generic code. Rename that file to 9p.c and move virtio specific code to virtio-9p-device.c. Rename virtio-9p.h to 9p.h and split out virtio specific code to new virtio-9p.h.

Finally fix up virtio-pci.h header file inclusion.

Note that V9fsState and V9fsPDU are still tied to virtio at the moment. They will be handled later.

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

Can you split this to smaller patches as done for others.

I'm not sure what you're asking for. IMHO splitting out C and header file is better done in one single commit.

virtio-9p.h -> 9p.h one patch

This can be done.

Quoted 2 lines

virtio_p9_push_and_notify . There is one other instance of that conversion in the next patch

The next patch ("9pfs: factor out v9fs_device_{,un}realize_common ") doesn't touch virtio_p9_push_and_notify. What do I miss?

Quoted 1 line

handle_p9_output movement

This can be done.

Quoted 2 lines

V9fsThPool, what is that ?

This structure will be removed.

Quoted 2 lines

-aneesh

author
#45 lore raw
In reply to Aneesh Kumar K.V
Quoted 37 lines · Aneesh Kumar K.V
Quoted 35 lines · Wei Liu

Hi all

Back in 2015 summer one of our OPW interns Linda Jacobson explored the possibility of making 9pfs work on Xen. It turned out lots of code in QEMU can be reused.

This series refactors 9pfs related code:

1. Rename a bunch of files and functions to make clear they are generic.
2. Only export two functions (marshal and unmarshal) from transport to generic code.
3. disentangle virtio transport code and generic 9pfs code.
4. Some function name clean-up.

To make sure this series doesn't break compilation a rune is use to compile every commit.

$ git rebase -i origin/master --exec "make -j16 clean; ./configure --target-list=x86_64-softmmu --enable-virtfs --enable-kvm; make -j16 && echo ok."

Three use cases are tested:

1. Local file system driver with passthrough security policy
./qemu-system-x86_64 -L . -hda /dev/DATA/jessie -vnc 0.0.0.0:0,to=99 -fsdev local,path=/root/qemu,security_model=passthrough,id=fs1 -device virtio-9p-pci,fsdev=fs1,mount_tag=qemu &

2. Local file system driver with mapped security policy
./qemu-system-x86_64 -L . -hda /dev/DATA/jessie -vnc 0.0.0.0:0,to=99 -fsdev local,path=/root/qemu,security_model=mapped,id=fs1 -device virtio-9p-pci,fsdev=fs1,mount_tag=qemu &

3. Proxy file system driver
./virtfs-proxy-helper -p /root/qemu -n -s virtfs-helper-sock -u 0 -g 0 &
./qemu-system-x86_64 -L . -hda /dev/DATA/jessie -vnc 0.0.0.0:0,to=99 -fsdev proxy,socket=virtfs-helper-sock,id=fs1 -device virtio-9p-pci,fsdev=fs1,mount_tag=qemu &

During each of the tests, mounting, unmounting, read and write operations are performed. In "mapped" test, getfattr in host was used to inspect the attributes.

Quoted 5 lines
Quoted 1 line

Let me know if you would like to see more tests.

you can also try this http://www.tuxera.com/community/posix-test-suite/
with the xen transport. Are you looking at getting this merged before

Thanks for the info.

Quoted 3 lines

the xen transport is done or are we expecting further changes to this as you make progress with Xen transport ?

I wish to merge this sooner rather than later. It's better to have a cleaner starting point. And as you see, as I rebase this series over time errors are easily introduced. It would also be far easier for you maintainers to review Xen transport alone than reviewing 20+ prerequisite patches plus Xen transport.

Interface-wise, I don't expect much to change but I can't say I'm 100% sure. My current thought is that hooking into multiple transport specific locations should be good enough. And this series should cover most cases where hooks are needed.

Quoted 3 lines

W.r.t posix test suite with upstream we have one expected failure in the acl test. You can ignore that. I will also try to get some test run going here.

OK.

Wei.

Quoted 13 lines
Quoted 7 lines

Xen transport is still under development. I figure it would be better to post this series as soon as possible because rebasing such huge series from time to time is prone to error.

Comments are welcome. Thanks!

Good series with some nice cleanups.

-aneesh

author
#35 lore raw

Re: [Qemu-devel] [PATCH 20/22] 9pfs: break out generic code from virtio-9p.{c, h}

In reply to Wei Liu
Quoted 25 lines · Wei Liu
Quoted 15 lines · Aneesh Kumar K.V
Quoted 13 lines · Wei Liu
Quoted 12 lines · Aneesh Kumar K.V
Quoted 9 lines · Wei Liu

The vast majority of code in virtio-9p.c is actually generic code. Rename that file to 9p.c and move virtio specific code to virtio-9p-device.c. Rename virtio-9p.h to 9p.h and split out virtio specific code to new virtio-9p.h.

Finally fix up virtio-pci.h header file inclusion.

Note that V9fsState and V9fsPDU are still tied to virtio at the moment. They will be handled later.

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

Can you split this to smaller patches as done for others.

I'm not sure what you're asking for. IMHO splitting out C and header file is better done in one single commit.

virtio-9p.h -> 9p.h one patch

Quoted 8 lines

This can be done.

Quoted 2 lines

virtio_p9_push_and_notify . There is one other instance of that conversion in the next patch

The next patch ("9pfs: factor out v9fs_device_{,un}realize_common ") doesn't touch virtio_p9_push_and_notify. What do I miss?

I've made a patch to break out v9fs_9p_push_and_notify. I guess that's what you want.

Wei.