xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
To: xen-devel@lists.xensource.com
Cc: Ian.Jackson@eu.citrix.com, Ian.Campbell@citrix.com,
	Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Subject: [PATCH 2/6] libxl: introduce libxl__device_generic_add_t
Date: Tue, 27 Mar 2012 14:59:28 +0100	[thread overview]
Message-ID: <1332856772-30292-2-git-send-email-stefano.stabellini@eu.citrix.com> (raw)
In-Reply-To: <alpine.DEB.2.00.1203271453390.15151@kaball-desktop>

Introduce libxl__device_generic_add_t that takes an xs_transaction_t as
parameter.
Use libxl__device_generic_add_t to implement libxl__device_generic_add.


Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
---
 tools/libxl/libxl_device.c   |   36 ++++++++++++++++++++++++++----------
 tools/libxl/libxl_internal.h |    2 ++
 2 files changed, 28 insertions(+), 10 deletions(-)

diff --git a/tools/libxl/libxl_device.c b/tools/libxl/libxl_device.c
index c2880e0..c6f9044 100644
--- a/tools/libxl/libxl_device.c
+++ b/tools/libxl/libxl_device.c
@@ -61,12 +61,37 @@ int libxl__parse_backend_path(libxl__gc *gc,
 int libxl__device_generic_add(libxl__gc *gc, libxl__device *device,
                              char **bents, char **fents)
 {
+    int rc = 0;
+    xs_transaction_t t;
+    libxl_ctx *ctx = libxl__gc_owner(gc);
+
+retry_transaction:
+    t = xs_transaction_start(ctx->xsh);
+
+    rc = libxl__device_generic_add_t(gc, t, device, bents, fents);
+
+    if (!xs_transaction_end(ctx->xsh, t, 0)) {
+        if (errno == EAGAIN)
+            goto retry_transaction;
+        else
+            LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "xs transaction failed");
+    }
+    return rc;
+}
+
+int libxl__device_generic_add_t(libxl__gc *gc, xs_transaction_t t,
+        libxl__device *device, char **bents, char **fents)
+{
     libxl_ctx *ctx = libxl__gc_owner(gc);
     char *frontend_path, *backend_path;
-    xs_transaction_t t;
     struct xs_permissions frontend_perms[2];
     struct xs_permissions backend_perms[2];
 
+    if (t == XBT_NULL)
+        /* we need a valid transaction: call libxl__device_generic_add
+         * to create one for us */
+        return libxl__device_generic_add(gc, device, bents, fents);
+
     frontend_path = libxl__device_frontend_path(gc, device);
     backend_path = libxl__device_backend_path(gc, device);
 
@@ -80,8 +105,6 @@ int libxl__device_generic_add(libxl__gc *gc, libxl__device *device,
     backend_perms[1].id = device->domid;
     backend_perms[1].perms = XS_PERM_READ;
 
-retry_transaction:
-    t = xs_transaction_start(ctx->xsh);
     /* FIXME: read frontend_path and check state before removing stuff */
 
     if (fents) {
@@ -100,13 +123,6 @@ retry_transaction:
         libxl__xs_writev(gc, t, backend_path, bents);
     }
 
-    if (!xs_transaction_end(ctx->xsh, t, 0)) {
-        if (errno == EAGAIN)
-            goto retry_transaction;
-        else
-            LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "xs transaction failed");
-    }
-
     return 0;
 }
 
diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h
index e0a1070..f97213f 100644
--- a/tools/libxl/libxl_internal.h
+++ b/tools/libxl/libxl_internal.h
@@ -667,6 +667,8 @@ _hidden int libxl__device_console_add(libxl__gc *gc, uint32_t domid,
 
 _hidden int libxl__device_generic_add(libxl__gc *gc, libxl__device *device,
                              char **bents, char **fents);
+_hidden int libxl__device_generic_add_t(libxl__gc *gc, xs_transaction_t t,
+        libxl__device *device, char **bents, char **fents);
 _hidden char *libxl__device_backend_path(libxl__gc *gc, libxl__device *device);
 _hidden char *libxl__device_frontend_path(libxl__gc *gc, libxl__device *device);
 _hidden int libxl__parse_backend_path(libxl__gc *gc, const char *path,
-- 
1.7.2.5

  parent reply	other threads:[~2012-03-27 13:59 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-27 13:58 [PATCH 0/6] qdisk local attach Stefano Stabellini
2012-03-27 13:59 ` [PATCH 1/6] libxl: libxl_device_disk_local_attach return a new libxl_device_disk Stefano Stabellini
2012-03-27 14:07   ` Ian Campbell
2012-03-30 10:42     ` Stefano Stabellini
2012-03-27 16:21   ` Ian Jackson
2012-03-30 10:43     ` Stefano Stabellini
2012-03-27 13:59 ` Stefano Stabellini [this message]
2012-03-27 14:04   ` [PATCH 2/6] libxl: introduce libxl__device_generic_add_t Ian Campbell
2012-03-30 10:44     ` Stefano Stabellini
2012-03-27 16:50   ` Ian Jackson
2012-03-30 10:46     ` Stefano Stabellini
2012-04-02 16:18       ` Ian Jackson
2012-04-03 12:03         ` Stefano Stabellini
2012-03-27 13:59 ` [PATCH 3/6] libxl: add an xs_transaction_t parameter to two libxl functions Stefano Stabellini
2012-03-27 14:17   ` Ian Campbell
2012-03-27 16:50   ` Ian Jackson
2012-03-27 13:59 ` [PATCH 4/6] libxl: introduce libxl__device_disk_add_t Stefano Stabellini
2012-03-27 13:59 ` [PATCH 5/6] libxl: introduce libxl__alloc_vdev Stefano Stabellini
2012-03-27 14:21   ` Ian Campbell
2012-03-27 17:21     ` Ian Jackson
2012-03-30 11:43     ` Stefano Stabellini
2012-03-30 12:14       ` Ian Campbell
2012-03-30 12:57         ` Stefano Stabellini
2012-03-27 17:19   ` Ian Jackson
2012-03-30 11:57     ` Stefano Stabellini
2012-03-30 14:17       ` Ian Jackson
2012-03-30 15:23         ` Stefano Stabellini
2012-04-02 16:15           ` Ian Jackson
2012-04-03 13:15             ` Stefano Stabellini
2012-04-03 13:17               ` Ian Jackson
2012-04-03 14:19                 ` Stefano Stabellini
2012-04-03 14:24                   ` Ian Jackson
2012-04-10 17:37                     ` Stefano Stabellini
2012-04-11 15:49                       ` Stefano Stabellini
2012-03-27 13:59 ` [PATCH 6/6] xl/libxl: implement QDISK libxl_device_disk_local_attach Stefano Stabellini
2012-03-27 17:20   ` Ian Jackson
2012-03-30 10:50     ` Stefano Stabellini
2012-03-30 13:47       ` Ian Jackson
2012-03-30 14:55         ` Stefano Stabellini

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=1332856772-30292-2-git-send-email-stefano.stabellini@eu.citrix.com \
    --to=stefano.stabellini@eu.citrix.com \
    --cc=Ian.Campbell@citrix.com \
    --cc=Ian.Jackson@eu.citrix.com \
    --cc=xen-devel@lists.xensource.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).