mirror of
https://github.com/xen-project/xen.git
synced 2026-10-28 10:11:27 +01:00
libxl: provide _init and _setdefault for libxl_domain_build_info.
Some fields require further scaffolding before they can use the _init/_setdefault scheme and are handled in later patches. Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
This commit is contained in:
1 parent
c8d71a6de2
commit
7e449837dc
7 files changed
+73
-26
No files matched your search
+6
-1
@@ -2625,7 +2625,11 @@ int libxl_domain_need_memory(libxl_ctx *ctx, libxl_domain_build_info *b_info,
|
||||
uint32_t *need_memkb)
|
||||
{
|
||||
GC_INIT(ctx);
|
||||
int rc = ERROR_INVAL;
|
||||
int rc;
|
||||
|
||||
rc = libxl__domain_build_info_setdefault(gc, b_info);
|
||||
if (rc) goto out;
|
||||
|
||||
*need_memkb = b_info->target_memkb;
|
||||
switch (b_info->type) {
|
||||
case LIBXL_DOMAIN_TYPE_HVM:
|
||||
@@ -2637,6 +2641,7 @@ int libxl_domain_need_memory(libxl_ctx *ctx, libxl_domain_build_info *b_info,
|
||||
*need_memkb += b_info->shadow_memkb + LIBXL_PV_EXTRA_MEMORY;
|
||||
break;
|
||||
default:
|
||||
rc = ERROR_INVAL;
|
||||
goto out;
|
||||
}
|
||||
if (*need_memkb % (2 * 1024))
|
||||
|
||||
+2
-3
@@ -357,9 +357,8 @@ int libxl_ctx_postfork(libxl_ctx *ctx);
|
||||
|
||||
/* domain related functions */
|
||||
void libxl_domain_create_info_init(libxl_domain_create_info *c_info);
|
||||
int libxl_init_build_info(libxl_ctx *ctx,
|
||||
libxl_domain_build_info *b_info,
|
||||
libxl_domain_create_info *c_info);
|
||||
void libxl_domain_build_info_init(libxl_domain_build_info *b_info,
|
||||
const libxl_domain_create_info *c_info);
|
||||
typedef int (*libxl_console_ready)(libxl_ctx *ctx, uint32_t domid, void *priv);
|
||||
int libxl_domain_create_new(libxl_ctx *ctx, libxl_domain_config *d_config, libxl_console_ready cb, void *priv, uint32_t *domid);
|
||||
int libxl_domain_create_restore(libxl_ctx *ctx, libxl_domain_config *d_config, libxl_console_ready cb, void *priv, uint32_t *domid, int restore_fd);
|
||||
|
||||
@@ -346,6 +346,9 @@ int libxl_run_bootloader(libxl_ctx *ctx,
|
||||
|
||||
struct stat st_buf;
|
||||
|
||||
rc = libxl__domain_build_info_setdefault(gc, info);
|
||||
if (rc) goto out;
|
||||
|
||||
if (info->type != LIBXL_DOMAIN_TYPE_PV || !info->u.pv.bootloader)
|
||||
goto out;
|
||||
|
||||
|
||||
+45
-17
@@ -66,16 +66,10 @@ int libxl__domain_create_info_setdefault(libxl__gc *gc,
|
||||
return 0;
|
||||
}
|
||||
|
||||
int libxl_init_build_info(libxl_ctx *ctx,
|
||||
libxl_domain_build_info *b_info,
|
||||
libxl_domain_create_info *c_info)
|
||||
void libxl_domain_build_info_init(libxl_domain_build_info *b_info,
|
||||
const libxl_domain_create_info *c_info)
|
||||
{
|
||||
memset(b_info, '\0', sizeof(*b_info));
|
||||
b_info->max_vcpus = 1;
|
||||
b_info->cur_vcpus = 1;
|
||||
if (libxl_cpumap_alloc(ctx, &b_info->cpumap))
|
||||
return ERROR_NOMEM;
|
||||
libxl_cpumap_set_any(&b_info->cpumap);
|
||||
b_info->max_memkb = 32 * 1024;
|
||||
b_info->target_memkb = b_info->max_memkb;
|
||||
b_info->disable_migrate = 0;
|
||||
@@ -83,8 +77,6 @@ int libxl_init_build_info(libxl_ctx *ctx,
|
||||
b_info->shadow_memkb = 0;
|
||||
b_info->type = c_info->type;
|
||||
|
||||
b_info->device_model_version =
|
||||
LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN_TRADITIONAL;
|
||||
b_info->device_model_stubdomain = false;
|
||||
b_info->device_model = NULL;
|
||||
|
||||
@@ -108,15 +100,9 @@ int libxl_init_build_info(libxl_ctx *ctx,
|
||||
|
||||
b_info->u.hvm.stdvga = 0;
|
||||
b_info->u.hvm.vnc.enable = 1;
|
||||
b_info->u.hvm.vnc.listen = strdup("127.0.0.1");
|
||||
b_info->u.hvm.vnc.display = 0;
|
||||
b_info->u.hvm.vnc.findunused = 1;
|
||||
b_info->u.hvm.keymap = NULL;
|
||||
b_info->u.hvm.sdl.enable = 0;
|
||||
b_info->u.hvm.sdl.opengl = 0;
|
||||
b_info->u.hvm.nographic = 0;
|
||||
b_info->u.hvm.serial = NULL;
|
||||
b_info->u.hvm.boot = strdup("cda");
|
||||
b_info->u.hvm.usb = 0;
|
||||
b_info->u.hvm.usbdevice = NULL;
|
||||
b_info->u.hvm.xen_platform_pci = 1;
|
||||
@@ -125,7 +111,47 @@ int libxl_init_build_info(libxl_ctx *ctx,
|
||||
b_info->u.pv.slack_memkb = 8 * 1024;
|
||||
break;
|
||||
default:
|
||||
LIBXL__LOG(ctx, LIBXL__LOG_ERROR,
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
int libxl__domain_build_info_setdefault(libxl__gc *gc,
|
||||
libxl_domain_build_info *b_info)
|
||||
{
|
||||
if (!b_info->device_model_version)
|
||||
b_info->device_model_version =
|
||||
LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN_TRADITIONAL;
|
||||
|
||||
if (!b_info->max_vcpus)
|
||||
b_info->max_vcpus = 1;
|
||||
if (!b_info->cur_vcpus)
|
||||
b_info->cur_vcpus = 1;
|
||||
|
||||
if (!b_info->cpumap.size) {
|
||||
if (libxl_cpumap_alloc(CTX, &b_info->cpumap))
|
||||
return ERROR_NOMEM;
|
||||
libxl_cpumap_set_any(&b_info->cpumap);
|
||||
}
|
||||
|
||||
switch (b_info->type) {
|
||||
case LIBXL_DOMAIN_TYPE_HVM:
|
||||
if (!b_info->u.hvm.boot) {
|
||||
b_info->u.hvm.boot = strdup("cda");
|
||||
if (!b_info->u.hvm.boot) return ERROR_NOMEM;
|
||||
}
|
||||
|
||||
if (b_info->u.hvm.vnc.enable) {
|
||||
if (!b_info->u.hvm.vnc.listen) {
|
||||
b_info->u.hvm.vnc.listen = strdup("127.0.0.1");
|
||||
if (!b_info->u.hvm.vnc.listen) return ERROR_NOMEM;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
case LIBXL_DOMAIN_TYPE_PV:
|
||||
break;
|
||||
default:
|
||||
LIBXL__LOG(CTX, LIBXL__LOG_ERROR,
|
||||
"invalid domain type %s in create info",
|
||||
libxl_domain_type_to_string(b_info->type));
|
||||
return ERROR_INVAL;
|
||||
@@ -488,6 +514,8 @@ static int do_domain_create(libxl__gc *gc, libxl_domain_config *d_config,
|
||||
goto error_out;
|
||||
}
|
||||
|
||||
ret = libxl__domain_build_info_setdefault(gc, &d_config->b_info);
|
||||
if (ret) goto error_out;
|
||||
|
||||
for (i = 0; i < d_config->num_disks; i++) {
|
||||
ret = libxl__device_disk_set_backend(gc, &d_config->disks[i]);
|
||||
|
||||
@@ -713,13 +713,12 @@ static int libxl__create_stubdom(libxl__gc *gc,
|
||||
|
||||
libxl_uuid_generate(&dm_config.c_info.uuid);
|
||||
|
||||
memset(&dm_config.b_info, 0x00, sizeof(libxl_domain_build_info));
|
||||
dm_config.b_info.type = dm_config.c_info.type;
|
||||
libxl_domain_build_info_init(&dm_config.b_info, &dm_config.c_info);
|
||||
|
||||
dm_config.b_info.max_vcpus = 1;
|
||||
dm_config.b_info.max_memkb = 32 * 1024;
|
||||
dm_config.b_info.target_memkb = dm_config.b_info.max_memkb;
|
||||
|
||||
dm_config.b_info.type = LIBXL_DOMAIN_TYPE_PV;
|
||||
dm_config.b_info.u.pv.kernel.path = libxl__abs_path(gc, "ioemu-stubdom.gz",
|
||||
libxl_xenfirmwaredir_path());
|
||||
dm_config.b_info.u.pv.cmdline = libxl__sprintf(gc, " -d %d", guest_domid);
|
||||
@@ -742,6 +741,8 @@ static int libxl__create_stubdom(libxl__gc *gc,
|
||||
|
||||
ret = libxl__domain_create_info_setdefault(gc, &dm_config.c_info);
|
||||
if (ret) goto out;
|
||||
ret = libxl__domain_build_info_setdefault(gc, &dm_config.b_info);
|
||||
if (ret) goto out;
|
||||
|
||||
libxl__vfb_and_vkb_from_hvm_guest_config(gc, guest_config, &vfb, &vkb);
|
||||
dm_config.vfbs = &vfb;
|
||||
|
||||
@@ -189,6 +189,8 @@ libxl__ev_xswatch *libxl__watch_slot_contents(libxl__gc *gc, int slotnum);
|
||||
*/
|
||||
_hidden int libxl__domain_create_info_setdefault(libxl__gc *gc,
|
||||
libxl_domain_create_info *c_info);
|
||||
_hidden int libxl__domain_build_info_setdefault(libxl__gc *gc,
|
||||
libxl_domain_build_info *b_info);
|
||||
|
||||
struct libxl__evgen_domain_death {
|
||||
uint32_t domid;
|
||||
|
||||
@@ -584,8 +584,7 @@ static void parse_config_data(const char *configfile_filename_report,
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (libxl_init_build_info(ctx, b_info, c_info))
|
||||
exit(1);
|
||||
libxl_domain_build_info_init(b_info, c_info);
|
||||
|
||||
/* the following is the actual config parsing with overriding values in the structures */
|
||||
if (!xlu_cfg_get_long (config, "vcpus", &l, 0)) {
|
||||
@@ -599,6 +598,11 @@ static void parse_config_data(const char *configfile_filename_report,
|
||||
if (!xlu_cfg_get_list (config, "cpus", &cpus, 0, 1)) {
|
||||
int i, n_cpus = 0;
|
||||
|
||||
if (libxl_cpumap_alloc(ctx, &b_info->cpumap)) {
|
||||
fprintf(stderr, "Unable to allocate cpumap\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
libxl_cpumap_set_none(&b_info->cpumap);
|
||||
while ((buf = xlu_cfg_get_listitem(cpus, n_cpus)) != NULL) {
|
||||
i = atoi(buf);
|
||||
@@ -613,6 +617,11 @@ static void parse_config_data(const char *configfile_filename_report,
|
||||
else if (!xlu_cfg_get_string (config, "cpus", &buf, 0)) {
|
||||
char *buf2 = strdup(buf);
|
||||
|
||||
if (libxl_cpumap_alloc(ctx, &b_info->cpumap)) {
|
||||
fprintf(stderr, "Unable to allocate cpumap\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
libxl_cpumap_set_none(&b_info->cpumap);
|
||||
if (vcpupin_parse(buf2, &b_info->cpumap))
|
||||
exit(1);
|
||||
|
||||