From nobody Sat Feb 7 08:54:59 2026 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=1675259399; cv=none; d=zohomail.com; s=zohoarc; b=HyIUADUjTcXAsusj5wZifvjD2t5Yhpr+TOJvNC6lBahxQoXG/cj3JRotjYaenKisztSGxtY4P8xeKRrb5CtSLYqWVQb+WO/Z4IsoyeoVIqxOC7jVOxpoi4si4AAciB47HV0ocSmpQJPwNvwx6twNmz2s1Z3+5dXOXk4co4AcSCw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675259399; 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; bh=jl4yXLhZrPHRPE0mgrVOZGm9vTxc2GeMjyi9FYlAqFU=; b=SY97mLrt62XOqZxqV4GgcSDvST7MeFzT8saqAKVuVetfYb0MaJ/e7z3Ekfn8GNrKl+XC96eiKZKT1Hye0PZbt2/n9oecyc9BKCAESaAa0iTLxET3+XlM0MG0nW/wZhk25CQ2yfbDl+Jx9s+9v62Dadsx0paf1QF7pxryy5KjI8I= 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) 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 1675259399370199.41384023102148; Wed, 1 Feb 2023 05:49:59 -0800 (PST) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-226-pC3BdIMTOJaGss6KgWqs4g-1; Wed, 01 Feb 2023 08:49:54 -0500 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 7AC5488B7AC; Wed, 1 Feb 2023 13:49:48 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6858B492B05; Wed, 1 Feb 2023 13:49:48 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id C71F31947343; Wed, 1 Feb 2023 13:49:46 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 89992194658F for ; Wed, 1 Feb 2023 13:49:44 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 9079443FB8; Wed, 1 Feb 2023 13:49:38 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.39]) by smtp.corp.redhat.com (Postfix) with ESMTP id 36B3353A0 for ; Wed, 1 Feb 2023 13:49:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675259396; 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: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=jl4yXLhZrPHRPE0mgrVOZGm9vTxc2GeMjyi9FYlAqFU=; b=Tr9NZ3a+5Pc0Ck420fBG+0CpI1Ahe04k9iiVyn3lwobe/iNPFnssCoPUs56aBQynXIz/jH LWcdylbdFw3o20IstpY+44n5YQc+Y+QzTJ4iNopdbtWqksZ2NVh/XkcUt5PTuKelsNGZqd MGmClWXCXsEjQ9QvrVFl0CGonfewF4s= X-MC-Unique: pC3BdIMTOJaGss6KgWqs4g-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 5/5] qemu: Don't remove macvtaps on failed start Date: Wed, 1 Feb 2023 14:49:34 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1675259400345100002 Content-Type: text/plain; charset="utf-8"; x-default="true" If a domain is configured to create a macvtap/macvlan but the target link already exists, startup fails (as expected) with: error: error creating macvtap interface test@eth0 (52:54:00:d9:0b:db): Fi= le exists Okay, we could make that error message better, but that's not the point. Since this error originated while generating cmd line (the caller is qemuProcessStart(), transitively), the cleanup after failed start is performed (qemuProcessStop()). Here, virNetDevMacVLanDeleteWithVPortProfile() is called which removes the macvtap interface we did not create (as it made us fail in the first place). Therefore, we need to track which macvtap/macvlan interface was created successfully and remove only those. You'll notice that only qemuProcessStop() has the new check. For the (failed) hotplug case (qemuDomainAttachNetDevice()) this function is already in place (the @iface_connected variable), or not needed (qemuDomainRemoveNetDevice() - we're removing an interface that was already attached to QEMU). Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=3D2166235 Signed-off-by: Michal Privoznik --- src/qemu/qemu_domain.c | 27 +++++++++++++++++++++++++++ src/qemu/qemu_domain.h | 5 +++++ src/qemu/qemu_interface.c | 3 +++ src/qemu/qemu_process.c | 12 +++++++----- 4 files changed, 42 insertions(+), 5 deletions(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 1757a6aaad..e9bc0f375d 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -1235,6 +1235,31 @@ qemuDomainTPMPrivateFormat(const virDomainTPMDef *tp= m, } =20 =20 +static int +qemuDomainNetworkPrivateParse(xmlXPathContextPtr ctxt, + virDomainNetDef *net) +{ + qemuDomainNetworkPrivate *priv =3D QEMU_DOMAIN_NETWORK_PRIVATE(net); + + priv->created =3D virXPathBoolean("string(./created[@value=3D'yes'])",= ctxt); + + return 0; +} + + +static int +qemuDomainNetworkPrivateFormat(const virDomainNetDef *net, + virBuffer *buf) +{ + qemuDomainNetworkPrivate *priv =3D QEMU_DOMAIN_NETWORK_PRIVATE(net); + + if (priv->created) + virBufferAddLit(buf, "\n"); + + return 0; +} + + /* qemuDomainSecretInfoSetup: * @priv: pointer to domain private object * @alias: alias of the secret @@ -3328,6 +3353,8 @@ virDomainXMLPrivateDataCallbacks virQEMUDriverPrivate= DataCallbacks =3D { .vsockNew =3D qemuDomainVsockPrivateNew, .graphicsNew =3D qemuDomainGraphicsPrivateNew, .networkNew =3D qemuDomainNetworkPrivateNew, + .networkParse =3D qemuDomainNetworkPrivateParse, + .networkFormat =3D qemuDomainNetworkPrivateFormat, .videoNew =3D qemuDomainVideoPrivateNew, .tpmNew =3D qemuDomainTPMPrivateNew, .tpmParse =3D qemuDomainTPMPrivateParse, diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h index eca5404cdc..1053d1d4cb 100644 --- a/src/qemu/qemu_domain.h +++ b/src/qemu/qemu_domain.h @@ -412,6 +412,11 @@ typedef struct _qemuDomainNetworkPrivate qemuDomainNet= workPrivate; struct _qemuDomainNetworkPrivate { virObject parent; =20 + /* True if the device was created by us. Otherwise we should + * avoid removing it. Currently only used for + * VIR_DOMAIN_NET_TYPE_DIRECT. */ + bool created; + qemuSlirp *slirp; =20 /* file descriptor transfer helpers */ diff --git a/src/qemu/qemu_interface.c b/src/qemu/qemu_interface.c index ed2c209167..076640cbde 100644 --- a/src/qemu/qemu_interface.c +++ b/src/qemu/qemu_interface.c @@ -268,6 +268,7 @@ qemuInterfaceDirectConnect(virDomainDef *def, char *res_ifname =3D NULL; g_autoptr(virQEMUDriverConfig) cfg =3D virQEMUDriverGetConfig(driver); unsigned int macvlan_create_flags =3D VIR_NETDEV_MACVLAN_CREATE_WITH_T= AP; + qemuDomainNetworkPrivate *netpriv =3D QEMU_DOMAIN_NETWORK_PRIVATE(net); =20 if (qemuInterfaceIsVnetCompatModel(net)) macvlan_create_flags |=3D VIR_NETDEV_MACVLAN_VNET_HDR; @@ -285,6 +286,8 @@ qemuInterfaceDirectConnect(virDomainDef *def, macvlan_create_flags) < 0) goto cleanup; =20 + netpriv->created =3D true; + virDomainAuditNetDevice(def, net, res_ifname, true); VIR_FREE(net->ifname); net->ifname =3D res_ifname; diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 9a31a11acc..ff219e0030 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -8443,11 +8443,13 @@ void qemuProcessStop(virQEMUDriver *driver, vport =3D virDomainNetGetActualVirtPortProfile(net); switch (virDomainNetGetActualType(net)) { case VIR_DOMAIN_NET_TYPE_DIRECT: - virNetDevMacVLanDeleteWithVPortProfile(net->ifname, &net->mac, - virDomainNetGetActualDi= rectDev(net), - virDomainNetGetActualDi= rectMode(net), - virDomainNetGetActualVi= rtPortProfile(net), - cfg->stateDir); + if (QEMU_DOMAIN_NETWORK_PRIVATE(net)->created) { + virNetDevMacVLanDeleteWithVPortProfile(net->ifname, &net->= mac, + virDomainNetGetActu= alDirectDev(net), + virDomainNetGetActu= alDirectMode(net), + virDomainNetGetActu= alVirtPortProfile(net), + cfg->stateDir); + } break; case VIR_DOMAIN_NET_TYPE_ETHERNET: if (net->managed_tap !=3D VIR_TRISTATE_BOOL_NO && net->ifname)= { --=20 2.39.1