static int qemuHotplugCreateObjects(virDomainXMLOptionPtr xmlopt, virDomainObjPtr *vm, const char *filename) { int ret = -1; qemuDomainObjPrivatePtr priv = NULL; if (!(*vm = virDomainObjNew(xmlopt))) goto cleanup; if (!((*vm)->def = virDomainDefParseFile(filename, driver.caps, driver.xmlopt, QEMU_EXPECTED_VIRT_TYPES, 0))) goto cleanup; priv = (*vm)->privateData; if (!(priv->qemuCaps = virQEMUCapsNew())) goto cleanup; /* for attach & detach qemu must support -device */ virQEMUCapsSet(priv->qemuCaps, QEMU_CAPS_DEVICE); ret = 0; cleanup: return ret; }
static int qemuHotplugCreateObjects(virDomainXMLOptionPtr xmlopt, virDomainObjPtr *vm, const char *domxml, bool event, const char *testname) { int ret = -1; qemuDomainObjPrivatePtr priv = NULL; if (!(*vm = virDomainObjNew(xmlopt))) goto cleanup; priv = (*vm)->privateData; if (!(priv->qemuCaps = virQEMUCapsNew())) goto cleanup; virQEMUCapsSet(priv->qemuCaps, QEMU_CAPS_VIRTIO_SCSI); virQEMUCapsSet(priv->qemuCaps, QEMU_CAPS_DEVICE_USB_STORAGE); virQEMUCapsSet(priv->qemuCaps, QEMU_CAPS_VIRTIO_CCW); virQEMUCapsSet(priv->qemuCaps, QEMU_CAPS_DEVICE_IVSHMEM_PLAIN); virQEMUCapsSet(priv->qemuCaps, QEMU_CAPS_DEVICE_IVSHMEM_DOORBELL); if (event) virQEMUCapsSet(priv->qemuCaps, QEMU_CAPS_DEVICE_DEL_EVENT); if (qemuTestCapsCacheInsert(driver.qemuCapsCache, testname, priv->qemuCaps) < 0) goto cleanup; if (!((*vm)->def = virDomainDefParseString(domxml, driver.caps, driver.xmlopt, NULL, VIR_DOMAIN_DEF_PARSE_INACTIVE))) goto cleanup; if (qemuDomainAssignAddresses((*vm)->def, priv->qemuCaps, *vm, true) < 0) goto cleanup; if (qemuAssignDeviceAliases((*vm)->def, priv->qemuCaps) < 0) goto cleanup; (*vm)->def->id = QEMU_HOTPLUG_TEST_DOMAIN_ID; if (qemuDomainSetPrivatePaths(&driver, *vm) < 0) goto cleanup; ret = 0; cleanup: return ret; }
static int qemuHotplugCreateObjects(virDomainXMLOptionPtr xmlopt, virDomainObjPtr *vm, const char *domxml, bool event, const char *testname) { int ret = -1; qemuDomainObjPrivatePtr priv = NULL; if (!(*vm = virDomainObjNew(xmlopt))) goto cleanup; priv = (*vm)->privateData; if (!(priv->qemuCaps = virQEMUCapsNew())) goto cleanup; /* for attach & detach qemu must support -device */ virQEMUCapsSet(priv->qemuCaps, QEMU_CAPS_DRIVE); virQEMUCapsSet(priv->qemuCaps, QEMU_CAPS_DEVICE); virQEMUCapsSet(priv->qemuCaps, QEMU_CAPS_NET_NAME); virQEMUCapsSet(priv->qemuCaps, QEMU_CAPS_VIRTIO_SCSI); virQEMUCapsSet(priv->qemuCaps, QEMU_CAPS_DEVICE_USB_STORAGE); if (event) virQEMUCapsSet(priv->qemuCaps, QEMU_CAPS_DEVICE_DEL_EVENT); ret = qemuTestCapsCacheInsert(driver.qemuCapsCache, testname, priv->qemuCaps); if (ret < 0) goto cleanup; if (!((*vm)->def = virDomainDefParseString(domxml, driver.caps, driver.xmlopt, VIR_DOMAIN_DEF_PARSE_INACTIVE))) goto cleanup; if (qemuDomainAssignAddresses((*vm)->def, priv->qemuCaps, *vm) < 0) goto cleanup; if (qemuAssignDeviceAliases((*vm)->def, priv->qemuCaps) < 0) goto cleanup; (*vm)->def->id = QEMU_HOTPLUG_TEST_DOMAIN_ID; ret = 0; cleanup: return ret; }
static int qemuHotplugCreateObjects(virDomainXMLOptionPtr xmlopt, virDomainObjPtr *vm, const char *domxml, bool event) { int ret = -1; qemuDomainObjPrivatePtr priv = NULL; if (!(*vm = virDomainObjNew(xmlopt))) goto cleanup; if (!((*vm)->def = virDomainDefParseString(domxml, driver.caps, driver.xmlopt, QEMU_EXPECTED_VIRT_TYPES, 0))) goto cleanup; priv = (*vm)->privateData; if (!(priv->qemuCaps = virQEMUCapsNew())) goto cleanup; /* for attach & detach qemu must support -device */ virQEMUCapsSet(priv->qemuCaps, QEMU_CAPS_DRIVE); virQEMUCapsSet(priv->qemuCaps, QEMU_CAPS_DEVICE); virQEMUCapsSet(priv->qemuCaps, QEMU_CAPS_NET_NAME); virQEMUCapsSet(priv->qemuCaps, QEMU_CAPS_VIRTIO_SCSI); virQEMUCapsSet(priv->qemuCaps, QEMU_CAPS_DEVICE_USB_STORAGE); if (event) virQEMUCapsSet(priv->qemuCaps, QEMU_CAPS_DEVICE_DEL_EVENT); if (qemuDomainAssignPCIAddresses((*vm)->def, priv->qemuCaps, *vm) < 0) goto cleanup; if (qemuAssignDeviceAliases((*vm)->def, priv->qemuCaps) < 0) goto cleanup; ret = 0; cleanup: return ret; }
qemuMonitorTestPtr qemuMonitorTestNew(bool json, virCapsPtr caps) { qemuMonitorTestPtr test = NULL; virDomainChrSourceDef src; char *path = NULL; char *tmpdir_template = NULL; if (VIR_ALLOC(test) < 0) goto no_memory; if (virMutexInit(&test->lock) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", "Cannot initialize mutex"); VIR_FREE(test); return NULL; } if (!(tmpdir_template = strdup("/tmp/libvirt_XXXXXX"))) goto no_memory; if (!(test->tmpdir = mkdtemp(tmpdir_template))) { virReportSystemError(errno, "%s", "Failed to create temporary directory"); goto error; } tmpdir_template = NULL; if (virAsprintf(&path, "%s/qemumonitorjsontest.sock", test->tmpdir) < 0) goto no_memory; test->json = json; if (!(test->vm = virDomainObjNew(caps))) goto error; if (virNetSocketNewListenUNIX(path, 0700, getuid(), getgid(), &test->server) < 0) goto error; memset(&src, 0, sizeof(src)); src.type = VIR_DOMAIN_CHR_TYPE_UNIX; src.data.nix.path = (char *)path; src.data.nix.listen = false; if (virNetSocketListen(test->server, 1) < 0) goto error; if (!(test->mon = qemuMonitorOpen(test->vm, &src, json ? 1 : 0, &qemuCallbacks))) goto error; qemuMonitorLock(test->mon); if (virNetSocketAccept(test->server, &test->client) < 0) goto error; if (!test->client) goto error; if (qemuMonitorTestAddReponse(test, json ? QEMU_JSON_GREETING : QEMU_TEXT_GREETING) < 0) goto error; if (virNetSocketAddIOCallback(test->client, VIR_EVENT_HANDLE_WRITABLE, qemuMonitorTestIO, test, NULL) < 0) goto error; virMutexLock(&test->lock); if (virThreadCreate(&test->thread, true, qemuMonitorTestWorker, test) < 0) { virMutexUnlock(&test->lock); goto error; } test->running = true; virMutexUnlock(&test->lock); cleanup: VIR_FREE(path); return test; no_memory: virReportOOMError(); error: VIR_FREE(tmpdir_template); qemuMonitorTestFree(test); goto cleanup; }