From nobody Thu Mar 28 20:57:44 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1553207372741152.89014942771837; Thu, 21 Mar 2019 15:29:32 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 286AA8553A; Thu, 21 Mar 2019 22:29:31 +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 0040A60865; Thu, 21 Mar 2019 22:29:30 +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 AB5FD180338D; Thu, 21 Mar 2019 22:29:30 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x2LMT97X015620 for ; Thu, 21 Mar 2019 18:29:09 -0400 Received: by smtp.corp.redhat.com (Postfix) id 677551001DF9; Thu, 21 Mar 2019 22:29:09 +0000 (UTC) Received: from vhost2.laine.org (ovpn-116-180.phx2.redhat.com [10.3.116.180]) by smtp.corp.redhat.com (Postfix) with ESMTP id 57E6A1001DC9; Thu, 21 Mar 2019 22:29:08 +0000 (UTC) From: Laine Stump To: libvir-list@redhat.com Date: Thu, 21 Mar 2019 18:28:41 -0400 Message-Id: <20190321222901.12902-2-laine@laine.org> In-Reply-To: <20190321222901.12902-1-laine@laine.org> References: <20190321222901.12902-1-laine@laine.org> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Cc: Peter Krempa , =?UTF-8?q?J=E1n=20Tomko?= , Michal Privoznik , Stefan Zimmermann , Cornelia Huck , Andrea Bolognani , Boris Fiuczynski , Yi Min Zhao , Bjoern Walk Subject: [libvirt] [PATCH 01/21] qemu_hotplug: remove erroneous call to qemuDomainDetachExtensionDevice() 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Thu, 21 Mar 2019 22:29:31 +0000 (UTC) Content-Type: text/plain; charset="utf-8" qemuDomainDetachControllerDevice() calls qemuDomainDetachExtensionDevice() when the *controller* type is PCI. This is incorrect in multiple ways: * Any code that tears down a device should be in the qemuDomainRemove*Device() function (which is called after libvirt gets a DEVICE_DELETED event from qemu indicating that the guest is finished with the device on its end. The qemuDomainDetach*Device() functions should only contain code that ensures the requested operation is valid, and sends the command to qemu to initiate the unplug. * qemuDomainDetachExtensionDevice() is a function that applies to devices that plug into a PCI slot, *not* necessarily PCI controllers (which is what's being checked in the offending code). The proper way to check for this would be to see if the DeviceInfo for the controller device had a PCI address, not to check if the controller is a PCI controller (the code being removed was doing the latter). * According to commit 1d1e264f1 that added this code (and other support for hotplugging zPCI devices on s390), it's not necessary to explicitly detach the zPCI device when unplugging a PCI device. To quote: There's no need to implement hot unplug for zPCI as QEMU implements an unplug callback which will unplug both PCI and zPCI device in a cascaded way. and the evidence bears this out - all the other uses of qemuDomainDetachExtensionDevice() (except one, which I believe is also in error, and is being removed in a separate patch) are only to remove the zPCI extension device in cases where it was successfully added, but there was some other failure later in the hotplug process (so there was no regular PCI device to remove and trigger removal of the zPCI extension device). * PCI controllers are not hot pluggable, so this is dead code anyway. (The only controllers that can currently be hotplugged/unplugged are SCSI controllers). Signed-off-by: Laine Stump Reviewed-by: Boris Fiuczynski Reviewed-by: J=C3=A1n Tomko --- src/qemu/qemu_hotplug.c | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 41d60277d1..18075dc48e 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -5457,7 +5457,6 @@ int qemuDomainDetachControllerDevice(virQEMUDriverPtr= driver, { int idx, ret =3D -1; virDomainControllerDefPtr detach =3D NULL; - qemuDomainObjPrivatePtr priv =3D vm->privateData; =20 if ((idx =3D virDomainControllerFind(vm->def, dev->data.controller->type, @@ -5503,17 +5502,6 @@ int qemuDomainDetachControllerDevice(virQEMUDriverPt= r driver, if (!async) qemuDomainMarkDeviceForRemoval(vm, &detach->info); =20 - if (detach->type =3D=3D VIR_DOMAIN_CONTROLLER_TYPE_PCI) { - int rc; - qemuDomainObjEnterMonitor(driver, vm); - rc =3D qemuDomainDetachExtensionDevice(priv->mon, &detach->info); - if (qemuDomainObjExitMonitor(driver, vm) < 0) - rc =3D -1; - - if (rc < 0) - goto cleanup; - } - if (qemuDomainDeleteDevice(vm, detach->info.alias) < 0) goto cleanup; =20 --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Mar 28 20:57:44 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1553207377691673.6651613062089; Thu, 21 Mar 2019 15:29:37 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 1331C308620D; Thu, 21 Mar 2019 22:29:36 +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 D00B65D75F; Thu, 21 Mar 2019 22:29:35 +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 3B3843FAF4; Thu, 21 Mar 2019 22:29:35 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x2LMTA4m015628 for ; Thu, 21 Mar 2019 18:29:10 -0400 Received: by smtp.corp.redhat.com (Postfix) id 9B2581001DE2; Thu, 21 Mar 2019 22:29:10 +0000 (UTC) Received: from vhost2.laine.org (ovpn-116-180.phx2.redhat.com [10.3.116.180]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8F21B1001DC9; Thu, 21 Mar 2019 22:29:09 +0000 (UTC) From: Laine Stump To: libvir-list@redhat.com Date: Thu, 21 Mar 2019 18:28:42 -0400 Message-Id: <20190321222901.12902-3-laine@laine.org> In-Reply-To: <20190321222901.12902-1-laine@laine.org> References: <20190321222901.12902-1-laine@laine.org> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Cc: Peter Krempa , =?UTF-8?q?J=E1n=20Tomko?= , Michal Privoznik , Stefan Zimmermann , Cornelia Huck , Andrea Bolognani , Boris Fiuczynski , Yi Min Zhao , Bjoern Walk Subject: [libvirt] [PATCH 02/21] qemu_hotplug: remove another erroneous qemuDomainDetachExtensionDevice() call 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Thu, 21 Mar 2019 22:29:36 +0000 (UTC) Content-Type: text/plain; charset="utf-8" qemuDomainRemoveRNGDevice() calls qemuDomainDetachExtensionDevice(). According to commit 1d1e264f1 that added this code, it should not be necessary to explicitly remove the zPCI extension device for a PCI device during unplug, because "QEMU implements an unplug callback which will unplug both PCI and zPCI device in a cascaded way". In fact, no other devices call qemuDomainDetachExtensionDevice() during their qemuDomainRemove*Device() function, so it should be removed from qemuDomainRemoveRNGDevice as well. Signed-off-by: Laine Stump Reviewed-by: Boris Fiuczynski Reviewed-by: J=C3=A1n Tomko --- src/qemu/qemu_hotplug.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 18075dc48e..65ec5187e6 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -4884,9 +4884,6 @@ qemuDomainRemoveRNGDevice(virQEMUDriverPtr driver, =20 qemuDomainObjEnterMonitor(driver, vm); =20 - if (qemuDomainDetachExtensionDevice(priv->mon, &rng->info) < 0) - rc =3D -1; - if (rc =3D=3D 0 && qemuMonitorDelObject(priv->mon, objAlias) < 0) rc =3D -1; --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Mar 28 20:57:44 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 155320738169195.64744139723746; Thu, 21 Mar 2019 15:29:41 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 1BF8C30832C2; Thu, 21 Mar 2019 22:29:39 +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 E23C660BEC; Thu, 21 Mar 2019 22:29:38 +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 A9718181A847; Thu, 21 Mar 2019 22:29:38 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x2LMTBqi015635 for ; Thu, 21 Mar 2019 18:29:11 -0400 Received: by smtp.corp.redhat.com (Postfix) id 376151001DD3; Thu, 21 Mar 2019 22:29:11 +0000 (UTC) Received: from vhost2.laine.org (ovpn-116-180.phx2.redhat.com [10.3.116.180]) by smtp.corp.redhat.com (Postfix) with ESMTP id C29331001DC9; Thu, 21 Mar 2019 22:29:10 +0000 (UTC) From: Laine Stump To: libvir-list@redhat.com Date: Thu, 21 Mar 2019 18:28:43 -0400 Message-Id: <20190321222901.12902-4-laine@laine.org> In-Reply-To: <20190321222901.12902-1-laine@laine.org> References: <20190321222901.12902-1-laine@laine.org> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Cc: Michal Privoznik , Peter Krempa Subject: [libvirt] [PATCH 03/21] qemu_hotplug: remove unnecessary check for valid PCI address 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Thu, 21 Mar 2019 22:29:39 +0000 (UTC) Content-Type: text/plain; charset="utf-8" When support for hotplug/unplug of SCSI controllers was added way back in December 2009 (commit da9d937b), unplug was handled by calling the now-extinct function qemuMonitorRemovePCIDevice(), which required a PCI address as an argument. At the same time, the idea of every device in the config having a PCI address apparentlty was not yet fully implemented, because the author of the patch including a check for a valid PCI address in the device object. These days, all PCI devices are guaranteed to have a valid PCI address. But more important than that, we no longer detach devices by PCI address, but instead use qemuDomainDeleteDevice(), which identifies the device by its alias. So checking for a valid PCI address is just pointless extra code that obscures the high level of similarity between all the individual qemuDomainDetach*Device() functions. Signed-off-by: Laine Stump Reviewed-by: J=C3=A1n Tomko --- src/qemu/qemu_hotplug.c | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 65ec5187e6..f2aa3cc048 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -5467,22 +5467,6 @@ int qemuDomainDetachControllerDevice(virQEMUDriverPt= r driver, =20 detach =3D vm->def->controllers[idx]; =20 - if (detach->info.type !=3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI && - detach->info.type !=3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE_CCW && - detach->info.type !=3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_S390)= { - virReportError(VIR_ERR_OPERATION_FAILED, - _("device with '%s' address cannot be detached"), - virDomainDeviceAddressTypeToString(detach->info.typ= e)); - goto cleanup; - } - - if (!virDomainDeviceAddressIsValid(&detach->info, detach->info.type)) { - virReportError(VIR_ERR_OPERATION_FAILED, - _("device with invalid '%s' address cannot be detac= hed"), - virDomainDeviceAddressTypeToString(detach->info.typ= e)); - goto cleanup; - } - if (qemuIsMultiFunctionDevice(vm->def, &detach->info)) { virReportError(VIR_ERR_OPERATION_FAILED, _("cannot hot unplug multifunction PCI device: %s"), --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Mar 28 20:57:44 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 15532073843921015.558699106185; Thu, 21 Mar 2019 15:29:44 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BC3163024560; Thu, 21 Mar 2019 22:29:42 +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 94F27608AB; Thu, 21 Mar 2019 22:29:42 +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 5AEDC181A84F; Thu, 21 Mar 2019 22:29:42 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x2LMTBxS015640 for ; Thu, 21 Mar 2019 18:29:11 -0400 Received: by smtp.corp.redhat.com (Postfix) id CBF021001DDB; Thu, 21 Mar 2019 22:29:11 +0000 (UTC) Received: from vhost2.laine.org (ovpn-116-180.phx2.redhat.com [10.3.116.180]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5FD791001DC9; Thu, 21 Mar 2019 22:29:11 +0000 (UTC) From: Laine Stump To: libvir-list@redhat.com Date: Thu, 21 Mar 2019 18:28:44 -0400 Message-Id: <20190321222901.12902-5-laine@laine.org> In-Reply-To: <20190321222901.12902-1-laine@laine.org> References: <20190321222901.12902-1-laine@laine.org> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Cc: Michal Privoznik , Peter Krempa Subject: [libvirt] [PATCH 04/21] qemu_hotplug: rename a virDomainDeviceInfoPtr to avoid confusion 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Thu, 21 Mar 2019 22:29:43 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Having an InfoPtr named "dev" made my brain hurt. Renaming it to "info" gives one less thing to confuse when looking at the code. Signed-off-by: Laine Stump --- src/qemu/qemu_hotplug.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index f2aa3cc048..701458b2cd 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -4380,12 +4380,12 @@ static int qemuComparePCIDevice(virDomainDefPtr def= ATTRIBUTE_UNUSED, } =20 static bool qemuIsMultiFunctionDevice(virDomainDefPtr def, - virDomainDeviceInfoPtr dev) + virDomainDeviceInfoPtr info) { - if (dev->type !=3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI) + if (info->type !=3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI) return false; =20 - if (virDomainDeviceInfoIterate(def, qemuComparePCIDevice, dev) < 0) + if (virDomainDeviceInfoIterate(def, qemuComparePCIDevice, info) < 0) return true; return false; } --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Mar 28 20:57:44 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1553207357105773.5179134917602; Thu, 21 Mar 2019 15:29:17 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0D698307D8BE; Thu, 21 Mar 2019 22:29:15 +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 1672460857; Thu, 21 Mar 2019 22:29:14 +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 1EB6F1803387; Thu, 21 Mar 2019 22:29:13 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x2LMTC6e015645 for ; Thu, 21 Mar 2019 18:29:12 -0400 Received: by smtp.corp.redhat.com (Postfix) id 6CC331001DD3; Thu, 21 Mar 2019 22:29:12 +0000 (UTC) Received: from vhost2.laine.org (ovpn-116-180.phx2.redhat.com [10.3.116.180]) by smtp.corp.redhat.com (Postfix) with ESMTP id 01C711001DC9; Thu, 21 Mar 2019 22:29:11 +0000 (UTC) From: Laine Stump To: libvir-list@redhat.com Date: Thu, 21 Mar 2019 18:28:45 -0400 Message-Id: <20190321222901.12902-6-laine@laine.org> In-Reply-To: <20190321222901.12902-1-laine@laine.org> References: <20190321222901.12902-1-laine@laine.org> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Cc: Michal Privoznik , Peter Krempa Subject: [libvirt] [PATCH 05/21] qemu_hotplug: eliminate multiple identical qemuDomainDetachHost*Device() functions 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Thu, 21 Mar 2019 22:29:15 +0000 (UTC) Content-Type: text/plain; charset="utf-8" There are separate Detach functions for PCI, USB, SCSI, Vhost, and Mediated hostdevs, but the functions are all 100% the same code, except that the PCI function checks for the guest side of the device being a PCI Multifunction device, while the other 4 check that the device's alias !=3D NULL. The check for multifunction PCI devices should be done for *all* devices that are connected to the PCI bus in the guest, not just PCI hostdevs, and qemuIsMultiFunctionDevice() conveniently returns false if the queried device doesn't connect with PCI, so it is safe to make this check for all hostdev devices. (It also needs to be done for many other device types, but that will be addressed in a future patch). Likewise, since all hostdevs are detached by calling qemuDomainDeleteDevice(), which requires the device's alias, checking for a valid alias is a reasonable thing for PCI hostdevs too (NB: you'd think that we could rely on every device having a valid alias, but unfortunately when you run virsh qemu-attach on a qemu process that was started with some "old style" device args, they don't include an "id" option on the commandline, so there is no alias in the device object that's created). Signed-off-by: Laine Stump Reviewed-by: J=C3=A1n Tomko --- src/qemu/qemu_hotplug.c | 129 +++++++++------------------------------- 1 file changed, 28 insertions(+), 101 deletions(-) diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 701458b2cd..389d16b090 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -5499,124 +5499,42 @@ int qemuDomainDetachControllerDevice(virQEMUDriver= Ptr driver, return ret; } =20 -static int -qemuDomainDetachHostPCIDevice(virDomainObjPtr vm, - virDomainHostdevDefPtr detach, - bool async) -{ - virDomainHostdevSubsysPCIPtr pcisrc =3D &detach->source.subsys.u.pci; - - if (qemuIsMultiFunctionDevice(vm->def, detach->info)) { - virReportError(VIR_ERR_OPERATION_FAILED, - _("cannot hot unplug multifunction PCI device: %.4x= :%.2x:%.2x.%.1x"), - pcisrc->addr.domain, pcisrc->addr.bus, - pcisrc->addr.slot, pcisrc->addr.function); - return -1; - } - - if (!async) - qemuDomainMarkDeviceForRemoval(vm, detach->info); - - return qemuDomainDeleteDevice(vm, detach->info->alias); -} =20 static int -qemuDomainDetachHostUSBDevice(virDomainObjPtr vm, - virDomainHostdevDefPtr detach, - bool async) -{ - if (!detach->info->alias) { - virReportError(VIR_ERR_OPERATION_FAILED, - "%s", _("device cannot be detached without a device= alias")); - return -1; - } - - if (!async) - qemuDomainMarkDeviceForRemoval(vm, detach->info); - - return qemuDomainDeleteDevice(vm, detach->info->alias); -} - -static int -qemuDomainDetachHostSCSIDevice(virDomainObjPtr vm, +qemuDomainDetachThisHostDevice(virQEMUDriverPtr driver, + virDomainObjPtr vm, virDomainHostdevDefPtr detach, bool async) { - if (!detach->info->alias) { - virReportError(VIR_ERR_OPERATION_FAILED, - "%s", _("device cannot be detached without a device= alias")); - return -1; - } - - if (!async) - qemuDomainMarkDeviceForRemoval(vm, detach->info); + int ret =3D -1; =20 - return qemuDomainDeleteDevice(vm, detach->info->alias); -} + if (qemuAssignDeviceHostdevAlias(vm->def, &detach->info->alias, -1) < = 0) + return -1; =20 -static int -qemuDomainDetachSCSIVHostDevice(virDomainObjPtr vm, - virDomainHostdevDefPtr detach, - bool async) -{ - if (!detach->info->alias) { + if (qemuIsMultiFunctionDevice(vm->def, detach->info)) { virReportError(VIR_ERR_OPERATION_FAILED, - "%s", _("device cannot be detached without a device= alias")); + _("cannot hot unplug multifunction PCI device with = guest address: " + "%.4x:%.2x:%.2x.%.1x"), + detach->info->addr.pci.domain, detach->info->addr.p= ci.bus, + detach->info->addr.pci.slot, detach->info->addr.pci= .function); return -1; } =20 - if (!async) - qemuDomainMarkDeviceForRemoval(vm, detach->info); - - return qemuDomainDeleteDevice(vm, detach->info->alias); -} - - -static int -qemuDomainDetachMediatedDevice(virDomainObjPtr vm, - virDomainHostdevDefPtr detach, - bool async) -{ if (!detach->info->alias) { - virReportError(VIR_ERR_OPERATION_FAILED, "%s", - _("device cannot be detached without a device alias= ")); + virReportError(VIR_ERR_OPERATION_FAILED, + "%s", _("device cannot be detached without a device= alias")); return -1; } =20 - if (!async) - qemuDomainMarkDeviceForRemoval(vm, detach->info); - - return qemuDomainDeleteDevice(vm, detach->info->alias); -} - - -static int -qemuDomainDetachThisHostDevice(virQEMUDriverPtr driver, - virDomainObjPtr vm, - virDomainHostdevDefPtr detach, - bool async) -{ - int ret =3D -1; - - if (qemuAssignDeviceHostdevAlias(vm->def, &detach->info->alias, -1) < = 0) - return -1; - switch (detach->source.subsys.type) { case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI: - ret =3D qemuDomainDetachHostPCIDevice(vm, detach, async); - break; case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB: - ret =3D qemuDomainDetachHostUSBDevice(vm, detach, async); - break; case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI: - ret =3D qemuDomainDetachHostSCSIDevice(vm, detach, async); - break; case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI_HOST: - ret =3D qemuDomainDetachSCSIVHostDevice(vm, detach, async); - break; case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV: - ret =3D qemuDomainDetachMediatedDevice(vm, detach, async); - break; + /* we support detach of all these types of hostdev */ + break; + default: virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("hot unplug is not supported for hostdev subsys t= ype '%s'"), @@ -5624,14 +5542,23 @@ qemuDomainDetachThisHostDevice(virQEMUDriverPtr dri= ver, return -1; } =20 - if (ret < 0) { + if (!async) + qemuDomainMarkDeviceForRemoval(vm, detach->info); + + if (qemuDomainDeleteDevice(vm, detach->info->alias) < 0) { if (virDomainObjIsActive(vm)) virDomainAuditHostdev(vm, detach, "detach", false); - } else if (!async && - (ret =3D qemuDomainWaitForDeviceRemoval(vm)) =3D=3D 1) { - ret =3D qemuDomainRemoveHostDevice(driver, vm, detach); + goto cleanup; } =20 + if (async) { + ret =3D 0; + } else { + if ((ret =3D qemuDomainWaitForDeviceRemoval(vm)) =3D=3D 1) + ret =3D qemuDomainRemoveHostDevice(driver, vm, detach); + } + + cleanup: if (!async) qemuDomainResetDeviceRemoval(vm); =20 --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Mar 28 20:57:44 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 155320738787021.750076973176306; Thu, 21 Mar 2019 15:29:47 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 53DBA3087936; Thu, 21 Mar 2019 22:29:46 +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 2C31F5D9D6; Thu, 21 Mar 2019 22:29:46 +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 D6BC6180338D; Thu, 21 Mar 2019 22:29:45 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x2LMTD5L015651 for ; Thu, 21 Mar 2019 18:29:13 -0400 Received: by smtp.corp.redhat.com (Postfix) id 0EEF71001DD3; Thu, 21 Mar 2019 22:29:13 +0000 (UTC) Received: from vhost2.laine.org (ovpn-116-180.phx2.redhat.com [10.3.116.180]) by smtp.corp.redhat.com (Postfix) with ESMTP id 983181001DC9; Thu, 21 Mar 2019 22:29:12 +0000 (UTC) From: Laine Stump To: libvir-list@redhat.com Date: Thu, 21 Mar 2019 18:28:46 -0400 Message-Id: <20190321222901.12902-7-laine@laine.org> In-Reply-To: <20190321222901.12902-1-laine@laine.org> References: <20190321222901.12902-1-laine@laine.org> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Cc: Michal Privoznik , Peter Krempa Subject: [libvirt] [PATCH 06/21] qemu_hotplug: eliminate unnecessary call to qemuDomainDetachNetDevice() 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Thu, 21 Mar 2019 22:29:46 +0000 (UTC) Content-Type: text/plain; charset="utf-8" qemuDomainDetachHostDevice() has a check at the end that calls qemuDomainDetachNetDevice() in the case that the hostdev is actually a Net device of type=3D'hostdev'. A long time ago when device removal was (supposedly but not actually) synchronous, this would cause some extra code to be run prior to removing the device (e.g. restoring the original MAC address of the device, undoing some sort of virtual port profile, etc). For quite awhile now the device removal has been asynchronous, so that "extra teardown" isn't handled by the detach function, but instead is handled by the Remove function called at a later time. The result is that when we call qemuDomainDetachNetDevice() from qemuDomainDetachHostDevice(), it ends up just calling qemuDomainDetachThisHostDevice() and returning, which is exactly what we do for all other hostdevs anyway. Based on that, remove the behavioral difference when parent.type =3D=3D VIR_DOMAIN_DEVICE_NET, and just call qemuDomainDetachThisHostDevice() for all hostdevs. Signed-off-by: Laine Stump --- src/qemu/qemu_hotplug.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 389d16b090..af99f3bf4c 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -5640,13 +5640,7 @@ int qemuDomainDetachHostDevice(virQEMUDriverPtr driv= er, return -1; } =20 - /* If this is a network hostdev, we need to use the higher-level detach - * function so that mac address / virtualport are reset - */ - if (detach->parent.type =3D=3D VIR_DOMAIN_DEVICE_NET) - return qemuDomainDetachNetDevice(driver, vm, &detach->parent, asyn= c); - else - return qemuDomainDetachThisHostDevice(driver, vm, detach, async); + return qemuDomainDetachThisHostDevice(driver, vm, detach, async); } =20 =20 --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Mar 28 20:57:44 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1553207391165363.32381093987806; Thu, 21 Mar 2019 15:29:51 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9B2963082B43; Thu, 21 Mar 2019 22:29:49 +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 7592C5D9E1; Thu, 21 Mar 2019 22:29:49 +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 33EE2181A009; Thu, 21 Mar 2019 22:29:49 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x2LMTDSp015659 for ; Thu, 21 Mar 2019 18:29:13 -0400 Received: by smtp.corp.redhat.com (Postfix) id A4E091001DDB; Thu, 21 Mar 2019 22:29:13 +0000 (UTC) Received: from vhost2.laine.org (ovpn-116-180.phx2.redhat.com [10.3.116.180]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3A2011001DCF; Thu, 21 Mar 2019 22:29:13 +0000 (UTC) From: Laine Stump To: libvir-list@redhat.com Date: Thu, 21 Mar 2019 18:28:47 -0400 Message-Id: <20190321222901.12902-8-laine@laine.org> In-Reply-To: <20190321222901.12902-1-laine@laine.org> References: <20190321222901.12902-1-laine@laine.org> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Cc: Michal Privoznik , Peter Krempa Subject: [libvirt] [PATCH 07/21] qemu_hotplug: refactor qemuDomainDetachDiskLive and qemuDomainDetachDiskDevice 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Thu, 21 Mar 2019 22:29:50 +0000 (UTC) Content-Type: text/plain; charset="utf-8" qemuDomainDetachDiskDevice() is only called from one place. Moving the contents of the function to that place makes qemuDomainDetachDiskLive() more similar to the other Detach functions called by the toplevel qemuDomainDetachDevice(). The goal is to make each of the device-type-specific functions do this: 1) find the exact device 2) do any device-specific validation 3) do general validation 4) do device-specific shutdown (only needed for net devices) 5) do the common block of code to send device_del to qemu, then optionally wait for a corresponding DEVICE_DELETED event from qemu. with the final aim being that only items 1 & 2 will remain in each device-type-specific function, while 3 & 5 (which are the same for almost every type) will be de-duplicated and moved to the toplevel function that calls all of these (qemuDomainDetachDeviceLive(), which will also contain a callout to the one instance of (4) (netdev). Signed-off-by: Laine Stump --- src/qemu/qemu_hotplug.c | 96 ++++++++++++++++++----------------------- 1 file changed, 43 insertions(+), 53 deletions(-) diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index af99f3bf4c..820929b109 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -5273,47 +5273,6 @@ qemuDomainSignalDeviceRemoval(virDomainObjPtr vm, } =20 =20 -static int -qemuDomainDetachDiskDevice(virQEMUDriverPtr driver, - virDomainObjPtr vm, - virDomainDiskDefPtr detach, - bool async) -{ - int ret =3D -1; - - if (qemuDomainDiskBlockJobIsActive(detach)) - return -1; - - if (detach->bus =3D=3D VIR_DOMAIN_DISK_BUS_VIRTIO && - qemuIsMultiFunctionDevice(vm->def, &detach->info)) { - virReportError(VIR_ERR_OPERATION_FAILED, - _("cannot hot unplug multifunction PCI device: %s"), - detach->dst); - return -1; - } - - if (!async) - qemuDomainMarkDeviceForRemoval(vm, &detach->info); - - if (qemuDomainDeleteDevice(vm, detach->info.alias) < 0) { - if (virDomainObjIsActive(vm)) - virDomainAuditDisk(vm, detach->src, NULL, "detach", false); - goto cleanup; - } - - if (async) { - ret =3D 0; - } else { - if ((ret =3D qemuDomainWaitForDeviceRemoval(vm)) =3D=3D 1) - ret =3D qemuDomainRemoveDiskDevice(driver, vm, detach); - } - - cleanup: - if (!async) - qemuDomainResetDeviceRemoval(vm); - return ret; -} - static int qemuFindDisk(virDomainDefPtr def, const char *dst) { @@ -5333,25 +5292,26 @@ qemuDomainDetachDeviceDiskLive(virQEMUDriverPtr dri= ver, virDomainDeviceDefPtr dev, bool async) { - virDomainDiskDefPtr disk; + virDomainDiskDefPtr detach; int idx; + int ret =3D -1; =20 if ((idx =3D qemuFindDisk(vm->def, dev->data.disk->dst)) < 0) { virReportError(VIR_ERR_OPERATION_FAILED, _("disk %s not found"), dev->data.disk->dst); return -1; } - disk =3D vm->def->disks[idx]; + detach =3D vm->def->disks[idx]; =20 - switch ((virDomainDiskDevice) disk->device) { + switch ((virDomainDiskDevice) detach->device) { case VIR_DOMAIN_DISK_DEVICE_DISK: case VIR_DOMAIN_DISK_DEVICE_LUN: =20 - switch ((virDomainDiskBus) disk->bus) { + switch ((virDomainDiskBus) detach->bus) { case VIR_DOMAIN_DISK_BUS_VIRTIO: case VIR_DOMAIN_DISK_BUS_USB: case VIR_DOMAIN_DISK_BUS_SCSI: - return qemuDomainDetachDiskDevice(driver, vm, disk, async); + break; =20 case VIR_DOMAIN_DISK_BUS_IDE: case VIR_DOMAIN_DISK_BUS_FDC: @@ -5361,12 +5321,12 @@ qemuDomainDetachDeviceDiskLive(virQEMUDriverPtr dri= ver, case VIR_DOMAIN_DISK_BUS_SD: virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", _("This type of disk cannot be hot unplugged")); - break; + return -1; =20 case VIR_DOMAIN_DISK_BUS_LAST: default: - virReportEnumRangeError(virDomainDiskBus, disk->bus); - break; + virReportEnumRangeError(virDomainDiskBus, detach->bus); + return -1; } break; =20 @@ -5374,16 +5334,46 @@ qemuDomainDetachDeviceDiskLive(virQEMUDriverPtr dri= ver, case VIR_DOMAIN_DISK_DEVICE_FLOPPY: virReportError(VIR_ERR_OPERATION_UNSUPPORTED, _("disk device type '%s' cannot be detached"), - virDomainDiskDeviceTypeToString(disk->device)); - break; + virDomainDiskDeviceTypeToString(detach->device)); + return -1; =20 case VIR_DOMAIN_DISK_DEVICE_LAST: default: - virReportEnumRangeError(virDomainDiskDevice, disk->device); + virReportEnumRangeError(virDomainDiskDevice, detach->device); break; } =20 - return -1; + if (qemuDomainDiskBlockJobIsActive(detach)) + return -1; + + if (detach->bus =3D=3D VIR_DOMAIN_DISK_BUS_VIRTIO && + qemuIsMultiFunctionDevice(vm->def, &detach->info)) { + virReportError(VIR_ERR_OPERATION_FAILED, + _("cannot hot unplug multifunction PCI device: %s"), + detach->dst); + return -1; + } + + if (!async) + qemuDomainMarkDeviceForRemoval(vm, &detach->info); + + if (qemuDomainDeleteDevice(vm, detach->info.alias) < 0) { + if (virDomainObjIsActive(vm)) + virDomainAuditDisk(vm, detach->src, NULL, "detach", false); + goto cleanup; + } + + if (async) { + ret =3D 0; + } else { + if ((ret =3D qemuDomainWaitForDeviceRemoval(vm)) =3D=3D 1) + ret =3D qemuDomainRemoveDiskDevice(driver, vm, detach); + } + + cleanup: + if (!async) + qemuDomainResetDeviceRemoval(vm); + return ret; } =20 =20 --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Mar 28 20:57:44 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1553207394647315.7069421458182; Thu, 21 Mar 2019 15:29:54 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 230005D671; Thu, 21 Mar 2019 22:29:53 +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 EFB33608AC; Thu, 21 Mar 2019 22:29:52 +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 AF9EA3FA46; Thu, 21 Mar 2019 22:29:52 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x2LMTEwd015669 for ; Thu, 21 Mar 2019 18:29:14 -0400 Received: by smtp.corp.redhat.com (Postfix) id 46BFC1001DD3; Thu, 21 Mar 2019 22:29:14 +0000 (UTC) Received: from vhost2.laine.org (ovpn-116-180.phx2.redhat.com [10.3.116.180]) by smtp.corp.redhat.com (Postfix) with ESMTP id CDDDB1001DCF; Thu, 21 Mar 2019 22:29:13 +0000 (UTC) From: Laine Stump To: libvir-list@redhat.com Date: Thu, 21 Mar 2019 18:28:48 -0400 Message-Id: <20190321222901.12902-9-laine@laine.org> In-Reply-To: <20190321222901.12902-1-laine@laine.org> References: <20190321222901.12902-1-laine@laine.org> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Cc: Michal Privoznik , Peter Krempa Subject: [libvirt] [PATCH 08/21] qemu_hotplug: don't call DetachThisHostDevice for hostdev network devices 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Thu, 21 Mar 2019 22:29:53 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Back in the bad old days different device types required a different qemu monitor call to detach them, and so an needed to call the function for detaching hostdevs, while other types could be deleted as netdevs. Times have changed, and *all* device types are detached by calling the common function qemuDomainDeleteDevice(vm, alias), so we don't need to differentiate between hostdev interfaces and the others for that reason. There are a few other netdev-specific functions called during qemuDomainDetachNetDevice() (clearing bandwidth limits, stopping the interface), but those turn into NOPs when type=3Dhostdev, so they're safe to call for type=3Dhostdev. The only thing that is different + not a NOP is the call to virDomainAudit*() when qemuDomainDeleteDevice() fails, so if we add a conditional for that small bit of code, we can eliminate the callout from qemuDomainDetachNetDevice() to qemuDomainDetachThisDevice(), which makes this function fit the desired pattern for merging with the other detach functions, and paves the way to simplifying qemuDomainDetachHostDevice() too. Signed-off-by: Laine Stump --- src/qemu/qemu_hotplug.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 820929b109..ee3042cc4c 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -5801,13 +5801,6 @@ qemuDomainDetachNetDevice(virQEMUDriverPtr driver, =20 detach =3D vm->def->nets[detachidx]; =20 - if (virDomainNetGetActualType(detach) =3D=3D VIR_DOMAIN_NET_TYPE_HOSTD= EV) { - ret =3D qemuDomainDetachThisHostDevice(driver, vm, - virDomainNetGetActualHostdev(= detach), - async); - goto cleanup; - } - if (qemuIsMultiFunctionDevice(vm->def, &detach->info)) { virReportError(VIR_ERR_OPERATION_FAILED, _("cannot hot unplug multifunction PCI device: %s"), @@ -5836,8 +5829,13 @@ qemuDomainDetachNetDevice(virQEMUDriverPtr driver, qemuDomainMarkDeviceForRemoval(vm, &detach->info); =20 if (qemuDomainDeleteDevice(vm, detach->info.alias) < 0) { - if (virDomainObjIsActive(vm)) - virDomainAuditNet(vm, detach, NULL, "detach", false); + if (virDomainObjIsActive(vm)) { + /* the audit message has a different format for hostdev networ= k devices */ + if (virDomainNetGetActualType(detach) =3D=3D VIR_DOMAIN_NET_TY= PE_HOSTDEV) + virDomainAuditHostdev(vm, virDomainNetGetActualHostdev(det= ach), "detach", false); + else + virDomainAuditNet(vm, detach, NULL, "detach", false); + } goto cleanup; } =20 --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Mar 28 20:57:44 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 15532073614601007.9617944994337; Thu, 21 Mar 2019 15:29:21 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5AB3A308339A; Thu, 21 Mar 2019 22:29:19 +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 338525C659; Thu, 21 Mar 2019 22:29:19 +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 E15D3180338B; Thu, 21 Mar 2019 22:29:18 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x2LMTEVe015674 for ; Thu, 21 Mar 2019 18:29:14 -0400 Received: by smtp.corp.redhat.com (Postfix) id E0F121001DE2; Thu, 21 Mar 2019 22:29:14 +0000 (UTC) Received: from vhost2.laine.org (ovpn-116-180.phx2.redhat.com [10.3.116.180]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6FCED1001DCF; Thu, 21 Mar 2019 22:29:14 +0000 (UTC) From: Laine Stump To: libvir-list@redhat.com Date: Thu, 21 Mar 2019 18:28:49 -0400 Message-Id: <20190321222901.12902-10-laine@laine.org> In-Reply-To: <20190321222901.12902-1-laine@laine.org> References: <20190321222901.12902-1-laine@laine.org> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Cc: Michal Privoznik , Peter Krempa Subject: [libvirt] [PATCH 09/21] qemu_hotplug: merge qemuDomainDetachThisHostDevice into qemuDomainDetachHostDevice 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Thu, 21 Mar 2019 22:29:19 +0000 (UTC) Content-Type: text/plain; charset="utf-8" It's now only called from one place, and combining the two functions highlights the similarity with Detach functions for other device types. Signed-off-by: Laine Stump --- src/qemu/qemu_hotplug.c | 107 +++++++++++++++------------------------- 1 file changed, 41 insertions(+), 66 deletions(-) diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index ee3042cc4c..1f17e2a05e 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -5490,71 +5490,6 @@ int qemuDomainDetachControllerDevice(virQEMUDriverPt= r driver, } =20 =20 -static int -qemuDomainDetachThisHostDevice(virQEMUDriverPtr driver, - virDomainObjPtr vm, - virDomainHostdevDefPtr detach, - bool async) -{ - int ret =3D -1; - - if (qemuAssignDeviceHostdevAlias(vm->def, &detach->info->alias, -1) < = 0) - return -1; - - if (qemuIsMultiFunctionDevice(vm->def, detach->info)) { - virReportError(VIR_ERR_OPERATION_FAILED, - _("cannot hot unplug multifunction PCI device with = guest address: " - "%.4x:%.2x:%.2x.%.1x"), - detach->info->addr.pci.domain, detach->info->addr.p= ci.bus, - detach->info->addr.pci.slot, detach->info->addr.pci= .function); - return -1; - } - - if (!detach->info->alias) { - virReportError(VIR_ERR_OPERATION_FAILED, - "%s", _("device cannot be detached without a device= alias")); - return -1; - } - - switch (detach->source.subsys.type) { - case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI: - case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB: - case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI: - case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI_HOST: - case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV: - /* we support detach of all these types of hostdev */ - break; - - default: - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("hot unplug is not supported for hostdev subsys t= ype '%s'"), - virDomainHostdevSubsysTypeToString(detach->source.s= ubsys.type)); - return -1; - } - - if (!async) - qemuDomainMarkDeviceForRemoval(vm, detach->info); - - if (qemuDomainDeleteDevice(vm, detach->info->alias) < 0) { - if (virDomainObjIsActive(vm)) - virDomainAuditHostdev(vm, detach, "detach", false); - goto cleanup; - } - - if (async) { - ret =3D 0; - } else { - if ((ret =3D qemuDomainWaitForDeviceRemoval(vm)) =3D=3D 1) - ret =3D qemuDomainRemoveHostDevice(driver, vm, detach); - } - - cleanup: - if (!async) - qemuDomainResetDeviceRemoval(vm); - - return ret; -} - /* search for a hostdev matching dev and detach it */ int qemuDomainDetachHostDevice(virQEMUDriverPtr driver, virDomainObjPtr vm, @@ -5569,6 +5504,7 @@ int qemuDomainDetachHostDevice(virQEMUDriverPtr drive= r, virDomainHostdevSubsysMediatedDevPtr mdevsrc =3D &subsys->u.mdev; virDomainHostdevDefPtr detach =3D NULL; int idx; + int ret =3D -1; =20 if (hostdev->mode !=3D VIR_DOMAIN_HOSTDEV_MODE_SUBSYS) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, @@ -5630,7 +5566,46 @@ int qemuDomainDetachHostDevice(virQEMUDriverPtr driv= er, return -1; } =20 - return qemuDomainDetachThisHostDevice(driver, vm, detach, async); + if (qemuAssignDeviceHostdevAlias(vm->def, &detach->info->alias, -1) < = 0) + return -1; + + if (qemuIsMultiFunctionDevice(vm->def, detach->info)) { + virReportError(VIR_ERR_OPERATION_FAILED, + _("cannot hot unplug multifunction PCI device with = guest address: " + "%.4x:%.2x:%.2x.%.1x"), + detach->info->addr.pci.domain, detach->info->addr.p= ci.bus, + detach->info->addr.pci.slot, detach->info->addr.pci= .function); + return -1; + } + + if (!detach->info->alias) { + virReportError(VIR_ERR_OPERATION_FAILED, + "%s", _("device cannot be detached without a device= alias")); + return -1; + } + + if (!async) + qemuDomainMarkDeviceForRemoval(vm, detach->info); + + if (qemuDomainDeleteDevice(vm, detach->info->alias) < 0) { + if (virDomainObjIsActive(vm)) + virDomainAuditHostdev(vm, detach, "detach", false); + goto cleanup; + } + + if (async) { + ret =3D 0; + } else { + if ((ret =3D qemuDomainWaitForDeviceRemoval(vm)) =3D=3D 1) + ret =3D qemuDomainRemoveHostDevice(driver, vm, detach); + } + + cleanup: + if (!async) + qemuDomainResetDeviceRemoval(vm); + + return ret; + } =20 =20 --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Mar 28 20:57:44 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1553207371064833.8053029553521; Thu, 21 Mar 2019 15:29:31 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id F04578666A; Thu, 21 Mar 2019 22:29:28 +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 C77CF1001DDB; Thu, 21 Mar 2019 22:29:28 +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 8413B38BE; Thu, 21 Mar 2019 22:29:28 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x2LMTHbv015694 for ; Thu, 21 Mar 2019 18:29:17 -0400 Received: by smtp.corp.redhat.com (Postfix) id 77FC91001DC9; Thu, 21 Mar 2019 22:29:17 +0000 (UTC) Received: from vhost2.laine.org (ovpn-116-180.phx2.redhat.com [10.3.116.180]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1533A1001DCF; Thu, 21 Mar 2019 22:29:14 +0000 (UTC) From: Laine Stump To: libvir-list@redhat.com Date: Thu, 21 Mar 2019 18:28:50 -0400 Message-Id: <20190321222901.12902-11-laine@laine.org> In-Reply-To: <20190321222901.12902-1-laine@laine.org> References: <20190321222901.12902-1-laine@laine.org> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Cc: Michal Privoznik , Peter Krempa Subject: [libvirt] [PATCH 10/21] qemu_hotplug: move qemuDomainChangeGraphicsPasswords() 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Thu, 21 Mar 2019 22:29:29 +0000 (UTC) Content-Type: text/plain; charset="utf-8" It was sitting down in the middle of all the qemuDomainDetach*() functions. Move it up with the rest of the qemuDomain*Graphics*() functions. Signed-off-by: Laine Stump --- src/qemu/qemu_hotplug.c | 151 ++++++++++++++++++++-------------------- 1 file changed, 77 insertions(+), 74 deletions(-) diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 1f17e2a05e..ca89cf5d97 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -4170,6 +4170,83 @@ qemuDomainFindGraphicsIndex(virDomainDefPtr def, return -1; } =20 + +int +qemuDomainChangeGraphicsPasswords(virQEMUDriverPtr driver, + virDomainObjPtr vm, + int type, + virDomainGraphicsAuthDefPtr auth, + const char *defaultPasswd, + int asyncJob) +{ + qemuDomainObjPrivatePtr priv =3D vm->privateData; + time_t now =3D time(NULL); + const char *expire; + char *validTo =3D NULL; + const char *connected =3D NULL; + const char *password; + int ret =3D -1; + virQEMUDriverConfigPtr cfg =3D virQEMUDriverGetConfig(driver); + + if (!auth->passwd && !defaultPasswd) { + ret =3D 0; + goto cleanup; + } + password =3D auth->passwd ? auth->passwd : defaultPasswd; + + if (auth->connected) + connected =3D virDomainGraphicsAuthConnectedTypeToString(auth->con= nected); + + if (qemuDomainObjEnterMonitorAsync(driver, vm, asyncJob) < 0) + goto cleanup; + ret =3D qemuMonitorSetPassword(priv->mon, type, password, connected); + + if (ret =3D=3D -2) { + if (type !=3D VIR_DOMAIN_GRAPHICS_TYPE_VNC) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Graphics password only supported for VNC")); + ret =3D -1; + } else { + ret =3D qemuMonitorSetVNCPassword(priv->mon, password); + } + } + if (ret !=3D 0) + goto end_job; + + if (password[0] =3D=3D '\0' || + (auth->expires && auth->validTo <=3D now)) { + expire =3D "now"; + } else if (auth->expires) { + if (virAsprintf(&validTo, "%lu", (unsigned long)auth->validTo) < 0) + goto end_job; + expire =3D validTo; + } else { + expire =3D "never"; + } + + ret =3D qemuMonitorExpirePassword(priv->mon, type, expire); + + if (ret =3D=3D -2) { + /* XXX we could fake this with a timer */ + if (auth->expires) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Expiry of passwords is not supported")); + ret =3D -1; + } else { + ret =3D 0; + } + } + + end_job: + if (qemuDomainObjExitMonitor(driver, vm) < 0) + ret =3D -1; + cleanup: + VIR_FREE(validTo); + virObjectUnref(cfg); + return ret; +} + + int qemuDomainChangeGraphics(virQEMUDriverPtr driver, virDomainObjPtr vm, @@ -5827,80 +5904,6 @@ qemuDomainDetachNetDevice(virQEMUDriverPtr driver, return ret; } =20 -int -qemuDomainChangeGraphicsPasswords(virQEMUDriverPtr driver, - virDomainObjPtr vm, - int type, - virDomainGraphicsAuthDefPtr auth, - const char *defaultPasswd, - int asyncJob) -{ - qemuDomainObjPrivatePtr priv =3D vm->privateData; - time_t now =3D time(NULL); - const char *expire; - char *validTo =3D NULL; - const char *connected =3D NULL; - const char *password; - int ret =3D -1; - virQEMUDriverConfigPtr cfg =3D virQEMUDriverGetConfig(driver); - - if (!auth->passwd && !defaultPasswd) { - ret =3D 0; - goto cleanup; - } - password =3D auth->passwd ? auth->passwd : defaultPasswd; - - if (auth->connected) - connected =3D virDomainGraphicsAuthConnectedTypeToString(auth->con= nected); - - if (qemuDomainObjEnterMonitorAsync(driver, vm, asyncJob) < 0) - goto cleanup; - ret =3D qemuMonitorSetPassword(priv->mon, type, password, connected); - - if (ret =3D=3D -2) { - if (type !=3D VIR_DOMAIN_GRAPHICS_TYPE_VNC) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Graphics password only supported for VNC")); - ret =3D -1; - } else { - ret =3D qemuMonitorSetVNCPassword(priv->mon, password); - } - } - if (ret !=3D 0) - goto end_job; - - if (password[0] =3D=3D '\0' || - (auth->expires && auth->validTo <=3D now)) { - expire =3D "now"; - } else if (auth->expires) { - if (virAsprintf(&validTo, "%lu", (unsigned long)auth->validTo) < 0) - goto end_job; - expire =3D validTo; - } else { - expire =3D "never"; - } - - ret =3D qemuMonitorExpirePassword(priv->mon, type, expire); - - if (ret =3D=3D -2) { - /* XXX we could fake this with a timer */ - if (auth->expires) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Expiry of passwords is not supported")); - ret =3D -1; - } else { - ret =3D 0; - } - } - - end_job: - if (qemuDomainObjExitMonitor(driver, vm) < 0) - ret =3D -1; - cleanup: - VIR_FREE(validTo); - virObjectUnref(cfg); - return ret; -} =20 int qemuDomainAttachLease(virQEMUDriverPtr driver, virDomainObjPtr vm, --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Mar 28 20:57:44 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1553207398303163.37664384345965; Thu, 21 Mar 2019 15:29:58 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 98326316891A; Thu, 21 Mar 2019 22:29:56 +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 690634108; Thu, 21 Mar 2019 22:29:56 +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 2444C181A136; Thu, 21 Mar 2019 22:29:56 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x2LMTI4B015701 for ; Thu, 21 Mar 2019 18:29:18 -0400 Received: by smtp.corp.redhat.com (Postfix) id 1805B1001DDB; Thu, 21 Mar 2019 22:29:18 +0000 (UTC) Received: from vhost2.laine.org (ovpn-116-180.phx2.redhat.com [10.3.116.180]) by smtp.corp.redhat.com (Postfix) with ESMTP id A04F41001DC9; Thu, 21 Mar 2019 22:29:17 +0000 (UTC) From: Laine Stump To: libvir-list@redhat.com Date: Thu, 21 Mar 2019 18:28:51 -0400 Message-Id: <20190321222901.12902-12-laine@laine.org> In-Reply-To: <20190321222901.12902-1-laine@laine.org> References: <20190321222901.12902-1-laine@laine.org> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Cc: Michal Privoznik , Peter Krempa Subject: [libvirt] [PATCH 11/21] qemu_hotplug: move (almost) all qemuDomainDetach*() functions together 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Thu, 21 Mar 2019 22:29:57 +0000 (UTC) Content-Type: text/plain; charset="utf-8" There were two outliers at the end of the file beyond the Vcpu functions. Signed-off-by: Laine Stump --- src/qemu/qemu_hotplug.c | 174 ++++++++++++++++++++-------------------- 1 file changed, 87 insertions(+), 87 deletions(-) diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index ca89cf5d97..094d135aac 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -6102,6 +6102,93 @@ qemuDomainDetachMemoryDevice(virQEMUDriverPtr driver, } =20 =20 +int +qemuDomainDetachInputDevice(virDomainObjPtr vm, + virDomainInputDefPtr def, + bool async) +{ + virDomainInputDefPtr input; + int ret =3D -1; + int idx; + + if ((idx =3D virDomainInputDefFind(vm->def, def)) < 0) { + virReportError(VIR_ERR_OPERATION_FAILED, "%s", + _("matching input device not found")); + return -1; + } + input =3D vm->def->inputs[idx]; + + switch ((virDomainInputBus) input->bus) { + case VIR_DOMAIN_INPUT_BUS_PS2: + case VIR_DOMAIN_INPUT_BUS_XEN: + case VIR_DOMAIN_INPUT_BUS_PARALLELS: + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, + _("input device on bus '%s' cannot be detached"), + virDomainInputBusTypeToString(input->bus)); + return -1; + + case VIR_DOMAIN_INPUT_BUS_LAST: + case VIR_DOMAIN_INPUT_BUS_USB: + case VIR_DOMAIN_INPUT_BUS_VIRTIO: + break; + } + + if (!async) + qemuDomainMarkDeviceForRemoval(vm, &input->info); + + if (qemuDomainDeleteDevice(vm, input->info.alias) < 0) + goto cleanup; + + if (async) { + ret =3D 0; + } else { + if ((ret =3D qemuDomainWaitForDeviceRemoval(vm)) =3D=3D 1) + ret =3D qemuDomainRemoveInputDevice(vm, input); + } + + cleanup: + if (!async) + qemuDomainResetDeviceRemoval(vm); + return ret; +} + + +int +qemuDomainDetachVsockDevice(virDomainObjPtr vm, + virDomainVsockDefPtr dev, + bool async) +{ + virDomainVsockDefPtr vsock =3D vm->def->vsock; + int ret =3D -1; + + + if (!vsock || + !virDomainVsockDefEquals(dev, vsock)) { + virReportError(VIR_ERR_OPERATION_FAILED, "%s", + _("matching vsock device not found")); + return -1; + } + + if (!async) + qemuDomainMarkDeviceForRemoval(vm, &vsock->info); + + if (qemuDomainDeleteDevice(vm, vsock->info.alias) < 0) + goto cleanup; + + if (async) { + ret =3D 0; + } else { + if ((ret =3D qemuDomainWaitForDeviceRemoval(vm)) =3D=3D 1) + ret =3D qemuDomainRemoveVsockDevice(vm, vsock); + } + + cleanup: + if (!async) + qemuDomainResetDeviceRemoval(vm); + return ret; +} + + static int qemuDomainRemoveVcpu(virQEMUDriverPtr driver, virDomainObjPtr vm, @@ -6755,90 +6842,3 @@ qemuDomainSetVcpuInternal(virQEMUDriverPtr driver, virObjectUnref(cfg); return ret; } - - -int -qemuDomainDetachInputDevice(virDomainObjPtr vm, - virDomainInputDefPtr def, - bool async) -{ - virDomainInputDefPtr input; - int ret =3D -1; - int idx; - - if ((idx =3D virDomainInputDefFind(vm->def, def)) < 0) { - virReportError(VIR_ERR_OPERATION_FAILED, "%s", - _("matching input device not found")); - return -1; - } - input =3D vm->def->inputs[idx]; - - switch ((virDomainInputBus) input->bus) { - case VIR_DOMAIN_INPUT_BUS_PS2: - case VIR_DOMAIN_INPUT_BUS_XEN: - case VIR_DOMAIN_INPUT_BUS_PARALLELS: - virReportError(VIR_ERR_OPERATION_UNSUPPORTED, - _("input device on bus '%s' cannot be detached"), - virDomainInputBusTypeToString(input->bus)); - return -1; - - case VIR_DOMAIN_INPUT_BUS_LAST: - case VIR_DOMAIN_INPUT_BUS_USB: - case VIR_DOMAIN_INPUT_BUS_VIRTIO: - break; - } - - if (!async) - qemuDomainMarkDeviceForRemoval(vm, &input->info); - - if (qemuDomainDeleteDevice(vm, input->info.alias) < 0) - goto cleanup; - - if (async) { - ret =3D 0; - } else { - if ((ret =3D qemuDomainWaitForDeviceRemoval(vm)) =3D=3D 1) - ret =3D qemuDomainRemoveInputDevice(vm, input); - } - - cleanup: - if (!async) - qemuDomainResetDeviceRemoval(vm); - return ret; -} - - -int -qemuDomainDetachVsockDevice(virDomainObjPtr vm, - virDomainVsockDefPtr dev, - bool async) -{ - virDomainVsockDefPtr vsock =3D vm->def->vsock; - int ret =3D -1; - - - if (!vsock || - !virDomainVsockDefEquals(dev, vsock)) { - virReportError(VIR_ERR_OPERATION_FAILED, "%s", - _("matching vsock device not found")); - return -1; - } - - if (!async) - qemuDomainMarkDeviceForRemoval(vm, &vsock->info); - - if (qemuDomainDeleteDevice(vm, vsock->info.alias) < 0) - goto cleanup; - - if (async) { - ret =3D 0; - } else { - if ((ret =3D qemuDomainWaitForDeviceRemoval(vm)) =3D=3D 1) - ret =3D qemuDomainRemoveVsockDevice(vm, vsock); - } - - cleanup: - if (!async) - qemuDomainResetDeviceRemoval(vm); - return ret; -} --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Mar 28 20:57:44 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1553207402259153.79472674284602; Thu, 21 Mar 2019 15:30:02 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 9AF254E938; Thu, 21 Mar 2019 22:30:00 +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 7094860BE7; Thu, 21 Mar 2019 22:30:00 +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 2CDF93FA4F; Thu, 21 Mar 2019 22:30:00 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x2LMTIpA015706 for ; Thu, 21 Mar 2019 18:29:18 -0400 Received: by smtp.corp.redhat.com (Postfix) id AE60F1001DDB; Thu, 21 Mar 2019 22:29:18 +0000 (UTC) Received: from vhost2.laine.org (ovpn-116-180.phx2.redhat.com [10.3.116.180]) by smtp.corp.redhat.com (Postfix) with ESMTP id 422BC1001DC9; Thu, 21 Mar 2019 22:29:18 +0000 (UTC) From: Laine Stump To: libvir-list@redhat.com Date: Thu, 21 Mar 2019 18:28:52 -0400 Message-Id: <20190321222901.12902-13-laine@laine.org> In-Reply-To: <20190321222901.12902-1-laine@laine.org> References: <20190321222901.12902-1-laine@laine.org> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Cc: Michal Privoznik , Peter Krempa Subject: [libvirt] [PATCH 12/21] qemu_hotplug: move (Attach|Detach)Lease functions with others of same type 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Thu, 21 Mar 2019 22:30:01 +0000 (UTC) Content-Type: text/plain; charset="utf-8" The Attach and Detach Lease functions were together in the middle of the Detach functions. Put them at the end of their respective sections, since they behave differently from the other attach/detach functions (DetachLease doesn't use qemuDomainDeleteDevice(), and is always synchronous). Signed-off-by: Laine Stump --- src/qemu/qemu_hotplug.c | 96 +++++++++++++++++++++-------------------- 1 file changed, 50 insertions(+), 46 deletions(-) diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 094d135aac..1f96f56942 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -3563,6 +3563,32 @@ qemuDomainAttachVsockDevice(virQEMUDriverPtr driver, } =20 =20 +int +qemuDomainAttachLease(virQEMUDriverPtr driver, + virDomainObjPtr vm, + virDomainLeaseDefPtr lease) +{ + int ret =3D -1; + virQEMUDriverConfigPtr cfg =3D virQEMUDriverGetConfig(driver); + + if (virDomainLeaseInsertPreAlloc(vm->def) < 0) + goto cleanup; + + if (virDomainLockLeaseAttach(driver->lockManager, cfg->uri, + vm, lease) < 0) { + virDomainLeaseInsertPreAlloced(vm->def, NULL); + goto cleanup; + } + + virDomainLeaseInsertPreAlloced(vm->def, lease); + ret =3D 0; + + cleanup: + virObjectUnref(cfg); + return ret; +} + + static int qemuDomainChangeNetBridge(virDomainObjPtr vm, virDomainNetDefPtr olddev, @@ -5905,52 +5931,6 @@ qemuDomainDetachNetDevice(virQEMUDriverPtr driver, } =20 =20 -int qemuDomainAttachLease(virQEMUDriverPtr driver, - virDomainObjPtr vm, - virDomainLeaseDefPtr lease) -{ - int ret =3D -1; - virQEMUDriverConfigPtr cfg =3D virQEMUDriverGetConfig(driver); - - if (virDomainLeaseInsertPreAlloc(vm->def) < 0) - goto cleanup; - - if (virDomainLockLeaseAttach(driver->lockManager, cfg->uri, - vm, lease) < 0) { - virDomainLeaseInsertPreAlloced(vm->def, NULL); - goto cleanup; - } - - virDomainLeaseInsertPreAlloced(vm->def, lease); - ret =3D 0; - - cleanup: - virObjectUnref(cfg); - return ret; -} - -int qemuDomainDetachLease(virQEMUDriverPtr driver, - virDomainObjPtr vm, - virDomainLeaseDefPtr lease) -{ - virDomainLeaseDefPtr det_lease; - int idx; - - if ((idx =3D virDomainLeaseIndex(vm->def, lease)) < 0) { - virReportError(VIR_ERR_INVALID_ARG, - _("Lease %s in lockspace %s does not exist"), - lease->key, NULLSTR(lease->lockspace)); - return -1; - } - - if (virDomainLockLeaseDetach(driver->lockManager, vm, lease) < 0) - return -1; - - det_lease =3D virDomainLeaseRemoveAt(vm->def, idx); - virDomainLeaseDefFree(det_lease); - return 0; -} - int qemuDomainDetachChrDevice(virQEMUDriverPtr driver, virDomainObjPtr vm, virDomainChrDefPtr chr, @@ -6189,6 +6169,30 @@ qemuDomainDetachVsockDevice(virDomainObjPtr vm, } =20 =20 +int +qemuDomainDetachLease(virQEMUDriverPtr driver, + virDomainObjPtr vm, + virDomainLeaseDefPtr lease) +{ + virDomainLeaseDefPtr det_lease; + int idx; + + if ((idx =3D virDomainLeaseIndex(vm->def, lease)) < 0) { + virReportError(VIR_ERR_INVALID_ARG, + _("Lease %s in lockspace %s does not exist"), + lease->key, NULLSTR(lease->lockspace)); + return -1; + } + + if (virDomainLockLeaseDetach(driver->lockManager, vm, lease) < 0) + return -1; + + det_lease =3D virDomainLeaseRemoveAt(vm->def, idx); + virDomainLeaseDefFree(det_lease); + return 0; +} + + static int qemuDomainRemoveVcpu(virQEMUDriverPtr driver, virDomainObjPtr vm, --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Mar 28 20:57:44 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1553207374748885.4421443654262; Thu, 21 Mar 2019 15:29:34 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id B86C030842CF; Thu, 21 Mar 2019 22:29:32 +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 8DA005D793; Thu, 21 Mar 2019 22:29:32 +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 43BD23FB30; Thu, 21 Mar 2019 22:29:32 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x2LMTJcg015714 for ; Thu, 21 Mar 2019 18:29:19 -0400 Received: by smtp.corp.redhat.com (Postfix) id 6459D1001DD3; Thu, 21 Mar 2019 22:29:19 +0000 (UTC) Received: from vhost2.laine.org (ovpn-116-180.phx2.redhat.com [10.3.116.180]) by smtp.corp.redhat.com (Postfix) with ESMTP id D84571001DC9; Thu, 21 Mar 2019 22:29:18 +0000 (UTC) From: Laine Stump To: libvir-list@redhat.com Date: Thu, 21 Mar 2019 18:28:53 -0400 Message-Id: <20190321222901.12902-14-laine@laine.org> In-Reply-To: <20190321222901.12902-1-laine@laine.org> References: <20190321222901.12902-1-laine@laine.org> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Cc: Michal Privoznik , Peter Krempa Subject: [libvirt] [PATCH 13/21] qemu_hotplug: move qemuDomainDetachDeviceLive() to qemu_hotplug.c 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Thu, 21 Mar 2019 22:29:33 +0000 (UTC) Content-Type: text/plain; charset="utf-8" This function is going to take on some of the functionality of its subordinate functions, which all live in qemu_hotplug.c. Signed-off-by: Laine Stump --- src/qemu/qemu_driver.c | 95 ----------------------------- src/qemu/qemu_hotplug.c | 129 +++++++++++++++++++++++++++++++++++----- src/qemu/qemu_hotplug.h | 68 ++++++--------------- 3 files changed, 133 insertions(+), 159 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index a16eab5467..0b80004c6e 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -8004,101 +8004,6 @@ qemuDomainAttachDeviceLive(virDomainObjPtr vm, return ret; } =20 -static int -qemuDomainDetachDeviceControllerLive(virQEMUDriverPtr driver, - virDomainObjPtr vm, - virDomainDeviceDefPtr dev, - bool async) -{ - virDomainControllerDefPtr cont =3D dev->data.controller; - int ret =3D -1; - - switch (cont->type) { - case VIR_DOMAIN_CONTROLLER_TYPE_SCSI: - ret =3D qemuDomainDetachControllerDevice(driver, vm, dev, async); - break; - default : - virReportError(VIR_ERR_OPERATION_UNSUPPORTED, - _("'%s' controller cannot be hot unplugged."), - virDomainControllerTypeToString(cont->type)); - } - return ret; -} - -static int -qemuDomainDetachDeviceLive(virDomainObjPtr vm, - virDomainDeviceDefPtr dev, - virQEMUDriverPtr driver, - bool async) -{ - int ret =3D -1; - - switch ((virDomainDeviceType)dev->type) { - case VIR_DOMAIN_DEVICE_DISK: - ret =3D qemuDomainDetachDeviceDiskLive(driver, vm, dev, async); - break; - case VIR_DOMAIN_DEVICE_CONTROLLER: - ret =3D qemuDomainDetachDeviceControllerLive(driver, vm, dev, asyn= c); - break; - case VIR_DOMAIN_DEVICE_LEASE: - ret =3D qemuDomainDetachLease(driver, vm, dev->data.lease); - break; - case VIR_DOMAIN_DEVICE_NET: - ret =3D qemuDomainDetachNetDevice(driver, vm, dev, async); - break; - case VIR_DOMAIN_DEVICE_HOSTDEV: - ret =3D qemuDomainDetachHostDevice(driver, vm, dev, async); - break; - case VIR_DOMAIN_DEVICE_CHR: - ret =3D qemuDomainDetachChrDevice(driver, vm, dev->data.chr, async= ); - break; - case VIR_DOMAIN_DEVICE_RNG: - ret =3D qemuDomainDetachRNGDevice(driver, vm, dev->data.rng, async= ); - break; - case VIR_DOMAIN_DEVICE_MEMORY: - ret =3D qemuDomainDetachMemoryDevice(driver, vm, dev->data.memory,= async); - break; - case VIR_DOMAIN_DEVICE_SHMEM: - ret =3D qemuDomainDetachShmemDevice(driver, vm, dev->data.shmem, a= sync); - break; - case VIR_DOMAIN_DEVICE_WATCHDOG: - ret =3D qemuDomainDetachWatchdog(driver, vm, dev->data.watchdog, a= sync); - break; - case VIR_DOMAIN_DEVICE_INPUT: - ret =3D qemuDomainDetachInputDevice(vm, dev->data.input, async); - break; - case VIR_DOMAIN_DEVICE_REDIRDEV: - ret =3D qemuDomainDetachRedirdevDevice(driver, vm, dev->data.redir= dev, async); - break; - - case VIR_DOMAIN_DEVICE_VSOCK: - ret =3D qemuDomainDetachVsockDevice(vm, dev->data.vsock, async); - break; - - case VIR_DOMAIN_DEVICE_FS: - case VIR_DOMAIN_DEVICE_SOUND: - case VIR_DOMAIN_DEVICE_VIDEO: - case VIR_DOMAIN_DEVICE_GRAPHICS: - case VIR_DOMAIN_DEVICE_HUB: - case VIR_DOMAIN_DEVICE_SMARTCARD: - case VIR_DOMAIN_DEVICE_MEMBALLOON: - case VIR_DOMAIN_DEVICE_NVRAM: - case VIR_DOMAIN_DEVICE_NONE: - case VIR_DOMAIN_DEVICE_TPM: - case VIR_DOMAIN_DEVICE_PANIC: - case VIR_DOMAIN_DEVICE_IOMMU: - case VIR_DOMAIN_DEVICE_LAST: - virReportError(VIR_ERR_OPERATION_UNSUPPORTED, - _("live detach of device '%s' is not supported"), - virDomainDeviceTypeToString(dev->type)); - break; - } - - if (ret =3D=3D 0) - ret =3D qemuDomainUpdateDeviceList(driver, vm, QEMU_ASYNC_JOB_NONE= ); - - return ret; -} =20 static int qemuDomainChangeDiskLive(virDomainObjPtr vm, diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 1f96f56942..c7aba74c6b 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -5540,10 +5540,11 @@ static bool qemuDomainControllerIsBusy(virDomainObj= Ptr vm, } } =20 -int qemuDomainDetachControllerDevice(virQEMUDriverPtr driver, - virDomainObjPtr vm, - virDomainDeviceDefPtr dev, - bool async) +static int +qemuDomainDetachControllerDevice(virQEMUDriverPtr driver, + virDomainObjPtr vm, + virDomainDeviceDefPtr dev, + bool async) { int idx, ret =3D -1; virDomainControllerDefPtr detach =3D NULL; @@ -5594,10 +5595,11 @@ int qemuDomainDetachControllerDevice(virQEMUDriverP= tr driver, =20 =20 /* search for a hostdev matching dev and detach it */ -int qemuDomainDetachHostDevice(virQEMUDriverPtr driver, - virDomainObjPtr vm, - virDomainDeviceDefPtr dev, - bool async) +static int +qemuDomainDetachHostDevice(virQEMUDriverPtr driver, + virDomainObjPtr vm, + virDomainDeviceDefPtr dev, + bool async) { virDomainHostdevDefPtr hostdev =3D dev->data.hostdev; virDomainHostdevSubsysPtr subsys =3D &hostdev->source.subsys; @@ -5821,7 +5823,7 @@ qemuDomainDetachWatchdog(virQEMUDriverPtr driver, } =20 =20 -int +static int qemuDomainDetachRedirdevDevice(virQEMUDriverPtr driver, virDomainObjPtr vm, virDomainRedirdevDefPtr dev, @@ -5865,7 +5867,7 @@ qemuDomainDetachRedirdevDevice(virQEMUDriverPtr drive= r, } =20 =20 -int +static int qemuDomainDetachNetDevice(virQEMUDriverPtr driver, virDomainObjPtr vm, virDomainDeviceDefPtr dev, @@ -5988,7 +5990,7 @@ int qemuDomainDetachChrDevice(virQEMUDriverPtr driver, } =20 =20 -int +static int qemuDomainDetachRNGDevice(virQEMUDriverPtr driver, virDomainObjPtr vm, virDomainRNGDefPtr rng, @@ -6034,7 +6036,7 @@ qemuDomainDetachRNGDevice(virQEMUDriverPtr driver, } =20 =20 -int +static int qemuDomainDetachMemoryDevice(virQEMUDriverPtr driver, virDomainObjPtr vm, virDomainMemoryDefPtr memdef, @@ -6082,7 +6084,7 @@ qemuDomainDetachMemoryDevice(virQEMUDriverPtr driver, } =20 =20 -int +static int qemuDomainDetachInputDevice(virDomainObjPtr vm, virDomainInputDefPtr def, bool async) @@ -6133,7 +6135,7 @@ qemuDomainDetachInputDevice(virDomainObjPtr vm, } =20 =20 -int +static int qemuDomainDetachVsockDevice(virDomainObjPtr vm, virDomainVsockDefPtr dev, bool async) @@ -6169,7 +6171,7 @@ qemuDomainDetachVsockDevice(virDomainObjPtr vm, } =20 =20 -int +static int qemuDomainDetachLease(virQEMUDriverPtr driver, virDomainObjPtr vm, virDomainLeaseDefPtr lease) @@ -6193,6 +6195,103 @@ qemuDomainDetachLease(virQEMUDriverPtr driver, } =20 =20 +static int +qemuDomainDetachDeviceControllerLive(virQEMUDriverPtr driver, + virDomainObjPtr vm, + virDomainDeviceDefPtr dev, + bool async) +{ + virDomainControllerDefPtr cont =3D dev->data.controller; + int ret =3D -1; + + switch (cont->type) { + case VIR_DOMAIN_CONTROLLER_TYPE_SCSI: + ret =3D qemuDomainDetachControllerDevice(driver, vm, dev, async); + break; + default : + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, + _("'%s' controller cannot be hot unplugged."), + virDomainControllerTypeToString(cont->type)); + } + return ret; +} + +int +qemuDomainDetachDeviceLive(virDomainObjPtr vm, + virDomainDeviceDefPtr dev, + virQEMUDriverPtr driver, + bool async) +{ + int ret =3D -1; + + switch ((virDomainDeviceType)dev->type) { + case VIR_DOMAIN_DEVICE_DISK: + ret =3D qemuDomainDetachDeviceDiskLive(driver, vm, dev, async); + break; + case VIR_DOMAIN_DEVICE_CONTROLLER: + ret =3D qemuDomainDetachDeviceControllerLive(driver, vm, dev, asyn= c); + break; + case VIR_DOMAIN_DEVICE_LEASE: + ret =3D qemuDomainDetachLease(driver, vm, dev->data.lease); + break; + case VIR_DOMAIN_DEVICE_NET: + ret =3D qemuDomainDetachNetDevice(driver, vm, dev, async); + break; + case VIR_DOMAIN_DEVICE_HOSTDEV: + ret =3D qemuDomainDetachHostDevice(driver, vm, dev, async); + break; + case VIR_DOMAIN_DEVICE_CHR: + ret =3D qemuDomainDetachChrDevice(driver, vm, dev->data.chr, async= ); + break; + case VIR_DOMAIN_DEVICE_RNG: + ret =3D qemuDomainDetachRNGDevice(driver, vm, dev->data.rng, async= ); + break; + case VIR_DOMAIN_DEVICE_MEMORY: + ret =3D qemuDomainDetachMemoryDevice(driver, vm, dev->data.memory,= async); + break; + case VIR_DOMAIN_DEVICE_SHMEM: + ret =3D qemuDomainDetachShmemDevice(driver, vm, dev->data.shmem, a= sync); + break; + case VIR_DOMAIN_DEVICE_WATCHDOG: + ret =3D qemuDomainDetachWatchdog(driver, vm, dev->data.watchdog, a= sync); + break; + case VIR_DOMAIN_DEVICE_INPUT: + ret =3D qemuDomainDetachInputDevice(vm, dev->data.input, async); + break; + case VIR_DOMAIN_DEVICE_REDIRDEV: + ret =3D qemuDomainDetachRedirdevDevice(driver, vm, dev->data.redir= dev, async); + break; + + case VIR_DOMAIN_DEVICE_VSOCK: + ret =3D qemuDomainDetachVsockDevice(vm, dev->data.vsock, async); + break; + + case VIR_DOMAIN_DEVICE_FS: + case VIR_DOMAIN_DEVICE_SOUND: + case VIR_DOMAIN_DEVICE_VIDEO: + case VIR_DOMAIN_DEVICE_GRAPHICS: + case VIR_DOMAIN_DEVICE_HUB: + case VIR_DOMAIN_DEVICE_SMARTCARD: + case VIR_DOMAIN_DEVICE_MEMBALLOON: + case VIR_DOMAIN_DEVICE_NVRAM: + case VIR_DOMAIN_DEVICE_NONE: + case VIR_DOMAIN_DEVICE_TPM: + case VIR_DOMAIN_DEVICE_PANIC: + case VIR_DOMAIN_DEVICE_IOMMU: + case VIR_DOMAIN_DEVICE_LAST: + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, + _("live detach of device '%s' is not supported"), + virDomainDeviceTypeToString(dev->type)); + break; + } + + if (ret =3D=3D 0) + ret =3D qemuDomainUpdateDeviceList(driver, vm, QEMU_ASYNC_JOB_NONE= ); + + return ret; +} + + static int qemuDomainRemoveVcpu(virQEMUDriverPtr driver, virDomainObjPtr vm, diff --git a/src/qemu/qemu_hotplug.h b/src/qemu/qemu_hotplug.h index 7ac03b7810..61f732c506 100644 --- a/src/qemu/qemu_hotplug.h +++ b/src/qemu/qemu_hotplug.h @@ -79,10 +79,6 @@ int qemuDomainFindGraphicsIndex(virDomainDefPtr def, int qemuDomainAttachMemory(virQEMUDriverPtr driver, virDomainObjPtr vm, virDomainMemoryDefPtr mem); -int qemuDomainDetachMemoryDevice(virQEMUDriverPtr driver, - virDomainObjPtr vm, - virDomainMemoryDefPtr memdef, - bool async); int qemuDomainChangeGraphics(virQEMUDriverPtr driver, virDomainObjPtr vm, virDomainGraphicsDefPtr dev); @@ -99,35 +95,6 @@ int qemuDomainChangeNetLinkState(virQEMUDriverPtr driver, virDomainObjPtr vm, virDomainNetDefPtr dev, int linkstate); -int qemuDomainDetachDeviceDiskLive(virQEMUDriverPtr driver, - virDomainObjPtr vm, - virDomainDeviceDefPtr dev, - bool async); -int qemuDomainDetachControllerDevice(virQEMUDriverPtr driver, - virDomainObjPtr vm, - virDomainDeviceDefPtr dev, - bool async); -int qemuDomainDetachNetDevice(virQEMUDriverPtr driver, - virDomainObjPtr vm, - virDomainDeviceDefPtr dev, - bool async); -int qemuDomainDetachHostDevice(virQEMUDriverPtr driver, - virDomainObjPtr vm, - virDomainDeviceDefPtr dev, - bool async); -int qemuDomainDetachShmemDevice(virQEMUDriverPtr driver, - virDomainObjPtr vm, - virDomainShmemDefPtr dev, - bool async); -int qemuDomainDetachWatchdog(virQEMUDriverPtr driver, - virDomainObjPtr vm, - virDomainWatchdogDefPtr watchdog, - bool async); - -int qemuDomainDetachRedirdevDevice(virQEMUDriverPtr driver, - virDomainObjPtr vm, - virDomainRedirdevDefPtr dev, - bool async); =20 int qemuDomainAttachInputDevice(virQEMUDriverPtr driver, virDomainObjPtr vm, @@ -140,23 +107,33 @@ int qemuDomainAttachVsockDevice(virQEMUDriverPtr driv= er, int qemuDomainAttachLease(virQEMUDriverPtr driver, virDomainObjPtr vm, virDomainLeaseDefPtr lease); -int qemuDomainDetachLease(virQEMUDriverPtr driver, - virDomainObjPtr vm, - virDomainLeaseDefPtr lease); int qemuDomainAttachChrDevice(virQEMUDriverPtr driver, virDomainObjPtr vm, virDomainChrDefPtr chr); -int qemuDomainDetachChrDevice(virQEMUDriverPtr driver, - virDomainObjPtr vm, - virDomainChrDefPtr chr, - bool async); int qemuDomainAttachRNGDevice(virQEMUDriverPtr driver, virDomainObjPtr vm, virDomainRNGDefPtr rng); -int qemuDomainDetachRNGDevice(virQEMUDriverPtr driver, + +int qemuDomainDetachDeviceDiskLive(virQEMUDriverPtr driver, + virDomainObjPtr vm, + virDomainDeviceDefPtr dev, + bool async); +int qemuDomainDetachShmemDevice(virQEMUDriverPtr driver, + virDomainObjPtr vm, + virDomainShmemDefPtr dev, + bool async); +int qemuDomainDetachWatchdog(virQEMUDriverPtr driver, + virDomainObjPtr vm, + virDomainWatchdogDefPtr watchdog, + bool async); +int qemuDomainDetachChrDevice(virQEMUDriverPtr driver, virDomainObjPtr vm, - virDomainRNGDefPtr rng, + virDomainChrDefPtr chr, bool async); +int qemuDomainDetachDeviceLive(virDomainObjPtr vm, + virDomainDeviceDefPtr dev, + virQEMUDriverPtr driver, + bool async); =20 void qemuDomainRemoveVcpuAlias(virQEMUDriverPtr driver, virDomainObjPtr vm, @@ -191,11 +168,4 @@ int qemuDomainSetVcpuInternal(virQEMUDriverPtr driver, virBitmapPtr vcpus, bool state); =20 -int qemuDomainDetachInputDevice(virDomainObjPtr vm, - virDomainInputDefPtr def, - bool async); - -int qemuDomainDetachVsockDevice(virDomainObjPtr vm, - virDomainVsockDefPtr dev, - bool async); #endif /* LIBVIRT_QEMU_HOTPLUG_H */ --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Mar 28 20:57:44 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1553207408021624.0251544761162; Thu, 21 Mar 2019 15:30:08 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 152D330B2488; Thu, 21 Mar 2019 22:30:06 +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 D6EA460BE5; Thu, 21 Mar 2019 22:30:05 +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 738C33FA4C; Thu, 21 Mar 2019 22:30:05 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x2LMTKc1015724 for ; Thu, 21 Mar 2019 18:29:20 -0400 Received: by smtp.corp.redhat.com (Postfix) id 03DD71001DCF; Thu, 21 Mar 2019 22:29:20 +0000 (UTC) Received: from vhost2.laine.org (ovpn-116-180.phx2.redhat.com [10.3.116.180]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8C9D31001DC9; Thu, 21 Mar 2019 22:29:19 +0000 (UTC) From: Laine Stump To: libvir-list@redhat.com Date: Thu, 21 Mar 2019 18:28:54 -0400 Message-Id: <20190321222901.12902-15-laine@laine.org> In-Reply-To: <20190321222901.12902-1-laine@laine.org> References: <20190321222901.12902-1-laine@laine.org> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Cc: Michal Privoznik , Peter Krempa Subject: [libvirt] [PATCH 14/21] qemu_hotplug: remove extra function in middle of DetachController call chain 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Thu, 21 Mar 2019 22:30:06 +0000 (UTC) Content-Type: text/plain; charset="utf-8" qemuDomainDetachDeviceControllerLive() just checks if the controller type is SCSI, and then either returns failure, or calls qemuDomainDetachControllerDevice(). Instead, lets just check for type !=3D SCSI at the top of the latter function, and call it directly. Signed-off-by: Laine Stump --- src/qemu/qemu_hotplug.c | 42 ++++++++++++++--------------------------- 1 file changed, 14 insertions(+), 28 deletions(-) diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index c7aba74c6b..6b713e1c27 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -5549,6 +5549,13 @@ qemuDomainDetachControllerDevice(virQEMUDriverPtr dr= iver, int idx, ret =3D -1; virDomainControllerDefPtr detach =3D NULL; =20 + if (dev->data.controller->type !=3D VIR_DOMAIN_CONTROLLER_TYPE_SCSI) { + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, + _("'%s' controller cannot be hot unplugged."), + virDomainControllerTypeToString(dev->data.controlle= r->type)); + return -1; + } + if ((idx =3D virDomainControllerFind(vm->def, dev->data.controller->type, dev->data.controller->idx)) < 0) { @@ -5561,6 +5568,12 @@ qemuDomainDetachControllerDevice(virQEMUDriverPtr dr= iver, =20 detach =3D vm->def->controllers[idx]; =20 + if (qemuDomainControllerIsBusy(vm, detach)) { + virReportError(VIR_ERR_OPERATION_FAILED, "%s", + _("device cannot be detached: device is busy")); + goto cleanup; + } + if (qemuIsMultiFunctionDevice(vm->def, &detach->info)) { virReportError(VIR_ERR_OPERATION_FAILED, _("cannot hot unplug multifunction PCI device: %s"), @@ -5568,12 +5581,6 @@ qemuDomainDetachControllerDevice(virQEMUDriverPtr dr= iver, goto cleanup; } =20 - if (qemuDomainControllerIsBusy(vm, detach)) { - virReportError(VIR_ERR_OPERATION_FAILED, "%s", - _("device cannot be detached: device is busy")); - goto cleanup; - } - if (!async) qemuDomainMarkDeviceForRemoval(vm, &detach->info); =20 @@ -6195,27 +6202,6 @@ qemuDomainDetachLease(virQEMUDriverPtr driver, } =20 =20 -static int -qemuDomainDetachDeviceControllerLive(virQEMUDriverPtr driver, - virDomainObjPtr vm, - virDomainDeviceDefPtr dev, - bool async) -{ - virDomainControllerDefPtr cont =3D dev->data.controller; - int ret =3D -1; - - switch (cont->type) { - case VIR_DOMAIN_CONTROLLER_TYPE_SCSI: - ret =3D qemuDomainDetachControllerDevice(driver, vm, dev, async); - break; - default : - virReportError(VIR_ERR_OPERATION_UNSUPPORTED, - _("'%s' controller cannot be hot unplugged."), - virDomainControllerTypeToString(cont->type)); - } - return ret; -} - int qemuDomainDetachDeviceLive(virDomainObjPtr vm, virDomainDeviceDefPtr dev, @@ -6229,7 +6215,7 @@ qemuDomainDetachDeviceLive(virDomainObjPtr vm, ret =3D qemuDomainDetachDeviceDiskLive(driver, vm, dev, async); break; case VIR_DOMAIN_DEVICE_CONTROLLER: - ret =3D qemuDomainDetachDeviceControllerLive(driver, vm, dev, asyn= c); + ret =3D qemuDomainDetachControllerDevice(driver, vm, dev, async); break; case VIR_DOMAIN_DEVICE_LEASE: ret =3D qemuDomainDetachLease(driver, vm, dev->data.lease); --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Mar 28 20:57:44 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1553207378077682.3498928981533; Thu, 21 Mar 2019 15:29:38 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 4CDDD81F18; Thu, 21 Mar 2019 22:29:36 +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 269745D788; Thu, 21 Mar 2019 22:29:36 +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 D35891803386; Thu, 21 Mar 2019 22:29:35 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x2LMTKCL015729 for ; Thu, 21 Mar 2019 18:29:20 -0400 Received: by smtp.corp.redhat.com (Postfix) id 97B8A1001DDB; Thu, 21 Mar 2019 22:29:20 +0000 (UTC) Received: from vhost2.laine.org (ovpn-116-180.phx2.redhat.com [10.3.116.180]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2BC241001DC9; Thu, 21 Mar 2019 22:29:20 +0000 (UTC) From: Laine Stump To: libvir-list@redhat.com Date: Thu, 21 Mar 2019 18:28:55 -0400 Message-Id: <20190321222901.12902-16-laine@laine.org> In-Reply-To: <20190321222901.12902-1-laine@laine.org> References: <20190321222901.12902-1-laine@laine.org> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Cc: Michal Privoznik , Peter Krempa Subject: [libvirt] [PATCH 15/21] qemu_hotplug: pull qemuDomainUpdateDeviceList out of qemuDomainDetachDeviceLive 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Thu, 21 Mar 2019 22:29:36 +0000 (UTC) Content-Type: text/plain; charset="utf-8" qemuDomainDetachDeviceLive() is called from two places in qemu_driver.c. Move the call to qemuDomainUpdateDeviceList() from the end of that function, which is now in qemu_hotplug.c, to the two places that call qemuDomainDetachDeviceLive(). Removing that one call from qemuDomainDetachDeviceList() will permit us to call it from the test driver, replacing the separate calls to qemuDomainDetachDeviceDiskLive(), qemuDomainDetachChrDevice(), qemuDomainDetachShmemDevice() and qemuDomainDetachWatchdog(). We want to do this so that part of the common functionality of those three functions (and the rest of the device-specific Detach functions) can be pulled up into qemuDomainDetachDeviceLive() without breaking the test. (This is done in the next patch). Signed-off-by: Laine Stump --- src/qemu/qemu_driver.c | 7 +++++++ src/qemu/qemu_hotplug.c | 3 --- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 0b80004c6e..8e7bb913a2 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -8932,6 +8932,10 @@ qemuDomainDetachDeviceLiveAndConfig(virQEMUDriverPtr= driver, if (flags & VIR_DOMAIN_AFFECT_LIVE) { if (qemuDomainDetachDeviceLive(vm, dev_copy, driver, false) < 0) goto cleanup; + + if (qemuDomainUpdateDeviceList(driver, vm, QEMU_ASYNC_JOB_NONE) < = 0) + goto cleanup; + /* * update domain status forcibly because the domain status may be * changed even if we failed to attach the device. For example, @@ -9014,6 +9018,9 @@ qemuDomainDetachDeviceAliasLiveAndConfig(virQEMUDrive= rPtr driver, =20 if (qemuDomainDetachDeviceLive(vm, &dev, driver, true) < 0) goto cleanup; + + if (qemuDomainUpdateDeviceList(driver, vm, QEMU_ASYNC_JOB_NONE) < = 0) + goto cleanup; } =20 if (vmdef) { diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 6b713e1c27..ea5b6bf8ac 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -6271,9 +6271,6 @@ qemuDomainDetachDeviceLive(virDomainObjPtr vm, break; } =20 - if (ret =3D=3D 0) - ret =3D qemuDomainUpdateDeviceList(driver, vm, QEMU_ASYNC_JOB_NONE= ); - return ret; } =20 --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Mar 28 20:57:44 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1553207412703256.0826468403436; Thu, 21 Mar 2019 15:30:12 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id E10B130B24E8; Thu, 21 Mar 2019 22:30:10 +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 B233C5D71E; Thu, 21 Mar 2019 22:30:10 +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 60311181A850; Thu, 21 Mar 2019 22:30:10 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x2LMTLKC015739 for ; Thu, 21 Mar 2019 18:29:21 -0400 Received: by smtp.corp.redhat.com (Postfix) id 3985F1001DE2; Thu, 21 Mar 2019 22:29:21 +0000 (UTC) Received: from vhost2.laine.org (ovpn-116-180.phx2.redhat.com [10.3.116.180]) by smtp.corp.redhat.com (Postfix) with ESMTP id C086C1001DC9; Thu, 21 Mar 2019 22:29:20 +0000 (UTC) From: Laine Stump To: libvir-list@redhat.com Date: Thu, 21 Mar 2019 18:28:56 -0400 Message-Id: <20190321222901.12902-17-laine@laine.org> In-Reply-To: <20190321222901.12902-1-laine@laine.org> References: <20190321222901.12902-1-laine@laine.org> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Cc: Michal Privoznik , Peter Krempa Subject: [libvirt] [PATCH 16/21] test: replace calls to individual detach functions with one call to main detach 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Thu, 21 Mar 2019 22:30:11 +0000 (UTC) Content-Type: text/plain; charset="utf-8" The individual qemuDomainDetach*Device() functions will soon be "less functional", since some of the code that is duplicated in 10 of the 12 detach functions is going to be moved into the common qemuDomainDetachDeviceLive(), which calls them all. qemuhotplugtest.c is the only place any of these individual functions is called other than qemuDomainDetachDeviceLive() itself. Fortunately, qemuDomainDetachDeviceLive() provides exactly the functionality needed by the test driver (except that it supports detach of more device types than the test driver has tests for). This patch replaces the calls to qemuDomainDetach(Chr|Shmen|Watchdog|Disk)Device with a single call to the higher level function, allowing us to shift functionality between the lower level functions without breaking the tests. Signed-off-by: Laine Stump --- src/qemu/qemu_hotplug.c | 15 ++++++++------- src/qemu/qemu_hotplug.h | 16 ---------------- tests/qemuhotplugtest.c | 8 +------- 3 files changed, 9 insertions(+), 30 deletions(-) diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index ea5b6bf8ac..2d13fca871 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -5389,7 +5389,7 @@ qemuFindDisk(virDomainDefPtr def, const char *dst) return -1; } =20 -int +static int qemuDomainDetachDeviceDiskLive(virQEMUDriverPtr driver, virDomainObjPtr vm, virDomainDeviceDefPtr dev, @@ -5721,7 +5721,7 @@ qemuDomainDetachHostDevice(virQEMUDriverPtr driver, } =20 =20 -int +static int qemuDomainDetachShmemDevice(virQEMUDriverPtr driver, virDomainObjPtr vm, virDomainShmemDefPtr dev, @@ -5775,7 +5775,7 @@ qemuDomainDetachShmemDevice(virQEMUDriverPtr driver, } =20 =20 -int +static int qemuDomainDetachWatchdog(virQEMUDriverPtr driver, virDomainObjPtr vm, virDomainWatchdogDefPtr dev, @@ -5940,10 +5940,11 @@ qemuDomainDetachNetDevice(virQEMUDriverPtr driver, } =20 =20 -int qemuDomainDetachChrDevice(virQEMUDriverPtr driver, - virDomainObjPtr vm, - virDomainChrDefPtr chr, - bool async) +static int +qemuDomainDetachChrDevice(virQEMUDriverPtr driver, + virDomainObjPtr vm, + virDomainChrDefPtr chr, + bool async) { int ret =3D -1; qemuDomainObjPrivatePtr priv =3D vm->privateData; diff --git a/src/qemu/qemu_hotplug.h b/src/qemu/qemu_hotplug.h index 61f732c506..9980c2a756 100644 --- a/src/qemu/qemu_hotplug.h +++ b/src/qemu/qemu_hotplug.h @@ -114,22 +114,6 @@ int qemuDomainAttachRNGDevice(virQEMUDriverPtr driver, virDomainObjPtr vm, virDomainRNGDefPtr rng); =20 -int qemuDomainDetachDeviceDiskLive(virQEMUDriverPtr driver, - virDomainObjPtr vm, - virDomainDeviceDefPtr dev, - bool async); -int qemuDomainDetachShmemDevice(virQEMUDriverPtr driver, - virDomainObjPtr vm, - virDomainShmemDefPtr dev, - bool async); -int qemuDomainDetachWatchdog(virQEMUDriverPtr driver, - virDomainObjPtr vm, - virDomainWatchdogDefPtr watchdog, - bool async); -int qemuDomainDetachChrDevice(virQEMUDriverPtr driver, - virDomainObjPtr vm, - virDomainChrDefPtr chr, - bool async); int qemuDomainDetachDeviceLive(virDomainObjPtr vm, virDomainDeviceDefPtr dev, virQEMUDriverPtr driver, diff --git a/tests/qemuhotplugtest.c b/tests/qemuhotplugtest.c index 1491c214d0..3eb97d886a 100644 --- a/tests/qemuhotplugtest.c +++ b/tests/qemuhotplugtest.c @@ -147,16 +147,10 @@ testQemuHotplugDetach(virDomainObjPtr vm, =20 switch (dev->type) { case VIR_DOMAIN_DEVICE_DISK: - ret =3D qemuDomainDetachDeviceDiskLive(&driver, vm, dev, async); - break; case VIR_DOMAIN_DEVICE_CHR: - ret =3D qemuDomainDetachChrDevice(&driver, vm, dev->data.chr, asyn= c); - break; case VIR_DOMAIN_DEVICE_SHMEM: - ret =3D qemuDomainDetachShmemDevice(&driver, vm, dev->data.shmem, = async); - break; case VIR_DOMAIN_DEVICE_WATCHDOG: - ret =3D qemuDomainDetachWatchdog(&driver, vm, dev->data.watchdog, = async); + ret =3D qemuDomainDetachDeviceLive(vm, dev, &driver, async); break; default: VIR_TEST_VERBOSE("device type '%s' cannot be detached\n", --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Mar 28 20:57:44 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1553207370715593.8847056041418; Thu, 21 Mar 2019 15:29:30 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 191533083394; Thu, 21 Mar 2019 22:29:29 +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 E383F60865; Thu, 21 Mar 2019 22:29:28 +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 A46183FB11; Thu, 21 Mar 2019 22:29:28 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x2LMTLp4015749 for ; Thu, 21 Mar 2019 18:29:21 -0400 Received: by smtp.corp.redhat.com (Postfix) id CFFDE1001DF9; Thu, 21 Mar 2019 22:29:21 +0000 (UTC) Received: from vhost2.laine.org (ovpn-116-180.phx2.redhat.com [10.3.116.180]) by smtp.corp.redhat.com (Postfix) with ESMTP id 61C791001DDB; Thu, 21 Mar 2019 22:29:21 +0000 (UTC) From: Laine Stump To: libvir-list@redhat.com Date: Thu, 21 Mar 2019 18:28:57 -0400 Message-Id: <20190321222901.12902-18-laine@laine.org> In-Reply-To: <20190321222901.12902-1-laine@laine.org> References: <20190321222901.12902-1-laine@laine.org> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Cc: Michal Privoznik , Peter Krempa Subject: [libvirt] [PATCH 17/21] qemu_hotplug: rename dev to match in qemuDomainDetachDeviceLive 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Thu, 21 Mar 2019 22:29:29 +0000 (UTC) Content-Type: text/plain; charset="utf-8" I'm about to add a second virDomainDeviceDef to this function that will point to the actual device in the domain object. while this is just a partially filled-in example of what to look for. Naming it match will make the code easier to follow. Signed-off-by: Laine Stump --- src/qemu/qemu_hotplug.c | 54 +++++++++++++++++++++++++---------------- src/qemu/qemu_hotplug.h | 2 +- 2 files changed, 34 insertions(+), 22 deletions(-) diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 2d13fca871..903a0c46eb 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -6205,52 +6205,64 @@ qemuDomainDetachLease(virQEMUDriverPtr driver, =20 int qemuDomainDetachDeviceLive(virDomainObjPtr vm, - virDomainDeviceDefPtr dev, + virDomainDeviceDefPtr match, virQEMUDriverPtr driver, bool async) { int ret =3D -1; =20 - switch ((virDomainDeviceType)dev->type) { + switch ((virDomainDeviceType)match->type) { + /* + * lease and chr devices don't follow the standard pattern of + * the others, so they must have their own self-contained + * Detach functions. + */ + case VIR_DOMAIN_DEVICE_LEASE: + return qemuDomainDetachLease(driver, vm, match->data.lease); + + case VIR_DOMAIN_DEVICE_CHR: + return qemuDomainDetachChrDevice(driver, vm, match->data.chr, asyn= c); + + /* + * All the other device types follow a very similar pattern - + * First we call type-specific functions to 1) locate the device + * we want to detach (based on the prototype device in match) + * and 2) do any device-type-specific validation to assure it + * is okay to detach the device. + */ case VIR_DOMAIN_DEVICE_DISK: - ret =3D qemuDomainDetachDeviceDiskLive(driver, vm, dev, async); + ret =3D qemuDomainDetachDeviceDiskLive(driver, vm, match, async); break; case VIR_DOMAIN_DEVICE_CONTROLLER: - ret =3D qemuDomainDetachControllerDevice(driver, vm, dev, async); - break; - case VIR_DOMAIN_DEVICE_LEASE: - ret =3D qemuDomainDetachLease(driver, vm, dev->data.lease); + ret =3D qemuDomainDetachControllerDevice(driver, vm, match, async); break; case VIR_DOMAIN_DEVICE_NET: - ret =3D qemuDomainDetachNetDevice(driver, vm, dev, async); + ret =3D qemuDomainDetachNetDevice(driver, vm, match, async); break; case VIR_DOMAIN_DEVICE_HOSTDEV: - ret =3D qemuDomainDetachHostDevice(driver, vm, dev, async); - break; - case VIR_DOMAIN_DEVICE_CHR: - ret =3D qemuDomainDetachChrDevice(driver, vm, dev->data.chr, async= ); + ret =3D qemuDomainDetachHostDevice(driver, vm, match, async); break; case VIR_DOMAIN_DEVICE_RNG: - ret =3D qemuDomainDetachRNGDevice(driver, vm, dev->data.rng, async= ); + ret =3D qemuDomainDetachRNGDevice(driver, vm, match->data.rng, asy= nc); break; case VIR_DOMAIN_DEVICE_MEMORY: - ret =3D qemuDomainDetachMemoryDevice(driver, vm, dev->data.memory,= async); + ret =3D qemuDomainDetachMemoryDevice(driver, vm, match->data.memor= y, async); break; case VIR_DOMAIN_DEVICE_SHMEM: - ret =3D qemuDomainDetachShmemDevice(driver, vm, dev->data.shmem, a= sync); + ret =3D qemuDomainDetachShmemDevice(driver, vm, match->data.shmem,= async); break; case VIR_DOMAIN_DEVICE_WATCHDOG: - ret =3D qemuDomainDetachWatchdog(driver, vm, dev->data.watchdog, a= sync); + ret =3D qemuDomainDetachWatchdog(driver, vm, match->data.watchdog,= async); break; case VIR_DOMAIN_DEVICE_INPUT: - ret =3D qemuDomainDetachInputDevice(vm, dev->data.input, async); + ret =3D qemuDomainDetachInputDevice(vm, match->data.input, async); break; case VIR_DOMAIN_DEVICE_REDIRDEV: - ret =3D qemuDomainDetachRedirdevDevice(driver, vm, dev->data.redir= dev, async); + ret =3D qemuDomainDetachRedirdevDevice(driver, vm, match->data.red= irdev, async); break; =20 case VIR_DOMAIN_DEVICE_VSOCK: - ret =3D qemuDomainDetachVsockDevice(vm, dev->data.vsock, async); + ret =3D qemuDomainDetachVsockDevice(vm, match->data.vsock, async); break; =20 case VIR_DOMAIN_DEVICE_FS: @@ -6268,8 +6280,8 @@ qemuDomainDetachDeviceLive(virDomainObjPtr vm, case VIR_DOMAIN_DEVICE_LAST: virReportError(VIR_ERR_OPERATION_UNSUPPORTED, _("live detach of device '%s' is not supported"), - virDomainDeviceTypeToString(dev->type)); - break; + virDomainDeviceTypeToString(match->type)); + return -1; } =20 return ret; diff --git a/src/qemu/qemu_hotplug.h b/src/qemu/qemu_hotplug.h index 9980c2a756..78aa4e991b 100644 --- a/src/qemu/qemu_hotplug.h +++ b/src/qemu/qemu_hotplug.h @@ -115,7 +115,7 @@ int qemuDomainAttachRNGDevice(virQEMUDriverPtr driver, virDomainRNGDefPtr rng); =20 int qemuDomainDetachDeviceLive(virDomainObjPtr vm, - virDomainDeviceDefPtr dev, + virDomainDeviceDefPtr match, virQEMUDriverPtr driver, bool async); =20 --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Mar 28 20:57:44 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1553207374526147.58501475493233; Thu, 21 Mar 2019 15:29:34 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C6BF359473; Thu, 21 Mar 2019 22:29:32 +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 A3E9B4A4; Thu, 21 Mar 2019 22:29:32 +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 6224F181A00D; Thu, 21 Mar 2019 22:29:32 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x2LMTMLk015754 for ; Thu, 21 Mar 2019 18:29:22 -0400 Received: by smtp.corp.redhat.com (Postfix) id 885241001DE2; Thu, 21 Mar 2019 22:29:22 +0000 (UTC) Received: from vhost2.laine.org (ovpn-116-180.phx2.redhat.com [10.3.116.180]) by smtp.corp.redhat.com (Postfix) with ESMTP id 071161001DD3; Thu, 21 Mar 2019 22:29:21 +0000 (UTC) From: Laine Stump To: libvir-list@redhat.com Date: Thu, 21 Mar 2019 18:28:58 -0400 Message-Id: <20190321222901.12902-19-laine@laine.org> In-Reply-To: <20190321222901.12902-1-laine@laine.org> References: <20190321222901.12902-1-laine@laine.org> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Cc: Michal Privoznik , Peter Krempa Subject: [libvirt] [PATCH 18/21] qemu_hotplug: standardize the names/args/calling of qemuDomainDetach*() 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Thu, 21 Mar 2019 22:29:33 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Most of these functions will soon contain only some setup for detaching the device, not the detach code proper (since that code is identical for these devices). Their device specific functions are all being renamed to qemuDomainDetachPrep*(), where * is the name of that device's data member in the virDomainDeviceDef object. Since there will be other code in qemuDomainDetachDeviceLive() after the calls to qemuDomainDetachPrep*() that could still fail, we no longer directly set "ret" with the return code from qemuDomainDetachPrep*() functions, but simply return -1 on failure, and wait until the end of qemuDomainDetachDeviceLive() to set ret =3D 0. Two of the functions (for Lease and Chr) are atypical, and can't be easily consolidated with the others, so they are just being named qemuDomainDetachDevice*() to make it clearer that they perform the entire operation and not just some setup. Along with the rename, qemuDomainDetachPrep*() functions are also given similar arglists, including an arg called "match" that points to the proto-object of the device we want to delete, and another arg "detach" that is used to return a pointer to the actual object that will be (for now *has been*) detached. To make sure these new args aren't confused with existing local pointers that sometimes had the same name (detach), the local pointer to the device is now named after the device type ("controller", "disk", etc). These point to the same place as (*detach)->data.blah, it's just easier on the eyes to have, e.g., "disk->dst" rather than "(*detach)->data.disk-dst". Signed-off-by: Laine Stump --- src/qemu/qemu_hotplug.c | 363 +++++++++++++++++++++++----------------- 1 file changed, 205 insertions(+), 158 deletions(-) diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 903a0c46eb..b0e2c738b9 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -5390,27 +5390,28 @@ qemuFindDisk(virDomainDefPtr def, const char *dst) } =20 static int -qemuDomainDetachDeviceDiskLive(virQEMUDriverPtr driver, - virDomainObjPtr vm, - virDomainDeviceDefPtr dev, - bool async) +qemuDomainDetachPrepDisk(virQEMUDriverPtr driver, + virDomainObjPtr vm, + virDomainDiskDefPtr match, + virDomainDiskDefPtr *detach, + bool async) { - virDomainDiskDefPtr detach; + virDomainDiskDefPtr disk; int idx; int ret =3D -1; =20 - if ((idx =3D qemuFindDisk(vm->def, dev->data.disk->dst)) < 0) { + if ((idx =3D qemuFindDisk(vm->def, match->dst)) < 0) { virReportError(VIR_ERR_OPERATION_FAILED, - _("disk %s not found"), dev->data.disk->dst); + _("disk %s not found"), match->dst); return -1; } - detach =3D vm->def->disks[idx]; + *detach =3D disk =3D vm->def->disks[idx]; =20 - switch ((virDomainDiskDevice) detach->device) { + switch ((virDomainDiskDevice) disk->device) { case VIR_DOMAIN_DISK_DEVICE_DISK: case VIR_DOMAIN_DISK_DEVICE_LUN: =20 - switch ((virDomainDiskBus) detach->bus) { + switch ((virDomainDiskBus) disk->bus) { case VIR_DOMAIN_DISK_BUS_VIRTIO: case VIR_DOMAIN_DISK_BUS_USB: case VIR_DOMAIN_DISK_BUS_SCSI: @@ -5428,7 +5429,7 @@ qemuDomainDetachDeviceDiskLive(virQEMUDriverPtr drive= r, =20 case VIR_DOMAIN_DISK_BUS_LAST: default: - virReportEnumRangeError(virDomainDiskBus, detach->bus); + virReportEnumRangeError(virDomainDiskBus, disk->bus); return -1; } break; @@ -5437,32 +5438,32 @@ qemuDomainDetachDeviceDiskLive(virQEMUDriverPtr dri= ver, case VIR_DOMAIN_DISK_DEVICE_FLOPPY: virReportError(VIR_ERR_OPERATION_UNSUPPORTED, _("disk device type '%s' cannot be detached"), - virDomainDiskDeviceTypeToString(detach->device)); + virDomainDiskDeviceTypeToString(disk->device)); return -1; =20 case VIR_DOMAIN_DISK_DEVICE_LAST: default: - virReportEnumRangeError(virDomainDiskDevice, detach->device); + virReportEnumRangeError(virDomainDiskDevice, disk->device); break; } =20 - if (qemuDomainDiskBlockJobIsActive(detach)) + if (qemuDomainDiskBlockJobIsActive(disk)) return -1; =20 - if (detach->bus =3D=3D VIR_DOMAIN_DISK_BUS_VIRTIO && - qemuIsMultiFunctionDevice(vm->def, &detach->info)) { + if (disk->bus =3D=3D VIR_DOMAIN_DISK_BUS_VIRTIO && + qemuIsMultiFunctionDevice(vm->def, &disk->info)) { virReportError(VIR_ERR_OPERATION_FAILED, _("cannot hot unplug multifunction PCI device: %s"), - detach->dst); + disk->dst); return -1; } =20 if (!async) - qemuDomainMarkDeviceForRemoval(vm, &detach->info); + qemuDomainMarkDeviceForRemoval(vm, &disk->info); =20 - if (qemuDomainDeleteDevice(vm, detach->info.alias) < 0) { + if (qemuDomainDeleteDevice(vm, disk->info.alias) < 0) { if (virDomainObjIsActive(vm)) - virDomainAuditDisk(vm, detach->src, NULL, "detach", false); + virDomainAuditDisk(vm, disk->src, NULL, "detach", false); goto cleanup; } =20 @@ -5470,7 +5471,7 @@ qemuDomainDetachDeviceDiskLive(virQEMUDriverPtr drive= r, ret =3D 0; } else { if ((ret =3D qemuDomainWaitForDeviceRemoval(vm)) =3D=3D 1) - ret =3D qemuDomainRemoveDiskDevice(driver, vm, detach); + ret =3D qemuDomainRemoveDiskDevice(driver, vm, disk); } =20 cleanup: @@ -5541,57 +5542,55 @@ static bool qemuDomainControllerIsBusy(virDomainObj= Ptr vm, } =20 static int -qemuDomainDetachControllerDevice(virQEMUDriverPtr driver, - virDomainObjPtr vm, - virDomainDeviceDefPtr dev, - bool async) +qemuDomainDetachPrepController(virQEMUDriverPtr driver, + virDomainObjPtr vm, + virDomainControllerDefPtr match, + virDomainControllerDefPtr *detach, + bool async) { + virDomainControllerDefPtr controller; int idx, ret =3D -1; - virDomainControllerDefPtr detach =3D NULL; =20 - if (dev->data.controller->type !=3D VIR_DOMAIN_CONTROLLER_TYPE_SCSI) { + if (match->type !=3D VIR_DOMAIN_CONTROLLER_TYPE_SCSI) { virReportError(VIR_ERR_OPERATION_UNSUPPORTED, _("'%s' controller cannot be hot unplugged."), - virDomainControllerTypeToString(dev->data.controlle= r->type)); + virDomainControllerTypeToString(match->type)); return -1; } =20 - if ((idx =3D virDomainControllerFind(vm->def, - dev->data.controller->type, - dev->data.controller->idx)) < 0) { + if ((idx =3D virDomainControllerFind(vm->def, match->type, match->idx)= ) < 0) { virReportError(VIR_ERR_DEVICE_MISSING, _("controller %s:%d not found"), - virDomainControllerTypeToString(dev->data.controlle= r->type), - dev->data.controller->idx); + virDomainControllerTypeToString(match->type), + match->idx); goto cleanup; } =20 - detach =3D vm->def->controllers[idx]; + *detach =3D controller =3D vm->def->controllers[idx]; =20 - if (qemuDomainControllerIsBusy(vm, detach)) { + if (qemuDomainControllerIsBusy(vm, controller)) { virReportError(VIR_ERR_OPERATION_FAILED, "%s", _("device cannot be detached: device is busy")); goto cleanup; } =20 - if (qemuIsMultiFunctionDevice(vm->def, &detach->info)) { - virReportError(VIR_ERR_OPERATION_FAILED, - _("cannot hot unplug multifunction PCI device: %s"), - dev->data.disk->dst); + if (qemuIsMultiFunctionDevice(vm->def, &controller->info)) { + virReportError(VIR_ERR_OPERATION_FAILED, "%s", + _("cannot hot unplug multifunction PCI device")); goto cleanup; } =20 if (!async) - qemuDomainMarkDeviceForRemoval(vm, &detach->info); + qemuDomainMarkDeviceForRemoval(vm, &controller->info); =20 - if (qemuDomainDeleteDevice(vm, detach->info.alias) < 0) + if (qemuDomainDeleteDevice(vm, controller->info.alias) < 0) goto cleanup; =20 if (async) { ret =3D 0; } else { if ((ret =3D qemuDomainWaitForDeviceRemoval(vm)) =3D=3D 1) - ret =3D qemuDomainRemoveControllerDevice(driver, vm, detach); + ret =3D qemuDomainRemoveControllerDevice(driver, vm, controlle= r); } =20 cleanup: @@ -5603,29 +5602,30 @@ qemuDomainDetachControllerDevice(virQEMUDriverPtr d= river, =20 /* search for a hostdev matching dev and detach it */ static int -qemuDomainDetachHostDevice(virQEMUDriverPtr driver, - virDomainObjPtr vm, - virDomainDeviceDefPtr dev, - bool async) +qemuDomainDetachPrepHostdev(virQEMUDriverPtr driver, + virDomainObjPtr vm, + virDomainHostdevDefPtr match, + virDomainHostdevDefPtr *detach, + bool async) { - virDomainHostdevDefPtr hostdev =3D dev->data.hostdev; - virDomainHostdevSubsysPtr subsys =3D &hostdev->source.subsys; + virDomainHostdevSubsysPtr subsys =3D &match->source.subsys; virDomainHostdevSubsysUSBPtr usbsrc =3D &subsys->u.usb; virDomainHostdevSubsysPCIPtr pcisrc =3D &subsys->u.pci; virDomainHostdevSubsysSCSIPtr scsisrc =3D &subsys->u.scsi; virDomainHostdevSubsysMediatedDevPtr mdevsrc =3D &subsys->u.mdev; - virDomainHostdevDefPtr detach =3D NULL; + virDomainHostdevDefPtr hostdev; int idx; int ret =3D -1; =20 - if (hostdev->mode !=3D VIR_DOMAIN_HOSTDEV_MODE_SUBSYS) { + if (match->mode !=3D VIR_DOMAIN_HOSTDEV_MODE_SUBSYS) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("hot unplug is not supported for hostdev mode '%s= '"), - virDomainHostdevModeTypeToString(hostdev->mode)); + virDomainHostdevModeTypeToString(match->mode)); return -1; } =20 - idx =3D virDomainHostdevFind(vm->def, hostdev, &detach); + idx =3D virDomainHostdevFind(vm->def, match, &hostdev); + *detach =3D hostdev; =20 if (idx < 0) { switch (subsys->type) { @@ -5678,30 +5678,30 @@ qemuDomainDetachHostDevice(virQEMUDriverPtr driver, return -1; } =20 - if (qemuAssignDeviceHostdevAlias(vm->def, &detach->info->alias, -1) < = 0) + if (qemuAssignDeviceHostdevAlias(vm->def, &hostdev->info->alias, -1) <= 0) return -1; =20 - if (qemuIsMultiFunctionDevice(vm->def, detach->info)) { + if (qemuIsMultiFunctionDevice(vm->def, hostdev->info)) { virReportError(VIR_ERR_OPERATION_FAILED, _("cannot hot unplug multifunction PCI device with = guest address: " "%.4x:%.2x:%.2x.%.1x"), - detach->info->addr.pci.domain, detach->info->addr.p= ci.bus, - detach->info->addr.pci.slot, detach->info->addr.pci= .function); + hostdev->info->addr.pci.domain, hostdev->info->addr= .pci.bus, + hostdev->info->addr.pci.slot, hostdev->info->addr.p= ci.function); return -1; } =20 - if (!detach->info->alias) { + if (!hostdev->info->alias) { virReportError(VIR_ERR_OPERATION_FAILED, "%s", _("device cannot be detached without a device= alias")); return -1; } =20 if (!async) - qemuDomainMarkDeviceForRemoval(vm, detach->info); + qemuDomainMarkDeviceForRemoval(vm, hostdev->info); =20 - if (qemuDomainDeleteDevice(vm, detach->info->alias) < 0) { + if (qemuDomainDeleteDevice(vm, hostdev->info->alias) < 0) { if (virDomainObjIsActive(vm)) - virDomainAuditHostdev(vm, detach, "detach", false); + virDomainAuditHostdev(vm, hostdev, "detach", false); goto cleanup; } =20 @@ -5709,7 +5709,7 @@ qemuDomainDetachHostDevice(virQEMUDriverPtr driver, ret =3D 0; } else { if ((ret =3D qemuDomainWaitForDeviceRemoval(vm)) =3D=3D 1) - ret =3D qemuDomainRemoveHostDevice(driver, vm, detach); + ret =3D qemuDomainRemoveHostDevice(driver, vm, hostdev); } =20 cleanup: @@ -5722,24 +5722,25 @@ qemuDomainDetachHostDevice(virQEMUDriverPtr driver, =20 =20 static int -qemuDomainDetachShmemDevice(virQEMUDriverPtr driver, - virDomainObjPtr vm, - virDomainShmemDefPtr dev, - bool async) +qemuDomainDetachPrepShmem(virQEMUDriverPtr driver, + virDomainObjPtr vm, + virDomainShmemDefPtr match, + virDomainShmemDefPtr *detach, + bool async) { int ret =3D -1; ssize_t idx =3D -1; - virDomainShmemDefPtr shmem =3D NULL; + virDomainShmemDefPtr shmem; =20 - if ((idx =3D virDomainShmemDefFind(vm->def, dev)) < 0) { + if ((idx =3D virDomainShmemDefFind(vm->def, match)) < 0) { virReportError(VIR_ERR_DEVICE_MISSING, _("model '%s' shmem device not present " "in domain configuration"), - virDomainShmemModelTypeToString(dev->model)); + virDomainShmemModelTypeToString(match->model)); return -1; } =20 - shmem =3D vm->def->shmems[idx]; + *detach =3D shmem =3D vm->def->shmems[idx]; =20 switch ((virDomainShmemModel)shmem->model) { case VIR_DOMAIN_SHMEM_MODEL_IVSHMEM_PLAIN: @@ -5776,13 +5777,17 @@ qemuDomainDetachShmemDevice(virQEMUDriverPtr driver, =20 =20 static int -qemuDomainDetachWatchdog(virQEMUDriverPtr driver, - virDomainObjPtr vm, - virDomainWatchdogDefPtr dev, - bool async) +qemuDomainDetachPrepWatchdog(virQEMUDriverPtr driver, + virDomainObjPtr vm, + virDomainWatchdogDefPtr match, + virDomainWatchdogDefPtr *detach, + bool async) { int ret =3D -1; - virDomainWatchdogDefPtr watchdog =3D vm->def->watchdog; + virDomainWatchdogDefPtr watchdog; + + + *detach =3D watchdog =3D vm->def->watchdog; =20 if (!watchdog) { virReportError(VIR_ERR_DEVICE_MISSING, "%s", @@ -5793,9 +5798,9 @@ qemuDomainDetachWatchdog(virQEMUDriverPtr driver, /* While domains can have up to one watchdog, the one supplied by the = user * doesn't necessarily match the one domain has. Refuse to detach in s= uch * case. */ - if (!(watchdog->model =3D=3D dev->model && - watchdog->action =3D=3D dev->action && - virDomainDeviceInfoAddressIsEqual(&dev->info, &watchdog->info)))= { + if (!(watchdog->model =3D=3D match->model && + watchdog->action =3D=3D match->action && + virDomainDeviceInfoAddressIsEqual(&match->info, &watchdog->info)= )) { virReportError(VIR_ERR_DEVICE_MISSING, _("model '%s' watchdog device not present " "in domain configuration"), @@ -5831,40 +5836,41 @@ qemuDomainDetachWatchdog(virQEMUDriverPtr driver, =20 =20 static int -qemuDomainDetachRedirdevDevice(virQEMUDriverPtr driver, - virDomainObjPtr vm, - virDomainRedirdevDefPtr dev, - bool async) +qemuDomainDetachPrepRedirdev(virQEMUDriverPtr driver, + virDomainObjPtr vm, + virDomainRedirdevDefPtr match, + virDomainRedirdevDefPtr *detach, + bool async) { int ret =3D -1; - virDomainRedirdevDefPtr tmpRedirdevDef; + virDomainRedirdevDefPtr redirdev; ssize_t idx; =20 - if ((idx =3D virDomainRedirdevDefFind(vm->def, dev)) < 0) { + if ((idx =3D virDomainRedirdevDefFind(vm->def, match)) < 0) { virReportError(VIR_ERR_OPERATION_INVALID, "%s", _("no matching redirdev was not found")); return -1; } =20 - tmpRedirdevDef =3D vm->def->redirdevs[idx]; + *detach =3D redirdev =3D vm->def->redirdevs[idx]; =20 - if (!tmpRedirdevDef->info.alias) { + if (!redirdev->info.alias) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("alias not set for redirdev device")); return -1; } =20 if (!async) - qemuDomainMarkDeviceForRemoval(vm, &tmpRedirdevDef->info); + qemuDomainMarkDeviceForRemoval(vm, &redirdev->info); =20 - if (qemuDomainDeleteDevice(vm, tmpRedirdevDef->info.alias) < 0) + if (qemuDomainDeleteDevice(vm, redirdev->info.alias) < 0) goto cleanup; =20 if (async) { ret =3D 0; } else { if ((ret =3D qemuDomainWaitForDeviceRemoval(vm)) =3D=3D 1) - ret =3D qemuDomainRemoveRedirdevDevice(driver, vm, tmpRedirdev= Def); + ret =3D qemuDomainRemoveRedirdevDevice(driver, vm, redirdev); } =20 cleanup: @@ -5875,53 +5881,54 @@ qemuDomainDetachRedirdevDevice(virQEMUDriverPtr dri= ver, =20 =20 static int -qemuDomainDetachNetDevice(virQEMUDriverPtr driver, - virDomainObjPtr vm, - virDomainDeviceDefPtr dev, - bool async) +qemuDomainDetachPrepNet(virQEMUDriverPtr driver, + virDomainObjPtr vm, + virDomainNetDefPtr match, + virDomainNetDefPtr *detach, + bool async) { int detachidx, ret =3D -1; - virDomainNetDefPtr detach =3D NULL; + virDomainNetDefPtr net; =20 - if ((detachidx =3D virDomainNetFindIdx(vm->def, dev->data.net)) < 0) + if ((detachidx =3D virDomainNetFindIdx(vm->def, match)) < 0) goto cleanup; =20 - detach =3D vm->def->nets[detachidx]; + *detach =3D net =3D vm->def->nets[detachidx]; =20 - if (qemuIsMultiFunctionDevice(vm->def, &detach->info)) { + if (qemuIsMultiFunctionDevice(vm->def, &net->info)) { virReportError(VIR_ERR_OPERATION_FAILED, _("cannot hot unplug multifunction PCI device: %s"), - detach->ifname); + net->ifname); goto cleanup; } =20 - if (!detach->info.alias) { - if (qemuAssignDeviceNetAlias(vm->def, detach, -1) < 0) + if (!net->info.alias) { + if (qemuAssignDeviceNetAlias(vm->def, net, -1) < 0) goto cleanup; } =20 - if (virDomainNetGetActualBandwidth(detach) && - virNetDevSupportBandwidth(virDomainNetGetActualType(detach)) && - virNetDevBandwidthClear(detach->ifname) < 0) + if (virDomainNetGetActualBandwidth(net) && + virNetDevSupportBandwidth(virDomainNetGetActualType(net)) && + virNetDevBandwidthClear(net->ifname) < 0) VIR_WARN("cannot clear bandwidth setting for device : %s", - detach->ifname); + net->ifname); =20 /* deactivate the tap/macvtap device on the host, which could also * affect the parent device (e.g. macvtap passthrough mode sets * the parent device offline) */ - ignore_value(qemuInterfaceStopDevice(detach)); + ignore_value(qemuInterfaceStopDevice(net)); =20 if (!async) - qemuDomainMarkDeviceForRemoval(vm, &detach->info); + qemuDomainMarkDeviceForRemoval(vm, &net->info); =20 - if (qemuDomainDeleteDevice(vm, detach->info.alias) < 0) { + if (qemuDomainDeleteDevice(vm, net->info.alias) < 0) { if (virDomainObjIsActive(vm)) { /* the audit message has a different format for hostdev networ= k devices */ - if (virDomainNetGetActualType(detach) =3D=3D VIR_DOMAIN_NET_TY= PE_HOSTDEV) - virDomainAuditHostdev(vm, virDomainNetGetActualHostdev(det= ach), "detach", false); + if (virDomainNetGetActualType(net) =3D=3D VIR_DOMAIN_NET_TYPE_= HOSTDEV) + virDomainAuditHostdev(vm, virDomainNetGetActualHostdev(net= ), "detach", false); else - virDomainAuditNet(vm, detach, NULL, "detach", false); + virDomainAuditNet(vm, net, NULL, "detach", false); } goto cleanup; } @@ -5930,7 +5937,7 @@ qemuDomainDetachNetDevice(virQEMUDriverPtr driver, ret =3D 0; } else { if ((ret =3D qemuDomainWaitForDeviceRemoval(vm)) =3D=3D 1) - ret =3D qemuDomainRemoveNetDevice(driver, vm, detach); + ret =3D qemuDomainRemoveNetDevice(driver, vm, net); } =20 cleanup: @@ -5941,7 +5948,7 @@ qemuDomainDetachNetDevice(virQEMUDriverPtr driver, =20 =20 static int -qemuDomainDetachChrDevice(virQEMUDriverPtr driver, +qemuDomainDetachDeviceChr(virQEMUDriverPtr driver, virDomainObjPtr vm, virDomainChrDefPtr chr, bool async) @@ -5999,42 +6006,43 @@ qemuDomainDetachChrDevice(virQEMUDriverPtr driver, =20 =20 static int -qemuDomainDetachRNGDevice(virQEMUDriverPtr driver, - virDomainObjPtr vm, - virDomainRNGDefPtr rng, - bool async) +qemuDomainDetachPrepRNG(virQEMUDriverPtr driver, + virDomainObjPtr vm, + virDomainRNGDefPtr match, + virDomainRNGDefPtr *detach, + bool async) { ssize_t idx; - virDomainRNGDefPtr tmpRNG; + virDomainRNGDefPtr rng; int ret =3D -1; =20 - if ((idx =3D virDomainRNGFind(vm->def, rng)) < 0) { + if ((idx =3D virDomainRNGFind(vm->def, match)) < 0) { virReportError(VIR_ERR_DEVICE_MISSING, _("model '%s' RNG device not present " "in domain configuration"), - virDomainRNGBackendTypeToString(rng->model)); + virDomainRNGBackendTypeToString(match->model)); return -1; } =20 - tmpRNG =3D vm->def->rngs[idx]; + *detach =3D rng =3D vm->def->rngs[idx]; =20 - if (!tmpRNG->info.alias) { + if (!rng->info.alias) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("alias not set for RNG device")); return -1; } =20 if (!async) - qemuDomainMarkDeviceForRemoval(vm, &tmpRNG->info); + qemuDomainMarkDeviceForRemoval(vm, &rng->info); =20 - if (qemuDomainDeleteDevice(vm, tmpRNG->info.alias) < 0) + if (qemuDomainDeleteDevice(vm, rng->info.alias) < 0) goto cleanup; =20 if (async) { ret =3D 0; } else { if ((ret =3D qemuDomainWaitForDeviceRemoval(vm)) =3D=3D 1) - ret =3D qemuDomainRemoveRNGDevice(driver, vm, tmpRNG); + ret =3D qemuDomainRemoveRNGDevice(driver, vm, rng); } =20 cleanup: @@ -6045,26 +6053,27 @@ qemuDomainDetachRNGDevice(virQEMUDriverPtr driver, =20 =20 static int -qemuDomainDetachMemoryDevice(virQEMUDriverPtr driver, - virDomainObjPtr vm, - virDomainMemoryDefPtr memdef, - bool async) +qemuDomainDetachPrepMemory(virQEMUDriverPtr driver, + virDomainObjPtr vm, + virDomainMemoryDefPtr match, + virDomainMemoryDefPtr *detach, + bool async) { virDomainMemoryDefPtr mem; int idx; int ret =3D -1; =20 - qemuDomainMemoryDeviceAlignSize(vm->def, memdef); + qemuDomainMemoryDeviceAlignSize(vm->def, match); =20 - if ((idx =3D virDomainMemoryFindByDef(vm->def, memdef)) < 0) { + if ((idx =3D virDomainMemoryFindByDef(vm->def, match)) < 0) { virReportError(VIR_ERR_DEVICE_MISSING, _("model '%s' memory device not present " "in the domain configuration"), - virDomainMemoryModelTypeToString(memdef->model)); + virDomainMemoryModelTypeToString(match->model)); return -1; } =20 - mem =3D vm->def->mems[idx]; + *detach =3D mem =3D vm->def->mems[idx]; =20 if (!mem->info.alias) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", @@ -6093,20 +6102,21 @@ qemuDomainDetachMemoryDevice(virQEMUDriverPtr drive= r, =20 =20 static int -qemuDomainDetachInputDevice(virDomainObjPtr vm, - virDomainInputDefPtr def, - bool async) +qemuDomainDetachPrepInput(virDomainObjPtr vm, + virDomainInputDefPtr match, + virDomainInputDefPtr *detach, + bool async) { virDomainInputDefPtr input; int ret =3D -1; int idx; =20 - if ((idx =3D virDomainInputDefFind(vm->def, def)) < 0) { + if ((idx =3D virDomainInputDefFind(vm->def, match)) < 0) { virReportError(VIR_ERR_OPERATION_FAILED, "%s", _("matching input device not found")); return -1; } - input =3D vm->def->inputs[idx]; + *detach =3D input =3D vm->def->inputs[idx]; =20 switch ((virDomainInputBus) input->bus) { case VIR_DOMAIN_INPUT_BUS_PS2: @@ -6144,16 +6154,18 @@ qemuDomainDetachInputDevice(virDomainObjPtr vm, =20 =20 static int -qemuDomainDetachVsockDevice(virDomainObjPtr vm, - virDomainVsockDefPtr dev, - bool async) +qemuDomainDetachPrepVsock(virDomainObjPtr vm, + virDomainVsockDefPtr match, + virDomainVsockDefPtr *detach, + bool async) { - virDomainVsockDefPtr vsock =3D vm->def->vsock; + virDomainVsockDefPtr vsock; int ret =3D -1; =20 =20 + *detach =3D vsock =3D vm->def->vsock; if (!vsock || - !virDomainVsockDefEquals(dev, vsock)) { + !virDomainVsockDefEquals(match, vsock)) { virReportError(VIR_ERR_OPERATION_FAILED, "%s", _("matching vsock device not found")); return -1; @@ -6180,9 +6192,9 @@ qemuDomainDetachVsockDevice(virDomainObjPtr vm, =20 =20 static int -qemuDomainDetachLease(virQEMUDriverPtr driver, - virDomainObjPtr vm, - virDomainLeaseDefPtr lease) +qemuDomainDetachDeviceLease(virQEMUDriverPtr driver, + virDomainObjPtr vm, + virDomainLeaseDefPtr lease) { virDomainLeaseDefPtr det_lease; int idx; @@ -6209,6 +6221,7 @@ qemuDomainDetachDeviceLive(virDomainObjPtr vm, virQEMUDriverPtr driver, bool async) { + virDomainDeviceDef detach =3D { .type =3D match->type }; int ret =3D -1; =20 switch ((virDomainDeviceType)match->type) { @@ -6218,10 +6231,10 @@ qemuDomainDetachDeviceLive(virDomainObjPtr vm, * Detach functions. */ case VIR_DOMAIN_DEVICE_LEASE: - return qemuDomainDetachLease(driver, vm, match->data.lease); + return qemuDomainDetachDeviceLease(driver, vm, match->data.lease); =20 case VIR_DOMAIN_DEVICE_CHR: - return qemuDomainDetachChrDevice(driver, vm, match->data.chr, asyn= c); + return qemuDomainDetachDeviceChr(driver, vm, match->data.chr, asyn= c); =20 /* * All the other device types follow a very similar pattern - @@ -6231,38 +6244,70 @@ qemuDomainDetachDeviceLive(virDomainObjPtr vm, * is okay to detach the device. */ case VIR_DOMAIN_DEVICE_DISK: - ret =3D qemuDomainDetachDeviceDiskLive(driver, vm, match, async); + if (qemuDomainDetachPrepDisk(driver, vm, match->data.disk, + &detach.data.disk, async) < 0) { + return -1; + } break; case VIR_DOMAIN_DEVICE_CONTROLLER: - ret =3D qemuDomainDetachControllerDevice(driver, vm, match, async); + if (qemuDomainDetachPrepController(driver, vm, match->data.control= ler, + &detach.data.controller, async)= < 0) { + return -1; + } break; case VIR_DOMAIN_DEVICE_NET: - ret =3D qemuDomainDetachNetDevice(driver, vm, match, async); + if (qemuDomainDetachPrepNet(driver, vm, match->data.net, + &detach.data.net, async) < 0) { + return -1; + } break; case VIR_DOMAIN_DEVICE_HOSTDEV: - ret =3D qemuDomainDetachHostDevice(driver, vm, match, async); + if (qemuDomainDetachPrepHostdev(driver, vm, match->data.hostdev, + &detach.data.hostdev, async) < 0) { + return -1; + } break; case VIR_DOMAIN_DEVICE_RNG: - ret =3D qemuDomainDetachRNGDevice(driver, vm, match->data.rng, asy= nc); + if (qemuDomainDetachPrepRNG(driver, vm, match->data.rng, + &detach.data.rng, async) < 0) { + return -1; + } break; case VIR_DOMAIN_DEVICE_MEMORY: - ret =3D qemuDomainDetachMemoryDevice(driver, vm, match->data.memor= y, async); + if (qemuDomainDetachPrepMemory(driver, vm, match->data.memory, + &detach.data.memory, async) < 0) { + return -1; + } break; case VIR_DOMAIN_DEVICE_SHMEM: - ret =3D qemuDomainDetachShmemDevice(driver, vm, match->data.shmem,= async); + if (qemuDomainDetachPrepShmem(driver, vm, match->data.shmem, + &detach.data.shmem, async) < 0) { + return -1; + } break; case VIR_DOMAIN_DEVICE_WATCHDOG: - ret =3D qemuDomainDetachWatchdog(driver, vm, match->data.watchdog,= async); + if (qemuDomainDetachPrepWatchdog(driver, vm, match->data.watchdog, + &detach.data.watchdog, async) < 0= ) { + return -1; + } break; case VIR_DOMAIN_DEVICE_INPUT: - ret =3D qemuDomainDetachInputDevice(vm, match->data.input, async); + if (qemuDomainDetachPrepInput(vm, match->data.input, + &detach.data.input, async) < 0) { + return -1; + } break; case VIR_DOMAIN_DEVICE_REDIRDEV: - ret =3D qemuDomainDetachRedirdevDevice(driver, vm, match->data.red= irdev, async); + if (qemuDomainDetachPrepRedirdev(driver, vm, match->data.redirdev, + &detach.data.redirdev, async) < 0= ) { + return -1; + } break; - case VIR_DOMAIN_DEVICE_VSOCK: - ret =3D qemuDomainDetachVsockDevice(vm, match->data.vsock, async); + if (qemuDomainDetachPrepVsock(vm, match->data.vsock, + &detach.data.vsock, async) < 0) { + return -1; + } break; =20 case VIR_DOMAIN_DEVICE_FS: @@ -6284,6 +6329,8 @@ qemuDomainDetachDeviceLive(virDomainObjPtr vm, return -1; } =20 + ret =3D 0; + return ret; } =20 --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Mar 28 20:57:44 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1553207418713164.466372192192; Thu, 21 Mar 2019 15:30:18 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 8B1A930BC67E; Thu, 21 Mar 2019 22:30:15 +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 5162F60BFB; Thu, 21 Mar 2019 22:30:15 +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 F26AF181A867; Thu, 21 Mar 2019 22:30:14 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x2LMTNuY015765 for ; Thu, 21 Mar 2019 18:29:23 -0400 Received: by smtp.corp.redhat.com (Postfix) id 26E711001DE2; Thu, 21 Mar 2019 22:29:23 +0000 (UTC) Received: from vhost2.laine.org (ovpn-116-180.phx2.redhat.com [10.3.116.180]) by smtp.corp.redhat.com (Postfix) with ESMTP id B14BE1001DDB; Thu, 21 Mar 2019 22:29:22 +0000 (UTC) From: Laine Stump To: libvir-list@redhat.com Date: Thu, 21 Mar 2019 18:28:59 -0400 Message-Id: <20190321222901.12902-20-laine@laine.org> In-Reply-To: <20190321222901.12902-1-laine@laine.org> References: <20190321222901.12902-1-laine@laine.org> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Cc: Michal Privoznik , Peter Krempa Subject: [libvirt] [PATCH 19/21] qemu_hotplug: new function qemuDomainRemoveAuditDevice() 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Thu, 21 Mar 2019 22:30:17 +0000 (UTC) Content-Type: text/plain; charset="utf-8" This function can be called with a virDomainDevicePtr and whether or not the removal was successful, and it will call the appropriate virDomainAudit*() function with the appropriate args for whatever type of device it's given (or do nothing, if that's appropriate). This permits generalizing some code that currently has a separate copy for each type of device. Signed-off-by: Laine Stump --- src/qemu/qemu_hotplug.c | 72 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index b0e2c738b9..5e5ffe16d3 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -5208,6 +5208,78 @@ qemuDomainRemoveRedirdevDevice(virQEMUDriverPtr driv= er, } =20 =20 +static inline void +qemuDomainRemoveAuditDevice(virDomainObjPtr vm, + virDomainDeviceDefPtr detach, + bool success) +{ + switch ((virDomainDeviceType)detach->type) { + case VIR_DOMAIN_DEVICE_CHR: + virDomainAuditChardev(vm, detach->data.chr, NULL, "detach", succes= s); + break; + + case VIR_DOMAIN_DEVICE_DISK: + virDomainAuditDisk(vm, detach->data.disk->src, NULL, "detach", suc= cess); + break; + + case VIR_DOMAIN_DEVICE_NET: + virDomainAuditNet(vm, detach->data.net, NULL, "detach", success); + break; + + case VIR_DOMAIN_DEVICE_HOSTDEV: + virDomainAuditHostdev(vm, detach->data.hostdev, "detach", success); + break; + + case VIR_DOMAIN_DEVICE_RNG: + virDomainAuditRNG(vm, detach->data.rng, NULL, "detach", success); + break; + + case VIR_DOMAIN_DEVICE_MEMORY: { + unsigned long long oldmem =3D virDomainDefGetMemoryTotal(vm->def); + unsigned long long newmem =3D oldmem - detach->data.memory->size; + + virDomainAuditMemory(vm, oldmem, newmem, "update", success); + break; + } + + case VIR_DOMAIN_DEVICE_SHMEM: + virDomainAuditShmem(vm, detach->data.shmem, "detach", success); + break; + + case VIR_DOMAIN_DEVICE_INPUT: + virDomainAuditInput(vm, detach->data.input, "detach", success); + break; + + case VIR_DOMAIN_DEVICE_REDIRDEV: + virDomainAuditRedirdev(vm, detach->data.redirdev, "detach", succes= s); + break; + + case VIR_DOMAIN_DEVICE_LEASE: + case VIR_DOMAIN_DEVICE_CONTROLLER: + case VIR_DOMAIN_DEVICE_WATCHDOG: + case VIR_DOMAIN_DEVICE_VSOCK: + /* These devices don't have associated audit logs */ + break; + + case VIR_DOMAIN_DEVICE_FS: + case VIR_DOMAIN_DEVICE_SOUND: + case VIR_DOMAIN_DEVICE_VIDEO: + case VIR_DOMAIN_DEVICE_GRAPHICS: + case VIR_DOMAIN_DEVICE_HUB: + case VIR_DOMAIN_DEVICE_SMARTCARD: + case VIR_DOMAIN_DEVICE_MEMBALLOON: + case VIR_DOMAIN_DEVICE_NVRAM: + case VIR_DOMAIN_DEVICE_NONE: + case VIR_DOMAIN_DEVICE_TPM: + case VIR_DOMAIN_DEVICE_PANIC: + case VIR_DOMAIN_DEVICE_IOMMU: + case VIR_DOMAIN_DEVICE_LAST: + /* these will never happen, these devices can't be unplugged */ + break; + } +} + + int qemuDomainRemoveDevice(virQEMUDriverPtr driver, virDomainObjPtr vm, --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Mar 28 20:57:44 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1553207378071852.9149602742533; Thu, 21 Mar 2019 15:29:38 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6F414C04FFF0; Thu, 21 Mar 2019 22:29:36 +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 471B3608AA; Thu, 21 Mar 2019 22:29:36 +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 F12963FA45; Thu, 21 Mar 2019 22:29:35 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x2LMTP5i015777 for ; Thu, 21 Mar 2019 18:29:25 -0400 Received: by smtp.corp.redhat.com (Postfix) id C66B71001DE4; Thu, 21 Mar 2019 22:29:25 +0000 (UTC) Received: from vhost2.laine.org (ovpn-116-180.phx2.redhat.com [10.3.116.180]) by smtp.corp.redhat.com (Postfix) with ESMTP id 580811001DD3; Thu, 21 Mar 2019 22:29:23 +0000 (UTC) From: Laine Stump To: libvir-list@redhat.com Date: Thu, 21 Mar 2019 18:29:00 -0400 Message-Id: <20190321222901.12902-21-laine@laine.org> In-Reply-To: <20190321222901.12902-1-laine@laine.org> References: <20190321222901.12902-1-laine@laine.org> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Cc: Michal Privoznik , Peter Krempa Subject: [libvirt] [PATCH 20/21] qemu_hotplug: consolidate all common detach code in qemuDomainDetachDeviceLive 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Thu, 21 Mar 2019 22:29:37 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Now that all the qemuDomainDetachPrep*() functions look nearly identical at the end, we can put one copy of that identical code in qemuDomainDetachDeviceLive() at the point after the individual prep functions have been called, and remove the duplicated code from all the prep functions. The code to locate the target "detach" device based on the "match" device remains, as do all device-type-specific validations. Unfortunately there are a few things going on at once in this patch, which makes it a bit more difficult to follow than the others; it was just impossible to do the changes in stages and still have a buildable/testable tree at each step. The other changes of note: * The individual prep functions no longer need their driver or async args, so those are removed, as are the local "ret" variables, since in all cases the functions just directly return -1 or 0. * Some of the prep functions were checking for a valid alias and/or for attempts to detach a multifunction PCI device, but not all. In fact, both checks are valid (or at least harmless) for *all* device types, so they are removed from the prep functions, and done a single time in the common function. (any attempts to *create* an alias when there isn't one has been removed, since that is doomed to failure anyway; the only way the device wouldn't have an alias is if 1) the domain was created by calling virsh qemu-attach to attach an existing qemu process to libvirt, and 2) the qemu command that started said process used "old style" arguments for creating devices that didn't have any device ids. Even if we constructed a device id for one of these devices, qemu wouldn't recognize it in the device_del command anyway, so we may as well fail earlier with "device missing alias" rather than failing later with "couldn't delete device net0".) * Only one type of device has shutdown code that must not be called until after *all* validation of the device is done (including checking for multifunction PCI and valid alias, which is done in the toplevel common code). For this reason, the Net function has been split in two, with the 2nd half (qemuDomainDetachShutdownNet()) called from the common function, right before sending the delete command to qemu. Signed-off-by: Laine Stump --- src/qemu/qemu_hotplug.c | 497 ++++++++++++---------------------------- 1 file changed, 149 insertions(+), 348 deletions(-) diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 5e5ffe16d3..de7a7a2c95 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -5208,7 +5208,7 @@ qemuDomainRemoveRedirdevDevice(virQEMUDriverPtr drive= r, } =20 =20 -static inline void +static void qemuDomainRemoveAuditDevice(virDomainObjPtr vm, virDomainDeviceDefPtr detach, bool success) @@ -5462,15 +5462,12 @@ qemuFindDisk(virDomainDefPtr def, const char *dst) } =20 static int -qemuDomainDetachPrepDisk(virQEMUDriverPtr driver, - virDomainObjPtr vm, +qemuDomainDetachPrepDisk(virDomainObjPtr vm, virDomainDiskDefPtr match, - virDomainDiskDefPtr *detach, - bool async) + virDomainDiskDefPtr *detach) { virDomainDiskDefPtr disk; int idx; - int ret =3D -1; =20 if ((idx =3D qemuFindDisk(vm->def, match->dst)) < 0) { virReportError(VIR_ERR_OPERATION_FAILED, @@ -5522,34 +5519,7 @@ qemuDomainDetachPrepDisk(virQEMUDriverPtr driver, if (qemuDomainDiskBlockJobIsActive(disk)) return -1; =20 - if (disk->bus =3D=3D VIR_DOMAIN_DISK_BUS_VIRTIO && - qemuIsMultiFunctionDevice(vm->def, &disk->info)) { - virReportError(VIR_ERR_OPERATION_FAILED, - _("cannot hot unplug multifunction PCI device: %s"), - disk->dst); - return -1; - } - - if (!async) - qemuDomainMarkDeviceForRemoval(vm, &disk->info); - - if (qemuDomainDeleteDevice(vm, disk->info.alias) < 0) { - if (virDomainObjIsActive(vm)) - virDomainAuditDisk(vm, disk->src, NULL, "detach", false); - goto cleanup; - } - - if (async) { - ret =3D 0; - } else { - if ((ret =3D qemuDomainWaitForDeviceRemoval(vm)) =3D=3D 1) - ret =3D qemuDomainRemoveDiskDevice(driver, vm, disk); - } - - cleanup: - if (!async) - qemuDomainResetDeviceRemoval(vm); - return ret; + return 0; } =20 =20 @@ -5614,14 +5584,12 @@ static bool qemuDomainControllerIsBusy(virDomainObj= Ptr vm, } =20 static int -qemuDomainDetachPrepController(virQEMUDriverPtr driver, - virDomainObjPtr vm, +qemuDomainDetachPrepController(virDomainObjPtr vm, virDomainControllerDefPtr match, - virDomainControllerDefPtr *detach, - bool async) + virDomainControllerDefPtr *detach) { virDomainControllerDefPtr controller; - int idx, ret =3D -1; + int idx; =20 if (match->type !=3D VIR_DOMAIN_CONTROLLER_TYPE_SCSI) { virReportError(VIR_ERR_OPERATION_UNSUPPORTED, @@ -5635,7 +5603,7 @@ qemuDomainDetachPrepController(virQEMUDriverPtr drive= r, _("controller %s:%d not found"), virDomainControllerTypeToString(match->type), match->idx); - goto cleanup; + return -1; } =20 *detach =3D controller =3D vm->def->controllers[idx]; @@ -5643,42 +5611,18 @@ qemuDomainDetachPrepController(virQEMUDriverPtr dri= ver, if (qemuDomainControllerIsBusy(vm, controller)) { virReportError(VIR_ERR_OPERATION_FAILED, "%s", _("device cannot be detached: device is busy")); - goto cleanup; - } - - if (qemuIsMultiFunctionDevice(vm->def, &controller->info)) { - virReportError(VIR_ERR_OPERATION_FAILED, "%s", - _("cannot hot unplug multifunction PCI device")); - goto cleanup; - } - - if (!async) - qemuDomainMarkDeviceForRemoval(vm, &controller->info); - - if (qemuDomainDeleteDevice(vm, controller->info.alias) < 0) - goto cleanup; - - if (async) { - ret =3D 0; - } else { - if ((ret =3D qemuDomainWaitForDeviceRemoval(vm)) =3D=3D 1) - ret =3D qemuDomainRemoveControllerDevice(driver, vm, controlle= r); + return -1; } =20 - cleanup: - if (!async) - qemuDomainResetDeviceRemoval(vm); - return ret; + return 0; } =20 =20 /* search for a hostdev matching dev and detach it */ static int -qemuDomainDetachPrepHostdev(virQEMUDriverPtr driver, - virDomainObjPtr vm, +qemuDomainDetachPrepHostdev(virDomainObjPtr vm, virDomainHostdevDefPtr match, - virDomainHostdevDefPtr *detach, - bool async) + virDomainHostdevDefPtr *detach) { virDomainHostdevSubsysPtr subsys =3D &match->source.subsys; virDomainHostdevSubsysUSBPtr usbsrc =3D &subsys->u.usb; @@ -5687,7 +5631,6 @@ qemuDomainDetachPrepHostdev(virQEMUDriverPtr driver, virDomainHostdevSubsysMediatedDevPtr mdevsrc =3D &subsys->u.mdev; virDomainHostdevDefPtr hostdev; int idx; - int ret =3D -1; =20 if (match->mode !=3D VIR_DOMAIN_HOSTDEV_MODE_SUBSYS) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, @@ -5750,58 +5693,16 @@ qemuDomainDetachPrepHostdev(virQEMUDriverPtr driver, return -1; } =20 - if (qemuAssignDeviceHostdevAlias(vm->def, &hostdev->info->alias, -1) <= 0) - return -1; - - if (qemuIsMultiFunctionDevice(vm->def, hostdev->info)) { - virReportError(VIR_ERR_OPERATION_FAILED, - _("cannot hot unplug multifunction PCI device with = guest address: " - "%.4x:%.2x:%.2x.%.1x"), - hostdev->info->addr.pci.domain, hostdev->info->addr= .pci.bus, - hostdev->info->addr.pci.slot, hostdev->info->addr.p= ci.function); - return -1; - } - - if (!hostdev->info->alias) { - virReportError(VIR_ERR_OPERATION_FAILED, - "%s", _("device cannot be detached without a device= alias")); - return -1; - } - - if (!async) - qemuDomainMarkDeviceForRemoval(vm, hostdev->info); - - if (qemuDomainDeleteDevice(vm, hostdev->info->alias) < 0) { - if (virDomainObjIsActive(vm)) - virDomainAuditHostdev(vm, hostdev, "detach", false); - goto cleanup; - } - - if (async) { - ret =3D 0; - } else { - if ((ret =3D qemuDomainWaitForDeviceRemoval(vm)) =3D=3D 1) - ret =3D qemuDomainRemoveHostDevice(driver, vm, hostdev); - } - - cleanup: - if (!async) - qemuDomainResetDeviceRemoval(vm); - - return ret; - + return 0; } =20 =20 static int -qemuDomainDetachPrepShmem(virQEMUDriverPtr driver, - virDomainObjPtr vm, +qemuDomainDetachPrepShmem(virDomainObjPtr vm, virDomainShmemDefPtr match, - virDomainShmemDefPtr *detach, - bool async) + virDomainShmemDefPtr *detach) { - int ret =3D -1; - ssize_t idx =3D -1; + ssize_t idx; virDomainShmemDefPtr shmem; =20 if ((idx =3D virDomainShmemDefFind(vm->def, match)) < 0) { @@ -5828,34 +5729,15 @@ qemuDomainDetachPrepShmem(virQEMUDriverPtr driver, return -1; } =20 - if (!async) - qemuDomainMarkDeviceForRemoval(vm, &shmem->info); - - if (qemuDomainDeleteDevice(vm, shmem->info.alias) < 0) - goto cleanup; - - if (async) { - ret =3D 0; - } else { - if ((ret =3D qemuDomainWaitForDeviceRemoval(vm)) =3D=3D 1) - ret =3D qemuDomainRemoveShmemDevice(driver, vm, shmem); - } - - cleanup: - if (!async) - qemuDomainResetDeviceRemoval(vm); - return ret; + return 0; } =20 =20 static int -qemuDomainDetachPrepWatchdog(virQEMUDriverPtr driver, - virDomainObjPtr vm, +qemuDomainDetachPrepWatchdog(virDomainObjPtr vm, virDomainWatchdogDefPtr match, - virDomainWatchdogDefPtr *detach, - bool async) + virDomainWatchdogDefPtr *detach) { - int ret =3D -1; virDomainWatchdogDefPtr watchdog; =20 =20 @@ -5887,34 +5769,15 @@ qemuDomainDetachPrepWatchdog(virQEMUDriverPtr drive= r, return -1; } =20 - if (!async) - qemuDomainMarkDeviceForRemoval(vm, &watchdog->info); - - if (qemuDomainDeleteDevice(vm, watchdog->info.alias) < 0) - goto cleanup; - - if (async) { - ret =3D 0; - } else { - if ((ret =3D qemuDomainWaitForDeviceRemoval(vm)) =3D=3D 1) - ret =3D qemuDomainRemoveWatchdog(driver, vm, watchdog); - } - - cleanup: - if (!async) - qemuDomainResetDeviceRemoval(vm); - return ret; + return 0; } =20 =20 static int -qemuDomainDetachPrepRedirdev(virQEMUDriverPtr driver, - virDomainObjPtr vm, +qemuDomainDetachPrepRedirdev(virDomainObjPtr vm, virDomainRedirdevDefPtr match, - virDomainRedirdevDefPtr *detach, - bool async) + virDomainRedirdevDefPtr *detach) { - int ret =3D -1; virDomainRedirdevDefPtr redirdev; ssize_t idx; =20 @@ -5926,59 +5789,41 @@ qemuDomainDetachPrepRedirdev(virQEMUDriverPtr drive= r, =20 *detach =3D redirdev =3D vm->def->redirdevs[idx]; =20 - if (!redirdev->info.alias) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("alias not set for redirdev device")); - return -1; - } - - if (!async) - qemuDomainMarkDeviceForRemoval(vm, &redirdev->info); - - if (qemuDomainDeleteDevice(vm, redirdev->info.alias) < 0) - goto cleanup; - - if (async) { - ret =3D 0; - } else { - if ((ret =3D qemuDomainWaitForDeviceRemoval(vm)) =3D=3D 1) - ret =3D qemuDomainRemoveRedirdevDevice(driver, vm, redirdev); - } - - cleanup: - if (!async) - qemuDomainResetDeviceRemoval(vm); - return ret; + return 0; } =20 =20 static int -qemuDomainDetachPrepNet(virQEMUDriverPtr driver, - virDomainObjPtr vm, +qemuDomainDetachPrepNet(virDomainObjPtr vm, virDomainNetDefPtr match, - virDomainNetDefPtr *detach, - bool async) + virDomainNetDefPtr *detach) { - int detachidx, ret =3D -1; + int detachidx; virDomainNetDefPtr net; =20 if ((detachidx =3D virDomainNetFindIdx(vm->def, match)) < 0) - goto cleanup; + return -1; =20 *detach =3D net =3D vm->def->nets[detachidx]; =20 - if (qemuIsMultiFunctionDevice(vm->def, &net->info)) { - virReportError(VIR_ERR_OPERATION_FAILED, - _("cannot hot unplug multifunction PCI device: %s"), - net->ifname); - goto cleanup; - } + return 0; +} =20 - if (!net->info.alias) { - if (qemuAssignDeviceNetAlias(vm->def, net, -1) < 0) - goto cleanup; - } =20 +static void +qemuDomainDetachShutdownNet(virDomainNetDefPtr net) +{ +/* + * These operations are in a separate function from + * qemuDomainDetachPrepNet() because they can't be done until after + * we've validated that this device really can be removed - in + * particular we need to check for multifunction PCI devices and + * presence of a device alias, which isn't done until *after* the + * return from qemuDomainDetachPrepNet(). Since we've already passed + * the "point of no return", we ignore any errors, and trudge ahead + * with shutting down and detaching the device even if there is an + * error in one of these functions. + */ if (virDomainNetGetActualBandwidth(net) && virNetDevSupportBandwidth(virDomainNetGetActualType(net)) && virNetDevBandwidthClear(net->ifname) < 0) @@ -5990,35 +5835,8 @@ qemuDomainDetachPrepNet(virQEMUDriverPtr driver, * the parent device offline) */ ignore_value(qemuInterfaceStopDevice(net)); - - if (!async) - qemuDomainMarkDeviceForRemoval(vm, &net->info); - - if (qemuDomainDeleteDevice(vm, net->info.alias) < 0) { - if (virDomainObjIsActive(vm)) { - /* the audit message has a different format for hostdev networ= k devices */ - if (virDomainNetGetActualType(net) =3D=3D VIR_DOMAIN_NET_TYPE_= HOSTDEV) - virDomainAuditHostdev(vm, virDomainNetGetActualHostdev(net= ), "detach", false); - else - virDomainAuditNet(vm, net, NULL, "detach", false); - } - goto cleanup; - } - - if (async) { - ret =3D 0; - } else { - if ((ret =3D qemuDomainWaitForDeviceRemoval(vm)) =3D=3D 1) - ret =3D qemuDomainRemoveNetDevice(driver, vm, net); - } - - cleanup: - if (!async) - qemuDomainResetDeviceRemoval(vm); - return ret; } =20 - static int qemuDomainDetachDeviceChr(virQEMUDriverPtr driver, virDomainObjPtr vm, @@ -6078,15 +5896,12 @@ qemuDomainDetachDeviceChr(virQEMUDriverPtr driver, =20 =20 static int -qemuDomainDetachPrepRNG(virQEMUDriverPtr driver, - virDomainObjPtr vm, +qemuDomainDetachPrepRNG(virDomainObjPtr vm, virDomainRNGDefPtr match, - virDomainRNGDefPtr *detach, - bool async) + virDomainRNGDefPtr *detach) { ssize_t idx; virDomainRNGDefPtr rng; - int ret =3D -1; =20 if ((idx =3D virDomainRNGFind(vm->def, match)) < 0) { virReportError(VIR_ERR_DEVICE_MISSING, @@ -6098,42 +5913,17 @@ qemuDomainDetachPrepRNG(virQEMUDriverPtr driver, =20 *detach =3D rng =3D vm->def->rngs[idx]; =20 - if (!rng->info.alias) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("alias not set for RNG device")); - return -1; - } - - if (!async) - qemuDomainMarkDeviceForRemoval(vm, &rng->info); - - if (qemuDomainDeleteDevice(vm, rng->info.alias) < 0) - goto cleanup; - - if (async) { - ret =3D 0; - } else { - if ((ret =3D qemuDomainWaitForDeviceRemoval(vm)) =3D=3D 1) - ret =3D qemuDomainRemoveRNGDevice(driver, vm, rng); - } - - cleanup: - if (!async) - qemuDomainResetDeviceRemoval(vm); - return ret; + return 0; } =20 =20 static int -qemuDomainDetachPrepMemory(virQEMUDriverPtr driver, - virDomainObjPtr vm, +qemuDomainDetachPrepMemory(virDomainObjPtr vm, virDomainMemoryDefPtr match, - virDomainMemoryDefPtr *detach, - bool async) + virDomainMemoryDefPtr *detach) { virDomainMemoryDefPtr mem; int idx; - int ret =3D -1; =20 qemuDomainMemoryDeviceAlignSize(vm->def, match); =20 @@ -6147,40 +5937,16 @@ qemuDomainDetachPrepMemory(virQEMUDriverPtr driver, =20 *detach =3D mem =3D vm->def->mems[idx]; =20 - if (!mem->info.alias) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("alias for the memory device was not found")); - return -1; - } - - if (!async) - qemuDomainMarkDeviceForRemoval(vm, &mem->info); - - if (qemuDomainDeleteDevice(vm, mem->info.alias) < 0) - goto cleanup; - - if (async) { - ret =3D 0; - } else { - if ((ret =3D qemuDomainWaitForDeviceRemoval(vm)) =3D=3D 1) - ret =3D qemuDomainRemoveMemoryDevice(driver, vm, mem); - } - - cleanup: - if (!async) - qemuDomainResetDeviceRemoval(vm); - return ret; + return 0; } =20 =20 static int qemuDomainDetachPrepInput(virDomainObjPtr vm, virDomainInputDefPtr match, - virDomainInputDefPtr *detach, - bool async) + virDomainInputDefPtr *detach) { virDomainInputDefPtr input; - int ret =3D -1; int idx; =20 if ((idx =3D virDomainInputDefFind(vm->def, match)) < 0) { @@ -6205,35 +5971,16 @@ qemuDomainDetachPrepInput(virDomainObjPtr vm, break; } =20 - if (!async) - qemuDomainMarkDeviceForRemoval(vm, &input->info); - - if (qemuDomainDeleteDevice(vm, input->info.alias) < 0) - goto cleanup; - - if (async) { - ret =3D 0; - } else { - if ((ret =3D qemuDomainWaitForDeviceRemoval(vm)) =3D=3D 1) - ret =3D qemuDomainRemoveInputDevice(vm, input); - } - - cleanup: - if (!async) - qemuDomainResetDeviceRemoval(vm); - return ret; + return 0; } =20 =20 static int qemuDomainDetachPrepVsock(virDomainObjPtr vm, virDomainVsockDefPtr match, - virDomainVsockDefPtr *detach, - bool async) + virDomainVsockDefPtr *detach) { virDomainVsockDefPtr vsock; - int ret =3D -1; - =20 *detach =3D vsock =3D vm->def->vsock; if (!vsock || @@ -6243,23 +5990,7 @@ qemuDomainDetachPrepVsock(virDomainObjPtr vm, return -1; } =20 - if (!async) - qemuDomainMarkDeviceForRemoval(vm, &vsock->info); - - if (qemuDomainDeleteDevice(vm, vsock->info.alias) < 0) - goto cleanup; - - if (async) { - ret =3D 0; - } else { - if ((ret =3D qemuDomainWaitForDeviceRemoval(vm)) =3D=3D 1) - ret =3D qemuDomainRemoveVsockDevice(vm, vsock); - } - - cleanup: - if (!async) - qemuDomainResetDeviceRemoval(vm); - return ret; + return 0; } =20 =20 @@ -6294,6 +6025,7 @@ qemuDomainDetachDeviceLive(virDomainObjPtr vm, bool async) { virDomainDeviceDef detach =3D { .type =3D match->type }; + virDomainDeviceInfoPtr info =3D NULL; int ret =3D -1; =20 switch ((virDomainDeviceType)match->type) { @@ -6309,75 +6041,76 @@ qemuDomainDetachDeviceLive(virDomainObjPtr vm, return qemuDomainDetachDeviceChr(driver, vm, match->data.chr, asyn= c); =20 /* - * All the other device types follow a very similar pattern - - * First we call type-specific functions to 1) locate the device - * we want to detach (based on the prototype device in match) - * and 2) do any device-type-specific validation to assure it - * is okay to detach the device. + * The rest of the device types (that support hot unplug) + * follow a very similar pattern - First we call type-specific + * functions to 1) locate the device we want to detach (based + * on the prototype device in match) and 2) do any + * device-type-specific validation to assure it is okay to + * detach the device. */ case VIR_DOMAIN_DEVICE_DISK: - if (qemuDomainDetachPrepDisk(driver, vm, match->data.disk, - &detach.data.disk, async) < 0) { + if (qemuDomainDetachPrepDisk(vm, match->data.disk, + &detach.data.disk) < 0) { return -1; } break; case VIR_DOMAIN_DEVICE_CONTROLLER: - if (qemuDomainDetachPrepController(driver, vm, match->data.control= ler, - &detach.data.controller, async)= < 0) { + if (qemuDomainDetachPrepController(vm, match->data.controller, + &detach.data.controller) < 0) { return -1; } break; case VIR_DOMAIN_DEVICE_NET: - if (qemuDomainDetachPrepNet(driver, vm, match->data.net, - &detach.data.net, async) < 0) { + if (qemuDomainDetachPrepNet(vm, match->data.net, + &detach.data.net) < 0) { return -1; } break; case VIR_DOMAIN_DEVICE_HOSTDEV: - if (qemuDomainDetachPrepHostdev(driver, vm, match->data.hostdev, - &detach.data.hostdev, async) < 0) { + if (qemuDomainDetachPrepHostdev(vm, match->data.hostdev, + &detach.data.hostdev) < 0) { return -1; } break; case VIR_DOMAIN_DEVICE_RNG: - if (qemuDomainDetachPrepRNG(driver, vm, match->data.rng, - &detach.data.rng, async) < 0) { + if (qemuDomainDetachPrepRNG(vm, match->data.rng, + &detach.data.rng) < 0) { return -1; } break; case VIR_DOMAIN_DEVICE_MEMORY: - if (qemuDomainDetachPrepMemory(driver, vm, match->data.memory, - &detach.data.memory, async) < 0) { + if (qemuDomainDetachPrepMemory(vm, match->data.memory, + &detach.data.memory) < 0) { return -1; } break; case VIR_DOMAIN_DEVICE_SHMEM: - if (qemuDomainDetachPrepShmem(driver, vm, match->data.shmem, - &detach.data.shmem, async) < 0) { + if (qemuDomainDetachPrepShmem(vm, match->data.shmem, + &detach.data.shmem) < 0) { return -1; } break; case VIR_DOMAIN_DEVICE_WATCHDOG: - if (qemuDomainDetachPrepWatchdog(driver, vm, match->data.watchdog, - &detach.data.watchdog, async) < 0= ) { + if (qemuDomainDetachPrepWatchdog(vm, match->data.watchdog, + &detach.data.watchdog) < 0) { return -1; } break; case VIR_DOMAIN_DEVICE_INPUT: if (qemuDomainDetachPrepInput(vm, match->data.input, - &detach.data.input, async) < 0) { + &detach.data.input) < 0) { return -1; } break; case VIR_DOMAIN_DEVICE_REDIRDEV: - if (qemuDomainDetachPrepRedirdev(driver, vm, match->data.redirdev, - &detach.data.redirdev, async) < 0= ) { + if (qemuDomainDetachPrepRedirdev(vm, match->data.redirdev, + &detach.data.redirdev) < 0) { return -1; } break; case VIR_DOMAIN_DEVICE_VSOCK: if (qemuDomainDetachPrepVsock(vm, match->data.vsock, - &detach.data.vsock, async) < 0) { + &detach.data.vsock) < 0) { return -1; } break; @@ -6401,7 +6134,75 @@ qemuDomainDetachDeviceLive(virDomainObjPtr vm, return -1; } =20 - ret =3D 0; + /* "detach" now points to the actual device we want to detach */ + + if (!(info =3D virDomainDeviceGetInfo(&detach))) { + /* + * This should never happen, since all of the device types in + * the switch cases that end with a "break" instead of a + * return have a virDeviceInfo in them. + */ + virReportError(VIR_ERR_INTERNAL_ERROR, + _("device of type '%s' has no device info"), + virDomainDeviceTypeToString(detach.type)); + return -1; + } + + + /* Make generic validation checks common to all device types */ + + if (!info->alias) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Cannot detach %s device with no alias"), + virDomainDeviceTypeToString(detach.type)); + return -1; + } + + if (qemuIsMultiFunctionDevice(vm->def, info)) { + virReportError(VIR_ERR_OPERATION_FAILED, + _("cannot hot unplug %s device with multifunction P= CI guest address: " + "%.4x:%.2x:%.2x.%.1x"), + virDomainDeviceTypeToString(detach.type), + info->addr.pci.domain, info->addr.pci.bus, + info->addr.pci.slot, info->addr.pci.function); + return -1; + } + + + /* + * Do any device-specific shutdown that should be + * done after all validation checks, but before issuing the qemu + * command to delete the device. For now, the only type of device + * that has such shutdown needs is the net device. + */ + if (detach.type =3D=3D VIR_DOMAIN_DEVICE_NET) + qemuDomainDetachShutdownNet(detach.data.net); + + + /* + * Issue the qemu monitor command to delete the device (based on + * its alias), and optionally wait a short time in case the + * DEVICE_DELETED event arrives from qemu right away. + */ + if (!async) + qemuDomainMarkDeviceForRemoval(vm, info); + + if (qemuDomainDeleteDevice(vm, info->alias) < 0) { + if (virDomainObjIsActive(vm)) + qemuDomainRemoveAuditDevice(vm, &detach, false); + goto cleanup; + } + + if (async) { + ret =3D 0; + } else { + if ((ret =3D qemuDomainWaitForDeviceRemoval(vm)) =3D=3D 1) + ret =3D qemuDomainRemoveDevice(driver, vm, &detach); + } + + cleanup: + if (!async) + qemuDomainResetDeviceRemoval(vm); =20 return ret; } --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Mar 28 20:57:44 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1553207382623927.5141834460217; Thu, 21 Mar 2019 15:29:42 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id F24A32D806; Thu, 21 Mar 2019 22:29:40 +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 C97FA5D70A; Thu, 21 Mar 2019 22:29:40 +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 7FAEA3FA4A; Thu, 21 Mar 2019 22:29:40 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x2LMTQA2015782 for ; Thu, 21 Mar 2019 18:29:26 -0400 Received: by smtp.corp.redhat.com (Postfix) id 6505C1001DE2; Thu, 21 Mar 2019 22:29:26 +0000 (UTC) Received: from vhost2.laine.org (ovpn-116-180.phx2.redhat.com [10.3.116.180]) by smtp.corp.redhat.com (Postfix) with ESMTP id EF1D21001DD3; Thu, 21 Mar 2019 22:29:25 +0000 (UTC) From: Laine Stump To: libvir-list@redhat.com Date: Thu, 21 Mar 2019 18:29:01 -0400 Message-Id: <20190321222901.12902-22-laine@laine.org> In-Reply-To: <20190321222901.12902-1-laine@laine.org> References: <20190321222901.12902-1-laine@laine.org> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Cc: Michal Privoznik , Peter Krempa Subject: [libvirt] [PATCH 21/21] qemu_hotplug: delay sending DEVICE_REMOVED event until after *all* teardown 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Thu, 21 Mar 2019 22:29:41 +0000 (UTC) Content-Type: text/plain; charset="utf-8" The VIR_DOMAIN_EVENT_ID_DEVICE_REMOVED event is sent after qemu has responded to a device_del command with a DEVICE_DELETED event. Before queuing the event, *some* of the final teardown of the device's trappings in libvirt is done, but not *all* of it. As a result, an application may receive and process the DEVICE_REMOVED event before libvirt has really finished with it. Usually this doesn't cause a problem, but it can - in the case of the bug report referenced below, vdsm is assigning a PCI device to a guest with managed=3D'no', using livirt's virNodeDeviceDetachFlags() and virNodeDeviceReAttach() APIs. Immediately after receiving a DEVICE_REMOVED event from libvirt signalling that the device had been successfully unplugged, vdsm would cal virNodeDeviceReAttach() to unbind the device from vfio-pci and rebind it to the host driverm but because the event was received before libvirt had completely finished processing the removal, that device was still on the "activeDevs" list, and so virNodeDeviceReAttach() failed. Experimentation with additional debug logs proved that libvirt would always end up dispatching the DEVICE_REMOVED event before it had removed the device from activeDevs (with a *much* greater difference with managed=3D'yes', since in that case the re-binding of the device occurred after queuing the device). Although the case of hostdev devices is the most extreme (since there is so much involved in tearing down the device), *all* device types suffer from the same problem - the DEVICE_REMOVED event is queued very early in the qemuDomainRemove*Device() function for all of them, resulting in a possibility of any application receiving the event before libvirt has really finished with the device. The solution is to save the device's alias (which is the only piece of info from the device object that is needed for the event) at the beginning of processing the device removal, and then queue the event as a final act before returning. Since all of the qemuDomainRemove*Device() functions (except qemuDomainRemoveChrDevice()) are now called exclusively from qemuDomainRemoveDevice() (which selects which of the subordinates to call in a switch statement based on the type of device), the shortest route to a solution is to doing the saving of alias, and later queueing of the event, in the higher level qemuDomainRemoveDevice(), and just completely remove the event-related code from all the subordinate functions. The single exception to this, as mentioned before, is qemuDomainRemoveChrDevice(), which is still called from somewhere other than qemuDomainRemoveDevice() (and has a separate arg used to trigger different behavior when the chr device has targetType =3D=3D GUESTFWD), so it must keep its original behavior intact, and must be treated differently by qemuDomainRemoveDevice() (similar to the way that qemuDomainDetachDeviceLive() treats chr and lease devices differently from all the others). Resolves: https://bugzilla.redhat.com/1658198 Signed-off-by: Laine Stump --- src/qemu/qemu_hotplug.c | 154 ++++++++++++++++++++-------------------- 1 file changed, 78 insertions(+), 76 deletions(-) diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index de7a7a2c95..43cc3a314d 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -4501,7 +4501,6 @@ qemuDomainRemoveDiskDevice(virQEMUDriverPtr driver, { qemuHotplugDiskSourceDataPtr diskbackend =3D NULL; virDomainDeviceDef dev; - virObjectEventPtr event; size_t i; qemuDomainObjPrivatePtr priv =3D vm->privateData; int ret =3D -1; @@ -4529,9 +4528,6 @@ qemuDomainRemoveDiskDevice(virQEMUDriverPtr driver, =20 virDomainAuditDisk(vm, disk->src, NULL, "detach", true); =20 - event =3D virDomainEventDeviceRemovedNewFromObj(vm, disk->info.alias); - virObjectEventStateQueue(driver->domainEventState, event); - qemuDomainReleaseDeviceAddress(vm, &disk->info, virDomainDiskGetSource= (disk)); =20 /* tear down disk security access */ @@ -4555,19 +4551,14 @@ qemuDomainRemoveDiskDevice(virQEMUDriverPtr driver, =20 =20 static int -qemuDomainRemoveControllerDevice(virQEMUDriverPtr driver, - virDomainObjPtr vm, +qemuDomainRemoveControllerDevice(virDomainObjPtr vm, virDomainControllerDefPtr controller) { - virObjectEventPtr event; size_t i; =20 VIR_DEBUG("Removing controller %s from domain %p %s", controller->info.alias, vm, vm->def->name); =20 - event =3D virDomainEventDeviceRemovedNewFromObj(vm, controller->info.a= lias); - virObjectEventStateQueue(driver->domainEventState, event); - for (i =3D 0; i < vm->def->ncontrollers; i++) { if (vm->def->controllers[i] =3D=3D controller) { virDomainControllerRemove(vm->def, i); @@ -4589,7 +4580,6 @@ qemuDomainRemoveMemoryDevice(virQEMUDriverPtr driver, qemuDomainObjPrivatePtr priv =3D vm->privateData; unsigned long long oldmem =3D virDomainDefGetMemoryTotal(vm->def); unsigned long long newmem =3D oldmem - mem->size; - virObjectEventPtr event; char *backendAlias =3D NULL; int rc; int idx; @@ -4611,9 +4601,6 @@ qemuDomainRemoveMemoryDevice(virQEMUDriverPtr driver, if (rc < 0) return -1; =20 - event =3D virDomainEventDeviceRemovedNewFromObj(vm, mem->info.alias); - virObjectEventStateQueue(driver->domainEventState, event); - if ((idx =3D virDomainMemoryFindByDef(vm->def, mem)) >=3D 0) virDomainMemoryRemove(vm->def, idx); =20 @@ -4693,7 +4680,6 @@ qemuDomainRemoveHostDevice(virQEMUDriverPtr driver, { virQEMUDriverConfigPtr cfg =3D virQEMUDriverGetConfig(driver); virDomainNetDefPtr net =3D NULL; - virObjectEventPtr event; size_t i; int ret =3D -1; qemuDomainObjPrivatePtr priv =3D vm->privateData; @@ -4737,9 +4723,6 @@ qemuDomainRemoveHostDevice(virQEMUDriverPtr driver, goto cleanup; } =20 - event =3D virDomainEventDeviceRemovedNewFromObj(vm, hostdev->info->ali= as); - virObjectEventStateQueue(driver->domainEventState, event); - if (hostdev->parent.type =3D=3D VIR_DOMAIN_DEVICE_NET) { net =3D hostdev->parent.data.net; =20 @@ -4818,7 +4801,6 @@ qemuDomainRemoveNetDevice(virQEMUDriverPtr driver, { virQEMUDriverConfigPtr cfg =3D virQEMUDriverGetConfig(driver); qemuDomainObjPrivatePtr priv =3D vm->privateData; - virObjectEventPtr event; char *hostnet_name =3D NULL; char *charDevAlias =3D NULL; size_t i; @@ -4863,9 +4845,6 @@ qemuDomainRemoveNetDevice(virQEMUDriverPtr driver, =20 virDomainAuditNet(vm, net, NULL, "detach", true); =20 - event =3D virDomainEventDeviceRemovedNewFromObj(vm, net->info.alias); - virObjectEventStateQueue(driver->domainEventState, event); - for (i =3D 0; i < vm->def->nnets; i++) { if (vm->def->nets[i] =3D=3D net) { virDomainNetRemove(vm->def, i); @@ -4948,11 +4927,20 @@ qemuDomainRemoveChrDevice(virQEMUDriverPtr driver, if (qemuDomainNamespaceTeardownChardev(vm, chr) < 0) VIR_WARN("Unable to remove chr device from /dev"); =20 + qemuDomainReleaseDeviceAddress(vm, &chr->info, NULL); + qemuDomainChrRemove(vm->def, chr); + + /* NB: all other qemuDomainRemove*Device() functions omit the + * sending of the DEVICE_REMOVED event, because they are *only* + * called from qemuDomainRemoveDevice(), and that function sends + * the DEVICE_REMOVED event for them, this function is different - + * it is called from other places than just + * qemuDomainRemoveDevice(), so it must send the DEVICE_REMOVED + * event itself. + */ event =3D virDomainEventDeviceRemovedNewFromObj(vm, chr->info.alias); virObjectEventStateQueue(driver->domainEventState, event); =20 - qemuDomainReleaseDeviceAddress(vm, &chr->info, NULL); - qemuDomainChrRemove(vm->def, chr); virDomainChrDefFree(chr); ret =3D 0; =20 @@ -4967,7 +4955,6 @@ qemuDomainRemoveRNGDevice(virQEMUDriverPtr driver, virDomainObjPtr vm, virDomainRNGDefPtr rng) { - virObjectEventPtr event; char *charAlias =3D NULL; char *objAlias =3D NULL; qemuDomainObjPrivatePtr priv =3D vm->privateData; @@ -5016,9 +5003,6 @@ qemuDomainRemoveRNGDevice(virQEMUDriverPtr driver, if (qemuDomainNamespaceTeardownRNG(vm, rng) < 0) VIR_WARN("Unable to remove RNG device from /dev"); =20 - event =3D virDomainEventDeviceRemovedNewFromObj(vm, rng->info.alias); - virObjectEventStateQueue(driver->domainEventState, event); - if ((idx =3D virDomainRNGFind(vm->def, rng)) >=3D 0) virDomainRNGRemove(vm->def, idx); qemuDomainReleaseDeviceAddress(vm, &rng->info, NULL); @@ -5043,7 +5027,6 @@ qemuDomainRemoveShmemDevice(virQEMUDriverPtr driver, char *charAlias =3D NULL; char *memAlias =3D NULL; qemuDomainObjPrivatePtr priv =3D vm->privateData; - virObjectEventPtr event =3D NULL; =20 VIR_DEBUG("Removing shmem device %s from domain %p %s", shmem->info.alias, vm, vm->def->name); @@ -5071,9 +5054,6 @@ qemuDomainRemoveShmemDevice(virQEMUDriverPtr driver, if (rc < 0) goto cleanup; =20 - event =3D virDomainEventDeviceRemovedNewFromObj(vm, shmem->info.alias); - virObjectEventStateQueue(driver->domainEventState, event); - if ((idx =3D virDomainShmemDefFind(vm->def, shmem)) >=3D 0) virDomainShmemDefRemove(vm->def, idx); qemuDomainReleaseDeviceAddress(vm, &shmem->info, NULL); @@ -5089,17 +5069,12 @@ qemuDomainRemoveShmemDevice(virQEMUDriverPtr driver, =20 =20 static int -qemuDomainRemoveWatchdog(virQEMUDriverPtr driver, - virDomainObjPtr vm, +qemuDomainRemoveWatchdog(virDomainObjPtr vm, virDomainWatchdogDefPtr watchdog) { - virObjectEventPtr event =3D NULL; - VIR_DEBUG("Removing watchdog %s from domain %p %s", watchdog->info.alias, vm, vm->def->name); =20 - event =3D virDomainEventDeviceRemovedNewFromObj(vm, watchdog->info.ali= as); - virObjectEventStateQueue(driver->domainEventState, event); qemuDomainReleaseDeviceAddress(vm, &watchdog->info, NULL); virDomainWatchdogDefFree(vm->def->watchdog); vm->def->watchdog =3D NULL; @@ -5111,16 +5086,11 @@ static int qemuDomainRemoveInputDevice(virDomainObjPtr vm, virDomainInputDefPtr dev) { - qemuDomainObjPrivatePtr priv =3D vm->privateData; - virQEMUDriverPtr driver =3D priv->driver; - virObjectEventPtr event =3D NULL; size_t i; =20 VIR_DEBUG("Removing input device %s from domain %p %s", dev->info.alias, vm, vm->def->name); =20 - event =3D virDomainEventDeviceRemovedNewFromObj(vm, dev->info.alias); - virObjectEventStateQueue(driver->domainEventState, event); for (i =3D 0; i < vm->def->ninputs; i++) { if (vm->def->inputs[i] =3D=3D dev) break; @@ -5145,15 +5115,9 @@ static int qemuDomainRemoveVsockDevice(virDomainObjPtr vm, virDomainVsockDefPtr dev) { - qemuDomainObjPrivatePtr priv =3D vm->privateData; - virQEMUDriverPtr driver =3D priv->driver; - virObjectEventPtr event =3D NULL; - VIR_DEBUG("Removing vsock device %s from domain %p %s", dev->info.alias, vm, vm->def->name); =20 - event =3D virDomainEventDeviceRemovedNewFromObj(vm, dev->info.alias); - virObjectEventStateQueue(driver->domainEventState, event); qemuDomainReleaseDeviceAddress(vm, &dev->info, NULL); virDomainVsockDefFree(vm->def->vsock); vm->def->vsock =3D NULL; @@ -5167,7 +5131,6 @@ qemuDomainRemoveRedirdevDevice(virQEMUDriverPtr drive= r, virDomainRedirdevDefPtr dev) { qemuDomainObjPrivatePtr priv =3D vm->privateData; - virObjectEventPtr event; char *charAlias =3D NULL; ssize_t idx; int ret =3D -1; @@ -5192,9 +5155,6 @@ qemuDomainRemoveRedirdevDevice(virQEMUDriverPtr drive= r, =20 virDomainAuditRedirdev(vm, dev, "detach", true); =20 - event =3D virDomainEventDeviceRemovedNewFromObj(vm, dev->info.alias); - virObjectEventStateQueue(driver->domainEventState, event); - if ((idx =3D virDomainRedirdevDefFind(vm->def, dev)) >=3D 0) virDomainRedirdevDefRemove(vm->def, idx); qemuDomainReleaseDeviceAddress(vm, &dev->info, NULL); @@ -5285,50 +5245,88 @@ qemuDomainRemoveDevice(virQEMUDriverPtr driver, virDomainObjPtr vm, virDomainDeviceDefPtr dev) { - int ret =3D -1; + virDomainDeviceInfoPtr info; + virObjectEventPtr event; + VIR_AUTOFREE(char *)alias =3D NULL; + + if (!(info =3D virDomainDeviceGetInfo(dev))) { + /* + * This should never happen, since all of the device types in + * the switch cases that end with a "break" instead of a + * return have a virDeviceInfo in them. + */ + virReportError(VIR_ERR_INTERNAL_ERROR, + _("device of type '%s' has no device info"), + virDomainDeviceTypeToString(dev->type)); + return -1; + } + + /* + * save the alias to use when sending a DEVICE_REMOVED event after + * all other teardown is complete + */ + if (VIR_STRDUP(alias, info->alias) < 0) + return -1; + switch ((virDomainDeviceType)dev->type) { + case VIR_DOMAIN_DEVICE_CHR: + /* unlike other qemuDomainRemove*Device() functions, this one + * can't take advantage of any common code at the end of + * qemuDomainRemoveDevice(). This is because it is called + * directly from other places (with an extra arg that would be + * clumsy to add into qemuDomainRemoveDevice()) + */ + return qemuDomainRemoveChrDevice(driver, vm, dev->data.chr, true); + + /* + * all of the following qemuDomainRemove*Device() functions + * are (and must be) only called from this function, so any + * code that is common to them all can be pulled out and put + * at the end of this function. + */ case VIR_DOMAIN_DEVICE_DISK: - ret =3D qemuDomainRemoveDiskDevice(driver, vm, dev->data.disk); + if (qemuDomainRemoveDiskDevice(driver, vm, dev->data.disk) < 0) + return -1; break; case VIR_DOMAIN_DEVICE_CONTROLLER: - ret =3D qemuDomainRemoveControllerDevice(driver, vm, dev->data.con= troller); + if (qemuDomainRemoveControllerDevice(vm, dev->data.controller) < 0) + return -1; break; case VIR_DOMAIN_DEVICE_NET: - ret =3D qemuDomainRemoveNetDevice(driver, vm, dev->data.net); + if (qemuDomainRemoveNetDevice(driver, vm, dev->data.net) < 0) + return -1; break; case VIR_DOMAIN_DEVICE_HOSTDEV: - ret =3D qemuDomainRemoveHostDevice(driver, vm, dev->data.hostdev); - break; - - case VIR_DOMAIN_DEVICE_CHR: - ret =3D qemuDomainRemoveChrDevice(driver, vm, dev->data.chr, true); + if (qemuDomainRemoveHostDevice(driver, vm, dev->data.hostdev) < 0) + return -1; break; case VIR_DOMAIN_DEVICE_RNG: - ret =3D qemuDomainRemoveRNGDevice(driver, vm, dev->data.rng); + if (qemuDomainRemoveRNGDevice(driver, vm, dev->data.rng) < 0) + return -1; break; - case VIR_DOMAIN_DEVICE_MEMORY: - ret =3D qemuDomainRemoveMemoryDevice(driver, vm, dev->data.memory); + if (qemuDomainRemoveMemoryDevice(driver, vm, dev->data.memory) < 0) + return -1; break; - case VIR_DOMAIN_DEVICE_SHMEM: - ret =3D qemuDomainRemoveShmemDevice(driver, vm, dev->data.shmem); + if (qemuDomainRemoveShmemDevice(driver, vm, dev->data.shmem) < 0) + return -1; break; - case VIR_DOMAIN_DEVICE_INPUT: - ret =3D qemuDomainRemoveInputDevice(vm, dev->data.input); + if (qemuDomainRemoveInputDevice(vm, dev->data.input) < 0) + return -1; break; - case VIR_DOMAIN_DEVICE_REDIRDEV: - ret =3D qemuDomainRemoveRedirdevDevice(driver, vm, dev->data.redir= dev); + if (qemuDomainRemoveRedirdevDevice(driver, vm, dev->data.redirdev)= < 0) + return -1; break; - case VIR_DOMAIN_DEVICE_WATCHDOG: - ret =3D qemuDomainRemoveWatchdog(driver, vm, dev->data.watchdog); + if (qemuDomainRemoveWatchdog(vm, dev->data.watchdog) < 0) + return -1; break; - case VIR_DOMAIN_DEVICE_VSOCK: - ret =3D qemuDomainRemoveVsockDevice(vm, dev->data.vsock); + if (qemuDomainRemoveVsockDevice(vm, dev->data.vsock) < 0) + return -1; break; =20 case VIR_DOMAIN_DEVICE_NONE: @@ -5350,7 +5348,11 @@ qemuDomainRemoveDevice(virQEMUDriverPtr driver, virDomainDeviceTypeToString(dev->type)); break; } - return ret; + + event =3D virDomainEventDeviceRemovedNewFromObj(vm, alias); + virObjectEventStateQueue(driver->domainEventState, event); + + return 0; } =20 =20 --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list