Exemplo n.º 1
0
static int
libxlDiskSetDiscard(libxl_device_disk *x_disk, int discard)
{
    if (!x_disk->readwrite)
        return 0;
#if defined(LIBXL_HAVE_LIBXL_DEVICE_DISK_DISCARD_ENABLE)
    switch ((virDomainDiskDiscard)discard) {
    case VIR_DOMAIN_DISK_DISCARD_DEFAULT:
    case VIR_DOMAIN_DISK_DISCARD_LAST:
        break;
    case VIR_DOMAIN_DISK_DISCARD_UNMAP:
        libxl_defbool_set(&x_disk->discard_enable, true);
        break;
    case VIR_DOMAIN_DISK_DISCARD_IGNORE:
        libxl_defbool_set(&x_disk->discard_enable, false);
        break;
    }
    return 0;
#else
    if (discard == VIR_DOMAIN_DISK_DISCARD_DEFAULT)
        return 0;
    virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
                   _("This version of libxenlight does not support "
                     "disk 'discard' option passing"));
    return -1;
#endif
}
Exemplo n.º 2
0
int
libxlMakeVfb(libxlDriverPrivatePtr driver,
             virDomainGraphicsDefPtr l_vfb,
             libxl_device_vfb *x_vfb)
{
    unsigned short port;
    const char *listenAddr;

    libxl_device_vfb_init(x_vfb);

    switch (l_vfb->type) {
        case VIR_DOMAIN_GRAPHICS_TYPE_SDL:
            libxl_defbool_set(&x_vfb->sdl.enable, 1);
            if (VIR_STRDUP(x_vfb->sdl.display, l_vfb->data.sdl.display) < 0)
                return -1;
            if (VIR_STRDUP(x_vfb->sdl.xauthority, l_vfb->data.sdl.xauth) < 0)
                return -1;
            break;
        case  VIR_DOMAIN_GRAPHICS_TYPE_VNC:
            libxl_defbool_set(&x_vfb->vnc.enable, 1);
            /* driver handles selection of free port */
            libxl_defbool_set(&x_vfb->vnc.findunused, 0);
            if (l_vfb->data.vnc.autoport) {

                if (virPortAllocatorAcquire(driver->reservedVNCPorts, &port) < 0)
                    return -1;
                l_vfb->data.vnc.port = port;
            }
            x_vfb->vnc.display = l_vfb->data.vnc.port - LIBXL_VNC_PORT_MIN;

            listenAddr = virDomainGraphicsListenGetAddress(l_vfb, 0);
            if (listenAddr) {
                /* libxl_device_vfb_init() does VIR_STRDUP("127.0.0.1") */
                VIR_FREE(x_vfb->vnc.listen);
                if (VIR_STRDUP(x_vfb->vnc.listen, listenAddr) < 0)
                    return -1;
            }
            if (VIR_STRDUP(x_vfb->keymap, l_vfb->data.vnc.keymap) < 0)
                return -1;
            break;
    }

    return 0;
}
Exemplo n.º 3
0
int xlu_cfg_get_defbool(const XLU_Config *cfg, const char *n, libxl_defbool *b,
                     int dont_warn)
{
    int ret;
    long l;

    ret = xlu_cfg_get_long(cfg, n, &l, dont_warn);
    if (ret) return ret;
    libxl_defbool_set(b, !!l);
    return 0;
}
Exemplo n.º 4
0
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;
}
Exemplo n.º 5
0
static int
libxlMakeDomBuildInfo(virDomainObjPtr vm, libxl_domain_config *d_config)
{
    virDomainDefPtr def = vm->def;
    libxlDomainObjPrivatePtr priv = vm->privateData;
    libxl_domain_build_info *b_info = &d_config->b_info;
    int hvm = STREQ(def->os.type, "hvm");
    size_t i;

    libxl_domain_build_info_init(b_info);

    if (hvm)
        libxl_domain_build_info_init_type(b_info, LIBXL_DOMAIN_TYPE_HVM);
    else
        libxl_domain_build_info_init_type(b_info, LIBXL_DOMAIN_TYPE_PV);

    b_info->max_vcpus = def->maxvcpus;
    if (libxl_cpu_bitmap_alloc(priv->ctx, &b_info->avail_vcpus, def->maxvcpus))
        goto error;
    libxl_bitmap_set_none(&b_info->avail_vcpus);
    for (i = 0; i < def->vcpus; i++)
        libxl_bitmap_set((&b_info->avail_vcpus), i);

    if (def->clock.ntimers > 0 &&
        def->clock.timers[0]->name == VIR_DOMAIN_TIMER_NAME_TSC) {
        switch (def->clock.timers[0]->mode) {
            case VIR_DOMAIN_TIMER_MODE_NATIVE:
                b_info->tsc_mode = 2;
                break;
            case VIR_DOMAIN_TIMER_MODE_PARAVIRT:
                b_info->tsc_mode = 3;
                break;
            default:
                b_info->tsc_mode = 1;
        }
    }
    b_info->sched_params.weight = 1000;
    b_info->max_memkb = def->mem.max_balloon;
    b_info->target_memkb = def->mem.cur_balloon;
    if (hvm) {
        char bootorder[VIR_DOMAIN_BOOT_LAST + 1];

        libxl_defbool_set(&b_info->u.hvm.pae,
                          def->features[VIR_DOMAIN_FEATURE_PAE] ==
                          VIR_DOMAIN_FEATURE_STATE_ON);
        libxl_defbool_set(&b_info->u.hvm.apic,
                          def->features[VIR_DOMAIN_FEATURE_APIC] ==
                          VIR_DOMAIN_FEATURE_STATE_ON);
        libxl_defbool_set(&b_info->u.hvm.acpi,
                          def->features[VIR_DOMAIN_FEATURE_ACPI] ==
                          VIR_DOMAIN_FEATURE_STATE_ON);
        for (i = 0; i < def->clock.ntimers; i++) {
            if (def->clock.timers[i]->name == VIR_DOMAIN_TIMER_NAME_HPET &&
                def->clock.timers[i]->present == 1) {
                libxl_defbool_set(&b_info->u.hvm.hpet, 1);
            }
        }
        for (i = 0; i < def->os.nBootDevs; i++) {
            switch (def->os.bootDevs[i]) {
                case VIR_DOMAIN_BOOT_FLOPPY:
                    bootorder[i] = 'a';
                    break;
                default:
                case VIR_DOMAIN_BOOT_DISK:
                    bootorder[i] = 'c';
                    break;
                case VIR_DOMAIN_BOOT_CDROM:
                    bootorder[i] = 'd';
                    break;
                case VIR_DOMAIN_BOOT_NET:
                    bootorder[i] = 'n';
                    break;
            }
        }
        if (def->os.nBootDevs == 0) {
            bootorder[0] = 'c';
            bootorder[1] = '\0';
        }
        else {
            bootorder[def->os.nBootDevs] = '\0';
        }
        if (VIR_STRDUP(b_info->u.hvm.boot, bootorder) < 0)
            goto error;

        if (def->nserials) {
            if (def->nserials > 1) {
                virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
                               "%s",
                               _("Only one serial device is supported by libxl"));
                goto error;
            }
            if (libxlMakeChrdevStr(def->serials[0], &b_info->u.hvm.serial) < 0)
                goto error;
        }

        if (def->nparallels) {
            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
                           "%s",
                           _("Parallel devices are not supported by libxl"));
            goto error;
        }

        /*
         * 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));
    } else {
        /*
         * For compatibility with the legacy xen toolstack, default to pygrub
         * if bootloader is not specified AND direct kernel boot is not specified.
         */
        if (def->os.bootloader) {
            if (VIR_STRDUP(b_info->u.pv.bootloader, def->os.bootloader) < 0)
                goto error;
        } else if (def->os.kernel == NULL) {
            if (VIR_STRDUP(b_info->u.pv.bootloader, LIBXL_BOOTLOADER_PATH) < 0)
                goto error;
        }
        if (def->os.bootloaderArgs) {
            if (!(b_info->u.pv.bootloader_args =
                  virStringSplit(def->os.bootloaderArgs, " \t\n", 0)))
                goto error;
        }
        if (VIR_STRDUP(b_info->u.pv.cmdline, def->os.cmdline) < 0)
            goto error;
        if (def->os.kernel) {
            /* libxl_init_build_info() sets VIR_STRDUP(kernel.path, "hvmloader") */
            VIR_FREE(b_info->u.pv.kernel);
            if (VIR_STRDUP(b_info->u.pv.kernel, def->os.kernel) < 0)
                goto error;
        }
        if (VIR_STRDUP(b_info->u.pv.ramdisk, def->os.initrd) < 0)
            goto error;
    }

    return 0;

error:
    libxl_domain_build_info_dispose(b_info);
    return -1;
}
Exemplo n.º 6
0
static int
libxlMakeVfbList(virPortAllocatorPtr graphicsports,
                 virDomainDefPtr def,
                 libxl_domain_config *d_config)
{
    virDomainGraphicsDefPtr *l_vfbs = def->graphics;
    int nvfbs = def->ngraphics;
    libxl_device_vfb *x_vfbs;
    libxl_device_vkb *x_vkbs;
    size_t i;

    if (nvfbs == 0)
        return 0;

    if (VIR_ALLOC_N(x_vfbs, nvfbs) < 0)
        return -1;
    if (VIR_ALLOC_N(x_vkbs, nvfbs) < 0) {
        VIR_FREE(x_vfbs);
        return -1;
    }

    for (i = 0; i < nvfbs; i++) {
        libxl_device_vkb_init(&x_vkbs[i]);

        if (libxlMakeVfb(graphicsports, l_vfbs[i], &x_vfbs[i]) < 0)
            goto error;
    }

    d_config->vfbs = x_vfbs;
    d_config->vkbs = x_vkbs;
    d_config->num_vfbs = d_config->num_vkbs = nvfbs;

    /*
     * VNC or SDL info must also be set in libxl_domain_build_info
     * for HVM domains.  Use the first vfb device.
     */
    if (STREQ(def->os.type, "hvm")) {
        libxl_domain_build_info *b_info = &d_config->b_info;
        libxl_device_vfb vfb = d_config->vfbs[0];

        if (libxl_defbool_val(vfb.vnc.enable)) {
            libxl_defbool_set(&b_info->u.hvm.vnc.enable, true);
            if (VIR_STRDUP(b_info->u.hvm.vnc.listen, vfb.vnc.listen) < 0)
                goto error;
            if (VIR_STRDUP(b_info->u.hvm.vnc.passwd, vfb.vnc.passwd) < 0)
                goto error;
            b_info->u.hvm.vnc.display = vfb.vnc.display;
            libxl_defbool_set(&b_info->u.hvm.vnc.findunused,
                              libxl_defbool_val(vfb.vnc.findunused));
        } else if (libxl_defbool_val(vfb.sdl.enable)) {
            libxl_defbool_set(&b_info->u.hvm.sdl.enable, true);
            libxl_defbool_set(&b_info->u.hvm.sdl.opengl,
                              libxl_defbool_val(vfb.sdl.opengl));
            if (VIR_STRDUP(b_info->u.hvm.sdl.display, vfb.sdl.display) < 0)
                goto error;
            if (VIR_STRDUP(b_info->u.hvm.sdl.xauthority, vfb.sdl.xauthority) < 0)
                goto error;
        }
    }

    return 0;

 error:
    for (i = 0; i < nvfbs; i++) {
        libxl_device_vfb_dispose(&x_vfbs[i]);
        libxl_device_vkb_dispose(&x_vkbs[i]);
    }
    VIR_FREE(x_vfbs);
    VIR_FREE(x_vkbs);
    return -1;
}