[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [RFC PATCH 04/17] libxl: Build the domain with a Linux based stubdomain
From: Eric Shelton <eshelton@xxxxxxxxx> This will build a Linux-based stubdomain with QEMU upstream. Signed-off-by: Eric Shelton <eshelton@xxxxxxxxx> Simon: * use initramfs instead of disk with rootfs * don't initialize qmp (unused in Qubes) * Make libxl_domain_need_memory consistent with actual stubdoma build code (bugfix relevant also for non-linux case) * Make stubdomain memory size configurable Signed-off-by: Simon Gaiser <simon@xxxxxxxxxxxxxxxxxxxxxx> Marek: * Make kernel and ramdisk paths configurable. Signed-off-by: Marek Marczykowski-Górecki <marmarek@xxxxxxxxxxxxxxxxxxxxxx> --- tools/libxl/libxl_create.c | 75 +++++++++++++++++++++++++++---------- tools/libxl/libxl_dm.c | 48 ++++++++++++++++++------ tools/libxl/libxl_internal.c | 22 +++++++++++- tools/libxl/libxl_internal.h | 4 ++- tools/libxl/libxl_mem.c | 6 ++- tools/libxl/libxl_types.idl | 3 +- 6 files changed, 126 insertions(+), 32 deletions(-) diff --git a/tools/libxl/libxl_create.c b/tools/libxl/libxl_create.c index 9f5e6b7..fff1f9c 100644 --- a/tools/libxl/libxl_create.c +++ b/tools/libxl/libxl_create.c @@ -162,32 +162,54 @@ int libxl__domain_build_info_setdefault(libxl__gc *gc, libxl_defbool_val(b_info->device_model_stubdomain)) { if (!b_info->stubdomain_version) { switch (b_info->device_model_version) { + case LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN_TRADITIONAL: + b_info->stubdomain_version = LIBXL_STUBDOMAIN_VERSION_MINIOS; + break; + case LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN: + b_info->stubdomain_version = LIBXL_STUBDOMAIN_VERSION_LINUX; + break; + default: abort(); + } + } + + switch (b_info->device_model_version) { case LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN_TRADITIONAL: - b_info->stubdomain_version = LIBXL_STUBDOMAIN_VERSION_MINIOS; + if (b_info->stubdomain_version != LIBXL_STUBDOMAIN_VERSION_MINIOS) { + LOG(ERROR, + "\"qemu-xen-traditional\" require \"minios\" as stubdomain"); + return ERROR_INVAL; + } break; case LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN: - b_info->stubdomain_version = LIBXL_STUBDOMAIN_VERSION_LINUX; + if (b_info->stubdomain_version != LIBXL_STUBDOMAIN_VERSION_LINUX) { + LOG(ERROR, + "\"qemu-xen\" require \"linux\" as stubdomain"); + return ERROR_INVAL; + } break; default: abort(); - } } - switch (b_info->device_model_version) { - case LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN_TRADITIONAL: - if (b_info->stubdomain_version != LIBXL_STUBDOMAIN_VERSION_MINIOS) { - LOG(ERROR, - "\"qemu-xen-traditional\" require \"minios\" as stubdomain"); - return ERROR_INVAL; + if (!b_info->stubdomain_kernel) { + switch (b_info->stubdomain_version) { + case LIBXL_STUBDOMAIN_VERSION_MINIOS: + b_info->stubdomain_kernel = + libxl__abs_path(NOGC, "ioemu-stubdom.gz", libxl__xenfirmwaredir_path()); + b_info->stubdomain_ramdisk = NULL; + break; + case LIBXL_STUBDOMAIN_VERSION_LINUX: + b_info->stubdomain_kernel = + libxl__abs_path(NOGC, + "stubdom-linux-kernel", + libxl__xenfirmwaredir_path()); + b_info->stubdomain_ramdisk = + libxl__abs_path(NOGC, + "stubdom-linux-rootfs", + libxl__xenfirmwaredir_path()); + break; + default: + abort(); } - break; - case LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN: - if (b_info->stubdomain_version != LIBXL_STUBDOMAIN_VERSION_LINUX) { - LOG(ERROR, - "\"qemu-xen\" require \"linux\" as stubdomain"); - return ERROR_INVAL; - } - break; - default: abort(); } } @@ -226,6 +248,19 @@ int libxl__domain_build_info_setdefault(libxl__gc *gc, if (b_info->target_memkb == LIBXL_MEMKB_DEFAULT) b_info->target_memkb = b_info->max_memkb; + if (b_info->stubdomain_memkb == LIBXL_MEMKB_DEFAULT) { + switch (b_info->stubdomain_version) { + case LIBXL_STUBDOMAIN_VERSION_MINIOS: + b_info->stubdomain_memkb = 28 * 1024; + break; + case LIBXL_STUBDOMAIN_VERSION_LINUX: + b_info->stubdomain_memkb = LIBXL_LINUX_STUBDOM_MEM * 1024;; + break; + default: + b_info->stubdomain_memkb = 0; // no stubdomain + } + } + libxl_defbool_setdefault(&b_info->claim_mode, false); libxl_defbool_setdefault(&b_info->localtime, false); @@ -1591,7 +1626,9 @@ static void domcreate_devmodel_started(libxl__egc *egc, if (dcs->sdss.dm.guest_domid) { if (d_config->b_info.device_model_version == LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN) { - libxl__qmp_initializations(gc, domid, d_config); + if (!libxl_defbool_val(d_config->b_info.device_model_stubdomain)) { + libxl__qmp_initializations(gc, domid, d_config); + } } } diff --git a/tools/libxl/libxl_dm.c b/tools/libxl/libxl_dm.c index b38c1d2..7828444 100644 --- a/tools/libxl/libxl_dm.c +++ b/tools/libxl/libxl_dm.c @@ -1880,6 +1880,16 @@ retry_transaction: return 0; } +static int libxl__store_libxl_entry(libxl__gc *gc, uint32_t domid, + const char *name, const char *value) +{ + char *path = NULL; + + path = libxl__xs_libxl_path(gc, domid); + path = libxl__sprintf(gc, "%s/%s", path, name); + return libxl__xs_printf(gc, XBT_NULL, path, "%s", value); +} + static void spawn_stubdom_pvqemu_cb(libxl__egc *egc, libxl__dm_spawn_state *stubdom_dmss, int rc); @@ -1917,10 +1927,14 @@ void libxl__spawn_stub_dm(libxl__egc *egc, libxl__stub_dm_spawn_state *sdss) libxl__domain_build_state *const d_state = sdss->dm.build_state; libxl__domain_build_state *const stubdom_state = &sdss->dm_state; - if (guest_config->b_info.device_model_version != - LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN_TRADITIONAL) { - ret = ERROR_INVAL; - goto out; + assert(libxl_defbool_val(guest_config->b_info.device_model_stubdomain)); + + if (guest_config->b_info.stubdomain_version == LIBXL_STUBDOMAIN_VERSION_LINUX) { + if (d_state->saved_state) { + LOG(ERROR, "Save/Restore not supported yet with Linux Stubdom."); + ret = -1; + goto out; + } } sdss->pvqemu.guest_domid = 0; @@ -1941,8 +1955,8 @@ void libxl__spawn_stub_dm(libxl__egc *egc, libxl__stub_dm_spawn_state *sdss) libxl_domain_build_info_init_type(&dm_config->b_info, LIBXL_DOMAIN_TYPE_PV); dm_config->b_info.max_vcpus = 1; - dm_config->b_info.max_memkb = 28 * 1024 + - guest_config->b_info.video_memkb; + dm_config->b_info.max_memkb = guest_config->b_info.stubdomain_memkb; + dm_config->b_info.max_memkb += guest_config->b_info.video_memkb; dm_config->b_info.target_memkb = dm_config->b_info.max_memkb; dm_config->b_info.max_grant_frames = guest_config->b_info.max_grant_frames; @@ -1983,10 +1997,8 @@ void libxl__spawn_stub_dm(libxl__egc *egc, libxl__stub_dm_spawn_state *sdss) dm_config->num_vkbs = 1; } - stubdom_state->pv_kernel.path - = libxl__abs_path(gc, "ioemu-stubdom.gz", libxl__xenfirmwaredir_path()); - stubdom_state->pv_cmdline = GCSPRINTF(" -d %d", guest_domid); - stubdom_state->pv_ramdisk.path = ""; + stubdom_state->pv_kernel.path = guest_config->b_info.stubdomain_kernel; + stubdom_state->pv_ramdisk.path = guest_config->b_info.stubdomain_ramdisk; /* fixme: this function can leak the stubdom if it fails */ ret = libxl__domain_make(gc, dm_config, stubdom_state, @@ -2006,7 +2018,12 @@ void libxl__spawn_stub_dm(libxl__egc *egc, libxl__stub_dm_spawn_state *sdss) goto out; } - libxl__write_stub_dmargs(gc, dm_domid, guest_domid, args); + libxl__store_libxl_entry(gc, guest_domid, "dm-version", + libxl_device_model_version_to_string(dm_config->b_info.device_model_version)); + libxl__store_libxl_entry(gc, dm_domid, "stubdom-version", + libxl_stubdomain_version_to_string(guest_config->b_info.stubdomain_version)); + libxl__write_stub_dmargs(gc, dm_domid, guest_domid, args, + guest_config->b_info.stubdomain_version == LIBXL_STUBDOMAIN_VERSION_LINUX); libxl__xs_printf(gc, XBT_NULL, GCSPRINTF("%s/image/device-model-domid", libxl__xs_get_dompath(gc, guest_domid)), @@ -2015,6 +2032,15 @@ void libxl__spawn_stub_dm(libxl__egc *egc, libxl__stub_dm_spawn_state *sdss) GCSPRINTF("%s/target", libxl__xs_get_dompath(gc, dm_domid)), "%d", guest_domid); + if (guest_config->b_info.stubdomain_version == LIBXL_STUBDOMAIN_VERSION_LINUX) { + /* qemu-xen is used as a dm in the stubdomain, so we set the bios + * accroding to this */ + libxl__xs_printf(gc, XBT_NULL, + libxl__sprintf(gc, "%s/hvmloader/bios", + libxl__xs_get_dompath(gc, guest_domid)), + "%s", + libxl_bios_type_to_string(guest_config->b_info.u.hvm.bios)); + } ret = xc_domain_set_target(ctx->xch, dm_domid, guest_domid); if (ret<0) { LOGED(ERROR, guest_domid, "setting target domain %d -> %d", diff --git a/tools/libxl/libxl_internal.c b/tools/libxl/libxl_internal.c index f492dae..c6b7465 100644 --- a/tools/libxl/libxl_internal.c +++ b/tools/libxl/libxl_internal.c @@ -377,6 +377,28 @@ out: return rc; } +int libxl__stubdomain_version_running(libxl__gc *gc, uint32_t domid) +{ + char *path = NULL; + char *stub_version = NULL; + libxl_stubdomain_version value; + + path = libxl__xs_libxl_path(gc, domid); + path = libxl__sprintf(gc, "%s/stubdom-version", path); + stub_version = libxl__xs_read(gc, XBT_NULL, path); + if (!stub_version) { + return LIBXL_STUBDOMAIN_VERSION_MINIOS; + } + + if (libxl_stubdomain_version_from_string(stub_version, &value) < 0) { + libxl_ctx *ctx = libxl__gc_owner(gc); + LIBXL__LOG(ctx, LIBXL__LOG_ERROR, + "fatal: %s contain a wrong value (%s)", path, stub_version); + return -1; + } + return value; +} + int libxl__device_model_version_running(libxl__gc *gc, uint32_t domid) { char *path = NULL; diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h index 52e1e8e..9a01aa3 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -117,6 +117,7 @@ #define STUBDOM_CONSOLE_RESTORE 2 #define STUBDOM_CONSOLE_SERIAL 3 #define STUBDOM_SPECIAL_CONSOLES 3 +#define LIBXL_LINUX_STUBDOM_MEM 128 #define TAP_DEVICE_SUFFIX "-emu" #define DOMID_XS_PATH "domid" #define INVALID_DOMID ~0 @@ -2041,6 +2042,9 @@ _hidden libxl__json_object *libxl__json_parse(libxl__gc *gc_opt, const char *s); _hidden int libxl__device_model_version_running(libxl__gc *gc, uint32_t domid); /* Return the system-wide default device model */ _hidden libxl_device_model_version libxl__default_device_model(libxl__gc *gc); + /* Based on /libxl/$domid/stubdom-version xenstore key + * default is minios */ +_hidden int libxl__stubdomain_version_running(libxl__gc *gc, uint32_t domid); #define DEVICE_MODEL_XS_PATH(gc, dm_domid, domid, fmt, _a...) \ libxl__sprintf(gc, "/local/domain/%u/device-model/%u" fmt, dm_domid, \ diff --git a/tools/libxl/libxl_mem.c b/tools/libxl/libxl_mem.c index e551e09..4cf6a73 100644 --- a/tools/libxl/libxl_mem.c +++ b/tools/libxl/libxl_mem.c @@ -463,8 +463,10 @@ int libxl_domain_need_memory(libxl_ctx *ctx, case LIBXL_DOMAIN_TYPE_PVH: case LIBXL_DOMAIN_TYPE_HVM: *need_memkb += b_info->shadow_memkb + LIBXL_HVM_EXTRA_MEMORY; - if (libxl_defbool_val(b_info->device_model_stubdomain)) - *need_memkb += 32 * 1024; + if (libxl_defbool_val(b_info->device_model_stubdomain)) { + *need_memkb += b_info->stubdomain_memkb; + *need_memkb += b_info->video_memkb; + } break; case LIBXL_DOMAIN_TYPE_PV: *need_memkb += b_info->shadow_memkb + LIBXL_PV_EXTRA_MEMORY; diff --git a/tools/libxl/libxl_types.idl b/tools/libxl/libxl_types.idl index 946c5b5..f739754 100644 --- a/tools/libxl/libxl_types.idl +++ b/tools/libxl/libxl_types.idl @@ -492,6 +492,9 @@ libxl_domain_build_info = Struct("domain_build_info",[ ("device_model_version", libxl_device_model_version), ("device_model_stubdomain", libxl_defbool), ("stubdomain_version", libxl_stubdomain_version), + ("stubdomain_memkb", MemKB), + ("stubdomain_kernel", string), + ("stubdomain_ramdisk", string), # if you set device_model you must set device_model_version too ("device_model", string), ("device_model_ssidref", uint32), -- git-series 0.9.1 _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxxxxxxxxx https://lists.xenproject.org/mailman/listinfo/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |