xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Roger Pau Monne <roger.pau@citrix.com>
To: xen-devel@lists.xen.org
Cc: Ian Jackson <ian.jackson@eu.citrix.com>,
	Roger Pau Monne <roger.pau@citrix.com>
Subject: [PATCH v2 04/15] libxl: reoder libxl_device unplug functions
Date: Tue, 22 May 2012 15:02:34 +0100	[thread overview]
Message-ID: <1337695365-5142-5-git-send-email-roger.pau@citrix.com> (raw)
In-Reply-To: <1337695365-5142-1-git-send-email-roger.pau@citrix.com>

This is a reorder of functions, no functional change. This is needed
because in future patches much code is added to libxl_device and it
needs to follow the usual ao operation scheme (prototypes, functions
and callbacks in order they should be called)

Cc: Ian Jackson <ian.jackson@eu.citrix.com>
Signed-off-by: Roger Pau Monne <roger.pau@citrix.com>
---
 tools/libxl/libxl_device.c |  148 +++++++++++++++++++++++---------------------
 1 files changed, 78 insertions(+), 70 deletions(-)

diff --git a/tools/libxl/libxl_device.c b/tools/libxl/libxl_device.c
index c7e057d..2006406 100644
--- a/tools/libxl/libxl_device.c
+++ b/tools/libxl/libxl_device.c
@@ -362,76 +362,6 @@ typedef struct {
     libxl__ev_devstate ds;
 } libxl__ao_device_remove;
 
-static void device_remove_cleanup(libxl__gc *gc,
-                                  libxl__ao_device_remove *aorm) {
-    if (!aorm) return;
-    libxl__ev_devstate_cancel(gc, &aorm->ds);
-}
-
-static void device_remove_callback(libxl__egc *egc, libxl__ev_devstate *ds,
-                                   int rc) {
-    libxl__ao_device_remove *aorm = CONTAINER_OF(ds, *aorm, ds);
-    libxl__gc *gc = &aorm->ao->gc;
-    libxl__ao_complete(egc, aorm->ao, rc);
-    device_remove_cleanup(gc, aorm);
-}
-
-int libxl__initiate_device_remove(libxl__egc *egc, libxl__ao *ao,
-                                  libxl__device *dev)
-{
-    AO_GC;
-    libxl_ctx *ctx = libxl__gc_owner(gc);
-    xs_transaction_t t;
-    char *be_path = libxl__device_backend_path(gc, dev);
-    char *state_path = libxl__sprintf(gc, "%s/state", be_path);
-    char *state = libxl__xs_read(gc, XBT_NULL, state_path);
-    int rc = 0;
-    libxl__ao_device_remove *aorm = 0;
-
-    if (!state)
-        goto out_ok;
-    if (atoi(state) != 4) {
-        libxl__device_destroy_tapdisk(gc, be_path);
-        xs_rm(ctx->xsh, XBT_NULL, be_path);
-        goto out_ok;
-    }
-
-retry_transaction:
-    t = xs_transaction_start(ctx->xsh);
-    xs_write(ctx->xsh, t, libxl__sprintf(gc, "%s/online", be_path), "0", strlen("0"));
-    xs_write(ctx->xsh, t, state_path, "5", strlen("5"));
-    if (!xs_transaction_end(ctx->xsh, t, 0)) {
-        if (errno == EAGAIN)
-            goto retry_transaction;
-        else {
-            rc = ERROR_FAIL;
-            goto out_fail;
-        }
-    }
-
-    libxl__device_destroy_tapdisk(gc, be_path);
-
-    aorm = libxl__zalloc(gc, sizeof(*aorm));
-    aorm->ao = ao;
-    libxl__ev_devstate_init(&aorm->ds);
-
-    rc = libxl__ev_devstate_wait(gc, &aorm->ds, device_remove_callback,
-                                 state_path, XenbusStateClosed,
-                                 LIBXL_DESTROY_TIMEOUT * 1000);
-    if (rc) goto out_fail;
-
-    return 0;
-
- out_fail:
-    assert(rc);
-    device_remove_cleanup(gc, aorm);
-    return rc;
-
- out_ok:
-    libxl__ao_complete(egc, ao, 0);
-    return 0;
-}
-
 int libxl__device_destroy(libxl__gc *gc, libxl__device *dev)
 {
     libxl_ctx *ctx = libxl__gc_owner(gc);
@@ -504,6 +434,84 @@ out:
     return 0;
 }
 
