From: Roger Pau Monne <roger.pau@citrix.com>
To: xen-devel@lists.xenproject.org
Cc: Ian Jackson <Ian.Jackson@eu.citrix.com>,
Ian Campbell <ian.campbell@citrix.com>,
Roger Pau Monne <roger.pau@citrix.com>
Subject: [PATCH v3 3/9] libxl: synchronize device removal when using driver domains
Date: Mon, 18 Nov 2013 15:56:25 +0100 [thread overview]
Message-ID: <1384786591-3020-4-git-send-email-roger.pau@citrix.com> (raw)
In-Reply-To: <1384786591-3020-1-git-send-email-roger.pau@citrix.com>
Synchronize the clean up of the backend from the toolstack domain when
the driver domain has actually finished closing the backend for the
device.
This is accomplished by waiting for the driver domain to remove the
directory containing the backend keys, then the toolstack domain will
finish the cleanup by removing the empty folders on the backend path.
Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
Cc: Ian Jackson <Ian.Jackson@eu.citrix.com>
Cc: Ian Campbell <ian.campbell@citrix.com>
---
Changes since v1:
* Place cleanup of aodev events in device_hotplug_clean, get rid of
some code duplication.
Changes since RFC:
* This patch has been reworked to synchronize the toolstack and the
driver domain, by making the driver domain only remove the first
directory of the backend path, and the toolstack domain remove the
rest.
---
tools/libxl/libxl_device.c | 80 ++++++++++++++++++++++++++++++++++++++++-
tools/libxl/libxl_internal.h | 2 +
2 files changed, 80 insertions(+), 2 deletions(-)
diff --git a/tools/libxl/libxl_device.c b/tools/libxl/libxl_device.c
index d5f23cf..b7168d4 100644
--- a/tools/libxl/libxl_device.c
+++ b/tools/libxl/libxl_device.c
@@ -432,6 +432,11 @@ void libxl__prepare_ao_device(libxl__ao *ao, libxl__ao_device *aodev)
aodev->num_exec = 0;
/* Initialize timer for QEMU Bodge and hotplug execution */
libxl__ev_time_init(&aodev->timeout);
+ /*
+ * Initialize xs_watch, because it's not used on all possible
+ * execution paths, but it's unconditionally destroyed when finished.
+ */
+ libxl__ev_xswatch_init(&aodev->xs_watch);
aodev->active = 1;
/* We init this here because we might call device_hotplug_done
* without actually calling any hotplug script */
@@ -709,6 +714,14 @@ static void device_hotplug_child_death_cb(libxl__egc *egc,
libxl__ev_child *child,
pid_t pid, int status);
+static void device_destroy_be_timeout_cb(libxl__egc *egc, libxl__ev_time *ev,
+ const struct timeval *requested_abs);
+
+static void device_destroy_be_watch_cb(libxl__egc *egc,
+ libxl__ev_xswatch *watch,
+ const char *watch_path,
+ const char *event_path);
+
static void device_hotplug_done(libxl__egc *egc, libxl__ao_device *aodev);
static void device_hotplug_clean(libxl__gc *gc, libxl__ao_device *aodev);
@@ -768,6 +781,7 @@ void libxl__initiate_device_remove(libxl__egc *egc,
LOG(ERROR, "unable to get info for domain %d", domid);
goto out;
}
+
if (QEMU_BACKEND(aodev->dev) &&
(info.paused || info.dying || info.shutdown)) {
/*
@@ -919,8 +933,28 @@ static void device_hotplug(libxl__egc *egc, libxl__ao_device *aodev)
*/
rc = libxl__get_domid(gc, &domid);
if (rc) goto out;
- if (aodev->dev->backend_domid != domid)
- goto out;
+ if (aodev->dev->backend_domid != domid) {
+ if (aodev->action != LIBXL__DEVICE_ACTION_REMOVE)
+ goto out;
+
+ rc = libxl__ev_time_register_rel(gc, &aodev->timeout,
+ device_destroy_be_timeout_cb,
+ LIBXL_DESTROY_TIMEOUT * 1000);
+ if (rc) {
+ LOG(ERROR, "setup of xs watch timeout failed");
+ goto out;
+ }
+
+ rc = libxl__ev_xswatch_register(gc, &aodev->xs_watch,
+ device_destroy_be_watch_cb,
+ be_path);
+ if (rc) {
+ LOG(ERROR, "setup of xs watch for %s failed", be_path);
+ libxl__ev_time_deregister(gc, &aodev->timeout);
+ goto out;
+ }
+ return;
+ }
/* Check if we have to execute hotplug scripts for this device
* and return the necessary args/env vars for execution */
@@ -1038,6 +1072,47 @@ error:
device_hotplug_done(egc, aodev);
}
+static void device_destroy_be_timeout_cb(libxl__egc *egc, libxl__ev_time *ev,
+ const struct timeval *requested_abs)
+{
+ libxl__ao_device *aodev = CONTAINER_OF(ev, *aodev, timeout);
+ STATE_AO_GC(aodev->ao);
+
+ LOG(ERROR, "timed out while waiting for %s to be removed",
+ libxl__device_backend_path(gc, aodev->dev));
+
+ aodev->rc = ERROR_TIMEDOUT;
+
+ device_hotplug_done(egc, aodev);
+ return;
+}
+
+static void device_destroy_be_watch_cb(libxl__egc *egc,
+ libxl__ev_xswatch *watch,
+ const char *watch_path,
+ const char *event_path)
+{
+ libxl__ao_device *aodev = CONTAINER_OF(watch, *aodev, xs_watch);
+ STATE_AO_GC(aodev->ao);
+ const char *dir;
+ int rc;
+
+ rc = libxl__xs_read_checked(gc, XBT_NULL, watch_path, &dir);
+ if (rc) {
+ LOG(ERROR, "unable to read backend path: %s", watch_path);
+ aodev->rc = rc;
+ goto out;
+ }
+ if (dir) {
+ /* backend path still exists, wait a little longer... */
+ return;
+ }
+
+out:
+ /* We are done, backend path no longer exists */
+ device_hotplug_done(egc, aodev);
+}
+
static void device_hotplug_done(libxl__egc *egc, libxl__ao_device *aodev)
{
STATE_AO_GC(aodev->ao);
@@ -1060,6 +1135,7 @@ static void device_hotplug_clean(libxl__gc *gc, libxl__ao_device *aodev)
{
/* Clean events and check reentrancy */
libxl__ev_time_deregister(gc, &aodev->timeout);
+ libxl__ev_xswatch_deregister(gc, &aodev->xs_watch);
assert(!libxl__ev_child_inuse(&aodev->child));
}
diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h
index 23ff265..e3b9fb4 100644
--- a/tools/libxl/libxl_internal.h
+++ b/tools/libxl/libxl_internal.h
@@ -1928,6 +1928,8 @@ struct libxl__ao_device {
libxl__ev_devstate backend_ds;
/* Bodge for Qemu devices, also used for timeout of hotplug execution */
libxl__ev_time timeout;
+ /* xenstore watch for backend path of driver domains */
+ libxl__ev_xswatch xs_watch;
/* device hotplug execution */
const char *what;
int num_exec;
--
1.7.7.5 (Apple Git-26)
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel
next prev parent reply other threads:[~2013-11-18 14:56 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-11-18 14:56 [PATCH v3 00/9] libxl: add driver domain backend daemon Roger Pau Monne
2013-11-18 14:56 ` [PATCH v3 1/9] libxl: create a local xenstore libxl and device-model dir for guests Roger Pau Monne
2013-11-18 14:56 ` [PATCH v3 2/9] libxl: don't remove device frontend path from driver domains Roger Pau Monne
2013-11-18 14:56 ` Roger Pau Monne [this message]
2013-11-18 14:56 ` [PATCH v3 4/9] libxl: remove the Qemu bodge for driver domain devices Roger Pau Monne
2013-11-18 14:56 ` [PATCH v3 5/9] libxl: don't launch Qemu on Dom0 for Qdisk devices on driver domains Roger Pau Monne
2013-11-18 14:56 ` [PATCH v3 6/9] libxl: add Qdisk backend launch helper Roger Pau Monne
2013-11-18 15:20 ` Ian Jackson
2013-11-18 15:26 ` Ian Jackson
2013-11-18 15:36 ` [PATCH v4 " Roger Pau Monne
2013-11-18 15:59 ` Ian Jackson
2013-11-18 17:24 ` [PATCH v3 6/9] libxl: add Qdisk backend launch helper [and 1 more messages] Ian Jackson
2013-11-18 17:44 ` [PATCH v3 6/9] libxl: add Qdisk backend launch helper Anthony PERARD
2013-11-18 17:46 ` Ian Jackson
2013-11-18 18:12 ` Roger Pau Monné
2013-11-18 14:56 ` [PATCH v3 7/9] xl: put daemonize code in it's own function Roger Pau Monne
2013-11-18 14:56 ` [PATCH v3 8/9] libxl: revert 326a7b74 Roger Pau Monne
2013-11-18 14:56 ` [PATCH v3 9/9] libxl: add device backend listener in order to launch backends Roger Pau Monne
2013-11-18 15:00 ` [PATCH v3 00/9] libxl: add driver domain backend daemon Roger Pau Monné
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=1384786591-3020-4-git-send-email-roger.pau@citrix.com \
--to=roger.pau@citrix.com \
--cc=Ian.Jackson@eu.citrix.com \
--cc=ian.campbell@citrix.com \
--cc=xen-devel@lists.xenproject.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).