All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH v2 00/27] 9pfs: disentangling virtio and generic code
@ 2016-01-07 19:55 Wei Liu
  2016-01-07 19:55 ` [Qemu-devel] [PATCH v2 01/27] 9pfs: rename virtio-9p-coth.{c, h} to coth.{c, h} Wei Liu
                   ` (27 more replies)
  0 siblings, 28 replies; 38+ messages in thread
From: Wei Liu @ 2016-01-07 19:55 UTC (permalink / raw)
  To: qemu-devel
  Cc: Michael S. Tsirkin, Wei Liu, Aneesh Kumar K.V,
	Stefano Stabellini, Greg Kurz

Hi all

Version 2 of this series is even longer. :-)

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 patch series can be found at:

  git://xenbits.xen.org/people/liuw/qemu.git wip.9pfs-refactor-v2

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.

I also ran Tuxera POSIX test suite (20080816) as Aneesh suggsted. The test
suite was run with passthrough and mapped mode.  All tests passed.

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.

I tried to break down the changes to bit-size patches as much as possible to
make review easier. If you want me to squash patches together please let me
know.

Comments are welcome. Thanks!

Wei.
---
Cc: "Aneesh Kumar K.V" <aneesh.kumar@linux.vnet.ibm.com>
Cc: Greg Kurz <gkurz@linux.vnet.ibm.com>
Cc: "Michael S. Tsirkin" <mst@redhat.com>
Cc: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
---

Wei Liu (27):
  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-local.c to 9p-local.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 9p.h from virtio-9p.h
  9pfs: factor out virtio_9p_push_and_notify
  9pfs: export pdu_{submit,alloc,free}
  9pfs: move handle_9p_output and make it static function
  9pfs: rename virtio_9p_set_fd_limit to use v9fs_ prefix
  9pfs: rename virtio-9p.c to 9p.c
  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                                 |  63 ++++
 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}                      | 297 +++++++++++-----
 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}               |   6 +-
 hw/9pfs/coxattr.c                                  |   2 +-
 hw/9pfs/virtio-9p-device.c                         | 201 ++++++-----
 hw/9pfs/virtio-9p.h                                | 391 +--------------------
 hw/s390x/virtio-ccw.h                              |   2 +-
 hw/virtio/virtio-pci.h                             |   3 +-
 include/hw/virtio/virtio-9p.h                      |  24 --
 31 files changed, 921 insertions(+), 753 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} (98%)
 delete mode 100644 include/hw/virtio/virtio-9p.h

-- 
2.1.4

^ permalink raw reply	[flat|nested] 38+ messages in thread

* [Qemu-devel] [PATCH v2 01/27] 9pfs: rename virtio-9p-coth.{c, h} to coth.{c, h}
  2016-01-07 19:55 [Qemu-devel] [PATCH v2 00/27] 9pfs: disentangling virtio and generic code Wei Liu
@ 2016-01-07 19:55 ` Wei Liu
  2016-01-07 19:55 ` [Qemu-devel] [PATCH v2 02/27] 9pfs: rename virtio-9p-handle.c to 9p-handle.c Wei Liu
                   ` (26 subsequent siblings)
  27 siblings, 0 replies; 38+ messages in thread
From: Wei Liu @ 2016-01-07 19:55 UTC (permalink / raw)
  To: qemu-devel; +Cc: Michael S. Tsirkin, Wei Liu, Aneesh Kumar K.V, Greg Kurz

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.

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
---
 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%)

diff --git a/hw/9pfs/Makefile.objs b/hw/9pfs/Makefile.objs
index 1e9b595..76dadbe 100644
--- a/hw/9pfs/Makefile.objs
+++ b/hw/9pfs/Makefile.objs
@@ -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
diff --git a/hw/9pfs/codir.c b/hw/9pfs/codir.c
index ec9cc7f..5a4f74d 100644
--- a/hw/9pfs/codir.c
+++ b/hw/9pfs/codir.c
@@ -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)
diff --git a/hw/9pfs/cofile.c b/hw/9pfs/cofile.c
index 7cb55ee..893df2c 100644
--- a/hw/9pfs/cofile.c
+++ b/hw/9pfs/cofile.c
@@ -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)
diff --git a/hw/9pfs/cofs.c b/hw/9pfs/cofs.c
index e1953a9..7b4202b 100644
--- a/hw/9pfs/cofs.c
+++ b/hw/9pfs/cofs.c
@@ -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)
 {
diff --git a/hw/9pfs/virtio-9p-coth.c b/hw/9pfs/coth.c
similarity index 95%
rename from hw/9pfs/virtio-9p-coth.c
rename to hw/9pfs/coth.c
index ab9425c..56772d6 100644
--- a/hw/9pfs/virtio-9p-coth.c
+++ b/hw/9pfs/coth.c
@@ -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)
diff --git a/hw/9pfs/virtio-9p-coth.h b/hw/9pfs/coth.h
similarity index 98%
rename from hw/9pfs/virtio-9p-coth.h
rename to hw/9pfs/coth.h
index 4ac1aaf..209fc6a 100644
--- a/hw/9pfs/virtio-9p-coth.h
+++ b/hw/9pfs/coth.h
@@ -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"
diff --git a/hw/9pfs/coxattr.c b/hw/9pfs/coxattr.c
index 55c0d23..0590cbf 100644
--- a/hw/9pfs/coxattr.c
+++ b/hw/9pfs/coxattr.c
@@ -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)
 {
diff --git a/hw/9pfs/virtio-9p-device.c b/hw/9pfs/virtio-9p-device.c
index b42d3b3..667b54a 100644
--- a/hw/9pfs/virtio-9p-device.c
+++ b/hw/9pfs/virtio-9p-device.c
@@ -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,
diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c
index f972731..0f178de 100644
--- a/hw/9pfs/virtio-9p.c
+++ b/hw/9pfs/virtio-9p.c
@@ -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"
 
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [Qemu-devel] [PATCH v2 02/27] 9pfs: rename virtio-9p-handle.c to 9p-handle.c
  2016-01-07 19:55 [Qemu-devel] [PATCH v2 00/27] 9pfs: disentangling virtio and generic code Wei Liu
  2016-01-07 19:55 ` [Qemu-devel] [PATCH v2 01/27] 9pfs: rename virtio-9p-coth.{c, h} to coth.{c, h} Wei Liu
@ 2016-01-07 19:55 ` Wei Liu
  2016-01-07 19:56 ` [Qemu-devel] [PATCH v2 03/27] 9pfs: rename virtio-9p-local.c to 9p-local.c Wei Liu
                   ` (25 subsequent siblings)
  27 siblings, 0 replies; 38+ messages in thread
From: Wei Liu @ 2016-01-07 19:55 UTC (permalink / raw)
  To: qemu-devel; +Cc: Wei Liu, Aneesh Kumar K.V, Greg Kurz

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

Fix comment and remove unneeded inclusion of virtio.h.

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
---
 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%)

diff --git a/hw/9pfs/virtio-9p-handle.c b/hw/9pfs/9p-handle.c
similarity index 99%
rename from hw/9pfs/virtio-9p-handle.c
rename to hw/9pfs/9p-handle.c
index 13eabb9..a48dbc9 100644
--- a/hw/9pfs/virtio-9p-handle.c
+++ b/hw/9pfs/9p-handle.c
@@ -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>
diff --git a/hw/9pfs/Makefile.objs b/hw/9pfs/Makefile.objs
index 76dadbe..9fdd8a4 100644
--- a/hw/9pfs/Makefile.objs
+++ b/hw/9pfs/Makefile.objs
@@ -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
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [Qemu-devel] [PATCH v2 03/27] 9pfs: rename virtio-9p-local.c to 9p-local.c
  2016-01-07 19:55 [Qemu-devel] [PATCH v2 00/27] 9pfs: disentangling virtio and generic code Wei Liu
  2016-01-07 19:55 ` [Qemu-devel] [PATCH v2 01/27] 9pfs: rename virtio-9p-coth.{c, h} to coth.{c, h} Wei Liu
  2016-01-07 19:55 ` [Qemu-devel] [PATCH v2 02/27] 9pfs: rename virtio-9p-handle.c to 9p-handle.c Wei Liu
@ 2016-01-07 19:56 ` Wei Liu
  2016-01-07 19:56 ` [Qemu-devel] [PATCH v2 04/27] 9pfs: rename virtio-9p-posix-acl.c to 9p-posix-acl.c Wei Liu
                   ` (24 subsequent siblings)
  27 siblings, 0 replies; 38+ messages in thread
From: Wei Liu @ 2016-01-07 19:56 UTC (permalink / raw)
  To: qemu-devel; +Cc: Wei Liu, Aneesh Kumar K.V, Greg Kurz

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

Fix comment and remove unneeded inclusion of virtio.h.

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
---
v2: fix commit message
---
 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%)

diff --git a/hw/9pfs/virtio-9p-local.c b/hw/9pfs/9p-local.c
similarity index 99%
rename from hw/9pfs/virtio-9p-local.c
rename to hw/9pfs/9p-local.c
index f1f2e25..877ad86 100644
--- a/hw/9pfs/virtio-9p-local.c
+++ b/hw/9pfs/9p-local.c
@@ -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 */
diff --git a/hw/9pfs/Makefile.objs b/hw/9pfs/Makefile.objs
index 9fdd8a4..5059681 100644
--- a/hw/9pfs/Makefile.objs
+++ b/hw/9pfs/Makefile.objs
@@ -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
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [Qemu-devel] [PATCH v2 04/27] 9pfs: rename virtio-9p-posix-acl.c to 9p-posix-acl.c
  2016-01-07 19:55 [Qemu-devel] [PATCH v2 00/27] 9pfs: disentangling virtio and generic code Wei Liu
                   ` (2 preceding siblings ...)
  2016-01-07 19:56 ` [Qemu-devel] [PATCH v2 03/27] 9pfs: rename virtio-9p-local.c to 9p-local.c Wei Liu
@ 2016-01-07 19:56 ` Wei Liu
  2016-01-07 19:56 ` [Qemu-devel] [PATCH v2 05/27] 9pfs: rename virtio-9p-proxy.{c, h} to 9p-proxy.{c, h} Wei Liu
                   ` (23 subsequent siblings)
  27 siblings, 0 replies; 38+ messages in thread
From: Wei Liu @ 2016-01-07 19:56 UTC (permalink / raw)
  To: qemu-devel; +Cc: Wei Liu, Aneesh Kumar K.V, Greg Kurz

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

Fix comment and remove unneeded inclusion of virtio.h.

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
---
 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%)

diff --git a/hw/9pfs/virtio-9p-posix-acl.c b/hw/9pfs/9p-posix-acl.c
similarity index 98%
rename from hw/9pfs/virtio-9p-posix-acl.c
rename to hw/9pfs/9p-posix-acl.c
index 09dad07..1ee7bdc 100644
--- a/hw/9pfs/virtio-9p-posix-acl.c
+++ b/hw/9pfs/9p-posix-acl.c
@@ -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"
diff --git a/hw/9pfs/Makefile.objs b/hw/9pfs/Makefile.objs
index 5059681..0721462 100644
--- a/hw/9pfs/Makefile.objs
+++ b/hw/9pfs/Makefile.objs
@@ -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
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [Qemu-devel] [PATCH v2 05/27] 9pfs: rename virtio-9p-proxy.{c, h} to 9p-proxy.{c, h}
  2016-01-07 19:55 [Qemu-devel] [PATCH v2 00/27] 9pfs: disentangling virtio and generic code Wei Liu
                   ` (3 preceding siblings ...)
  2016-01-07 19:56 ` [Qemu-devel] [PATCH v2 04/27] 9pfs: rename virtio-9p-posix-acl.c to 9p-posix-acl.c Wei Liu
@ 2016-01-07 19:56 ` Wei Liu
  2016-01-07 19:56 ` [Qemu-devel] [PATCH v2 06/27] 9pfs: rename virtio-9p-synth.{c, h} to 9p-synth.{c, h} Wei Liu
                   ` (22 subsequent siblings)
  27 siblings, 0 replies; 38+ messages in thread
From: Wei Liu @ 2016-01-07 19:56 UTC (permalink / raw)
  To: qemu-devel; +Cc: Wei Liu, Aneesh Kumar K.V, Greg Kurz

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.

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
---
 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%)

diff --git a/fsdev/virtfs-proxy-helper.c b/fsdev/virtfs-proxy-helper.c
index ad1da0d..7753654 100644
--- a/fsdev/virtfs-proxy-helper.c
+++ b/fsdev/virtfs-proxy-helper.c
@@ -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"
diff --git a/hw/9pfs/virtio-9p-proxy.c b/hw/9pfs/9p-proxy.c
similarity index 99%
rename from hw/9pfs/virtio-9p-proxy.c
rename to hw/9pfs/9p-proxy.c
index 1bc7881..67c1fb9 100644
--- a/hw/9pfs/virtio-9p-proxy.c
+++ b/hw/9pfs/9p-proxy.c
@@ -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;
diff --git a/hw/9pfs/virtio-9p-proxy.h b/hw/9pfs/9p-proxy.h
similarity index 95%
rename from hw/9pfs/virtio-9p-proxy.h
rename to hw/9pfs/9p-proxy.h
index 005c1ad..56150b9 100644
--- a/hw/9pfs/virtio-9p-proxy.h
+++ b/hw/9pfs/9p-proxy.h
@@ -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
diff --git a/hw/9pfs/Makefile.objs b/hw/9pfs/Makefile.objs
index 0721462..cd5d146 100644
--- a/hw/9pfs/Makefile.objs
+++ b/hw/9pfs/Makefile.objs
@@ -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
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [Qemu-devel] [PATCH v2 06/27] 9pfs: rename virtio-9p-synth.{c, h} to 9p-synth.{c, h}
  2016-01-07 19:55 [Qemu-devel] [PATCH v2 00/27] 9pfs: disentangling virtio and generic code Wei Liu
                   ` (4 preceding siblings ...)
  2016-01-07 19:56 ` [Qemu-devel] [PATCH v2 05/27] 9pfs: rename virtio-9p-proxy.{c, h} to 9p-proxy.{c, h} Wei Liu
@ 2016-01-07 19:56 ` Wei Liu
  2016-01-07 19:56 ` [Qemu-devel] [PATCH v2 07/27] 9pfs: rename virtio-9p-xattr{, -user}.{c, h} to 9p-xattr{, -user}.{c, h} Wei Liu
                   ` (21 subsequent siblings)
  27 siblings, 0 replies; 38+ messages in thread
From: Wei Liu @ 2016-01-07 19:56 UTC (permalink / raw)
  To: qemu-devel; +Cc: Wei Liu, Aneesh Kumar K.V, Greg Kurz

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.

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
---
 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%)

diff --git a/hw/9pfs/virtio-9p-synth.c b/hw/9pfs/9p-synth.c
similarity index 99%
rename from hw/9pfs/virtio-9p-synth.c
rename to hw/9pfs/9p-synth.c
index a0ab9a8..6d34b89 100644
--- a/hw/9pfs/virtio-9p-synth.c
+++ b/hw/9pfs/9p-synth.c
@@ -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>
diff --git a/hw/9pfs/virtio-9p-synth.h b/hw/9pfs/9p-synth.h
similarity index 94%
rename from hw/9pfs/virtio-9p-synth.h
rename to hw/9pfs/9p-synth.h
index ab05a8e..eaf5a0c 100644
--- a/hw/9pfs/virtio-9p-synth.h
+++ b/hw/9pfs/9p-synth.h
@@ -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>
diff --git a/hw/9pfs/Makefile.objs b/hw/9pfs/Makefile.objs
index cd5d146..ba62571 100644
--- a/hw/9pfs/Makefile.objs
+++ b/hw/9pfs/Makefile.objs
@@ -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
 
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [Qemu-devel] [PATCH v2 07/27] 9pfs: rename virtio-9p-xattr{, -user}.{c, h} to 9p-xattr{, -user}.{c, h}
  2016-01-07 19:55 [Qemu-devel] [PATCH v2 00/27] 9pfs: disentangling virtio and generic code Wei Liu
                   ` (5 preceding siblings ...)
  2016-01-07 19:56 ` [Qemu-devel] [PATCH v2 06/27] 9pfs: rename virtio-9p-synth.{c, h} to 9p-synth.{c, h} Wei Liu
@ 2016-01-07 19:56 ` Wei Liu
  2016-01-07 19:56 ` [Qemu-devel] [PATCH v2 08/27] 9pfs: merge hw/virtio/virtio-9p.h into hw/9pfs/virtio-9p.h Wei Liu
                   ` (20 subsequent siblings)
  27 siblings, 0 replies; 38+ messages in thread
From: Wei Liu @ 2016-01-07 19:56 UTC (permalink / raw)
  To: qemu-devel; +Cc: Michael S. Tsirkin, Wei Liu, Aneesh Kumar K.V, Greg Kurz

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

Fix comments and header inclusion in various files.

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
---
 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%)

diff --git a/hw/9pfs/9p-handle.c b/hw/9pfs/9p-handle.c
index a48dbc9..51a9d15 100644
--- a/hw/9pfs/9p-handle.c
+++ b/hw/9pfs/9p-handle.c
@@ -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>
diff --git a/hw/9pfs/9p-local.c b/hw/9pfs/9p-local.c
index 877ad86..ac553e0 100644
--- a/hw/9pfs/9p-local.c
+++ b/hw/9pfs/9p-local.c
@@ -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>
diff --git a/hw/9pfs/9p-posix-acl.c b/hw/9pfs/9p-posix-acl.c
index 1ee7bdc..073af39 100644
--- a/hw/9pfs/9p-posix-acl.c
+++ b/hw/9pfs/9p-posix-acl.c
@@ -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"
diff --git a/hw/9pfs/9p-synth.c b/hw/9pfs/9p-synth.c
index 6d34b89..b1064e3 100644
--- a/hw/9pfs/9p-synth.c
+++ b/hw/9pfs/9p-synth.c
@@ -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"
diff --git a/hw/9pfs/virtio-9p-xattr-user.c b/hw/9pfs/9p-xattr-user.c
similarity index 97%
rename from hw/9pfs/virtio-9p-xattr-user.c
rename to hw/9pfs/9p-xattr-user.c
index 46133e0..163b158 100644
--- a/hw/9pfs/virtio-9p-xattr-user.c
+++ b/hw/9pfs/9p-xattr-user.c
@@ -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,
diff --git a/hw/9pfs/virtio-9p-xattr.c b/hw/9pfs/9p-xattr.c
similarity index 97%
rename from hw/9pfs/virtio-9p-xattr.c
rename to hw/9pfs/9p-xattr.c
index 0718388..1d7861b 100644
--- a/hw/9pfs/virtio-9p-xattr.c
+++ b/hw/9pfs/9p-xattr.c
@@ -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,
diff --git a/hw/9pfs/virtio-9p-xattr.h b/hw/9pfs/9p-xattr.h
similarity index 97%
rename from hw/9pfs/virtio-9p-xattr.h
rename to hw/9pfs/9p-xattr.h
index 327b32b..4d39a20 100644
--- a/hw/9pfs/virtio-9p-xattr.h
+++ b/hw/9pfs/9p-xattr.h
@@ -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"
 
diff --git a/hw/9pfs/Makefile.objs b/hw/9pfs/Makefile.objs
index ba62571..838c5e1 100644
--- a/hw/9pfs/Makefile.objs
+++ b/hw/9pfs/Makefile.objs
@@ -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
diff --git a/hw/9pfs/virtio-9p-device.c b/hw/9pfs/virtio-9p-device.c
index 667b54a..92ac19b 100644
--- a/hw/9pfs/virtio-9p-device.c
+++ b/hw/9pfs/virtio-9p-device.c
@@ -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"
 
diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c
index 0f178de..30ff828 100644
--- a/hw/9pfs/virtio-9p.c
+++ b/hw/9pfs/virtio-9p.c
@@ -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"
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [Qemu-devel] [PATCH v2 08/27] 9pfs: merge hw/virtio/virtio-9p.h into hw/9pfs/virtio-9p.h
  2016-01-07 19:55 [Qemu-devel] [PATCH v2 00/27] 9pfs: disentangling virtio and generic code Wei Liu
                   ` (6 preceding siblings ...)
  2016-01-07 19:56 ` [Qemu-devel] [PATCH v2 07/27] 9pfs: rename virtio-9p-xattr{, -user}.{c, h} to 9p-xattr{, -user}.{c, h} Wei Liu
@ 2016-01-07 19:56 ` Wei Liu
  2016-01-07 19:56 ` [Qemu-devel] [PATCH v2 09/27] 9pfs: remove dead code Wei Liu
                   ` (19 subsequent siblings)
  27 siblings, 0 replies; 38+ messages in thread
From: Wei Liu @ 2016-01-07 19:56 UTC (permalink / raw)
  To: qemu-devel; +Cc: Greg Kurz, Wei Liu, Aneesh Kumar K.V, Michael S. Tsirkin

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.

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
---
 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

diff --git a/hw/9pfs/virtio-9p-device.c b/hw/9pfs/virtio-9p-device.c
index 92ac19b..885b940 100644
--- a/hw/9pfs/virtio-9p-device.c
+++ b/hw/9pfs/virtio-9p-device.c
@@ -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"
diff --git a/hw/9pfs/virtio-9p.h b/hw/9pfs/virtio-9p.h
index d7a4dc1..ac4cb00 100644
--- a/hw/9pfs/virtio-9p.h
+++ b/hw/9pfs/virtio-9p.h
@@ -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;
diff --git a/hw/virtio/virtio-pci.h b/hw/virtio/virtio-pci.h
index a104ff2..7cf5974 100644
--- a/hw/virtio/virtio-pci.h
+++ b/hw/virtio/virtio-pci.h
@@ -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
diff --git a/include/hw/virtio/virtio-9p.h b/include/hw/virtio/virtio-9p.h
deleted file mode 100644
index 65789db..0000000
--- a/include/hw/virtio/virtio-9p.h
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * Virtio 9p
- *
- * Copyright IBM, Corp. 2010
- *
- * Authors:
- *  Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
- *
- * 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
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [Qemu-devel] [PATCH v2 09/27] 9pfs: remove dead code
  2016-01-07 19:55 [Qemu-devel] [PATCH v2 00/27] 9pfs: disentangling virtio and generic code Wei Liu
                   ` (7 preceding siblings ...)
  2016-01-07 19:56 ` [Qemu-devel] [PATCH v2 08/27] 9pfs: merge hw/virtio/virtio-9p.h into hw/9pfs/virtio-9p.h Wei Liu
@ 2016-01-07 19:56 ` Wei Liu
  2016-01-07 19:56 ` [Qemu-devel] [PATCH v2 10/27] fsdev: break out 9p-marshal.{c, h} from virtio-9p-marshal.{c, h} Wei Liu
                   ` (18 subsequent siblings)
  27 siblings, 0 replies; 38+ messages in thread
From: Wei Liu @ 2016-01-07 19:56 UTC (permalink / raw)
  To: qemu-devel; +Cc: Greg Kurz, Wei Liu, Aneesh Kumar K.V, Michael S. Tsirkin

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.

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
---
v2: don't delete set_fd_limit function
---
 hw/9pfs/virtio-9p.h | 68 -----------------------------------------------------
 1 file changed, 68 deletions(-)

diff --git a/hw/9pfs/virtio-9p.h b/hw/9pfs/virtio-9p.h
index ac4cb00..3c78d3c 100644
--- a/hw/9pfs/virtio-9p.h
+++ b/hw/9pfs/virtio-9p.h
@@ -227,65 +227,6 @@ typedef struct V9fsState
     V9fsConf fsconf;
 } V9fsState;
 
-typedef struct V9fsStatState {
-    V9fsPDU *pdu;
-    size_t offset;
-    V9fsStat v9stat;
-    V9fsFidState *fidp;
-    struct stat stbuf;
-} V9fsStatState;
-
-typedef struct V9fsOpenState {
-    V9fsPDU *pdu;
-    size_t offset;
-    int32_t mode;
-    V9fsFidState *fidp;
-    V9fsQID qid;
-    struct stat stbuf;
-    int iounit;
-} V9fsOpenState;
-
-typedef struct V9fsReadState {
-    V9fsPDU *pdu;
-    size_t offset;
-    int32_t count;
-    int32_t total;
-    int64_t off;
-    V9fsFidState *fidp;
-    struct iovec iov[128]; /* FIXME: bad, bad, bad */
-    struct iovec *sg;
-    off_t dir_pos;
-    struct dirent *dent;
-    struct stat stbuf;
-    V9fsString name;
-    V9fsStat v9stat;
-    int32_t len;
-    int32_t cnt;
-    int32_t max_count;
-} V9fsReadState;
-
-typedef struct V9fsWriteState {
-    V9fsPDU *pdu;
-    size_t offset;
-    int32_t len;
-    int32_t count;
-    int32_t total;
-    int64_t off;
-    V9fsFidState *fidp;
-    struct iovec iov[128]; /* FIXME: bad, bad, bad */
-    struct iovec *sg;
-    int cnt;
-} V9fsWriteState;
-
-typedef struct V9fsMkState {
-    V9fsPDU *pdu;
-    size_t offset;
-    V9fsQID qid;
-    struct stat stbuf;
-    V9fsString name;
-    V9fsString fullname;
-} V9fsMkState;
-
 /* 9p2000.L open flags */
 #define P9_DOTL_RDONLY        00000000
 #define P9_DOTL_WRONLY        00000001
@@ -345,15 +286,6 @@ typedef struct V9fsGetlock
 extern int open_fd_hw;
 extern int total_open_fd;
 
-size_t pdu_packunpack(void *addr, struct iovec *sg, int sg_count,
-                      size_t offset, size_t size, int pack);
-
-static inline size_t do_pdu_unpack(void *dst, struct iovec *sg, int sg_count,
-                        size_t offset, size_t size)
-{
-    return pdu_packunpack(dst, sg, sg_count, offset, size, 0);
-}
-
 static inline void v9fs_path_write_lock(V9fsState *s)
 {
     if (s->ctx.export_flags & V9FS_PATHNAME_FSCONTEXT) {
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [Qemu-devel] [PATCH v2 10/27] fsdev: break out 9p-marshal.{c, h} from virtio-9p-marshal.{c, h}
  2016-01-07 19:55 [Qemu-devel] [PATCH v2 00/27] 9pfs: disentangling virtio and generic code Wei Liu
                   ` (8 preceding siblings ...)
  2016-01-07 19:56 ` [Qemu-devel] [PATCH v2 09/27] 9pfs: remove dead code Wei Liu
@ 2016-01-07 19:56 ` Wei Liu
  2016-01-07 19:56 ` [Qemu-devel] [PATCH v2 11/27] fsdev: 9p-marshal: introduce V9fsBlob Wei Liu
                   ` (17 subsequent siblings)
  27 siblings, 0 replies; 38+ messages in thread
From: Wei Liu @ 2016-01-07 19:56 UTC (permalink / raw)
  To: qemu-devel; +Cc: Wei Liu, Aneesh Kumar K.V, Greg Kurz

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

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
---
v2: remove my name and email
---
 Makefile                  |  2 +-
 fsdev/9p-marshal.c        | 56 +++++++++++++++++++++++++++++++
 fsdev/9p-marshal.h        | 84 +++++++++++++++++++++++++++++++++++++++++++++++
 fsdev/Makefile.objs       |  2 +-
 fsdev/virtio-9p-marshal.c | 31 -----------------
 fsdev/virtio-9p-marshal.h | 79 +-------------------------------------------
 6 files changed, 143 insertions(+), 111 deletions(-)
 create mode 100644 fsdev/9p-marshal.c
 create mode 100644 fsdev/9p-marshal.h

diff --git a/Makefile b/Makefile
index 82b2fc8..7e881d8 100644
--- a/Makefile
+++ b/Makefile
@@ -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
diff --git a/fsdev/9p-marshal.c b/fsdev/9p-marshal.c
new file mode 100644
index 0000000..991e35d
--- /dev/null
+++ b/fsdev/9p-marshal.c
@@ -0,0 +1,56 @@
+/*
+ * 9p backend
+ *
+ * Copyright IBM, Corp. 2010
+ *
+ * Authors:
+ *  Anthony Liguori   <aliguori@us.ibm.com>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.  See
+ * the COPYING file in the top-level directory.
+ *
+ */
+
+#include <glib.h>
+#include <glib/gprintf.h>
+#include <sys/types.h>
+#include <dirent.h>
+#include <sys/time.h>
+#include <utime.h>
+#include <sys/uio.h>
+#include <string.h>
+#include <stdint.h>
+#include <errno.h>
+
+#include "qemu/compiler.h"
+#include "9p-marshal.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);
+}
diff --git a/fsdev/9p-marshal.h b/fsdev/9p-marshal.h
new file mode 100644
index 0000000..e91b24e
--- /dev/null
+++ b/fsdev/9p-marshal.h
@@ -0,0 +1,84 @@
+#ifndef _QEMU_9P_MARSHAL_H
+#define _QEMU_9P_MARSHAL_H
+
+typedef struct V9fsString
+{
+    uint16_t size;
+    char *data;
+} V9fsString;
+
+typedef struct V9fsQID
+{
+    int8_t type;
+    int32_t version;
+    int64_t path;
+} V9fsQID;
+
+typedef struct V9fsStat
+{
+    int16_t size;
+    int16_t type;
+    int32_t dev;
+    V9fsQID qid;
+    int32_t mode;
+    int32_t atime;
+    int32_t mtime;
+    int64_t length;
+    V9fsString name;
+    V9fsString uid;
+    V9fsString gid;
+    V9fsString muid;
+    /* 9p2000.u */
+    V9fsString extension;
+    int32_t n_uid;
+    int32_t n_gid;
+    int32_t n_muid;
+} V9fsStat;
+
+typedef struct V9fsIattr
+{
+    int32_t valid;
+    int32_t mode;
+    int32_t uid;
+    int32_t gid;
+    int64_t size;
+    int64_t atime_sec;
+    int64_t atime_nsec;
+    int64_t mtime_sec;
+    int64_t mtime_nsec;
+} V9fsIattr;
+
+typedef struct V9fsStatDotl {
+    uint64_t st_result_mask;
+    V9fsQID qid;
+    uint32_t st_mode;
+    uint32_t st_uid;
+    uint32_t st_gid;
+    uint64_t st_nlink;
+    uint64_t st_rdev;
+    uint64_t st_size;
+    uint64_t st_blksize;
+    uint64_t st_blocks;
+    uint64_t st_atime_sec;
+    uint64_t st_atime_nsec;
+    uint64_t st_mtime_sec;
+    uint64_t st_mtime_nsec;
+    uint64_t st_ctime_sec;
+    uint64_t st_ctime_nsec;
+    uint64_t st_btime_sec;
+    uint64_t st_btime_nsec;
+    uint64_t st_gen;
+    uint64_t st_data_version;
+} V9fsStatDotl;
+
+static inline void v9fs_string_init(V9fsString *str)
+{
+    str->data = NULL;
+    str->size = 0;
+}
+extern void v9fs_string_free(V9fsString *str);
+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);
+
+#endif
diff --git a/fsdev/Makefile.objs b/fsdev/Makefile.objs
index c27dad3..8357851 100644
--- a/fsdev/Makefile.objs
+++ b/fsdev/Makefile.objs
@@ -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
diff --git a/fsdev/virtio-9p-marshal.c b/fsdev/virtio-9p-marshal.c
index 7748d32..f236bab 100644
--- a/fsdev/virtio-9p-marshal.c
+++ b/fsdev/virtio-9p-marshal.c
@@ -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)
 {
diff --git a/fsdev/virtio-9p-marshal.h b/fsdev/virtio-9p-marshal.h
index 5df65a8..0709bcd 100644
--- a/fsdev/virtio-9p-marshal.h
+++ b/fsdev/virtio-9p-marshal.h
@@ -1,85 +1,8 @@
 #ifndef _QEMU_VIRTIO_9P_MARSHAL_H
 #define _QEMU_VIRTIO_9P_MARSHAL_H
 
-typedef struct V9fsString
-{
-    uint16_t size;
-    char *data;
-} V9fsString;
+#include "9p-marshal.h"
 
-typedef struct V9fsQID
-{
-    int8_t type;
-    int32_t version;
-    int64_t path;
-} V9fsQID;
-
-typedef struct V9fsStat
-{
-    int16_t size;
-    int16_t type;
-    int32_t dev;
-    V9fsQID qid;
-    int32_t mode;
-    int32_t atime;
-    int32_t mtime;
-    int64_t length;
-    V9fsString name;
-    V9fsString uid;
-    V9fsString gid;
-    V9fsString muid;
-    /* 9p2000.u */
-    V9fsString extension;
-   int32_t n_uid;
-    int32_t n_gid;
-    int32_t n_muid;
-} V9fsStat;
-
-typedef struct V9fsIattr
-{
-    int32_t valid;
-    int32_t mode;
-    int32_t uid;
-    int32_t gid;
-    int64_t size;
-    int64_t atime_sec;
-    int64_t atime_nsec;
-    int64_t mtime_sec;
-    int64_t mtime_nsec;
-} V9fsIattr;
-
-typedef struct V9fsStatDotl {
-    uint64_t st_result_mask;
-    V9fsQID qid;
-    uint32_t st_mode;
-    uint32_t st_uid;
-    uint32_t st_gid;
-    uint64_t st_nlink;
-    uint64_t st_rdev;
-    uint64_t st_size;
-    uint64_t st_blksize;
-    uint64_t st_blocks;
-    uint64_t st_atime_sec;
-    uint64_t st_atime_nsec;
-    uint64_t st_mtime_sec;
-    uint64_t st_mtime_nsec;
-    uint64_t st_ctime_sec;
-    uint64_t st_ctime_nsec;
-    uint64_t st_btime_sec;
-    uint64_t st_btime_nsec;
-    uint64_t st_gen;
-    uint64_t st_data_version;
-} V9fsStatDotl;
-
-static inline void v9fs_string_init(V9fsString *str)
-{
-    str->data = NULL;
-    str->size = 0;
-}
-extern void v9fs_string_free(V9fsString *str);
-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);
 
 ssize_t v9fs_pack(struct iovec *in_sg, int in_num, size_t offset,
                   const void *src, size_t size);
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [Qemu-devel] [PATCH v2 11/27] fsdev: 9p-marshal: introduce V9fsBlob
  2016-01-07 19:55 [Qemu-devel] [PATCH v2 00/27] 9pfs: disentangling virtio and generic code Wei Liu
                   ` (9 preceding siblings ...)
  2016-01-07 19:56 ` [Qemu-devel] [PATCH v2 10/27] fsdev: break out 9p-marshal.{c, h} from virtio-9p-marshal.{c, h} Wei Liu
@ 2016-01-07 19:56 ` Wei Liu
  2016-01-07 19:56 ` [Qemu-devel] [PATCH v2 12/27] 9pfs: use V9fsBlob to transmit xattr Wei Liu
                   ` (16 subsequent siblings)
  27 siblings, 0 replies; 38+ messages in thread
From: Wei Liu @ 2016-01-07 19:56 UTC (permalink / raw)
  To: qemu-devel; +Cc: Wei Liu, Aneesh Kumar K.V, Greg Kurz

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.

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
---
 fsdev/9p-marshal.c        |  7 +++++++
 fsdev/9p-marshal.h        | 14 ++++++++++++++
 fsdev/virtio-9p-marshal.c | 26 ++++++++++++++++++++++++++
 3 files changed, 47 insertions(+)

diff --git a/fsdev/9p-marshal.c b/fsdev/9p-marshal.c
index 991e35d..a914244 100644
--- a/fsdev/9p-marshal.c
+++ b/fsdev/9p-marshal.c
@@ -54,3 +54,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;
+}
diff --git a/fsdev/9p-marshal.h b/fsdev/9p-marshal.h
index e91b24e..5a0150b 100644
--- a/fsdev/9p-marshal.h
+++ b/fsdev/9p-marshal.h
@@ -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
diff --git a/fsdev/virtio-9p-marshal.c b/fsdev/virtio-9p-marshal.c
index f236bab..c3ac316 100644
--- a/fsdev/virtio-9p-marshal.c
+++ b/fsdev/virtio-9p-marshal.c
@@ -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",
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [Qemu-devel] [PATCH v2 12/27] 9pfs: use V9fsBlob to transmit xattr
  2016-01-07 19:55 [Qemu-devel] [PATCH v2 00/27] 9pfs: disentangling virtio and generic code Wei Liu
                   ` (10 preceding siblings ...)
  2016-01-07 19:56 ` [Qemu-devel] [PATCH v2 11/27] fsdev: 9p-marshal: introduce V9fsBlob Wei Liu
@ 2016-01-07 19:56 ` Wei Liu
  2016-01-08  8:30   ` Aneesh Kumar K.V
  2016-01-07 19:56 ` [Qemu-devel] [PATCH v2 13/27] fsdev: rename virtio-9p-marshal.{c, h} to 9p-iov-marshal.{c, h} Wei Liu
                   ` (15 subsequent siblings)
  27 siblings, 1 reply; 38+ messages in thread
From: Wei Liu @ 2016-01-07 19:56 UTC (permalink / raw)
  To: qemu-devel; +Cc: Michael S. Tsirkin, Wei Liu, Aneesh Kumar K.V, Greg Kurz

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

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
---
 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(-)

diff --git a/fsdev/virtio-9p-marshal.c b/fsdev/virtio-9p-marshal.c
index c3ac316..d120bd2 100644
--- a/fsdev/virtio-9p-marshal.c
+++ b/fsdev/virtio-9p-marshal.c
@@ -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);
 }
diff --git a/fsdev/virtio-9p-marshal.h b/fsdev/virtio-9p-marshal.h
index 0709bcd..766a48e 100644
--- a/fsdev/virtio-9p-marshal.h
+++ b/fsdev/virtio-9p-marshal.h
@@ -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,
diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c
index 30ff828..654c103 100644
--- a/hw/9pfs/virtio-9p.c
+++ b/hw/9pfs/virtio-9p.c
@@ -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;
     }
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [Qemu-devel] [PATCH v2 13/27] fsdev: rename virtio-9p-marshal.{c, h} to 9p-iov-marshal.{c, h}
  2016-01-07 19:55 [Qemu-devel] [PATCH v2 00/27] 9pfs: disentangling virtio and generic code Wei Liu
                   ` (11 preceding siblings ...)
  2016-01-07 19:56 ` [Qemu-devel] [PATCH v2 12/27] 9pfs: use V9fsBlob to transmit xattr Wei Liu
@ 2016-01-07 19:56 ` Wei Liu
  2016-01-07 19:56 ` [Qemu-devel] [PATCH v2 14/27] 9pfs: PDU processing functions don't need to take V9fsState as argument Wei Liu
                   ` (14 subsequent siblings)
  27 siblings, 0 replies; 38+ messages in thread
From: Wei Liu @ 2016-01-07 19:56 UTC (permalink / raw)
  To: qemu-devel; +Cc: Michael S. Tsirkin, Wei Liu, Aneesh Kumar K.V, Greg Kurz

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.

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
---
 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

diff --git a/Makefile b/Makefile
index 7e881d8..d0de2d4 100644
--- a/Makefile
+++ b/Makefile
@@ -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
diff --git a/fsdev/virtio-9p-marshal.c b/fsdev/9p-iov-marshal.c
similarity index 63%
rename from fsdev/virtio-9p-marshal.c
rename to fsdev/9p-iov-marshal.c
index d120bd2..d17983e 100644
--- a/fsdev/virtio-9p-marshal.c
+++ b/fsdev/9p-iov-marshal.c
@@ -1,5 +1,5 @@
 /*
- * Virtio 9p backend
+ * 9p backend
  *
  * Copyright IBM, Corp. 2010
  *
@@ -22,7 +22,7 @@
 #include <errno.h>
 
 #include "qemu/compiler.h"
-#include "virtio-9p-marshal.h"
+#include "9p-iov-marshal.h"
 #include "qemu/bswap.h"
 
 static ssize_t v9fs_packunpack(void *addr, struct iovec *sg, int sg_count,
@@ -76,8 +76,8 @@ 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_unmarshal(struct iovec *out_sg, int out_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;
     va_list ap;
@@ -127,8 +127,8 @@ ssize_t v9fs_unmarshal(struct iovec *out_sg, int out_num, size_t offset,
         }
         case 's': {
             V9fsString *str = va_arg(ap, V9fsString *);
-            copied = v9fs_unmarshal(out_sg, out_num, offset, bswap,
-                                    "w", &str->size);
+            copied = v9fs_iov_unmarshal(out_sg, out_num, offset, bswap,
+                                        "w", &str->size);
             if (copied > 0) {
                 offset += copied;
                 str->data = g_malloc(str->size + 1);
@@ -144,8 +144,8 @@ ssize_t v9fs_unmarshal(struct iovec *out_sg, int out_num, size_t offset,
         }
         case 'B': {
             V9fsBlob *blob = va_arg(ap, V9fsBlob *);
-            copied = v9fs_unmarshal(out_sg, out_num, offset, bswap,
-                                    "w", &blob->size);
+            copied = v9fs_iov_unmarshal(out_sg, out_num, offset, bswap,
+                                        "w", &blob->size);
             if (copied > 0) {
                 offset += copied;
                 blob->data = g_malloc(blob->size);
@@ -159,31 +159,36 @@ ssize_t v9fs_unmarshal(struct iovec *out_sg, int out_num, size_t offset,
         }
         case 'Q': {
             V9fsQID *qidp = va_arg(ap, V9fsQID *);
-            copied = v9fs_unmarshal(out_sg, out_num, offset, bswap, "bdq",
-                                    &qidp->type, &qidp->version, &qidp->path);
+            copied = v9fs_iov_unmarshal(out_sg, out_num, offset, bswap,
+                                        "bdq", &qidp->type, &qidp->version,
+                                        &qidp->path);
             break;
         }
         case 'S': {
             V9fsStat *statp = va_arg(ap, V9fsStat *);
-            copied = v9fs_unmarshal(out_sg, out_num, offset, bswap,
-                                    "wwdQdddqsssssddd",
-                                    &statp->size, &statp->type, &statp->dev,
-                                    &statp->qid, &statp->mode, &statp->atime,
-                                    &statp->mtime, &statp->length,
-                                    &statp->name, &statp->uid, &statp->gid,
-                                    &statp->muid, &statp->extension,
-                                    &statp->n_uid, &statp->n_gid,
-                                    &statp->n_muid);
+            copied = v9fs_iov_unmarshal(out_sg, out_num, offset, bswap,
+                                        "wwdQdddqsssssddd",
+                                        &statp->size, &statp->type,
+                                        &statp->dev, &statp->qid,
+                                        &statp->mode, &statp->atime,
+                                        &statp->mtime, &statp->length,
+                                        &statp->name, &statp->uid,
+                                        &statp->gid, &statp->muid,
+                                        &statp->extension,
+                                        &statp->n_uid, &statp->n_gid,
+                                        &statp->n_muid);
             break;
         }
         case 'I': {
             V9fsIattr *iattr = va_arg(ap, V9fsIattr *);
-            copied = v9fs_unmarshal(out_sg, out_num, offset, bswap,
-                                    "ddddqqqqq",
-                                    &iattr->valid, &iattr->mode,
-                                    &iattr->uid, &iattr->gid, &iattr->size,
-                                    &iattr->atime_sec, &iattr->atime_nsec,
-                                    &iattr->mtime_sec, &iattr->mtime_nsec);
+            copied = v9fs_iov_unmarshal(out_sg, out_num, offset, bswap,
+                                        "ddddqqqqq",
+                                        &iattr->valid, &iattr->mode,
+                                        &iattr->uid, &iattr->gid,
+                                        &iattr->size, &iattr->atime_sec,
+                                        &iattr->atime_nsec,
+                                        &iattr->mtime_sec,
+                                        &iattr->mtime_nsec);
             break;
         }
         default:
@@ -200,8 +205,8 @@ ssize_t v9fs_unmarshal(struct iovec *out_sg, int out_num, size_t offset,
     return offset - old_offset;
 }
 
-ssize_t v9fs_marshal(struct iovec *in_sg, int in_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, ...)
 {
     int i;
     va_list ap;
@@ -248,8 +253,8 @@ ssize_t v9fs_marshal(struct iovec *in_sg, int in_num, size_t offset,
         }
         case 's': {
             V9fsString *str = va_arg(ap, V9fsString *);
-            copied = v9fs_marshal(in_sg, in_num, offset, bswap,
-                                  "w", str->size);
+            copied = v9fs_iov_marshal(in_sg, in_num, offset, bswap,
+                                      "w", str->size);
             if (copied > 0) {
                 offset += copied;
                 copied = v9fs_pack(in_sg, in_num, offset, str->data, str->size);
@@ -258,8 +263,8 @@ ssize_t v9fs_marshal(struct iovec *in_sg, int in_num, size_t offset,
         }
         case 'B': {
             V9fsBlob *blob = va_arg(ap, V9fsBlob *);
-            copied = v9fs_marshal(in_sg, in_num, offset, bswap,
-                                  "w", blob->size);
+            copied = v9fs_iov_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,
@@ -269,37 +274,42 @@ ssize_t v9fs_marshal(struct iovec *in_sg, int in_num, size_t offset,
         }
         case 'Q': {
             V9fsQID *qidp = va_arg(ap, V9fsQID *);
-            copied = v9fs_marshal(in_sg, in_num, offset, bswap, "bdq",
-                                  qidp->type, qidp->version, qidp->path);
+            copied = v9fs_iov_marshal(in_sg, in_num, offset, bswap, "bdq",
+                                      qidp->type, qidp->version,
+                                      qidp->path);
             break;
         }
         case 'S': {
             V9fsStat *statp = va_arg(ap, V9fsStat *);
-            copied = v9fs_marshal(in_sg, in_num, offset, bswap,
-                                  "wwdQdddqsssssddd",
-                                  statp->size, statp->type, statp->dev,
-                                  &statp->qid, statp->mode, statp->atime,
-                                  statp->mtime, statp->length, &statp->name,
-                                  &statp->uid, &statp->gid, &statp->muid,
-                                  &statp->extension, statp->n_uid,
-                                  statp->n_gid, statp->n_muid);
+            copied = v9fs_iov_marshal(in_sg, in_num, offset, bswap,
+                                      "wwdQdddqsssssddd",
+                                      statp->size, statp->type, statp->dev,
+                                      &statp->qid, statp->mode, statp->atime,
+                                      statp->mtime, statp->length,
+                                      &statp->name,
+                                      &statp->uid, &statp->gid, &statp->muid,
+                                      &statp->extension, statp->n_uid,
+                                      statp->n_gid, statp->n_muid);
             break;
         }
         case 'A': {
             V9fsStatDotl *statp = va_arg(ap, V9fsStatDotl *);
-            copied = v9fs_marshal(in_sg, in_num, offset, bswap,
-                                   "qQdddqqqqqqqqqqqqqqq",
-                                   statp->st_result_mask,
-                                   &statp->qid, statp->st_mode,
-                                   statp->st_uid, statp->st_gid,
-                                   statp->st_nlink, statp->st_rdev,
-                                   statp->st_size, statp->st_blksize,
-                                   statp->st_blocks, statp->st_atime_sec,
-                                   statp->st_atime_nsec, statp->st_mtime_sec,
-                                   statp->st_mtime_nsec, statp->st_ctime_sec,
-                                   statp->st_ctime_nsec, statp->st_btime_sec,
-                                   statp->st_btime_nsec, statp->st_gen,
-                                   statp->st_data_version);
+            copied = v9fs_iov_marshal(in_sg, in_num, offset, bswap,
+                                      "qQdddqqqqqqqqqqqqqqq",
+                                      statp->st_result_mask,
+                                      &statp->qid, statp->st_mode,
+                                      statp->st_uid, statp->st_gid,
+                                      statp->st_nlink, statp->st_rdev,
+                                      statp->st_size, statp->st_blksize,
+                                      statp->st_blocks, statp->st_atime_sec,
+                                      statp->st_atime_nsec,
+                                      statp->st_mtime_sec,
+                                      statp->st_mtime_nsec,
+                                      statp->st_ctime_sec,
+                                      statp->st_ctime_nsec,
+                                      statp->st_btime_sec,
+                                      statp->st_btime_nsec, statp->st_gen,
+                                      statp->st_data_version);
             break;
         }
         default:
diff --git a/fsdev/9p-iov-marshal.h b/fsdev/9p-iov-marshal.h
new file mode 100644
index 0000000..72c0cb3
--- /dev/null
+++ b/fsdev/9p-iov-marshal.h
@@ -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
diff --git a/fsdev/Makefile.objs b/fsdev/Makefile.objs
index 8357851..1b120a4 100644
--- a/fsdev/Makefile.objs
+++ b/fsdev/Makefile.objs
@@ -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
diff --git a/fsdev/virtfs-proxy-helper.c b/fsdev/virtfs-proxy-helper.c
index 7753654..44c7d88 100644
--- a/fsdev/virtfs-proxy-helper.c
+++ b/fsdev/virtfs-proxy-helper.c
@@ -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"
 
diff --git a/fsdev/virtio-9p-marshal.h b/fsdev/virtio-9p-marshal.h
deleted file mode 100644
index 766a48e..0000000
--- a/fsdev/virtio-9p-marshal.h
+++ /dev/null
@@ -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
diff --git a/hw/9pfs/9p-proxy.h b/hw/9pfs/9p-proxy.h
index 56150b9..ba9ca20 100644
--- a/hw/9pfs/9p-proxy.h
+++ b/hw/9pfs/9p-proxy.h
@@ -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;
diff --git a/hw/9pfs/virtio-9p.h b/hw/9pfs/virtio-9p.h
index 3c78d3c..3a7e136 100644
--- a/hw/9pfs/virtio-9p.h
+++ b/hw/9pfs/virtio-9p.h
@@ -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) \
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [Qemu-devel] [PATCH v2 14/27] 9pfs: PDU processing functions don't need to take V9fsState as argument
  2016-01-07 19:55 [Qemu-devel] [PATCH v2 00/27] 9pfs: disentangling virtio and generic code Wei Liu
                   ` (12 preceding siblings ...)
  2016-01-07 19:56 ` [Qemu-devel] [PATCH v2 13/27] fsdev: rename virtio-9p-marshal.{c, h} to 9p-iov-marshal.{c, h} Wei Liu
@ 2016-01-07 19:56 ` Wei Liu
  2016-01-07 19:56 ` [Qemu-devel] [PATCH v2 15/27] 9pfs: PDU processing functions should start pdu_ prefix Wei Liu
                   ` (13 subsequent siblings)
  27 siblings, 0 replies; 38+ messages in thread
From: Wei Liu @ 2016-01-07 19:56 UTC (permalink / raw)
  To: qemu-devel; +Cc: Greg Kurz, Wei Liu, Aneesh Kumar K.V, Michael S. Tsirkin

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

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
---
 hw/9pfs/virtio-9p-device.c |  1 +
 hw/9pfs/virtio-9p.c        | 98 +++++++++++++++++++++-------------------------
 2 files changed, 46 insertions(+), 53 deletions(-)

diff --git a/hw/9pfs/virtio-9p-device.c b/hw/9pfs/virtio-9p-device.c
index 885b940..f3091cc 100644
--- a/hw/9pfs/virtio-9p-device.c
+++ b/hw/9pfs/virtio-9p-device.c
@@ -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);
diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c
index 654c103..13381c0 100644
--- a/hw/9pfs/virtio-9p.c
+++ b/hw/9pfs/virtio-9p.c
@@ -575,9 +575,10 @@ static V9fsPDU *alloc_pdu(V9fsState *s)
     return pdu;
 }
 
-static void free_pdu(V9fsState *s, V9fsPDU *pdu)
+static void free_pdu(V9fsPDU *pdu)
 {
     if (pdu) {
+        V9fsState *s = pdu->s;
         /*
          * Cancelled pdu are added back to the freelist
          * by flush request .
@@ -594,9 +595,10 @@ static void free_pdu(V9fsState *s, V9fsPDU *pdu)
  * because we always expect to have enough space to encode
  * error details
  */
-static void complete_pdu(V9fsState *s, V9fsPDU *pdu, ssize_t len)
+static void complete_pdu(V9fsPDU *pdu, ssize_t len)
 {
     int8_t id = pdu->id + 1; /* Response */
+    V9fsState *s = pdu->s;
 
     if (len < 0) {
         int err = -len;
@@ -636,7 +638,7 @@ static void complete_pdu(V9fsState *s, V9fsPDU *pdu, ssize_t len)
     /* Now wakeup anybody waiting in flush for this request */
     qemu_co_queue_next(&pdu->complete);
 
-    free_pdu(s, pdu);
+    free_pdu(pdu);
 }
 
 static mode_t v9mode_to_mode(uint32_t mode, V9fsString *extension)
@@ -931,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(s, pdu, offset);
+    complete_pdu(pdu, offset);
     v9fs_string_free(&version);
 }
 
@@ -995,7 +997,7 @@ static void v9fs_attach(void *opaque)
 out:
     put_fid(pdu, fidp);
 out_nofid:
-    complete_pdu(s, pdu, err);
+    complete_pdu(pdu, err);
     v9fs_string_free(&uname);
     v9fs_string_free(&aname);
 }
@@ -1009,7 +1011,6 @@ static void v9fs_stat(void *opaque)
     struct stat stbuf;
     V9fsFidState *fidp;
     V9fsPDU *pdu = opaque;
-    V9fsState *s = pdu->s;
 
     err = pdu_unmarshal(pdu, offset, "d", &fid);
     if (err < 0) {
@@ -1042,7 +1043,7 @@ static void v9fs_stat(void *opaque)
 out:
     put_fid(pdu, fidp);
 out_nofid:
-    complete_pdu(s, pdu, err);
+    complete_pdu(pdu, err);
 }
 
 static void v9fs_getattr(void *opaque)
@@ -1105,7 +1106,7 @@ static void v9fs_getattr(void *opaque)
 out:
     put_fid(pdu, fidp);
 out_nofid:
-    complete_pdu(s, pdu, retval);
+    complete_pdu(pdu, retval);
 }
 
 /* Attribute flags */
@@ -1129,7 +1130,6 @@ static void v9fs_setattr(void *opaque)
     size_t offset = 7;
     V9fsIattr v9iattr;
     V9fsPDU *pdu = opaque;
-    V9fsState *s = pdu->s;
 
     err = pdu_unmarshal(pdu, offset, "dI", &fid, &v9iattr);
     if (err < 0) {
@@ -1203,7 +1203,7 @@ static void v9fs_setattr(void *opaque)
 out:
     put_fid(pdu, fidp);
 out_nofid:
-    complete_pdu(s, pdu, err);
+    complete_pdu(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(s, pdu, err);
+        complete_pdu(pdu, err);
         return ;
     }
     offset += err;
@@ -1313,7 +1313,7 @@ out:
     v9fs_path_free(&dpath);
     v9fs_path_free(&path);
 out_nofid:
-    complete_pdu(s, pdu, err);
+    complete_pdu(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(s, pdu, err);
+    complete_pdu(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->s, pdu, err);
+    complete_pdu(pdu, err);
     v9fs_string_free(&name);
 }
 
@@ -1499,7 +1499,6 @@ static void v9fs_fsync(void *opaque)
     size_t offset = 7;
     V9fsFidState *fidp;
     V9fsPDU *pdu = opaque;
-    V9fsState *s = pdu->s;
 
     err = pdu_unmarshal(pdu, offset, "dd", &fid, &datasync);
     if (err < 0) {
@@ -1518,7 +1517,7 @@ static void v9fs_fsync(void *opaque)
     }
     put_fid(pdu, fidp);
 out_nofid:
-    complete_pdu(s, pdu, err);
+    complete_pdu(pdu, err);
 }
 
 static void v9fs_clunk(void *opaque)
@@ -1551,7 +1550,7 @@ static void v9fs_clunk(void *opaque)
         err = offset;
     }
 out_nofid:
-    complete_pdu(s, pdu, err);
+    complete_pdu(pdu, err);
 }
 
 static int v9fs_xattr_read(V9fsState *s, V9fsPDU *pdu, V9fsFidState *fidp,
@@ -1766,7 +1765,7 @@ static void v9fs_read(void *opaque)
 out:
     put_fid(pdu, fidp);
 out_nofid:
-    complete_pdu(s, pdu, err);
+    complete_pdu(pdu, err);
 }
 
 static size_t v9fs_readdir_data_size(V9fsString *name)
@@ -1853,7 +1852,6 @@ static void v9fs_readdir(void *opaque)
     int32_t count;
     uint32_t max_count;
     V9fsPDU *pdu = opaque;
-    V9fsState *s = pdu->s;
 
     retval = pdu_unmarshal(pdu, offset, "dqd", &fid,
                            &initial_offset, &max_count);
@@ -1890,7 +1888,7 @@ static void v9fs_readdir(void *opaque)
 out:
     put_fid(pdu, fidp);
 out_nofid:
-    complete_pdu(s, pdu, retval);
+    complete_pdu(pdu, retval);
 }
 
 static int v9fs_xattr_write(V9fsState *s, V9fsPDU *pdu, V9fsFidState *fidp,
@@ -1957,7 +1955,7 @@ static void v9fs_write(void *opaque)
 
     err = pdu_unmarshal(pdu, offset, "dqd", &fid, &off, &count);
     if (err < 0) {
-        complete_pdu(s, pdu, err);
+        complete_pdu(pdu, err);
         return;
     }
     offset += err;
@@ -2020,7 +2018,7 @@ out:
     put_fid(pdu, fidp);
 out_nofid:
     qemu_iovec_destroy(&qiov_full);
-    complete_pdu(s, pdu, err);
+    complete_pdu(pdu, err);
 }
 
 static void v9fs_create(void *opaque)
@@ -2187,7 +2185,7 @@ static void v9fs_create(void *opaque)
 out:
     put_fid(pdu, fidp);
 out_nofid:
-   complete_pdu(pdu->s, pdu, err);
+   complete_pdu(pdu, err);
    v9fs_string_free(&name);
    v9fs_string_free(&extension);
    v9fs_path_free(&path);
@@ -2234,7 +2232,7 @@ static void v9fs_symlink(void *opaque)
 out:
     put_fid(pdu, dfidp);
 out_nofid:
-    complete_pdu(pdu->s, pdu, err);
+    complete_pdu(pdu, err);
     v9fs_string_free(&name);
     v9fs_string_free(&symname);
 }
