Re: [Qemu-devel] [PATCH v6 2/6] Qemu-Xen-vTPM: Xen frontend driver infrastructure

2015-05-08 Thread Stefano Stabellini
On Mon, 4 May 2015, Quan Xu wrote:
 @@ -97,6 +116,7 @@ extern struct XenDevOps xen_kbdmouse_ops; /* 
 xen_framebuffer.c */
  extern struct XenDevOps xen_framebuffer_ops;  /* xen_framebuffer.c */
  extern struct XenDevOps xen_blkdev_ops;   /* xen_disk.c*/
  extern struct XenDevOps xen_netdev_ops;   /* xen_nic.c */
 +extern struct XenDevOps xen_vtpmdev_ops;  /* xen_vtpm_frontend.c*/

This should be in the next patch.



Re: [Qemu-devel] [PATCH v6 2/6] Qemu-Xen-vTPM: Xen frontend driver infrastructure

2015-05-07 Thread Stefano Stabellini
On Mon, 4 May 2015, Quan Xu wrote:
 This patch adds infrastructure for xen front drivers living in qemu,
 so drivers don't need to implement common stuff on their own.  It's
 mostly xenbus management stuff: some functions to access XenStore,
 setting up XenStore watches, callbacks on device discovery and state
 changes, and handle event channel between the virtual machines.
 
 Call xen_fe_register() function to register XenDevOps, and make sure,
 XenDevOps's flags is DEVOPS_FLAG_FE, which is flag bit to point out
 the XenDevOps is Xen frontend.
 
 Create a new file xen_pvdev.c for some common part of xen frontend
 and backend, such as xendevs queue and xenstore update functions.
 
 Signed-off-by: Quan Xu quan...@intel.com

Better than the early versions, thanks.

However the patch is too big and it is too difficult to read as is.
Could you please split it in two: a patch that creates xen_pvdev.c and
moves a few functions from xen_backend.c to it and a second patch that
introduces xen_frontend.c.


  hw/display/xenfb.c   |   4 +-
  hw/xen/Makefile.objs |   2 +-
  hw/xen/xen_backend.c | 353 ---
  hw/xen/xen_frontend.c| 345 +++
  hw/xen/xen_pvdev.c   | 481 
 +++
  include/hw/xen/xen_backend.h |  22 +-
  6 files changed, 850 insertions(+), 357 deletions(-)
  create mode 100644 hw/xen/xen_frontend.c
  create mode 100644 hw/xen/xen_pvdev.c
 
 diff --git a/hw/display/xenfb.c b/hw/display/xenfb.c
 index 5e324ef..10751df 100644
 --- a/hw/display/xenfb.c
 +++ b/hw/display/xenfb.c
 @@ -988,8 +988,8 @@ void xen_init_display(int domid)
  wait_more:
  i++;
  main_loop_wait(true);
 -xfb = xen_be_find_xendev(vfb, domid, 0);
 -xin = xen_be_find_xendev(vkbd, domid, 0);
 +xfb = xen_find_xendev(vfb, domid, 0);
 +xin = xen_find_xendev(vkbd, domid, 0);
  if (!xfb || !xin) {
  if (i  256) {
  usleep(1);
 diff --git a/hw/xen/Makefile.objs b/hw/xen/Makefile.objs
 index a0ca0aa..95eb9d0 100644
 --- a/hw/xen/Makefile.objs
 +++ b/hw/xen/Makefile.objs
 @@ -1,5 +1,5 @@
  # xen backend driver support
 -common-obj-$(CONFIG_XEN_BACKEND) += xen_backend.o xen_devconfig.o
 +common-obj-$(CONFIG_XEN_BACKEND) += xen_backend.o xen_devconfig.o 
 xen_frontend.o xen_pvdev.o
  
  obj-$(CONFIG_XEN_PCI_PASSTHROUGH) += xen-host-pci-device.o
  obj-$(CONFIG_XEN_PCI_PASSTHROUGH) += xen_pt.o xen_pt_config_init.o 
 xen_pt_msi.o
 diff --git a/hw/xen/xen_backend.c b/hw/xen/xen_backend.c
 index b2cb22b..844f918 100644
 --- a/hw/xen/xen_backend.c
 +++ b/hw/xen/xen_backend.c
 @@ -44,86 +44,11 @@
  /* - */
  
  /* public */
 -XenXC xen_xc = XC_HANDLER_INITIAL_VALUE;
 -struct xs_handle *xenstore = NULL;
  const char *xen_protocol;
  
  /* private */
 -static QTAILQ_HEAD(XenDeviceHead, XenDevice) xendevs = 
 QTAILQ_HEAD_INITIALIZER(xendevs);
  static int debug = 0;
  
 -/* - */
 -
 -int xenstore_write_str(const char *base, const char *node, const char *val)
 -{
 -char abspath[XEN_BUFSIZE];
 -
 -snprintf(abspath, sizeof(abspath), %s/%s, base, node);
 -if (!xs_write(xenstore, 0, abspath, val, strlen(val))) {
 -return -1;
 -}
 -return 0;
 -}
 -
 -char *xenstore_read_str(const char *base, const char *node)
 -{
 -char abspath[XEN_BUFSIZE];
 -unsigned int len;
 -char *str, *ret = NULL;
 -
 -snprintf(abspath, sizeof(abspath), %s/%s, base, node);
 -str = xs_read(xenstore, 0, abspath, len);
 -if (str != NULL) {
 -/* move to qemu-allocated memory to make sure
 - * callers can savely g_free() stuff. */
 -ret = g_strdup(str);
 -free(str);
 -}
 -return ret;
 -}
 -
 -int xenstore_write_int(const char *base, const char *node, int ival)
 -{
 -char val[12];
 -
 -snprintf(val, sizeof(val), %d, ival);
 -return xenstore_write_str(base, node, val);
 -}
 -
 -int xenstore_write_int64(const char *base, const char *node, int64_t ival)
 -{
 -char val[21];
 -
 -snprintf(val, sizeof(val), %PRId64, ival);
 -return xenstore_write_str(base, node, val);
 -}
 -
 -int xenstore_read_int(const char *base, const char *node, int *ival)
 -{
 -char *val;
 -int rc = -1;
 -
 -val = xenstore_read_str(base, node);
 -if (val  1 == sscanf(val, %d, ival)) {
 -rc = 0;
 -}
 -g_free(val);
 -return rc;
 -}
 -
 -int xenstore_read_uint64(const char *base, const char *node, uint64_t *uval)
 -{
 -char *val;
 -int rc = -1;
 -
 -val = xenstore_read_str(base, node);
 -if (val  1 == sscanf(val, %SCNu64, uval)) {
 -rc = 0;
 -}
 -g_free(val);
 -return rc;
 -}
 -
  int xenstore_write_be_str(struct XenDevice *xendev, const char *node, const 
 char *val)
  {
  return xenstore_write_str(xendev-be, node, val);
 @@ -195,183 +120,6 @@ int 

[Qemu-devel] [PATCH v6 2/6] Qemu-Xen-vTPM: Xen frontend driver infrastructure

2015-05-04 Thread Quan Xu
This patch adds infrastructure for xen front drivers living in qemu,
so drivers don't need to implement common stuff on their own.  It's
mostly xenbus management stuff: some functions to access XenStore,
setting up XenStore watches, callbacks on device discovery and state
changes, and handle event channel between the virtual machines.

Call xen_fe_register() function to register XenDevOps, and make sure,
XenDevOps's flags is DEVOPS_FLAG_FE, which is flag bit to point out
the XenDevOps is Xen frontend.

Create a new file xen_pvdev.c for some common part of xen frontend
and backend, such as xendevs queue and xenstore update functions.

Signed-off-by: Quan Xu quan...@intel.com
---
 hw/display/xenfb.c   |   4 +-
 hw/xen/Makefile.objs |   2 +-
 hw/xen/xen_backend.c | 353 ---
 hw/xen/xen_frontend.c| 345 +++
 hw/xen/xen_pvdev.c   | 481 +++
 include/hw/xen/xen_backend.h |  22 +-
 6 files changed, 850 insertions(+), 357 deletions(-)
 create mode 100644 hw/xen/xen_frontend.c
 create mode 100644 hw/xen/xen_pvdev.c

diff --git a/hw/display/xenfb.c b/hw/display/xenfb.c
index 5e324ef..10751df 100644
--- a/hw/display/xenfb.c
+++ b/hw/display/xenfb.c
@@ -988,8 +988,8 @@ void xen_init_display(int domid)
 wait_more:
 i++;
 main_loop_wait(true);
-xfb = xen_be_find_xendev(vfb, domid, 0);
-xin = xen_be_find_xendev(vkbd, domid, 0);
+xfb = xen_find_xendev(vfb, domid, 0);
+xin = xen_find_xendev(vkbd, domid, 0);
 if (!xfb || !xin) {
 if (i  256) {
 usleep(1);
diff --git a/hw/xen/Makefile.objs b/hw/xen/Makefile.objs
index a0ca0aa..95eb9d0 100644
--- a/hw/xen/Makefile.objs
+++ b/hw/xen/Makefile.objs
@@ -1,5 +1,5 @@
 # xen backend driver support
-common-obj-$(CONFIG_XEN_BACKEND) += xen_backend.o xen_devconfig.o
+common-obj-$(CONFIG_XEN_BACKEND) += xen_backend.o xen_devconfig.o 
xen_frontend.o xen_pvdev.o
 
 obj-$(CONFIG_XEN_PCI_PASSTHROUGH) += xen-host-pci-device.o
 obj-$(CONFIG_XEN_PCI_PASSTHROUGH) += xen_pt.o xen_pt_config_init.o xen_pt_msi.o
diff --git a/hw/xen/xen_backend.c b/hw/xen/xen_backend.c
index b2cb22b..844f918 100644
--- a/hw/xen/xen_backend.c
+++ b/hw/xen/xen_backend.c
@@ -44,86 +44,11 @@
 /* - */
 
 /* public */
-XenXC xen_xc = XC_HANDLER_INITIAL_VALUE;
-struct xs_handle *xenstore = NULL;
 const char *xen_protocol;
 
 /* private */
-static QTAILQ_HEAD(XenDeviceHead, XenDevice) xendevs = 
QTAILQ_HEAD_INITIALIZER(xendevs);
 static int debug = 0;
 
-/* - */
-
-int xenstore_write_str(const char *base, const char *node, const char *val)
-{
-char abspath[XEN_BUFSIZE];
-
-snprintf(abspath, sizeof(abspath), %s/%s, base, node);
-if (!xs_write(xenstore, 0, abspath, val, strlen(val))) {
-return -1;
-}
-return 0;
-}
-
-char *xenstore_read_str(const char *base, const char *node)
-{
-char abspath[XEN_BUFSIZE];
-unsigned int len;
-char *str, *ret = NULL;
-
-snprintf(abspath, sizeof(abspath), %s/%s, base, node);
-str = xs_read(xenstore, 0, abspath, len);
-if (str != NULL) {
-/* move to qemu-allocated memory to make sure
- * callers can savely g_free() stuff. */
-ret = g_strdup(str);
-free(str);
-}
-return ret;
-}
-
-int xenstore_write_int(const char *base, const char *node, int ival)
-{
-char val[12];
-
-snprintf(val, sizeof(val), %d, ival);
-return xenstore_write_str(base, node, val);
-}
-
-int xenstore_write_int64(const char *base, const char *node, int64_t ival)
-{
-char val[21];
-
-snprintf(val, sizeof(val), %PRId64, ival);
-return xenstore_write_str(base, node, val);
-}
-
-int xenstore_read_int(const char *base, const char *node, int *ival)
-{
-char *val;
-int rc = -1;
-
-val = xenstore_read_str(base, node);
-if (val  1 == sscanf(val, %d, ival)) {
-rc = 0;
-}
-g_free(val);
-return rc;
-}
-
-int xenstore_read_uint64(const char *base, const char *node, uint64_t *uval)
-{
-char *val;
-int rc = -1;
-
-val = xenstore_read_str(base, node);
-if (val  1 == sscanf(val, %SCNu64, uval)) {
-rc = 0;
-}
-g_free(val);
-return rc;
-}
-
 int xenstore_write_be_str(struct XenDevice *xendev, const char *node, const 
char *val)
 {
 return xenstore_write_str(xendev-be, node, val);
@@ -195,183 +120,6 @@ int xen_be_set_state(struct XenDevice *xendev, enum 
xenbus_state state)
 }
 
 /* - */
-
-struct XenDevice *xen_be_find_xendev(const char *type, int dom, int dev)
-{
-struct XenDevice *xendev;
-
-QTAILQ_FOREACH(xendev, xendevs, next) {
-if (xendev-dom != dom) {
-continue;
-}
-if (xendev-dev != dev) {
-continue;
-}
-if