From nobody Wed May 15 15:55:16 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 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=1621520350; cv=none; d=zohomail.com; s=zohoarc; b=kknm8mcmAb62zL59Adf68RWs8Vcmh8DlXYyE6f2zzODkvZ7C2kFzDE1E0aayhdmkDTX02zYG+vl2tH9p4SQcMc9yy0dqHGWdUb3G/1a/AysjIv55NaCNok83i/1IfXfUrjeRsUxdpypOFzuZxqQJ0EzbLUOM36ZFcsQ+rh6/tKw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1621520350; h=Content-Type:Content-Transfer-Encoding:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=wKFHkmH/6WmzWxuREYOayT033Kv928aOAHwVvWwwl3k=; b=D2JmQInr7QccNyhodUTrbcrAiOzxpTfNu0d8MJx+2XWbYAEx7wuFpTPbx4ai/5Ek5MXKOLkm1pVvw/re2lcCNmRfyJblqZ3AFGCM5rgsBKD8rXjK3H2aVXYlrY4LfhTkyeThhYTXonXc3rhaGf9DoAXh4fQnw12Dy0iVsFFbmx8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 162152035065968.37287499255422; Thu, 20 May 2021 07:19:10 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-554-VYzMeS7UN86Kjj_R_F7vSg-1; Thu, 20 May 2021 10:19:07 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 151DC8042A6; Thu, 20 May 2021 14:19:03 +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 381165D742; Thu, 20 May 2021 14:19:02 +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 14B4955353; Thu, 20 May 2021 14:19:00 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 14KEDiDA011301 for ; Thu, 20 May 2021 10:13:44 -0400 Received: by smtp.corp.redhat.com (Postfix) id 8B746608DB; Thu, 20 May 2021 14:13:44 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.40.193.145]) by smtp.corp.redhat.com (Postfix) with ESMTP id B1DC0687DB for ; Thu, 20 May 2021 14:13:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1621520349; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=wKFHkmH/6WmzWxuREYOayT033Kv928aOAHwVvWwwl3k=; b=esRMw75EdaMqvu6BElnwmYHq4jeRkAAPi1y+n/E/jTnJdxS+HMlHMWH7NcwxuGVALfbPh9 BSU6sXM7mB2b2R798VXCv5BNb/XUsFfeN/XYxVVeBJQEIgpRGnyWLJf9LZP4b/oxdslPN5 2GA4hHlTKqEXEf+PLJtEYigmXoF4hAA= X-MC-Unique: VYzMeS7UN86Kjj_R_F7vSg-1 From: Kristina Hanicova To: libvir-list@redhat.com Subject: [PATCH v2] conf: Report alias name of the detached device in error Date: Thu, 20 May 2021 16:13:34 +0200 Message-Id: <51a288360bb499ea379e77785f9d3851d14bc4c4.1621519824.git.khanicov@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" This is v2 from: https://listman.redhat.com/archives/libvir-list/2021-May/msg00481.html I have reworked the code a bit to have only one error report instead of multiple ones with different combinations of possible matching items. Suggested by Laine. Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=3D1942367 Signed-off-by: Kristina Hanicova Reviewed-by: Laine Stump --- src/conf/domain_conf.c | 67 ++++++++++++++++-------------------------- 1 file changed, 25 insertions(+), 42 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index b3ed3a9c5a..9631e40815 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -15645,6 +15645,12 @@ virDomainNetFindIdx(virDomainDef *def, virDomainNe= tDef *net) VIR_DOMAIN_DEVIC= E_ADDRESS_TYPE_PCI); bool CCWAddrSpecified =3D virDomainDeviceAddressIsValid(&net->info, VIR_DOMAIN_DEVIC= E_ADDRESS_TYPE_CCW); + g_autofree char *addr =3D NULL; + const char *macAddr =3D _("()"); + const char *alias =3D _("()"); + + if (MACAddrSpecified) + macAddr =3D virMacAddrFormat(&net->mac, mac); =20 for (i =3D 0; i < def->nnets; i++) { if (MACAddrSpecified && @@ -15676,7 +15682,7 @@ virDomainNetFindIdx(virDomainDef *def, virDomainNet= Def *net) if (MACAddrSpecified) { virReportError(VIR_ERR_OPERATION_FAILED, _("multiple devices matching MAC address %s= found"), - virMacAddrFormat(&net->mac, mac)); + macAddr); } else { virReportError(VIR_ERR_OPERATION_FAILED, "%s", _("multiple matching devices found")); @@ -15688,47 +15694,24 @@ virDomainNetFindIdx(virDomainDef *def, virDomainN= etDef *net) matchidx =3D i; } =20 - if (matchidx < 0) { - if (MACAddrSpecified && PCIAddrSpecified) { - virReportError(VIR_ERR_DEVICE_MISSING, - _("no device matching MAC address %s found on " - VIR_PCI_DEVICE_ADDRESS_FMT), - virMacAddrFormat(&net->mac, mac), - net->info.addr.pci.domain, - net->info.addr.pci.bus, - net->info.addr.pci.slot, - net->info.addr.pci.function); - } else if (MACAddrSpecified && CCWAddrSpecified) { - virReportError(VIR_ERR_DEVICE_MISSING, - _("no device matching MAC address %s found on " - VIR_CCW_DEVICE_ADDRESS_FMT), - virMacAddrFormat(&net->mac, mac), - net->info.addr.ccw.cssid, - net->info.addr.ccw.ssid, - net->info.addr.ccw.devno); - } else if (PCIAddrSpecified) { - virReportError(VIR_ERR_DEVICE_MISSING, - _("no device found on " VIR_PCI_DEVICE_ADDRESS_= FMT), - net->info.addr.pci.domain, - net->info.addr.pci.bus, - net->info.addr.pci.slot, - net->info.addr.pci.function); - } else if (CCWAddrSpecified) { - virReportError(VIR_ERR_DEVICE_MISSING, - _("no device found on " VIR_CCW_DEVICE_ADDRESS_= FMT), - net->info.addr.ccw.cssid, - net->info.addr.ccw.ssid, - net->info.addr.ccw.devno); - } else if (MACAddrSpecified) { - virReportError(VIR_ERR_DEVICE_MISSING, - _("no device matching MAC address %s found"), - virMacAddrFormat(&net->mac, mac)); - } else { - virReportError(VIR_ERR_DEVICE_MISSING, "%s", - _("no matching device found")); - } - } - return matchidx; + if (matchidx >=3D 0) + return matchidx; + + if (net->info.alias) + alias =3D net->info.alias; + + if (CCWAddrSpecified) + addr =3D virDomainCCWAddressAsString(&net->info.addr.ccw); + else if (PCIAddrSpecified) + addr =3D virPCIDeviceAddressAsString(&net->info.addr.pci); + else + addr =3D g_strdup(_("()")); + + virReportError(VIR_ERR_DEVICE_MISSING, + _("no device found at address '%s' matching MAC address" + " '%s' and alias '%s'"), + addr, macAddr, alias); + return -1; } =20 bool --=20 2.31.1