2013-06-21 14:27:59 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2011-2013 Red Hat, Inc.
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library. If not, see
|
|
|
|
* <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2016-02-16 15:24:35 +00:00
|
|
|
#include "qemu/qemu_alias.h"
|
2013-06-21 14:27:59 +00:00
|
|
|
#include "qemu/qemu_conf.h"
|
|
|
|
#include "qemu/qemu_hotplug.h"
|
2018-12-13 14:53:50 +00:00
|
|
|
#define LIBVIRT_QEMU_HOTPLUGPRIV_H_ALLOW
|
2013-07-26 12:22:10 +00:00
|
|
|
#include "qemu/qemu_hotplugpriv.h"
|
2013-06-21 14:27:59 +00:00
|
|
|
#include "qemumonitortestutils.h"
|
|
|
|
#include "testutils.h"
|
|
|
|
#include "testutilsqemu.h"
|
2019-06-07 11:56:14 +00:00
|
|
|
#include "testutilsqemuschema.h"
|
2019-08-29 19:19:00 +00:00
|
|
|
#include "virhostdev.h"
|
2013-06-21 14:27:59 +00:00
|
|
|
#include "virerror.h"
|
|
|
|
#include "virstring.h"
|
|
|
|
#include "virthread.h"
|
|
|
|
#include "virfile.h"
|
|
|
|
|
|
|
|
#define VIR_FROM_THIS VIR_FROM_NONE
|
|
|
|
|
|
|
|
static virQEMUDriver driver;
|
|
|
|
|
2013-07-02 08:16:30 +00:00
|
|
|
enum {
|
|
|
|
ATTACH,
|
|
|
|
DETACH,
|
|
|
|
UPDATE
|
|
|
|
};
|
|
|
|
|
2014-12-16 07:46:44 +00:00
|
|
|
#define QEMU_HOTPLUG_TEST_DOMAIN_ID 7
|
|
|
|
|
2013-06-21 14:27:59 +00:00
|
|
|
struct qemuHotplugTestData {
|
|
|
|
const char *domain_filename;
|
|
|
|
const char *device_filename;
|
|
|
|
bool fail;
|
|
|
|
const char *const *mon;
|
2013-07-02 08:16:30 +00:00
|
|
|
int action;
|
|
|
|
bool keep;
|
|
|
|
virDomainObjPtr vm;
|
2013-07-26 12:22:10 +00:00
|
|
|
bool deviceDeletedEvent;
|
2013-06-21 14:27:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
|
|
|
qemuHotplugCreateObjects(virDomainXMLOptionPtr xmlopt,
|
|
|
|
virDomainObjPtr *vm,
|
2019-02-07 11:06:12 +00:00
|
|
|
const char *domxml)
|
2013-06-21 14:27:59 +00:00
|
|
|
{
|
|
|
|
int ret = -1;
|
2013-07-02 08:16:30 +00:00
|
|
|
qemuDomainObjPrivatePtr priv = NULL;
|
2017-10-17 11:13:08 +00:00
|
|
|
const unsigned int parseFlags = 0;
|
2013-06-21 14:27:59 +00:00
|
|
|
|
|
|
|
if (!(*vm = virDomainObjNew(xmlopt)))
|
|
|
|
goto cleanup;
|
|
|
|
|
2013-07-02 08:16:30 +00:00
|
|
|
priv = (*vm)->privateData;
|
|
|
|
|
|
|
|
if (!(priv->qemuCaps = virQEMUCapsNew()))
|
|
|
|
goto cleanup;
|
|
|
|
|
2013-07-26 13:28:33 +00:00
|
|
|
virQEMUCapsSet(priv->qemuCaps, QEMU_CAPS_VIRTIO_SCSI);
|
2013-08-23 10:38:10 +00:00
|
|
|
virQEMUCapsSet(priv->qemuCaps, QEMU_CAPS_DEVICE_USB_STORAGE);
|
2018-05-07 14:41:11 +00:00
|
|
|
virQEMUCapsSet(priv->qemuCaps, QEMU_CAPS_CCW);
|
2016-09-12 13:40:48 +00:00
|
|
|
virQEMUCapsSet(priv->qemuCaps, QEMU_CAPS_DEVICE_IVSHMEM_PLAIN);
|
|
|
|
virQEMUCapsSet(priv->qemuCaps, QEMU_CAPS_DEVICE_IVSHMEM_DOORBELL);
|
2017-06-23 12:11:25 +00:00
|
|
|
virQEMUCapsSet(priv->qemuCaps, QEMU_CAPS_SCSI_DISK_WWN);
|
2019-08-29 19:19:00 +00:00
|
|
|
virQEMUCapsSet(priv->qemuCaps, QEMU_CAPS_DEVICE_VFIO_PCI);
|
|
|
|
virQEMUCapsSet(priv->qemuCaps, QEMU_CAPS_DEVICE_SPAPR_PCI_HOST_BRIDGE);
|
2013-07-18 09:21:34 +00:00
|
|
|
|
2017-04-11 12:02:06 +00:00
|
|
|
if (qemuTestCapsCacheInsert(driver.qemuCapsCache, priv->qemuCaps) < 0)
|
2015-09-09 14:03:15 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (!((*vm)->def = virDomainDefParseString(domxml,
|
|
|
|
driver.caps,
|
|
|
|
driver.xmlopt,
|
2016-09-22 15:14:17 +00:00
|
|
|
NULL,
|
2017-10-17 11:13:08 +00:00
|
|
|
parseFlags)))
|
2015-09-09 14:03:15 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2016-11-03 20:33:32 +00:00
|
|
|
if (qemuDomainAssignAddresses((*vm)->def, priv->qemuCaps,
|
|
|
|
&driver, *vm, true) < 0) {
|
2013-07-18 09:21:34 +00:00
|
|
|
goto cleanup;
|
2016-11-03 20:33:32 +00:00
|
|
|
}
|
2013-07-18 09:21:34 +00:00
|
|
|
|
|
|
|
if (qemuAssignDeviceAliases((*vm)->def, priv->qemuCaps) < 0)
|
|
|
|
goto cleanup;
|
2013-07-02 08:16:30 +00:00
|
|
|
|
2014-12-16 07:46:44 +00:00
|
|
|
(*vm)->def->id = QEMU_HOTPLUG_TEST_DOMAIN_ID;
|
|
|
|
|
2016-03-30 07:01:11 +00:00
|
|
|
if (qemuDomainSetPrivatePaths(&driver, *vm) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2013-06-21 14:27:59 +00:00
|
|
|
ret = 0;
|
2014-03-25 06:53:44 +00:00
|
|
|
cleanup:
|
2013-06-21 14:27:59 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-07-02 08:16:30 +00:00
|
|
|
static int
|
|
|
|
testQemuHotplugAttach(virDomainObjPtr vm,
|
|
|
|
virDomainDeviceDefPtr dev)
|
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
switch (dev->type) {
|
2013-07-18 09:21:34 +00:00
|
|
|
case VIR_DOMAIN_DEVICE_DISK:
|
|
|
|
/* conn in only used for storage pool and secrets lookup so as long
|
|
|
|
* as we don't use any of them, passing NULL should be safe
|
|
|
|
*/
|
2018-09-25 12:21:27 +00:00
|
|
|
ret = qemuDomainAttachDeviceDiskLive(&driver, vm, dev);
|
2013-07-18 09:21:34 +00:00
|
|
|
break;
|
2013-07-02 08:16:30 +00:00
|
|
|
case VIR_DOMAIN_DEVICE_CHR:
|
2018-02-09 16:14:41 +00:00
|
|
|
ret = qemuDomainAttachChrDevice(&driver, vm, dev->data.chr);
|
2013-07-02 08:16:30 +00:00
|
|
|
break;
|
2016-09-12 13:40:48 +00:00
|
|
|
case VIR_DOMAIN_DEVICE_SHMEM:
|
|
|
|
ret = qemuDomainAttachShmemDevice(&driver, vm, dev->data.shmem);
|
|
|
|
break;
|
2017-09-01 11:39:15 +00:00
|
|
|
case VIR_DOMAIN_DEVICE_WATCHDOG:
|
|
|
|
ret = qemuDomainAttachWatchdog(&driver, vm, dev->data.watchdog);
|
|
|
|
break;
|
2019-08-29 19:19:00 +00:00
|
|
|
case VIR_DOMAIN_DEVICE_HOSTDEV:
|
|
|
|
ret = qemuDomainAttachHostDevice(&driver, vm, dev->data.hostdev);
|
|
|
|
break;
|
2013-07-02 08:16:30 +00:00
|
|
|
default:
|
2019-05-03 08:45:58 +00:00
|
|
|
VIR_TEST_VERBOSE("device type '%s' cannot be attached",
|
2015-04-23 17:38:00 +00:00
|
|
|
virDomainDeviceTypeToString(dev->type));
|
2013-07-02 08:16:30 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
testQemuHotplugDetach(virDomainObjPtr vm,
|
2018-05-23 16:01:16 +00:00
|
|
|
virDomainDeviceDefPtr dev,
|
|
|
|
bool async)
|
2013-07-02 08:16:30 +00:00
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
switch (dev->type) {
|
2013-07-18 09:21:34 +00:00
|
|
|
case VIR_DOMAIN_DEVICE_DISK:
|
2013-07-02 08:16:30 +00:00
|
|
|
case VIR_DOMAIN_DEVICE_CHR:
|
2016-09-12 13:40:48 +00:00
|
|
|
case VIR_DOMAIN_DEVICE_SHMEM:
|
2017-09-05 09:08:36 +00:00
|
|
|
case VIR_DOMAIN_DEVICE_WATCHDOG:
|
2019-08-29 19:19:00 +00:00
|
|
|
case VIR_DOMAIN_DEVICE_HOSTDEV:
|
2019-03-19 18:47:40 +00:00
|
|
|
ret = qemuDomainDetachDeviceLive(vm, dev, &driver, async);
|
2017-09-05 09:08:36 +00:00
|
|
|
break;
|
2013-07-02 08:16:30 +00:00
|
|
|
default:
|
2019-05-03 08:45:58 +00:00
|
|
|
VIR_TEST_VERBOSE("device type '%s' cannot be detached",
|
2015-04-23 17:38:00 +00:00
|
|
|
virDomainDeviceTypeToString(dev->type));
|
2013-07-02 08:16:30 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
testQemuHotplugUpdate(virDomainObjPtr vm,
|
|
|
|
virDomainDeviceDefPtr dev)
|
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
/* XXX Ideally, we would call qemuDomainUpdateDeviceLive here. But that
|
|
|
|
* would require us to provide virConnectPtr and virDomainPtr (they're used
|
|
|
|
* in case of updating a disk device. So for now, we will proceed with
|
|
|
|
* breaking the function into pieces. If we ever learn how to fake those
|
|
|
|
* required object, we can replace this code then. */
|
|
|
|
switch (dev->type) {
|
|
|
|
case VIR_DOMAIN_DEVICE_GRAPHICS:
|
|
|
|
ret = qemuDomainChangeGraphics(&driver, vm, dev->data.graphics);
|
|
|
|
break;
|
|
|
|
default:
|
2019-05-03 08:45:58 +00:00
|
|
|
VIR_TEST_VERBOSE("device type '%s' cannot be updated",
|
2015-04-23 17:38:00 +00:00
|
|
|
virDomainDeviceTypeToString(dev->type));
|
2013-07-02 08:16:30 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-07-18 14:46:13 +00:00
|
|
|
static int
|
|
|
|
testQemuHotplugCheckResult(virDomainObjPtr vm,
|
|
|
|
const char *expected,
|
2015-12-10 13:12:13 +00:00
|
|
|
const char *expectedFile,
|
2013-07-18 14:46:13 +00:00
|
|
|
bool fail)
|
|
|
|
{
|
|
|
|
char *actual;
|
|
|
|
int ret;
|
|
|
|
|
2016-02-03 21:40:35 +00:00
|
|
|
actual = virDomainDefFormat(vm->def, driver.caps,
|
|
|
|
VIR_DOMAIN_DEF_FORMAT_SECURE);
|
2013-07-18 14:46:13 +00:00
|
|
|
if (!actual)
|
|
|
|
return -1;
|
2014-12-16 07:46:44 +00:00
|
|
|
vm->def->id = QEMU_HOTPLUG_TEST_DOMAIN_ID;
|
2013-07-18 14:46:13 +00:00
|
|
|
|
|
|
|
if (STREQ(expected, actual)) {
|
2015-04-23 17:38:00 +00:00
|
|
|
if (fail)
|
2019-05-03 08:45:58 +00:00
|
|
|
VIR_TEST_VERBOSE("domain XML should not match the expected result");
|
2013-07-18 14:46:13 +00:00
|
|
|
ret = 0;
|
|
|
|
} else {
|
|
|
|
if (!fail)
|
2016-05-26 15:01:54 +00:00
|
|
|
virTestDifferenceFull(stderr,
|
|
|
|
expected, expectedFile,
|
|
|
|
actual, NULL);
|
2013-07-18 14:46:13 +00:00
|
|
|
ret = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
VIR_FREE(actual);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-06-21 14:27:59 +00:00
|
|
|
static int
|
|
|
|
testQemuHotplug(const void *data)
|
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
struct qemuHotplugTestData *test = (struct qemuHotplugTestData *) data;
|
|
|
|
char *domain_filename = NULL;
|
|
|
|
char *device_filename = NULL;
|
2013-07-18 14:46:13 +00:00
|
|
|
char *result_filename = NULL;
|
|
|
|
char *domain_xml = NULL;
|
2013-06-21 14:27:59 +00:00
|
|
|
char *device_xml = NULL;
|
2013-07-18 14:46:13 +00:00
|
|
|
char *result_xml = NULL;
|
2013-06-21 14:27:59 +00:00
|
|
|
const char *const *tmp;
|
|
|
|
bool fail = test->fail;
|
2013-07-02 08:16:30 +00:00
|
|
|
bool keep = test->keep;
|
2014-03-19 14:46:07 +00:00
|
|
|
unsigned int device_parse_flags = 0;
|
2013-06-21 14:27:59 +00:00
|
|
|
virDomainObjPtr vm = NULL;
|
|
|
|
virDomainDeviceDefPtr dev = NULL;
|
|
|
|
virCapsPtr caps = NULL;
|
|
|
|
qemuMonitorTestPtr test_mon = NULL;
|
|
|
|
qemuDomainObjPrivatePtr priv = NULL;
|
|
|
|
|
2016-07-07 22:53:19 +00:00
|
|
|
if (virAsprintf(&domain_filename, "%s/qemuhotplugtestdomains/qemuhotplug-%s.xml",
|
2013-06-21 14:27:59 +00:00
|
|
|
abs_srcdir, test->domain_filename) < 0 ||
|
2016-07-07 22:53:19 +00:00
|
|
|
virAsprintf(&device_filename, "%s/qemuhotplugtestdevices/qemuhotplug-%s.xml",
|
2013-07-18 14:46:13 +00:00
|
|
|
abs_srcdir, test->device_filename) < 0 ||
|
|
|
|
virAsprintf(&result_filename,
|
2016-07-07 22:53:19 +00:00
|
|
|
"%s/qemuhotplugtestdomains/qemuhotplug-%s+%s.xml",
|
2013-07-18 14:46:13 +00:00
|
|
|
abs_srcdir, test->domain_filename,
|
|
|
|
test->device_filename) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2016-05-26 15:01:52 +00:00
|
|
|
if (virTestLoadFile(domain_filename, &domain_xml) < 0 ||
|
|
|
|
virTestLoadFile(device_filename, &device_xml) < 0)
|
2013-07-18 14:46:13 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2016-09-15 08:58:17 +00:00
|
|
|
if (test->action == ATTACH &&
|
2016-05-26 15:01:52 +00:00
|
|
|
virTestLoadFile(result_filename, &result_xml) < 0)
|
2013-06-21 14:27:59 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (!(caps = virQEMUDriverGetCapabilities(&driver, false)))
|
|
|
|
goto cleanup;
|
|
|
|
|
2013-07-02 08:16:30 +00:00
|
|
|
if (test->vm) {
|
|
|
|
vm = test->vm;
|
2017-06-29 13:20:54 +00:00
|
|
|
if (!vm->def) {
|
2019-05-03 08:45:58 +00:00
|
|
|
VIR_TEST_VERBOSE("test skipped due to failure of dependent test");
|
2017-06-29 13:20:54 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
2013-07-02 08:16:30 +00:00
|
|
|
} else {
|
2019-02-07 11:06:12 +00:00
|
|
|
if (qemuHotplugCreateObjects(driver.xmlopt, &vm, domain_xml) < 0)
|
2013-07-02 08:16:30 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
2013-06-21 14:27:59 +00:00
|
|
|
|
2014-03-19 14:46:07 +00:00
|
|
|
if (test->action == ATTACH)
|
2014-11-18 16:44:00 +00:00
|
|
|
device_parse_flags = VIR_DOMAIN_DEF_PARSE_INACTIVE;
|
2014-03-19 14:46:07 +00:00
|
|
|
|
2013-06-21 14:27:59 +00:00
|
|
|
if (!(dev = virDomainDeviceDefParse(device_xml, vm->def,
|
2019-08-08 13:36:00 +00:00
|
|
|
caps, driver.xmlopt, NULL,
|
2014-03-19 14:46:07 +00:00
|
|
|
device_parse_flags)))
|
2013-06-21 14:27:59 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
/* Now is the best time to feed the spoofed monitor with predefined
|
|
|
|
* replies. */
|
2019-06-14 18:14:23 +00:00
|
|
|
if (!(test_mon = qemuMonitorTestNew(driver.xmlopt, vm, &driver,
|
2018-03-22 18:05:26 +00:00
|
|
|
NULL, NULL)))
|
2013-06-21 14:27:59 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
tmp = test->mon;
|
|
|
|
while (tmp && *tmp) {
|
|
|
|
const char *command_name;
|
|
|
|
const char *response;
|
|
|
|
|
|
|
|
if (!(command_name = *tmp++) ||
|
|
|
|
!(response = *tmp++))
|
|
|
|
break;
|
|
|
|
if (qemuMonitorTestAddItem(test_mon, command_name, response) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2013-07-02 08:16:30 +00:00
|
|
|
priv = vm->privateData;
|
2013-06-21 14:27:59 +00:00
|
|
|
priv->mon = qemuMonitorTestGetMonitor(test_mon);
|
|
|
|
|
|
|
|
/* XXX We need to unlock the monitor here, as
|
|
|
|
* qemuDomainObjEnterMonitorInternal (called from qemuDomainChangeGraphics)
|
|
|
|
* tries to lock it again */
|
|
|
|
virObjectUnlock(priv->mon);
|
|
|
|
|
2013-07-02 08:16:30 +00:00
|
|
|
switch (test->action) {
|
|
|
|
case ATTACH:
|
|
|
|
ret = testQemuHotplugAttach(vm, dev);
|
2013-07-18 09:21:34 +00:00
|
|
|
if (ret == 0) {
|
|
|
|
/* vm->def stolen dev->data.* so we just need to free the dev
|
|
|
|
* envelope */
|
|
|
|
VIR_FREE(dev);
|
|
|
|
}
|
2013-07-18 14:46:13 +00:00
|
|
|
if (ret == 0 || fail)
|
2015-12-10 13:12:13 +00:00
|
|
|
ret = testQemuHotplugCheckResult(vm, result_xml,
|
|
|
|
result_filename, fail);
|
2013-06-21 14:27:59 +00:00
|
|
|
break;
|
2013-07-02 08:16:30 +00:00
|
|
|
|
|
|
|
case DETACH:
|
2018-05-23 16:01:16 +00:00
|
|
|
ret = testQemuHotplugDetach(vm, dev, false);
|
2013-07-18 14:46:13 +00:00
|
|
|
if (ret == 0 || fail)
|
2015-12-10 13:12:13 +00:00
|
|
|
ret = testQemuHotplugCheckResult(vm, domain_xml,
|
|
|
|
domain_filename, fail);
|
2013-06-21 14:27:59 +00:00
|
|
|
break;
|
2013-07-02 08:16:30 +00:00
|
|
|
|
|
|
|
case UPDATE:
|
|
|
|
ret = testQemuHotplugUpdate(vm, dev);
|
2013-06-21 14:27:59 +00:00
|
|
|
}
|
|
|
|
|
2014-03-25 06:53:44 +00:00
|
|
|
cleanup:
|
2013-06-21 14:27:59 +00:00
|
|
|
VIR_FREE(domain_filename);
|
|
|
|
VIR_FREE(device_filename);
|
2013-07-18 14:46:13 +00:00
|
|
|
VIR_FREE(result_filename);
|
|
|
|
VIR_FREE(domain_xml);
|
2013-06-21 14:27:59 +00:00
|
|
|
VIR_FREE(device_xml);
|
2013-07-18 14:46:13 +00:00
|
|
|
VIR_FREE(result_xml);
|
2013-06-21 14:27:59 +00:00
|
|
|
/* don't dispose test monitor with VM */
|
|
|
|
if (priv)
|
|
|
|
priv->mon = NULL;
|
2013-07-02 08:16:30 +00:00
|
|
|
if (keep) {
|
|
|
|
test->vm = vm;
|
|
|
|
} else {
|
|
|
|
virObjectUnref(vm);
|
|
|
|
test->vm = NULL;
|
|
|
|
}
|
2013-06-21 14:27:59 +00:00
|
|
|
virDomainDeviceDefFree(dev);
|
|
|
|
virObjectUnref(caps);
|
|
|
|
qemuMonitorTestFree(test_mon);
|
|
|
|
return ((ret < 0 && fail) || (!ret && !fail)) ? 0 : -1;
|
|
|
|
}
|
|
|
|
|
2016-12-04 18:08:25 +00:00
|
|
|
|
|
|
|
struct testQemuHotplugCpuData {
|
|
|
|
char *file_xml_dom;
|
|
|
|
char *file_xml_res_live;
|
|
|
|
char *file_xml_res_conf;
|
|
|
|
char *file_json_monitor;
|
|
|
|
|
|
|
|
char *xml_dom;
|
|
|
|
|
|
|
|
virDomainObjPtr vm;
|
|
|
|
qemuMonitorTestPtr mon;
|
|
|
|
bool modern;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
testQemuHotplugCpuDataFree(struct testQemuHotplugCpuData *data)
|
|
|
|
{
|
2017-02-02 15:42:18 +00:00
|
|
|
qemuDomainObjPrivatePtr priv;
|
|
|
|
|
2016-12-04 18:08:25 +00:00
|
|
|
if (!data)
|
|
|
|
return;
|
|
|
|
|
|
|
|
VIR_FREE(data->file_xml_dom);
|
|
|
|
VIR_FREE(data->file_xml_res_live);
|
|
|
|
VIR_FREE(data->file_xml_res_conf);
|
|
|
|
VIR_FREE(data->file_json_monitor);
|
|
|
|
|
|
|
|
VIR_FREE(data->xml_dom);
|
|
|
|
|
2017-02-02 15:42:18 +00:00
|
|
|
if (data->vm) {
|
|
|
|
priv = data->vm->privateData;
|
|
|
|
priv->mon = NULL;
|
|
|
|
|
|
|
|
virObjectUnref(data->vm);
|
|
|
|
}
|
|
|
|
|
2016-12-04 18:08:25 +00:00
|
|
|
qemuMonitorTestFree(data->mon);
|
2017-02-02 14:57:29 +00:00
|
|
|
VIR_FREE(data);
|
2016-12-04 18:08:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static struct testQemuHotplugCpuData *
|
|
|
|
testQemuHotplugCpuPrepare(const char *test,
|
2019-06-07 11:56:14 +00:00
|
|
|
bool modern,
|
|
|
|
virHashTablePtr qmpschema)
|
2016-12-04 18:08:25 +00:00
|
|
|
{
|
|
|
|
qemuDomainObjPrivatePtr priv = NULL;
|
|
|
|
virCapsPtr caps = NULL;
|
|
|
|
char *prefix = NULL;
|
|
|
|
struct testQemuHotplugCpuData *data = NULL;
|
|
|
|
|
|
|
|
if (virAsprintf(&prefix, "%s/qemuhotplugtestcpus/%s", abs_srcdir, test) < 0)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (VIR_ALLOC(data) < 0)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
data->modern = modern;
|
|
|
|
|
|
|
|
if (virAsprintf(&data->file_xml_dom, "%s-domain.xml", prefix) < 0 ||
|
|
|
|
virAsprintf(&data->file_xml_res_live, "%s-result-live.xml", prefix) < 0 ||
|
|
|
|
virAsprintf(&data->file_xml_res_conf, "%s-result-conf.xml", prefix) < 0 ||
|
|
|
|
virAsprintf(&data->file_json_monitor, "%s-monitor.json", prefix) < 0)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
if (virTestLoadFile(data->file_xml_dom, &data->xml_dom) < 0)
|
|
|
|
goto error;
|
|
|
|
|
2019-02-07 11:06:12 +00:00
|
|
|
if (qemuHotplugCreateObjects(driver.xmlopt, &data->vm, data->xml_dom) < 0)
|
2016-12-04 18:08:25 +00:00
|
|
|
goto error;
|
|
|
|
|
|
|
|
if (!(caps = virQEMUDriverGetCapabilities(&driver, false)))
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
/* create vm->newDef */
|
|
|
|
data->vm->persistent = true;
|
2019-08-06 11:41:42 +00:00
|
|
|
if (virDomainObjSetDefTransient(caps, driver.xmlopt, data->vm, NULL) < 0)
|
2016-12-04 18:08:25 +00:00
|
|
|
goto error;
|
|
|
|
|
|
|
|
priv = data->vm->privateData;
|
|
|
|
|
|
|
|
if (data->modern)
|
|
|
|
virQEMUCapsSet(priv->qemuCaps, QEMU_CAPS_QUERY_HOTPLUGGABLE_CPUS);
|
|
|
|
|
|
|
|
if (!(data->mon = qemuMonitorTestNewFromFileFull(data->file_json_monitor,
|
2019-06-07 11:56:14 +00:00
|
|
|
&driver, data->vm, qmpschema)))
|
2016-12-04 18:08:25 +00:00
|
|
|
goto error;
|
|
|
|
|
|
|
|
priv->mon = qemuMonitorTestGetMonitor(data->mon);
|
|
|
|
virObjectUnlock(priv->mon);
|
|
|
|
|
|
|
|
if (qemuDomainRefreshVcpuInfo(&driver, data->vm, 0, false) < 0)
|
|
|
|
goto error;
|
|
|
|
|
2017-02-02 14:57:29 +00:00
|
|
|
VIR_FREE(prefix);
|
|
|
|
|
2016-12-04 18:08:25 +00:00
|
|
|
return data;
|
|
|
|
|
|
|
|
error:
|
|
|
|
virObjectUnref(caps);
|
|
|
|
testQemuHotplugCpuDataFree(data);
|
|
|
|
VIR_FREE(prefix);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
testQemuHotplugCpuFinalize(struct testQemuHotplugCpuData *data)
|
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
char *activeXML = NULL;
|
|
|
|
char *configXML = NULL;
|
|
|
|
|
|
|
|
if (data->file_xml_res_live) {
|
|
|
|
if (!(activeXML = virDomainDefFormat(data->vm->def, driver.caps,
|
|
|
|
VIR_DOMAIN_DEF_FORMAT_SECURE)))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (virTestCompareToFile(activeXML, data->file_xml_res_live) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (data->file_xml_res_conf) {
|
|
|
|
if (!(configXML = virDomainDefFormat(data->vm->newDef, driver.caps,
|
|
|
|
VIR_DOMAIN_DEF_FORMAT_SECURE |
|
|
|
|
VIR_DOMAIN_DEF_FORMAT_INACTIVE)))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (virTestCompareToFile(configXML, data->file_xml_res_conf) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
VIR_FREE(activeXML);
|
|
|
|
VIR_FREE(configXML);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
struct testQemuHotplugCpuParams {
|
|
|
|
const char *test;
|
|
|
|
int newcpus;
|
2017-02-10 16:14:22 +00:00
|
|
|
const char *cpumap;
|
|
|
|
bool state;
|
2016-12-04 18:08:25 +00:00
|
|
|
bool modern;
|
|
|
|
bool fail;
|
2019-06-07 11:56:14 +00:00
|
|
|
virHashTablePtr schema;
|
2016-12-04 18:08:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
testQemuHotplugCpuGroup(const void *opaque)
|
|
|
|
{
|
|
|
|
const struct testQemuHotplugCpuParams *params = opaque;
|
|
|
|
struct testQemuHotplugCpuData *data = NULL;
|
|
|
|
int ret = -1;
|
|
|
|
int rc;
|
|
|
|
|
2019-06-07 11:56:14 +00:00
|
|
|
if (!(data = testQemuHotplugCpuPrepare(params->test, params->modern,
|
|
|
|
params->schema)))
|
2016-12-04 18:08:25 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
rc = qemuDomainSetVcpusInternal(&driver, data->vm, data->vm->def,
|
|
|
|
data->vm->newDef, params->newcpus,
|
|
|
|
params->modern);
|
|
|
|
|
|
|
|
if (params->fail) {
|
|
|
|
if (rc == 0)
|
|
|
|
fprintf(stderr, "cpu test '%s' should have failed\n", params->test);
|
|
|
|
else
|
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
goto cleanup;
|
|
|
|
} else {
|
|
|
|
if (rc < 0)
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = testQemuHotplugCpuFinalize(data);
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
testQemuHotplugCpuDataFree(data);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-02-10 16:14:22 +00:00
|
|
|
static int
|
|
|
|
testQemuHotplugCpuIndividual(const void *opaque)
|
|
|
|
{
|
|
|
|
const struct testQemuHotplugCpuParams *params = opaque;
|
|
|
|
struct testQemuHotplugCpuData *data = NULL;
|
|
|
|
virBitmapPtr map = NULL;
|
|
|
|
int ret = -1;
|
|
|
|
int rc;
|
|
|
|
|
2019-06-07 11:56:14 +00:00
|
|
|
if (!(data = testQemuHotplugCpuPrepare(params->test, params->modern,
|
|
|
|
params->schema)))
|
2017-02-10 16:14:22 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (virBitmapParse(params->cpumap, &map, 128) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
rc = qemuDomainSetVcpuInternal(&driver, data->vm, data->vm->def,
|
|
|
|
data->vm->newDef, map, params->state);
|
|
|
|
|
|
|
|
if (params->fail) {
|
|
|
|
if (rc == 0)
|
|
|
|
fprintf(stderr, "cpu test '%s' should have failed\n", params->test);
|
|
|
|
else
|
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
goto cleanup;
|
|
|
|
} else {
|
|
|
|
if (rc < 0)
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = testQemuHotplugCpuFinalize(data);
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
virBitmapFree(map);
|
|
|
|
testQemuHotplugCpuDataFree(data);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2019-08-29 19:19:00 +00:00
|
|
|
#define FAKEROOTDIRTEMPLATE abs_builddir "/fakerootdir-XXXXXX"
|
2017-02-10 16:14:22 +00:00
|
|
|
|
|
|
|
|
2013-06-21 14:27:59 +00:00
|
|
|
static int
|
|
|
|
mymain(void)
|
|
|
|
{
|
2019-06-07 11:56:14 +00:00
|
|
|
VIR_AUTOPTR(virHashTable) qmpschema = NULL;
|
2013-06-21 14:27:59 +00:00
|
|
|
int ret = 0;
|
2013-07-02 08:16:30 +00:00
|
|
|
struct qemuHotplugTestData data = {0};
|
2016-12-04 18:08:25 +00:00
|
|
|
struct testQemuHotplugCpuParams cpudata;
|
2019-08-29 19:19:00 +00:00
|
|
|
char *fakerootdir;
|
|
|
|
|
|
|
|
if (VIR_STRDUP_QUIET(fakerootdir, FAKEROOTDIRTEMPLATE) < 0) {
|
|
|
|
fprintf(stderr, "Out of memory\n");
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mkdtemp(fakerootdir)) {
|
|
|
|
fprintf(stderr, "Cannot create fakerootdir");
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
|
|
|
|
setenv("LIBVIRT_FAKE_ROOT_DIR", fakerootdir, 1);
|
2013-06-21 14:27:59 +00:00
|
|
|
|
2018-08-13 11:40:18 +00:00
|
|
|
#if !WITH_YAJL
|
2018-05-09 14:42:43 +00:00
|
|
|
fputs("libvirt not compiled with JSON support, skipping this test\n", stderr);
|
2013-06-21 14:27:59 +00:00
|
|
|
return EXIT_AM_SKIP;
|
|
|
|
#endif
|
|
|
|
|
2019-09-16 16:44:23 +00:00
|
|
|
if (qemuTestDriverInit(&driver) < 0)
|
2013-06-21 14:27:59 +00:00
|
|
|
return EXIT_FAILURE;
|
|
|
|
|
|
|
|
virEventRegisterDefaultImpl();
|
|
|
|
|
|
|
|
VIR_FREE(driver.config->spiceListen);
|
|
|
|
VIR_FREE(driver.config->vncListen);
|
2013-07-18 09:21:34 +00:00
|
|
|
/* some dummy values from 'config file' */
|
|
|
|
if (VIR_STRDUP_QUIET(driver.config->spicePassword, "123456") < 0)
|
|
|
|
return EXIT_FAILURE;
|
2013-06-21 14:27:59 +00:00
|
|
|
|
2013-11-21 10:43:10 +00:00
|
|
|
if (!(driver.domainEventState = virObjectEventStateNew()))
|
2013-07-11 15:30:56 +00:00
|
|
|
return EXIT_FAILURE;
|
|
|
|
|
2019-06-07 11:56:14 +00:00
|
|
|
if (!(qmpschema = testQEMUSchemaLoad())) {
|
|
|
|
VIR_TEST_VERBOSE("failed to load qapi schema\n");
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
cpudata.schema = qmpschema;
|
|
|
|
|
2013-07-18 09:21:34 +00:00
|
|
|
driver.lockManager = virLockManagerPluginNew("nop", "qemu",
|
|
|
|
driver.config->configBaseDir,
|
|
|
|
0);
|
|
|
|
if (!driver.lockManager)
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
|
2019-08-29 19:19:00 +00:00
|
|
|
driver.hostdevMgr = virHostdevManagerGetDefault();
|
|
|
|
|
2013-07-26 12:22:10 +00:00
|
|
|
/* wait only 100ms for DEVICE_DELETED event */
|
|
|
|
qemuDomainRemoveDeviceWaitTime = 100;
|
|
|
|
|
2019-02-07 11:06:12 +00:00
|
|
|
#define DO_TEST(file, ACTION, dev, fial, kep, ...) \
|
2017-11-03 12:09:47 +00:00
|
|
|
do { \
|
|
|
|
const char *my_mon[] = { __VA_ARGS__, NULL}; \
|
|
|
|
const char *name = file " " #ACTION " " dev; \
|
|
|
|
data.action = ACTION; \
|
|
|
|
data.domain_filename = file; \
|
|
|
|
data.device_filename = dev; \
|
|
|
|
data.fail = fial; \
|
|
|
|
data.mon = my_mon; \
|
|
|
|
data.keep = kep; \
|
|
|
|
if (virTestRun(name, testQemuHotplug, &data) < 0) \
|
|
|
|
ret = -1; \
|
2013-07-18 09:07:21 +00:00
|
|
|
} while (0)
|
2013-07-02 08:16:30 +00:00
|
|
|
|
2017-11-03 12:09:47 +00:00
|
|
|
#define DO_TEST_ATTACH(file, dev, fial, kep, ...) \
|
2019-02-07 11:06:12 +00:00
|
|
|
DO_TEST(file, ATTACH, dev, fial, kep, __VA_ARGS__)
|
2013-07-02 08:16:30 +00:00
|
|
|
|
2017-11-03 12:09:47 +00:00
|
|
|
#define DO_TEST_DETACH(file, dev, fial, kep, ...) \
|
2019-02-07 11:06:12 +00:00
|
|
|
DO_TEST(file, DETACH, dev, fial, kep, __VA_ARGS__)
|
2013-07-26 12:22:10 +00:00
|
|
|
|
2017-11-03 12:09:47 +00:00
|
|
|
#define DO_TEST_UPDATE(file, dev, fial, kep, ...) \
|
2019-02-07 11:06:12 +00:00
|
|
|
DO_TEST(file, UPDATE, dev, fial, kep, __VA_ARGS__)
|
2013-06-21 14:27:59 +00:00
|
|
|
|
2013-07-26 13:06:37 +00:00
|
|
|
|
|
|
|
#define QMP_OK "{\"return\": {}}"
|
2013-07-18 09:21:34 +00:00
|
|
|
#define HMP(msg) "{\"return\": \"" msg "\"}"
|
2013-07-26 13:06:37 +00:00
|
|
|
|
2013-07-19 11:04:44 +00:00
|
|
|
#define QMP_DEVICE_DELETED(dev) \
|
2017-11-03 12:09:47 +00:00
|
|
|
"{" \
|
|
|
|
" \"timestamp\": {" \
|
|
|
|
" \"seconds\": 1374137171," \
|
|
|
|
" \"microseconds\": 2659" \
|
|
|
|
" }," \
|
|
|
|
" \"event\": \"DEVICE_DELETED\"," \
|
|
|
|
" \"data\": {" \
|
|
|
|
" \"device\": \"" dev "\"," \
|
|
|
|
" \"path\": \"/machine/peripheral/" dev "\"" \
|
|
|
|
" }" \
|
2013-07-19 11:04:44 +00:00
|
|
|
"}\r\n"
|
|
|
|
|
2013-07-02 08:16:30 +00:00
|
|
|
DO_TEST_UPDATE("graphics-spice", "graphics-spice-nochange", false, false, NULL);
|
|
|
|
DO_TEST_UPDATE("graphics-spice-timeout", "graphics-spice-timeout-nochange", false, false,
|
2013-07-26 13:06:37 +00:00
|
|
|
"set_password", QMP_OK, "expire_password", QMP_OK);
|
2013-07-02 08:16:30 +00:00
|
|
|
DO_TEST_UPDATE("graphics-spice-timeout", "graphics-spice-timeout-password", false, false,
|
2013-07-26 13:06:37 +00:00
|
|
|
"set_password", QMP_OK, "expire_password", QMP_OK);
|
2013-07-02 08:16:30 +00:00
|
|
|
DO_TEST_UPDATE("graphics-spice", "graphics-spice-listen", true, false, NULL);
|
2016-07-07 22:52:41 +00:00
|
|
|
DO_TEST_UPDATE("graphics-spice-listen-network", "graphics-spice-listen-network-password", false, false,
|
2013-07-26 13:06:37 +00:00
|
|
|
"set_password", QMP_OK, "expire_password", QMP_OK);
|
2013-07-02 08:16:30 +00:00
|
|
|
/* Strange huh? Currently, only graphics can be updated :-P */
|
|
|
|
DO_TEST_UPDATE("disk-cdrom", "disk-cdrom-nochange", true, false, NULL);
|
|
|
|
|
2016-03-30 07:01:11 +00:00
|
|
|
DO_TEST_ATTACH("console-compat-2-live", "console-virtio", false, true,
|
2013-07-02 08:16:30 +00:00
|
|
|
"chardev-add", "{\"return\": {\"pty\": \"/dev/pts/26\"}}",
|
2013-07-26 13:06:37 +00:00
|
|
|
"device_add", QMP_OK);
|
2013-07-02 08:16:30 +00:00
|
|
|
|
2016-03-30 07:01:11 +00:00
|
|
|
DO_TEST_DETACH("console-compat-2-live", "console-virtio", false, false,
|
2019-02-07 10:55:12 +00:00
|
|
|
"device_del", QMP_DEVICE_DELETED("console1") QMP_OK,
|
2013-07-26 13:06:37 +00:00
|
|
|
"chardev-remove", QMP_OK);
|
2013-06-21 14:27:59 +00:00
|
|
|
|
2019-02-07 11:06:12 +00:00
|
|
|
DO_TEST_ATTACH("base-live", "disk-virtio", false, true,
|
|
|
|
"human-monitor-command", HMP("OK\\r\\n"),
|
|
|
|
"device_add", QMP_OK);
|
2016-07-07 22:52:41 +00:00
|
|
|
DO_TEST_DETACH("base-live", "disk-virtio", true, true,
|
2013-07-19 11:04:44 +00:00
|
|
|
"device_del", QMP_OK,
|
|
|
|
"human-monitor-command", HMP(""));
|
2016-07-07 22:52:41 +00:00
|
|
|
DO_TEST_DETACH("base-live", "disk-virtio", false, false,
|
2013-07-19 11:04:44 +00:00
|
|
|
"device_del", QMP_DEVICE_DELETED("virtio-disk4") QMP_OK,
|
|
|
|
"human-monitor-command", HMP(""));
|
|
|
|
|
2019-02-07 11:06:12 +00:00
|
|
|
DO_TEST_ATTACH("base-live", "disk-usb", false, true,
|
|
|
|
"human-monitor-command", HMP("OK\\r\\n"),
|
|
|
|
"device_add", QMP_OK);
|
2016-07-07 22:52:41 +00:00
|
|
|
DO_TEST_DETACH("base-live", "disk-usb", true, true,
|
2013-07-26 12:44:52 +00:00
|
|
|
"device_del", QMP_OK,
|
|
|
|
"human-monitor-command", HMP(""));
|
2016-07-07 22:52:41 +00:00
|
|
|
DO_TEST_DETACH("base-live", "disk-usb", false, false,
|
2013-07-26 12:44:52 +00:00
|
|
|
"device_del", QMP_DEVICE_DELETED("usb-disk16") QMP_OK,
|
|
|
|
"human-monitor-command", HMP(""));
|
|
|
|
|
2019-02-07 11:06:12 +00:00
|
|
|
DO_TEST_ATTACH("base-live", "disk-scsi", false, true,
|
|
|
|
"human-monitor-command", HMP("OK\\r\\n"),
|
|
|
|
"device_add", QMP_OK);
|
2016-07-07 22:52:41 +00:00
|
|
|
DO_TEST_DETACH("base-live", "disk-scsi", true, true,
|
2013-07-26 13:28:33 +00:00
|
|
|
"device_del", QMP_OK,
|
|
|
|
"human-monitor-command", HMP(""));
|
2016-07-07 22:52:41 +00:00
|
|
|
DO_TEST_DETACH("base-live", "disk-scsi", false, false,
|
2013-07-26 13:28:33 +00:00
|
|
|
"device_del", QMP_DEVICE_DELETED("scsi0-0-0-5") QMP_OK,
|
|
|
|
"human-monitor-command", HMP(""));
|
|
|
|
|
2019-02-07 11:06:12 +00:00
|
|
|
DO_TEST_ATTACH("base-without-scsi-controller-live", "disk-scsi-2", false, true,
|
|
|
|
/* Four controllers added */
|
|
|
|
"device_add", QMP_OK,
|
|
|
|
"device_add", QMP_OK,
|
|
|
|
"device_add", QMP_OK,
|
|
|
|
"device_add", QMP_OK,
|
|
|
|
"human-monitor-command", HMP("OK\\r\\n"),
|
|
|
|
/* Disk added */
|
|
|
|
"device_add", QMP_OK);
|
2016-07-07 22:52:41 +00:00
|
|
|
DO_TEST_DETACH("base-with-scsi-controller-live", "disk-scsi-2", true, true,
|
2016-06-27 14:43:48 +00:00
|
|
|
"device_del", QMP_OK,
|
|
|
|
"human-monitor-command", HMP(""));
|
2016-07-07 22:52:41 +00:00
|
|
|
DO_TEST_DETACH("base-with-scsi-controller-live", "disk-scsi-2", false, false,
|
2019-04-11 14:23:38 +00:00
|
|
|
"device_del", QMP_DEVICE_DELETED("scsi3-0-5-6") QMP_OK,
|
2016-06-27 14:43:48 +00:00
|
|
|
"human-monitor-command", HMP(""));
|
|
|
|
|
2016-07-07 22:52:41 +00:00
|
|
|
DO_TEST_ATTACH("base-live", "qemu-agent", false, true,
|
2016-03-30 14:43:28 +00:00
|
|
|
"chardev-add", QMP_OK,
|
|
|
|
"device_add", QMP_OK);
|
2016-07-07 22:52:41 +00:00
|
|
|
DO_TEST_DETACH("base-live", "qemu-agent-detach", false, false,
|
2019-02-07 10:55:12 +00:00
|
|
|
"device_del", QMP_DEVICE_DELETED("channel0") QMP_OK,
|
2016-03-30 14:43:28 +00:00
|
|
|
"chardev-remove", QMP_OK);
|
|
|
|
|
2016-07-22 18:10:47 +00:00
|
|
|
DO_TEST_ATTACH("base-ccw-live", "ccw-virtio", false, true,
|
|
|
|
"human-monitor-command", HMP("OK\\r\\n"),
|
|
|
|
"device_add", QMP_OK);
|
|
|
|
DO_TEST_DETACH("base-ccw-live", "ccw-virtio", false, false,
|
2019-02-07 10:55:12 +00:00
|
|
|
"device_del", QMP_DEVICE_DELETED("virtio-disk4") QMP_OK,
|
2016-07-22 18:10:47 +00:00
|
|
|
"human-monitor-command", HMP(""));
|
|
|
|
|
|
|
|
DO_TEST_ATTACH("base-ccw-live-with-ccw-virtio", "ccw-virtio-2", false, true,
|
|
|
|
"human-monitor-command", HMP("OK\\r\\n"),
|
|
|
|
"device_add", QMP_OK);
|
|
|
|
|
|
|
|
DO_TEST_DETACH("base-ccw-live-with-ccw-virtio", "ccw-virtio-2", false, false,
|
2019-02-07 10:55:12 +00:00
|
|
|
"device_del", QMP_DEVICE_DELETED("virtio-disk0") QMP_OK,
|
2016-07-22 18:10:47 +00:00
|
|
|
"human-monitor-command", HMP(""));
|
|
|
|
|
|
|
|
DO_TEST_ATTACH("base-ccw-live-with-ccw-virtio", "ccw-virtio-2-explicit", false, true,
|
|
|
|
"human-monitor-command", HMP("OK\\r\\n"),
|
|
|
|
"device_add", QMP_OK);
|
|
|
|
|
|
|
|
DO_TEST_DETACH("base-ccw-live-with-ccw-virtio", "ccw-virtio-2-explicit", false, false,
|
2019-02-07 10:55:12 +00:00
|
|
|
"device_del", QMP_DEVICE_DELETED("virtio-disk0") QMP_OK,
|
2016-07-22 18:10:47 +00:00
|
|
|
"human-monitor-command", HMP(""));
|
|
|
|
|
|
|
|
/* Attach a second device, then detach the first one. Then attach the first one again. */
|
|
|
|
DO_TEST_ATTACH("base-ccw-live-with-ccw-virtio", "ccw-virtio-2-explicit", false, true,
|
|
|
|
"human-monitor-command", HMP("OK\\r\\n"),
|
|
|
|
"device_add", QMP_OK);
|
|
|
|
|
|
|
|
DO_TEST_DETACH("base-ccw-live-with-2-ccw-virtio", "ccw-virtio-1-explicit", false, true,
|
2019-02-07 10:55:12 +00:00
|
|
|
"device_del", QMP_DEVICE_DELETED("virtio-disk4") QMP_OK,
|
2016-07-22 18:10:47 +00:00
|
|
|
"human-monitor-command", HMP(""));
|
|
|
|
|
|
|
|
DO_TEST_ATTACH("base-ccw-live-with-2-ccw-virtio", "ccw-virtio-1-reverse", false, false,
|
|
|
|
"human-monitor-command", HMP("OK\\r\\n"),
|
|
|
|
"device_add", QMP_OK);
|
|
|
|
|
2016-09-12 13:40:48 +00:00
|
|
|
DO_TEST_ATTACH("base-live", "ivshmem-plain", false, true,
|
|
|
|
"object-add", QMP_OK,
|
|
|
|
"device_add", QMP_OK);
|
|
|
|
DO_TEST_ATTACH("base-live", "ivshmem-doorbell", false, true,
|
|
|
|
"chardev-add", QMP_OK,
|
|
|
|
"device_add", QMP_OK);
|
|
|
|
DO_TEST_DETACH("base-live+ivshmem-plain", "ivshmem-doorbell-detach", false, true,
|
2019-02-07 10:55:12 +00:00
|
|
|
"device_del", QMP_DEVICE_DELETED("shmem1") QMP_OK,
|
2016-09-12 13:40:48 +00:00
|
|
|
"chardev-remove", QMP_OK);
|
|
|
|
DO_TEST_DETACH("base-live", "ivshmem-plain-detach", false, false,
|
2019-02-07 10:55:12 +00:00
|
|
|
"device_del", QMP_DEVICE_DELETED("shmem0") QMP_OK,
|
2016-09-12 13:40:48 +00:00
|
|
|
"object-del", QMP_OK);
|
2017-06-23 12:11:25 +00:00
|
|
|
DO_TEST_ATTACH("base-live+disk-scsi-wwn",
|
2017-09-01 11:39:15 +00:00
|
|
|
"disk-scsi-duplicate-wwn", false, false,
|
2017-06-23 12:11:25 +00:00
|
|
|
"human-monitor-command", HMP("OK\\r\\n"),
|
|
|
|
"device_add", QMP_OK);
|
2016-09-12 13:40:48 +00:00
|
|
|
|
2019-08-29 19:19:00 +00:00
|
|
|
DO_TEST_ATTACH("base-live", "hostdev-pci", false, true,
|
|
|
|
"device_add", QMP_OK);
|
|
|
|
DO_TEST_DETACH("base-live", "hostdev-pci", false, false,
|
|
|
|
"device_del", QMP_DEVICE_DELETED("hostdev0") QMP_OK);
|
|
|
|
DO_TEST_ATTACH("pseries-base-live", "hostdev-pci", false, true,
|
|
|
|
"device_add", QMP_OK);
|
|
|
|
DO_TEST_DETACH("pseries-base-live", "hostdev-pci", false, false,
|
|
|
|
"device_del", QMP_DEVICE_DELETED("hostdev0") QMP_OK);
|
|
|
|
|
2017-09-05 09:08:36 +00:00
|
|
|
DO_TEST_ATTACH("base-live", "watchdog", false, true,
|
2017-09-01 11:39:15 +00:00
|
|
|
"watchdog-set-action", QMP_OK,
|
|
|
|
"device_add", QMP_OK);
|
2017-09-05 09:08:36 +00:00
|
|
|
DO_TEST_DETACH("base-live", "watchdog-full", false, false,
|
2019-02-07 10:55:12 +00:00
|
|
|
"device_del", QMP_DEVICE_DELETED("watchdog0") QMP_OK);
|
2017-09-01 11:39:15 +00:00
|
|
|
|
2017-10-22 13:42:45 +00:00
|
|
|
DO_TEST_ATTACH("base-live", "watchdog-user-alias", false, true,
|
|
|
|
"watchdog-set-action", QMP_OK,
|
|
|
|
"device_add", QMP_OK);
|
|
|
|
DO_TEST_DETACH("base-live", "watchdog-user-alias-full", false, false,
|
2019-02-07 10:55:12 +00:00
|
|
|
"device_del", QMP_DEVICE_DELETED("ua-UserWatchdog") QMP_OK);
|
2017-10-22 13:42:45 +00:00
|
|
|
|
2019-02-11 15:17:53 +00:00
|
|
|
DO_TEST_ATTACH("base-live", "guestfwd", false, true,
|
|
|
|
"chardev-add", QMP_OK,
|
|
|
|
"netdev_add", QMP_OK);
|
|
|
|
DO_TEST_DETACH("base-live", "guestfwd", false, false,
|
|
|
|
"netdev_del", QMP_OK);
|
|
|
|
|
2017-11-03 12:09:47 +00:00
|
|
|
#define DO_TEST_CPU_GROUP(prefix, vcpus, modernhp, expectfail) \
|
|
|
|
do { \
|
|
|
|
cpudata.test = prefix; \
|
|
|
|
cpudata.newcpus = vcpus; \
|
|
|
|
cpudata.modern = modernhp; \
|
|
|
|
cpudata.fail = expectfail; \
|
|
|
|
if (virTestRun("hotplug vcpus group " prefix, \
|
|
|
|
testQemuHotplugCpuGroup, &cpudata) < 0) \
|
|
|
|
ret = -1; \
|
2016-12-04 18:08:25 +00:00
|
|
|
} while (0)
|
|
|
|
|
|
|
|
DO_TEST_CPU_GROUP("x86-modern-bulk", 7, true, false);
|
2016-12-09 14:54:54 +00:00
|
|
|
DO_TEST_CPU_GROUP("x86-old-bulk", 7, false, false);
|
2016-12-09 15:52:16 +00:00
|
|
|
DO_TEST_CPU_GROUP("ppc64-modern-bulk", 24, true, false);
|
|
|
|
DO_TEST_CPU_GROUP("ppc64-modern-bulk", 15, true, true);
|
|
|
|
DO_TEST_CPU_GROUP("ppc64-modern-bulk", 23, true, true);
|
|
|
|
DO_TEST_CPU_GROUP("ppc64-modern-bulk", 25, true, true);
|
2016-12-04 18:08:25 +00:00
|
|
|
|
2017-11-03 12:09:47 +00:00
|
|
|
#define DO_TEST_CPU_INDIVIDUAL(prefix, mapstr, statefl, modernhp, expectfail) \
|
|
|
|
do { \
|
|
|
|
cpudata.test = prefix; \
|
|
|
|
cpudata.cpumap = mapstr; \
|
|
|
|
cpudata.state = statefl; \
|
|
|
|
cpudata.modern = modernhp; \
|
|
|
|
cpudata.fail = expectfail; \
|
|
|
|
if (virTestRun("hotplug vcpus group " prefix, \
|
|
|
|
testQemuHotplugCpuIndividual, &cpudata) < 0) \
|
|
|
|
ret = -1; \
|
2017-02-10 16:14:22 +00:00
|
|
|
} while (0)
|
|
|
|
|
|
|
|
DO_TEST_CPU_INDIVIDUAL("x86-modern-individual-add", "7", true, true, false);
|
|
|
|
DO_TEST_CPU_INDIVIDUAL("x86-modern-individual-add", "6,7", true, true, true);
|
|
|
|
DO_TEST_CPU_INDIVIDUAL("x86-modern-individual-add", "7", false, true, true);
|
|
|
|
DO_TEST_CPU_INDIVIDUAL("x86-modern-individual-add", "7", true, false, true);
|
|
|
|
|
|
|
|
DO_TEST_CPU_INDIVIDUAL("ppc64-modern-individual", "16-23", true, true, false);
|
|
|
|
DO_TEST_CPU_INDIVIDUAL("ppc64-modern-individual", "16-22", true, true, true);
|
|
|
|
DO_TEST_CPU_INDIVIDUAL("ppc64-modern-individual", "17", true, true, true);
|
|
|
|
|
2019-08-29 19:19:00 +00:00
|
|
|
if (getenv("LIBVIRT_SKIP_CLEANUP") == NULL)
|
|
|
|
virFileDeleteTree(fakerootdir);
|
|
|
|
VIR_FREE(fakerootdir);
|
|
|
|
|
2015-09-15 06:16:02 +00:00
|
|
|
qemuTestDriverFree(&driver);
|
2017-08-04 13:25:40 +00:00
|
|
|
virObjectUnref(data.vm);
|
2013-06-21 14:27:59 +00:00
|
|
|
return (ret == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
|
2019-08-29 19:19:00 +00:00
|
|
|
VIR_TEST_MAIN_PRELOAD(mymain,
|
|
|
|
VIR_TEST_MOCK("virpci"),
|
|
|
|
VIR_TEST_MOCK("virprocess"));
|