From: Roger Pau Monne <roger.pau@entel.upc.edu>
To: xen-devel@lists.xensource.com
Cc: ian.campbell@citrix.com
Subject: [PATCH] libxl: fix device removal handling of wait_for_dev_destroy
Date: Tue, 18 Oct 2011 14:55:00 +0200 [thread overview]
Message-ID: <973022eb35ed3c2e5898.1318942500@loki> (raw)
In-Reply-To: <patchbomb.1318499605@localhost.localdomain>
# HG changeset patch
# User Roger Pau Monne <roger.pau@entel.upc.edu>
# Date 1318942350 -7200
# Node ID 973022eb35ed3c2e58980d8c4482721d4e1d7bab
# Parent c9c228ec718a4c2d22b58ce306f269868af0d12f
libxl: fix device removal handling of wait_for_dev_destroy
This patch is a fix for Ian Campbell's "libxl: rationalise libxl_device_* APIs" and addresses the problem of not handling the return value from destroy functions correctly. The return value can represent three different options, the device is removed correctly, the device is busy or and error occurred.
Signed-off-by: Roger Pau Monne <roger.pau@entel.upc.edu>
diff -r c9c228ec718a -r 973022eb35ed tools/libxl/libxl_device.c
--- a/tools/libxl/libxl_device.c Thu Oct 13 10:52:46 2011 +0100
+++ b/tools/libxl/libxl_device.c Tue Oct 18 14:52:30 2011 +0200
@@ -367,6 +367,10 @@ int libxl__device_disk_dev_number(const
return -1;
}
+/*
+ * Returns 0 on succesful device removal, 1 if a timeout
+ * happenned and ERROR_* if there was an error
+ */
static int wait_for_dev_destroy(libxl__gc *gc, struct timeval *tv)
{
libxl_ctx *ctx = libxl__gc_owner(gc);
@@ -375,27 +379,47 @@ static int wait_for_dev_destroy(libxl__g
fd_set rfds;
char **l1 = NULL;
+start:
rc = 1;
nfds = xs_fileno(ctx->xsh) + 1;
FD_ZERO(&rfds);
FD_SET(xs_fileno(ctx->xsh), &rfds);
- if (select(nfds, &rfds, NULL, NULL, tv) > 0) {
- l1 = xs_read_watch(ctx->xsh, &n);
- if (l1 != NULL) {
- char *state = libxl__xs_read(gc, XBT_NULL, l1[XS_WATCH_PATH]);
- if (!state || atoi(state) == 6) {
- xs_unwatch(ctx->xsh, l1[0], l1[1]);
- xs_rm(ctx->xsh, XBT_NULL, l1[XS_WATCH_TOKEN]);
- LIBXL__LOG(ctx, LIBXL__LOG_DEBUG, "Destroyed device backend at %s", l1[XS_WATCH_TOKEN]);
- rc = 0;
+ switch (select(nfds, &rfds, NULL, NULL, tv)) {
+ case -1:
+ if (errno == EINTR)
+ goto start;
+ rc = ERROR_FAIL;
+ break;
+ case 0:
+ rc = 1;
+ break;
+ case 1:
+ l1 = xs_read_watch(ctx->xsh, &n);
+ if (l1 != NULL) {
+ char *state = libxl__xs_read(gc, XBT_NULL,
+ l1[XS_WATCH_PATH]);
+ if (!state || atoi(state) == 6) {
+ xs_unwatch(ctx->xsh, l1[0], l1[1]);
+ xs_rm(ctx->xsh, XBT_NULL, l1[XS_WATCH_TOKEN]);
+ LIBXL__LOG(ctx, LIBXL__LOG_DEBUG,
+ "Destroyed device backend at %s",
+ l1[XS_WATCH_TOKEN]);
+ rc = 0;
+ }
+ free(l1);
+ } else {
+ rc = ERROR_FAIL;
}
- free(l1);
- }
+ break;
}
return rc;
}
-/* Returns 0 on success, ERROR_* on fail */
+/*
+ * Returns 0 on success, ERROR_* on fail and 1 if there's an event
+ * pending (a device has been added to a watch to wait for
+ * disconnection)
+ */
int libxl__device_remove(libxl__gc *gc, libxl__device *dev, int wait)
{
libxl_ctx *ctx = libxl__gc_owner(gc);
@@ -428,16 +452,15 @@ retry_transaction:
xs_watch(ctx->xsh, state_path, be_path);
libxl__device_destroy_tapdisk(gc, be_path);
+ rc = 1;
if (wait) {
struct timeval tv;
tv.tv_sec = LIBXL_DESTROY_TIMEOUT;
tv.tv_usec = 0;
- (void)wait_for_dev_destroy(gc, &tv);
+ rc = wait_for_dev_destroy(gc, &tv);
xs_rm(ctx->xsh, XBT_NULL, libxl__device_frontend_path(gc, dev));
}
-
- rc = 0;
out:
return rc;
}
@@ -496,7 +519,7 @@ int libxl__devices_destroy(libxl__gc *gc
if (force) {
libxl__device_destroy(gc, &dev);
} else {
- if (libxl__device_remove(gc, &dev, 0) == 0)
+ if (libxl__device_remove(gc, &dev, 0) == 1)
n_watches++;
}
}
@@ -515,7 +538,7 @@ int libxl__devices_destroy(libxl__gc *gc
if (force) {
libxl__device_destroy(gc, &dev);
} else {
- if (libxl__device_remove(gc, &dev, 0) == 0)
+ if (libxl__device_remove(gc, &dev, 0) == 1)
n_watches++;
}
}
@@ -531,7 +554,7 @@ int libxl__devices_destroy(libxl__gc *gc
tv.tv_usec = 0;
while (n_watches > 0) {
if (wait_for_dev_destroy(gc, &tv)) {
- break;
+ continue;
} else {
n_watches--;
}
prev parent reply other threads:[~2011-10-18 12:55 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-10-13 9:53 [PATCH 00 of 27 v2] libxl: rationalise libxl_device_* APIs Ian Campbell
2011-10-13 9:53 ` [PATCH 01 of 27 v2] libxl: add missing "break; " to do_pci_remove Ian Campbell
2011-10-13 9:53 ` [PATCH 02 of 27 v2] libxl: remove generated file testidl.c on clean Ian Campbell
2011-10-13 9:53 ` [PATCH 03 of 27 v2] libxl: idl: use "dispose" rather than "destroy" for function to free IDL types Ian Campbell
2011-10-13 11:26 ` Roger Pau Monné
2011-10-13 11:39 ` Ian Campbell
2011-10-13 11:47 ` Roger Pau Monné
2011-10-13 9:53 ` [PATCH 04 of 27 v2] libxl: libxl_destroy_cpumap becomes libxl_cpumap_destroy Ian Campbell
2011-10-13 9:53 ` [PATCH 05 of 27 v2] libxl: add a comment describing the device interfaces Ian Campbell
2011-10-13 9:53 ` [PATCH 06 of 27 v2] libxl: various fixes to libxl_device_disk_list (and internals) Ian Campbell
2011-10-13 9:53 ` [PATCH 07 of 27 v2] libxl: refactor code to construct disk from xenstore backend Ian Campbell
2011-10-13 9:53 ` [PATCH 08 of 27 v2] libxl: do not read f.e. xenstore dir in disk list function Ian Campbell
2011-10-17 14:20 ` Ian Jackson
2011-10-17 14:23 ` Ian Campbell
2011-10-17 14:26 ` Ian Jackson
2011-10-13 9:53 ` [PATCH 09 of 27 v2] libxl: update nic list API to use common device API style Ian Campbell
2011-10-13 9:53 ` [PATCH 10 of 27 v2] libxl: reimplement devid->nic in terms of from_xs_be function Ian Campbell
2011-10-13 9:53 ` [PATCH 11 of 27 v2] libxl: reimplement devid->disk " Ian Campbell
2011-10-13 9:53 ` [PATCH 12 of 27 v2] libxl: libxl_devid_to_* should take an integer device id Ian Campbell
2011-10-13 9:53 ` [PATCH 13 of 27 v2] libxl: separate forced and non-forced device remove Ian Campbell
2011-10-13 9:53 ` [PATCH 14 of 27 v2] libxl: split forced and non-forced uses of libxl__device_del Ian Campbell
2011-10-13 9:53 ` [PATCH 15 of 27 v2] libxl: use IDL to define device front- and back-end kinds Ian Campbell
2011-10-13 9:53 ` [PATCH 16 of 27 v2] libxl: do not remove unidentified frontend paths in libxl__devices_destroy Ian Campbell
2011-10-13 9:53 ` [PATCH 17 of 27 v2] libxl: use libxl__device in libxl_devices_destroy and libxl__device_pci_remove_xenstore Ian Campbell
2011-10-13 9:53 ` [PATCH 18 of 27 v2] libxl: merge libxl__device_del into libxl__device_remove Ian Campbell
2011-10-17 14:34 ` Roger Pau Monné
2011-10-17 14:43 ` Ian Campbell
2011-10-13 9:53 ` [PATCH 19 of 27 v2] libxl: use more descriptive variable names in libxl__devices_destroy Ian Campbell
2011-10-13 9:53 ` [PATCH 20 of 27 v2] libxl: convert disk handling to device API Ian Campbell
2011-10-13 9:53 ` [PATCH 21 of 27 v2] libxl: convert NIC " Ian Campbell
2011-10-13 9:53 ` [PATCH 22 of 27 v2] libxl: remove libxl_device_console_add Ian Campbell
2011-10-13 9:53 ` [PATCH 23 of 27 v2] libxl: convert VKB handling to device API Ian Campbell
2011-10-13 9:53 ` [PATCH 24 of 27 v2] libxl: convert VFB " Ian Campbell
2011-10-13 9:53 ` [PATCH 25 of 27 v2] libxl: reorder device functions to put functions for each device together Ian Campbell
2011-10-13 9:53 ` [PATCH 26 of 27 v2] libxl: convert PCI device handling to device API Ian Campbell
2011-10-13 9:53 ` [PATCH 27 of 27 v2] imported patch libxl-flags-on-ctx-alloc.patch Ian Campbell
2011-10-13 9:55 ` Ian Campbell
2011-10-13 10:44 ` libxl stable API work left (Was: Re: [PATCH 00 of 27 v2] libxl: rationalise libxl_device_* APIs) Ian Campbell
2011-10-18 12:55 ` Roger Pau Monne [this message]
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=973022eb35ed3c2e5898.1318942500@loki \
--to=roger.pau@entel.upc.edu \
--cc=ian.campbell@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 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.