From nobody Tue Feb 10 16:18:50 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.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 216.205.24.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=1621624296; cv=none; d=zohomail.com; s=zohoarc; b=guJ034N/V5leSGJ5yIUlE0/rLnquGRssT5TjTh3ACIvpJ0rKuTGkogVTzR7kOr0qkfJCTHeTi4k80YyIKHBq9ERWiUvhhjahhxmPAIwaWPhUggRLLLZWtnCS1OMqaYanfgf9oTRwcDaqmIWljhiJhmCKu2al/iDavhV5omWgzGQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1621624296; 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=svXtBURd0B4N+G98VA7KjvK538QvJpW1sRb6zKtm01Q=; b=Nolau5z1ysnCRdtgO0e4qsE99TTI1ffri9fZGeVPSuKcxODo1R6ZW0ONS+kZ0sKGL57V3xKPXqxkWl+nL9Idfp54++YcCgnpi6S4mP50b1Koyq+wNaD5zC6XtkzncJcGMh2eGz+rWYFVptFqFb1PpLpGF26Nzvnnpr9AtCgyeZg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.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 [216.205.24.124]) by mx.zohomail.com with SMTPS id 1621624296940971.8874482153527; Fri, 21 May 2021 12:11:36 -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-451-5BlrcqcLPe6LMRG6Co7Mrg-1; Fri, 21 May 2021 15:11:33 -0400 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id C5A731074642; Fri, 21 May 2021 19:11:26 +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 A40386C32C; Fri, 21 May 2021 19:11:26 +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 C221B44A66; Fri, 21 May 2021 19:11:25 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 14LJBNf2005496 for ; Fri, 21 May 2021 15:11:23 -0400 Received: by smtp.corp.redhat.com (Postfix) id 0C04046; Fri, 21 May 2021 19:11:23 +0000 (UTC) Received: from vhost2.router.laine.org (ovpn-113-185.phx2.redhat.com [10.3.113.185]) by smtp.corp.redhat.com (Postfix) with ESMTP id C3A6619C45 for ; Fri, 21 May 2021 19:11:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1621624295; 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=svXtBURd0B4N+G98VA7KjvK538QvJpW1sRb6zKtm01Q=; b=Vhk7sUFOpJrGYckF4HR2DNGW0AvZKTfMNfhpPUaeU7jWcZEbxd4Hx3kXauxtqZM87MnnaZ zGRznlXVHPgT6qHL5Z5eTeT1dOqsqOnI8Jm7wywyGSUxGghAYn65b90OxKxYduQWBhmaJs jIHSQnHEgX8zd+WdJIicnTtBrTYP/QM= X-MC-Unique: 5BlrcqcLPe6LMRG6Co7Mrg-1 From: Laine Stump To: libvir-list@redhat.com Subject: [libvirt PATCH 2/4] conf: new function virDomainNetRemoveByObj() Date: Fri, 21 May 2021 15:11:18 -0400 Message-Id: <20210521191120.936899-3-laine@redhat.com> In-Reply-To: <20210521191120.936899-1-laine@redhat.com> References: <20210521191120.936899-1-laine@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 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.11 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" virDomainNetRemove() requires the index of the net device you want to remove from the list, but in some cases you may not have the index handy, only the object itself (or the object may not have been added to the domain's list). virDomainNetRemoveByObj() first tries to find the given object in the nets list, and deletes that if it is found. As with virDomainNetRemove() it always unconditionally tries to remove the device from the hostdevs list (in case it is the ridiculous combined net+hostdev device created for ). Signed-off-by: Laine Stump --- src/conf/domain_conf.c | 16 ++++++++++++++++ src/conf/domain_conf.h | 1 + src/libvirt_private.syms | 1 + 3 files changed, 18 insertions(+) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 0c52efa816..22e4ab5661 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -15742,6 +15742,22 @@ virDomainNetRemove(virDomainDef *def, size_t i) } =20 =20 +virDomainNetDef * +virDomainNetRemoveByObj(virDomainDef *def, virDomainNetDef *net) +{ + size_t i; + + /* the device might have been added to hostdevs but not nets */ + virDomainNetRemoveHostdev(def, net); + + for (i =3D 0; i < def->nnets; i++) { + if (def->nets[i] =3D=3D net) + VIR_DELETE_ELEMENT(def->nets, i, def->nnets); + } + return net; +} + + int virDomainNetUpdate(virDomainDef *def, size_t netidx, diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 8d64d4a1e2..8b4ed6d7d2 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -3581,6 +3581,7 @@ int virDomainNetUpdate(virDomainDef *def, size_t neti= dx, virDomainNetDef *newnet int virDomainNetDHCPInterfaces(virDomainDef *def, virDomainInterfacePtr **= ifaces); int virDomainNetARPInterfaces(virDomainDef *def, virDomainInterfacePtr **i= faces); virDomainNetDef *virDomainNetRemove(virDomainDef *def, size_t i); +virDomainNetDef *virDomainNetRemoveByObj(virDomainDef *def, virDomainNetDe= f *net); void virDomainNetRemoveHostdev(virDomainDef *def, virDomainNetDef *net); =20 int virDomainHostdevInsert(virDomainDef *def, virDomainHostdevDef *hostdev= ); diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 7c7627052b..c327098f68 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -544,6 +544,7 @@ virDomainNetModelTypeToString; virDomainNetNotifyActualDevice; virDomainNetReleaseActualDevice; virDomainNetRemove; +virDomainNetRemoveByObj; virDomainNetRemoveHostdev; virDomainNetResolveActualType; virDomainNetSetModelString; --=20 2.31.1