@@ -2250,7 +2248,7 @@ static void v9fs_flush(void *opaque)
 
     err = pdu_unmarshal(pdu, offset, "w", &tag);
     if (err < 0) {
-        complete_pdu(s, pdu, err);
+        complete_pdu(pdu, err);
         return;
     }
     trace_v9fs_flush(pdu->tag, pdu->id, tag);
@@ -2267,15 +2265,14 @@ static void v9fs_flush(void *opaque)
          */
         qemu_co_queue_wait(&cancel_pdu->complete);
         cancel_pdu->cancelled = 0;
-        free_pdu(pdu->s, cancel_pdu);
+        free_pdu(cancel_pdu);
     }
-    complete_pdu(s, pdu, 7);
+    complete_pdu(pdu, 7);
 }
 
 static void v9fs_link(void *opaque)
 {
     V9fsPDU *pdu = opaque;
-    V9fsState *s = pdu->s;
     int32_t dfid, oldfid;
     V9fsFidState *dfidp, *oldfidp;
     V9fsString name;
@@ -2308,7 +2305,7 @@ out:
     put_fid(pdu, dfidp);
 out_nofid:
     v9fs_string_free(&name);
-    complete_pdu(s, pdu, err);
+    complete_pdu(pdu, err);
 }
 
 /* Only works with path name based fid */
@@ -2353,7 +2350,7 @@ out_err:
     clunk_fid(pdu->s, fidp->fid);
     put_fid(pdu, fidp);
 out_nofid:
-    complete_pdu(pdu->s, pdu, err);
+    complete_pdu(pdu, err);
 }
 
 static void v9fs_unlinkat(void *opaque)
@@ -2397,7 +2394,7 @@ out_err:
     put_fid(pdu, dfidp);
     v9fs_path_free(&path);
 out_nofid:
-    complete_pdu(pdu->s, pdu, err);
+    complete_pdu(pdu, err);
     v9fs_string_free(&name);
 }
 
@@ -2497,7 +2494,7 @@ static void v9fs_rename(void *opaque)
 out:
     put_fid(pdu, fidp);
 out_nofid:
-    complete_pdu(s, pdu, err);
+    complete_pdu(pdu, err);
     v9fs_string_free(&name);
 }
 
@@ -2598,7 +2595,7 @@ static void v9fs_renameat(void *opaque)
     }
 
 out_err:
-    complete_pdu(s, pdu, err);
+    complete_pdu(pdu, err);
     v9fs_string_free(&old_name);
     v9fs_string_free(&new_name);
 }
@@ -2613,7 +2610,6 @@ static void v9fs_wstat(void *opaque)
     struct stat stbuf;
     V9fsFidState *fidp;
     V9fsPDU *pdu = opaque;
-    V9fsState *s = pdu->s;
 
     v9fs_stat_init(&v9stat);
     err = pdu_unmarshal(pdu, offset, "dwS", &fid, &unused, &v9stat);
@@ -2695,7 +2691,7 @@ out:
     put_fid(pdu, fidp);
 out_nofid:
     v9fs_stat_free(&v9stat);
-    complete_pdu(s, pdu, err);
+    complete_pdu(pdu, err);
 }
 
 static int v9fs_fill_statfs(V9fsState *s, V9fsPDU *pdu, struct statfs *stbuf)
@@ -2774,7 +2770,7 @@ static void v9fs_statfs(void *opaque)
 out:
     put_fid(pdu, fidp);
 out_nofid:
-    complete_pdu(s, pdu, retval);
+    complete_pdu(pdu, retval);
 }
 
 static void v9fs_mknod(void *opaque)
@@ -2791,7 +2787,6 @@ static void v9fs_mknod(void *opaque)
     struct stat stbuf;
     V9fsFidState *fidp;
     V9fsPDU *pdu = opaque;
-    V9fsState *s = pdu->s;
 
     v9fs_string_init(&name);
     err = pdu_unmarshal(pdu, offset, "dsdddd", &fid, &name, &mode,
@@ -2822,7 +2817,7 @@ static void v9fs_mknod(void *opaque)
 out:
     put_fid(pdu, fidp);
 out_nofid:
-    complete_pdu(s, pdu, err);
+    complete_pdu(pdu, err);
     v9fs_string_free(&name);
 }
 
@@ -2843,7 +2838,6 @@ static void v9fs_lock(void *opaque)
     V9fsFidState *fidp;
     int32_t fid, err = 0;
     V9fsPDU *pdu = opaque;
-    V9fsState *s = pdu->s;
 
     status = P9_LOCK_ERROR;
     v9fs_string_init(&flock.client_id);
@@ -2880,7 +2874,7 @@ out_nofid:
         err += offset;
     }
     trace_v9fs_lock_return(pdu->tag, pdu->id, status);
-    complete_pdu(s, pdu, err);
+    complete_pdu(pdu, err);
     v9fs_string_free(&flock.client_id);
 }
 
@@ -2896,7 +2890,6 @@ static void v9fs_getlock(void *opaque)
     V9fsGetlock glock;
     int32_t fid, err = 0;
     V9fsPDU *pdu = opaque;
-    V9fsState *s = pdu->s;
 
     v9fs_string_init(&glock.client_id);
     err = pdu_unmarshal(pdu, offset, "dbqqds", &fid, &glock.type,
@@ -2930,7 +2923,7 @@ static void v9fs_getlock(void *opaque)
 out:
     put_fid(pdu, fidp);
 out_nofid:
-    complete_pdu(s, pdu, err);
+    complete_pdu(pdu, err);
     v9fs_string_free(&glock.client_id);
 }
 
@@ -2974,7 +2967,7 @@ static void v9fs_mkdir(void *opaque)
 out:
     put_fid(pdu, fidp);
 out_nofid:
-    complete_pdu(pdu->s, pdu, err);
+    complete_pdu(pdu, err);
     v9fs_string_free(&name);
 }
 
@@ -3080,7 +3073,7 @@ out:
         put_fid(pdu, xattr_fidp);
     }
 out_nofid:
-    complete_pdu(s, pdu, err);
+    complete_pdu(pdu, err);
     v9fs_string_free(&name);
 }
 
@@ -3095,7 +3088,6 @@ static void v9fs_xattrcreate(void *opaque)
     V9fsFidState *file_fidp;
     V9fsFidState *xattr_fidp;
     V9fsPDU *pdu = opaque;
-    V9fsState *s = pdu->s;
 
     v9fs_string_init(&name);
     err = pdu_unmarshal(pdu, offset, "dsqd", &fid, &name, &size, &flags);
@@ -3121,7 +3113,7 @@ static void v9fs_xattrcreate(void *opaque)
     err = offset;
     put_fid(pdu, file_fidp);
 out_nofid:
-    complete_pdu(s, pdu, err);
+    complete_pdu(pdu, err);
     v9fs_string_free(&name);
 }
 
@@ -3161,7 +3153,7 @@ static void v9fs_readlink(void *opaque)
 out:
     put_fid(pdu, fidp);
 out_nofid:
-    complete_pdu(pdu->s, pdu, err);
+    complete_pdu(pdu, err);
 }
 
 static CoroutineEntry *pdu_co_handlers[] = {
@@ -3204,13 +3196,13 @@ static CoroutineEntry *pdu_co_handlers[] = {
 static void v9fs_op_not_supp(void *opaque)
 {
     V9fsPDU *pdu = opaque;
-    complete_pdu(pdu->s, pdu, -EOPNOTSUPP);
+    complete_pdu(pdu, -EOPNOTSUPP);
 }
 
 static void v9fs_fs_ro(void *opaque)
 {
     V9fsPDU *pdu = opaque;
-    complete_pdu(pdu->s, pdu, -EROFS);
+    complete_pdu(pdu, -EROFS);
 }
 
 static inline bool is_read_only_op(V9fsPDU *pdu)
@@ -3240,10 +3232,11 @@ static inline bool is_read_only_op(V9fsPDU *pdu)
     }
 }
 
-static void submit_pdu(V9fsState *s, V9fsPDU *pdu)
+static void submit_pdu(V9fsPDU *pdu)
 {
     Coroutine *co;
     CoroutineEntry *handler;
+    V9fsState *s = pdu->s;
 
     if (pdu->id >= ARRAY_SIZE(pdu_co_handlers) ||
         (pdu_co_handlers[pdu->id] == NULL)) {
@@ -3274,7 +3267,6 @@ void handle_9p_output(VirtIODevice *vdev, VirtQueue *vq)
         } QEMU_PACKED out;
         int len;
 
-        pdu->s = s;
         BUG_ON(pdu->elem.out_num == 0 || pdu->elem.in_num == 0);
         QEMU_BUILD_BUG_ON(sizeof out != 7);
 
@@ -3288,9 +3280,9 @@ void handle_9p_output(VirtIODevice *vdev, VirtQueue *vq)
         pdu->tag = le16_to_cpu(out.tag_le);
 
         qemu_co_queue_init(&pdu->complete);
-        submit_pdu(s, pdu);
+        submit_pdu(pdu);
     }
-    free_pdu(s, pdu);
+    free_pdu(pdu);
 }
 
 static void __attribute__((__constructor__)) virtio_9p_set_fd_limit(void)
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [Qemu-devel] [PATCH v2 15/27] 9pfs: PDU processing functions should start pdu_ prefix
  2016-01-07 19:55 [Qemu-devel] [PATCH v2 00/27] 9pfs: disentangling virtio and generic code Wei Liu
                   ` (13 preceding siblings ...)
  2016-01-07 19:56 ` [Qemu-devel] [PATCH v2 14/27] 9pfs: PDU processing functions don't need to take V9fsState as argument Wei Liu
@ 2016-01-07 19:56 ` Wei Liu
  2016-01-07 19:56 ` [Qemu-devel] [PATCH v2 16/27] 9pfs: make pdu_{, un}marshal proper functions Wei Liu
                   ` (12 subsequent siblings)
  27 siblings, 0 replies; 38+ messages in thread
From: Wei Liu @ 2016-01-07 19:56 UTC (permalink / raw)
  To: qemu-devel; +Cc: Greg Kurz, Wei Liu, Aneesh Kumar K.V, Michael S. Tsirkin

This matches naming convention of pdu_marshal and pdu_unmarshal.

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
---
 hw/9pfs/virtio-9p.c | 88 ++++++++++++++++++++++++++---------------------------
 1 file changed, 44 insertions(+), 44 deletions(-)

diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c
index 13381c0..c0a489e 100644
--- a/hw/9pfs/virtio-9p.c
+++ b/hw/9pfs/virtio-9p.c
@@ -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,9 +3280,9 @@ 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);
 }
 
 static void __attribute__((__constructor__)) virtio_9p_set_fd_limit(void)
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [Qemu-devel] [PATCH v2 16/27] 9pfs: make pdu_{, un}marshal proper functions
  2016-01-07 19:55 [Qemu-devel] [PATCH v2 00/27] 9pfs: disentangling virtio and generic code Wei Liu
                   ` (14 preceding siblings ...)
  2016-01-07 19:56 ` [Qemu-devel] [PATCH v2 15/27] 9pfs: PDU processing functions should start pdu_ prefix Wei Liu
@ 2016-01-07 19:56 ` Wei Liu
  2016-01-07 19:56 ` [Qemu-devel] [PATCH v2 17/27] 9pfs: factor out virtio_pdu_{, un}marshal Wei Liu
                   ` (11 subsequent siblings)
  27 siblings, 0 replies; 38+ messages in thread
From: Wei Liu @ 2016-01-07 19:56 UTC (permalink / raw)
  To: qemu-devel; +Cc: Michael S. Tsirkin, Wei Liu, Aneesh Kumar K.V, Greg Kurz

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

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
---
 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(-)

diff --git a/fsdev/9p-iov-marshal.c b/fsdev/9p-iov-marshal.c
index d17983e..4db7133 100644
--- a/fsdev/9p-iov-marshal.c
+++ b/fsdev/9p-iov-marshal.c
@@ -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;
+}
diff --git a/fsdev/9p-iov-marshal.h b/fsdev/9p-iov-marshal.h
index 72c0cb3..410a1ea 100644
--- a/fsdev/9p-iov-marshal.h
+++ b/fsdev/9p-iov-marshal.h
@@ -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
diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c
index c0a489e..d63510a 100644
--- a/hw/9pfs/virtio-9p.c
+++ b/hw/9pfs/virtio-9p.c
@@ -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;
diff --git a/hw/9pfs/virtio-9p.h b/hw/9pfs/virtio-9p.h
index 3a7e136..d6f3ac0 100644
--- a/hw/9pfs/virtio-9p.h
+++ b/hw/9pfs/virtio-9p.h
@@ -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) \
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [Qemu-devel] [PATCH v2 17/27] 9pfs: factor out virtio_pdu_{, un}marshal
  2016-01-07 19:55 [Qemu-devel] [PATCH v2 00/27] 9pfs: disentangling virtio and generic code Wei Liu
                   ` (15 preceding siblings ...)
  2016-01-07 19:56 ` [Qemu-devel] [PATCH v2 16/27] 9pfs: make pdu_{, un}marshal proper functions Wei Liu
@ 2016-01-07 19:56 ` Wei Liu
  2016-01-07 19:56 ` [Qemu-devel] [PATCH v2 18/27] 9pfs: factor out pdu_push_and_notify Wei Liu
                   ` (10 subsequent siblings)
  27 siblings, 0 replies; 38+ messages in thread
From: Wei Liu @ 2016-01-07 19:56 UTC (permalink / raw)
  To: qemu-devel; +Cc: Greg Kurz, Wei Liu, Aneesh Kumar K.V, Michael S. Tsirkin

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
---
 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(-)

diff --git a/hw/9pfs/virtio-9p-device.c b/hw/9pfs/virtio-9p-device.c
index f3091cc..d77247f 100644
--- a/hw/9pfs/virtio-9p-device.c
+++ b/hw/9pfs/virtio-9p-device.c
@@ -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[] = {
diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c
index d63510a..498e327 100644
--- a/hw/9pfs/virtio-9p.c
+++ b/hw/9pfs/virtio-9p.c
@@ -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;
diff --git a/hw/9pfs/virtio-9p.h b/hw/9pfs/virtio-9p.h
index d6f3ac0..e298949 100644
--- a/hw/9pfs/virtio-9p.h
+++ b/hw/9pfs/virtio-9p.h
@@ -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)
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [Qemu-devel] [PATCH v2 18/27] 9pfs: factor out pdu_push_and_notify
  2016-01-07 19:55 [Qemu-devel] [PATCH v2 00/27] 9pfs: disentangling virtio and generic code Wei Liu
                   ` (16 preceding siblings ...)
  2016-01-07 19:56 ` [Qemu-devel] [PATCH v2 17/27] 9pfs: factor out virtio_pdu_{, un}marshal Wei Liu
@ 2016-01-07 19:56 ` Wei Liu
  2016-01-07 19:56 ` [Qemu-devel] [PATCH v2 19/27] 9pfs: break out virtio_init_iov_from_pdu Wei Liu
                   ` (9 subsequent siblings)
  27 siblings, 0 replies; 38+ messages in thread
From: Wei Liu @ 2016-01-07 19:56 UTC (permalink / raw)
  To: qemu-devel; +Cc: Greg Kurz, Wei Liu, Aneesh Kumar K.V, Michael S. Tsirkin

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
---
 hw/9pfs/virtio-9p.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c
index 498e327..af9b1d1 100644
--- a/hw/9pfs/virtio-9p.c
+++ b/hw/9pfs/virtio-9p.c
@@ -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);
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [Qemu-devel] [PATCH v2 19/27] 9pfs: break out virtio_init_iov_from_pdu
  2016-01-07 19:55 [Qemu-devel] [PATCH v2 00/27] 9pfs: disentangling virtio and generic code Wei Liu
                   ` (17 preceding siblings ...)
  2016-01-07 19:56 ` [Qemu-devel] [PATCH v2 18/27] 9pfs: factor out pdu_push_and_notify Wei Liu
@ 2016-01-07 19:56 ` Wei Liu
  2016-01-07 19:56 ` [Qemu-devel] [PATCH v2 20/27] 9pfs: break out 9p.h from virtio-9p.h Wei Liu
                   ` (8 subsequent siblings)
  27 siblings, 0 replies; 38+ messages in thread
From: Wei Liu @ 2016-01-07 19:56 UTC (permalink / raw)
  To: qemu-devel; +Cc: Greg Kurz, Wei Liu, Aneesh Kumar K.V, Michael S. Tsirkin

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
---
 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(-)

diff --git a/hw/9pfs/virtio-9p-device.c b/hw/9pfs/virtio-9p-device.c
index d77247f..5cad654 100644
--- a/hw/9pfs/virtio-9p-device.c
+++ b/hw/9pfs/virtio-9p-device.c
@@ -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[] = {
diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c
index af9b1d1..3c39247 100644
--- a/hw/9pfs/virtio-9p.c
+++ b/hw/9pfs/virtio-9p.c
@@ -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);
diff --git a/hw/9pfs/virtio-9p.h b/hw/9pfs/virtio-9p.h
index e298949..5024ad0 100644
--- a/hw/9pfs/virtio-9p.h
+++ b/hw/9pfs/virtio-9p.h
@@ -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) \
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [Qemu-devel] [PATCH v2 20/27] 9pfs: break out 9p.h from virtio-9p.h
  2016-01-07 19:55 [Qemu-devel] [PATCH v2 00/27] 9pfs: disentangling virtio and generic code Wei Liu
                   ` (18 preceding siblings ...)
  2016-01-07 19:56 ` [Qemu-devel] [PATCH v2 19/27] 9pfs: break out virtio_init_iov_from_pdu Wei Liu
@ 2016-01-07 19:56 ` Wei Liu
  2016-01-07 19:56 ` [Qemu-devel] [PATCH v2 21/27] 9pfs: factor out virtio_9p_push_and_notify Wei Liu
                   ` (7 subsequent siblings)
  27 siblings, 0 replies; 38+ messages in thread
From: Wei Liu @ 2016-01-07 19:56 UTC (permalink / raw)
  To: qemu-devel; +Cc: Michael S. Tsirkin, Wei Liu, Aneesh Kumar K.V, Greg Kurz

Move out generic definitions from virtio-9p.h to 9p.h. Fix header
inclusions.

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
---
v2: new, part of original "9pfs: break out generic code from
    virtio-9p.{c,h}"
---
 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/9p.h            | 325 ++++++++++++++++++++++++++++++++++++++++++++++++
 hw/9pfs/virtio-9p.h     | 319 +----------------------------------------------
 9 files changed, 333 insertions(+), 325 deletions(-)
 create mode 100644 hw/9pfs/9p.h

diff --git a/hw/9pfs/9p-handle.c b/hw/9pfs/9p-handle.c
index 51a9d15..58b77b4 100644
--- a/hw/9pfs/9p-handle.c
+++ b/hw/9pfs/9p-handle.c
@@ -11,7 +11,7 @@
  *
  */
 
-#include "virtio-9p.h"
+#include "9p.h"
 #include "9p-xattr.h"
 #include <arpa/inet.h>
 #include <pwd.h>
diff --git a/hw/9pfs/9p-local.c b/hw/9pfs/9p-local.c
index ac553e0..bf63eab 100644
--- a/hw/9pfs/9p-local.c
+++ b/hw/9pfs/9p-local.c
@@ -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>
diff --git a/hw/9pfs/9p-posix-acl.c b/hw/9pfs/9p-posix-acl.c
index 073af39..8df8228 100644
--- a/hw/9pfs/9p-posix-acl.c
+++ b/hw/9pfs/9p-posix-acl.c
@@ -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"
 
