From mboxrd@z Thu Jan 1 00:00:00 1970 From: Ian Jackson Subject: [PATCH 01/11] libxl: unify libxl__device_destroy and device_hotplug_done Date: Wed, 1 Aug 2012 17:24:10 +0100 Message-ID: <1343838260-17725-2-git-send-email-ian.jackson@eu.citrix.com> References: <1343838260-17725-1-git-send-email-ian.jackson@eu.citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1343838260-17725-1-git-send-email-ian.jackson@eu.citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel@lists.xen.org Cc: Ian Jackson List-Id: xen-devel@lists.xenproject.org device_hotplug_done contains an open-coded but improved version of libxl__device_destroy. So move the contents of device_hotplug_done into libxl__device_destroy, deleting the old code, and replace it at its old location with a function call. Also fix the error handling: the rc from the destroy should be propagated into the aodev. Reported-by: Ian Campbell Signed-off-by: Ian Jackson --- tools/libxl/libxl_device.c | 35 ++++++++++++----------------------- 1 files changed, 12 insertions(+), 23 deletions(-) diff --git a/tools/libxl/libxl_device.c b/tools/libxl/libxl_device.c index da0c3ea..3658bd1 100644 --- a/tools/libxl/libxl_device.c +++ b/tools/libxl/libxl_device.c @@ -513,17 +513,18 @@ int libxl__device_destroy(libxl__gc *gc, libxl__device *dev) char *be_path = libxl__device_backend_path(gc, dev); char *fe_path = libxl__device_frontend_path(gc, dev); xs_transaction_t t = 0; - int rc = 0; + int rc; + + for (;;) { + rc = libxl__xs_transaction_start(gc, &t); + if (rc) goto out; - do { - t = xs_transaction_start(CTX->xsh); libxl__xs_path_cleanup(gc, t, fe_path); libxl__xs_path_cleanup(gc, t, be_path); - rc = !xs_transaction_end(CTX->xsh, t, 0); - } while (rc && errno == EAGAIN); - if (rc) { - LOGE(ERROR, "unable to finish transaction"); - goto out; + + rc = libxl__xs_transaction_commit(gc, &t); + if (!rc) break; + if (rc < 0) goto out; } libxl__device_destroy_tapdisk(gc, be_path); @@ -993,29 +994,17 @@ error: static void device_hotplug_done(libxl__egc *egc, libxl__ao_device *aodev) { STATE_AO_GC(aodev->ao); - char *be_path = libxl__device_backend_path(gc, aodev->dev); - char *fe_path = libxl__device_frontend_path(gc, aodev->dev); - xs_transaction_t t = 0; int rc; device_hotplug_clean(gc, aodev); /* Clean xenstore if it's a disconnection */ if (aodev->action == DEVICE_DISCONNECT) { - for (;;) { - rc = libxl__xs_transaction_start(gc, &t); - if (rc) goto out; - - libxl__xs_path_cleanup(gc, t, fe_path); - libxl__xs_path_cleanup(gc, t, be_path); - - rc = libxl__xs_transaction_commit(gc, &t); - if (!rc) break; - if (rc < 0) goto out; - } + rc = libxl__device_destroy(gc, aodev->dev); + if (!aodev->rc) + aodev->rc = rc; } -out: aodev->callback(egc, aodev); return; } -- 1.7.2.5