From nobody Thu May 15 17:41:06 2025 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1506943560651156.13495884896042; Mon, 2 Oct 2017 04:26:00 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8995280F7A; Mon, 2 Oct 2017 11:25:59 +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 6743490817; Mon, 2 Oct 2017 11:25:59 +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 0AADA18355C7; Mon, 2 Oct 2017 11:25:59 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v92B1WMb012895 for ; Mon, 2 Oct 2017 07:01:32 -0400 Received: by smtp.corp.redhat.com (Postfix) id 61043503B0; Mon, 2 Oct 2017 11:01:32 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.192]) by smtp.corp.redhat.com (Postfix) with ESMTP id DB2B58E7A2 for ; Mon, 2 Oct 2017 11:01:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 8995280F7A Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=libvir-list-bounces@redhat.com From: Michal Privoznik To: libvir-list@redhat.com Date: Mon, 2 Oct 2017 13:01:20 +0200 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 3/3] virDomainNetFindIdx: Ignore auto generated MAC addresses 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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Mon, 02 Oct 2017 11:26:00 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" When detaching an from domain, it's MAC address is parsed and if not present one is generated. If, however, no corresponding interface is found in the domain, the following error is reported: error: operation failed: no device matching mac address 52:54:00:75:32:5b f= ound where the MAC address is the auto generated one. This might be very confusing. Solution to this is to ignore auto generated MAC address when looking up the device. Signed-off-by: Michal Privoznik Reviewed-by: Erik Skultety to this patch. --- src/conf/domain_conf.c | 45 +++++++++++++++++++++++++++++++++++---------- 1 file changed, 35 insertions(+), 10 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 87192eb2d..aab43d307 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -15634,11 +15634,17 @@ int virDomainNetInsert(virDomainDefPtr def, virDo= mainNetDefPtr net) return 0; } =20 -/* virDomainNetFindIdx: search according to mac address and guest side - * PCI address (if specified) +/** + * virDomainNetFindIdx: + * @def: domain definition + * @net: interface definition * - * Return: index of match if unique match found - * -1 otherwise and an error is logged + * Lookup domain's network interface based on passed @net + * definition. If @net's MAC address was auto generated, + * the MAC comparison is ignored. + * + * Return: index of match if unique match found, + * -1 otherwise and an error is logged. */ int virDomainNetFindIdx(virDomainDefPtr def, virDomainNetDefPtr net) @@ -15646,11 +15652,13 @@ virDomainNetFindIdx(virDomainDefPtr def, virDomai= nNetDefPtr net) size_t i; int matchidx =3D -1; char mac[VIR_MAC_STRING_BUFLEN]; + bool MACAddrSpecified =3D !net->mac.generated; bool PCIAddrSpecified =3D virDomainDeviceAddressIsValid(&net->info, VIR_DOMAIN_DEVIC= E_ADDRESS_TYPE_PCI); =20 for (i =3D 0; i < def->nnets; i++) { - if (virMacAddrCmp(&def->nets[i]->mac, &net->mac)) + if (MACAddrSpecified && + virMacAddrCmp(&def->nets[i]->mac, &net->mac) !=3D 0) continue; =20 if ((matchidx >=3D 0) && !PCIAddrSpecified) { @@ -15660,9 +15668,15 @@ virDomainNetFindIdx(virDomainDefPtr def, virDomain= NetDefPtr net) * specify only vendor and product ID, and there may be * multiples of those. */ - virReportError(VIR_ERR_OPERATION_FAILED, - _("multiple devices matching mac address %s fou= nd"), - virMacAddrFormat(&net->mac, mac)); + if (MACAddrSpecified) { + virReportError(VIR_ERR_OPERATION_FAILED, + _("multiple devices matching mac address %s= found"), + virMacAddrFormat(&net->mac, mac)); + } else { + virReportError(VIR_ERR_OPERATION_FAILED, "%s", + _("multiple matching devices found")); + } + return -1; } if (PCIAddrSpecified) { @@ -15679,8 +15693,9 @@ virDomainNetFindIdx(virDomainDefPtr def, virDomainN= etDefPtr net) matchidx =3D i; } } + if (matchidx < 0) { - if (PCIAddrSpecified) { + if (MACAddrSpecified && PCIAddrSpecified) { virReportError(VIR_ERR_OPERATION_FAILED, _("no device matching mac address %s found on " "%.4x:%.2x:%.2x.%.1x"), @@ -15689,10 +15704,20 @@ virDomainNetFindIdx(virDomainDefPtr def, virDomai= nNetDefPtr net) net->info.addr.pci.bus, net->info.addr.pci.slot, net->info.addr.pci.function); - } else { + } else if (PCIAddrSpecified) { + virReportError(VIR_ERR_OPERATION_FAILED, + _("no device found on %.4x:%.2x:%.2x.%.1x"), + net->info.addr.pci.domain, + net->info.addr.pci.bus, + net->info.addr.pci.slot, + net->info.addr.pci.function); + } else if (MACAddrSpecified) { virReportError(VIR_ERR_OPERATION_FAILED, _("no device matching mac address %s found"), virMacAddrFormat(&net->mac, mac)); + } else { + virReportError(VIR_ERR_OPERATION_FAILED, "%s", + _("no matching device found")); } } return matchidx; --=20 2.13.5 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list