From: Roger Pau Monne <roger.pau@entel.upc.edu>
To: xen-devel@lists.xensource.com
Subject: [PATCH 5 of 9] libxl: wait for devices to initialize upon addition to the domain
Date: Fri, 14 Oct 2011 15:35:37 +0200 [thread overview]
Message-ID: <d14479efe33c3955dcf4.1318599337@loki> (raw)
In-Reply-To: <patchbomb.1318599332@loki>
# HG changeset patch
# User Roger Pau Monne <roger.pau@entel.upc.edu>
# Date 1318592310 -7200
# Node ID d14479efe33c3955dcf41783a1b02c8d2bb572e6
# Parent 0235e192a519e29ac3d77e91fe59b38e6a6f06ef
libxl: wait for devices to initialize upon addition to the domain.
Block waiting for devices to initialize (switch to state 2).
Signed-off-by: Roger Pau Monne <roger.pau@entel.upc.edu>
diff -r 0235e192a519 -r d14479efe33c tools/libxl/libxl.c
--- a/tools/libxl/libxl.c Fri Oct 14 13:38:30 2011 +0200
+++ b/tools/libxl/libxl.c Fri Oct 14 13:38:30 2011 +0200
@@ -1070,6 +1070,11 @@ int libxl_device_disk_add(libxl_ctx *ctx
libxl__xs_kvs_of_flexarray(&gc, back, back->count),
libxl__xs_kvs_of_flexarray(&gc, front, front->count));
+ if (libxl__wait_for_device_initialization(&gc, &device) < 0) {
+ rc = -1;
+ goto out_free;
+ }
+
rc = 0;
out_free:
@@ -1513,7 +1518,11 @@ int libxl_device_nic_add(libxl_ctx *ctx,
libxl__xs_kvs_of_flexarray(&gc, back, back->count),
libxl__xs_kvs_of_flexarray(&gc, front, front->count));
- /* FIXME: wait for plug */
+ if (libxl__wait_for_device_initialization(&gc, &device) < 0) {
+ rc = -1;
+ goto out_free;
+ }
+
rc = 0;
out_free:
flexarray_free(back);
diff -r 0235e192a519 -r d14479efe33c tools/libxl/libxl_device.c
--- a/tools/libxl/libxl_device.c Fri Oct 14 13:38:30 2011 +0200
+++ b/tools/libxl/libxl_device.c Fri Oct 14 13:38:30 2011 +0200
@@ -366,6 +366,38 @@ int libxl__device_disk_dev_number(const
return -1;
}
+int libxl__wait_for_device_initialization(libxl__gc *gc, libxl__device *device)
+{
+ libxl_ctx *ctx = libxl__gc_owner(gc);
+ char *be_path = libxl__device_backend_path(gc, device);
+ char *state_path = libxl__sprintf(gc, "%s/state", be_path);
+ char *state = libxl__xs_read(gc, XBT_NULL, state_path);
+ int rc = -1;
+ char **l1 = NULL;
+ unsigned int n;
+
+ if (atoi(state) == 2) {
+ rc = 0;
+ goto out;
+ }
+
+ xs_watch(ctx->xsh, state_path, be_path);
+ while (atoi(state) != 2) {
+ l1 = xs_read_watch(ctx->xsh, &n);
+ if (l1 == NULL) {
+ goto out;
+ }
+ state = libxl__xs_read(gc, XBT_NULL, l1[XS_WATCH_PATH]);
+ if (state == NULL) {
+ goto out;
+ }
+ }
+ rc = 0;
+
+out:
+ return rc;
+}
+
static int wait_for_dev_destroy(libxl__gc *gc, struct timeval *tv)
{
libxl_ctx *ctx = libxl__gc_owner(gc);
diff -r 0235e192a519 -r d14479efe33c tools/libxl/libxl_internal.h
--- a/tools/libxl/libxl_internal.h Fri Oct 14 13:38:30 2011 +0200
+++ b/tools/libxl/libxl_internal.h Fri Oct 14 13:38:30 2011 +0200
@@ -231,7 +231,7 @@ _hidden int libxl__device_disk_set_backe
_hidden int libxl__device_physdisk_major_minor(const char *physpath, int *major, int *minor);
_hidden int libxl__device_disk_dev_number(const char *virtpath,
int *pdisk, int *ppartition);
-
+_hidden int libxl__wait_for_device_initialization(libxl__gc *gc, libxl__device *device);
_hidden int libxl__device_console_add(libxl__gc *gc, uint32_t domid,
libxl_device_console *console,
libxl__domain_build_state *state);
next prev parent reply other threads:[~2011-10-14 13:35 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-10-14 13:35 [PATCH 0 of 9] Call hotplug scripts from libxl for NetBSD Roger Pau Monne
2011-10-14 13:35 ` [PATCH 1 of 9] xenbackendd: pass type of block device to hotplug script Roger Pau Monne
2011-10-14 13:35 ` [PATCH 2 of 9] libxl: fix for libxl not waiting for devices to disconnect Roger Pau Monne
2011-10-14 13:35 ` [PATCH 3 of 9] libxl: add support for image files for NetBSD Roger Pau Monne
2011-10-14 13:35 ` [PATCH 4 of 9] libxl: add libxl__forkexec to execute hotplug scripts Roger Pau Monne
2011-10-14 13:35 ` Roger Pau Monne [this message]
2011-10-14 13:35 ` [PATCH 6 of 9] libxl: execute hotplug scripts directly from libxl Roger Pau Monne
2011-10-14 13:35 ` [PATCH 7 of 9] hotplug NetBSD: detach devices when state is 5 or 6 Roger Pau Monne
2011-10-14 13:35 ` [PATCH 8 of 9] hotplug: remove debug messages from NetBSD hotplug scripts Roger Pau Monne
2011-10-14 13:35 ` [PATCH 9 of 9] rc.d NetBSD: don't start xenbackendd by default, only when xend needs it Roger Pau Monne
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=d14479efe33c3955dcf4.1318599337@loki \
--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 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.