diff --git a/hw/9pfs/9p-proxy.c b/hw/9pfs/9p-proxy.c
index 67c1fb9..73d00dd 100644
--- a/hw/9pfs/9p-proxy.c
+++ b/hw/9pfs/9p-proxy.c
@@ -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"
diff --git a/hw/9pfs/9p-synth.c b/hw/9pfs/9p-synth.c
index b1064e3..090ae0c 100644
--- a/hw/9pfs/9p-synth.c
+++ b/hw/9pfs/9p-synth.c
@@ -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"
diff --git a/hw/9pfs/9p-xattr-user.c b/hw/9pfs/9p-xattr-user.c
index 163b158..c490ec3 100644
--- a/hw/9pfs/9p-xattr-user.c
+++ b/hw/9pfs/9p-xattr-user.c
@@ -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"
 
diff --git a/hw/9pfs/9p-xattr.c b/hw/9pfs/9p-xattr.c
index 1d7861b..741dd03 100644
--- a/hw/9pfs/9p-xattr.c
+++ b/hw/9pfs/9p-xattr.c
@@ -11,7 +11,7 @@
  *
  */
 
-#include "virtio-9p.h"
+#include "9p.h"
 #include "fsdev/file-op-9p.h"
 #include "9p-xattr.h"
 
diff --git a/hw/9pfs/9p.h b/hw/9pfs/9p.h
new file mode 100644
index 0000000..9aeb874
--- /dev/null
+++ b/hw/9pfs/9p.h
@@ -0,0 +1,325 @@
+#ifndef _QEMU_9P_H
+#define _QEMU_9P_H
+
+#include <sys/types.h>
+#include <dirent.h>
+#include <sys/time.h>
+#include <utime.h>
+#include <sys/resource.h>
+#include <glib.h>
+#include "standard-headers/linux/virtio_9p.h"
+#include "hw/virtio/virtio.h"
+#include "fsdev/file-op-9p.h"
+#include "fsdev/9p-iov-marshal.h"
+#include "qemu/thread.h"
+#include "qemu/coroutine.h"
+
+enum {
+    P9_TLERROR = 6,
+    P9_RLERROR,
+    P9_TSTATFS = 8,
+    P9_RSTATFS,
+    P9_TLOPEN = 12,
+    P9_RLOPEN,
+    P9_TLCREATE = 14,
+    P9_RLCREATE,
+    P9_TSYMLINK = 16,
+    P9_RSYMLINK,
+    P9_TMKNOD = 18,
+    P9_RMKNOD,
+    P9_TRENAME = 20,
+    P9_RRENAME,
+    P9_TREADLINK = 22,
+    P9_RREADLINK,
+    P9_TGETATTR = 24,
+    P9_RGETATTR,
+    P9_TSETATTR = 26,
+    P9_RSETATTR,
+    P9_TXATTRWALK = 30,
+    P9_RXATTRWALK,
+    P9_TXATTRCREATE = 32,
+    P9_RXATTRCREATE,
+    P9_TREADDIR = 40,
+    P9_RREADDIR,
+    P9_TFSYNC = 50,
+    P9_RFSYNC,
+    P9_TLOCK = 52,
+    P9_RLOCK,
+    P9_TGETLOCK = 54,
+    P9_RGETLOCK,
+    P9_TLINK = 70,
+    P9_RLINK,
+    P9_TMKDIR = 72,
+    P9_RMKDIR,
+    P9_TRENAMEAT = 74,
+    P9_RRENAMEAT,
+    P9_TUNLINKAT = 76,
+    P9_RUNLINKAT,
+    P9_TVERSION = 100,
+    P9_RVERSION,
+    P9_TAUTH = 102,
+    P9_RAUTH,
+    P9_TATTACH = 104,
+    P9_RATTACH,
+    P9_TERROR = 106,
+    P9_RERROR,
+    P9_TFLUSH = 108,
+    P9_RFLUSH,
+    P9_TWALK = 110,
+    P9_RWALK,
+    P9_TOPEN = 112,
+    P9_ROPEN,
+    P9_TCREATE = 114,
+    P9_RCREATE,
+    P9_TREAD = 116,
+    P9_RREAD,
+    P9_TWRITE = 118,
+    P9_RWRITE,
+    P9_TCLUNK = 120,
+    P9_RCLUNK,
+    P9_TREMOVE = 122,
+    P9_RREMOVE,
+    P9_TSTAT = 124,
+    P9_RSTAT,
+    P9_TWSTAT = 126,
+    P9_RWSTAT,
+};
+
+
+/* qid.types */
+enum {
+    P9_QTDIR = 0x80,
+    P9_QTAPPEND = 0x40,
+    P9_QTEXCL = 0x20,
+    P9_QTMOUNT = 0x10,
+    P9_QTAUTH = 0x08,
+    P9_QTTMP = 0x04,
+    P9_QTSYMLINK = 0x02,
+    P9_QTLINK = 0x01,
+    P9_QTFILE = 0x00,
+};
+
+enum p9_proto_version {
+    V9FS_PROTO_2000U = 0x01,
+    V9FS_PROTO_2000L = 0x02,
+};
+
+#define P9_NOTAG    (u16)(~0)
+#define P9_NOFID    (u32)(~0)
+#define P9_MAXWELEM 16
+
+#define FID_REFERENCED          0x1
+#define FID_NON_RECLAIMABLE     0x2
+static inline char *rpath(FsContext *ctx, const char *path)
+{
+    return g_strdup_printf("%s/%s", ctx->fs_root, path);
+}
+
+/*
+ * ample room for Twrite/Rread header
+ * size[4] Tread/Twrite tag[2] fid[4] offset[8] count[4]
+ */
+#define P9_IOHDRSZ 24
+
+typedef struct V9fsPDU V9fsPDU;
+struct V9fsState;
+
+struct V9fsPDU
+{
+    uint32_t size;
+    uint16_t tag;
+    uint8_t id;
+    uint8_t cancelled;
+    CoQueue complete;
+    VirtQueueElement elem;
+    struct V9fsState *s;
+    QLIST_ENTRY(V9fsPDU) next;
+};
+
+
+/* FIXME
+ * 1) change user needs to set groups and stuff
+ */
+
+#define MAX_REQ         128
+#define MAX_TAG_LEN     32
+
+#define BUG_ON(cond) assert(!(cond))
+
+typedef struct V9fsFidState V9fsFidState;
+
+enum {
+    P9_FID_NONE = 0,
+    P9_FID_FILE,
+    P9_FID_DIR,
+    P9_FID_XATTR,
+};
+
+typedef struct V9fsConf
+{
+    /* tag name for the device */
+    char *tag;
+    char *fsdev_id;
+} V9fsConf;
+
+typedef struct V9fsXattr
+{
+    int64_t copied_len;
+    int64_t len;
+    void *value;
+    V9fsString name;
+    int flags;
+} V9fsXattr;
+
+/*
+ * Filled by fs driver on open and other
+ * calls.
+ */
+union V9fsFidOpenState {
+    int fd;
+    DIR *dir;
+    V9fsXattr xattr;
+    /*
+     * private pointer for fs drivers, that
+     * have its own internal representation of
+     * open files.
+     */
+    void *private;
+};
+
+struct V9fsFidState
+{
+    int fid_type;
+    int32_t fid;
+    V9fsPath path;
+    V9fsFidOpenState fs;
+    V9fsFidOpenState fs_reclaim;
+    int flags;
+    int open_flags;
+    uid_t uid;
+    int ref;
+    int clunked;
+    V9fsFidState *next;
+    V9fsFidState *rclm_lst;
+};
+
+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;
+    /*
+     * lock ensuring atomic path update
+     * on rename.
+     */
+    CoRwlock rename_lock;
+    int32_t root_fid;
+    Error *migration_blocker;
+    V9fsConf fsconf;
+} V9fsState;
+
+/* 9p2000.L open flags */
+#define P9_DOTL_RDONLY        00000000
+#define P9_DOTL_WRONLY        00000001
+#define P9_DOTL_RDWR          00000002
+#define P9_DOTL_NOACCESS      00000003
+#define P9_DOTL_CREATE        00000100
+#define P9_DOTL_EXCL          00000200
+#define P9_DOTL_NOCTTY        00000400
+#define P9_DOTL_TRUNC         00001000
+#define P9_DOTL_APPEND        00002000
+#define P9_DOTL_NONBLOCK      00004000
+#define P9_DOTL_DSYNC         00010000
+#define P9_DOTL_FASYNC        00020000
+#define P9_DOTL_DIRECT        00040000
+#define P9_DOTL_LARGEFILE     00100000
+#define P9_DOTL_DIRECTORY     00200000
+#define P9_DOTL_NOFOLLOW      00400000
+#define P9_DOTL_NOATIME       01000000
+#define P9_DOTL_CLOEXEC       02000000
+#define P9_DOTL_SYNC          04000000
+
+/* 9p2000.L at flags */
+#define P9_DOTL_AT_REMOVEDIR         0x200
+
+/* 9P2000.L lock type */
+#define P9_LOCK_TYPE_RDLCK 0
+#define P9_LOCK_TYPE_WRLCK 1
+#define P9_LOCK_TYPE_UNLCK 2
+
+#define P9_LOCK_SUCCESS 0
+#define P9_LOCK_BLOCKED 1
+#define P9_LOCK_ERROR 2
+#define P9_LOCK_GRACE 3
+
+#define P9_LOCK_FLAGS_BLOCK 1
+#define P9_LOCK_FLAGS_RECLAIM 2
+
+typedef struct V9fsFlock
+{
+    uint8_t type;
+    uint32_t flags;
+    uint64_t start; /* absolute offset */
+    uint64_t length;
+    uint32_t proc_id;
+    V9fsString client_id;
+} V9fsFlock;
+
+typedef struct V9fsGetlock
+{
+    uint8_t type;
+    uint64_t start; /* absolute offset */
+    uint64_t length;
+    uint32_t proc_id;
+    V9fsString client_id;
+} V9fsGetlock;
+
+extern int open_fd_hw;
+extern int total_open_fd;
+
+static inline void v9fs_path_write_lock(V9fsState *s)
+{
+    if (s->ctx.export_flags & V9FS_PATHNAME_FSCONTEXT) {
+        qemu_co_rwlock_wrlock(&s->rename_lock);
+    }
+}
+
+static inline void v9fs_path_read_lock(V9fsState *s)
+{
+    if (s->ctx.export_flags & V9FS_PATHNAME_FSCONTEXT) {
+        qemu_co_rwlock_rdlock(&s->rename_lock);
+    }
+}
+
+static inline void v9fs_path_unlock(V9fsState *s)
+{
+    if (s->ctx.export_flags & V9FS_PATHNAME_FSCONTEXT) {
+        qemu_co_rwlock_unlock(&s->rename_lock);
+    }
+}
+
+static inline uint8_t v9fs_request_cancelled(V9fsPDU *pdu)
+{
+    return pdu->cancelled;
+}
+
+extern void v9fs_reclaim_fd(V9fsPDU *pdu);
+extern void v9fs_path_init(V9fsPath *path);
+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);
+
+ssize_t pdu_marshal(V9fsPDU *pdu, size_t offset, const char *fmt, ...);
+ssize_t pdu_unmarshal(V9fsPDU *pdu, size_t offset, const char *fmt, ...);
+
+#endif
diff --git a/hw/9pfs/virtio-9p.h b/hw/9pfs/virtio-9p.h
index 5024ad0..b4d344a 100644
--- a/hw/9pfs/virtio-9p.h
+++ b/hw/9pfs/virtio-9p.h
@@ -1,328 +1,11 @@
 #ifndef _QEMU_VIRTIO_9P_H
 #define _QEMU_VIRTIO_9P_H
 
-#include <sys/types.h>
-#include <dirent.h>
-#include <sys/time.h>
-#include <utime.h>
-#include <sys/resource.h>
-#include <glib.h>
 #include "standard-headers/linux/virtio_9p.h"
 #include "hw/virtio/virtio.h"
-#include "fsdev/file-op-9p.h"
-#include "fsdev/9p-iov-marshal.h"
-#include "qemu/thread.h"
-#include "qemu/coroutine.h"
-
-enum {
-    P9_TLERROR = 6,
-    P9_RLERROR,
-    P9_TSTATFS = 8,
-    P9_RSTATFS,
-    P9_TLOPEN = 12,
-    P9_RLOPEN,
-    P9_TLCREATE = 14,
-    P9_RLCREATE,
-    P9_TSYMLINK = 16,
-    P9_RSYMLINK,
-    P9_TMKNOD = 18,
-    P9_RMKNOD,
-    P9_TRENAME = 20,
-    P9_RRENAME,
-    P9_TREADLINK = 22,
-    P9_RREADLINK,
-    P9_TGETATTR = 24,
-    P9_RGETATTR,
-    P9_TSETATTR = 26,
-    P9_RSETATTR,
-    P9_TXATTRWALK = 30,
-    P9_RXATTRWALK,
-    P9_TXATTRCREATE = 32,
-    P9_RXATTRCREATE,
-    P9_TREADDIR = 40,
-    P9_RREADDIR,
-    P9_TFSYNC = 50,
-    P9_RFSYNC,
-    P9_TLOCK = 52,
-    P9_RLOCK,
-    P9_TGETLOCK = 54,
-    P9_RGETLOCK,
-    P9_TLINK = 70,
-    P9_RLINK,
-    P9_TMKDIR = 72,
-    P9_RMKDIR,
-    P9_TRENAMEAT = 74,
-    P9_RRENAMEAT,
-    P9_TUNLINKAT = 76,
-    P9_RUNLINKAT,
-    P9_TVERSION = 100,
-    P9_RVERSION,
-    P9_TAUTH = 102,
-    P9_RAUTH,
-    P9_TATTACH = 104,
-    P9_RATTACH,
-    P9_TERROR = 106,
-    P9_RERROR,
-    P9_TFLUSH = 108,
-    P9_RFLUSH,
-    P9_TWALK = 110,
-    P9_RWALK,
-    P9_TOPEN = 112,
-    P9_ROPEN,
-    P9_TCREATE = 114,
-    P9_RCREATE,
-    P9_TREAD = 116,
-    P9_RREAD,
-    P9_TWRITE = 118,
-    P9_RWRITE,
-    P9_TCLUNK = 120,
-    P9_RCLUNK,
-    P9_TREMOVE = 122,
-    P9_RREMOVE,
-    P9_TSTAT = 124,
-    P9_RSTAT,
-    P9_TWSTAT = 126,
-    P9_RWSTAT,
-};
-
-
-/* qid.types */
-enum {
-    P9_QTDIR = 0x80,
-    P9_QTAPPEND = 0x40,
-    P9_QTEXCL = 0x20,
-    P9_QTMOUNT = 0x10,
-    P9_QTAUTH = 0x08,
-    P9_QTTMP = 0x04,
-    P9_QTSYMLINK = 0x02,
-    P9_QTLINK = 0x01,
-    P9_QTFILE = 0x00,
-};
-
-enum p9_proto_version {
-    V9FS_PROTO_2000U = 0x01,
-    V9FS_PROTO_2000L = 0x02,
-};
-
-#define P9_NOTAG    (u16)(~0)
-#define P9_NOFID    (u32)(~0)
-#define P9_MAXWELEM 16
-
-#define FID_REFERENCED          0x1
-#define FID_NON_RECLAIMABLE     0x2
-static inline char *rpath(FsContext *ctx, const char *path)
-{
-    return g_strdup_printf("%s/%s", ctx->fs_root, path);
-}
-
-/*
- * ample room for Twrite/Rread header
- * size[4] Tread/Twrite tag[2] fid[4] offset[8] count[4]
- */
-#define P9_IOHDRSZ 24
-
-typedef struct V9fsPDU V9fsPDU;
-struct V9fsState;
-
-struct V9fsPDU
-{
-    uint32_t size;
-    uint16_t tag;
-    uint8_t id;
-    uint8_t cancelled;
-    CoQueue complete;
-    VirtQueueElement elem;
-    struct V9fsState *s;
-    QLIST_ENTRY(V9fsPDU) next;
-};
-
-
-/* FIXME
- * 1) change user needs to set groups and stuff
- */
-
-#define MAX_REQ         128
-#define MAX_TAG_LEN     32
-
-#define BUG_ON(cond) assert(!(cond))
-
-typedef struct V9fsFidState V9fsFidState;
-
-enum {
-    P9_FID_NONE = 0,
-    P9_FID_FILE,
-    P9_FID_DIR,
-    P9_FID_XATTR,
-};
-
-typedef struct V9fsConf
-{
-    /* tag name for the device */
-    char *tag;
-    char *fsdev_id;
-} V9fsConf;
-
-typedef struct V9fsXattr
-{
-    int64_t copied_len;
-    int64_t len;
-    void *value;
-    V9fsString name;
-    int flags;
-} V9fsXattr;
-
-/*
- * Filled by fs driver on open and other
- * calls.
- */
-union V9fsFidOpenState {
-    int fd;
-    DIR *dir;
-    V9fsXattr xattr;
-    /*
-     * private pointer for fs drivers, that
-     * have its own internal representation of
-     * open files.
-     */
-    void *private;
-};
-
-struct V9fsFidState
-{
-    int fid_type;
-    int32_t fid;
-    V9fsPath path;
-    V9fsFidOpenState fs;
-    V9fsFidOpenState fs_reclaim;
-    int flags;
-    int open_flags;
-    uid_t uid;
-    int ref;
-    int clunked;
-    V9fsFidState *next;
-    V9fsFidState *rclm_lst;
-};
-
-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;
-    /*
-     * lock ensuring atomic path update
-     * on rename.
-     */
-    CoRwlock rename_lock;
-    int32_t root_fid;
-    Error *migration_blocker;
-    V9fsConf fsconf;
-} V9fsState;
-
-/* 9p2000.L open flags */
-#define P9_DOTL_RDONLY        00000000
-#define P9_DOTL_WRONLY        00000001
-#define P9_DOTL_RDWR          00000002
-#define P9_DOTL_NOACCESS      00000003
-#define P9_DOTL_CREATE        00000100
-#define P9_DOTL_EXCL          00000200
-#define P9_DOTL_NOCTTY        00000400
-#define P9_DOTL_TRUNC         00001000
-#define P9_DOTL_APPEND        00002000
-#define P9_DOTL_NONBLOCK      00004000
-#define P9_DOTL_DSYNC         00010000
-#define P9_DOTL_FASYNC        00020000
-#define P9_DOTL_DIRECT        00040000
-#define P9_DOTL_LARGEFILE     00100000
-#define P9_DOTL_DIRECTORY     00200000
-#define P9_DOTL_NOFOLLOW      00400000
-#define P9_DOTL_NOATIME       01000000
-#define P9_DOTL_CLOEXEC       02000000
-#define P9_DOTL_SYNC          04000000
-
-/* 9p2000.L at flags */
-#define P9_DOTL_AT_REMOVEDIR         0x200
-
-/* 9P2000.L lock type */
-#define P9_LOCK_TYPE_RDLCK 0
-#define P9_LOCK_TYPE_WRLCK 1
-#define P9_LOCK_TYPE_UNLCK 2
-
-#define P9_LOCK_SUCCESS 0
-#define P9_LOCK_BLOCKED 1
-#define P9_LOCK_ERROR 2
-#define P9_LOCK_GRACE 3
-
-#define P9_LOCK_FLAGS_BLOCK 1
-#define P9_LOCK_FLAGS_RECLAIM 2
-
-typedef struct V9fsFlock
-{
-    uint8_t type;
-    uint32_t flags;
-    uint64_t start; /* absolute offset */
-    uint64_t length;
-    uint32_t proc_id;
-    V9fsString client_id;
-} V9fsFlock;
-
-typedef struct V9fsGetlock
-{
-    uint8_t type;
-    uint64_t start; /* absolute offset */
-    uint64_t length;
-    uint32_t proc_id;
-    V9fsString client_id;
-} V9fsGetlock;
-
-extern int open_fd_hw;
-extern int total_open_fd;
-
-static inline void v9fs_path_write_lock(V9fsState *s)
-{
-    if (s->ctx.export_flags & V9FS_PATHNAME_FSCONTEXT) {
-        qemu_co_rwlock_wrlock(&s->rename_lock);
-    }
-}
-
-static inline void v9fs_path_read_lock(V9fsState *s)
-{
-    if (s->ctx.export_flags & V9FS_PATHNAME_FSCONTEXT) {
-        qemu_co_rwlock_rdlock(&s->rename_lock);
-    }
-}
-
-static inline void v9fs_path_unlock(V9fsState *s)
-{
-    if (s->ctx.export_flags & V9FS_PATHNAME_FSCONTEXT) {
-        qemu_co_rwlock_unlock(&s->rename_lock);
-    }
-}
-
-static inline uint8_t v9fs_request_cancelled(V9fsPDU *pdu)
-{
-    return pdu->cancelled;
-}
+#include "9p.h"
 
 extern void handle_9p_output(VirtIODevice *vdev, VirtQueue *vq);
