From nobody Tue Feb 10 12:57:26 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=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 --- 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