From nobody Sun Feb 8 16:50:30 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1531775699759137.93003793858452; Mon, 16 Jul 2018 14:14:59 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 67C1E30E2671; Mon, 16 Jul 2018 21:14:58 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 251ED60C80; Mon, 16 Jul 2018 21:14:58 +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 CC5B34A465; Mon, 16 Jul 2018 21:14:57 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6GLET2s003176 for ; Mon, 16 Jul 2018 17:14:29 -0400 Received: by smtp.corp.redhat.com (Postfix) id DB47E600CD; Mon, 16 Jul 2018 21:14:29 +0000 (UTC) Received: from unknown4CEB42C824F4.redhat.com (ovpn-116-112.phx2.redhat.com [10.3.116.112]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9BCD3600C9 for ; Mon, 16 Jul 2018 21:14:29 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Mon, 16 Jul 2018 17:14:22 -0400 Message-Id: <20180716211424.15582-2-jferlan@redhat.com> In-Reply-To: <20180716211424.15582-1-jferlan@redhat.com> References: <20180716211424.15582-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 1/3] conf: Add @target_bus to virDomainDefHasDeviceAddress 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Mon, 16 Jul 2018 21:14:59 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Add the @target_bus argument which will allow a caller to pass the virDomainDiskBus onto which the @info (
) would be placed. This will allow logic to provide the bus for cold plugged devices to determine whether the about to be added device
is already present on the @bus. Just passing the @info isn't sufficient since, for example, ADDRESS_TYPE_DRIVE is used for both SCSI and IDE 's as well as 'scsi' and 'scsi_host' 's. Signed-off-by: John Ferlan --- src/conf/domain_conf.c | 32 ++++++++++++++++++++++++++++---- src/conf/domain_conf.h | 3 ++- src/qemu/qemu_driver.c | 2 +- 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 7396616eda..82df8012af 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -3688,13 +3688,31 @@ virDomainDeviceGetInfo(virDomainDeviceDefPtr device) } =20 =20 +struct virDomainDefHasDeviceAddressIteratorData { + int target_bus; /* virDomainDiskBus or -1 */ + virDomainDeviceInfoPtr info; +}; + static int virDomainDefHasDeviceAddressIterator(virDomainDefPtr def ATTRIBUTE_UNUSED, - virDomainDeviceDefPtr dev ATTRIBUTE_U= NUSED, + virDomainDeviceDefPtr dev, virDomainDeviceInfoPtr info, void *opaque) { - virDomainDeviceInfoPtr needle =3D opaque; + struct virDomainDefHasDeviceAddressIteratorData *data =3D opaque; + int target_bus =3D data->target_bus; + virDomainDeviceInfoPtr needle =3D data->info; + + /* If the target_bus of the about to be cold plugged device needs + * to be checked and the currently to be matched device is a disk, + * then compare it's target bus against the new device. If they don't + * match, then no need to compare. For disks this ensures addresses + * using drive won't erroneously match if one is IDE and another is SC= SI. + * Likewise, for SCSI hostdev's this ensures the new hostdev doesn't + * erroneously match an IDE for the address comparison. */ + if (target_bus !=3D -1 && dev->type =3D=3D VIR_DOMAIN_DEVICE_DISK && + dev->data.disk->bus !=3D target_bus) + return 0; =20 /* break iteration if the info was found */ if (virDomainDeviceInfoAddressIsEqual(info, needle)) @@ -3933,12 +3951,18 @@ virDomainDeviceInfoIterate(virDomainDefPtr def, =20 bool virDomainDefHasDeviceAddress(virDomainDefPtr def, + int target_bus, virDomainDeviceInfoPtr info) { + struct virDomainDefHasDeviceAddressIteratorData data =3D { + .target_bus =3D target_bus, + .info =3D info, + }; + if (virDomainDeviceInfoIterateInternal(def, virDomainDefHasDeviceAddressIte= rator, true, - info) < 0) + &data) < 0) return true; =20 return false; @@ -17508,7 +17532,7 @@ virDomainMemoryInsert(virDomainDefPtr def, int id =3D def->nmems; =20 if (mem->info.type !=3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE && - virDomainDefHasDeviceAddress(def, &mem->info)) { + virDomainDefHasDeviceAddress(def, -1, &mem->info)) { virReportError(VIR_ERR_OPERATION_INVALID, "%s", _("Domain already contains a device with the same " "address")); diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 0f10e242fd..82231161c6 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -2912,8 +2912,9 @@ int virDomainDeviceInfoIterate(virDomainDefPtr def, void *opaque); =20 bool virDomainDefHasDeviceAddress(virDomainDefPtr def, + int target_bus, virDomainDeviceInfoPtr info) - ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK; + ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(3) ATTRIBUTE_RETURN_CHECK; =20 void virDomainDefFree(virDomainDefPtr vm); =20 diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 8fae46370e..5f91d463ae 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -8082,7 +8082,7 @@ qemuDomainAttachDeviceConfig(virDomainDefPtr vmdef, =20 case VIR_DOMAIN_DEVICE_RNG: if (dev->data.rng->info.type !=3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE_N= ONE && - virDomainDefHasDeviceAddress(vmdef, &dev->data.rng->info)) { + virDomainDefHasDeviceAddress(vmdef, -1, &dev->data.rng->info))= { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("a device with the same address already exist= s ")); return -1; --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list