-extern void v9fs_reclaim_fd(V9fsPDU *pdu);
-extern void v9fs_path_init(V9fsPath *path);
-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);
-
-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,
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [Qemu-devel] [PATCH v2 21/27] 9pfs: factor out virtio_9p_push_and_notify
  2016-01-07 19:55 [Qemu-devel] [PATCH v2 00/27] 9pfs: disentangling virtio and generic code Wei Liu
                   ` (19 preceding siblings ...)
  2016-01-07 19:56 ` [Qemu-devel] [PATCH v2 20/27] 9pfs: break out 9p.h from virtio-9p.h Wei Liu
@ 2016-01-07 19:56 ` Wei Liu
  2016-01-08  9:57   ` Aneesh Kumar K.V
  2016-01-07 19:56 ` [Qemu-devel] [PATCH v2 22/27] 9pfs: export pdu_{submit, alloc, free} Wei Liu
                   ` (6 subsequent siblings)
  27 siblings, 1 reply; 38+ messages in thread
From: Wei Liu @ 2016-01-07 19:56 UTC (permalink / raw)
  To: qemu-devel; +Cc: Greg Kurz, Wei Liu, Aneesh Kumar K.V, Michael S. Tsirkin

The new function resides in virtio specific file.

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
---
v2: new, part of original "9pfs: break out generic code from
    virtio-9p.{c,h}"
---
 hw/9pfs/virtio-9p-device.c | 11 +++++++++++
 hw/9pfs/virtio-9p.c        |  8 +-------
 hw/9pfs/virtio-9p.h        |  2 ++
 3 files changed, 14 insertions(+), 7 deletions(-)

diff --git a/hw/9pfs/virtio-9p-device.c b/hw/9pfs/virtio-9p-device.c
index 5cad654..cfad13a 100644
--- a/hw/9pfs/virtio-9p-device.c
+++ b/hw/9pfs/virtio-9p-device.c
@@ -20,6 +20,17 @@
 #include "coth.h"
 #include "hw/virtio/virtio-access.h"
 
+void virtio_9p_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 uint64_t virtio_9p_get_features(VirtIODevice *vdev, uint64_t features,
                                        Error **errp)
 {
diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c
index 3c39247..0ba2312 100644
--- a/hw/9pfs/virtio-9p.c
+++ b/hw/9pfs/virtio-9p.c
@@ -65,13 +65,7 @@ ssize_t pdu_unmarshal(V9fsPDU *pdu, size_t offset, const char *fmt, ...)
 
 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);
+    virtio_9p_push_and_notify(pdu);
 }
 
 static int omode_to_uflags(int8_t mode)
diff --git a/hw/9pfs/virtio-9p.h b/hw/9pfs/virtio-9p.h
index b4d344a..a1ac398 100644
--- a/hw/9pfs/virtio-9p.h
+++ b/hw/9pfs/virtio-9p.h
@@ -6,6 +6,8 @@
 #include "9p.h"
 
 extern void handle_9p_output(VirtIODevice *vdev, VirtQueue *vq);
+extern void virtio_9p_push_and_notify(V9fsPDU *pdu);
+
 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,
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [Qemu-devel] [PATCH v2 22/27] 9pfs: export pdu_{submit, alloc, free}
  2016-01-07 19:55 [Qemu-devel] [PATCH v2 00/27] 9pfs: disentangling virtio and generic code Wei Liu
                   ` (20 preceding siblings ...)
  2016-01-07 19:56 ` [Qemu-devel] [PATCH v2 21/27] 9pfs: factor out virtio_9p_push_and_notify Wei Liu
@ 2016-01-07 19:56 ` Wei Liu
  2016-01-07 19:56 ` [Qemu-devel] [PATCH v2 23/27] 9pfs: move handle_9p_output and make it static function Wei Liu
                   ` (5 subsequent siblings)
  27 siblings, 0 replies; 38+ messages in thread
From: Wei Liu @ 2016-01-07 19:56 UTC (permalink / raw)
  To: qemu-devel; +Cc: Michael S. Tsirkin, Wei Liu, Aneesh Kumar K.V, Greg Kurz

They will be used in later patches.

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
---
v2: new, part of original "9pfs: break out generic code from
    virtio-9p.{c,h}"
---
 hw/9pfs/9p.h        | 3 +++
 hw/9pfs/virtio-9p.c | 6 +++---
 2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/hw/9pfs/9p.h b/hw/9pfs/9p.h
index 9aeb874..b62c9a8 100644
--- a/hw/9pfs/9p.h
+++ b/hw/9pfs/9p.h
@@ -321,5 +321,8 @@ 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, ...);
+V9fsPDU *pdu_alloc(V9fsState *s);
+void pdu_free(V9fsPDU *pdu);
+void pdu_submit(V9fsPDU *pdu);
 
 #endif
diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c
index 0ba2312..c74e601 100644
--- a/hw/9pfs/virtio-9p.c
+++ b/hw/9pfs/virtio-9p.c
@@ -592,7 +592,7 @@ static int fid_to_qid(V9fsPDU *pdu, V9fsFidState *fidp, V9fsQID *qidp)
     return 0;
 }
 
-static V9fsPDU *pdu_alloc(V9fsState *s)
+V9fsPDU *pdu_alloc(V9fsState *s)
 {
     V9fsPDU *pdu = NULL;
 
@@ -604,7 +604,7 @@ static V9fsPDU *pdu_alloc(V9fsState *s)
     return pdu;
 }
 
-static void pdu_free(V9fsPDU *pdu)
+void pdu_free(V9fsPDU *pdu)
 {
     if (pdu) {
         V9fsState *s = pdu->s;
@@ -3251,7 +3251,7 @@ static inline bool is_read_only_op(V9fsPDU *pdu)
     }
 }
 
-static void pdu_submit(V9fsPDU *pdu)
+void pdu_submit(V9fsPDU *pdu)
 {
     Coroutine *co;
     CoroutineEntry *handler;
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [Qemu-devel] [PATCH v2 23/27] 9pfs: move handle_9p_output and make it static function
  2016-01-07 19:55 [Qemu-devel] [PATCH v2 00/27] 9pfs: disentangling virtio and generic code Wei Liu
                   ` (21 preceding siblings ...)
  2016-01-07 19:56 ` [Qemu-devel] [PATCH v2 22/27] 9pfs: export pdu_{submit, alloc, free} Wei Liu
@ 2016-01-07 19:56 ` Wei Liu
  2016-01-07 19:56 ` [Qemu-devel] [PATCH v2 24/27] 9pfs: rename virtio_9p_set_fd_limit to use v9fs_ prefix Wei Liu
                   ` (4 subsequent siblings)
  27 siblings, 0 replies; 38+ messages in thread
From: Wei Liu @ 2016-01-07 19:56 UTC (permalink / raw)
  To: qemu-devel; +Cc: Greg Kurz, Wei Liu, Aneesh Kumar K.V, Michael S. Tsirkin

It's only used in virtio device.

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
---
v2: new, part of original "9pfs: break out generic code from
    virtio-9p.{c,h}"
---
 hw/9pfs/virtio-9p-device.c | 34 ++++++++++++++++++++++++++++++++++
 hw/9pfs/virtio-9p.c        | 33 ---------------------------------
 hw/9pfs/virtio-9p.h        |  1 -
 3 files changed, 34 insertions(+), 34 deletions(-)

diff --git a/hw/9pfs/virtio-9p-device.c b/hw/9pfs/virtio-9p-device.c
index cfad13a..bc103b7 100644
--- a/hw/9pfs/virtio-9p-device.c
+++ b/hw/9pfs/virtio-9p-device.c
@@ -19,6 +19,7 @@
 #include "9p-xattr.h"
 #include "coth.h"
 #include "hw/virtio/virtio-access.h"
+#include "qemu/iov.h"
 
 void virtio_9p_push_and_notify(V9fsPDU *pdu)
 {
@@ -31,6 +32,39 @@ void virtio_9p_push_and_notify(V9fsPDU *pdu)
     virtio_notify(VIRTIO_DEVICE(s), s->vq);
 }
 
+static void handle_9p_output(VirtIODevice *vdev, VirtQueue *vq)
+{
+    V9fsState *s = (V9fsState *)vdev;
+    V9fsPDU *pdu;
+    ssize_t len;
+
+    while ((pdu = pdu_alloc(s)) &&
+            (len = virtqueue_pop(vq, &pdu->elem)) != 0) {
+        struct {
+            uint32_t size_le;
+            uint8_t id;
+            uint16_t tag_le;
+        } QEMU_PACKED out;
+        int len;
+
+        BUG_ON(pdu->elem.out_num == 0 || pdu->elem.in_num == 0);
+        QEMU_BUILD_BUG_ON(sizeof out != 7);
+
+        len = iov_to_buf(pdu->elem.out_sg, pdu->elem.out_num, 0,
+                         &out, sizeof out);
+        BUG_ON(len != sizeof out);
+
+        pdu->size = le32_to_cpu(out.size_le);
+
+        pdu->id = out.id;
+        pdu->tag = le16_to_cpu(out.tag_le);
+
+        qemu_co_queue_init(&pdu->complete);
+        pdu_submit(pdu);
+    }
+    pdu_free(pdu);
+}
+
 static uint64_t virtio_9p_get_features(VirtIODevice *vdev, uint64_t features,
                                        Error **errp)
 {
diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c
index c74e601..e2c047c 100644
--- a/hw/9pfs/virtio-9p.c
+++ b/hw/9pfs/virtio-9p.c
@@ -3271,39 +3271,6 @@ void pdu_submit(V9fsPDU *pdu)
     qemu_coroutine_enter(co, pdu);
 }
 
-void handle_9p_output(VirtIODevice *vdev, VirtQueue *vq)
-{
-    V9fsState *s = (V9fsState *)vdev;
-    V9fsPDU *pdu;
-    ssize_t len;
-
-    while ((pdu = pdu_alloc(s)) &&
-            (len = virtqueue_pop(vq, &pdu->elem)) != 0) {
-        struct {
-            uint32_t size_le;
-            uint8_t id;
-            uint16_t tag_le;
-        } QEMU_PACKED out;
-        int len;
-
-        BUG_ON(pdu->elem.out_num == 0 || pdu->elem.in_num == 0);
-        QEMU_BUILD_BUG_ON(sizeof out != 7);
-
-        len = iov_to_buf(pdu->elem.out_sg, pdu->elem.out_num, 0,
-                         &out, sizeof out);
-        BUG_ON(len != sizeof out);
-
-        pdu->size = le32_to_cpu(out.size_le);
-
-        pdu->id = out.id;
-        pdu->tag = le16_to_cpu(out.tag_le);
-
-        qemu_co_queue_init(&pdu->complete);
-        pdu_submit(pdu);
-    }
-    pdu_free(pdu);
-}
-
 static void __attribute__((__constructor__)) virtio_9p_set_fd_limit(void)
 {
     struct rlimit rlim;
diff --git a/hw/9pfs/virtio-9p.h b/hw/9pfs/virtio-9p.h
index a1ac398..474ab94 100644
--- a/hw/9pfs/virtio-9p.h
+++ b/hw/9pfs/virtio-9p.h
@@ -5,7 +5,6 @@
 #include "hw/virtio/virtio.h"
 #include "9p.h"
 
-extern void handle_9p_output(VirtIODevice *vdev, VirtQueue *vq);
 extern void virtio_9p_push_and_notify(V9fsPDU *pdu);
 
 ssize_t virtio_pdu_vmarshal(V9fsPDU *pdu, size_t offset,
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [Qemu-devel] [PATCH v2 24/27] 9pfs: rename virtio_9p_set_fd_limit to use v9fs_ prefix
  2016-01-07 19:55 [Qemu-devel] [PATCH v2 00/27] 9pfs: disentangling virtio and generic code Wei Liu
                   ` (22 preceding siblings ...)
  2016-01-07 19:56 ` [Qemu-devel] [PATCH v2 23/27] 9pfs: move handle_9p_output and make it static function Wei Liu
@ 2016-01-07 19:56 ` Wei Liu
  2016-01-07 19:56 ` [Qemu-devel] [PATCH v2 25/27] 9pfs: rename virtio-9p.c to 9p.c Wei Liu
                   ` (3 subsequent siblings)
  27 siblings, 0 replies; 38+ messages in thread
From: Wei Liu @ 2016-01-07 19:56 UTC (permalink / raw)
  To: qemu-devel; +Cc: Greg Kurz, Wei Liu, Aneesh Kumar K.V, Michael S. Tsirkin

It's not virtio specific.

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
---
v2: new, part of original "9pfs: break out generic code from
    virtio-9p.{c,h}"
---
 hw/9pfs/virtio-9p.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c
index e2c047c..50d7333 100644
--- a/hw/9pfs/virtio-9p.c
+++ b/hw/9pfs/virtio-9p.c
@@ -3271,7 +3271,7 @@ void pdu_submit(V9fsPDU *pdu)
     qemu_coroutine_enter(co, pdu);
 }
 
-static void __attribute__((__constructor__)) virtio_9p_set_fd_limit(void)
+static void __attribute__((__constructor__)) v9fs_set_fd_limit(void)
 {
     struct rlimit rlim;
     if (getrlimit(RLIMIT_NOFILE, &rlim) < 0) {
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [Qemu-devel] [PATCH v2 25/27] 9pfs: rename virtio-9p.c to 9p.c
  2016-01-07 19:55 [Qemu-devel] [PATCH v2 00/27] 9pfs: disentangling virtio and generic code Wei Liu
                   ` (23 preceding siblings ...)
  2016-01-07 19:56 ` [Qemu-devel] [PATCH v2 24/27] 9pfs: rename virtio_9p_set_fd_limit to use v9fs_ prefix Wei Liu
@ 2016-01-07 19:56 ` Wei Liu
  2016-01-07 19:56 ` [Qemu-devel] [PATCH v2 26/27] 9pfs: factor out v9fs_device_{, un}realize_common Wei Liu
                   ` (2 subsequent siblings)
  27 siblings, 0 replies; 38+ messages in thread
From: Wei Liu @ 2016-01-07 19:56 UTC (permalink / raw)
  To: qemu-devel; +Cc: Wei Liu, Aneesh Kumar K.V, Greg Kurz

Now that file only contains generic code.

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
---
v2: new, part of original "9pfs: break out generic code from
    virtio-9p.{c,h}"
---
 hw/9pfs/{virtio-9p.c => 9p.c} | 0
 hw/9pfs/Makefile.objs         | 2 +-
 2 files changed, 1 insertion(+), 1 deletion(-)
 rename hw/9pfs/{virtio-9p.c => 9p.c} (100%)

diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/9p.c
similarity index 100%
rename from hw/9pfs/virtio-9p.c
rename to hw/9pfs/9p.c
diff --git a/hw/9pfs/Makefile.objs b/hw/9pfs/Makefile.objs
index 838c5e1..da0ae0c 100644
--- a/hw/9pfs/Makefile.objs
+++ b/hw/9pfs/Makefile.objs
@@ -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
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [Qemu-devel] [PATCH v2 26/27] 9pfs: factor out v9fs_device_{, un}realize_common
  2016-01-07 19:55 [Qemu-devel] [PATCH v2 00/27] 9pfs: disentangling virtio and generic code Wei Liu
                   ` (24 preceding siblings ...)
  2016-01-07 19:56 ` [Qemu-devel] [PATCH v2 25/27] 9pfs: rename virtio-9p.c to 9p.c Wei Liu
@ 2016-01-07 19:56 ` Wei Liu
  2016-01-07 19:56 ` [Qemu-devel] [PATCH v2 27/27] 9pfs: disentangle V9fsState Wei Liu
  2016-01-08 10:49 ` [Qemu-devel] [PATCH v2 00/27] 9pfs: disentangling virtio and generic code Aneesh Kumar K.V
  27 siblings, 0 replies; 38+ messages in thread
From: Wei Liu @ 2016-01-07 19:56 UTC (permalink / raw)
  To: qemu-devel; +Cc: Michael S. Tsirkin, Wei Liu, Aneesh Kumar K.V, Greg Kurz

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
---
 hw/9pfs/9p.c               | 95 ++++++++++++++++++++++++++++++++++++++++++++++
 hw/9pfs/9p.h               |  2 +
 hw/9pfs/virtio-9p-device.c | 90 ++++---------------------------------------
 3 files changed, 104 insertions(+), 83 deletions(-)

diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c
index 50d7333..6858b21 100644
--- a/hw/9pfs/9p.c
+++ b/hw/9pfs/9p.c
@@ -3271,6 +3271,101 @@ void pdu_submit(V9fsPDU *pdu)
     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);
+}
+
 static void __attribute__((__constructor__)) v9fs_set_fd_limit(void)
 {
     struct rlimit rlim;
diff --git a/hw/9pfs/9p.h b/hw/9pfs/9p.h
index b62c9a8..3fe4da4 100644
--- a/hw/9pfs/9p.h
+++ b/hw/9pfs/9p.h
@@ -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, ...);
diff --git a/hw/9pfs/virtio-9p-device.c b/hw/9pfs/virtio-9p-device.c
index bc103b7..4aa8a6b 100644
--- a/hw/9pfs/virtio-9p-device.c
+++ b/hw/9pfs/virtio-9p-device.c
@@ -101,93 +101,18 @@ static void virtio_9p_device_realize(DeviceState *dev, Error **errp)
 {
     VirtIODevice *vdev = VIRTIO_DEVICE(dev);
     V9fsState *s = VIRTIO_9P(dev);
-    int i, len;
-    struct stat stat;
-    FsDriverEntry *fse;
-    V9fsPath path;
-
-    virtio_init(vdev, "virtio-9p", VIRTIO_ID_9P,
-                sizeof(struct virtio_9p_config) + MAX_TAG_LEN);
-
-    /* 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;
-    }
-
-    s->vq = virtio_add_queue(vdev, MAX_REQ, handle_9p_output);
-
-    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, "Virtio-9p 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);
+    if (v9fs_device_realize_common(s, errp)) {
         goto out;
     }
 
-    s->tag = g_strdup(s->fsconf.tag);
-    s->ctx.uid = -1;
-
-    s->ops = fse->ops;
-    s->config_size = sizeof(struct virtio_9p_config) + len;
-    s->fid_list = NULL;
-    qemu_co_rwlock_init(&s->rename_lock);
-
-    if (s->ops->init(&s->ctx) < 0) {
-        error_setg(errp, "Virtio-9p 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);
-
+    s->config_size = sizeof(struct virtio_9p_config) + strlen(s->fsconf.tag);
+    virtio_init(vdev, "virtio-9p", VIRTIO_ID_9P, s->config_size);
+    s->vq = virtio_add_queue(vdev, MAX_REQ, handle_9p_output);
     register_savevm(dev, "virtio-9p", -1, 1, virtio_9p_save, virtio_9p_load, s);
-    return;
+
 out:
-    g_free(s->ctx.fs_root);
-    g_free(s->tag);
-    virtio_cleanup(vdev);
-    v9fs_path_free(&path);
+    return;
 }
 
 static void virtio_9p_device_unrealize(DeviceState *dev, Error **errp)
@@ -197,8 +122,7 @@ static void virtio_9p_device_unrealize(DeviceState *dev, Error **errp)
 
     virtio_cleanup(vdev);
     unregister_savevm(dev, "virtio-9p", s);
-    g_free(s->ctx.fs_root);
-    g_free(s->tag);
+    v9fs_device_unrealize_common(s, errp);
 }
 
 ssize_t virtio_pdu_vmarshal(V9fsPDU *pdu, size_t offset,
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [Qemu-devel] [PATCH v2 27/27] 9pfs: disentangle V9fsState
  2016-01-07 19:55 [Qemu-devel] [PATCH v2 00/27] 9pfs: disentangling virtio and generic code Wei Liu
                   ` (25 preceding siblings ...)
  2016-01-07 19:56 ` [Qemu-devel] [PATCH v2 26/27] 9pfs: factor out v9fs_device_{, un}realize_common Wei Liu
@ 2016-01-07 19:56 ` Wei Liu
  2016-01-08  6:09   ` Aneesh Kumar K.V
  2016-01-08 10:49 ` [Qemu-devel] [PATCH v2 00/27] 9pfs: disentangling virtio and generic code Aneesh Kumar K.V
  27 siblings, 1 reply; 38+ messages in thread
From: Wei Liu @ 2016-01-07 19:56 UTC (permalink / raw)
  To: qemu-devel
  Cc: Wei Liu, Michael S. Tsirkin, Alexander Graf,
	Christian Borntraeger, Aneesh Kumar K.V, Cornelia Huck,
	Richard Henderson, Greg Kurz

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.

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
---
 hw/9pfs/9p.c               | 41 ++++++++++++++++++-----
 hw/9pfs/9p.h               | 19 +++++++----
 hw/9pfs/virtio-9p-device.c | 82 ++++++++++++++++++++++++++++------------------
 hw/9pfs/virtio-9p.h        | 12 ++++++-
 hw/s390x/virtio-ccw.h      |  2 +-
 hw/virtio/virtio-pci.h     |  2 +-
 6 files changed, 109 insertions(+), 49 deletions(-)

diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c
index 6858b21..2cf8580 100644
--- a/hw/9pfs/9p.c
+++ b/hw/9pfs/9p.c
@@ -45,7 +45,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;
@@ -57,7 +63,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;
@@ -65,7 +77,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)
@@ -1696,7 +1712,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);
@@ -3272,8 +3292,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;
@@ -3284,8 +3306,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);
@@ -3360,7 +3384,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);
diff --git a/hw/9pfs/9p.h b/hw/9pfs/9p.h
index 3fe4da4..bd8588d 100644
--- a/hw/9pfs/9p.h
+++ b/hw/9pfs/9p.h
@@ -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, ...);
diff --git a/hw/9pfs/virtio-9p-device.c b/hw/9pfs/virtio-9p-device.c
index 4aa8a6b..ba6ba11 100644
--- a/hw/9pfs/virtio-9p-device.c
+++ b/hw/9pfs/virtio-9p-device.c
@@ -24,33 +24,41 @@
 void virtio_9p_push_and_notify(V9fsPDU *pdu)
 {
     V9fsState *s = pdu->s;
+    V9fsVirtioState *v = container_of(s, V9fsVirtioState, state);
+    VirtQueueElement *elem = &v->elems[pdu->idx];
 
     /* push onto queue and notify */
-    virtqueue_push(s->vq, &pdu->elem, pdu->size);
+    virtqueue_push(v->vq, elem, pdu->size);
 
     /* FIXME: we should batch these completions */
-    virtio_notify(VIRTIO_DEVICE(s), s->vq);
+    virtio_notify(VIRTIO_DEVICE(v), v->vq);
 }
 
 static void handle_9p_output(VirtIODevice *vdev, VirtQueue *vq)
 {
-    V9fsState *s = (V9fsState *)vdev;
+    V9fsVirtioState *v = (V9fsVirtioState *)vdev;
+    V9fsState *s = &v->state;
     V9fsPDU *pdu;
     ssize_t len;
 
-    while ((pdu = pdu_alloc(s)) &&
-            (len = virtqueue_pop(vq, &pdu->elem)) != 0) {
+    while ((pdu = pdu_alloc(s))) {
         struct {
             uint32_t size_le;
             uint8_t id;
             uint16_t tag_le;
         } QEMU_PACKED out;
-        int len;
+        VirtQueueElement *elem = &v->elems[pdu->idx];
 
-        BUG_ON(pdu->elem.out_num == 0 || pdu->elem.in_num == 0);
+        len = virtqueue_pop(vq, elem);
+        if (!len) {
+            pdu_free(pdu);
+            break;
+        }
+
+        BUG_ON(elem->out_num == 0 || elem->in_num == 0);
         QEMU_BUILD_BUG_ON(sizeof out != 7);
 
-        len = iov_to_buf(pdu->elem.out_sg, pdu->elem.out_num, 0,
+        len = iov_to_buf(elem->out_sg, elem->out_num, 0,
                          &out, sizeof out);
         BUG_ON(len != sizeof out);
 
@@ -62,7 +70,6 @@ static void handle_9p_output(VirtIODevice *vdev, VirtQueue *vq)
         qemu_co_queue_init(&pdu->complete);
         pdu_submit(pdu);
     }
-    pdu_free(pdu);
 }
 
 static uint64_t virtio_9p_get_features(VirtIODevice *vdev, uint64_t features,
@@ -76,14 +83,15 @@ static void virtio_9p_get_config(VirtIODevice *vdev, uint8_t *config)
 {
     int len;
     struct virtio_9p_config *cfg;
-    V9fsState *s = VIRTIO_9P(vdev);
+    V9fsVirtioState *v = VIRTIO_9P(vdev);
+    V9fsState *s = &v->state;
 
     len = strlen(s->tag);
     cfg = g_malloc0(sizeof(struct virtio_9p_config) + len);
     virtio_stw_p(vdev, &cfg->tag_len, len);
     /* We don't copy the terminating null to config space */
     memcpy(cfg->tag, s->tag, len);
-    memcpy(config, cfg, s->config_size);
+    memcpy(config, cfg, v->config_size);
     g_free(cfg);
 }
 
@@ -100,16 +108,17 @@ static int virtio_9p_load(QEMUFile *f, void *opaque, int version_id)
 static void virtio_9p_device_realize(DeviceState *dev, Error **errp)
 {
     VirtIODevice *vdev = VIRTIO_DEVICE(dev);
-    V9fsState *s = VIRTIO_9P(dev);
+    V9fsVirtioState *v = VIRTIO_9P(dev);
+    V9fsState *s = &v->state;
 
-    if (v9fs_device_realize_common(s, errp)) {
+    if (v9fs_device_realize_common(s, VIRTIO, errp)) {
         goto out;
     }
 
-    s->config_size = sizeof(struct virtio_9p_config) + strlen(s->fsconf.tag);
-    virtio_init(vdev, "virtio-9p", VIRTIO_ID_9P, s->config_size);
-    s->vq = virtio_add_queue(vdev, MAX_REQ, handle_9p_output);
-    register_savevm(dev, "virtio-9p", -1, 1, virtio_9p_save, virtio_9p_load, s);
+    v->config_size = sizeof(struct virtio_9p_config) + strlen(s->fsconf.tag);
+    virtio_init(vdev, "virtio-9p", VIRTIO_ID_9P, v->config_size);
+    v->vq = virtio_add_queue(vdev, MAX_REQ, handle_9p_output);
+    register_savevm(dev, "virtio-9p", -1, 1, virtio_9p_save, virtio_9p_load, v);
 
 out:
     return;
@@ -118,44 +127,55 @@ out:
 static void virtio_9p_device_unrealize(DeviceState *dev, Error **errp)
 {
     VirtIODevice *vdev = VIRTIO_DEVICE(dev);
-    V9fsState *s = VIRTIO_9P(dev);
+    V9fsVirtioState *v = VIRTIO_9P(dev);
+    V9fsState *s = &v->state;
 
     virtio_cleanup(vdev);
-    unregister_savevm(dev, "virtio-9p", s);
-    v9fs_device_unrealize_common(s, errp);
+    unregister_savevm(dev, "virtio-9p", v);
+    v9fs_device_unrealize_common(s, VIRTIO, errp);
 }
 
 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);
+    V9fsState *s = pdu->s;
+    V9fsVirtioState *v = container_of(s, V9fsVirtioState, state);
+    VirtQueueElement *elem = &v->elems[pdu->idx];
+
+    return v9fs_iov_vmarshal(elem->in_sg, 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);
+    V9fsState *s = pdu->s;
+    V9fsVirtioState *v = container_of(s, V9fsVirtioState, state);
+    VirtQueueElement *elem = &v->elems[pdu->idx];
+
+    return v9fs_iov_vunmarshal(elem->out_sg, elem->out_num, offset, 1, fmt, ap);
 }
 
 void virtio_init_iov_from_pdu(V9fsPDU *pdu, struct iovec **piov,
                               unsigned int *pniov, bool is_write)
 {
+    V9fsState *s = pdu->s;
+    V9fsVirtioState *v = container_of(s, V9fsVirtioState, state);
+    VirtQueueElement *elem = &v->elems[pdu->idx];
+
     if (is_write) {
-        *piov = pdu->elem.out_sg;
-        *pniov = pdu->elem.out_num;
+        *piov = elem->out_sg;
+        *pniov = elem->out_num;
     } else {
-        *piov = pdu->elem.in_sg;
-        *pniov = pdu->elem.in_num;
+        *piov = elem->in_sg;
+        *pniov = elem->in_num;
     }
 }
 
 /* virtio-9p device */
 
 static Property virtio_9p_properties[] = {
-    DEFINE_PROP_STRING("mount_tag", V9fsState, fsconf.tag),
-    DEFINE_PROP_STRING("fsdev", V9fsState, fsconf.fsdev_id),
+    DEFINE_PROP_STRING("mount_tag", V9fsVirtioState, state.fsconf.tag),
+    DEFINE_PROP_STRING("fsdev", V9fsVirtioState, state.fsconf.fsdev_id),
     DEFINE_PROP_END_OF_LIST(),
 };
 
@@ -175,7 +195,7 @@ static void virtio_9p_class_init(ObjectClass *klass, void *data)
 static const TypeInfo virtio_device_info = {
     .name = TYPE_VIRTIO_9P,
     .parent = TYPE_VIRTIO_DEVICE,
-    .instance_size = sizeof(V9fsState),
+    .instance_size = sizeof(V9fsVirtioState),
     .class_init = virtio_9p_class_init,
 };
 
diff --git a/hw/9pfs/virtio-9p.h b/hw/9pfs/virtio-9p.h
index 474ab94..1cdf0a2 100644
--- a/hw/9pfs/virtio-9p.h
+++ b/hw/9pfs/virtio-9p.h
@@ -5,6 +5,16 @@
 #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);
 
 ssize_t virtio_pdu_vmarshal(V9fsPDU *pdu, size_t offset,
@@ -16,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
diff --git a/hw/s390x/virtio-ccw.h b/hw/s390x/virtio-ccw.h
index 7ab8367..a526d2f 100644
--- a/hw/s390x/virtio-ccw.h
+++ b/hw/s390x/virtio-ccw.h
@@ -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 */
diff --git a/hw/virtio/virtio-pci.h b/hw/virtio/virtio-pci.h
index 7cf5974..e096e98 100644
--- a/hw/virtio/virtio-pci.h
+++ b/hw/virtio/virtio-pci.h
@@ -242,7 +242,7 @@ struct VirtIONetPCI {
 
 typedef struct V9fsPCIState {
     VirtIOPCIProxy parent_obj;
-    V9fsState vdev;
+    V9fsVirtioState vdev;
 } V9fsPCIState;
 
 #endif
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 38+ messages in thread

* Re: [Qemu-devel] [PATCH v2 27/27] 9pfs: disentangle V9fsState
  2016-01-07 19:56 ` [Qemu-devel] [PATCH v2 27/27] 9pfs: disentangle V9fsState Wei Liu
@ 2016-01-08  6:09   ` Aneesh Kumar K.V
  2016-01-08 18:54     ` Wei Liu
  0 siblings, 1 reply; 38+ messages in thread
From: Aneesh Kumar K.V @ 2016-01-08  6:09 UTC (permalink / raw)
  To: Wei Liu, qemu-devel
  Cc: Michael S. Tsirkin, Alexander Graf, Christian Borntraeger,
	Cornelia Huck, Greg Kurz, Richard Henderson

Wei Liu <wei.liu2@citrix.com> writes:

> 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.
>

Few comments below


> Signed-off-by: Wei Liu <wei.liu2@citrix.com>
> ---
>  hw/9pfs/9p.c               | 41 ++++++++++++++++++-----
>  hw/9pfs/9p.h               | 19 +++++++----
>  hw/9pfs/virtio-9p-device.c | 82 ++++++++++++++++++++++++++++------------------
>  hw/9pfs/virtio-9p.h        | 12 ++++++-
>  hw/s390x/virtio-ccw.h      |  2 +-
>  hw/virtio/virtio-pci.h     |  2 +-
>  6 files changed, 109 insertions(+), 49 deletions(-)
>
> diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c
> index 6858b21..2cf8580 100644
> --- a/hw/9pfs/9p.c
> +++ b/hw/9pfs/9p.c
> @@ -45,7 +45,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);
>


All that switch(pdu->transport) can go in the next series along with Xen
support. It is not really needed now and when we complete Xen transport
we will pull that. 

>      return ret;
> @@ -57,7 +63,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;
> @@ -65,7 +77,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)
> @@ -1696,7 +1712,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);
> @@ -3272,8 +3292,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;
> @@ -3284,8 +3306,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);
> @@ -3360,7 +3384,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);
> diff --git a/hw/9pfs/9p.h b/hw/9pfs/9p.h
> index 3fe4da4..bd8588d 100644
> --- a/hw/9pfs/9p.h
> +++ b/hw/9pfs/9p.h
> @@ -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;
>  };
>


Can you do this change as a separate patch ? ie, Make V9fsPDU
independent of virtio . Also introduce V9fsVirtioState 


>
> @@ -205,16 +210,12 @@ struct V9fsFidState
>

-aneesh

^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [Qemu-devel] [PATCH v2 12/27] 9pfs: use V9fsBlob to transmit xattr
  2016-01-07 19:56 ` [Qemu-devel] [PATCH v2 12/27] 9pfs: use V9fsBlob to transmit xattr Wei Liu
@ 2016-01-08  8:30   ` Aneesh Kumar K.V
  2016-01-08 17:56     ` Wei Liu
  0 siblings, 1 reply; 38+ messages in thread
From: Aneesh Kumar K.V @ 2016-01-08  8:30 UTC (permalink / raw)
  To: Wei Liu, qemu-devel; +Cc: Michael S. Tsirkin, Greg Kurz

Wei Liu <wei.liu2@citrix.com> writes:

> And make v9fs_pack static function. Now we only need to export
> v9fs_{,un}marshal to device.
>
> Signed-off-by: Wei Liu <wei.liu2@citrix.com>
> ---
>  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(-)
>
> diff --git a/fsdev/virtio-9p-marshal.c b/fsdev/virtio-9p-marshal.c
> index c3ac316..d120bd2 100644
> --- a/fsdev/virtio-9p-marshal.c
> +++ b/fsdev/virtio-9p-marshal.c
> @@ -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);
>  }
> diff --git a/fsdev/virtio-9p-marshal.h b/fsdev/virtio-9p-marshal.h
> index 0709bcd..766a48e 100644
> --- a/fsdev/virtio-9p-marshal.h
> +++ b/fsdev/virtio-9p-marshal.h
> @@ -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,
> diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c
> index 30ff828..654c103 100644
> --- a/hw/9pfs/virtio-9p.c
> +++ b/hw/9pfs/virtio-9p.c
> @@ -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);

Is this correct ?

earlier we had read_count <data>
now we have
read_count, <blob> which is read_count, blob->size, data


-aneesh

^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [Qemu-devel] [PATCH v2 21/27] 9pfs: factor out virtio_9p_push_and_notify
  2016-01-07 19:56 ` [Qemu-devel] [PATCH v2 21/27] 9pfs: factor out virtio_9p_push_and_notify Wei Liu
@ 2016-01-08  9:57   ` Aneesh Kumar K.V
  2016-01-08 17:57     ` Wei Liu
  0 siblings, 1 reply; 38+ messages in thread
From: Aneesh Kumar K.V @ 2016-01-08  9:57 UTC (permalink / raw)
  To: Wei Liu, qemu-devel; +Cc: Greg Kurz, Michael S. Tsirkin

Wei Liu <wei.liu2@citrix.com> writes:

> The new function resides in virtio specific file.
>
> Signed-off-by: Wei Liu <wei.liu2@citrix.com>
> ---
> v2: new, part of original "9pfs: break out generic code from
>     virtio-9p.{c,h}"
> ---
>  hw/9pfs/virtio-9p-device.c | 11 +++++++++++
>  hw/9pfs/virtio-9p.c        |  8 +-------
>  hw/9pfs/virtio-9p.h        |  2 ++
>  3 files changed, 14 insertions(+), 7 deletions(-)
>
> diff --git a/hw/9pfs/virtio-9p-device.c b/hw/9pfs/virtio-9p-device.c
> index 5cad654..cfad13a 100644
> --- a/hw/9pfs/virtio-9p-device.c
> +++ b/hw/9pfs/virtio-9p-device.c
> @@ -20,6 +20,17 @@
>  #include "coth.h"
>  #include "hw/virtio/virtio-access.h"
>
> +void virtio_9p_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 uint64_t virtio_9p_get_features(VirtIODevice *vdev, uint64_t features,
>                                         Error **errp)
>  {
> diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c
> index 3c39247..0ba2312 100644
> --- a/hw/9pfs/virtio-9p.c
> +++ b/hw/9pfs/virtio-9p.c
> @@ -65,13 +65,7 @@ ssize_t pdu_unmarshal(V9fsPDU *pdu, size_t offset, const char *fmt, ...)
>
>  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);
> +    virtio_9p_push_and_notify(pdu);
>  }
>
>  static int omode_to_uflags(int8_t mode)
> diff --git a/hw/9pfs/virtio-9p.h b/hw/9pfs/virtio-9p.h
> index b4d344a..a1ac398 100644
> --- a/hw/9pfs/virtio-9p.h
> +++ b/hw/9pfs/virtio-9p.h
> @@ -6,6 +6,8 @@
>  #include "9p.h"
>
>  extern void handle_9p_output(VirtIODevice *vdev, VirtQueue *vq);
> +extern void virtio_9p_push_and_notify(V9fsPDU *pdu);
> +
>  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,
> -- 
> 2.1.4

How is this different from pdu_push_notify added by  [PATCH 18/27]

-aneesh

^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [Qemu-devel] [PATCH v2 00/27] 9pfs: disentangling virtio and generic code
  2016-01-07 19:55 [Qemu-devel] [PATCH v2 00/27] 9pfs: disentangling virtio and generic code Wei Liu
                   ` (26 preceding siblings ...)
  2016-01-07 19:56 ` [Qemu-devel] [PATCH v2 27/27] 9pfs: disentangle V9fsState Wei Liu
@ 2016-01-08 10:49 ` Aneesh Kumar K.V
  2016-01-08 18:54   ` Wei Liu
  27 siblings, 1 reply; 38+ messages in thread
From: Aneesh Kumar K.V @ 2016-01-08 10:49 UTC (permalink / raw)
  To: Wei Liu, qemu-devel; +Cc: Michael S. Tsirkin, Stefano Stabellini, Greg Kurz

Wei Liu <wei.liu2@citrix.com> writes:

> Hi all
>
> Version 2 of this series is even longer. :-)
>
> 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 patch series can be found at:
>
>   git://xenbits.xen.org/people/liuw/qemu.git wip.9pfs-refactor-v2
>

I pushed most of the patches to

https://github.com/kvaneesh/qemu/commits/upstream-v9fs

Patches not yet applied are

fsdev: 9p-marshal: introduce V9fsBlob
9pfs: use V9fsBlob to transmit xattr
9pfs: disentangle V9fsState

Test result for pjd-fstest:

Test Summary Report
-------------------
./tests/xacl/00.t    (Wstat: 0 Tests: 45 Failed: 1)
  Failed test:  45
Files=191, Tests=2287, 109 wallclock secs ( 2.96 usr  1.36 sys + 13.96 cusr 40.93 csys = 59.21 CPU)

I will continue to run more tests with different security model and proxy
config before pushing this upstream.

-aneesh

^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [Qemu-devel] [PATCH v2 12/27] 9pfs: use V9fsBlob to transmit xattr
  2016-01-08  8:30   ` Aneesh Kumar K.V
@ 2016-01-08 17:56     ` Wei Liu
  2016-01-08 18:48       ` Aneesh Kumar K.V
  0 siblings, 1 reply; 38+ messages in thread
From: Wei Liu @ 2016-01-08 17:56 UTC (permalink / raw)
  To: Aneesh Kumar K.V; +Cc: Michael S. Tsirkin, Wei Liu, qemu-devel, Greg Kurz

On Fri, Jan 08, 2016 at 02:00:31PM +0530, Aneesh Kumar K.V wrote:
> Wei Liu <wei.liu2@citrix.com> writes:
> 
> > And make v9fs_pack static function. Now we only need to export
> > v9fs_{,un}marshal to device.
> >
> > Signed-off-by: Wei Liu <wei.liu2@citrix.com>
> > ---
> >  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(-)
> >
> > diff --git a/fsdev/virtio-9p-marshal.c b/fsdev/virtio-9p-marshal.c
> > index c3ac316..d120bd2 100644
> > --- a/fsdev/virtio-9p-marshal.c
> > +++ b/fsdev/virtio-9p-marshal.c
> > @@ -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);
> >  }
> > diff --git a/fsdev/virtio-9p-marshal.h b/fsdev/virtio-9p-marshal.h
> > index 0709bcd..766a48e 100644
> > --- a/fsdev/virtio-9p-marshal.h
> > +++ b/fsdev/virtio-9p-marshal.h
> > @@ -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,
> > diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c
> > index 30ff828..654c103 100644
> > --- a/hw/9pfs/virtio-9p.c
> > +++ b/hw/9pfs/virtio-9p.c
> > @@ -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);
> 
> Is this correct ?
> 
> earlier we had read_count <data>
> now we have
> read_count, <blob> which is read_count, blob->size, data
> 

Yes, you're right. There is an error.

The new code should be

    err = pdu_marshal(pdu, offset, "B", &blob);

Thanks for your careful review.

Wei.

> 
> -aneesh
> 

^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [Qemu-devel] [PATCH v2 21/27] 9pfs: factor out virtio_9p_push_and_notify
  2016-01-08  9:57   ` Aneesh Kumar K.V
@ 2016-01-08 17:57     ` Wei Liu
  0 siblings, 0 replies; 38+ messages in thread
From: Wei Liu @ 2016-01-08 17:57 UTC (permalink / raw)
  To: Aneesh Kumar K.V; +Cc: Michael S. Tsirkin, Wei Liu, qemu-devel, Greg Kurz

On Fri, Jan 08, 2016 at 03:27:49PM +0530, Aneesh Kumar K.V wrote:
[...]
> 
> How is this different from pdu_push_notify added by  [PATCH 18/27]
> 

#18 is encapsulating functionality into pdu_* function family. This
patch is encapsulating virtio specific code into virtio specific
function. The two patches reflect the process of code refactoring.

There is no functional change.  This patch just moves the code to virito
specific file and gives it a proper name. Then the virtio_ function is
called from pdu_ function.

Wei.


> -aneesh
> 
> 

^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [Qemu-devel] [PATCH v2 12/27] 9pfs: use V9fsBlob to transmit xattr
  2016-01-08 17:56     ` Wei Liu
@ 2016-01-08 18:48       ` Aneesh Kumar K.V
  2016-01-08 18:54         ` Wei Liu
  0 siblings, 1 reply; 38+ messages in thread
From: Aneesh Kumar K.V @ 2016-01-08 18:48 UTC (permalink / raw)
  To: Wei Liu; +Cc: Michael S. Tsirkin, qemu-devel, Greg Kurz

Wei Liu <wei.liu2@citrix.com> writes:

> On Fri, Jan 08, 2016 at 02:00:31PM +0530, Aneesh Kumar K.V wrote:
>> Wei Liu <wei.liu2@citrix.com> writes:
>> 
>> > And make v9fs_pack static function. Now we only need to export
>> > v9fs_{,un}marshal to device.
>> >
>> > Signed-off-by: Wei Liu <wei.liu2@citrix.com>
>> > ---
>> >  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(-)
>> >
>> > diff --git a/fsdev/virtio-9p-marshal.c b/fsdev/virtio-9p-marshal.c
>> > index c3ac316..d120bd2 100644
>> > --- a/fsdev/virtio-9p-marshal.c
>> > +++ b/fsdev/virtio-9p-marshal.c
>> > @@ -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);
>> >  }
>> > diff --git a/fsdev/virtio-9p-marshal.h b/fsdev/virtio-9p-marshal.h
>> > index 0709bcd..766a48e 100644
>> > --- a/fsdev/virtio-9p-marshal.h
>> > +++ b/fsdev/virtio-9p-marshal.h
>> > @@ -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,
>> > diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c
>> > index 30ff828..654c103 100644
>> > --- a/hw/9pfs/virtio-9p.c
>> > +++ b/hw/9pfs/virtio-9p.c
>> > @@ -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);
>> 
>> Is this correct ?
>> 
>> earlier we had read_count <data>
>> now we have
>> read_count, <blob> which is read_count, blob->size, data
>> 
>
> Yes, you're right. There is an error.
>
> The new code should be
>
>     err = pdu_marshal(pdu, offset, "B", &blob);
>
> Thanks for your careful review.
>

We would then need 'B' to encode size as int ie, 'd' instead of 'w'

-aneesh

^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [Qemu-devel] [PATCH v2 27/27] 9pfs: disentangle V9fsState
  2016-01-08  6:09   ` Aneesh Kumar K.V
@ 2016-01-08 18:54     ` Wei Liu
  0 siblings, 0 replies; 38+ messages in thread
From: Wei Liu @ 2016-01-08 18:54 UTC (permalink / raw)
  To: Aneesh Kumar K.V
  Cc: Wei Liu, Michael S. Tsirkin, qemu-devel, Alexander Graf,
	Christian Borntraeger, Cornelia Huck, Richard Henderson,
	Greg Kurz

On Fri, Jan 08, 2016 at 11:39:37AM +0530, Aneesh Kumar K.V wrote:
> Wei Liu <wei.liu2@citrix.com> writes:
> 
> > 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.
> >
> 
> Few comments below
> 
> 
> > Signed-off-by: Wei Liu <wei.liu2@citrix.com>
> > ---
> >  hw/9pfs/9p.c               | 41 ++++++++++++++++++-----
> >  hw/9pfs/9p.h               | 19 +++++++----
> >  hw/9pfs/virtio-9p-device.c | 82 ++++++++++++++++++++++++++++------------------
> >  hw/9pfs/virtio-9p.h        | 12 ++++++-
> >  hw/s390x/virtio-ccw.h      |  2 +-
> >  hw/virtio/virtio-pci.h     |  2 +-
> >  6 files changed, 109 insertions(+), 49 deletions(-)
> >
> > diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c
> > index 6858b21..2cf8580 100644
> > --- a/hw/9pfs/9p.c
> > +++ b/hw/9pfs/9p.c
> > @@ -45,7 +45,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);
> >
> 
> 
> All that switch(pdu->transport) can go in the next series along with Xen
> support. It is not really needed now and when we complete Xen transport
> we will pull that. 
> 

No problem.

> >      return ret;
> > @@ -57,7 +63,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;
> > @@ -65,7 +77,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)
> > @@ -1696,7 +1712,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);
> > @@ -3272,8 +3292,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;
> > @@ -3284,8 +3306,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);
> > @@ -3360,7 +3384,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);
> > diff --git a/hw/9pfs/9p.h b/hw/9pfs/9p.h
> > index 3fe4da4..bd8588d 100644
> > --- a/hw/9pfs/9p.h
> > +++ b/hw/9pfs/9p.h
> > @@ -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;
> >  };
> >
> 
> 
> Can you do this change as a separate patch ? ie, Make V9fsPDU
> independent of virtio . Also introduce V9fsVirtioState 
> 

No problem.

Wei.

> 
> >
> > @@ -205,16 +210,12 @@ struct V9fsFidState
> >
> 
> -aneesh
> 

^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [Qemu-devel] [PATCH v2 12/27] 9pfs: use V9fsBlob to transmit xattr
  2016-01-08 18:48       ` Aneesh Kumar K.V
@ 2016-01-08 18:54         ` Wei Liu
  0 siblings, 0 replies; 38+ messages in thread
From: Wei Liu @ 2016-01-08 18:54 UTC (permalink / raw)
  To: Aneesh Kumar K.V; +Cc: Greg Kurz, Wei Liu, qemu-devel, Michael S. Tsirkin

On Sat, Jan 09, 2016 at 12:18:40AM +0530, Aneesh Kumar K.V wrote:
> Wei Liu <wei.liu2@citrix.com> writes:
> 
> > On Fri, Jan 08, 2016 at 02:00:31PM +0530, Aneesh Kumar K.V wrote:
> >> Wei Liu <wei.liu2@citrix.com> writes:
> >> 
> >> > And make v9fs_pack static function. Now we only need to export
> >> > v9fs_{,un}marshal to device.
> >> >
> >> > Signed-off-by: Wei Liu <wei.liu2@citrix.com>
> >> > ---
> >> >  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(-)
> >> >
> >> > diff --git a/fsdev/virtio-9p-marshal.c b/fsdev/virtio-9p-marshal.c
> >> > index c3ac316..d120bd2 100644
> >> > --- a/fsdev/virtio-9p-marshal.c
> >> > +++ b/fsdev/virtio-9p-marshal.c
> >> > @@ -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);
> >> >  }
> >> > diff --git a/fsdev/virtio-9p-marshal.h b/fsdev/virtio-9p-marshal.h
> >> > index 0709bcd..766a48e 100644
> >> > --- a/fsdev/virtio-9p-marshal.h
> >> > +++ b/fsdev/virtio-9p-marshal.h
> >> > @@ -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,
> >> > diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c
> >> > index 30ff828..654c103 100644
> >> > --- a/hw/9pfs/virtio-9p.c
> >> > +++ b/hw/9pfs/virtio-9p.c
> >> > @@ -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);
> >> 
> >> Is this correct ?
> >> 
> >> earlier we had read_count <data>
> >> now we have
> >> read_count, <blob> which is read_count, blob->size, data
> >> 
> >
> > Yes, you're right. There is an error.
> >
> > The new code should be
> >
> >     err = pdu_marshal(pdu, offset, "B", &blob);
> >
> > Thanks for your careful review.
> >
> 
> We would then need 'B' to encode size as int ie, 'd' instead of 'w'
> 

Ack. I will make the change.

Wei.

> -aneesh
> 
> 

^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [Qemu-devel] [PATCH v2 00/27] 9pfs: disentangling virtio and generic code
  2016-01-08 10:49 ` [Qemu-devel] [PATCH v2 00/27] 9pfs: disentangling virtio and generic code Aneesh Kumar K.V
@ 2016-01-08 18:54   ` Wei Liu
  0 siblings, 0 replies; 38+ messages in thread
From: Wei Liu @ 2016-01-08 18:54 UTC (permalink / raw)
  To: Aneesh Kumar K.V
  Cc: Stefano Stabellini, Wei Liu, qemu-devel, Greg Kurz, Michael S. Tsirkin

On Fri, Jan 08, 2016 at 04:19:42PM +0530, Aneesh Kumar K.V wrote:
> Wei Liu <wei.liu2@citrix.com> writes:
> 
> > Hi all
> >
> > Version 2 of this series is even longer. :-)
> >
> > 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 patch series can be found at:
> >
> >   git://xenbits.xen.org/people/liuw/qemu.git wip.9pfs-refactor-v2
> >
> 
> I pushed most of the patches to
> 
> https://github.com/kvaneesh/qemu/commits/upstream-v9fs
> 
> Patches not yet applied are
> 
> fsdev: 9p-marshal: introduce V9fsBlob
> 9pfs: use V9fsBlob to transmit xattr
> 9pfs: disentangle V9fsState
> 

I will use your branch as my new baseline and work on the those three
patches.

> Test result for pjd-fstest:
> 
> Test Summary Report
> -------------------
> ./tests/xacl/00.t    (Wstat: 0 Tests: 45 Failed: 1)
>   Failed test:  45
> Files=191, Tests=2287, 109 wallclock secs ( 2.96 usr  1.36 sys + 13.96 cusr 40.93 csys = 59.21 CPU)
> 
> I will continue to run more tests with different security model and proxy
> config before pushing this upstream.
> 

Thank you very much.

Wei.


> -aneesh
> 
> 

^ permalink raw reply	[flat|nested] 38+ messages in thread

end of thread, other threads:[~2016-01-08 18:55 UTC | newest]

Thread overview: 38+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-01-07 19:55 [Qemu-devel] [PATCH v2 00/27] 9pfs: disentangling virtio and generic code Wei Liu
2016-01-07 19:55 ` [Qemu-devel] [PATCH v2 01/27] 9pfs: rename virtio-9p-coth.{c, h} to coth.{c, h} Wei Liu
2016-01-07 19:55 ` [Qemu-devel] [PATCH v2 02/27] 9pfs: rename virtio-9p-handle.c to 9p-handle.c Wei Liu
2016-01-07 19:56 ` [Qemu-devel] [PATCH v2 03/27] 9pfs: rename virtio-9p-local.c to 9p-local.c Wei Liu
2016-01-07 19:56 ` [Qemu-devel] [PATCH v2 04/27] 9pfs: rename virtio-9p-posix-acl.c to 9p-posix-acl.c Wei Liu
2016-01-07 19:56 ` [Qemu-devel] [PATCH v2 05/27] 9pfs: rename virtio-9p-proxy.{c, h} to 9p-proxy.{c, h} Wei Liu
2016-01-07 19:56 ` [Qemu-devel] [PATCH v2 06/27] 9pfs: rename virtio-9p-synth.{c, h} to 9p-synth.{c, h} Wei Liu
2016-01-07 19:56 ` [Qemu-devel] [PATCH v2 07/27] 9pfs: rename virtio-9p-xattr{, -user}.{c, h} to 9p-xattr{, -user}.{c, h} Wei Liu
2016-01-07 19:56 ` [Qemu-devel] [PATCH v2 08/27] 9pfs: merge hw/virtio/virtio-9p.h into hw/9pfs/virtio-9p.h Wei Liu
2016-01-07 19:56 ` [Qemu-devel] [PATCH v2 09/27] 9pfs: remove dead code Wei Liu
2016-01-07 19:56 ` [Qemu-devel] [PATCH v2 10/27] fsdev: break out 9p-marshal.{c, h} from virtio-9p-marshal.{c, h} Wei Liu
2016-01-07 19:56 ` [Qemu-devel] [PATCH v2 11/27] fsdev: 9p-marshal: introduce V9fsBlob Wei Liu
2016-01-07 19:56 ` [Qemu-devel] [PATCH v2 12/27] 9pfs: use V9fsBlob to transmit xattr Wei Liu
2016-01-08  8:30   ` Aneesh Kumar K.V
2016-01-08 17:56     ` Wei Liu
2016-01-08 18:48       ` Aneesh Kumar K.V
2016-01-08 18:54         ` Wei Liu
2016-01-07 19:56 ` [Qemu-devel] [PATCH v2 13/27] fsdev: rename virtio-9p-marshal.{c, h} to 9p-iov-marshal.{c, h} Wei Liu
2016-01-07 19:56 ` [Qemu-devel] [PATCH v2 14/27] 9pfs: PDU processing functions don't need to take V9fsState as argument Wei Liu
2016-01-07 19:56 ` [Qemu-devel] [PATCH v2 15/27] 9pfs: PDU processing functions should start pdu_ prefix Wei Liu
2016-01-07 19:56 ` [Qemu-devel] [PATCH v2 16/27] 9pfs: make pdu_{, un}marshal proper functions Wei Liu
2016-01-07 19:56 ` [Qemu-devel] [PATCH v2 17/27] 9pfs: factor out virtio_pdu_{, un}marshal Wei Liu
2016-01-07 19:56 ` [Qemu-devel] [PATCH v2 18/27] 9pfs: factor out pdu_push_and_notify Wei Liu
2016-01-07 19:56 ` [Qemu-devel] [PATCH v2 19/27] 9pfs: break out virtio_init_iov_from_pdu Wei Liu
2016-01-07 19:56 ` [Qemu-devel] [PATCH v2 20/27] 9pfs: break out 9p.h from virtio-9p.h Wei Liu
2016-01-07 19:56 ` [Qemu-devel] [PATCH v2 21/27] 9pfs: factor out virtio_9p_push_and_notify Wei Liu
2016-01-08  9:57   ` Aneesh Kumar K.V
2016-01-08 17:57     ` Wei Liu
2016-01-07 19:56 ` [Qemu-devel] [PATCH v2 22/27] 9pfs: export pdu_{submit, alloc, free} Wei Liu
2016-01-07 19:56 ` [Qemu-devel] [PATCH v2 23/27] 9pfs: move handle_9p_output and make it static function Wei Liu
2016-01-07 19:56 ` [Qemu-devel] [PATCH v2 24/27] 9pfs: rename virtio_9p_set_fd_limit to use v9fs_ prefix Wei Liu
2016-01-07 19:56 ` [Qemu-devel] [PATCH v2 25/27] 9pfs: rename virtio-9p.c to 9p.c Wei Liu
2016-01-07 19:56 ` [Qemu-devel] [PATCH v2 26/27] 9pfs: factor out v9fs_device_{, un}realize_common Wei Liu
2016-01-07 19:56 ` [Qemu-devel] [PATCH v2 27/27] 9pfs: disentangle V9fsState Wei Liu
2016-01-08  6:09   ` Aneesh Kumar K.V
2016-01-08 18:54     ` Wei Liu
2016-01-08 10:49 ` [Qemu-devel] [PATCH v2 00/27] 9pfs: disentangling virtio and generic code Aneesh Kumar K.V
2016-01-08 18:54   ` Wei Liu

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.