From nobody Mon Feb 9 00:20:02 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.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 63.128.21.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=1608082062; cv=none; d=zohomail.com; s=zohoarc; b=FcnClE4X+6Xe3cKZHPUyk6sxqjxoZW0QMS8lz9VJFkmcNnAm1tA1YoD0Z+P5LFZlgFui9CDuZdyQs76E7o5R0/+YQY4AD+zScY/fdlPxB5JD4KjnEG2u98mlyR7Zg/m2bxbEWXCTnAjql1vh1VXT0XecVoZiYNFojBRoXXIOSxY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608082062; h=Content-Type:Content-Transfer-Encoding:Cc: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; bh=Esim+vkl8/NRT3pGOp0N8P+fOIospkrEn5WpPEOeVVs=; b=Cv7X+QUnb3LD+bIF1AqrV9u3bzwSxubuiPUiJTrVxBFOhUyKY5s0hBsYRsr+8BuSI67wTghO+aKgoK95WlxEbEzbnXk1BcRdOcnZHh2mo3pB3edgDkAxOnVbnZANNn5nmvIFBuUFIZ4XpPfmHo/v1UbRB22cSQUuu2i2Yib8iLw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.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 [63.128.21.124]) by mx.zohomail.com with SMTPS id 1608082062670744.6992387795364; Tue, 15 Dec 2020 17:27:42 -0800 (PST) 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-234-s12Mx6ZCOl-3LajPVgjpFw-1; Tue, 15 Dec 2020 20:27:39 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0E6BC8030A0; Wed, 16 Dec 2020 01:27:34 +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 DCE9D19D9F; Wed, 16 Dec 2020 01:27:33 +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 7D52C180954D; Wed, 16 Dec 2020 01:27:33 +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 0BG1RU1K026614 for ; Tue, 15 Dec 2020 20:27:30 -0500 Received: by smtp.corp.redhat.com (Postfix) id 658CC5D9E3; Wed, 16 Dec 2020 01:27:30 +0000 (UTC) Received: from vhost2.laine.org (ovpn-112-38.phx2.redhat.com [10.3.112.38]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1E2DE5D9D7; Wed, 16 Dec 2020 01:27:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1608082061; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=Esim+vkl8/NRT3pGOp0N8P+fOIospkrEn5WpPEOeVVs=; b=g/jNwaERAZWURJl/uXfWzQa+RonB3oAA5sOSg+J6UzGI2Z81F2NHsoSgXLPYf69zgWhRrk kAXrG99pv8lMI3y4D2d+bnjA2feAB9wTOZfjbVNz7U4WIr2RoweOZEhmH2znmAf2YbepO3 u7nTgERD5DI3vQj2S5n9N3tPgDF0PDc= X-MC-Unique: s12Mx6ZCOl-3LajPVgjpFw-1 From: Laine Stump To: libvir-list@redhat.com Subject: [PATCH 4/5] util: simplify virNetDevMacVLanCreateWithVPortProfile() Date: Tue, 15 Dec 2020 20:27:22 -0500 Message-Id: <20201216012723.176100-5-laine@redhat.com> In-Reply-To: <20201216012723.176100-1-laine@redhat.com> References: <20201216012723.176100-1-laine@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Cc: Shi Lei 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.84 on 10.5.11.23 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" Since commit 282d135ddbb the parser for has cleared out any interface name from the input XML that used the macvtap/macvlan name as a prefix. Along with that, the switch to use the new virNetDevGenerateName() function for auto-generating macvtap/macvlan device names (commit 9b5d741a9), has realized two facts: 1) virNetDevGenerateName() can be called with a name already filled in, and in that case it is an effective NOP. 2) because virNetDevGenerate() will always find an unused name, there is no need to retry device creation in a loop - if it fails the first time, it would fail any subsequent time as well. that, combined with the aforementioned parser change allow us to simplify virNetDevMacVLanCreateWithVPortProfile() - we no longer need any extra code to determine if a template "AutoName" was requested, and don't need a separate code path for creating the device in the case that a specific name was given in the XML - all we need to do is log any requested name, and then call exactly the same code as we would if no name was given. Signed-off-by: Laine Stump --- src/util/virnetdevmacvlan.c | 64 ++++++------------------------------- 1 file changed, 10 insertions(+), 54 deletions(-) diff --git a/src/util/virnetdevmacvlan.c b/src/util/virnetdevmacvlan.c index a4ad698335..2deefe6589 100644 --- a/src/util/virnetdevmacvlan.c +++ b/src/util/virnetdevmacvlan.c @@ -673,6 +673,7 @@ virNetDevMacVLanCreateWithVPortProfile(const char *ifna= meRequested, uint32_t macvtapMode; int vf =3D -1; bool vnet_hdr =3D flags & VIR_NETDEV_MACVLAN_VNET_HDR; + virNetDevGenNameType type; =20 macvtapMode =3D modeMap[mode]; =20 @@ -706,66 +707,21 @@ virNetDevMacVLanCreateWithVPortProfile(const char *if= nameRequested, } =20 if (ifnameRequested) { - int rc; - bool isAutoName - =3D (STRPREFIX(ifnameRequested, VIR_NET_GENERATED_MACVTAP_PREF= IX) || - STRPREFIX(ifnameRequested, VIR_NET_GENERATED_MACVLAN_PREFIX= )); - VIR_INFO("Requested macvtap device name: %s", ifnameRequested); - - if ((rc =3D virNetDevExists(ifnameRequested)) < 0) - return -1; - - if (rc) { - /* ifnameRequested is already being used */ - - if (!isAutoName) { - virReportSystemError(EEXIST, - _("Unable to create device '%s'"), - ifnameRequested); - return -1; - } - } else { - - /* ifnameRequested is available. try to open it */ - - virNetDevReserveName(ifnameRequested); - - if (virNetDevMacVLanCreate(ifnameRequested, macaddress, - linkdev, macvtapMode, flags) =3D=3D= 0) { - - /* virNetDevMacVLanCreate() was successful - use this name= */ - ifname =3D g_strdup(ifnameRequested); - - } else if (!isAutoName) { - /* couldn't open ifnameRequested, but it wasn't an - * autogenerated named, so there is nothing else to - * try - fail and return. - */ - return -1; - } - } + ifname =3D g_strdup(ifnameRequested); } =20 - if (!ifname) { - /* ifnameRequested was NULL, or it was an already in use - * autogenerated name, so now we look for an unused - * autogenerated name. - */ - virNetDevGenNameType type; - if (flags & VIR_NETDEV_MACVLAN_CREATE_WITH_TAP) - type =3D VIR_NET_DEV_GEN_NAME_MACVTAP; - else - type =3D VIR_NET_DEV_GEN_NAME_MACVLAN; + if (flags & VIR_NETDEV_MACVLAN_CREATE_WITH_TAP) + type =3D VIR_NET_DEV_GEN_NAME_MACVTAP; + else + type =3D VIR_NET_DEV_GEN_NAME_MACVLAN; =20 - if (virNetDevGenerateName(&ifname, type) < 0 || - virNetDevMacVLanCreate(ifname, macaddress, - linkdev, macvtapMode, flags) < 0) - return -1; + if (virNetDevGenerateName(&ifname, type) < 0 || + virNetDevMacVLanCreate(ifname, macaddress, + linkdev, macvtapMode, flags) < 0) { + return -1; } =20 - /* all done creating the device */ - if (virNetDevVPortProfileAssociate(ifname, virtPortProfile, macaddress, --=20 2.28.0