|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH v8 11/11] (lib)xl: soft reset support
Use existing create/restore path to perform 'soft reset' for HVM domains.
Tear everything down, e.g. destroy domain's device model, remove the domain
from xenstore, save toolstack record and start over.
Signed-off-by: Vitaly Kuznetsov <vkuznets@xxxxxxxxxx>
---
Changes since 'v7'
- 'Reset everything approach': XEN_DOMCTL_soft_reset doesn't destroy the
original domain any more.
- libxl__domain_soft_reset_state introduced [Ian Campbell]
- Separate do_domain_soft_reset to not intertwine with do_domain_create
[Ian Campbell]
Signed-off-by: Vitaly Kuznetsov <vkuznets@xxxxxxxxxx>
---
docs/man/xl.cfg.pod.5 | 10 +++
tools/libxl/libxl.c | 16 +++-
tools/libxl/libxl.h | 12 +++
tools/libxl/libxl_create.c | 181 +++++++++++++++++++++++++++++++++++++------
tools/libxl/libxl_internal.h | 4 +
tools/libxl/libxl_types.idl | 3 +
tools/libxl/xl.h | 1 +
tools/libxl/xl_cmdimpl.c | 33 +++++++-
8 files changed, 232 insertions(+), 28 deletions(-)
diff --git a/docs/man/xl.cfg.pod.5 b/docs/man/xl.cfg.pod.5
index a3e0e2e..27f4c2a 100644
--- a/docs/man/xl.cfg.pod.5
+++ b/docs/man/xl.cfg.pod.5
@@ -368,6 +368,11 @@ destroy the domain.
write a "coredump" of the domain to F</var/lib/xen/dump/NAME> and then
restart the domain.
+=item B<soft-reset>
+
+cleanup the domain without destroying it, restart the device model. This action
+is supported for HVM guests only.
+
=back
The default for C<on_poweroff> is C<destroy>.
@@ -386,6 +391,11 @@ Default is C<destroy>.
Action to take if the domain crashes. Default is C<destroy>.
+=item B<on_soft_reset="ACTION">
+
+Action to take if the domain performs 'soft reset' (e.g. does kexec).
+Default is C<soft-reset>.
+
=back
=head3 Direct Kernel Boot
diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c
index d86ea62..a6743a7 100644
--- a/tools/libxl/libxl.c
+++ b/tools/libxl/libxl.c
@@ -1492,6 +1492,7 @@ void libxl__domain_destroy(libxl__egc *egc,
libxl__domain_destroy_state *dds)
dds->stubdom.ao = ao;
dds->stubdom.domid = stubdomid;
dds->stubdom.callback = stubdom_destroy_callback;
+ dds->stubdom.soft_reset = false;
libxl__destroy_domid(egc, &dds->stubdom);
} else {
dds->stubdom_finished = 1;
@@ -1500,6 +1501,7 @@ void libxl__domain_destroy(libxl__egc *egc,
libxl__domain_destroy_state *dds)
dds->domain.ao = ao;
dds->domain.domid = dds->domid;
dds->domain.callback = domain_destroy_callback;
+ dds->domain.soft_reset = dds->soft_reset;
libxl__destroy_domid(egc, &dds->domain);
}
@@ -1680,10 +1682,13 @@ static void devices_destroy_cb(libxl__egc *egc,
/* Clean up qemu-save and qemu-resume files. They are
* intermediate files created by libxc. Unfortunately they
- * don't fit in existing userdata scheme very well.
+ * don't fit in existing userdata scheme very well. In soft reset
+ * case we need to keep the file.
*/
- rc = libxl__remove_file(gc, libxl__device_model_savefile(gc, domid));
- if (rc < 0) goto out;
+ if (!dis->soft_reset) {
+ rc = libxl__remove_file(gc, libxl__device_model_savefile(gc, domid));
+ if (rc < 0) goto out;
+ }
rc = libxl__remove_file(gc,
GCSPRINTF(XC_DEVICE_MODEL_RESTORE_FILE".%u", domid));
if (rc < 0) goto out;
@@ -1694,7 +1699,10 @@ static void devices_destroy_cb(libxl__egc *egc,
ctx->xch = xc_interface_open(ctx->lg,0,0);
if (!ctx->xch) goto badchild;
- rc = xc_domain_destroy(ctx->xch, domid);
+ if (!dis->soft_reset)
+ rc = xc_domain_destroy(ctx->xch, domid);
+ else
+ rc = xc_domain_soft_reset(ctx->xch, domid);
if (rc < 0) goto badchild;
_exit(0);
diff --git a/tools/libxl/libxl.h b/tools/libxl/libxl.h
index 0a7913b..2006fd6f 100644
--- a/tools/libxl/libxl.h
+++ b/tools/libxl/libxl.h
@@ -200,6 +200,13 @@
#define LIBXL_HAVE_DEVICETREE_PASSTHROUGH 1
/*
+ * LIBXL_HAVE_SOFT_RESET indicates that libxl supports performing 'soft reset'
+ * for domains and there is 'soft_reset' shutdown reason in enum
+ * libxl_shutdown_reason.
+ */
+#define LIBXL_HAVE_SOFT_RESET 1
+
+/*
* libxl ABI compatibility
*
* The only guarantee which libxl makes regarding ABI compatibility
@@ -1012,6 +1019,11 @@ int static inline libxl_domain_create_restore_0x040200(
#endif
+int libxl_domain_soft_reset(libxl_ctx *ctx, libxl_domain_config *d_config,
+ uint32_t domid, const libxl_asyncop_how *ao_how,
+ const libxl_asyncprogress_how *aop_console_how)
+ LIBXL_EXTERNAL_CALLERS_ONLY;
+
/* A progress report will be made via ao_console_how, of type
* domain_create_console_available, when the domain's primary
* console is available and can be connected to.
diff --git a/tools/libxl/libxl_create.c b/tools/libxl/libxl_create.c
index 86384d2..7b8dcf5 100644
--- a/tools/libxl/libxl_create.c
+++ b/tools/libxl/libxl_create.c
@@ -536,8 +536,6 @@ int libxl__domain_make(libxl__gc *gc, libxl_domain_config
*d_config,
/* convenience aliases */
libxl_domain_create_info *info = &d_config->c_info;
- assert(!libxl_domid_valid_guest(*domid));
-
uuid_string = libxl__uuid2string(gc, info->uuid);
if (!uuid_string) {
rc = ERROR_NOMEM;
@@ -558,7 +556,6 @@ int libxl__domain_make(libxl__gc *gc, libxl_domain_config
*d_config,
}
flags |= XEN_DOMCTL_CDF_hap;
}
- *domid = -1;
/* Ultimately, handle is an array of 16 uint8_t, same as uuid */
libxl_uuid_copy(ctx, (libxl_uuid *)handle, &info->uuid);
@@ -570,13 +567,16 @@ int libxl__domain_make(libxl__gc *gc, libxl_domain_config
*d_config,
goto out;
}
- ret = xc_domain_create_config(ctx->xch, info->ssidref,
- handle, flags, domid,
- xc_config);
- if (ret < 0) {
- LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "domain creation fail");
- rc = ERROR_FAIL;
- goto out;
+ /* Valid domid here means we're soft resetting */
+ if (!libxl_domid_valid_guest(*domid)) {
+ ret = xc_domain_create_config(ctx->xch, info->ssidref,
+ handle, flags, domid,
+ xc_config);
+ if (ret < 0) {
+ LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "domain creation fail");
+ rc = ERROR_FAIL;
+ goto out;
+ }
}
ret = xc_cpupool_movedomain(ctx->xch, info->poolid, *domid);
@@ -809,9 +809,8 @@ static void initiate_domain_create(libxl__egc *egc,
libxl_domain_config *const d_config = dcs->guest_config;
libxl__domain_build_state *const state = &dcs->build_state;
const int restore_fd = dcs->restore_fd;
- memset(&dcs->build_state, 0, sizeof(dcs->build_state));
- domid = 0;
+ domid = dcs->domid_soft_reset;
if (d_config->c_info.ssid_label) {
char *s = d_config->c_info.ssid_label;
@@ -953,7 +952,7 @@ static void initiate_domain_create(libxl__egc *egc,
d_config->nics[i].devid = ++last_devid;
}
- if (restore_fd >= 0) {
+ if (restore_fd >= 0 || dcs->domid_soft_reset != INVALID_DOMID) {
LOG(DEBUG, "restoring, not running bootloader");
domcreate_bootloader_done(egc, &dcs->bl, 0);
} else {
@@ -1027,7 +1026,7 @@ static void domcreate_bootloader_done(libxl__egc *egc,
dcs->dmss.dm.callback = domcreate_devmodel_started;
dcs->dmss.callback = domcreate_devmodel_started;
- if ( restore_fd < 0 ) {
+ if ( restore_fd < 0 && dcs->domid_soft_reset == INVALID_DOMID) {
rc = libxl__domain_build(gc, d_config, domid, state);
domcreate_rebuild_done(egc, dcs, rc);
return;
@@ -1057,9 +1056,11 @@ static void domcreate_bootloader_done(libxl__egc *egc,
rc = ERROR_INVAL;
goto out;
}
- libxl__xc_domain_restore(egc, dcs,
- hvm, pae, superpages);
- return;
+ if ( restore_fd >= 0 ) {
+ libxl__xc_domain_restore(egc, dcs,
+ hvm, pae, superpages);
+ return;
+ }
out:
libxl__xc_domain_restore_done(egc, dcs, rc, 0, 0);
@@ -1143,8 +1144,12 @@ void libxl__xc_domain_restore_done(libxl__egc *egc, void
*dcs_void,
goto out;
if (info->type == LIBXL_DOMAIN_TYPE_HVM) {
- state->saved_state = GCSPRINTF(
- XC_DEVICE_MODEL_RESTORE_FILE".%d", domid);
+ if (fd != -1)
+ state->saved_state = GCSPRINTF(
+ XC_DEVICE_MODEL_RESTORE_FILE".%d", domid);
+ else
+ state->saved_state = GCSPRINTF(
+ XC_DEVICE_MODEL_SAVE_FILE".%d", domid);
}
out:
@@ -1153,9 +1158,12 @@ out:
libxl__file_reference_unmap(&state->pv_ramdisk);
}
- esave = errno;
- libxl_fd_set_nonblock(ctx, fd, 0);
- errno = esave;
+ /* fd == -1 here means we're doing soft reset */
+ if (fd != -1) {
+ esave = errno;
+ libxl_fd_set_nonblock(ctx, fd, 0);
+ errno = esave;
+ }
domcreate_rebuild_done(egc, dcs, ret);
}
@@ -1572,6 +1580,14 @@ typedef struct {
uint32_t *domid_out;
} libxl__app_domain_create_state;
+typedef struct {
+ libxl__app_domain_create_state cdcs;
+ libxl__domain_destroy_state dds;
+ libxl__domain_suspend_state dss;
+ uint8_t *toolstack_buf;
+ uint32_t toolstack_len;
+} libxl__domain_soft_reset_state;
+
static void domain_create_cb(libxl__egc *egc,
libxl__domain_create_state *dcs,
int rc, uint32_t domid);
@@ -1593,6 +1609,7 @@ static int do_domain_create(libxl_ctx *ctx,
libxl_domain_config *d_config,
cdcs->dcs.restore_fd = restore_fd;
cdcs->dcs.callback = domain_create_cb;
cdcs->dcs.checkpointed_stream = checkpointed_stream;
+ cdcs->dcs.domid_soft_reset = INVALID_DOMID;
libxl__ao_progress_gethow(&cdcs->dcs.aop_console_how, aop_console_how);
cdcs->domid_out = domid;
@@ -1601,6 +1618,115 @@ static int do_domain_create(libxl_ctx *ctx,
libxl_domain_config *d_config,
return AO_INPROGRESS;
}
+static void domain_soft_reset_cb(libxl__egc *egc,
+ libxl__domain_destroy_state *dds,
+ int rc)
+{
+ STATE_AO_GC(dds->ao);
+ libxl__domain_soft_reset_state *srs = CONTAINER_OF(dds, *srs, dds);
+ libxl__app_domain_create_state *cdcs = &srs->cdcs;
+
+ if (rc) {
+ LOG(ERROR, "destruction of domain %u failed", dds->domid);
+ goto error;
+ }
+
+ rc = libxl__toolstack_restore(cdcs->dcs.domid_soft_reset,
+ srs->toolstack_buf, srs->toolstack_len,
+ &cdcs->dcs.shs);
+ if (rc) {
+ LOG(ERROR, "failed to restore toolstack record");
+ goto error;
+ }
+
+ initiate_domain_create(egc, &cdcs->dcs);
+ return;
+
+error:
+ domcreate_complete(egc, &cdcs->dcs, rc);
+}
+
+static int do_domain_soft_reset(libxl_ctx *ctx, libxl_domain_config *d_config,
+ uint32_t domid_soft_reset,
+ const libxl_asyncop_how *ao_how,
+ const libxl_asyncprogress_how *aop_console_how)
+{
+ AO_CREATE(ctx, 0, ao_how);
+ libxl__domain_soft_reset_state *srs;
+ libxl__app_domain_create_state *cdcs;
+ libxl__domain_create_state *dcs;
+ libxl__domain_build_state *state;
+ libxl__domain_suspend_state *dss;
+ char *dom_path, *xs_store_mfn, *xs_console_mfn;
+ uint32_t domid_out;
+ int rc;
+
+ GCNEW(srs);
+ cdcs = &srs->cdcs;
+ dcs = &cdcs->dcs;
+ state = &dcs->build_state;
+ dss = &srs->dss;
+
+ srs->cdcs.dcs.ao = ao;
+ srs->cdcs.dcs.guest_config = d_config;
+ libxl_domain_config_init(&srs->cdcs.dcs.guest_config_saved);
+ libxl_domain_config_copy(ctx, &srs->cdcs.dcs.guest_config_saved, d_config);
+ cdcs->dcs.restore_fd = -1;
+ cdcs->dcs.domid_soft_reset = domid_soft_reset;
+ cdcs->dcs.callback = domain_create_cb;
+ libxl__ao_progress_gethow(&srs->cdcs.dcs.aop_console_how, aop_console_how);
+ cdcs->domid_out = &domid_out;
+
+ dom_path = libxl__xs_get_dompath(gc, domid_soft_reset);
+ if (!dom_path) {
+ LOG(ERROR, "failed to read domain path");
+ return AO_ABORT(ERROR_FAIL);
+ }
+
+ xs_store_mfn = xs_read(ctx->xsh, XBT_NULL,
+ GCSPRINTF("%s/store/ring-ref", dom_path), NULL);
+ state->store_mfn = xs_store_mfn ? atol(xs_store_mfn): 0;
+ free(xs_store_mfn);
+
+ xs_console_mfn = xs_read(ctx->xsh, XBT_NULL,
+ GCSPRINTF("%s/console/ring-ref", dom_path), NULL);
+ state->console_mfn = xs_console_mfn ? atol(xs_console_mfn): 0;
+ free(xs_console_mfn);
+
+ dss->ao = ao;
+ dss->domid = domid_soft_reset;
+ dss->dm_savefile = GCSPRINTF(XC_DEVICE_MODEL_SAVE_FILE".%d",
+ domid_soft_reset);
+
+ rc = libxl__toolstack_save(domid_soft_reset, &srs->toolstack_buf,
+ &srs->toolstack_len, dss);
+ if (rc) {
+ LOG(ERROR, "failed to save toolstack record");
+ return AO_ABORT(ERROR_FAIL);
+ }
+
+ rc = libxl__domain_suspend_device_model(gc, dss);
+ if (rc) {
+ LOG(ERROR, "failed to suspend device model");
+ return AO_ABORT(ERROR_FAIL);
+ }
+
+ /*
+ * On the domain creation path it will be introduced to xenstore with
+ * (probably) different store/console channels so we need to release
+ * it here.
+ */
+ xs_release_domain(ctx->xsh, cdcs->dcs.domid_soft_reset);
+
+ srs->dds.ao = ao;
+ srs->dds.domid = domid_soft_reset;
+ srs->dds.callback = domain_soft_reset_cb;
+ srs->dds.soft_reset = true;
+ libxl__domain_destroy(egc, &srs->dds);
+
+ return AO_INPROGRESS;
+}
+
static void domain_create_cb(libxl__egc *egc,
libxl__domain_create_state *dcs,
int rc, uint32_t domid)
@@ -1633,6 +1759,17 @@ int libxl_domain_create_restore(libxl_ctx *ctx,
libxl_domain_config *d_config,
params->checkpointed_stream, ao_how,
aop_console_how);
}
+int libxl_domain_soft_reset(libxl_ctx *ctx, libxl_domain_config *d_config,
+ uint32_t domid, const libxl_asyncop_how *ao_how,
+ const libxl_asyncprogress_how *aop_console_how)
+{
+ libxl_domain_build_info *const info = &d_config->b_info;
+
+ if (info->type != LIBXL_DOMAIN_TYPE_HVM) return ERROR_INVAL;
+
+ return do_domain_soft_reset(ctx, d_config, domid, ao_how, aop_console_how);
+}
+
/*
* Local variables:
* mode: C
diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h
index e96d6b5..212e007 100644
--- a/tools/libxl/libxl_internal.h
+++ b/tools/libxl/libxl_internal.h
@@ -106,6 +106,7 @@
#define TAP_DEVICE_SUFFIX "-emu"
#define DISABLE_UDEV_PATH "libxl/disable_udev"
#define DOMID_XS_PATH "domid"
+#define INVALID_DOMID ~0
#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
@@ -3008,6 +3009,7 @@ struct libxl__destroy_domid_state {
/* private to implementation */
libxl__devices_remove_state drs;
libxl__ev_child destroyer;
+ bool soft_reset;
};
struct libxl__domain_destroy_state {
@@ -3022,6 +3024,7 @@ struct libxl__domain_destroy_state {
int stubdom_finished;
libxl__destroy_domid_state domain;
int domain_finished;
+ bool soft_reset;
};
/*
@@ -3122,6 +3125,7 @@ struct libxl__domain_create_state {
libxl_domain_config *guest_config;
libxl_domain_config guest_config_saved; /* vanilla config */
int restore_fd;
+ uint32_t domid_soft_reset;
libxl__domain_create_cb *callback;
libxl_asyncprogress_how aop_console_how;
/* private to domain_create */
diff --git a/tools/libxl/libxl_types.idl b/tools/libxl/libxl_types.idl
index 9001f65..953d098 100644
--- a/tools/libxl/libxl_types.idl
+++ b/tools/libxl/libxl_types.idl
@@ -123,6 +123,8 @@ libxl_action_on_shutdown =
Enumeration("action_on_shutdown", [
(5, "COREDUMP_DESTROY"),
(6, "COREDUMP_RESTART"),
+
+ (7, "SOFT_RESET"),
], init_val = "LIBXL_ACTION_ON_SHUTDOWN_DESTROY")
libxl_trigger = Enumeration("trigger", [
@@ -584,6 +586,7 @@ libxl_domain_config = Struct("domain_config", [
("on_reboot", libxl_action_on_shutdown),
("on_watchdog", libxl_action_on_shutdown),
("on_crash", libxl_action_on_shutdown),
+ ("on_soft_reset", libxl_action_on_shutdown),
], dir=DIR_IN)
libxl_diskinfo = Struct("diskinfo", [
diff --git a/tools/libxl/xl.h b/tools/libxl/xl.h
index 374680c..5771b4c 100644
--- a/tools/libxl/xl.h
+++ b/tools/libxl/xl.h
@@ -190,6 +190,7 @@ typedef enum {
DOMAIN_RESTART_NONE = 0, /* No domain restart */
DOMAIN_RESTART_NORMAL, /* Domain should be restarted */
DOMAIN_RESTART_RENAME, /* Domain should be renamed and restarted */
+ DOMAIN_RESTART_SOFT_RESET, /* Soft reset should be performed */
} domain_restart_type;
extern void printf_info_sexp(int domid, libxl_domain_config *d_config, FILE
*fh);
diff --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c
index 32217fa..0c25a4e 100644
--- a/tools/libxl/xl_cmdimpl.c
+++ b/tools/libxl/xl_cmdimpl.c
@@ -130,6 +130,8 @@ static const char *action_on_shutdown_names[] = {
[LIBXL_ACTION_ON_SHUTDOWN_COREDUMP_DESTROY] = "coredump-destroy",
[LIBXL_ACTION_ON_SHUTDOWN_COREDUMP_RESTART] = "coredump-restart",
+
+ [LIBXL_ACTION_ON_SHUTDOWN_SOFT_RESET] = "soft-reset",
};
/* Optional data, in order:
@@ -1329,6 +1331,13 @@ static void parse_config_data(const char *config_source,
exit(1);
}
+ if (xlu_cfg_get_string (config, "on_soft_reset", &buf, 0))
+ buf = "soft-reset";
+ if (!parse_action_on_shutdown(buf, &d_config->on_soft_reset)) {
+ fprintf(stderr, "Unknown on_soft_reset action \"%s\" specified\n",
buf);
+ exit(1);
+ }
+
/* libxl_get_required_shadow_memory() must be called after final values
* (default or specified) for vcpus and memory are set, because the
* calculation depends on those values. */
@@ -2307,6 +2316,9 @@ static domain_restart_type handle_domain_death(uint32_t
*r_domid,
case LIBXL_SHUTDOWN_REASON_WATCHDOG:
action = d_config->on_watchdog;
break;
+ case LIBXL_SHUTDOWN_REASON_SOFT_RESET:
+ action = d_config->on_soft_reset;
+ break;
default:
LOG("Unknown shutdown reason code %d. Destroying domain.",
event->u.domain_shutdown.shutdown_reason);
@@ -2357,6 +2369,11 @@ static domain_restart_type handle_domain_death(uint32_t
*r_domid,
*r_domid = INVALID_DOMID;
break;
+ case LIBXL_ACTION_ON_SHUTDOWN_SOFT_RESET:
+ reload_domain_config(*r_domid, d_config);
+ restart = DOMAIN_RESTART_SOFT_RESET;
+ break;
+
case LIBXL_ACTION_ON_SHUTDOWN_COREDUMP_DESTROY:
case LIBXL_ACTION_ON_SHUTDOWN_COREDUMP_RESTART:
/* Already handled these above. */
@@ -2532,6 +2549,7 @@ static uint32_t create_domain(struct domain_create
*dom_info)
int restore_fd = -1;
const libxl_asyncprogress_how *autoconnect_console_how;
struct save_file_header hdr;
+ uint32_t domid_soft_reset = INVALID_DOMID;
int restoring = (restore_file || (migrate_fd >= 0));
@@ -2732,7 +2750,13 @@ start:
* restore/migrate-receive it again.
*/
restoring = 0;
- }else{
+ } else if ( domid_soft_reset != INVALID_DOMID ) {
+ /* Do soft reset */
+ ret = libxl_domain_soft_reset(ctx, &d_config, domid_soft_reset,
+ 0, autoconnect_console_how);
+ domid = domid_soft_reset;
+ domid_soft_reset = INVALID_DOMID;
+ } else {
ret = libxl_domain_create_new(ctx, &d_config, &domid,
0, autoconnect_console_how);
}
@@ -2796,8 +2820,13 @@ start:
event->u.domain_shutdown.shutdown_reason,
event->u.domain_shutdown.shutdown_reason);
switch (handle_domain_death(&domid, event, &d_config)) {
+ case DOMAIN_RESTART_SOFT_RESET:
+ domid_soft_reset = domid;
+ domid = INVALID_DOMID;
+ /* fall through */
case DOMAIN_RESTART_RENAME:
- if (!preserve_domain(&domid, event, &d_config)) {
+ if (domid_soft_reset == INVALID_DOMID &&
+ !preserve_domain(&domid, event, &d_config)) {
/* If we fail then exit leaving the old domain in place. */
ret = -1;
goto out;
--
2.4.2
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |