Re: [Qemu-devel] [PATCH v8 2/7] Qemu-Xen-vTPM: Create a new file xen_pvdev.c

2016-02-13 Thread Xu, Quan
> On June 23, 2015 12:37 AM, :
> Cc: stefano.stabell...@eu.citrix.com; qemu-devel@nongnu.org;
> stef...@linux.vnet.ibm.com; ebl...@redhat.com; wei.l...@citrix.com;
> dgde...@tycho.nsa.gov; xen-de...@lists.xen.org
> Subject: Re: [PATCH v8 2/7] Qemu-Xen-vTPM: Create a new file xen_pvdev.c
> 
> On Sun, 17 May 2015, Quan Xu wrote:
> > for some common part of xen frontend and backend, such as xendevs
> > queue and xenstore update functions.
> >
> > Signed-off-by: Quan Xu 
> 
> Hi Quan,
> 
> could you please separate out the code movement from any other changes?
> This patch would become two patches: the first would only move code from
> xen_backend.c to xen_pvdev.c, no other changes except for the ones actually
> required to build the code (Makefile.objs).  The second patch would rename
> xen_be_find_xendev to xen_find_xendev and any other changes to the code
> that you making here.  That way I can very easily go and look only at the 
> things
> you actually modify.

Sure, make sense.
I will modify it in next v9. I apologize for this late reply!

-Quan




> 
> 
> >  hw/display/xenfb.c   |   4 +-
> >  hw/xen/Makefile.objs |   2 +-
> >  hw/xen/xen_backend.c | 353 ---
> >  hw/xen/xen_pvdev.c   | 481
> +++
> >  include/hw/xen/xen_backend.h |  13 +-
> >  5 files changed, 496 insertions(+), 357 deletions(-)  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..9ac9f7c 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_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, );
> > -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;
> > -
> > -

Re: [Qemu-devel] [PATCH v8 2/7] Qemu-Xen-vTPM: Create a new file xen_pvdev.c

2015-06-23 Thread Xu, Quan


 -Original Message-
 From: Stefano Stabellini [mailto:stefano.stabell...@eu.citrix.com]
 Sent: Tuesday, June 23, 2015 12:37 AM
 To: Xu, Quan
 Cc: stefano.stabell...@eu.citrix.com; qemu-devel@nongnu.org;
 stef...@linux.vnet.ibm.com; ebl...@redhat.com; wei.l...@citrix.com;
 dgde...@tycho.nsa.gov; xen-de...@lists.xen.org
 Subject: Re: [PATCH v8 2/7] Qemu-Xen-vTPM: Create a new file xen_pvdev.c
 
 On Sun, 17 May 2015, Quan Xu wrote:
  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
 
 Hi Quan,
 
 could you please separate out the code movement from any other changes?
 This patch would become two patches: the first would only move code from
 xen_backend.c to xen_pvdev.c, no other changes except for the ones actually
 required to build the code (Makefile.objs).  The second patch would rename
 xen_be_find_xendev to xen_find_xendev and any other changes to the code
 that you making here.  That way I can very easily go and look only at the 
 things
 you actually modify.
 
 Thanks,
 
 Stefano
 
 

Stefano, thanks for your comment.
Now I am focusing on ' VT-d async invalidation for Device-TLB' feature as high 
priority. 
I will fix all of your comments when I send out v1 of ' VT-d async invalidation 
for Device-TLB' feature.


Quan




Re: [Qemu-devel] [PATCH v8 2/7] Qemu-Xen-vTPM: Create a new file xen_pvdev.c

2015-06-23 Thread Stefano Stabellini
On Tue, 23 Jun 2015, Xu, Quan wrote:
  -Original Message-
  From: Stefano Stabellini [mailto:stefano.stabell...@eu.citrix.com]
  Sent: Tuesday, June 23, 2015 12:37 AM
  To: Xu, Quan
  Cc: stefano.stabell...@eu.citrix.com; qemu-devel@nongnu.org;
  stef...@linux.vnet.ibm.com; ebl...@redhat.com; wei.l...@citrix.com;
  dgde...@tycho.nsa.gov; xen-de...@lists.xen.org
  Subject: Re: [PATCH v8 2/7] Qemu-Xen-vTPM: Create a new file xen_pvdev.c
  
  On Sun, 17 May 2015, Quan Xu wrote:
   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
  
  Hi Quan,
  
  could you please separate out the code movement from any other changes?
  This patch would become two patches: the first would only move code from
  xen_backend.c to xen_pvdev.c, no other changes except for the ones actually
  required to build the code (Makefile.objs).  The second patch would rename
  xen_be_find_xendev to xen_find_xendev and any other changes to the code
  that you making here.  That way I can very easily go and look only at the 
  things
  you actually modify.
  
  Thanks,
  
  Stefano
  
  
 
 Stefano, thanks for your comment.
 Now I am focusing on ' VT-d async invalidation for Device-TLB' feature as 
 high priority. 
 I will fix all of your comments when I send out v1 of ' VT-d async 
 invalidation for Device-TLB' feature.

Sure, no problem.



Re: [Qemu-devel] [PATCH v8 2/7] Qemu-Xen-vTPM: Create a new file xen_pvdev.c

2015-06-22 Thread Stefano Stabellini
On Sun, 17 May 2015, Quan Xu wrote:
 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

Hi Quan,

could you please separate out the code movement from any other changes?
This patch would become two patches: the first would only move code from
xen_backend.c to xen_pvdev.c, no other changes except for the ones
actually required to build the code (Makefile.objs).  The second patch
would rename xen_be_find_xendev to xen_find_xendev and any other changes
to the code that you making here.  That way I can very easily go and
look only at the things you actually modify.

Thanks,

Stefano


  hw/display/xenfb.c   |   4 +-
  hw/xen/Makefile.objs |   2 +-
  hw/xen/xen_backend.c | 353 ---
  hw/xen/xen_pvdev.c   | 481 
 +++
  include/hw/xen/xen_backend.h |  13 +-
  5 files changed, 496 insertions(+), 357 deletions(-)
  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..9ac9f7c 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_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;
 -}
 -

[Qemu-devel] [PATCH v8 2/7] Qemu-Xen-vTPM: Create a new file xen_pvdev.c

2015-05-17 Thread Quan Xu
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_pvdev.c   | 481 +++
 include/hw/xen/xen_backend.h |  13 +-
 5 files changed, 496 insertions(+), 357 deletions(-)
 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..9ac9f7c 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_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 (strcmp(xendev-type, type) != 0) {
-continue;
-}
-return xendev;
-}
-return NULL;
-}
-
-/*
- * get xen backend device, allocate a new one if it doesn't exist.
- */
-static struct XenDevice *xen_be_get_xendev(const char *type, int dom, int dev,
-   struct XenDevOps *ops)
-{
-struct XenDevice *xendev;
-
-xendev = xen_be_find_xendev(type, dom, dev);
-if (xendev) {
-return xendev;
-}
-
-/* init new xendev */
-xendev = g_malloc0(ops-size);
-xendev-type  = type;
-xendev-dom   = dom;
-xendev-dev   = dev;
-xendev-ops   = ops;
-
-snprintf(xendev-be,