[libvirt PATCH] qemu: add runtime config option for nbdkit
by Jonathon Jongsma
Currently when we build with nbdkit support, libvirt will always try to
use nbdkit to access remote disk sources when it is available. But
without an up-to-date selinux policy allowing this, it will fail.
Because the required selinux policies are not yet widely available, we
have disabled nbdkit support on rpm builds for all distributions before
Fedora 40.
Unfortunately, this makes it more difficult to test nbdkit support.
After someone updates to the necessary selinux policies, they would also
need to rebuild libvirt to enable nbdkit support. By introducing a
configure option (storage_use_nbdkit), we can build packages with nbdkit
support but have it disabled by default.
Signed-off-by: Jonathon Jongsma <jjongsma(a)redhat.com>
---
Suggested as an option for making testing easier by Andrea Bolognani
libvirt.spec.in | 10 +---------
src/qemu/libvirtd_qemu.aug | 3 +++
src/qemu/qemu.conf.in | 10 ++++++++++
src/qemu/qemu_conf.c | 14 ++++++++++++++
src/qemu/qemu_conf.h | 2 ++
src/qemu/qemu_domain.c | 3 +++
tests/qemuxml2argvtest.c | 15 +++++++++------
7 files changed, 42 insertions(+), 15 deletions(-)
diff --git a/libvirt.spec.in b/libvirt.spec.in
index f50c451e73..e2ba245ade 100644
--- a/libvirt.spec.in
+++ b/libvirt.spec.in
@@ -174,16 +174,8 @@
%endif
%endif
-# We should only enable nbdkit support if the OS ships a SELinux policy that
-# allows libvirt to launch it. Right now that's not the case anywhere, but
-# things should be fine by the time Fedora 40 is released.
-#
-# TODO: add RHEL 9 once a minor release that contains the necessary SELinux
-# bits exists (we only support the most recent minor release)
%if %{with_qemu}
- %if 0%{?fedora} >= 40
- %define with_nbdkit 0%{!?_without_nbdkit:1}
- %endif
+ %define with_nbdkit 0%{!?_without_nbdkit:1}
%endif
%ifarch %{arches_dmidecode}
diff --git a/src/qemu/libvirtd_qemu.aug b/src/qemu/libvirtd_qemu.aug
index ed097ea3d9..43485b43fb 100644
--- a/src/qemu/libvirtd_qemu.aug
+++ b/src/qemu/libvirtd_qemu.aug
@@ -147,6 +147,8 @@ module Libvirtd_qemu =
let capability_filters_entry = str_array_entry "capability_filters"
+ let storage_entry = bool_entry "storage_use_nbdkit"
+
(* Each entry in the config is one of the following ... *)
let entry = default_tls_entry
| vnc_entry
@@ -170,6 +172,7 @@ module Libvirtd_qemu =
| nbd_entry
| swtpm_entry
| capability_filters_entry
+ | storage_entry
| obsolete_entry
let comment = [ label "#comment" . del /#[ \t]*/ "# " . store /([^ \t\n][^\n]*)?/ . del /\n/ "\n" ]
diff --git a/src/qemu/qemu.conf.in b/src/qemu/qemu.conf.in
index 6897e0f760..1017edefa5 100644
--- a/src/qemu/qemu.conf.in
+++ b/src/qemu/qemu.conf.in
@@ -974,3 +974,13 @@
# "full" - both QEMU and its helper processes are placed into separate
# scheduling group
#sched_core = "none"
+
+# Using nbdkit to access remote disk sources
+#
+# If this is set then libvirt will use nbdkit to access remote disk sources
+# when available. nbdkit will export an NBD share to qemu rather than having
+# qemu attempt access the remote server directly.
+#
+# Possible values are 0 or 1. Disabled by default.
+#
+# storage_use_nbdkit = 1
diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
index 513b5ebb1e..b5c0ca10b4 100644
--- a/src/qemu/qemu_conf.c
+++ b/src/qemu/qemu_conf.c
@@ -1065,6 +1065,17 @@ virQEMUDriverConfigLoadCapsFiltersEntry(virQEMUDriverConfig *cfg,
}
+static int
+virQEMUDriverConfigLoadStorageEntry(virQEMUDriverConfig *cfg,
+ virConf *conf)
+{
+ if (virConfGetValueBool(conf, "storage_use_nbdkit", &cfg->storageUseNbdkit) < 0)
+ return -1;
+
+ return 0;
+}
+
+
int virQEMUDriverConfigLoadFile(virQEMUDriverConfig *cfg,
const char *filename,
bool privileged)
@@ -1136,6 +1147,9 @@ int virQEMUDriverConfigLoadFile(virQEMUDriverConfig *cfg,
if (virQEMUDriverConfigLoadCapsFiltersEntry(cfg, conf) < 0)
return -1;
+ if (virQEMUDriverConfigLoadStorageEntry(cfg, conf) < 0)
+ return -1;
+
return 0;
}
diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h
index 1a3ba3a0fb..36049b4bfa 100644
--- a/src/qemu/qemu_conf.h
+++ b/src/qemu/qemu_conf.h
@@ -230,6 +230,8 @@ struct _virQEMUDriverConfig {
char *deprecationBehavior;
+ bool storageUseNbdkit;
+
virQEMUSchedCore schedCore;
};
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index ae19ce884b..f8dda6c898 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -10333,6 +10333,9 @@ qemuDomainPrepareStorageSourceNbdkit(virStorageSource *src,
{
g_autoptr(qemuNbdkitCaps) nbdkit = NULL;
+ if (!cfg->storageUseNbdkit)
+ return false;
+
if (virStorageSourceGetActualType(src) != VIR_STORAGE_TYPE_NETWORK)
return false;
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index 4fda68a4ce..3c64fcc7eb 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -1115,7 +1115,6 @@ mymain(void)
DO_TEST_CAPS_LATEST("disk-cdrom-empty-network-invalid");
DO_TEST_CAPS_LATEST("disk-cdrom-bus-other");
DO_TEST_CAPS_LATEST("disk-cdrom-network");
- DO_TEST_CAPS_LATEST_NBDKIT("disk-cdrom-network-nbdkit", QEMU_NBDKIT_CAPS_PLUGIN_CURL);
DO_TEST_CAPS_LATEST("disk-cdrom-tray");
DO_TEST_CAPS_LATEST("disk-floppy");
DO_TEST_CAPS_LATEST("disk-floppy-q35");
@@ -1161,8 +1160,6 @@ mymain(void)
DO_TEST_CAPS_VER("disk-network-sheepdog", "6.0.0");
DO_TEST_CAPS_LATEST("disk-network-source-auth");
DO_TEST_CAPS_LATEST("disk-network-source-curl");
- DO_TEST_CAPS_LATEST_NBDKIT("disk-network-source-curl-nbdkit", QEMU_NBDKIT_CAPS_PLUGIN_CURL);
- DO_TEST_CAPS_LATEST_NBDKIT("disk-network-source-curl-nbdkit-backing", QEMU_NBDKIT_CAPS_PLUGIN_CURL);
DO_TEST_CAPS_LATEST("disk-network-nfs");
driver.config->vxhsTLS = 1;
driver.config->nbdTLSx509secretUUID = g_strdup("6fd3f62d-9fe7-4a4e-a869-7acd6376d8ea");
@@ -1173,13 +1170,10 @@ mymain(void)
DO_TEST_CAPS_LATEST("disk-network-tlsx509-nbd-hostname");
DO_TEST_CAPS_VER("disk-network-tlsx509-vxhs", "5.0.0");
DO_TEST_CAPS_LATEST("disk-network-http");
- DO_TEST_CAPS_LATEST_NBDKIT("disk-network-http-nbdkit", QEMU_NBDKIT_CAPS_PLUGIN_CURL);
VIR_FREE(driver.config->nbdTLSx509secretUUID);
VIR_FREE(driver.config->vxhsTLSx509secretUUID);
driver.config->vxhsTLS = 0;
DO_TEST_CAPS_LATEST("disk-network-ssh");
- DO_TEST_CAPS_LATEST_NBDKIT("disk-network-ssh-nbdkit", QEMU_NBDKIT_CAPS_PLUGIN_SSH);
- DO_TEST_CAPS_LATEST_NBDKIT("disk-network-ssh-password", QEMU_NBDKIT_CAPS_PLUGIN_SSH);
DO_TEST_CAPS_LATEST("disk-no-boot");
DO_TEST_CAPS_LATEST("disk-nvme");
DO_TEST_CAPS_VER("disk-vhostuser-numa", "4.2.0");
@@ -1249,6 +1243,15 @@ mymain(void)
DO_TEST_CAPS_LATEST("disk-geometry");
DO_TEST_CAPS_LATEST("disk-blockio");
+ driver.config->storageUseNbdkit = 1;
+ DO_TEST_CAPS_LATEST_NBDKIT("disk-cdrom-network-nbdkit", QEMU_NBDKIT_CAPS_PLUGIN_CURL);
+ DO_TEST_CAPS_LATEST_NBDKIT("disk-network-source-curl-nbdkit", QEMU_NBDKIT_CAPS_PLUGIN_CURL);
+ DO_TEST_CAPS_LATEST_NBDKIT("disk-network-source-curl-nbdkit-backing", QEMU_NBDKIT_CAPS_PLUGIN_CURL);
+ DO_TEST_CAPS_LATEST_NBDKIT("disk-network-http-nbdkit", QEMU_NBDKIT_CAPS_PLUGIN_CURL);
+ DO_TEST_CAPS_LATEST_NBDKIT("disk-network-ssh-nbdkit", QEMU_NBDKIT_CAPS_PLUGIN_SSH);
+ DO_TEST_CAPS_LATEST_NBDKIT("disk-network-ssh-password", QEMU_NBDKIT_CAPS_PLUGIN_SSH);
+ driver.config->storageUseNbdkit = 0;
+
DO_TEST_CAPS_VER("disk-virtio-scsi-reservations", "5.2.0");
DO_TEST_CAPS_LATEST("disk-virtio-scsi-reservations");
--
2.41.0
6 months, 1 week
[PATCH V4] support for hotplug/hotunplug in test hypervisor
by Thanos Makatos
Signed-off-by: Thanos Makatos <thanos.makatos(a)nutanix.com>
---
src/test/test_driver.c | 387 ++++++++++++++++++++++++++++++++++++++++-
1 file changed, 385 insertions(+), 2 deletions(-)
diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index e87d7cfd44..a3b4799a0f 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -26,8 +26,6 @@
#include <unistd.h>
#include <sys/stat.h>
#include <libxml/xmlsave.h>
-
-
#include "virerror.h"
#include "datatypes.h"
#include "test_driver.h"
@@ -38,10 +36,14 @@
#include "virnetworkobj.h"
#include "interface_conf.h"
#include "checkpoint_conf.h"
+#include "domain_addr.h"
+#include "domain_audit.h"
#include "domain_conf.h"
#include "domain_driver.h"
#include "domain_event.h"
+#include "domain_validate.h"
#include "network_event.h"
+#include "nwfilter_conf.h"
#include "snapshot_conf.h"
#include "virfdstream.h"
#include "storage_conf.h"
@@ -50,6 +52,7 @@
#include "node_device_conf.h"
#include "virnodedeviceobj.h"
#include "node_device_event.h"
+#include "vircgroup.h"
#include "virxml.h"
#include "virthread.h"
#include "virlog.h"
@@ -10035,6 +10038,383 @@ testConnectGetDomainCapabilities(virConnectPtr conn G_GNUC_UNUSED,
return virDomainCapsFormat(domCaps);
}
+static int
+testDomainAttachHostPCIDevice(testDriver *driver G_GNUC_UNUSED,
+ virDomainObj *vm,
+ virDomainHostdevDef *hostdev)
+{
+ int backend = hostdev->source.subsys.u.pci.backend;
+
+ switch ((virDomainHostdevSubsysPCIBackendType)backend) {
+ case VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO:
+ case VIR_DOMAIN_HOSTDEV_PCI_BACKEND_DEFAULT:
+ case VIR_DOMAIN_HOSTDEV_PCI_BACKEND_KVM:
+ break;
+
+ case VIR_DOMAIN_HOSTDEV_PCI_BACKEND_XEN:
+ case VIR_DOMAIN_HOSTDEV_PCI_BACKEND_TYPE_LAST:
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+ _("test hypervisor does not support device assignment mode '%s'"),
+ virDomainHostdevSubsysPCIBackendTypeToString(backend));
+ return -1;
+ }
+
+ if (!virDomainObjIsActive(vm)) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("guest unexpectedly quit during hotplug"));
+ return -1;
+ }
+
+ VIR_REALLOC_N(vm->def->hostdevs, vm->def->nhostdevs + 1);
+
+ virDomainAuditHostdev(vm, hostdev, "attach", true);
+
+ vm->def->hostdevs[vm->def->nhostdevs++] = hostdev;
+
+ return 0;
+}
+
+static int
+testDomainAttachHostDevice(testDriver *driver,
+ virDomainObj *vm,
+ virDomainHostdevDef *hostdev)
+{
+ if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+ _("hotplug is not supported for hostdev mode '%s'"),
+ virDomainHostdevModeTypeToString(hostdev->mode));
+ return -1;
+ }
+
+ if (hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+ _("hotplug is not supported for hostdev subsys type '%s'"),
+ virDomainHostdevSubsysTypeToString(hostdev->source.subsys.type));
+ return -1;
+ }
+
+ return testDomainAttachHostPCIDevice(driver, vm, hostdev);
+}
+
+static int
+testDomainAttachDeviceLive(virDomainObj *vm,
+ virDomainDeviceDef *dev,
+ testDriver *driver)
+{
+ int ret = -1;
+ const char *alias = NULL;
+
+ if ((virDomainDeviceType)dev->type != VIR_DOMAIN_DEVICE_HOSTDEV) {
+ virReportError(VIR_ERR_OPERATION_UNSUPPORTED,
+ _("live attach of device '%s' is not supported"),
+ virDomainDeviceTypeToString(dev->type));
+ return -1;
+ }
+
+ testDomainObjCheckHostdevTaint(vm, dev->data.hostdev);
+ if ((ret = testDomainAttachHostDevice(driver, vm, dev->data.hostdev)) != 0)
+ return ret;
+
+ alias = dev->data.hostdev->info->alias;
+ dev->data.hostdev = NULL;
+
+ if (alias) {
+ virObjectEvent *event;
+ event = virDomainEventDeviceAddedNewFromObj(vm, alias);
+ virObjectEventStateQueue(driver->eventState, event);
+ }
+
+ return 0;
+}
+
+static int
+testDomainAttachDeviceLiveAndConfig(virDomainObj *vm,
+ testDriver *driver,
+ const char *xml,
+ unsigned int flags)
+{
+ g_autoptr(virDomainDeviceDef) devConf = NULL;
+ g_autoptr(virDomainDeviceDef) devLive = NULL;
+ unsigned int parse_flags = VIR_DOMAIN_DEF_PARSE_INACTIVE |
+ VIR_DOMAIN_DEF_PARSE_ABI_UPDATE;
+
+ virCheckFlags(VIR_DOMAIN_AFFECT_LIVE, -1);
+
+ if (flags & VIR_DOMAIN_AFFECT_LIVE) {
+ if (!(devLive = virDomainDeviceDefParse(xml, vm->def,
+ driver->xmlopt, NULL,
+ parse_flags)))
+ return -1;
+
+ if (virDomainDeviceValidateAliasForHotplug(vm, devLive,
+ VIR_DOMAIN_AFFECT_LIVE) < 0)
+ return -1;
+
+ if (virDomainDefCompatibleDevice(vm->def, devLive, NULL,
+ VIR_DOMAIN_DEVICE_ACTION_ATTACH,
+ true) < 0)
+ return -1;
+
+ if (testDomainAttachDeviceLive(vm, devLive, driver) < 0)
+ return -1;
+ }
+
+ return 0;
+}
+
+static int
+testDomainAttachDeviceFlags(virDomainPtr domain,
+ const char *xml,
+ unsigned int flags) {
+
+ testDriver *driver = domain->conn->privateData;
+ virDomainObj *vm = NULL;
+ int ret = -1;
+
+ virNWFilterReadLockFilterUpdates();
+
+ if (!(vm = testDomObjFromDomain(domain)))
+ return -1;
+
+ if (virDomainObjUpdateModificationImpact(vm, &flags) < 0)
+ goto cleanup;
+
+ if (testDomainAttachDeviceLiveAndConfig(vm, driver, xml, flags) < 0)
+ goto cleanup;
+
+ ret = 0;
+
+ cleanup:
+ virDomainObjEndAPI(&vm);
+ virNWFilterUnlockFilterUpdates();
+ return ret;
+
+}
+
+static int
+testDomainAttachDevice(virDomainPtr domain, const char *xml)
+{
+ return testDomainAttachDeviceFlags(domain, xml, 0);
+}
+
+/* search for a hostdev matching dev and detach it */
+static int
+testDomainDetachPrepHostdev(virDomainObj *vm,
+ virDomainHostdevDef *match,
+ virDomainHostdevDef **detach)
+{
+ virDomainHostdevSubsys *subsys = &match->source.subsys;
+ virDomainHostdevSubsysPCI *pcisrc = &subsys->u.pci;
+ virDomainHostdevDef *hostdev = NULL;
+
+ if (match->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+ _("hot unplug is not supported for hostdev mode '%s'"),
+ virDomainHostdevModeTypeToString(match->mode));
+ return -1;
+ }
+
+ if (virDomainHostdevFind(vm->def, match, &hostdev) < 0) {
+ if (subsys->type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI) {
+ virReportError(VIR_ERR_DEVICE_MISSING,
+ _("host pci device " VIR_PCI_DEVICE_ADDRESS_FMT
+ " not found"),
+ pcisrc->addr.domain, pcisrc->addr.bus,
+ pcisrc->addr.slot, pcisrc->addr.function);
+ } else {
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("unexpected hostdev type %d"), subsys->type);
+ }
+ return -1;
+ }
+
+ *detach = hostdev;
+
+ return 0;
+}
+
+static int
+testDomainRemoveHostDevice(testDriver *driver G_GNUC_UNUSED,
+ virDomainObj *vm,
+ virDomainHostdevDef *hostdev)
+{
+ virDomainNetDef *net = NULL;
+ size_t i;
+
+ VIR_DEBUG("Removing host device %s from domain %p %s",
+ hostdev->info->alias, vm, vm->def->name);
+
+ if (hostdev->parentnet) {
+ net = hostdev->parentnet;
+ for (i = 0; i < vm->def->nnets; i++) {
+ if (vm->def->nets[i] == hostdev->parentnet) {
+ virDomainNetRemove(vm->def, i);
+ break;
+ }
+ }
+ }
+
+ for (i = 0; i < vm->def->nhostdevs; i++) {
+ if (vm->def->hostdevs[i] == hostdev) {
+ virDomainHostdevRemove(vm->def, i);
+ break;
+ }
+ }
+
+ virDomainAuditHostdev(vm, hostdev, "detach", true);
+
+ virDomainHostdevDefFree(hostdev);
+
+ if (net) {
+ if (net->type == VIR_DOMAIN_NET_TYPE_NETWORK) {
+ g_autoptr(virConnect) conn = virGetConnectNetwork();
+ if (conn)
+ virDomainNetReleaseActualDevice(conn, vm->def, net);
+ else
+ VIR_WARN("Unable to release network device '%s'", NULLSTR(net->ifname));
+ }
+ virDomainNetDefFree(net);
+ }
+
+ return 0;
+}
+
+static int
+testDomainRemoveDevice(testDriver *driver,
+ virDomainObj *vm,
+ virDomainDeviceDef *dev)
+{
+ virDomainDeviceInfo *info;
+ virObjectEvent *event;
+ g_autofree char *alias = NULL;
+
+ /*
+ * save the alias to use when sending a DEVICE_REMOVED event after
+ * all other teardown is complete
+ */
+ if ((info = virDomainDeviceGetInfo(dev)))
+ alias = g_strdup(info->alias);
+ info = NULL;
+
+ if ((virDomainDeviceType)dev->type != VIR_DOMAIN_DEVICE_HOSTDEV) {
+ virReportError(VIR_ERR_OPERATION_UNSUPPORTED,
+ _("don't know how to remove a %s device"),
+ virDomainDeviceTypeToString(dev->type));
+ goto out;
+ }
+
+ if (testDomainRemoveHostDevice(driver, vm, dev->data.hostdev) < 0)
+ return -1;
+
+out:
+ event = virDomainEventDeviceRemovedNewFromObj(vm, alias);
+ virObjectEventStateQueue(driver->eventState, event);
+
+ return 0;
+}
+
+static int
+testDomainDetachDeviceLive(virDomainObj *vm,
+ virDomainDeviceDef *match,
+ testDriver *driver)
+{
+ virDomainDeviceDef detach = { .type = match->type };
+ virDomainDeviceInfo *info = NULL;
+
+ if ((virDomainDeviceType)match->type != VIR_DOMAIN_DEVICE_HOSTDEV) {
+ virReportError(VIR_ERR_OPERATION_UNSUPPORTED,
+ _("live detach of device '%s' is not supported"),
+ virDomainDeviceTypeToString(match->type));
+ return -1;
+ }
+
+ if (testDomainDetachPrepHostdev(vm, match->data.hostdev,
+ &detach.data.hostdev) < 0)
+ return -1;
+
+ /* "detach" now points to the actual device we want to detach */
+
+ if (!(info = virDomainDeviceGetInfo(&detach))) {
+ /*
+ * This should never happen, since all of the device types in
+ * the switch cases that end with a "break" instead of a
+ * return have a virDeviceInfo in them.
+ */
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("device of type '%s' has no device info"),
+ virDomainDeviceTypeToString(detach.type));
+ return -1;
+ }
+
+ /* Make generic validation checks common to all device types */
+
+ if (!info->alias) {
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Cannot detach %s device with no alias"),
+ virDomainDeviceTypeToString(detach.type));
+ return -1;
+ }
+
+ return testDomainRemoveDevice(driver, vm, &detach);
+}
+
+static int
+testDomainDetachDeviceAliasLiveAndConfig(testDriver *driver,
+ virDomainObj *vm,
+ const char *alias,
+ unsigned int flags)
+{
+ virDomainDef *def = NULL;
+ g_autoptr(virDomainDef) vmdef = NULL;
+
+ virCheckFlags(VIR_DOMAIN_AFFECT_LIVE, -1);
+
+ if (virDomainObjGetDefs(vm, flags, &def, NULL) < 0)
+ return -1;
+
+ if (def) {
+ virDomainDeviceDef dev;
+
+ if (virDomainDefFindDevice(def, alias, &dev, true) < 0)
+ return -1;
+
+ if (testDomainDetachDeviceLive(vm, &dev, driver) < 0)
+ return -1;
+ }
+
+ if (vmdef) {
+ if (virDomainDefSave(vmdef, driver->xmlopt, NULL) < 0)
+ return -1;
+ virDomainObjAssignDef(vm, &vmdef, false, NULL);
+ }
+
+ return 0;
+}
+
+static int
+testDomainDetachDeviceAlias(virDomainPtr dom,
+ const char *alias,
+ unsigned int flags)
+{
+ testDriver *driver = dom->conn->privateData;
+ virDomainObj *vm = NULL;
+ int ret = -1;
+
+ if (!(vm = testDomObjFromDomain(dom)))
+ return -1;
+
+ if (virDomainObjUpdateModificationImpact(vm, &flags) < 0)
+ goto cleanup;
+
+ if (testDomainDetachDeviceAliasLiveAndConfig(driver, vm, alias, flags) < 0)
+ goto cleanup;
+
+ ret = 0;
+
+ cleanup:
+ virDomainObjEndAPI(&vm);
+ return ret;
+}
/*
* Test driver
@@ -10058,6 +10438,9 @@ static virHypervisorDriver testHypervisorDriver = {
.connectListDomains = testConnectListDomains, /* 0.1.1 */
.connectNumOfDomains = testConnectNumOfDomains, /* 0.1.1 */
.connectListAllDomains = testConnectListAllDomains, /* 0.9.13 */
+ .domainAttachDevice = testDomainAttachDevice, /* 9.10.0 */
+ .domainAttachDeviceFlags = testDomainAttachDeviceFlags, /* 9.10.0 */
+ .domainDetachDeviceAlias = testDomainDetachDeviceAlias, /* 9.10.0 */
.domainCreateXML = testDomainCreateXML, /* 0.1.4 */
.domainCreateXMLWithFiles = testDomainCreateXMLWithFiles, /* 5.7.0 */
.domainLookupByID = testDomainLookupByID, /* 0.1.1 */
--
2.27.0
6 months, 1 week
[PATCH V3] support for hotplug/hotunplug in test hypervisor
by Thanos Makatos
Signed-off-by: Thanos Makatos <thanos.makatos(a)nutanix.com>
---
src/test/test_driver.c | 59 ++++++++++++++++++++++++++++++++++++++++++
1 file changed, 59 insertions(+)
diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index e87d7cfd44..d605649262 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -10035,6 +10035,62 @@ testConnectGetDomainCapabilities(virConnectPtr conn G_GNUC_UNUSED,
return virDomainCapsFormat(domCaps);
}
+static int
+testVirDomainAttachDeviceFlags(virDomainPtr domain,
+ const char *xml,
+ unsigned int flags G_GNUC_UNUSED) {
+
+ int ret = -1;
+ virDomainObj *vm;
+ testDriver *driver;
+ virDomainDeviceDef *devConf;
+
+ if (!(vm = testDomObjFromDomain(domain)))
+ return -1;
+
+ driver = domain->conn->privateData;
+
+ if (!(devConf = virDomainDeviceDefParse(xml, vm->def, driver->xmlopt,
+ NULL, 0)))
+ goto out;
+
+ VIR_APPEND_ELEMENT(vm->def->hostdevs, vm->def->nhostdevs,
+ devConf->data.hostdev);
+ virDomainDeviceDefFree(devConf);
+ ret = 0;
+out:
+ virDomainObjEndAPI(&vm);
+ return ret;
+}
+
+static int
+testVirDomainAttachDevice(virDomainPtr domain, const char *xml)
+{
+ return testVirDomainAttachDeviceFlags(domain, xml, 0);
+}
+
+static int
+testVirDomainDetachDeviceAlias(virDomainPtr domain,
+ const char *alias,
+ unsigned int flags G_GNUC_UNUSED)
+{
+ virDomainObj *vm;
+ size_t i;
+ bool found = false;
+
+ if (!(vm = testDomObjFromDomain(domain)))
+ return -1;
+
+ for (i = 0; i < vm->def->nhostdevs && !found; i++) {
+ if (!strcmp(vm->def->hostdevs[i]->info->alias, alias)) {
+ virDomainHostdevDefFree(vm->def->hostdevs[i]);
+ VIR_DELETE_ELEMENT(vm->def->hostdevs, i, vm->def->nhostdevs);
+ found = true;
+ }
+ }
+ virDomainObjEndAPI(&vm);
+ return found ? 0 : -1;
+}
/*
* Test driver
@@ -10058,6 +10114,9 @@ static virHypervisorDriver testHypervisorDriver = {
.connectListDomains = testConnectListDomains, /* 0.1.1 */
.connectNumOfDomains = testConnectNumOfDomains, /* 0.1.1 */
.connectListAllDomains = testConnectListAllDomains, /* 0.9.13 */
+ .domainAttachDevice = testVirDomainAttachDevice, /* 9.9.0 */
+ .domainAttachDeviceFlags = testVirDomainAttachDeviceFlags, /* 9.9.0 */
+ .domainDetachDeviceAlias = testVirDomainDetachDeviceAlias, /* 9.9.0 */
.domainCreateXML = testDomainCreateXML, /* 0.1.4 */
.domainCreateXMLWithFiles = testDomainCreateXMLWithFiles, /* 5.7.0 */
.domainLookupByID = testDomainLookupByID, /* 0.1.1 */
--
2.27.0
6 months, 2 weeks
[libvirt PATCH] systemd: More tweaks to Description and Documentation lines
by Andrea Bolognani
We recently unified all services and sockets, except a couple
were missed. Finish the job.
Signed-off-by: Andrea Bolognani <abologna(a)redhat.com>
---
src/remote/virt-guest-shutdown.target | 4 ++--
tools/libvirt-guests.service.in | 6 +++---
2 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/src/remote/virt-guest-shutdown.target b/src/remote/virt-guest-shutdown.target
index 25d4aaa267..34219d00b0 100644
--- a/src/remote/virt-guest-shutdown.target
+++ b/src/remote/virt-guest-shutdown.target
@@ -1,3 +1,3 @@
[Unit]
-Description=Libvirt guests shutdown
-Documentation=https://libvirt.org
+Description=libvirt guests shutdown target
+Documentation=https://libvirt.org/
diff --git a/tools/libvirt-guests.service.in b/tools/libvirt-guests.service.in
index c547218f2a..b044444298 100644
--- a/tools/libvirt-guests.service.in
+++ b/tools/libvirt-guests.service.in
@@ -1,5 +1,7 @@
[Unit]
-Description=Suspend/Resume Running libvirt Guests
+Description=libvirt guests suspend/resume service
+Documentation=man:libvirt-guests(8)
+Documentation=https://libvirt.org/
Requires=virt-guest-shutdown.target
After=network.target
After=time-sync.target
@@ -10,8 +12,6 @@ After=virtvboxd.socket
After=virtvzd.socket
After=virtxend.socket
After=virt-guest-shutdown.target
-Documentation=man:libvirt-guests(8)
-Documentation=https://libvirt.org
[Service]
EnvironmentFile=-@initconfdir@/libvirt-guests
--
2.41.0
6 months, 2 weeks
[libvirt PATCH] conf: virDomainDiskSourceFormat: check for srcpool presence correctly
by Ján Tomko
As a guard against programming errors, one part of the condition
only dereferences srcpool if it exists, other one does not.
Move the check up one level so that it actually has a chance to do
something useful.
Fixes: 19b1c0d31988a3a10c4694c10c27eb15c018f450
Signed-off-by: Ján Tomko <jtomko(a)redhat.com>
---
src/conf/domain_conf.c | 14 ++++++--------
1 file changed, 6 insertions(+), 8 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 80f467ae7a..99f9d56f07 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -22357,14 +22357,12 @@ virDomainDiskSourceFormat(virBuffer *buf,
g_auto(virBuffer) attrBuf = VIR_BUFFER_INITIALIZER;
g_auto(virBuffer) childBuf = VIR_BUFFER_INIT_CHILD(buf);
- if (src->type == VIR_STORAGE_TYPE_VOLUME) {
- if (src->srcpool) {
- virBufferEscapeString(&attrBuf, " pool='%s'", src->srcpool->pool);
- virBufferEscapeString(&attrBuf, " volume='%s'", src->srcpool->volume);
- if (src->srcpool->mode)
- virBufferAsprintf(&attrBuf, " mode='%s'",
- virStorageSourcePoolModeTypeToString(src->srcpool->mode));
- }
+ if (src->type == VIR_STORAGE_TYPE_VOLUME && src->srcpool) {
+ virBufferEscapeString(&attrBuf, " pool='%s'", src->srcpool->pool);
+ virBufferEscapeString(&attrBuf, " volume='%s'", src->srcpool->volume);
+ if (src->srcpool->mode)
+ virBufferAsprintf(&attrBuf, " mode='%s'",
+ virStorageSourcePoolModeTypeToString(src->srcpool->mode));
if (flags & VIR_DOMAIN_DEF_FORMAT_VOLUME_TRANSLATED &&
src->srcpool->actualtype != VIR_STORAGE_TYPE_NONE) {
--
2.41.0
6 months, 2 weeks
[PATCH] ci: workaround broken opensuse leap 15.5 tirpc
by Daniel P. Berrangé
Temporarily disable '-Wmissing-include-dirs' becuase the
libtirpc pkg-confog file has a bogus include dir. The
headers can fortunately still be found since they are
in the system include dir.
Signed-off-by: Daniel P. Berrangé <berrange(a)redhat.com>
---
ci/gitlab/builds.yml | 2 ++
ci/manifest.yml | 2 ++
2 files changed, 4 insertions(+)
diff --git a/ci/gitlab/builds.yml b/ci/gitlab/builds.yml
index 9ae2225e35..e1ea87db1b 100644
--- a/ci/gitlab/builds.yml
+++ b/ci/gitlab/builds.yml
@@ -332,6 +332,7 @@ x86_64-opensuse-leap-15-prebuilt-env:
optional: true
allow_failure: false
variables:
+ CFLAGS: -Wno-missing-include-dirs
NAME: opensuse-leap-15
RPM: skip
@@ -340,6 +341,7 @@ x86_64-opensuse-leap-15-local-env:
needs: []
allow_failure: false
variables:
+ CFLAGS: -Wno-missing-include-dirs
IMAGE: registry.opensuse.org/opensuse/leap:15.5
NAME: opensuse-leap-15
RPM: skip
diff --git a/ci/manifest.yml b/ci/manifest.yml
index 0e5a17a2bd..2af8e62f28 100644
--- a/ci/manifest.yml
+++ b/ci/manifest.yml
@@ -205,6 +205,8 @@ targets:
- arch: x86_64
variables:
RPM: skip
+ # Keep until fix for: https://bugzilla.opensuse.org/show_bug.cgi?id=1216862
+ CFLAGS: -Wno-missing-include-dirs
opensuse-tumbleweed:
jobs:
--
2.41.0
6 months, 2 weeks
[libvirt PATCH 0/5] ci: Add macOS 13 & 14, drop macOS 12
by Andrea Bolognani
Test pipeline: https://gitlab.com/abologna/libvirt/-/pipelines/1062214982
Assumes that
https://gitlab.com/libvirt/libvirt-ci/-/merge_requests/444
has been merged, which it hasn't yet, but I don't expect it to be
controversial.
I've added both macOS 13 and 14, doubling the amount of coverage. I'm
not aware of us being particularly tight on Cirrus CI credits, but if
that's the case we can just skip the macOS 13 patch.
The job environment is supposed to make the build system pick up
dependencies that are installed via Homebrew but can't be exposed by
default because they conflict with OS-supplied packages. Right now it
doesn't really do anything, because it hasn't been updated with the
switch to aarch64. I'm going to look into it later, but for now I've
left it as-is as reminder/documentation.
Andrea Bolognani (5):
ci: Update generated files
ci: Drop rpcgen override from macOS $PATH
ci: Add macOS 13
ci: Add macOS 14
ci: Drop macOS 12
ci/buildenv/almalinux-8.sh | 1 -
ci/buildenv/alpine-317.sh | 1 -
ci/buildenv/alpine-edge.sh | 1 -
ci/buildenv/centos-stream-8.sh | 1 -
ci/buildenv/centos-stream-9.sh | 1 -
ci/buildenv/debian-11-cross-aarch64.sh | 1 -
ci/buildenv/debian-11-cross-armv6l.sh | 1 -
ci/buildenv/debian-11-cross-armv7l.sh | 1 -
ci/buildenv/debian-11-cross-i686.sh | 1 -
ci/buildenv/debian-11-cross-mips64el.sh | 1 -
ci/buildenv/debian-11-cross-mipsel.sh | 1 -
ci/buildenv/debian-11-cross-ppc64le.sh | 1 -
ci/buildenv/debian-11-cross-s390x.sh | 1 -
ci/buildenv/debian-11.sh | 1 -
ci/buildenv/debian-12-cross-aarch64.sh | 1 -
ci/buildenv/debian-12-cross-armv6l.sh | 1 -
ci/buildenv/debian-12-cross-armv7l.sh | 1 -
ci/buildenv/debian-12-cross-i686.sh | 1 -
ci/buildenv/debian-12-cross-mips64el.sh | 1 -
ci/buildenv/debian-12-cross-mipsel.sh | 1 -
ci/buildenv/debian-12-cross-ppc64le.sh | 1 -
ci/buildenv/debian-12-cross-s390x.sh | 1 -
ci/buildenv/debian-12.sh | 1 -
ci/buildenv/debian-sid-cross-aarch64.sh | 1 -
ci/buildenv/debian-sid-cross-armv6l.sh | 1 -
ci/buildenv/debian-sid-cross-armv7l.sh | 1 -
ci/buildenv/debian-sid-cross-i686.sh | 1 -
ci/buildenv/debian-sid-cross-mips64el.sh | 1 -
ci/buildenv/debian-sid-cross-ppc64le.sh | 1 -
ci/buildenv/debian-sid-cross-s390x.sh | 1 -
ci/buildenv/debian-sid.sh | 1 -
ci/buildenv/fedora-37.sh | 1 -
ci/buildenv/fedora-38-cross-mingw32.sh | 2 +-
ci/buildenv/fedora-38-cross-mingw64.sh | 2 +-
ci/buildenv/fedora-38.sh | 1 -
ci/buildenv/fedora-rawhide-cross-mingw32.sh | 2 +-
ci/buildenv/fedora-rawhide-cross-mingw64.sh | 2 +-
ci/buildenv/fedora-rawhide.sh | 1 -
ci/buildenv/opensuse-leap-15.sh | 1 -
ci/buildenv/opensuse-tumbleweed.sh | 1 -
ci/buildenv/ubuntu-2004.sh | 1 -
ci/buildenv/ubuntu-2204.sh | 1 -
ci/cirrus/{macos-12.vars => macos-13.vars} | 2 +-
ci/cirrus/{macos-12.vars => macos-14.vars} | 2 +-
ci/containers/almalinux-8.Dockerfile | 1 -
ci/containers/alpine-317.Dockerfile | 1 -
ci/containers/alpine-edge.Dockerfile | 1 -
ci/containers/centos-stream-8.Dockerfile | 1 -
ci/containers/centos-stream-9.Dockerfile | 1 -
.../debian-11-cross-aarch64.Dockerfile | 1 -
.../debian-11-cross-armv6l.Dockerfile | 1 -
.../debian-11-cross-armv7l.Dockerfile | 1 -
ci/containers/debian-11-cross-i686.Dockerfile | 1 -
.../debian-11-cross-mips64el.Dockerfile | 1 -
.../debian-11-cross-mipsel.Dockerfile | 1 -
.../debian-11-cross-ppc64le.Dockerfile | 1 -
.../debian-11-cross-s390x.Dockerfile | 1 -
ci/containers/debian-11.Dockerfile | 1 -
.../debian-12-cross-aarch64.Dockerfile | 1 -
.../debian-12-cross-armv6l.Dockerfile | 1 -
.../debian-12-cross-armv7l.Dockerfile | 1 -
ci/containers/debian-12-cross-i686.Dockerfile | 1 -
.../debian-12-cross-mips64el.Dockerfile | 1 -
.../debian-12-cross-mipsel.Dockerfile | 1 -
.../debian-12-cross-ppc64le.Dockerfile | 1 -
.../debian-12-cross-s390x.Dockerfile | 1 -
ci/containers/debian-12.Dockerfile | 1 -
.../debian-sid-cross-aarch64.Dockerfile | 1 -
.../debian-sid-cross-armv6l.Dockerfile | 1 -
.../debian-sid-cross-armv7l.Dockerfile | 1 -
.../debian-sid-cross-i686.Dockerfile | 1 -
.../debian-sid-cross-mips64el.Dockerfile | 1 -
.../debian-sid-cross-ppc64le.Dockerfile | 1 -
.../debian-sid-cross-s390x.Dockerfile | 1 -
ci/containers/debian-sid.Dockerfile | 1 -
ci/containers/fedora-37.Dockerfile | 1 -
.../fedora-38-cross-mingw32.Dockerfile | 2 +-
.../fedora-38-cross-mingw64.Dockerfile | 2 +-
ci/containers/fedora-38.Dockerfile | 1 -
.../fedora-rawhide-cross-mingw32.Dockerfile | 2 +-
.../fedora-rawhide-cross-mingw64.Dockerfile | 2 +-
ci/containers/fedora-rawhide.Dockerfile | 1 -
ci/containers/opensuse-leap-15.Dockerfile | 1 -
ci/containers/opensuse-tumbleweed.Dockerfile | 1 -
ci/containers/ubuntu-2004.Dockerfile | 1 -
ci/containers/ubuntu-2204.Dockerfile | 1 -
ci/gitlab/builds.yml | 24 +++++++++++++++----
ci/manifest.yml | 11 +++++++--
88 files changed, 39 insertions(+), 92 deletions(-)
copy ci/cirrus/{macos-12.vars => macos-13.vars} (91%)
rename ci/cirrus/{macos-12.vars => macos-14.vars} (91%)
--
2.41.0
6 months, 2 weeks
[PATCH] virDomainDeviceInfoCheckABIStability: Implement proper check for CCW addresses
by Peter Krempa
CCW addresses need to be also checked for ABI stability.
Signed-off-by: Peter Krempa <pkrempa(a)redhat.com>
---
src/conf/domain_conf.c | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 80f467ae7a..5ce1793c2d 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -19719,10 +19719,21 @@ virDomainDeviceInfoCheckABIStability(virDomainDeviceInfo *src,
}
break;
+ case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_CCW:
+ if (src->addr.ccw.cssid != dst->addr.ccw.cssid ||
+ src->addr.ccw.ssid != dst->addr.ccw.ssid ||
+ src->addr.ccw.devno != dst->addr.ccw.devno) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+ _("Target device CCW address %1$x.%2$x.%3$04x does not match source %4$x.%5$x.%6$04x"),
+ dst->addr.ccw.cssid, dst->addr.ccw.ssid, dst->addr.ccw.devno,
+ src->addr.ccw.cssid, src->addr.ccw.ssid, src->addr.ccw.devno);
+ return false;
+ }
+ break;
+
case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_USB:
case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_SPAPRVIO:
case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_S390:
- case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_CCW:
case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_MMIO:
case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE:
case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_UNASSIGNED:
--
2.41.0
6 months, 2 weeks
[PATCH] virhostmem: Get total memory on macOS properly
by Michal Privoznik
Problem with HW_PHYSMEM sysctl on 64-bit macOS is that it
returns a 32-bit signed value. Thus it overflows. Switching to
HW_MEMSIZE is recommended as it's of an uint_64 type [1].
1: https://github.com/apple-oss-distributions/xnu/blob/xnu-10002.1.13/bsd/sy...
Reported-by: Jaroslav Suchanek <jsuchane(a)redhat.com>
Signed-off-by: Michal Privoznik <mprivozn(a)redhat.com>
---
src/util/virhostmem.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/src/util/virhostmem.c b/src/util/virhostmem.c
index 1da2759ac3..a7027af835 100644
--- a/src/util/virhostmem.c
+++ b/src/util/virhostmem.c
@@ -617,7 +617,10 @@ virHostMemGetTotal(void)
unsigned long long physmem = 0;
size_t len = sizeof(physmem);
- if (sysctlbyname("hw.physmem", &physmem, &len, NULL, 0) < 0) {
+ /* On macOS hw.physmem is int32_t which doesn't fly with >4GiB of memory.
+ * But hw.memsize is uint64_t. */
+ if (sysctlbyname("hw.memsize", &physmem, &len, NULL, 0) < 0 &&
+ sysctlbyname("hw.physmem", &physmem, &len, NULL, 0) < 0) {
virReportSystemError(errno, "%s",
_("Unable to query memory total"));
return 0;
--
2.41.0
6 months, 2 weeks
[libvirt PATCH] rpcgen: use proper operators when comparing types
by Laine Stump
flake8 (run on all python scripts as a part of the syntax checks)
version 6.1.0 (on macOS 14) issued many complaints like this on the
new rpcgen python scripts:
[...]libvirt/scripts/rpcgen/rpcgen/lexer.py:57:17: E721 do not compare types, for exact checks use `is` / `is not`, for instance checks use `isinstance()`
This patch changes all [type] == [type] to use "is" instead of "==",
and similarly to use "is not" instead of "!=".
(flake8 5.03, e.g. on Fedora 38, is just fine with using "==" and "!=",
but python on both likes "is" and "is not")
Fixes: commit v9.9.0-24-g8ec79e5e14
Fixes: commit v9.9.0-22-gca3f025011
Fixes: commit v9.9.0-21-g031efb691f
Fixes: commit v9.9.0-20-g8c8b97685b
Signed-off-by: Laine Stump <laine(a)redhat.com>
---
scripts/rpcgen/rpcgen/ast.py | 4 +-
scripts/rpcgen/rpcgen/generator.py | 26 ++++++------
scripts/rpcgen/rpcgen/lexer.py | 2 +-
scripts/rpcgen/rpcgen/parser.py | 68 +++++++++++++++---------------
4 files changed, 50 insertions(+), 50 deletions(-)
diff --git a/scripts/rpcgen/rpcgen/ast.py b/scripts/rpcgen/rpcgen/ast.py
index 3e3e089713..52d9c3ac46 100644
--- a/scripts/rpcgen/rpcgen/ast.py
+++ b/scripts/rpcgen/rpcgen/ast.py
@@ -185,9 +185,9 @@ class XDRTypeCustom(XDRType):
self.definition = definition
def is_scalar(self):
- if type(self.definition) == XDRDefinitionEnum:
+ if type(self.definition) is XDRDefinitionEnum:
return True
- if type(self.definition) == XDRDefinitionTypedef:
+ if type(self.definition) is XDRDefinitionTypedef:
return self.definition.decl.typ.is_scalar()
return False
diff --git a/scripts/rpcgen/rpcgen/generator.py b/scripts/rpcgen/rpcgen/generator.py
index 73731e1497..c6e210e7b0 100644
--- a/scripts/rpcgen/rpcgen/generator.py
+++ b/scripts/rpcgen/rpcgen/generator.py
@@ -81,7 +81,7 @@ class XDRTypeDeclarationGenerator(XDRVisitor):
)
def visit_declaration_variablearray(self, obj, indent, context):
- if type(obj.typ) == XDRTypeString:
+ if type(obj.typ) is XDRTypeString:
return "%schar *%s" % (indent, obj.identifier)
else:
code = (
@@ -178,10 +178,10 @@ class XDRTypeDeclarationGenerator(XDRVisitor):
+ "%s union {\n" % indent
)
for value in obj.cases:
- if type(value.decl.typ) == XDRTypeVoid:
+ if type(value.decl.typ) is XDRTypeVoid:
continue
code = code + self.visit_object(value, indent + " ") + ";\n"
- if obj.default is not None and type(obj.default.typ) != XDRTypeVoid:
+ if obj.default is not None and type(obj.default.typ) is not XDRTypeVoid:
code = code + self.visit_object(obj.default, indent + " ") + ";\n"
code = code + "%s } %su;\n" % (indent, prefix) + "%s}" % indent
return code
@@ -250,10 +250,10 @@ class XDRMarshallImplementationGenerator(XDRVisitor):
return code
def generate_type_call(self, decl, field, typename, embedded=False, indent=""):
- if type(decl.typ) == XDRTypeVoid:
+ if type(decl.typ) is XDRTypeVoid:
return ""
- if type(decl) == XDRDeclarationFixedArray:
- if type(decl.typ) == XDRTypeOpaque:
+ if type(decl) is XDRDeclarationFixedArray:
+ if type(decl.typ) is XDRTypeOpaque:
code = "%s if (!xdr_%s(xdrs, %s, %s))\n" % (
indent,
self.visit_object(decl.typ, context="func"),
@@ -270,7 +270,7 @@ class XDRMarshallImplementationGenerator(XDRVisitor):
self.visit_object(decl.typ),
self.visit_object(decl.typ, context="func"),
)
- elif type(decl) == XDRDeclarationVariableArray:
+ elif type(decl) is XDRDeclarationVariableArray:
fieldRef = "."
pointerStr = ""
if embedded:
@@ -278,7 +278,7 @@ class XDRMarshallImplementationGenerator(XDRVisitor):
else:
fieldRef = "->"
- if type(decl.typ) == XDRTypeString:
+ if type(decl.typ) is XDRTypeString:
code = "%s if (!xdr_%s(xdrs, %s%s, %s))\n" % (
indent,
self.visit_object(decl.typ, context="func"),
@@ -286,7 +286,7 @@ class XDRMarshallImplementationGenerator(XDRVisitor):
field,
decl.maxlength,
)
- elif type(decl.typ) == XDRTypeOpaque:
+ elif type(decl.typ) is XDRTypeOpaque:
code = "%s if (!xdr_bytes(xdrs, (char **)&%s%s%s_val, " % (
indent,
field,
@@ -311,7 +311,7 @@ class XDRMarshallImplementationGenerator(XDRVisitor):
self.visit_object(decl.typ, context="func"),
)
)
- elif type(decl) == XDRDeclarationPointer:
+ elif type(decl) is XDRDeclarationPointer:
pointerStr = ""
if embedded:
pointerStr = "&"
@@ -327,9 +327,9 @@ class XDRMarshallImplementationGenerator(XDRVisitor):
else:
pointerStr = ""
isFixedArray = (
- type(decl.typ) == XDRTypeCustom
- and type(decl.typ.definition) == XDRDefinitionTypedef
- and type(decl.typ.definition.decl) == XDRDeclarationFixedArray
+ type(decl.typ) is XDRTypeCustom
+ and type(decl.typ.definition) is XDRDefinitionTypedef
+ and type(decl.typ.definition.decl) is XDRDeclarationFixedArray
)
if embedded and not isFixedArray:
diff --git a/scripts/rpcgen/rpcgen/lexer.py b/scripts/rpcgen/rpcgen/lexer.py
index 989c2ae216..a27d7005b8 100644
--- a/scripts/rpcgen/rpcgen/lexer.py
+++ b/scripts/rpcgen/rpcgen/lexer.py
@@ -55,7 +55,7 @@ class XDRToken(abc.ABC):
def __eq__(self, other):
return (
- type(self) == type(other)
+ type(self) is type(other)
and self.line == other.line
and self.column == other.column
and self.value == other.value
diff --git a/scripts/rpcgen/rpcgen/parser.py b/scripts/rpcgen/rpcgen/parser.py
index 7efbe5468e..c01ae56755 100644
--- a/scripts/rpcgen/rpcgen/parser.py
+++ b/scripts/rpcgen/rpcgen/parser.py
@@ -162,10 +162,10 @@ class XDRParser:
if token is None:
return None
- if type(token) == XDRTokenCEscape:
+ if type(token) is XDRTokenCEscape:
return XDRDefinitionCEscape(token.value[1:])
- if type(token) != XDRTokenIdentifier:
+ if type(token) is not XDRTokenIdentifier:
raise Exception("Expected identifier, but got %s" % token)
defs = {
@@ -186,18 +186,18 @@ class XDRParser:
definition = func()
semi = self.lexer.next()
- if type(semi) != XDRTokenPunctuation or semi.value != ";":
+ if type(semi) is not XDRTokenPunctuation or semi.value != ";":
raise Exception("Expected ';', but got %s" % semi)
return definition
def parse_definition_const(self):
ident = self.lexer.next()
- if type(ident) != XDRTokenIdentifier:
+ if type(ident) is not XDRTokenIdentifier:
raise Exception("Expected identifier, but got %s" % ident)
assign = self.lexer.next()
- if type(assign) != XDRTokenPunctuation or assign.value != "=":
+ if type(assign) is not XDRTokenPunctuation or assign.value != "=":
raise Exception("Expected '=', but got %s" % assign)
const = self.lexer.next()
@@ -217,7 +217,7 @@ class XDRParser:
def parse_definition_enum(self):
name = self.lexer.next()
- if type(name) != XDRTokenIdentifier:
+ if type(name) is not XDRTokenIdentifier:
raise Exception("Expected identifier, but got %s" % name)
body = self.parse_enum_body()
@@ -231,7 +231,7 @@ class XDRParser:
def parse_definition_struct(self):
name = self.lexer.next()
- if type(name) != XDRTokenIdentifier:
+ if type(name) is not XDRTokenIdentifier:
raise Exception("Expected identifier, but got %s" % name)
body = self.parse_struct_body()
@@ -245,7 +245,7 @@ class XDRParser:
def parse_definition_union(self):
name = self.lexer.next()
- if type(name) != XDRTokenIdentifier:
+ if type(name) is not XDRTokenIdentifier:
raise Exception("Expected identifier, but got %s" % name)
body = self.parse_union_body()
@@ -260,23 +260,23 @@ class XDRParser:
def parse_declaration(self):
typ = self.parse_type()
- if type(typ) == XDRTypeVoid:
+ if type(typ) is XDRTypeVoid:
return XDRDeclarationScalar(typ, None)
ident = self.lexer.next()
pointer = False
- if type(ident) == XDRTokenPunctuation:
+ if type(ident) is XDRTokenPunctuation:
if ident.value != "*":
raise Exception("Expected '*' or identifer, but got %s" % ident)
- if type(typ) == XDRTypeString or type(typ) == XDRTypeOpaque:
+ if type(typ) is XDRTypeString or type(typ) is XDRTypeOpaque:
raise Exception("Pointer invalid for 'string' and 'opaque' types")
pointer = True
ident = self.lexer.next()
bracket = self.lexer.peek()
- if type(bracket) == XDRTokenPunctuation:
+ if type(bracket) is XDRTokenPunctuation:
if bracket.value == "[":
_ = self.lexer.next()
value = self.lexer.next()
@@ -284,10 +284,10 @@ class XDRParser:
raise Exception("Expected constant, but got %s" % value)
close = self.lexer.next()
- if type(close) != XDRTokenPunctuation or close.value != "]":
+ if type(close) is not XDRTokenPunctuation or close.value != "]":
raise Exception("Expected ']', but got %s" % value)
- if type(typ) == XDRTypeString:
+ if type(typ) is XDRTypeString:
raise Exception("Fixed array invalid for 'string' type")
return XDRDeclarationFixedArray(typ, ident.value, value.value)
elif bracket.value == "<":
@@ -298,7 +298,7 @@ class XDRParser:
value = self.lexer.next().value
close = self.lexer.next()
- if type(close) != XDRTokenPunctuation or close.value != ">":
+ if type(close) is not XDRTokenPunctuation or close.value != ">":
raise Exception("Expected '>', but got %s" % close)
return XDRDeclarationVariableArray(typ, ident.value, value)
@@ -310,12 +310,12 @@ class XDRParser:
def parse_type(self):
typ = self.lexer.next()
- if type(typ) != XDRTokenIdentifier:
+ if type(typ) is not XDRTokenIdentifier:
raise Exception("Expected identifier, but got %s" % typ)
if typ.value == "unsigned":
typ = self.lexer.peek()
- if type(typ) != XDRTokenIdentifier:
+ if type(typ) is not XDRTokenIdentifier:
raise Exception("Expected identifier, but got %s" % typ)
if typ.value == "char":
@@ -366,25 +366,25 @@ class XDRParser:
def parse_enum_body(self):
body = self.lexer.next()
- if type(body) != XDRTokenPunctuation or body.value != "{":
+ if type(body) is not XDRTokenPunctuation or body.value != "{":
raise Exception("Expected '{', but got %s" % body)
values = []
while True:
ident = self.lexer.next()
- if type(ident) != XDRTokenIdentifier:
+ if type(ident) is not XDRTokenIdentifier:
raise Exception("Expected identifier, but got %s" % ident)
equal = self.lexer.next()
- if type(equal) != XDRTokenPunctuation or equal.value != "=":
+ if type(equal) is not XDRTokenPunctuation or equal.value != "=":
raise Exception("Expected '=', but got %s" % ident)
value = self.lexer.next()
- if type(value) != XDRTokenConstant:
+ if type(value) is not XDRTokenConstant:
raise Exception("Expected constant, but got %s" % ident)
separator = self.lexer.next()
- if type(separator) != XDRTokenPunctuation and separator.value not in [
+ if type(separator) is not XDRTokenPunctuation and separator.value not in [
"}",
",",
]:
@@ -403,7 +403,7 @@ class XDRParser:
def parse_struct_body(self):
body = self.lexer.next()
- if type(body) != XDRTokenPunctuation or body.value != "{":
+ if type(body) is not XDRTokenPunctuation or body.value != "{":
raise Exception("Expected '{', but got %s" % body)
fields = []
@@ -412,11 +412,11 @@ class XDRParser:
fields.append(field)
separator = self.lexer.next()
- if type(separator) != XDRTokenPunctuation and separator.value != ";":
+ if type(separator) is not XDRTokenPunctuation and separator.value != ";":
raise Exception("Expected ';', but got %s" % separator)
end = self.lexer.peek()
- if type(end) == XDRTokenPunctuation and end.value == "}":
+ if type(end) is XDRTokenPunctuation and end.value == "}":
break
# discard the '}' we peeked at to end the loop
@@ -429,28 +429,28 @@ class XDRParser:
def parse_union_body(self):
ident = self.lexer.next()
- if type(ident) != XDRTokenIdentifier or ident.value != "switch":
+ if type(ident) is not XDRTokenIdentifier or ident.value != "switch":
raise Exception("Expected 'switch', but got %s" % ident)
bracket = self.lexer.next()
- if type(bracket) != XDRTokenPunctuation or bracket.value != "(":
+ if type(bracket) is not XDRTokenPunctuation or bracket.value != "(":
raise Exception("Expected '(', but got %s" % bracket)
discriminator = self.parse_declaration()
bracket = self.lexer.next()
- if type(bracket) != XDRTokenPunctuation or bracket.value != ")":
+ if type(bracket) is not XDRTokenPunctuation or bracket.value != ")":
raise Exception("Expected ')', but got %s" % bracket)
bracket = self.lexer.next()
- if type(bracket) != XDRTokenPunctuation or bracket.value != "{":
+ if type(bracket) is not XDRTokenPunctuation or bracket.value != "{":
raise Exception("Expected '{', but got %s" % bracket)
default = None
cases = []
while True:
ident = self.lexer.next()
- if type(ident) != XDRTokenIdentifier or ident.value not in [
+ if type(ident) is not XDRTokenIdentifier or ident.value not in [
"default",
"case",
]:
@@ -463,7 +463,7 @@ class XDRParser:
raise Exception("Expected constant, but got %s" % value)
sep = self.lexer.next()
- if type(sep) != XDRTokenPunctuation or sep.value != ":":
+ if type(sep) is not XDRTokenPunctuation or sep.value != ":":
raise Exception("Expected ':', but got %s" % value)
decl = self.parse_declaration()
@@ -475,17 +475,17 @@ class XDRParser:
raise Exception("Duplicate 'default' clause")
sep = self.lexer.next()
- if type(sep) != XDRTokenPunctuation or sep.value != ":":
+ if type(sep) is not XDRTokenPunctuation or sep.value != ":":
raise Exception("Expected ':', but got %s" % value)
default = self.parse_declaration()
separator = self.lexer.next()
- if type(separator) != XDRTokenPunctuation and separator.value != ";":
+ if type(separator) is not XDRTokenPunctuation and separator.value != ";":
raise Exception("Expected ';', but got %s" % bracket)
end = self.lexer.peek()
- if type(end) == XDRTokenPunctuation and end.value == "}":
+ if type(end) is XDRTokenPunctuation and end.value == "}":
break
# discard the '}' we peeked at to end the loop
--
2.41.0
6 months, 2 weeks