From: Roger Pau Monne <roger.pau@entel.upc.edu>
To: xen-devel@lists.xensource.com
Subject: [PATCH 19 of 29 RFC] libxl: add libxl__device_hotplug_disconnect
Date: Thu, 02 Feb 2012 14:26:54 +0100 [thread overview]
Message-ID: <937bbe68a1942e22c40a.1328189214@debian.localdomain> (raw)
In-Reply-To: <patchbomb.1328189195@debian.localdomain>
# HG changeset patch
# User Roger Pau Monne <roger.pau@entel.upc.edu>
# Date 1328178627 -3600
# Node ID 937bbe68a1942e22c40aa18c8bb66490aec56945
# Parent 94733bc9cc2fbeaa08a660ec90dcd9c5ad924e1b
libxl: add libxl__device_hotplug_disconnect
Sets the necessary xenstore entries to trigger the unplug of a device,
and waits for the device to react (either by setting the device state
to disconnected or to error).
Signed-off-by: Roger Pau Monne <roger.pau@entel.upc.edu>
diff -r 94733bc9cc2f -r 937bbe68a194 tools/libxl/libxl_device.c
--- a/tools/libxl/libxl_device.c Thu Feb 02 11:27:27 2012 +0100
+++ b/tools/libxl/libxl_device.c Thu Feb 02 11:30:27 2012 +0100
@@ -405,7 +405,7 @@ int libxl__device_disk_dev_number(const
* or timeout occurred.
*/
int libxl__wait_for_device_state(libxl__gc *gc, struct timeval *tv,
- XenbusState state,
+ int state,
libxl__device_state_handler handler)
{
libxl_ctx *ctx = libxl__gc_owner(gc);
@@ -413,6 +413,7 @@ int libxl__wait_for_device_state(libxl__
unsigned int n;
fd_set rfds;
char **l1 = NULL;
+ char *entry;
start:
rc = 1;
@@ -431,6 +432,10 @@ start:
default:
l1 = xs_read_watch(ctx->xsh, &n);
if (l1 != NULL) {
+ entry = strrchr(l1[0], '/');
+ if (!entry || strcmp(entry, "/state"))
+ goto start;
+
char *sstate = libxl__xs_read(gc, XBT_NULL,
l1[XS_WATCH_PATH]);
if (!sstate || atoi(sstate) == state) {
@@ -575,6 +580,71 @@ out:
return rc;
}
+int libxl__device_hotplug_disconnect(libxl__gc *gc, libxl__device *dev,
+ libxl__hotplug_status disconnect_param)
+{
+ libxl_ctx *ctx = libxl__gc_owner(gc);
+ xs_transaction_t t;
+ char *hotplug_path = libxl__device_hotplug_path(gc, dev);
+ char *state_path = libxl__sprintf(gc, "%s/state", hotplug_path);
+ char *state;
+ struct timeval tv;
+ int rc = 0;
+
+retry_transaction:
+ t = xs_transaction_start(ctx->xsh);
+ state = libxl__xs_read(gc, t, state_path);
+ LIBXL__LOG(ctx, LIBXL__LOG_DEBUG, "Disconnecting device with path %s and "
+ "state %s", hotplug_path, state);
+ if (!state) {
+ xs_transaction_end(ctx->xsh, t, 0);
+ goto out;
+ }
+ if (atoi(state) != HOTPLUG_DEVICE_CONNECTED) {
+ xs_transaction_end(ctx->xsh, t, 0);
+ goto out;
+ }
+ libxl__xs_write(gc, t, state_path, "%d", disconnect_param);
+ if (!xs_transaction_end(ctx->xsh, t, 0)) {
+ if (errno == EAGAIN)
+ goto retry_transaction;
+ else {
+ rc = ERROR_FAIL;
+ goto out;
+ }
+ }
+
+ xs_watch(ctx->xsh, state_path, hotplug_path);
+
+ tv.tv_sec = LIBXL_DESTROY_TIMEOUT;
+ tv.tv_usec = 0;
+ rc = libxl__wait_for_device_state(gc, &tv, HOTPLUG_DEVICE_DISCONNECTED,
+ NULL);
+ xs_unwatch(ctx->xsh, state_path, hotplug_path);
+ state = libxl__xs_read(gc, XBT_NULL, state_path);
+ if (!state) {
+ goto out;
+ }
+ if (atoi(state) == HOTPLUG_DEVICE_ERROR) {
+ LIBXL__LOG(ctx, LIBXL__LOG_ERROR,
+ "Error while unplug of "
+ "device with hotplug path %s", hotplug_path);
+ rc = ERROR_FAIL;
+ } else if (rc == ERROR_TIMEDOUT) {
+ LIBXL__LOG(ctx, LIBXL__LOG_DEBUG,
+ "Timeout while waiting for unplug of "
+ "device with hotplug path %s", hotplug_path);
+ } else if (rc == ERROR_FAIL) {
+ LIBXL__LOG(ctx, LIBXL__LOG_ERROR,
+ "failed to destroy device with "
+ "hotplug path %s", hotplug_path);
+ }
+
+out:
+ libxl__xs_path_cleanup(gc, hotplug_path);
+ return rc;
+}
+
int libxl__device_destroy(libxl__gc *gc, libxl__device *dev)
{
char *be_path = libxl__device_backend_path(gc, dev);
diff -r 94733bc9cc2f -r 937bbe68a194 tools/libxl/libxl_internal.h
--- a/tools/libxl/libxl_internal.h Thu Feb 02 11:27:27 2012 +0100
+++ b/tools/libxl/libxl_internal.h Thu Feb 02 11:30:27 2012 +0100
@@ -334,7 +334,7 @@ typedef int libxl__device_state_handler(
* Returns 0 on success, and < 0 on error.
*/
_hidden int libxl__wait_for_device_state(libxl__gc *gc, struct timeval *tv,
- XenbusState state,
+ int state,
libxl__device_state_handler handler);
/*
@@ -366,6 +366,16 @@ typedef enum {
} libxl__hotplug_status;
/*
+ * libxl__device_hotplug_disconnect - disconnect remove device
+ * disconnect_param: action to use when disconnecting the device, either
+ * HOTPLUG_DEVICE_DISCONNECT or HOTPLUG_DEVICE_FORCE_DISCONNECT
+ *
+ * Returns 0 on success, and < 0 on error.
+ */
+_hidden int libxl__device_hotplug_disconnect(libxl__gc *gc, libxl__device *dev,
+ libxl__hotplug_status disconnect_param);
+
+/*
* libxl__device_hotplug - generic function to execute hotplug scripts
* gc: allocation pool
* dev: reference to the device that executes the hotplug scripts
next prev parent reply other threads:[~2012-02-02 13:26 UTC|newest]
Thread overview: 69+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-02-02 13:26 [PATCH 00 of 29 RFC] libxl: move device plug/unplug to a separate daemon Roger Pau Monne
2012-02-02 13:26 ` [PATCH 01 of 29 RFC] libxl: Atomicaly check backend state and set it to 5 at device_remove Roger Pau Monne
2012-02-02 13:26 ` [PATCH 02 of 29 RFC] hotplug/block: get the type of block device from file path (NetBSD) Roger Pau Monne
2012-02-02 13:26 ` [PATCH 03 of 29 RFC] libxl: allow libxl__exec to take a parameter containing the env variables Roger Pau Monne
2012-02-02 13:26 ` [PATCH 04 of 29 RFC] libxl: add libxl__forkexec function to libxl_exec Roger Pau Monne
2012-02-02 13:26 ` [PATCH 05 of 29 RFC] libxl: wait for devices to initialize upon addition to the domain Roger Pau Monne
2012-02-02 13:26 ` [PATCH 06 of 29 RFC] hotplug NetBSD: pass an action instead of a state to hotplug scripts Roger Pau Monne
2012-02-02 13:26 ` [PATCH 07 of 29 RFC] libxl: perform xenstore device cleanup from libxl Roger Pau Monne
2012-02-02 13:26 ` [PATCH 08 of 29 RFC] libxl: remove force parameter from libxl__device_remove Roger Pau Monne
2012-02-02 13:26 ` [PATCH 09 of 29 RFC] libxl: add better error checking on libxl__device_remove Roger Pau Monne
2012-02-02 13:26 ` [PATCH 10 of 29 RFC] libxl: destroy devices before device model Roger Pau Monne
2012-02-02 13:26 ` [PATCH 11 of 29 RFC] libxl: execute hotplug scripts directly from libxl Roger Pau Monne
2012-02-02 13:26 ` [PATCH 12 of 29 RFC] libxl: add hotplug script calling for NetBSD Roger Pau Monne
2012-02-02 13:26 ` [PATCH 13 of 29 RFC] libxl: add hotplug script calls for Linux Roger Pau Monne
2012-02-07 7:02 ` Shriram Rajagopalan
2012-02-07 9:04 ` Roger Pau Monné
2012-02-02 13:26 ` [PATCH 14 of 29 RFC] rc.d NetBSD: don't start xenbackendd by default, only when xend needs it Roger Pau Monne
2012-02-02 13:26 ` [PATCH 15 of 29 RFC] NetBSD/xencommons: remove xend precmd folder creation Roger Pau Monne
2012-02-09 15:34 ` Ian Jackson
2012-02-02 13:26 ` [PATCH 16 of 29 RFC] libxl: introduce libxl__device_hotplug_path Roger Pau Monne
2012-02-02 13:26 ` [PATCH 17 of 29 RFC] libxl: add enum with possible hotplug state Roger Pau Monne
2012-02-02 13:26 ` [PATCH 18 of 29 RFC] libxl: introduce libxl__device_generic_hotplug_add Roger Pau Monne
2012-02-02 13:26 ` Roger Pau Monne [this message]
2012-02-02 13:26 ` [PATCH 20 of 29 RFC] libxl: introduce libxl hotplug public API functions Roger Pau Monne
2012-02-08 16:42 ` Ian Jackson
2012-02-09 10:02 ` Stefano Stabellini
2012-02-09 15:22 ` Ian Jackson
2012-02-09 15:32 ` Stefano Stabellini
2012-02-09 15:33 ` Ian Jackson
2012-02-09 15:43 ` Stefano Stabellini
2012-02-09 15:41 ` Ian Jackson
2012-02-09 15:49 ` Ian Campbell
2012-02-09 16:00 ` Stefano Stabellini
2012-02-09 16:01 ` Ian Campbell
2012-02-09 16:18 ` Stefano Stabellini
2012-02-09 16:40 ` Ian Campbell
2012-02-09 17:28 ` Stefano Stabellini
2012-02-14 14:38 ` Roger Pau Monné
2012-02-14 14:23 ` Roger Pau Monné
2012-02-14 15:48 ` Ian Campbell
2012-02-20 18:52 ` Ian Jackson
2012-02-20 18:55 ` Ian Jackson
2012-02-21 11:04 ` Ian Campbell
2012-02-21 10:38 ` Stefano Stabellini
2012-02-21 16:42 ` Ian Jackson
2012-02-21 17:02 ` Ian Campbell
2012-02-08 16:42 ` Ian Jackson
2012-02-14 14:25 ` Roger Pau Monné
2012-02-02 13:26 ` [PATCH 21 of 29 RFC] libxl: add libxl__parse_hotplug_path Roger Pau Monne
2012-02-02 13:26 ` [PATCH 22 of 29 RFC] libxl: add libxl__parse_disk_hotplug_path Roger Pau Monne
2012-02-02 13:26 ` [PATCH 23 of 29 RFC] libxl: add libxl__parse_nic_hotplug_path Roger Pau Monne
2012-02-08 16:43 ` Ian Jackson
2012-02-02 13:26 ` [PATCH 24 of 29 RFC] libxl: add libxl_setup_hotplug_listener Roger Pau Monne
2012-02-02 13:27 ` [PATCH 25 of 29 RFC] libxl: add libxl_hotplug_dispatch Roger Pau Monne
2012-02-02 18:37 ` Stefano Stabellini
2012-02-02 18:45 ` Roger Pau Monné
2012-02-09 10:03 ` Stefano Stabellini
2012-02-02 13:27 ` [PATCH 26 of 29 RFC] xldeviced: new daemon to execute hotplug scripts Roger Pau Monne
2012-02-02 13:27 ` [PATCH 27 of 29 RFC] init: updated Linux and NetBSD init scripts to launch xldeviced Roger Pau Monne
2012-02-02 13:27 ` [PATCH 28 of 29 RFC] libxl: add libxl__find_free_vdev Roger Pau Monne
2012-02-09 15:40 ` Ian Jackson
2012-02-14 13:36 ` Roger Pau Monné
2012-02-15 17:18 ` Ian Jackson
2012-02-16 8:53 ` Roger Pau Monné
2012-02-02 13:27 ` [PATCH 29 of 29 RFC] libxl: delegate plug/unplug of disk and nic devices to xldeviced Roger Pau Monne
2012-02-09 15:43 ` Ian Jackson
2012-02-14 14:05 ` Roger Pau Monné
2012-02-17 15:45 ` Ian Jackson
2012-02-03 14:06 ` [PATCH 00 of 29 RFC] libxl: move device plug/unplug to a separate 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=937bbe68a1942e22c40a.1328189214@debian.localdomain \
--to=roger.pau@entel.upc.edu \
--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).