# HG changeset patch
# User Ian Campbell <ian.campbell@xxxxxxxxxx>
# Date 1310997150 -3600
# Node ID 9f059f087152cd98b509dc915be384ea97948d6f
# Parent e821a5d1144ba8ff44701eaeee4671f9b0ac1330
libxl: specify HVM vs PV in build_info using libxl_domain_type enum
Also caught one place (in libxl__domain_restore_common) which used
info->u.hvm.pae even if !hvm. (fortunately the value was unused in
xc_domain_restore).
Signed-off-by: Ian Campbell <ian.campbell@xxxxxxxxxx>
diff -r e821a5d1144b -r 9f059f087152 tools/libxl/libxl.c
--- a/tools/libxl/libxl.c Mon Jul 18 14:52:30 2011 +0100
+++ b/tools/libxl/libxl.c Mon Jul 18 14:52:30 2011 +0100
@@ -2036,17 +2036,27 @@ int libxl_domain_need_memory(libxl_ctx *
libxl_device_model_info *dm_info, uint32_t *need_memkb)
{
libxl__gc gc = LIBXL_INIT_GC(ctx);
+ int rc = ERROR_INVAL;
*need_memkb = b_info->target_memkb;
- if (b_info->hvm) {
+ switch (b_info->type) {
+ case LIBXL_DOMAIN_TYPE_HVM:
*need_memkb += b_info->shadow_memkb + LIBXL_HVM_EXTRA_MEMORY;
if (dm_info->device_model_stubdomain)
*need_memkb += 32 * 1024;
- } else
+ break;
+ case LIBXL_DOMAIN_TYPE_PV:
*need_memkb += b_info->shadow_memkb + LIBXL_PV_EXTRA_MEMORY;
+ break;
+ default:
+ goto out;
+ }
if (*need_memkb % (2 * 1024))
*need_memkb += (2 * 1024) - (*need_memkb % (2 * 1024));
+ rc = 0;
+out:
libxl__free_all(&gc);
- return 0;
+ return rc;
+
}
int libxl_get_free_memory(libxl_ctx *ctx, uint32_t *memkb)
diff -r e821a5d1144b -r 9f059f087152 tools/libxl/libxl.idl
--- a/tools/libxl/libxl.idl Mon Jul 18 14:52:30 2011 +0100
+++ b/tools/libxl/libxl.idl Mon Jul 18 14:52:30 2011 +0100
@@ -158,9 +158,9 @@ libxl_domain_build_info = Struct("domain
("shadow_memkb", uint32),
("disable_migrate", bool),
("cpuid", libxl_cpuid_policy_list),
- ("hvm", bool),
- ("u", KeyedUnion(None, "hvm",
- [("hvm", "%s", Struct(None,
+ ("type", libxl_domain_type),
+ ("u", KeyedUnion(None, "type",
+ [("hvm", "%s == LIBXL_DOMAIN_TYPE_HVM", Struct(None,
[("firmware", string),
("pae", bool),
("apic", bool),
@@ -173,7 +173,7 @@ libxl_domain_build_info = Struct("domain
("timer_mode", integer),
("nested_hvm", bool),
])),
- ("pv", "!%s", Struct(None,
+ ("pv", "%s == LIBXL_DOMAIN_TYPE_PV", Struct(None,
[("kernel", libxl_file_reference),
("slack_memkb", uint32),
("bootloader", string),
diff -r e821a5d1144b -r 9f059f087152 tools/libxl/libxl_bootloader.c
--- a/tools/libxl/libxl_bootloader.c Mon Jul 18 14:52:30 2011 +0100
+++ b/tools/libxl/libxl_bootloader.c Mon Jul 18 14:52:30 2011 +0100
@@ -323,7 +323,7 @@ int libxl_run_bootloader(libxl_ctx *ctx,
struct stat st_buf;
- if (info->hvm || !info->u.pv.bootloader)
+ if (info->type != LIBXL_DOMAIN_TYPE_PV || !info->u.pv.bootloader)
goto out;
rc = ERROR_INVAL;
diff -r e821a5d1144b -r 9f059f087152 tools/libxl/libxl_create.c
--- a/tools/libxl/libxl_create.c Mon Jul 18 14:52:30 2011 +0100
+++ b/tools/libxl/libxl_create.c Mon Jul 18 14:52:30 2011 +0100
@@ -84,7 +84,7 @@ void libxl_init_build_info(libxl_domain_
b_info->shadow_memkb = 0;
if (c_info->hvm) {
b_info->video_memkb = 8 * 1024;
- b_info->hvm = 1;
+ b_info->type = LIBXL_DOMAIN_TYPE_HVM;
b_info->u.hvm.firmware = NULL;
b_info->u.hvm.pae = 1;
b_info->u.hvm.apic = 1;
@@ -96,6 +96,7 @@ void libxl_init_build_info(libxl_domain_
b_info->u.hvm.timer_mode = 1;
b_info->u.hvm.nested_hvm = 0;
} else {
+ b_info->type = LIBXL_DOMAIN_TYPE_PV;
b_info->u.pv.slack_memkb = 8 * 1024;
}
}
@@ -160,7 +161,8 @@ int libxl__domain_build(libxl__gc *gc,
gettimeofday(&start_time, NULL);
- if (info->hvm) {
+ switch (info->type) {
+ case LIBXL_DOMAIN_TYPE_HVM:
ret = libxl__build_hvm(gc, domid, info, dm_info, state);
if (ret)
goto out;
@@ -172,7 +174,8 @@ int libxl__domain_build(libxl__gc *gc,
vments[3] = "hvm";
vments[4] = "start_time";
vments[5] = libxl__sprintf(gc, "%lu.%02d",
start_time.tv_sec,(int)start_time.tv_usec/10000);
- } else {
+ break;
+ case LIBXL_DOMAIN_TYPE_PV:
ret = libxl__build_pv(gc, domid, info, state);
if (ret)
goto out;
@@ -193,6 +196,10 @@ int libxl__domain_build(libxl__gc *gc,
vments[i++] = "image/cmdline";
vments[i++] = (char*) info->u.pv.cmdline;
}
+ break;
+ default:
+ ret = ERROR_INVAL;
+ goto out;
}
ret = libxl__build_post(gc, domid, info, state, vments, localents);
out:
@@ -219,7 +226,8 @@ static int domain_restore(libxl__gc *gc,
gettimeofday(&start_time, NULL);
- if (info->hvm) {
+ switch (info->type) {
+ case LIBXL_DOMAIN_TYPE_HVM:
vments = libxl__calloc(gc, 7, sizeof(char *));
vments[0] = "rtc/timeoffset";
vments[1] = (info->u.hvm.timeoffset) ? info->u.hvm.timeoffset : "";
@@ -227,7 +235,8 @@ static int domain_restore(libxl__gc *gc,
vments[3] = "hvm";
vments[4] = "start_time";
vments[5] = libxl__sprintf(gc, "%lu.%02d",
start_time.tv_sec,(int)start_time.tv_usec/10000);
- } else {
+ break;
+ case LIBXL_DOMAIN_TYPE_PV:
vments = libxl__calloc(gc, 11, sizeof(char *));
i = 0;
vments[i++] = "image/ostype";
@@ -244,20 +253,24 @@ static int domain_restore(libxl__gc *gc,
vments[i++] = "image/cmdline";
vments[i++] = (char*) info->u.pv.cmdline;
}
+ break;
+ default:
+ ret = ERROR_INVAL;
+ goto out;
}
ret = libxl__build_post(gc, domid, info, state, vments, localents);
if (ret)
goto out;
dm_info->saved_state = NULL;
- if (info->hvm) {
+ if (info->type == LIBXL_DOMAIN_TYPE_HVM) {
ret = asprintf(&dm_info->saved_state,
XC_DEVICE_MODEL_RESTORE_FILE".%d", domid);
ret = (ret < 0) ? ERROR_FAIL : 0;
}
out:
- if (!info->hvm) {
+ if (info->type == LIBXL_DOMAIN_TYPE_PV) {
libxl__file_reference_unmap(&info->u.pv.kernel);
libxl__file_reference_unmap(&info->u.pv.ramdisk);
}
diff -r e821a5d1144b -r 9f059f087152 tools/libxl/libxl_dm.c
--- a/tools/libxl/libxl_dm.c Mon Jul 18 14:52:30 2011 +0100
+++ b/tools/libxl/libxl_dm.c Mon Jul 18 14:52:30 2011 +0100
@@ -642,12 +642,13 @@ static int libxl__create_stubdom(libxl__
b_info.max_vcpus = 1;
b_info.max_memkb = 32 * 1024;
b_info.target_memkb = b_info.max_memkb;
+
+ b_info.type = LIBXL_DOMAIN_TYPE_PV;
b_info.u.pv.kernel.path = libxl__abs_path(gc, "ioemu-stubdom.gz",
libxl_xenfirmwaredir_path());
b_info.u.pv.cmdline = libxl__sprintf(gc, " -d %d", info->domid);
b_info.u.pv.ramdisk.path = "";
b_info.u.pv.features = "";
- b_info.hvm = 0;
/* fixme: this function can leak the stubdom if it fails */
diff -r e821a5d1144b -r 9f059f087152 tools/libxl/libxl_dom.c
--- a/tools/libxl/libxl_dom.c Mon Jul 18 14:52:30 2011 +0100
+++ b/tools/libxl/libxl_dom.c Mon Jul 18 14:52:30 2011 +0100
@@ -75,14 +75,14 @@ int libxl__build_pre(libxl__gc *gc, uint
libxl_ctx *ctx = libxl__gc_owner(gc);
xc_domain_max_vcpus(ctx->xch, domid, info->max_vcpus);
xc_domain_setmaxmem(ctx->xch, domid, info->target_memkb +
LIBXL_MAXMEM_CONSTANT);
- if (!info->hvm)
+ if (info->type == LIBXL_DOMAIN_TYPE_PV)
xc_domain_set_memmap_limit(ctx->xch, domid,
(info->max_memkb + info->u.pv.slack_memkb));
xc_domain_set_tsc_info(ctx->xch, domid, info->tsc_mode, 0, 0, 0);
if ( info->disable_migrate )
xc_domain_disable_migrate(ctx->xch, domid);
- if (info->hvm) {
+ if (info->type == LIBXL_DOMAIN_TYPE_HVM) {
unsigned long shadow;
shadow = (info->shadow_memkb + 1023) / 1024;
xc_shadow_control(ctx->xch, domid,
XEN_DOMCTL_SHADOW_OP_SET_ALLOCATION, NULL, 0, &shadow, 0, NULL);
@@ -340,10 +340,25 @@ int libxl__domain_restore_common(libxl__
libxl_ctx *ctx = libxl__gc_owner(gc);
/* read signature */
int rc;
+ int hvm, pae, superpages;
+ switch (info->type) {
+ case LIBXL_DOMAIN_TYPE_HVM:
+ hvm = 1;
+ superpages = 1;
+ pae = info->u.hvm.pae;
+ break;
+ case LIBXL_DOMAIN_TYPE_PV:
+ hvm = 0;
+ superpages = 0;
+ pae = 1;
+ break;
+ default:
+ return ERROR_INVAL;
+ }
rc = xc_domain_restore(ctx->xch, fd, domid,
- state->store_port, &state->store_mfn,
- state->console_port, &state->console_mfn,
- info->hvm, info->u.hvm.pae, !!info->hvm);
+ state->store_port, &state->store_mfn,
+ state->console_port, &state->console_mfn,
+ hvm, pae, superpages);
if ( rc ) {
LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "restoring domain");
return ERROR_FAIL;
diff -r e821a5d1144b -r 9f059f087152 tools/libxl/xl_cmdimpl.c
--- a/tools/libxl/xl_cmdimpl.c Mon Jul 18 14:52:30 2011 +0100
+++ b/tools/libxl/xl_cmdimpl.c Mon Jul 18 14:52:30 2011 +0100
@@ -381,7 +381,7 @@ static void printf_info(int domid,
printf("\t\t\t(spiceagent_mouse %d)\n", dm_info->spiceagent_mouse);
printf("\t\t)\n");
} else {
- printf("\t\t(linux %d)\n", b_info->hvm);
+ printf("\t\t(linux %d)\n", 0);
printf("\t\t\t(kernel %s)\n", b_info->u.pv.kernel.path);
printf("\t\t\t(cmdline %s)\n", b_info->u.pv.cmdline);
printf("\t\t\t(ramdisk %s)\n", b_info->u.pv.ramdisk.path);
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel
|