All of lore.kernel.org
 help / color / mirror / Atom feed
From: Anthony PERARD <anthony.perard@citrix.com>
To: Quan Xu <quan.xu2@aliyun.com>
Cc: Stefano Stabellini <sstabellini@kernel.org>,
	"wei.liu2" <wei.liu2@citrix.com>,
	stefanb <stefanb@linux.vnet.ibm.com>,
	qemu-devel <qemu-devel@nongnu.org>,
	xen-devel <xen-devel@lists.xen.org>,
	dgdegra <dgdegra@tycho.nsa.gov>, eblake <eblake@redhat.com>,
	rea <emilcondrea@gmail.com>
Subject: Re: [PATCH 01/19] xen: Create a new file xen_pvdev.c
Date: Mon, 18 Jul 2016 15:50:27 +0100	[thread overview]
Message-ID: <20160718145027.GC1835__44496.2836023935$1468853496$gmane$org@perard.uk.xensource.com> (raw)
In-Reply-To: <b45e5a51-c310-47fc-b417-d4aa5faea338.quan.xu2@aliyun.com>

On Sun, Jul 17, 2016 at 03:41:26PM +0800, Quan Xu wrote:
> 
> [Quan:]: comment starts with [Quan:]
> 
> 
> The purpose of the new file is to store generic functions shared by frontendand backends such as xenstore operations, xendevs.
> 
> Signed-off-by: Quan Xu <quan.xu@xxxxxxxxx>
> Signed-off-by: Emil Condrea <emilcondrea@xxxxxxxxx>
> ---
>  hw/xen/Makefile.objs         |   2 +-
>  hw/xen/xen_backend.c         | 125 +-----------------------------------
>  hw/xen/xen_pvdev.c           | 149 +++++++++++++++++++++++++++++++++++++++++++
>  include/hw/xen/xen_backend.h |  63 +-----------------
>  include/hw/xen/xen_pvdev.h   |  71 +++++++++++++++++++++
>  5 files changed, 223 insertions(+), 187 deletions(-)
>  create mode 100644 hw/xen/xen_pvdev.c
>  create mode 100644 include/hw/xen/xen_pvdev.h
> 
> diff --git a/hw/xen/Makefile.objs b/hw/xen/Makefile.objs
> index d367094..591cdc2 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_graphics.o xen_pt_msi.o
> diff --git a/hw/xen/xen_backend.c b/hw/xen/xen_backend.c
> index bab79b1..a251a4a 100644
> --- a/hw/xen/xen_backend.c
> +++ b/hw/xen/xen_backend.c
> @@ -30,6 +30,7 @@
>  #include "sysemu/char.h"
>  #include "qemu/log.h"
>  #include "hw/xen/xen_backend.h"
> +#include "hw/xen/xen_pvdev.h"
>  
>  #include <xen/grant_table.h>
>  
> @@ -56,8 +57,6 @@ static QTAILQ_HEAD(xs_dirs_head, xs_dirs) xs_cleanup =
>  static QTAILQ_HEAD(XenDeviceHead, XenDevice) xendevs = 
> QTAILQ_HEAD_INITIALIZER(xendevs);
>  static int debug = 0;
>  
> -/* ------------------------------------------------------------- */
> -
>  static void xenstore_cleanup_dir(char *dir)
>  {
>      struct xs_dirs *d;
> @@ -76,34 +75,6 @@ void xen_config_cleanup(void)
>      }
>  }
>  
> -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_mkdir(char *path, int p)
>  {
>      struct xs_permissions perms[2] = {
> @@ -128,48 +99,6 @@ int xenstore_mkdir(char *path, int p)
>      return 0;
>  }
>  
> -int xenstore_write_int(const char *base, const char *node, int ival)
> -{
> -    char val[12];
> -
> [Quan:]: why 12 ? what about XEN_BUFSIZE? 

That is the number of digit in INT_MAX (10) + 1 for the sign + 1 for '\0'.

> -    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];
> -
> [Quan:]: why 21 ? what about XEN_BUFSIZE?

Same with INT64_MAX (19 digits).

> 
> -    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);
> [Quan:]:  IMO, it is better to initialize val when declares.

I think I prefer it this way.

> -    if (val && 1 == sscanf(val, "%d", ival)) {
> -        rc = 0;
> -    }
> -    g_free(val);
> -    return rc;
> -}

-- 
Anthony PERARD

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

  parent reply	other threads:[~2016-07-18 14:50 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-17  7:41 [Qemu-devel] [Xen-devel] [PATCH 01/19] xen: Create a new file xen_pvdev.c Quan Xu
2016-07-17  7:41 ` Quan Xu
2016-07-17 17:02 ` Emil Condrea
2016-07-17 17:02 ` [Qemu-devel] [Xen-devel] " Emil Condrea
2016-07-18 14:50 ` Anthony PERARD [this message]
2016-07-18 14:50 ` Anthony PERARD
2016-07-18 14:57 ` Eric Blake
2016-07-18 14:57   ` Eric Blake
2016-07-18 16:54   ` Emil Condrea
2016-07-18 16:54   ` [Qemu-devel] [Xen-devel] " Emil Condrea
2016-07-22 14:00   ` Quan Xu
2016-07-22 14:00     ` Quan Xu
  -- strict thread matches above, loose matches on Subject: below --
2016-07-22 14:24 Quan Xu
2016-07-22 14:24 [Qemu-devel] [Xen-devel] " Quan Xu
2016-07-22 14:28 ` Emil Condrea
2016-07-10 11:47 [Qemu-devel] [v9 00/19] QEMU:Xen stubdom vTPM for HVM virtual machine(QEMU Part) Emil Condrea
2016-07-10 11:47 ` [PATCH 01/19] xen: Create a new file xen_pvdev.c Emil Condrea

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='20160718145027.GC1835__44496.2836023935$1468853496$gmane$org@perard.uk.xensource.com' \
    --to=anthony.perard@citrix.com \
    --cc=dgdegra@tycho.nsa.gov \
    --cc=eblake@redhat.com \
    --cc=emilcondrea@gmail.com \
    --cc=qemu-devel@nongnu.org \
    --cc=quan.xu2@aliyun.com \
    --cc=sstabellini@kernel.org \
    --cc=stefanb@linux.vnet.ibm.com \
    --cc=wei.liu2@citrix.com \
    --cc=xen-devel@lists.xen.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.