From nobody Mon Feb 9 11:47:18 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1558352288; cv=none; d=zoho.com; s=zohoarc; b=W1w7GceHgLDMeciZGSwC/1UoWeGjxNVOM4kX93rCTUfhd1TsZ/kLuIkURDO74kimODF2p7QGYfbJV0XDAj5rPGivg9ip+RqmBJFI88EAdugqxVfdWTBIzjyy/aP6Xp0Ip0YPd9KOd9HzOX3wBGDjyIljns8S70lnYo7FrSruwpc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1558352288; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=72+yEzucid7WMjSk9t8mKwp5JU6zvvC+pwMOtpzYU5w=; b=l3eUTWm4hn0uSxJgPEjYMiD76tgO7TGXqFFBHcZN6tDcLbOxJJ/jT3nKjHe781xN5si3Sb+g6qBTNz7Qc9G7tHe2pPy8zUJ6Q82BOZHxV5LXO4swGPAyx8khwo4R6A9dt0o2sol2/39iezvt8f7z7OmiQEd7QIe89XhW8nmh3kc= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1558352288450341.16518823376146; Mon, 20 May 2019 04:38:08 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 25207C04D318; Mon, 20 May 2019 11:38:07 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C6296100200D; Mon, 20 May 2019 11:38:06 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 810261806B18; Mon, 20 May 2019 11:38:06 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x4KBc2SL019646 for ; Mon, 20 May 2019 07:38:02 -0400 Received: by smtp.corp.redhat.com (Postfix) id 3CDA95DD8F; Mon, 20 May 2019 11:38:02 +0000 (UTC) Received: from kinshicho.redhat.com (ovpn-204-17.brq.redhat.com [10.40.204.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 960E35DD8A for ; Mon, 20 May 2019 11:38:01 +0000 (UTC) From: Andrea Bolognani To: libvir-list@redhat.com Date: Mon, 20 May 2019 13:37:49 +0200 Message-Id: <20190520113753.12345-5-abologna@redhat.com> In-Reply-To: <20190520113753.12345-1-abologna@redhat.com> References: <20190520113753.12345-1-abologna@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 4/8] conf: Allow NULL for virDomainDeviceInfoCallback X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Mon, 20 May 2019 11:38:07 +0000 (UTC) Content-Type: text/plain; charset="utf-8" The virDomainDeviceInfoIterate() function was initially written with the expectation that all devices would embed a virDomainDeviceInfo, and thus the user-provided callback would never be passed NULL; however, that doesn't really represent reality, as multiple devices don't have any virDomainDeviceInfo associated with them. Since we still want to be able to iterate over those devices, clarify that callbacks are expected to be able to handle NULL being passed to them, and update all existing callbacks so that they actually do so. Signed-off-by: Andrea Bolognani --- src/bhyve/bhyve_device.c | 4 ++++ src/conf/domain_addr.c | 9 +++++++++ src/conf/domain_conf.c | 34 +++++++++++++++++++++++++++++++- src/libxl/libxl_driver.c | 3 +++ src/qemu/qemu_domain_address.c | 36 +++++++++++++++++++++++++++++++--- src/qemu/qemu_hotplug.c | 3 +++ 6 files changed, 85 insertions(+), 4 deletions(-) diff --git a/src/bhyve/bhyve_device.c b/src/bhyve/bhyve_device.c index 201044d9e6..8c897cbd8d 100644 --- a/src/bhyve/bhyve_device.c +++ b/src/bhyve/bhyve_device.c @@ -37,6 +37,10 @@ bhyveCollectPCIAddress(virDomainDefPtr def ATTRIBUTE_UNU= SED, void *opaque) { int ret =3D -1; + + if (!info) + return 0; + if (info->type =3D=3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DRIVE) return 0; =20 diff --git a/src/conf/domain_addr.c b/src/conf/domain_addr.c index 04c4e6d7e1..548af89682 100644 --- a/src/conf/domain_addr.c +++ b/src/conf/domain_addr.c @@ -1468,6 +1468,9 @@ virDomainCCWAddressAllocate(virDomainDefPtr def ATTRI= BUTE_UNUSED, virDomainDeviceInfoPtr info, void *data) { + if (!info) + return 0; + return virDomainCCWAddressAssign(info, data, true); } =20 @@ -1477,6 +1480,9 @@ virDomainCCWAddressValidate(virDomainDefPtr def ATTRI= BUTE_UNUSED, virDomainDeviceInfoPtr info, void *data) { + if (!info) + return 0; + return virDomainCCWAddressAssign(info, data, false); } =20 @@ -1694,6 +1700,9 @@ virDomainVirtioSerialAddrReserve(virDomainDefPtr def = ATTRIBUTE_UNUSED, bool b; ssize_t i; =20 + if (!info) + return 0; + if (!virDomainVirtioSerialAddrIsComplete(info)) return 0; =20 diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index a3a514136b..f42d331341 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -4049,6 +4049,9 @@ virDomainDefHasDeviceAddressIterator(virDomainDefPtr = def ATTRIBUTE_UNUSED, { virDomainDeviceInfoPtr needle =3D opaque; =20 + if (!info) + return 0; + /* break iteration if the info was found */ if (virDomainDeviceInfoAddressIsEqual(info, needle)) return -1; @@ -4297,6 +4300,21 @@ virDomainDeviceInfoIterateInternal(virDomainDefPtr d= ef, } =20 =20 +/** + * virDomainDeviceInfoIterate: + * @def: domain definition + * @cb: callback + * @opaque: user data + * + * Call @cb for each device in @def. + * + * Note that some devices might not have a virDomainDeviceInfoPtr associat= ed + * with them, in which case the corresponding argument passed to the callb= ack + * will be NULL: @cb should be written to account for this possibility, wh= ich + * usually involves returning early. + * + * Return: 0 on success, <0 on failure + */ int virDomainDeviceInfoIterate(virDomainDefPtr def, virDomainDeviceInfoCallback cb, @@ -5543,6 +5561,9 @@ virDomainDefCollectBootOrder(virDomainDefPtr def ATTR= IBUTE_UNUSED, virHashTablePtr bootHash =3D data; VIR_AUTOFREE(char *) order =3D NULL; =20 + if (!info) + return 0; + if (info->bootIndex =3D=3D 0) return 0; =20 @@ -6383,7 +6404,12 @@ virDomainDeviceDefValidateAliasesIterator(virDomainD= efPtr def, void *opaque) { struct virDomainDefValidateAliasesData *data =3D opaque; - const char *alias =3D info->alias; + const char *alias; + + if (!info) + return 0; + + alias =3D info->alias; =20 if (!virDomainDeviceAliasIsUserAlias(alias)) return 0; @@ -28767,6 +28793,9 @@ virDomainDeviceInfoCheckBootIndex(virDomainDefPtr d= ef ATTRIBUTE_UNUSED, { virDomainCompatibleDeviceDataPtr data =3D opaque; =20 + if (!info) + return 0; + /* Ignore the device we're about to update */ if (data->oldInfo =3D=3D info) return 0; @@ -29856,6 +29885,9 @@ virDomainDefFindDeviceCallback(virDomainDefPtr def = ATTRIBUTE_UNUSED, { virDomainDefFindDeviceCallbackData *data =3D opaque; =20 + if (!info) + return 0; + if (STREQ_NULLABLE(info->alias, data->devAlias)) { *data->dev =3D *dev; return -1; diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index 2b9c6f1866..560f278761 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -3593,6 +3593,9 @@ libxlComparePCIDevice(virDomainDefPtr def ATTRIBUTE_U= NUSED, { virDomainDeviceInfoPtr info2 =3D opaque; =20 + if (!info1) + return 0; + if (info1->type !=3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI || info2->type !=3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI) return 0; diff --git a/src/qemu/qemu_domain_address.c b/src/qemu/qemu_domain_address.c index 4b99e8ca93..5bef29b9df 100644 --- a/src/qemu/qemu_domain_address.c +++ b/src/qemu/qemu_domain_address.c @@ -169,6 +169,9 @@ qemuDomainSpaprVIOFindByReg(virDomainDefPtr def ATTRIBU= TE_UNUSED, { virDomainDeviceInfoPtr target =3D opaque; =20 + if (!info) + return 0; + if (info->type !=3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE_SPAPRVIO) return 0; =20 @@ -427,6 +430,9 @@ qemuDomainHasVirtioMMIODevicesCallback(virDomainDefPtr = def ATTRIBUTE_UNUSED, virDomainDeviceInfoPtr info, void *opaque) { + if (!info) + return 0; + if (info->type =3D=3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_MMIO) { /* We can stop iterating as soon as we find the first * virtio-mmio device */ @@ -1083,6 +1089,9 @@ qemuDomainFillDevicePCIConnectFlagsIter(virDomainDefP= tr def ATTRIBUTE_UNUSED, { qemuDomainFillDevicePCIConnectFlagsIterData *data =3D opaque; =20 + if (!info) + return 0; + info->pciConnectFlags =3D qemuDomainDeviceCalculatePCIConnectFlags(dev, data->driver, data->pcieFlags, @@ -1139,6 +1148,9 @@ qemuDomainFillDevicePCIExtensionFlagsIter(virDomainDe= fPtr def ATTRIBUTE_UNUSED, { virQEMUCapsPtr qemuCaps =3D opaque; =20 + if (!info) + return 0; + info->pciAddrExtFlags =3D qemuDomainDeviceCalculatePCIAddressExtensionFlags(qemuCaps, dev); =20 @@ -1188,6 +1200,9 @@ qemuDomainFindUnusedIsolationGroupIter(virDomainDefPt= r def ATTRIBUTE_UNUSED, { unsigned int *isolationGroup =3D opaque; =20 + if (!info) + return 0; + if (info->isolationGroup =3D=3D *isolationGroup) return -1; =20 @@ -1479,7 +1494,12 @@ qemuDomainAssignPCIAddressExtension(virDomainDefPtr = def ATTRIBUTE_UNUSED, void *opaque) { virDomainPCIAddressSetPtr addrs =3D opaque; - virPCIDeviceAddressPtr addr =3D &info->addr.pci; + virPCIDeviceAddressPtr addr; + + if (!info) + return 0; + + addr =3D &info->addr.pci; =20 if (info->type =3D=3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI) addr->extFlags =3D info->pciAddrExtFlags; @@ -1498,7 +1518,12 @@ qemuDomainCollectPCIAddress(virDomainDefPtr def ATTR= IBUTE_UNUSED, { virDomainPCIAddressSetPtr addrs =3D opaque; int ret =3D -1; - virPCIDeviceAddressPtr addr =3D &info->addr.pci; + virPCIDeviceAddressPtr addr; + + if (!info) + return 0; + + addr =3D &info->addr.pci; =20 if (!virDeviceInfoPCIAddressIsPresent(info) || ((device->type =3D=3D VIR_DOMAIN_DEVICE_HOSTDEV) && @@ -1590,7 +1615,12 @@ qemuDomainCollectPCIAddressExtension(virDomainDefPtr= def ATTRIBUTE_UNUSED, void *opaque) { virDomainPCIAddressSetPtr addrs =3D opaque; - virPCIDeviceAddressPtr addr =3D &info->addr.pci; + virPCIDeviceAddressPtr addr; + + if (!info) + return 0; + + addr =3D &info->addr.pci; =20 if (info->type =3D=3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI) addr->extFlags =3D info->pciAddrExtFlags; diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 59ff88565d..e275685a60 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -4415,6 +4415,9 @@ static int qemuComparePCIDevice(virDomainDefPtr def A= TTRIBUTE_UNUSED, { virDomainDeviceInfoPtr info2 =3D opaque; =20 + if (!info1->type) + return 0; + if (info1->type !=3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI || info2->type !=3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI) return 0; --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list