static int libxlMakeDomCreateInfo(libxl_ctx *ctx, virDomainDefPtr def, libxl_domain_create_info *c_info) { char uuidstr[VIR_UUID_STRING_BUFLEN]; libxl_domain_create_info_init(c_info); if (STREQ(def->os.type, "hvm")) c_info->type = LIBXL_DOMAIN_TYPE_HVM; else c_info->type = LIBXL_DOMAIN_TYPE_PV; if (VIR_STRDUP(c_info->name, def->name) < 0) goto error; if (def->nseclabels && def->seclabels[0]->type == VIR_DOMAIN_SECLABEL_STATIC) { if (libxl_flask_context_to_sid(ctx, def->seclabels[0]->label, strlen(def->seclabels[0]->label), &c_info->ssidref)) { virReportError(VIR_ERR_INTERNAL_ERROR, _("libxenlight failed to resolve security label '%s'"), def->seclabels[0]->label); } } virUUIDFormat(def->uuid, uuidstr); if (libxl_uuid_from_string(&c_info->uuid, uuidstr)) { virReportError(VIR_ERR_INTERNAL_ERROR, _("libxenlight failed to parse UUID '%s'"), uuidstr); goto error; } return 0; error: libxl_domain_create_info_dispose(c_info); return -1; }
int hyperxl_domain_start(libxl_ctx* ctx, hyperxl_domain_config* config) { int i, ret = -1; uint32_t domid = 0; libxl_domain_config d_config; libxl_domain_config_init(&d_config); //init create info libxl_domain_create_info* c_info = &d_config.c_info; libxl_domain_create_info_init(c_info); if (config->hvm) c_info->type = LIBXL_DOMAIN_TYPE_HVM; else c_info->type = LIBXL_DOMAIN_TYPE_PV; libxl_uuid_generate(&c_info->uuid); c_info->name = strdup(config->name); libxl_defbool_set(&c_info->run_hotplug_scripts, false); //init_build_info libxl_domain_build_info* b_info = &d_config.b_info; if (config->hvm) libxl_domain_build_info_init_type(b_info, LIBXL_DOMAIN_TYPE_HVM); else { // currently only hvm is supported. pv mode will be enabled // whenever we can insert several serial ports and filesystem // into pv domain. goto cleanup; } // currently, we do not change vcpu and memory only, will add this // feature later. b_info->max_vcpus = config->max_vcpus; if (libxl_cpu_bitmap_alloc(ctx, &b_info->avail_vcpus, config->max_vcpus)) goto cleanup; libxl_bitmap_set_none(&b_info->avail_vcpus); for (i = 0; i < config->max_vcpus; i++) libxl_bitmap_set((&b_info->avail_vcpus), i); b_info->sched_params.weight = 1000; b_info->max_memkb = config->max_memory_kb; b_info->target_memkb = config->max_memory_kb; b_info->video_memkb = 0; // currently, we only initialize hvm fields if (config->hvm) { libxl_defbool_set(&b_info->u.hvm.pae, true); libxl_defbool_set(&b_info->u.hvm.apic, false); libxl_defbool_set(&b_info->u.hvm.acpi, true); b_info->u.hvm.boot = strdup("c"); b_info->cmdline = strdup(config->cmdline); b_info->kernel = strdup(config->kernel); b_info->ramdisk = strdup(config->initrd); b_info->u.hvm.vga.kind = LIBXL_VGA_INTERFACE_TYPE_NONE; libxl_defbool_set(&b_info->u.hvm.nographic, 1); libxl_defbool_set(&b_info->u.hvm.vnc.enable, 0); libxl_defbool_set(&b_info->u.hvm.sdl.enable, 0); b_info->u.hvm.serial = strdup(config->console_sock); libxl_string_list_copy(ctx, &b_info->extra, (libxl_string_list*)config->extra); /* * comments from libvirt and libxenlight: * * The following comment and calculation were taken directly from * libxenlight's internal function libxl_get_required_shadow_memory(): * * 256 pages (1MB) per vcpu, plus 1 page per MiB of RAM for the P2M map, * plus 1 page per MiB of RAM to shadow the resident processes. */ b_info->shadow_memkb = 4 * (256 * libxl_bitmap_count_set(&b_info->avail_vcpus) + 2 * (b_info->max_memkb / 1024)); } if (libxl_domain_create_new(ctx, &d_config, &domid, NULL, NULL)) { goto cleanup; } libxl_evgen_domain_death* e_death = NULL; if (libxl_evenable_domain_death(ctx, domid, 0, &e_death)) { goto cleanup; } libxl_domain_unpause(ctx, domid); config->domid = domid; config->ev = e_death; ret = 0; cleanup: libxl_domain_config_dispose(&d_config); return ret; }
void libxl__spawn_stub_dm(libxl__egc *egc, libxl__stub_dm_spawn_state *sdss) { STATE_AO_GC(sdss->dm.spawn.ao); libxl_ctx *ctx = libxl__gc_owner(gc); int ret; libxl_device_vfb *vfb; libxl_device_vkb *vkb; char **args; struct xs_permissions perm[2]; xs_transaction_t t; /* convenience aliases */ libxl_domain_config *const dm_config = &sdss->dm_config; libxl_domain_config *const guest_config = sdss->dm.guest_config; const int guest_domid = sdss->dm.guest_domid; 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; } sdss->pvqemu.guest_domid = 0; libxl_domain_create_info_init(&dm_config->c_info); dm_config->c_info.type = LIBXL_DOMAIN_TYPE_PV; dm_config->c_info.name = libxl__stub_dm_name(gc, libxl__domid_to_name(gc, guest_domid)); dm_config->c_info.ssidref = guest_config->b_info.device_model_ssidref; libxl_uuid_generate(&dm_config->c_info.uuid); libxl_domain_build_info_init(&dm_config->b_info); 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 = 32 * 1024; dm_config->b_info.target_memkb = dm_config->b_info.max_memkb; dm_config->b_info.u.pv.features = ""; dm_config->b_info.device_model_version = guest_config->b_info.device_model_version; dm_config->b_info.device_model = guest_config->b_info.device_model; dm_config->b_info.extra = guest_config->b_info.extra; dm_config->b_info.extra_pv = guest_config->b_info.extra_pv; dm_config->b_info.extra_hvm = guest_config->b_info.extra_hvm; dm_config->disks = guest_config->disks; dm_config->num_disks = guest_config->num_disks; libxl__dm_vifs_from_hvm_guest_config(gc, guest_config, dm_config); dm_config->c_info.run_hotplug_scripts = guest_config->c_info.run_hotplug_scripts; 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; GCNEW(vfb); GCNEW(vkb); libxl__vfb_and_vkb_from_hvm_guest_config(gc, guest_config, vfb, vkb); dm_config->vfbs = vfb; dm_config->num_vfbs = 1; dm_config->vkbs = vkb; dm_config->num_vkbs = 1; stubdom_state->pv_kernel.path = libxl__abs_path(gc, "ioemu-stubdom.gz", libxl__xenfirmwaredir_path()); stubdom_state->pv_cmdline = libxl__sprintf(gc, " -d %d", guest_domid); stubdom_state->pv_ramdisk.path = ""; /* fixme: this function can leak the stubdom if it fails */ ret = libxl__domain_make(gc, &dm_config->c_info, &sdss->pvqemu.guest_domid); if (ret) goto out; uint32_t dm_domid = sdss->pvqemu.guest_domid; ret = libxl__domain_build(gc, dm_config, dm_domid, stubdom_state); if (ret) goto out; args = libxl__build_device_model_args(gc, "stubdom-dm", guest_domid, guest_config, d_state); if (!args) { ret = ERROR_FAIL; goto out; } libxl__write_stub_dmargs(gc, dm_domid, guest_domid, args); libxl__xs_write(gc, XBT_NULL, libxl__sprintf(gc, "%s/image/device-model-domid", libxl__xs_get_dompath(gc, guest_domid)), "%d", dm_domid); libxl__xs_write(gc, XBT_NULL, libxl__sprintf(gc, "%s/target", libxl__xs_get_dompath(gc, dm_domid)), "%d", guest_domid); ret = xc_domain_set_target(ctx->xch, dm_domid, guest_domid); if (ret<0) { LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "setting target domain %d -> %d", dm_domid, guest_domid); ret = ERROR_FAIL; goto out; } xs_set_target(ctx->xsh, dm_domid, guest_domid); perm[0].id = dm_domid; perm[0].perms = XS_PERM_NONE; perm[1].id = guest_domid; perm[1].perms = XS_PERM_READ; retry_transaction: t = xs_transaction_start(ctx->xsh); xs_mkdir(ctx->xsh, t, libxl__sprintf(gc, "/local/domain/0/device-model/%d", guest_domid)); xs_set_permissions(ctx->xsh, t, libxl__sprintf(gc, "/local/domain/0/device-model/%d", guest_domid), perm, ARRAY_SIZE(perm)); if (!xs_transaction_end(ctx->xsh, t, 0)) if (errno == EAGAIN) goto retry_transaction; libxl__multidev_begin(ao, &sdss->multidev); sdss->multidev.callback = spawn_stub_launch_dm; libxl__add_disks(egc, ao, dm_domid, dm_config, &sdss->multidev); libxl__multidev_prepared(egc, &sdss->multidev, 0); return; out: assert(ret); spawn_stubdom_pvqemu_cb(egc, &sdss->pvqemu, ret); }
void libxl_domain_config_init(libxl_domain_config *d_config) { memset(d_config, 0, sizeof(*d_config)); libxl_domain_create_info_init(&d_config->c_info); libxl_domain_build_info_init(&d_config->b_info); }