* [PATCH 1 of 7] libxl: rename libxl__device_model_starting
2011-10-27 10:03 [PATCH 0 of 7] libxl: make spawn interface more generic Olaf Hering
@ 2011-10-27 10:03 ` Olaf Hering
2011-10-27 10:03 ` [PATCH 2 of 7] libxl: rename dm_xenstore_record_pid to libxl_spawner_record_pid Olaf Hering
` (6 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Olaf Hering @ 2011-10-27 10:03 UTC (permalink / raw)
To: xen-devel
# HG changeset patch
# User Olaf Hering <olaf@aepfle.de>
# Date 1319707156 -7200
# Node ID b709d7fefde93765b386204d9d56e2fe4e7a654f
# Parent c681dd5aecf3da3c6fd0e4d8a760a9cd18617033
libxl: rename libxl__device_model_starting
Signed-off-by: Olaf Hering <olaf@aepfle.de>
diff -r c681dd5aecf3 -r b709d7fefde9 tools/libxl/libxl_create.c
--- a/tools/libxl/libxl_create.c
+++ b/tools/libxl/libxl_create.c
@@ -434,7 +434,7 @@ static int do_domain_create(libxl__gc *g
uint32_t *domid_out, int restore_fd)
{
libxl_ctx *ctx = libxl__gc_owner(gc);
- libxl__device_model_starting *dm_starting = 0;
+ libxl__spawner_starting *dm_starting = 0;
libxl_device_model_info *dm_info = &d_config->dm_info;
libxl__domain_build_state state;
uint32_t domid;
diff -r c681dd5aecf3 -r b709d7fefde9 tools/libxl/libxl_dm.c
--- a/tools/libxl/libxl_dm.c
+++ b/tools/libxl/libxl_dm.c
@@ -518,7 +518,7 @@ static char ** libxl__build_device_model
static void dm_xenstore_record_pid(void *for_spawn, pid_t innerchild)
{
- libxl__device_model_starting *starting = for_spawn;
+ libxl__spawner_starting *starting = for_spawn;
struct xs_handle *xsh;
char *path = NULL, *pid = NULL;
int len;
@@ -619,7 +619,7 @@ static int libxl__create_stubdom(libxl__
libxl_device_nic *vifs, int num_vifs,
libxl_device_vfb *vfb,
libxl_device_vkb *vkb,
- libxl__device_model_starting **starting_r)
+ libxl__spawner_starting **starting_r)
{
libxl_ctx *ctx = libxl__gc_owner(gc);
int i, num_console = STUBDOM_SPECIAL_CONSOLES, ret;
@@ -631,7 +631,7 @@ static int libxl__create_stubdom(libxl__
char **args;
struct xs_permissions perm[2];
xs_transaction_t t;
- libxl__device_model_starting *dm_starting = 0;
+ libxl__spawner_starting *dm_starting = 0;
libxl_device_model_info xenpv_dm_info;
if (info->device_model_version != LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN_TRADITIONAL) {
@@ -784,7 +784,7 @@ retry_transaction:
libxl_domain_unpause(ctx, domid);
if (starting_r) {
- *starting_r = calloc(1, sizeof(libxl__device_model_starting));
+ *starting_r = calloc(1, sizeof(libxl__spawner_starting));
(*starting_r)->domid = info->domid;
(*starting_r)->dom_path = libxl__xs_get_dompath(gc, info->domid);
(*starting_r)->for_spawn = NULL;
@@ -802,14 +802,14 @@ int libxl__create_device_model(libxl__gc
libxl_device_model_info *info,
libxl_device_disk *disks, int num_disks,
libxl_device_nic *vifs, int num_vifs,
- libxl__device_model_starting **starting_r)
+ libxl__spawner_starting **starting_r)
{
libxl_ctx *ctx = libxl__gc_owner(gc);
char *path, *logfile;
int logfile_w, null;
int rc;
char **args;
- libxl__device_model_starting buf_starting, *p;
+ libxl__spawner_starting buf_starting, *p;
xs_transaction_t t;
char *vm_path;
char **pass_stuff;
@@ -861,7 +861,7 @@ int libxl__create_device_model(libxl__gc
if (starting_r) {
rc = ERROR_NOMEM;
- *starting_r = calloc(1, sizeof(libxl__device_model_starting));
+ *starting_r = calloc(1, sizeof(libxl__spawner_starting));
if (!*starting_r)
goto out_close;
p = *starting_r;
@@ -915,7 +915,7 @@ out:
}
static int detach_device_model(libxl__gc *gc,
- libxl__device_model_starting *starting)
+ libxl__spawner_starting *starting)
{
int rc;
rc = libxl__spawn_detach(gc, starting->for_spawn);
@@ -926,7 +926,7 @@ static int detach_device_model(libxl__gc
}
int libxl__confirm_device_model_startup(libxl__gc *gc,
- libxl__device_model_starting *starting)
+ libxl__spawner_starting *starting)
{
int detach;
int problem = libxl__wait_for_device_model(gc, starting->domid, "running",
@@ -1041,7 +1041,7 @@ out:
int libxl__create_xenpv_qemu(libxl__gc *gc, uint32_t domid,
libxl_device_model_info *info,
libxl_device_vfb *vfb,
- libxl__device_model_starting **starting_r)
+ libxl__spawner_starting **starting_r)
{
libxl__build_xenpv_qemu_args(gc, domid, vfb, info);
libxl__create_device_model(gc, info, NULL, 0, NULL, 0, starting_r);
diff -r c681dd5aecf3 -r b709d7fefde9 tools/libxl/libxl_internal.h
--- a/tools/libxl/libxl_internal.h
+++ b/tools/libxl/libxl_internal.h
@@ -279,7 +279,7 @@ typedef struct {
char *dom_path; /* from libxl_malloc, only for dm_xenstore_record_pid */
int domid;
libxl__spawn_starting *for_spawn;
-} libxl__device_model_starting;
+} libxl__spawner_starting;
/* from xl_create */
_hidden int libxl__domain_make(libxl__gc *gc, libxl_domain_create_info *info, uint32_t *domid);
@@ -296,11 +296,11 @@ _hidden int libxl__create_device_model(l
libxl_device_model_info *info,
libxl_device_disk *disk, int num_disks,
libxl_device_nic *vifs, int num_vifs,
- libxl__device_model_starting **starting_r);
+ libxl__spawner_starting **starting_r);
_hidden int libxl__create_xenpv_qemu(libxl__gc *gc, uint32_t domid,
libxl_device_model_info *dm_info,
libxl_device_vfb *vfb,
- libxl__device_model_starting **starting_r);
+ libxl__spawner_starting **starting_r);
_hidden int libxl__need_xenpv_qemu(libxl__gc *gc,
int nr_consoles, libxl_device_console *consoles,
int nr_vfbs, libxl_device_vfb *vfbs,
@@ -309,8 +309,8 @@ _hidden int libxl__need_xenpv_qemu(libxl
* return pass *starting_r (which will be non-0) to
* libxl_confirm_device_model or libxl_detach_device_model. */
_hidden int libxl__confirm_device_model_startup(libxl__gc *gc,
- libxl__device_model_starting *starting);
-_hidden int libxl__detach_device_model(libxl__gc *gc, libxl__device_model_starting *starting);
+ libxl__spawner_starting *starting);
+_hidden int libxl__detach_device_model(libxl__gc *gc, libxl__spawner_starting *starting);
_hidden int libxl__wait_for_device_model(libxl__gc *gc,
uint32_t domid, char *state,
libxl__spawn_starting *spawning,
^ permalink raw reply [flat|nested] 9+ messages in thread* [PATCH 2 of 7] libxl: rename dm_xenstore_record_pid to libxl_spawner_record_pid
2011-10-27 10:03 [PATCH 0 of 7] libxl: make spawn interface more generic Olaf Hering
2011-10-27 10:03 ` [PATCH 1 of 7] libxl: rename libxl__device_model_starting Olaf Hering
@ 2011-10-27 10:03 ` Olaf Hering
2011-10-27 10:03 ` [PATCH 3 of 7] libxl: add pid path to libxl__spawner_starting Olaf Hering
` (5 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Olaf Hering @ 2011-10-27 10:03 UTC (permalink / raw)
To: xen-devel
# HG changeset patch
# User Olaf Hering <olaf@aepfle.de>
# Date 1319707162 -7200
# Node ID 57af937278c5c00944bcaf245dd173e9345cdecc
# Parent b709d7fefde93765b386204d9d56e2fe4e7a654f
libxl: rename dm_xenstore_record_pid to libxl_spawner_record_pid
Signed-off-by: Olaf Hering <olaf@aepfle.de>
diff -r b709d7fefde9 -r 57af937278c5 tools/libxl/libxl_dm.c
--- a/tools/libxl/libxl_dm.c
+++ b/tools/libxl/libxl_dm.c
@@ -516,31 +516,6 @@ static char ** libxl__build_device_model
}
}
-static void dm_xenstore_record_pid(void *for_spawn, pid_t innerchild)
-{
- libxl__spawner_starting *starting = for_spawn;
- struct xs_handle *xsh;
- char *path = NULL, *pid = NULL;
- int len;
-
- if (asprintf(&path, "%s/%s", starting->dom_path, "image/device-model-pid") < 0)
- goto out;
-
- len = asprintf(&pid, "%d", innerchild);
- if (len < 0)
- goto out;
-
- /* we mustn't use the parent's handle in the child */
- xsh = xs_daemon_open();
-
- xs_write(xsh, XBT_NULL, path, pid, len);
-
- xs_daemon_close(xsh);
-out:
- free(path);
- free(pid);
-}
-
static int libxl__vfb_and_vkb_from_device_model_info(libxl__gc *gc,
libxl_device_model_info *info,
libxl_device_vfb *vfb,
@@ -896,7 +871,7 @@ retry_transaction:
}
rc = libxl__spawn_spawn(gc, p->for_spawn, "device model",
- dm_xenstore_record_pid, p);
+ libxl_spawner_record_pid, p);
if (rc < 0)
goto out_close;
if (!rc) { /* inner child */
diff -r b709d7fefde9 -r 57af937278c5 tools/libxl/libxl_exec.c
--- a/tools/libxl/libxl_exec.c
+++ b/tools/libxl/libxl_exec.c
@@ -144,6 +144,31 @@ void libxl_report_child_exitstatus(libxl
}
}
+void libxl_spawner_record_pid(void *for_spawn, pid_t innerchild)
+{
+ libxl__spawner_starting *starting = for_spawn;
+ struct xs_handle *xsh;
+ char *path = NULL, *pid = NULL;
+ int len;
+
+ if (asprintf(&path, "%s/%s", starting->dom_path, "image/device-model-pid") < 0)
+ goto out;
+
+ len = asprintf(&pid, "%d", innerchild);
+ if (len < 0)
+ goto out;
+
+ /* we mustn't use the parent's handle in the child */
+ xsh = xs_daemon_open();
+
+ xs_write(xsh, XBT_NULL, path, pid, len);
+
+ xs_daemon_close(xsh);
+out:
+ free(path);
+ free(pid);
+}
+
static int libxl__set_fd_flag(libxl__gc *gc, int fd, int flag)
{
int flags;
diff -r b709d7fefde9 -r 57af937278c5 tools/libxl/libxl_internal.h
--- a/tools/libxl/libxl_internal.h
+++ b/tools/libxl/libxl_internal.h
@@ -276,7 +276,7 @@ typedef struct {
} libxl__spawn_starting;
typedef struct {
- char *dom_path; /* from libxl_malloc, only for dm_xenstore_record_pid */
+ char *dom_path; /* from libxl_malloc, only for libxl_spawner_record_pid */
int domid;
libxl__spawn_starting *for_spawn;
} libxl__spawner_starting;
@@ -327,6 +327,8 @@ _hidden int libxl__spawn_spawn(libxl__gc
void *hook_data);
_hidden int libxl__destroy_device_model(libxl__gc *gc, uint32_t domid);
+_hidden void libxl_spawner_record_pid(void *for_spawn, pid_t innerchild);
+
/* Logs errors. A copy of "what" is taken. Return values:
* < 0 error, for_spawn need not be detached
* +1 caller is the parent, must call detach on *for_spawn eventually
^ permalink raw reply [flat|nested] 9+ messages in thread* [PATCH 3 of 7] libxl: add pid path to libxl__spawner_starting
2011-10-27 10:03 [PATCH 0 of 7] libxl: make spawn interface more generic Olaf Hering
2011-10-27 10:03 ` [PATCH 1 of 7] libxl: rename libxl__device_model_starting Olaf Hering
2011-10-27 10:03 ` [PATCH 2 of 7] libxl: rename dm_xenstore_record_pid to libxl_spawner_record_pid Olaf Hering
@ 2011-10-27 10:03 ` Olaf Hering
2011-10-27 10:03 ` [PATCH 4 of 7] libxl: add libxl__wait_for_offspring function Olaf Hering
` (4 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Olaf Hering @ 2011-10-27 10:03 UTC (permalink / raw)
To: xen-devel
# HG changeset patch
# User Olaf Hering <olaf@aepfle.de>
# Date 1319707225 -7200
# Node ID 1417042ea4ab7b43fed11535c6d79d88ded644dc
# Parent 57af937278c5c00944bcaf245dd173e9345cdecc
libxl: add pid path to libxl__spawner_starting
libxl_spawner_record_pid() should be able to write the pid to arbitrary paths.
v2:
- use const char* for ->pid_path, and update comment
Signed-off-by: Olaf Hering <olaf@aepfle.de>
diff -r 57af937278c5 -r 1417042ea4ab tools/libxl/libxl_dm.c
--- a/tools/libxl/libxl_dm.c
+++ b/tools/libxl/libxl_dm.c
@@ -848,6 +848,7 @@ int libxl__create_device_model(libxl__gc
p->domid = info->domid;
p->dom_path = libxl__xs_get_dompath(gc, info->domid);
+ p->pid_path = "image/device-model-pid";
if (!p->dom_path) {
rc = ERROR_FAIL;
goto out_close;
diff -r 57af937278c5 -r 1417042ea4ab tools/libxl/libxl_exec.c
--- a/tools/libxl/libxl_exec.c
+++ b/tools/libxl/libxl_exec.c
@@ -151,7 +151,7 @@ void libxl_spawner_record_pid(void *for_
char *path = NULL, *pid = NULL;
int len;
- if (asprintf(&path, "%s/%s", starting->dom_path, "image/device-model-pid") < 0)
+ if (asprintf(&path, "%s/%s", starting->dom_path, starting->pid_path) < 0)
goto out;
len = asprintf(&pid, "%d", innerchild);
diff -r 57af937278c5 -r 1417042ea4ab tools/libxl/libxl_internal.h
--- a/tools/libxl/libxl_internal.h
+++ b/tools/libxl/libxl_internal.h
@@ -277,6 +277,7 @@ typedef struct {
typedef struct {
char *dom_path; /* from libxl_malloc, only for libxl_spawner_record_pid */
+ const char *pid_path; /* only for libxl_spawner_record_pid */
int domid;
libxl__spawn_starting *for_spawn;
} libxl__spawner_starting;
^ permalink raw reply [flat|nested] 9+ messages in thread* [PATCH 4 of 7] libxl: add libxl__wait_for_offspring function
2011-10-27 10:03 [PATCH 0 of 7] libxl: make spawn interface more generic Olaf Hering
` (2 preceding siblings ...)
2011-10-27 10:03 ` [PATCH 3 of 7] libxl: add pid path to libxl__spawner_starting Olaf Hering
@ 2011-10-27 10:03 ` Olaf Hering
2011-10-27 10:03 ` [PATCH 5 of 7] libxl: add libxl__spawn_confirm_offspring_startup Olaf Hering
` (3 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Olaf Hering @ 2011-10-27 10:03 UTC (permalink / raw)
To: xen-devel
# HG changeset patch
# User Olaf Hering <olaf@aepfle.de>
# Date 1319707404 -7200
# Node ID f52460f64b6f58b480d0037a31c20606e9a4ef55
# Parent 1417042ea4ab7b43fed11535c6d79d88ded644dc
libxl: add libxl__wait_for_offspring function
libxl__wait_for_offspring() is a generic version of
libxl__wait_for_device_model().
Use libxl__wait_for_offspring for device model.
Signed-off-by: Olaf Hering <olaf@aepfle.de>
diff -r 1417042ea4ab -r f52460f64b6f tools/libxl/libxl_device.c
--- a/tools/libxl/libxl_device.c
+++ b/tools/libxl/libxl_device.c
@@ -535,88 +535,12 @@ int libxl__wait_for_device_model(libxl__
void *userdata),
void *check_callback_userdata)
{
- libxl_ctx *ctx = libxl__gc_owner(gc);
char *path;
- char *p;
- unsigned int len;
- int rc = 0;
- struct xs_handle *xsh;
- int nfds;
- fd_set rfds;
- struct timeval tv;
- unsigned int num;
- char **l = NULL;
-
- xsh = xs_daemon_open();
- if (xsh == NULL) {
- LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "Unable to open xenstore connection");
- goto err;
- }
-
path = libxl__sprintf(gc, "/local/domain/0/device-model/%d/state", domid);
- xs_watch(xsh, path, path);
- tv.tv_sec = LIBXL_DEVICE_MODEL_START_TIMEOUT;
- tv.tv_usec = 0;
- nfds = xs_fileno(xsh) + 1;
- if (spawning && spawning->fd > xs_fileno(xsh))
- nfds = spawning->fd + 1;
-
- while (rc > 0 || (!rc && tv.tv_sec > 0)) {
- if ( spawning ) {
- rc = libxl__spawn_check(gc, spawning);
- if ( rc ) {
- LIBXL__LOG(ctx, LIBXL__LOG_ERROR,
- "Device Model died during startup");
- rc = -1;
- goto err_died;
- }
- }
- p = xs_read(xsh, XBT_NULL, path, &len);
- if ( NULL == p )
- goto again;
-
- if ( NULL != state && strcmp(p, state) )
- goto again;
-
- if ( NULL != check_callback ) {
- rc = (*check_callback)(gc, domid, p, check_callback_userdata);
- if ( rc > 0 )
- goto again;
- }
-
- free(p);
- xs_unwatch(xsh, path, path);
- xs_daemon_close(xsh);
- return rc;
-again:
- free(p);
- FD_ZERO(&rfds);
- FD_SET(xs_fileno(xsh), &rfds);
- if (spawning)
- FD_SET(spawning->fd, &rfds);
- rc = select(nfds, &rfds, NULL, NULL, &tv);
- if (rc > 0) {
- if (FD_ISSET(xs_fileno(xsh), &rfds)) {
- l = xs_read_watch(xsh, &num);
- if (l != NULL)
- free(l);
- else
- goto again;
- }
- if (spawning && FD_ISSET(spawning->fd, &rfds)) {
- unsigned char dummy;
- if (read(spawning->fd, &dummy, sizeof(dummy)) != 1)
- LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_DEBUG,
- "failed to read spawn status pipe");
- }
- }
- }
- LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "Device Model not ready");
-err_died:
- xs_unwatch(xsh, path, path);
- xs_daemon_close(xsh);
-err:
- return -1;
+ return libxl__wait_for_offspring(gc, domid,
+ LIBXL_DEVICE_MODEL_START_TIMEOUT,
+ "Device Model", path, state, spawning,
+ check_callback, check_callback_userdata);
}
int libxl__wait_for_backend(libxl__gc *gc, char *be_path, char *state)
diff -r 1417042ea4ab -r f52460f64b6f tools/libxl/libxl_exec.c
--- a/tools/libxl/libxl_exec.c
+++ b/tools/libxl/libxl_exec.c
@@ -169,6 +169,99 @@ out:
free(pid);
}
+int libxl__wait_for_offspring(libxl__gc *gc,
+ uint32_t domid,
+ uint32_t timeout, char *what,
+ char *path, char *state,
+ libxl__spawn_starting *spawning,
+ int (*check_callback)(libxl__gc *gc,
+ uint32_t domid,
+ const char *state,
+ void *userdata),
+ void *check_callback_userdata)
+{
+ libxl_ctx *ctx = libxl__gc_owner(gc);
+ char *p;
+ unsigned int len;
+ int rc = 0;
+ struct xs_handle *xsh;
+ int nfds;
+ fd_set rfds;
+ struct timeval tv;
+ unsigned int num;
+ char **l = NULL;
+
+ xsh = xs_daemon_open();
+ if (xsh == NULL) {
+ LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "Unable to open xenstore connection");
+ goto err;
+ }
+
+ xs_watch(xsh, path, path);
+ tv.tv_sec = timeout;
+ tv.tv_usec = 0;
+ nfds = xs_fileno(xsh) + 1;
+ if (spawning && spawning->fd > xs_fileno(xsh))
+ nfds = spawning->fd + 1;
+
+ while (rc > 0 || (!rc && tv.tv_sec > 0)) {
+ if ( spawning ) {
+ rc = libxl__spawn_check(gc, spawning);
+ if ( rc ) {
+ LIBXL__LOG(ctx, LIBXL__LOG_ERROR,
+ "%s died during startup", what);
+ rc = -1;
+ goto err_died;
+ }
+ }
+ p = xs_read(xsh, XBT_NULL, path, &len);
+ if ( NULL == p )
+ goto again;
+
+ if ( NULL != state && strcmp(p, state) )
+ goto again;
+
+ if ( NULL != check_callback ) {
+ rc = (*check_callback)(gc, domid, p, check_callback_userdata);
+ if ( rc > 0 )
+ goto again;
+ }
+
+ free(p);
+ xs_unwatch(xsh, path, path);
+ xs_daemon_close(xsh);
+ return rc;
+again:
+ free(p);
+ FD_ZERO(&rfds);
+ FD_SET(xs_fileno(xsh), &rfds);
+ if (spawning)
+ FD_SET(spawning->fd, &rfds);
+ rc = select(nfds, &rfds, NULL, NULL, &tv);
+ if (rc > 0) {
+ if (FD_ISSET(xs_fileno(xsh), &rfds)) {
+ l = xs_read_watch(xsh, &num);
+ if (l != NULL)
+ free(l);
+ else
+ goto again;
+ }
+ if (spawning && FD_ISSET(spawning->fd, &rfds)) {
+ unsigned char dummy;
+ if (read(spawning->fd, &dummy, sizeof(dummy)) != 1)
+ LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_DEBUG,
+ "failed to read spawn status pipe");
+ }
+ }
+ }
+ LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "%s not ready", what);
+err_died:
+ xs_unwatch(xsh, path, path);
+ xs_daemon_close(xsh);
+err:
+ return -1;
+}
+
static int libxl__set_fd_flag(libxl__gc *gc, int fd, int flag)
{
int flags;
diff -r 1417042ea4ab -r f52460f64b6f tools/libxl/libxl_internal.h
--- a/tools/libxl/libxl_internal.h
+++ b/tools/libxl/libxl_internal.h
@@ -330,6 +330,16 @@ _hidden int libxl__destroy_device_model(
_hidden void libxl_spawner_record_pid(void *for_spawn, pid_t innerchild);
+_hidden int libxl__wait_for_offspring(libxl__gc *gc,
+ uint32_t domid,
+ uint32_t timeout, char *what,
+ char *path, char *state,
+ libxl__spawn_starting *spawning,
+ int (*check_callback)(libxl__gc *gc,
+ uint32_t domid,
+ const char *state,
+ void *userdata),
+ void *check_callback_userdata);
/* Logs errors. A copy of "what" is taken. Return values:
* < 0 error, for_spawn need not be detached
* +1 caller is the parent, must call detach on *for_spawn eventually
@@ -345,7 +355,7 @@ _hidden int libxl__spawn_check(libxl__gc
/* Logs errors but also returns them.
* for_spawn must actually be a libxl__spawn_starting* but
* we take void* so you can pass this function directly to
- * libxl__wait_for_device_model. Caller must still call detach. */
+ * libxl__wait_for_offspring. Caller must still call detach. */
/* low-level stuff, for synchronous subprocesses etc. */
^ permalink raw reply [flat|nested] 9+ messages in thread* [PATCH 5 of 7] libxl: add libxl__spawn_confirm_offspring_startup
2011-10-27 10:03 [PATCH 0 of 7] libxl: make spawn interface more generic Olaf Hering
` (3 preceding siblings ...)
2011-10-27 10:03 ` [PATCH 4 of 7] libxl: add libxl__wait_for_offspring function Olaf Hering
@ 2011-10-27 10:03 ` Olaf Hering
2011-10-27 10:03 ` [PATCH 6 of 7] libxl: document spawn related functions Olaf Hering
` (2 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Olaf Hering @ 2011-10-27 10:03 UTC (permalink / raw)
To: xen-devel
# HG changeset patch
# User Olaf Hering <olaf@aepfle.de>
# Date 1319707409 -7200
# Node ID 9d23f31c576395094233326409058078685850d2
# Parent f52460f64b6f58b480d0037a31c20606e9a4ef55
libxl: add libxl__spawn_confirm_offspring_startup
libxl__spawn_confirm_offspring_startup() is a generic version of
libxl__confirm_device_model_startup().
Use libxl__spawn_confirm_offspring_startup for device model.
Signed-off-by: Olaf Hering <olaf@aepfle.de>
diff -r f52460f64b6f -r 9d23f31c5763 tools/libxl/libxl_dm.c
--- a/tools/libxl/libxl_dm.c
+++ b/tools/libxl/libxl_dm.c
@@ -890,25 +890,16 @@ out:
return rc;
}
-static int detach_device_model(libxl__gc *gc,
- libxl__spawner_starting *starting)
-{
- int rc;
- rc = libxl__spawn_detach(gc, starting->for_spawn);
- if (starting->for_spawn)
- free(starting->for_spawn);
- free(starting);
- return rc;
-}
int libxl__confirm_device_model_startup(libxl__gc *gc,
libxl__spawner_starting *starting)
{
- int detach;
- int problem = libxl__wait_for_device_model(gc, starting->domid, "running",
- starting->for_spawn, NULL, NULL);
- detach = detach_device_model(gc, starting);
- return problem ? problem : detach;
+ char *path;
+ int domid = starting->domid;
+ path = libxl__sprintf(gc, "/local/domain/0/device-model/%d/state", domid);
+ return libxl__spawn_confirm_offspring_startup(gc,
+ LIBXL_DEVICE_MODEL_START_TIMEOUT,
+ "Device Model", path, "running", starting);
}
int libxl__destroy_device_model(libxl__gc *gc, uint32_t domid)
diff -r f52460f64b6f -r 9d23f31c5763 tools/libxl/libxl_exec.c
--- a/tools/libxl/libxl_exec.c
+++ b/tools/libxl/libxl_exec.c
@@ -262,6 +262,30 @@ err:
return -1;
}
+static int detach_offspring(libxl__gc *gc,
+ libxl__spawner_starting *starting)
+{
+ int rc;
+ rc = libxl__spawn_detach(gc, starting->for_spawn);
+ if (starting->for_spawn)
+ free(starting->for_spawn);
+ free(starting);
+ return rc;
+}
+
+int libxl__spawn_confirm_offspring_startup(libxl__gc *gc,
+ uint32_t timeout, char *what,
+ char *path, char *state,
+ libxl__spawner_starting *starting)
+{
+ int detach;
+ int problem = libxl__wait_for_offspring(gc, starting->domid, timeout, what,
+ path, state,
+ starting->for_spawn, NULL, NULL);
+ detach = detach_offspring(gc, starting);
+ return problem ? problem : detach;
+}
+
static int libxl__set_fd_flag(libxl__gc *gc, int fd, int flag)
{
int flags;
diff -r f52460f64b6f -r 9d23f31c5763 tools/libxl/libxl_internal.h
--- a/tools/libxl/libxl_internal.h
+++ b/tools/libxl/libxl_internal.h
@@ -340,6 +340,12 @@ _hidden int libxl__wait_for_offspring(li
const char *state,
void *userdata),
void *check_callback_userdata);
+
+_hidden int libxl__spawn_confirm_offspring_startup(libxl__gc *gc,
+ uint32_t timeout, char *what,
+ char *path, char *state,
+ libxl__spawner_starting *starting);
+
/* Logs errors. A copy of "what" is taken. Return values:
* < 0 error, for_spawn need not be detached
* +1 caller is the parent, must call detach on *for_spawn eventually
^ permalink raw reply [flat|nested] 9+ messages in thread* [PATCH 6 of 7] libxl: document spawn related functions
2011-10-27 10:03 [PATCH 0 of 7] libxl: make spawn interface more generic Olaf Hering
` (4 preceding siblings ...)
2011-10-27 10:03 ` [PATCH 5 of 7] libxl: add libxl__spawn_confirm_offspring_startup Olaf Hering
@ 2011-10-27 10:03 ` Olaf Hering
2011-10-27 10:03 ` [PATCH 7 of 7] libxl: update prototype of libxl__spawn_check Olaf Hering
2011-11-02 15:41 ` [PATCH 0 of 7] libxl: make spawn interface more generic Ian Jackson
7 siblings, 0 replies; 9+ messages in thread
From: Olaf Hering @ 2011-10-27 10:03 UTC (permalink / raw)
To: xen-devel
# HG changeset patch
# User Olaf Hering <olaf@aepfle.de>
# Date 1319708351 -7200
# Node ID 2423017c7ba57c9e0d91a061c4a28c06cee00d08
# Parent 9d23f31c576395094233326409058078685850d2
libxl: document spawn related functions
Group spawn related prototypes and add some documentation.
Remove unused prototype for libxl__log_child_exitstatus
Signed-off-by: Olaf Hering <olaf@aepfle.de>
diff -r 9d23f31c5763 -r 2423017c7ba5 tools/libxl/libxl_internal.h
--- a/tools/libxl/libxl_internal.h
+++ b/tools/libxl/libxl_internal.h
@@ -282,6 +282,121 @@ typedef struct {
libxl__spawn_starting *for_spawn;
} libxl__spawner_starting;
+/*
+ * libxl__spawn_spawn - Create a new process
+ * gc: allocation pool
+ * for_spawn: malloc'd pointer to libxl__spawn_starting (optional)
+ * what: string describing the spawned process
+ * intermediate_hook: helper to record pid, such as libxl_spawner_record_pid
+ * hook_data: data to pass to the hook function
+ *
+ * Logs errors. A copy of "what" is taken.
+ * Return values:
+ * < 0 error, for_spawn need not be detached
+ * +1 caller is the parent, must call detach on *for_spawn eventually
+ * 0 caller is now the inner child, should probably call libxl__exec
+ * Caller, may pass 0 for for_spawn, in which case no need to detach.
+ */
+_hidden int libxl__spawn_spawn(libxl__gc *gc,
+ libxl__spawn_starting *for_spawn,
+ const char *what,
+ void (*intermediate_hook)(void *for_spawn, pid_t innerchild),
+ void *hook_data);
+
+/*
+ * libxl_spawner_record_pid - Record given pid in xenstore
+ * for_spawn: malloc'd pointer to libxl__spawn_starting (optional)
+ * innerchild: pid of the child
+ *
+ * This function is passed as intermediate_hook to libxl__spawn_spawn.
+ */
+_hidden void libxl_spawner_record_pid(void *for_spawn, pid_t innerchild);
+
+/*
+ * libxl__spawn_confirm_offspring_startup - Wait for child state
+ * gc: allocation pool
+ * timeout: how many seconds to wait for the child
+ * what: string describing the spawned process
+ * path: path to the state file in xenstore
+ * state: expected string to wait for in path (optional)
+ * starting: malloc'd pointer to libxl__spawner_starting
+ *
+ * Returns 0 on success, and < 0 on error.
+ *
+ * This function waits the given timeout for the given path to appear
+ * in xenstore, and optionally for state in path.
+ * The intermediate process created in libxl__spawn_spawn is killed.
+ * The memory referenced by starting->for_spawn and starting is free'd.
+ */
+_hidden int libxl__spawn_confirm_offspring_startup(libxl__gc *gc,
+ uint32_t timeout, char *what,
+ char *path, char *state,
+ libxl__spawner_starting *starting);
+
+/*
+ * libxl__wait_for_offspring - Wait for child state
+ * gc: allocation pool
+ * domid: guest to work with
+ * timeout: how many seconds to wait for the state to appear
+ * what: string describing the spawned process
+ * path: path to the state file in xenstore
+ * state: expected string to wait for in path (optional)
+ * spawning: malloc'd pointer to libxl__spawn_starting (optional)
+ * check_callback: (optional)
+ * check_callback_userdata: data to pass to the callback function
+ *
+ * Returns 0 on success, and < 0 on error.
+ *
+ * This function waits the given timeout for the given path to appear
+ * in xenstore, and optionally for state in path.
+ * If path appears and state matches, check_callback is called.
+ * If check_callback returns > 0, waiting for path or state continues.
+ * Otherwise libxl__wait_for_offspring returns.
+ */
+_hidden int libxl__wait_for_offspring(libxl__gc *gc,
+ uint32_t domid,
+ uint32_t timeout, char *what,
+ char *path, char *state,
+ libxl__spawn_starting *spawning,
+ int (*check_callback)(libxl__gc *gc,
+ uint32_t domid,
+ const char *state,
+ void *userdata),
+ void *check_callback_userdata);
+
+/*
+ * libxl__spawn_detach - Kill intermediate process from spawn_spawn
+ * gc: allocation pool
+ * for_spawn: malloc'd pointer to libxl__spawn_starting (optional)
+ *
+ * Returns 0 on success, and < 0 on error.
+ *
+ * Logs errors. Idempotent, but only permitted after successful
+ * call to libxl__spawn_spawn, and no point calling it again if it fails.
+ */
+_hidden int libxl__spawn_detach(libxl__gc *gc,
+ libxl__spawn_starting *for_spawn);
+
+/*
+ * libxl__spawn_check - Check intermediate child process
+ * gc: allocation pool
+ * for_spawn: malloc'd pointer to libxl__spawn_starting (optional)
+ *
+ * Returns 0 on success, and < 0 on error.
+ *
+ * Logs errors but also returns them.
+ * for_spawn must actually be a libxl__spawn_starting* but
+ * we take void* so you can pass this function directly to
+ * libxl__wait_for_offspring. Caller must still call detach.
+ */
+_hidden int libxl__spawn_check(libxl__gc *gc,
+ void *for_spawn);
+
+ /* low-level stuff, for synchronous subprocesses etc. */
+
+_hidden void libxl__exec(int stdinfd, int stdoutfd, int stderrfd,
+ const char *arg0, char **args); // logs errors, never returns
+
/* from xl_create */
_hidden int libxl__domain_make(libxl__gc *gc, libxl_domain_create_info *info, uint32_t *domid);
_hidden int libxl__domain_build(libxl__gc *gc,
@@ -308,7 +423,7 @@ _hidden int libxl__need_xenpv_qemu(libxl
int nr_disks, libxl_device_disk *disks);
/* Caller must either: pass starting_r==0, or on successful
* return pass *starting_r (which will be non-0) to
- * libxl_confirm_device_model or libxl_detach_device_model. */
+ * libxl__confirm_device_model_startup or libxl__detach_device_model. */
_hidden int libxl__confirm_device_model_startup(libxl__gc *gc,
libxl__spawner_starting *starting);
_hidden int libxl__detach_device_model(libxl__gc *gc, libxl__spawner_starting *starting);
@@ -321,55 +436,8 @@ _hidden int libxl__wait_for_device_model
void *userdata),
void *check_callback_userdata);
-_hidden int libxl__spawn_spawn(libxl__gc *gc,
- libxl__spawn_starting *starting,
- const char *what,
- void (*intermediate_hook)(void *for_spawn, pid_t innerchild),
- void *hook_data);
_hidden int libxl__destroy_device_model(libxl__gc *gc, uint32_t domid);
-_hidden void libxl_spawner_record_pid(void *for_spawn, pid_t innerchild);
-
-_hidden int libxl__wait_for_offspring(libxl__gc *gc,
- uint32_t domid,
- uint32_t timeout, char *what,
- char *path, char *state,
- libxl__spawn_starting *spawning,
- int (*check_callback)(libxl__gc *gc,
- uint32_t domid,
- const char *state,
- void *userdata),
- void *check_callback_userdata);
-
-_hidden int libxl__spawn_confirm_offspring_startup(libxl__gc *gc,
- uint32_t timeout, char *what,
- char *path, char *state,
- libxl__spawner_starting *starting);
-
- /* Logs errors. A copy of "what" is taken. Return values:
- * < 0 error, for_spawn need not be detached
- * +1 caller is the parent, must call detach on *for_spawn eventually
- * 0 caller is now the inner child, should probably call libxl__exec
- * Caller, may pass 0 for for_spawn, in which case no need to detach.
- */
-_hidden int libxl__spawn_detach(libxl__gc *gc,
- libxl__spawn_starting *for_spawn);
- /* Logs errors. Idempotent, but only permitted after successful
- * call to libxl__spawn_spawn, and no point calling it again if it fails. */
-_hidden int libxl__spawn_check(libxl__gc *gc,
- void *for_spawn);
- /* Logs errors but also returns them.
- * for_spawn must actually be a libxl__spawn_starting* but
- * we take void* so you can pass this function directly to
- * libxl__wait_for_offspring. Caller must still call detach. */
-
- /* low-level stuff, for synchronous subprocesses etc. */
-
-_hidden void libxl__exec(int stdinfd, int stdoutfd, int stderrfd,
- const char *arg0, char **args); // logs errors, never returns
-_hidden void libxl__log_child_exitstatus(libxl__gc *gc,
- const char *what, pid_t pid, int status);
-
_hidden char *libxl__abs_path(libxl__gc *gc, const char *s, const char *path);
#define LIBXL__LOG_DEBUG XTL_DEBUG
^ permalink raw reply [flat|nested] 9+ messages in thread* [PATCH 7 of 7] libxl: update prototype of libxl__spawn_check
2011-10-27 10:03 [PATCH 0 of 7] libxl: make spawn interface more generic Olaf Hering
` (5 preceding siblings ...)
2011-10-27 10:03 ` [PATCH 6 of 7] libxl: document spawn related functions Olaf Hering
@ 2011-10-27 10:03 ` Olaf Hering
2011-11-02 15:41 ` [PATCH 0 of 7] libxl: make spawn interface more generic Ian Jackson
7 siblings, 0 replies; 9+ messages in thread
From: Olaf Hering @ 2011-10-27 10:03 UTC (permalink / raw)
To: xen-devel
# HG changeset patch
# User Olaf Hering <olaf@aepfle.de>
# Date 1319709256 -7200
# Node ID 2679263d65681e1e9f260bc1683eac1fa4ce2b66
# Parent 2423017c7ba57c9e0d91a061c4a28c06cee00d08
libxl: update prototype of libxl__spawn_check
libxl__spawn_check expects a malloc'd libxl__spawn_starting. The
currently only user of libxl__spawn_check gets a libxl__spawn_starting
and passes it on. Update prototype to not take a void pointer, and also
update comment in header file.
Signed-off-by: Olaf Hering <olaf@aepfle.de>
diff -r 2423017c7ba5 -r 2679263d6568 tools/libxl/libxl_exec.c
--- a/tools/libxl/libxl_exec.c
+++ b/tools/libxl/libxl_exec.c
@@ -431,10 +431,9 @@ int libxl__spawn_detach(libxl__gc *gc,
return rc;
}
-int libxl__spawn_check(libxl__gc *gc, void *for_spawn_void)
+int libxl__spawn_check(libxl__gc *gc, libxl__spawn_starting *for_spawn)
{
libxl_ctx *ctx = libxl__gc_owner(gc);
- libxl__spawn_starting *for_spawn = for_spawn_void;
pid_t got;
int status;
diff -r 2423017c7ba5 -r 2679263d6568 tools/libxl/libxl_internal.h
--- a/tools/libxl/libxl_internal.h
+++ b/tools/libxl/libxl_internal.h
@@ -385,12 +385,10 @@ _hidden int libxl__spawn_detach(libxl__g
* Returns 0 on success, and < 0 on error.
*
* Logs errors but also returns them.
- * for_spawn must actually be a libxl__spawn_starting* but
- * we take void* so you can pass this function directly to
- * libxl__wait_for_offspring. Caller must still call detach.
+ * Caller must still call detach.
*/
_hidden int libxl__spawn_check(libxl__gc *gc,
- void *for_spawn);
+ libxl__spawn_starting *for_spawn);
/* low-level stuff, for synchronous subprocesses etc. */
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: [PATCH 0 of 7] libxl: make spawn interface more generic
2011-10-27 10:03 [PATCH 0 of 7] libxl: make spawn interface more generic Olaf Hering
` (6 preceding siblings ...)
2011-10-27 10:03 ` [PATCH 7 of 7] libxl: update prototype of libxl__spawn_check Olaf Hering
@ 2011-11-02 15:41 ` Ian Jackson
7 siblings, 0 replies; 9+ messages in thread
From: Ian Jackson @ 2011-11-02 15:41 UTC (permalink / raw)
To: Olaf Hering; +Cc: xen-devel
Olaf Hering writes ("[Xen-devel] [PATCH 0 of 7] libxl: make spawn interface more generic"):
> The following series makes the libxl spawn interface more generic, so that it
> can be used for device model and xenpaging. The functions move from dm.c to
> exec.c. Some documentation about the interface is added as well.
>
> Please review and apply.
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
Committed-by: Ian Jackson <ian.jackson@eu.citrix.com>
For all seven, thanks.
Ian.
^ permalink raw reply [flat|nested] 9+ messages in thread