From nobody Fri May 17 03:00:40 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=1621624303; cv=none; d=zohomail.com; s=zohoarc; b=l7IAMQO4jIzjtEmXSjVIlB3EbOt1H0vqsTjtrwLMqgeutFeUxaKv0qSrJvauSRcR5Pgy5gy33O3lLchLgjt0Ujvz+UZzMgP53x6AumpHEA2GpJzVdRl+eum9vR871i0tkaR3w2UrwOU5acJdwOWWxVhXh1uTRqFj2rJIfMSR+lw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1621624303; 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=L+zSOjHjjvRwam3IeZ+HiX6n8iV85KSvbi0ceTU3MtI=; b=LJXfLXIuDuOeKkWeg7MsrQbtDhkLUdzA/oSjfBL57E5nTPiVspl9Twb/fmVj7ZMcU8FmjTRYQT5o/kRJU0z0TRp9lwGdeRYGR2Y8j5Zs/GDiQIx87+0mnv5aWyx/of+RMHzSAzIgzQb79Sjn3GyJ8Pp+7F+2WldetN2zmkXaLJ8= 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 1621624303102644.0120751944843; Fri, 21 May 2021 12:11:43 -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-430-sIARpLv2MSS78zrdJMco7A-1; Fri, 21 May 2021 15:11:39 -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 E69AE801107; Fri, 21 May 2021 19:11:34 +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 C9E235D6DC; Fri, 21 May 2021 19:11:34 +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 93E8844A6C; Fri, 21 May 2021 19:11:34 +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 14LJBMRo005491 for ; Fri, 21 May 2021 15:11:22 -0400 Received: by smtp.corp.redhat.com (Postfix) id 9CC0946; Fri, 21 May 2021 19:11:22 +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 5F1CD19C45 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=1621624302; 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=L+zSOjHjjvRwam3IeZ+HiX6n8iV85KSvbi0ceTU3MtI=; b=CNKriUczaRK7wpS22yg/4HL809IyYEyJFALXgKs0otONq8wvQDRNKK2FijJv3nH5Nbk6XZ HW9ogynG81Ayv789T/R6uTiRGMc0YX3sgQ91E86WMgNkmgq+inwzKpHtnAdB1wuPYZaByO 3ASEjLgyMRL3sEukVOwJXcJBSFx8qls= X-MC-Unique: sIARpLv2MSS78zrdJMco7A-1 From: Laine Stump To: libvir-list@redhat.com Subject: [libvirt PATCH 1/4] qemu_hotplug.c: don't skip cleanup on failures of qemuDomainAttachNetDevice Date: Fri, 21 May 2021 15:11:17 -0400 Message-Id: <20210521191120.936899-2-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.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" We have many places where the earliest error returns from a function skip any cleanup label at the bottom (the assumption being that it is so early in the function that there isn't yet anything that needs to be explicitly undone on failure). But in general it is a bad sign if there are any direct "return" statements in a function at any time after there has been a "goto cleanup" - that indicates someone thought that an earlier point in the code had done something needing cleanup, so we shouldn't be skipping it. There were two occurences of a "return -1" after "goto cleanup" in qemuDomainAttachDeviceNet(). The first of these has been around for a very long time (since 2013) and my assumption is that the earlier "goto cleanup" didn't exist at that time (so it was proper), and when the code further up in the function was added, the this return -1 was missed. The second was added during a mass change to check the return from qemuInterfacePrepareSlirp() in several places (commit 99a1cfc43889c6d); in this case it was erroneous from the start. Change both of these "return -1"s to "goto cleanup". Since we already have code paths earlier in the function that goto cleanup, this should not cause any new problem. Signed-off-by: Laine Stump Reviewed-by: Michal Privoznik --- src/qemu/qemu_hotplug.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index c6f275e11d..244cf65c87 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -1212,7 +1212,7 @@ qemuDomainAttachNetDevice(virQEMUDriver *driver, =20 /* final validation now that we have full info on the type */ if (qemuDomainValidateActualNetDef(net, priv->qemuCaps) < 0) - return -1; + goto cleanup; =20 actualType =3D virDomainNetGetActualType(net); =20 @@ -1330,7 +1330,7 @@ qemuDomainAttachNetDevice(virQEMUDriver *driver, int rv =3D qemuInterfacePrepareSlirp(driver, net, &slirp); =20 if (rv =3D=3D -1) - return -1; + goto cleanup; if (rv =3D=3D 0) break; =20 --=20 2.31.1 From nobody Fri May 17 03:00:40 2024 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 Reviewed-by: Michal Privoznik --- 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 From nobody Fri May 17 03:00:40 2024 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=1621624304; cv=none; d=zohomail.com; s=zohoarc; b=b1BW4QZk5yNWR3Zg3i31wweEUZUEE/M2WIQSxAo2iGp3mfoT+fjWr8INQSlQWb7TpbiLvOi5I4CaMjfQOIPRklKhd6QCdzRtrDIsmh+hshr7Du/VgpdOpZmWIUvTPmglihjVya4Tlev1GSDpE45gPyY33/2Ib6URXCT1cnm9Zic= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1621624304; 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=z5RZzh9dVRAS4179E75VwG5YhGMgNanWYHIBD1KjcZw=; b=RyFfn66mnxJLMvDsC8CoZDXpSz+vTKXvtXk46ZCxC0p2yiScakg2n//wcDqt7Ywssmtde3s5/q/3nB6akmQ8Fw9BG7ncVo0K6o11Tmjb6a9aGGfNDHFXDMOiExrffFoE96hDmXLixAo1X7/93H7C7itc09iF9q5NwdHhjhVxSRQ= 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 1621624304158243.7985653084237; Fri, 21 May 2021 12:11:44 -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-117-MMEQx9WvPkmlFtZ0Me_i9Q-1; Fri, 21 May 2021 15:11:41 -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 1A68F1074640; Fri, 21 May 2021 19:11:35 +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 C705D60BD8; Fri, 21 May 2021 19:11:34 +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 8D108180B463; Fri, 21 May 2021 19:11:34 +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 14LJBNQ4005504 for ; Fri, 21 May 2021 15:11:23 -0400 Received: by smtp.corp.redhat.com (Postfix) id 6FEF019C45; 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 338AC2BCD0 for ; Fri, 21 May 2021 19:11:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1621624303; 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=z5RZzh9dVRAS4179E75VwG5YhGMgNanWYHIBD1KjcZw=; b=RwnywfytANynzkBqCxARSNm32KLq+PP7YtxV5G5kWtYbykRItKmb/CvqSC4CxKIKdpcMsA 9qSJ/cO8hqbMYxlm4vnLWR4NdSg3dZfVBQ1+T7UwrgHESkXyaiPm9iNfGymdQ6Is5DHqIC gI7Rt8lZOiOSb2VV69M9k7b4ojcxnRA= X-MC-Unique: MMEQx9WvPkmlFtZ0Me_i9Q-1 From: Laine Stump To: libvir-list@redhat.com Subject: [libvirt PATCH 3/4] qemu_hotplug.c: add net devices to the domain list earlier Date: Fri, 21 May 2021 15:11:19 -0400 Message-Id: <20210521191120.936899-4-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" An upcoming patch will be checking if the addition of a new net device requires adjusting the domain locked memory limit, which must be done prior to sending the command to qemu to add the new device. But qemuDomainAdjustMaxMemLock() checks all (and only) the devices that are currently in the domain definition, and currently we are adding new net devices to the domain definition only at the very end of the hotplug operation, after qemu has already executed the device_add command. In order for the upcoming patch to work, this patch changes qemuDomainAttachNetDevice() to add the device to the domain nets list at an earlier time. It can't be added until after PCI address and alias name have been determined (because both of those examine existing devices in the domain to figure out a unique value for the new device), but must be done before making the qemu monitor call. Since the device has been added to the list earlier, we need to potentially remove it on failure. This is done by replacing the existing call to virDomainNetRemoveHostdev() (which checks if this is a hostdev net device, and if so removes it from the hostdevs list, since it could have already been added to that list) with a call to the new virDomainNetRemoveByObj(), which looks for the device on both nets and hostdevs lists, and removes it where it finds it. Signed-off-by: Laine Stump Reviewed-by: Michal Privoznik --- src/qemu/qemu_hotplug.c | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 244cf65c87..dff31666f7 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -1196,9 +1196,6 @@ qemuDomainAttachNetDevice(virQEMUDriver *driver, g_autoptr(virConnect) conn =3D NULL; virErrorPtr save_err =3D NULL; =20 - /* preallocate new slot for device */ - VIR_REALLOC_N(vm->def->nets, vm->def->nnets + 1); - /* If appropriate, grab a physical device from the configured * network's pool of devices, or resolve bridge device name * to the one defined in the network definition. @@ -1249,6 +1246,18 @@ qemuDomainAttachNetDevice(virQEMUDriver *driver, =20 releaseaddr =3D true; =20 + /* We've completed all examinations of the full domain definition + * that require the new device to *not* be present (e.g. PCI + * address allocation and alias name assignment) so it is now safe + * to add the new device to the domain's nets list (in order for + * it to be in place for checks that *do* need it present in the + * domain definition, e.g. checking if we need to adjust the + * locked memory limit). This means we will need to remove it if + * there is a failure. + */ + if (VIR_APPEND_ELEMENT_COPY(vm->def->nets, vm->def->nnets, net) < 0) + goto cleanup; + switch (actualType) { case VIR_DOMAIN_NET_TYPE_BRIDGE: case VIR_DOMAIN_NET_TYPE_NETWORK: @@ -1505,9 +1514,7 @@ qemuDomainAttachNetDevice(virQEMUDriver *driver, ret =3D 0; =20 cleanup: - if (!ret) { - vm->def->nets[vm->def->nnets++] =3D net; - } else { + if (ret < 0) { virErrorPreserveLast(&save_err); if (releaseaddr) qemuDomainReleaseDeviceAddress(vm, &net->info); @@ -1529,7 +1536,11 @@ qemuDomainAttachNetDevice(virQEMUDriver *driver, qemuDomainNetDeviceVportRemove(net); } =20 - virDomainNetRemoveHostdev(vm->def, net); + /* we had potentially pre-added the device to the domain + * device lists, if so we need to remove it (from def->nets + * and/or def->hostdevs) on failure + */ + virDomainNetRemoveByObj(vm->def, net); =20 if (net->type =3D=3D VIR_DOMAIN_NET_TYPE_NETWORK) { if (conn) --=20 2.31.1 From nobody Fri May 17 03:00:40 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=1621624305; cv=none; d=zohomail.com; s=zohoarc; b=ioiLYkzirOEka6rNkwkLjLii7aEF0x7TiNS6QMSDEUUe+X/a8wXNCXjzW/KbLD5kFQck+3QDR2F0WklfiUXFImHDEFSII7FixvZoa6Ha5zJr4tXN0odFVEiVOuv/A9nqD3fWaEgY2YttIUCIojrbSFmUEIkGIohYywRJ1gaNgaI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1621624305; 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=wCYCi8PCLkREB08sKsMcSwZior2kxDFX6TX042781js=; b=kvXTXD5f+eGo92hNfDhkDqm7mWFB0YfwZtK65a0CNc0ka27fgNa+99H8ATbbtObX9Smk9qG5LNBCopwFg5jS6648a7qES/QjxHxfx1Xn6EdxpPCagi6pecxLZz7OwB6D1B+IJQq/hHZKfsD0+QmOTJbZSKJpS5XmMh7Wn7ZbrXs= 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 1621624305834949.3191753277689; Fri, 21 May 2021 12:11:45 -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-460-qUhQYDz_Mm6hbSyLHdY2vg-1; Fri, 21 May 2021 15:11:42 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0C965107464E; Fri, 21 May 2021 19:11:38 +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 C12CB60C17; Fri, 21 May 2021 19:11:37 +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 88DF544A6E; Fri, 21 May 2021 19:11:37 +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 14LJBN3d005509 for ; Fri, 21 May 2021 15:11:23 -0400 Received: by smtp.corp.redhat.com (Postfix) id D3CFF46; 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 9706619C45 for ; Fri, 21 May 2021 19:11:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1621624304; 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=wCYCi8PCLkREB08sKsMcSwZior2kxDFX6TX042781js=; b=GlvhKS62iAj5tiVKQOfRLyyITixgvtPw5U22508LNc2oG2aUpJOZYZJBupehC1eXthM+HX KHbUAh5jf85saPNTJexAKk6zNLHMT3AkKvpmCqXimg7+C+j5YKP/Tls965APUa+bjfzb0/ xdHoCKOn7o5okgIIoHRelsEmb6UE2K4= X-MC-Unique: qUhQYDz_Mm6hbSyLHdY2vg-1 From: Laine Stump To: libvir-list@redhat.com Subject: [libvirt PATCH 4/4] qemu: adjust the maxmemlock limit when hotplugging a vDPA device Date: Fri, 21 May 2021 15:11:20 -0400 Message-Id: <20210521191120.936899-5-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.12 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" and re-adjust if the hotplug fails. This fixes a bug found during testing of https://bugzilla.redhat.com/1939776, which was supposed to be resolved by commit 98e22ff749, but failed to account for the case of device hotplug. Signed-off-by: Laine Stump Reviewed-by: Michal Privoznik --- src/qemu/qemu_hotplug.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index dff31666f7..794c80444f 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -1184,6 +1184,7 @@ qemuDomainAttachNetDevice(virQEMUDriver *driver, int ret =3D -1; bool releaseaddr =3D false; bool iface_connected =3D false; + bool adjustmemlock =3D false; virDomainNetType actualType; const virNetDevBandwidth *actualBandwidth; g_autoptr(virQEMUDriverConfig) cfg =3D virQEMUDriverGetConfig(driver); @@ -1362,6 +1363,10 @@ qemuDomainAttachNetDevice(virQEMUDriver *driver, break; =20 case VIR_DOMAIN_NET_TYPE_VDPA: + if (qemuDomainAdjustMaxMemLock(vm, false) < 0) + goto cleanup; + adjustmemlock =3D true; + if ((vdpafd =3D qemuInterfaceVDPAConnect(net)) < 0) goto cleanup; break; @@ -1542,6 +1547,13 @@ qemuDomainAttachNetDevice(virQEMUDriver *driver, */ virDomainNetRemoveByObj(vm->def, net); =20 + /* if we adjusted the memlock limit (for a vDPA device) then + * we need to re-adjust since we won't be using the device + * after all + */ + if (adjustmemlock) + qemuDomainAdjustMaxMemLock(vm, false); + if (net->type =3D=3D VIR_DOMAIN_NET_TYPE_NETWORK) { if (conn) virDomainNetReleaseActualDevice(conn, vm->def, net); --=20 2.31.1