|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH V9 02/12] libxl_device: use async exec script api
use async exec script api to exec device related scripts.
Signed-off-by: Lai Jiangshan <laijs@xxxxxxxxxxxxxx>
Signed-off-by: Wen Congyang <wency@xxxxxxxxxxxxxx>
---
tools/libxl/libxl_device.c | 80 ++++++++++++--------------------------------
tools/libxl/libxl_internal.h | 4 ++-
2 files changed, 25 insertions(+), 59 deletions(-)
diff --git a/tools/libxl/libxl_device.c b/tools/libxl/libxl_device.c
index fa99f77..2e26799 100644
--- a/tools/libxl/libxl_device.c
+++ b/tools/libxl/libxl_device.c
@@ -440,7 +440,7 @@ void libxl__prepare_ao_device(libxl__ao *ao,
libxl__ao_device *aodev)
aodev->active = 1;
/* We init this here because we might call device_hotplug_done
* without actually calling any hotplug script */
- libxl__ev_child_init(&aodev->child);
+ libxl__ev_child_init(&aodev->async_exec.child);
}
/* multidev */
@@ -707,12 +707,7 @@ static void device_backend_cleanup(libxl__gc *gc,
static void device_hotplug(libxl__egc *egc, libxl__ao_device *aodev);
-static void device_hotplug_timeout_cb(libxl__egc *egc, libxl__ev_time *ev,
- const struct timeval *requested_abs);
-
-static void device_hotplug_child_death_cb(libxl__egc *egc,
- libxl__ev_child *child,
- pid_t pid, int status);
+static void device_hotplug_child_death_cb(void *opaque, int status);
static void device_destroy_be_timeout_cb(libxl__egc *egc, libxl__ev_time *ev,
const struct timeval *requested_abs);
@@ -957,7 +952,6 @@ static void device_hotplug(libxl__egc *egc,
libxl__ao_device *aodev)
char **args = NULL, **env = NULL;
int rc = 0;
int hotplug, nullfd = -1;
- pid_t pid;
uint32_t domid;
/*
@@ -1009,15 +1003,6 @@ static void device_hotplug(libxl__egc *egc,
libxl__ao_device *aodev)
goto out;
}
- /* Set hotplug timeout */
- rc = libxl__ev_time_register_rel(gc, &aodev->timeout,
- device_hotplug_timeout_cb,
- LIBXL_HOTPLUG_TIMEOUT * 1000);
- if (rc) {
- LOG(ERROR, "unable to register timeout for hotplug device %s",
be_path);
- goto out;
- }
-
aodev->what = GCSPRINTF("%s %s", args[0], args[1]);
LOG(DEBUG, "calling hotplug script: %s %s", args[0], args[1]);
@@ -1028,23 +1013,24 @@ static void device_hotplug(libxl__egc *egc,
libxl__ao_device *aodev)
goto out;
}
- /* fork and execute hotplug script */
- pid = libxl__ev_child_fork(gc, &aodev->child,
device_hotplug_child_death_cb);
- if (pid == -1) {
- LOG(ERROR, "unable to fork");
- rc = ERROR_FAIL;
+ aodev->egc = egc;
+ aodev->async_exec.env = env;
+ aodev->async_exec.args = args;
+ aodev->async_exec.opaque = aodev;
+ aodev->async_exec.finish_cb = device_hotplug_child_death_cb;
+ aodev->async_exec.timeout = LIBXL_HOTPLUG_TIMEOUT;
+ aodev->async_exec.allow_fail = false;
+ aodev->async_exec.stdinfd = nullfd;
+ aodev->async_exec.stdoutfd = 2;
+ aodev->async_exec.stderrfd = -1;
+ aodev->async_exec.ao = ao;
+
+ rc = libxl_async_exec_script(gc, &aodev->async_exec);
+ if (rc)
goto out;
- }
-
- if (!pid) {
- /* child */
- libxl__exec(gc, nullfd, 2, -1, args[0], args, env);
- /* notreached */
- abort();
- }
close(nullfd);
- assert(libxl__ev_child_inuse(&aodev->child));
+ assert(libxl__ev_child_inuse(&aodev->async_exec.child));
return;
@@ -1055,29 +1041,9 @@ out:
return;
}
-static void device_hotplug_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);
-
- libxl__ev_time_deregister(gc, &aodev->timeout);
-
- assert(libxl__ev_child_inuse(&aodev->child));
- LOG(DEBUG, "killing hotplug script %s because of timeout", aodev->what);
- if (kill(aodev->child.pid, SIGKILL)) {
- LOGEV(ERROR, errno, "unable to kill hotplug script %s [%ld]",
- aodev->what, (unsigned long)aodev->child.pid);
- }
-
- return;
-}
-
-static void device_hotplug_child_death_cb(libxl__egc *egc,
- libxl__ev_child *child,
- pid_t pid, int status)
+static void device_hotplug_child_death_cb(void *opaque, int status)
{
- libxl__ao_device *aodev = CONTAINER_OF(child, *aodev, child);
+ libxl__ao_device *aodev = opaque;
STATE_AO_GC(aodev->ao);
char *be_path = libxl__device_backend_path(gc, aodev->dev);
char *hotplug_error;
@@ -1085,8 +1051,6 @@ static void device_hotplug_child_death_cb(libxl__egc *egc,
device_hotplug_clean(gc, aodev);
if (status) {
- libxl_report_child_exitstatus(CTX, LIBXL__LOG_ERROR,
- aodev->what, pid, status);
hotplug_error = libxl__xs_read(gc, XBT_NULL,
GCSPRINTF("%s/hotplug-error", be_path));
if (hotplug_error)
@@ -1105,13 +1069,13 @@ static void device_hotplug_child_death_cb(libxl__egc
*egc,
* device_hotplug_done breaking the loop.
*/
aodev->num_exec++;
- device_hotplug(egc, aodev);
+ device_hotplug(aodev->egc, aodev);
return;
error:
assert(aodev->rc);
- device_hotplug_done(egc, aodev);
+ device_hotplug_done(aodev->egc, aodev);
}
static void device_destroy_be_timeout_cb(libxl__egc *egc, libxl__ev_time *ev,
@@ -1178,7 +1142,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));
+ assert(!libxl__ev_child_inuse(&aodev->async_exec.child));
}
static void devices_remove_callback(libxl__egc *egc,
diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h
index eddafaf..cc8d558 100644
--- a/tools/libxl/libxl_internal.h
+++ b/tools/libxl/libxl_internal.h
@@ -2094,7 +2094,9 @@ struct libxl__ao_device {
/* device hotplug execution */
const char *what;
int num_exec;
- libxl__ev_child child;
+
+ libxl__egc *egc;
+ libxl_async_exec async_exec;
};
/*
--
1.8.3.2
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |