All of lore.kernel.org
 help / color / mirror / Atom feed
From: Wei Liu <wei.liu2@citrix.com>
To: xen-devel@lists.xen.org
Cc: Ian Jackson <ian.jackson@eu.citrix.com>,
	jfehlig@suse.com, Wei Liu <wei.liu2@citrix.com>,
	Ian Campbell <ian.campbell@citrix.com>
Subject: [PATCH 1/3] libxl, xl: don't init/dispose when not necessary
Date: Mon, 9 Feb 2015 13:21:06 +0000	[thread overview]
Message-ID: <1423488068-31268-2-git-send-email-wei.liu2@citrix.com> (raw)
In-Reply-To: <1423488068-31268-1-git-send-email-wei.liu2@citrix.com>

Functions like libxl__device_disk_from_xs_be and
libxl_vdev_to_device_disk should not touch the disk struct passed in.
It's caller's responsibility to do that.

This leads to some changes to the caller to prepare the disk struct.

Note that libxl_vdev_to_device_disk is a public API so a macro is
defined in libxl.h to indicate the change of behaviour.

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
Cc: Ian Campbell <ian.campbell@citrix.com>
Cc: Ian Jackson <ian.jackson@eu.citrix.com>
---
 tools/libxl/libxl.c      | 6 +-----
 tools/libxl/libxl.h      | 7 +++++++
 tools/libxl/xl_cmdimpl.c | 1 +
 3 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c
index cd6f42c..ef48550 100644
--- a/tools/libxl/libxl.c
+++ b/tools/libxl/libxl.c
@@ -2556,8 +2556,6 @@ static int libxl__device_disk_from_xs_be(libxl__gc *gc,
     char *tmp;
     int rc;
 
-    libxl_device_disk_init(disk);
-
     rc = sscanf(be_path, "/local/domain/%d/", &disk->backend_domid);
     if (rc != 1) {
         LOG(ERROR, "Unable to fetch device backend domid from %s", be_path);
@@ -2620,7 +2618,6 @@ static int libxl__device_disk_from_xs_be(libxl__gc *gc,
 
     return 0;
 cleanup:
-    libxl_device_disk_dispose(disk);
     return ERROR_FAIL;
 }
 
@@ -2635,8 +2632,6 @@ int libxl_vdev_to_device_disk(libxl_ctx *ctx, uint32_t domid,
     if (devid < 0)
         return ERROR_INVAL;
 
-    libxl_device_disk_init(disk);
-
     dompath = libxl__xs_get_dompath(gc, domid);
     if (!dompath) {
         goto out;
@@ -2675,6 +2670,7 @@ static int libxl__append_disk_list_of_type(libxl__gc *gc,
         tmp = realloc(*disks, sizeof (libxl_device_disk) * (*ndisks + n));
         if (tmp == NULL)
             return ERROR_NOMEM;
+        libxl_device_disk_init(tmp);
         *disks = tmp;
         pdisk = *disks + initial_disks;
         pdisk_end = *disks + initial_disks + n;
diff --git a/tools/libxl/libxl.h b/tools/libxl/libxl.h
index c219f59..8f6ed3c 100644
--- a/tools/libxl/libxl.h
+++ b/tools/libxl/libxl.h
@@ -135,6 +135,13 @@
 #define LIBXL_HAVE_LIBXL_DEVICE_DISK_DISCARD_ENABLE 1
 
 /*
+ * The caller of libxl_vdev_to_device_disk should call
+ * libxl_device_disk_init before passing in the disk struct because
+ * libxl_vdev_to_device_disk doesn't do that anymore.
+ */
+#define LIBXL_VDEV_TO_DEVICE_DISK_NO_INIT 1
+
+/*
  * LIBXL_HAVE_BUILDINFO_IOMEM_START_GFN indicates that it is possible
  * to specify the start guest frame number used to map a range of I/O
  * memory machine frame numbers via the 'gfn' field (of type uint64)
diff --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c
index b7eac29..ef101c3 100644
--- a/tools/libxl/xl_cmdimpl.c
+++ b/tools/libxl/xl_cmdimpl.c
@@ -6411,6 +6411,7 @@ int main_blockdetach(int argc, char **argv)
     }
 
     domid = find_domain(argv[optind]);
+    libxl_device_disk_init(&disk);
 
     if (libxl_vdev_to_device_disk(ctx, domid, argv[optind+1], &disk)) {
         fprintf(stderr, "Error: Device %s not connected.\n", argv[optind+1]);
-- 
1.9.1

  reply	other threads:[~2015-02-09 13:21 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-09 13:21 [PATCH 0/3] Misc patches for libxl_device_disk functions Wei Liu
2015-02-09 13:21 ` Wei Liu [this message]
2015-02-09 13:23   ` [PATCH 1/3] libxl, xl: don't init/dispose when not necessary Wei Liu
2015-02-09 14:36     ` Wei Liu
2015-02-10 10:54   ` Ian Jackson
2015-02-10 11:39     ` Wei Liu
2015-02-09 13:21 ` [PATCH 2/3] libxl: factor out libxl__disk_backend_from_xs_be Wei Liu
2015-02-10 10:56   ` Ian Jackson
2015-02-10 11:39     ` Wei Liu
2015-02-09 13:21 ` [PATCH 3/3] libxl: libxl__device_from_disk should retrieve backend from xenstore Wei Liu
2015-02-10 11:01   ` Ian Jackson
2015-02-10 11:49     ` Wei Liu
2015-02-11 17:18       ` Jim Fehlig
2015-02-12 18:35         ` Ian Jackson
2015-02-23 15:13         ` Wei Liu
2015-02-26 23:49           ` Jim Fehlig
2015-03-06 13:04             ` Wei Liu

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=1423488068-31268-2-git-send-email-wei.liu2@citrix.com \
    --to=wei.liu2@citrix.com \
    --cc=ian.campbell@citrix.com \
    --cc=ian.jackson@eu.citrix.com \
    --cc=jfehlig@suse.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.