+/* Callbacks for device related operations */
+
+static void device_remove_callback(libxl__egc *egc, libxl__ev_devstate *ds,
+                                   int rc);
+
+static void device_remove_cleanup(libxl__gc *gc,
+                                  libxl__ao_device_remove *aorm);
+
+int libxl__initiate_device_remove(libxl__egc *egc, libxl__ao *ao,
+                                  libxl__device *dev)
+{
+    AO_GC;
+    libxl_ctx *ctx = libxl__gc_owner(gc);
+    xs_transaction_t t;
+    char *be_path = libxl__device_backend_path(gc, dev);
+    char *state_path = libxl__sprintf(gc, "%s/state", be_path);
+    char *state = libxl__xs_read(gc, XBT_NULL, state_path);
+    int rc = 0;
+    libxl__ao_device_remove *aorm = 0;
+
+    if (!state)
+        goto out_ok;
+    if (atoi(state) != 4) {
+        libxl__device_destroy_tapdisk(gc, be_path);
+        xs_rm(ctx->xsh, XBT_NULL, be_path);
+        goto out_ok;
+    }
+
+retry_transaction:
+    t = xs_transaction_start(ctx->xsh);
+    xs_write(ctx->xsh, t, libxl__sprintf(gc, "%s/online", be_path), "0", strlen("0"));
+    xs_write(ctx->xsh, t, state_path, "5", strlen("5"));
+    if (!xs_transaction_end(ctx->xsh, t, 0)) {
+        if (errno == EAGAIN)
+            goto retry_transaction;
+        else {
+            rc = ERROR_FAIL;
+            goto out_fail;
+        }
+    }
+
+    libxl__device_destroy_tapdisk(gc, be_path);
+
+    aorm = libxl__zalloc(gc, sizeof(*aorm));
+    aorm->ao = ao;
+    libxl__ev_devstate_init(&aorm->ds);
+
+    rc = libxl__ev_devstate_wait(gc, &aorm->ds, device_remove_callback,
+                                 state_path, XenbusStateClosed,
+                                 LIBXL_DESTROY_TIMEOUT * 1000);
+    if (rc) goto out_fail;
+
+    return 0;
+
+ out_fail:
+    assert(rc);
+    device_remove_cleanup(gc, aorm);
+    return rc;
+
+ out_ok:
+    libxl__ao_complete(egc, ao, 0);
+    return 0;
+}
+
+static void device_remove_callback(libxl__egc *egc, libxl__ev_devstate *ds,
+                                   int rc) {
+    libxl__ao_device_remove *aorm = CONTAINER_OF(ds, *aorm, ds);
+    libxl__gc *gc = &aorm->ao->gc;
+    libxl__ao_complete(egc, aorm->ao, rc);
+    device_remove_cleanup(gc, aorm);
+}
+
+static void device_remove_cleanup(libxl__gc *gc,
+                                  libxl__ao_device_remove *aorm) {
+    if (!aorm) return;
+    libxl__ev_devstate_cancel(gc, &aorm->ds);
+}
+
 int libxl__wait_for_device_model(libxl__gc *gc,
                                  uint32_t domid, char *state,
                                  libxl__spawn_starting *spawning,
-- 
1.7.7.5 (Apple Git-26)

  parent reply	other threads:[~2012-05-22 14:02 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-22 14:02 [PATCH v2 0/15] execute hotplug scripts from libxl Roger Pau Monne
2012-05-22 14:02 ` [PATCH v2 01/15] libxl: pass env vars to libxl__exec Roger Pau Monne
2012-05-22 14:02 ` [PATCH v2 02/15] libxl: fix libxl__xs_directory usage of transaction Roger Pau Monne
2012-05-22 14:02 ` [PATCH v2 03/15] libxl: add libxl__xs_path_cleanup Roger Pau Monne
2012-05-22 14:19   ` Ian Jackson
2012-05-22 14:02 ` Roger Pau Monne [this message]
2012-05-22 14:21   ` [PATCH v2 04/15] libxl: reoder libxl_device unplug functions Ian Jackson
2012-05-22 14:02 ` [PATCH v2 05/15] libxl: change libxl__ao_device_remove to libxl__ao_device Roger Pau Monne
2012-05-22 15:10   ` Ian Jackson
2012-05-22 15:27     ` Ian Campbell
2012-05-22 16:23       ` Ian Jackson
2012-05-22 15:34     ` Roger Pau Monne
2012-05-22 15:55     ` Roger Pau Monne
2012-05-22 16:32       ` Ian Jackson
2012-05-22 14:02 ` [PATCH v2 06/15] libxl: move device model creation prototypes Roger Pau Monne
2012-05-22 15:10   ` Ian Jackson
2012-05-22 14:02 ` [PATCH v2 07/15] libxl: convert libxl_domain_destroy to an async op Roger Pau Monne
2012-05-22 14:11   ` Roger Pau Monne
2012-05-22 17:01   ` Ian Jackson
2012-05-22 17:30     ` Roger Pau Monne
2012-05-22 17:48       ` Ian Jackson
2012-05-23  9:47     ` Roger Pau Monne
2012-05-23 10:45       ` Ian Jackson
2012-05-22 14:02 ` [PATCH v2 08/15] libxl: convert libxl_device_disk_add to an asyn op Roger Pau Monne
2012-05-22 17:04   ` Ian Jackson
2012-05-22 14:02 ` [PATCH v2 09/15] libxl: convert libxl_device_nic_add to an async operation Roger Pau Monne
2012-05-22 17:06   ` Ian Jackson
2012-05-23 10:24     ` Roger Pau Monne
2012-05-22 14:02 ` [PATCH v2 10/15] libxl: add option to choose who executes hotplug scripts Roger Pau Monne
2012-05-22 17:13   ` Ian Jackson
2012-05-22 14:02 ` [PATCH v2 11/15] libxl: set nic type to VIF by default Roger Pau Monne
2012-05-22 14:02 ` [PATCH v2 12/15] libxl: call hotplug scripts for disk devices from libxl Roger Pau Monne
2012-05-22 17:40   ` Ian Jackson
2012-05-22 14:02 ` [PATCH v2 13/15] libxl: call hotplug scripts for nic " Roger Pau Monne
2012-05-22 17:45   ` Ian Jackson
2012-05-23 15:14     ` Roger Pau Monne
2012-05-22 14:02 ` [PATCH v2 14/15] libxl: use libxl__xs_path_cleanup on device_destroy Roger Pau Monne
2012-05-22 17:46   ` Ian Jackson
2012-05-22 14:02 ` [PATCH v2 15/15] libxl: add dummy netbsd functions Roger Pau Monne
2012-05-22 17:47   ` Ian Jackson
2012-05-22 17:47   ` Ian Jackson
2012-05-23 15:05     ` Roger Pau Monne
2012-05-23 10:07 ` [PATCH v2 0/15] execute hotplug scripts from libxl Ian Campbell

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=1337695365-5142-5-git-send-email-roger.pau@citrix.com \
    --to=roger.pau@citrix.com \
    --cc=ian.jackson@eu.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 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).