From nobody Fri Apr 26 06:49:14 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; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 15525661684811007.7232088858568; Thu, 14 Mar 2019 05:22:48 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B41663007C4E; Thu, 14 Mar 2019 12:22:46 +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 6EB9E60579; Thu, 14 Mar 2019 12:22: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 34E7D24C13; Thu, 14 Mar 2019 12:22:46 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x2ECMhVD030459 for ; Thu, 14 Mar 2019 08:22:43 -0400 Received: by smtp.corp.redhat.com (Postfix) id E7B255D706; Thu, 14 Mar 2019 12:22:43 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 40F0C5D73F for ; Thu, 14 Mar 2019 12:22:43 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Thu, 14 Mar 2019 13:22:35 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 1/5] qemu_hotplug: Introduce and use qemuDomainDeleteDevice 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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Thu, 14 Mar 2019 12:22:47 +0000 (UTC) Content-Type: text/plain; charset="utf-8" The aim of this function will be to fix return value of qemuMonitorDelDevice() in one specific case. But that is yet to come. Right now this is nothing but a plain substitution. Signed-off-by: Michal Privoznik --- src/qemu/qemu_hotplug.c | 278 +++++++++++++++------------------------- 1 file changed, 103 insertions(+), 175 deletions(-) diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index f43f80668c..baa4713cf4 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -67,6 +67,44 @@ VIR_LOG_INIT("qemu.qemu_hotplug"); unsigned long long qemuDomainRemoveDeviceWaitTime =3D 1000ull * 5; =20 =20 +/** + * qemuDomainDeleteDevice: + * @vm: domain object + * @alias: device to remove + * @enterMonitor: whether do EnterMonitor/ExitMonitor too + * + * This is a wrapper over qemuMonitorDelDevice() plus + * (optionally) enter/exit monitor calls. This function MUST be + * used instead of plain qemuMonitorDelDevice(). + * + * If @enterMonitor is true then the function expects @vm to be + * locked upon entry. + * + * Returns: 0 on success, + * -1 otherwise. + */ +static int +qemuDomainDeleteDevice(virDomainObjPtr vm, + const char *alias, + bool enterMonitor) +{ + qemuDomainObjPrivatePtr priv =3D vm->privateData; + virQEMUDriverPtr driver =3D priv->driver; + int rc; + + if (enterMonitor) + qemuDomainObjEnterMonitor(driver, vm); + + rc =3D qemuMonitorDelDevice(priv->mon, alias); + + if (enterMonitor && + qemuDomainObjExitMonitor(driver, vm) < 0) + rc =3D -1; + + return rc; +} + + /** * qemuHotplugPrepareDiskSourceAccess: * @driver: qemu driver struct @@ -158,7 +196,7 @@ qemuDomainAttachZPCIDevice(qemuMonitorPtr mon, =20 =20 static int -qemuDomainDetachZPCIDevice(qemuMonitorPtr mon, +qemuDomainDetachZPCIDevice(virDomainObjPtr vm, virDomainDeviceInfoPtr info) { char *zpciAlias =3D NULL; @@ -167,7 +205,7 @@ qemuDomainDetachZPCIDevice(qemuMonitorPtr mon, if (virAsprintf(&zpciAlias, "zpci%d", info->addr.pci.zpci.uid) < 0) goto cleanup; =20 - if (qemuMonitorDelDevice(mon, zpciAlias) < 0) + if (qemuDomainDeleteDevice(vm, zpciAlias, false) < 0) goto cleanup; =20 ret =3D 0; @@ -195,7 +233,7 @@ qemuDomainAttachExtensionDevice(qemuMonitorPtr mon, =20 =20 static int -qemuDomainDetachExtensionDevice(qemuMonitorPtr mon, +qemuDomainDetachExtensionDevice(virDomainObjPtr vm, virDomainDeviceInfoPtr info) { if (info->type !=3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI || @@ -204,7 +242,7 @@ qemuDomainDetachExtensionDevice(qemuMonitorPtr mon, } =20 if (info->addr.pci.extFlags & VIR_PCI_ADDRESS_EXTENSION_ZPCI) - return qemuDomainDetachZPCIDevice(mon, info); + return qemuDomainDetachZPCIDevice(vm, info); =20 return 0; } @@ -904,7 +942,7 @@ qemuDomainAttachDiskGeneric(virQEMUDriverPtr driver, goto exit_monitor; =20 if (qemuMonitorAddDevice(priv->mon, devstr) < 0) { - ignore_value(qemuDomainDetachExtensionDevice(priv->mon, &disk->inf= o)); + ignore_value(qemuDomainDetachExtensionDevice(vm, &disk->info)); goto exit_monitor; } =20 @@ -1021,7 +1059,7 @@ int qemuDomainAttachControllerDevice(virQEMUDriverPtr= driver, } =20 if ((ret =3D qemuMonitorAddDevice(priv->mon, devstr)) < 0) - ignore_value(qemuDomainDetachExtensionDevice(priv->mon, &controlle= r->info)); + ignore_value(qemuDomainDetachExtensionDevice(vm, &controller->info= )); =20 exit_monitor: if (qemuDomainObjExitMonitor(driver, vm) < 0) { @@ -1564,7 +1602,7 @@ qemuDomainAttachNetDevice(virQEMUDriverPtr driver, } =20 if (qemuMonitorAddDevice(priv->mon, nicstr) < 0) { - ignore_value(qemuDomainDetachExtensionDevice(priv->mon, &net->info= )); + ignore_value(qemuDomainDetachExtensionDevice(vm, &net->info)); ignore_value(qemuDomainObjExitMonitor(driver, vm)); virDomainAuditNet(vm, NULL, net, "attach", false); goto try_remove; @@ -1787,7 +1825,7 @@ qemuDomainAttachHostPCIDevice(virQEMUDriverPtr driver, =20 if ((ret =3D qemuMonitorAddDeviceWithFd(priv->mon, devstr, configfd, configfd_name)) < 0) { - ignore_value(qemuDomainDetachExtensionDevice(priv->mon, hostdev->i= nfo)); + ignore_value(qemuDomainDetachExtensionDevice(vm, hostdev->info)); } =20 exit_monitor: @@ -2460,7 +2498,7 @@ qemuDomainAttachRNGDevice(virQEMUDriverPtr driver, goto exit_monitor; =20 if (qemuMonitorAddDevice(priv->mon, devstr) < 0) { - ignore_value(qemuDomainDetachExtensionDevice(priv->mon, &rng->info= )); + ignore_value(qemuDomainDetachExtensionDevice(vm, &rng->info)); goto exit_monitor; } =20 @@ -2948,7 +2986,7 @@ qemuDomainAttachSCSIVHostDevice(virQEMUDriverPtr driv= er, =20 if ((ret =3D qemuMonitorAddDeviceWithFd(priv->mon, devstr, vhostfd, vhostfdName)) < 0) { - ignore_value(qemuDomainDetachExtensionDevice(priv->mon, hostdev->i= nfo)); + ignore_value(qemuDomainDetachExtensionDevice(vm, hostdev->info)); goto exit_monitor; } =20 @@ -3201,7 +3239,7 @@ qemuDomainAttachShmemDevice(virQEMUDriverPtr driver, goto exit_monitor; =20 if (qemuMonitorAddDevice(priv->mon, shmstr) < 0) { - ignore_value(qemuDomainDetachExtensionDevice(priv->mon, &shmem->in= fo)); + ignore_value(qemuDomainDetachExtensionDevice(vm, &shmem->info)); goto exit_monitor; } =20 @@ -3381,7 +3419,7 @@ qemuDomainAttachInputDevice(virQEMUDriverPtr driver, goto exit_monitor; =20 if (qemuMonitorAddDevice(priv->mon, devstr) < 0) { - ignore_value(qemuDomainDetachExtensionDevice(priv->mon, &input->in= fo)); + ignore_value(qemuDomainDetachExtensionDevice(vm, &input->info)); goto exit_monitor; } =20 @@ -3466,7 +3504,7 @@ qemuDomainAttachVsockDevice(virQEMUDriverPtr driver, goto exit_monitor; =20 if (qemuMonitorAddDeviceWithFd(priv->mon, devstr, vsockPriv->vhostfd, = fdname) < 0) { - ignore_value(qemuDomainDetachExtensionDevice(priv->mon, &vsock->in= fo)); + ignore_value(qemuDomainDetachExtensionDevice(vm, &vsock->info)); goto exit_monitor; } =20 @@ -4819,7 +4857,7 @@ qemuDomainRemoveRNGDevice(virQEMUDriverPtr driver, =20 qemuDomainObjEnterMonitor(driver, vm); =20 - if (qemuDomainDetachExtensionDevice(priv->mon, &rng->info) < 0) + if (qemuDomainDetachExtensionDevice(vm, &rng->info) < 0) rc =3D -1; =20 if (rc =3D=3D 0 && @@ -5216,7 +5254,6 @@ qemuDomainDetachVirtioDiskDevice(virQEMUDriverPtr dri= ver, bool async) { int ret =3D -1; - qemuDomainObjPrivatePtr priv =3D vm->privateData; =20 if (qemuIsMultiFunctionDevice(vm->def, &detach->info)) { virReportError(VIR_ERR_OPERATION_FAILED, @@ -5228,15 +5265,11 @@ qemuDomainDetachVirtioDiskDevice(virQEMUDriverPtr d= river, if (!async) qemuDomainMarkDeviceForRemoval(vm, &detach->info); =20 - qemuDomainObjEnterMonitor(driver, vm); - if (qemuMonitorDelDevice(priv->mon, detach->info.alias) < 0) { - if (qemuDomainObjExitMonitor(driver, vm) < 0) - goto cleanup; - virDomainAuditDisk(vm, detach->src, NULL, "detach", false); + if (qemuDomainDeleteDevice(vm, detach->info.alias, true) < 0) { + if (virDomainObjIsActive(vm)) + virDomainAuditDisk(vm, detach->src, NULL, "detach", false); goto cleanup; } - if (qemuDomainObjExitMonitor(driver, vm) < 0) - goto cleanup; =20 if (async) { ret =3D 0; @@ -5258,7 +5291,6 @@ qemuDomainDetachDiskDevice(virQEMUDriverPtr driver, bool async) { int ret =3D -1; - qemuDomainObjPrivatePtr priv =3D vm->privateData; =20 if (qemuDomainDiskBlockJobIsActive(detach)) goto cleanup; @@ -5266,15 +5298,11 @@ qemuDomainDetachDiskDevice(virQEMUDriverPtr driver, if (!async) qemuDomainMarkDeviceForRemoval(vm, &detach->info); =20 - qemuDomainObjEnterMonitor(driver, vm); - if (qemuMonitorDelDevice(priv->mon, detach->info.alias) < 0) { - if (qemuDomainObjExitMonitor(driver, vm) < 0) - goto cleanup; - virDomainAuditDisk(vm, detach->src, NULL, "detach", false); + if (qemuDomainDeleteDevice(vm, detach->info.alias, true) < 0) { + if (virDomainObjIsActive(vm)) + virDomainAuditDisk(vm, detach->src, NULL, "detach", false); goto cleanup; } - if (qemuDomainObjExitMonitor(driver, vm) < 0) - goto cleanup; =20 if (async) { ret =3D 0; @@ -5409,7 +5437,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, @@ -5455,19 +5482,18 @@ int qemuDomainDetachControllerDevice(virQEMUDriverP= tr driver, if (!async) qemuDomainMarkDeviceForRemoval(vm, &detach->info); =20 - qemuDomainObjEnterMonitor(driver, vm); - if (detach->type =3D=3D VIR_DOMAIN_CONTROLLER_TYPE_PCI && - qemuDomainDetachExtensionDevice(priv->mon, &detach->info) < 0) { - goto exit_monitor; - } + if (detach->type =3D=3D VIR_DOMAIN_CONTROLLER_TYPE_PCI) { + int rc; + qemuDomainObjEnterMonitor(driver, vm); + rc =3D qemuDomainDetachExtensionDevice(vm, &detach->info); + if (qemuDomainObjExitMonitor(driver, vm) < 0) + rc =3D -1; =20 - if (qemuMonitorDelDevice(priv->mon, detach->info.alias) < 0) { - ignore_value(qemuDomainObjExitMonitor(driver, vm)); - goto cleanup; + if (rc < 0) + goto cleanup; } =20 - exit_monitor: - if (qemuDomainObjExitMonitor(driver, vm) < 0) + if (qemuDomainDeleteDevice(vm, detach->info.alias, true) < 0) goto cleanup; =20 if (async) { @@ -5484,14 +5510,11 @@ int qemuDomainDetachControllerDevice(virQEMUDriverP= tr driver, } =20 static int -qemuDomainDetachHostPCIDevice(virQEMUDriverPtr driver, - virDomainObjPtr vm, +qemuDomainDetachHostPCIDevice(virDomainObjPtr vm, virDomainHostdevDefPtr detach, bool async) { - qemuDomainObjPrivatePtr priv =3D vm->privateData; virDomainHostdevSubsysPCIPtr pcisrc =3D &detach->source.subsys.u.pci; - int ret; =20 if (qemuIsMultiFunctionDevice(vm->def, detach->info)) { virReportError(VIR_ERR_OPERATION_FAILED, @@ -5504,23 +5527,14 @@ qemuDomainDetachHostPCIDevice(virQEMUDriverPtr driv= er, if (!async) qemuDomainMarkDeviceForRemoval(vm, detach->info); =20 - qemuDomainObjEnterMonitor(driver, vm); - ret =3D qemuMonitorDelDevice(priv->mon, detach->info->alias); - if (qemuDomainObjExitMonitor(driver, vm) < 0) - ret =3D -1; - - return ret; + return qemuDomainDeleteDevice(vm, detach->info->alias, true); } =20 static int -qemuDomainDetachHostUSBDevice(virQEMUDriverPtr driver, - virDomainObjPtr vm, +qemuDomainDetachHostUSBDevice(virDomainObjPtr vm, virDomainHostdevDefPtr detach, bool async) { - qemuDomainObjPrivatePtr priv =3D vm->privateData; - int ret; - if (!detach->info->alias) { virReportError(VIR_ERR_OPERATION_FAILED, "%s", _("device cannot be detached without a device= alias")); @@ -5530,23 +5544,14 @@ qemuDomainDetachHostUSBDevice(virQEMUDriverPtr driv= er, if (!async) qemuDomainMarkDeviceForRemoval(vm, detach->info); =20 - qemuDomainObjEnterMonitor(driver, vm); - ret =3D qemuMonitorDelDevice(priv->mon, detach->info->alias); - if (qemuDomainObjExitMonitor(driver, vm) < 0) - ret =3D -1; - - return ret; + return qemuDomainDeleteDevice(vm, detach->info->alias, true); } =20 static int -qemuDomainDetachHostSCSIDevice(virQEMUDriverPtr driver, - virDomainObjPtr vm, +qemuDomainDetachHostSCSIDevice(virDomainObjPtr vm, virDomainHostdevDefPtr detach, bool async) { - qemuDomainObjPrivatePtr priv =3D vm->privateData; - int ret =3D -1; - if (!detach->info->alias) { virReportError(VIR_ERR_OPERATION_FAILED, "%s", _("device cannot be detached without a device= alias")); @@ -5556,24 +5561,14 @@ qemuDomainDetachHostSCSIDevice(virQEMUDriverPtr dri= ver, if (!async) qemuDomainMarkDeviceForRemoval(vm, detach->info); =20 - qemuDomainObjEnterMonitor(driver, vm); - ret =3D qemuMonitorDelDevice(priv->mon, detach->info->alias); - - if (qemuDomainObjExitMonitor(driver, vm) < 0) - return -1; - - return ret; + return qemuDomainDeleteDevice(vm, detach->info->alias, true); } =20 static int -qemuDomainDetachSCSIVHostDevice(virQEMUDriverPtr driver, - virDomainObjPtr vm, +qemuDomainDetachSCSIVHostDevice(virDomainObjPtr vm, virDomainHostdevDefPtr detach, bool async) { - qemuDomainObjPrivatePtr priv =3D vm->privateData; - int ret =3D -1; - if (!detach->info->alias) { virReportError(VIR_ERR_OPERATION_FAILED, "%s", _("device cannot be detached without a device= alias")); @@ -5583,25 +5578,15 @@ qemuDomainDetachSCSIVHostDevice(virQEMUDriverPtr dr= iver, if (!async) qemuDomainMarkDeviceForRemoval(vm, detach->info); =20 - qemuDomainObjEnterMonitor(driver, vm); - ret =3D qemuMonitorDelDevice(priv->mon, detach->info->alias); - - if (qemuDomainObjExitMonitor(driver, vm) < 0) - return -1; - - return ret; + return qemuDomainDeleteDevice(vm, detach->info->alias, true); } =20 =20 static int -qemuDomainDetachMediatedDevice(virQEMUDriverPtr driver, - virDomainObjPtr vm, +qemuDomainDetachMediatedDevice(virDomainObjPtr vm, virDomainHostdevDefPtr detach, bool async) { - int ret =3D -1; - qemuDomainObjPrivatePtr priv =3D vm->privateData; - if (!detach->info->alias) { virReportError(VIR_ERR_OPERATION_FAILED, "%s", _("device cannot be detached without a device alias= ")); @@ -5611,12 +5596,7 @@ qemuDomainDetachMediatedDevice(virQEMUDriverPtr driv= er, if (!async) qemuDomainMarkDeviceForRemoval(vm, detach->info); =20 - qemuDomainObjEnterMonitor(driver, vm); - ret =3D qemuMonitorDelDevice(priv->mon, detach->info->alias); - if (qemuDomainObjExitMonitor(driver, vm) < 0) - ret =3D -1; - - return ret; + return qemuDomainDeleteDevice(vm, detach->info->alias, true); } =20 =20 @@ -5633,19 +5613,19 @@ qemuDomainDetachThisHostDevice(virQEMUDriverPtr dri= ver, =20 switch (detach->source.subsys.type) { case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI: - ret =3D qemuDomainDetachHostPCIDevice(driver, vm, detach, async); + ret =3D qemuDomainDetachHostPCIDevice(vm, detach, async); break; case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB: - ret =3D qemuDomainDetachHostUSBDevice(driver, vm, detach, async); + ret =3D qemuDomainDetachHostUSBDevice(vm, detach, async); break; case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI: - ret =3D qemuDomainDetachHostSCSIDevice(driver, vm, detach, async); + ret =3D qemuDomainDetachHostSCSIDevice(vm, detach, async); break; case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI_HOST: - ret =3D qemuDomainDetachSCSIVHostDevice(driver, vm, detach, async); + ret =3D qemuDomainDetachSCSIVHostDevice(vm, detach, async); break; case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV: - ret =3D qemuDomainDetachMediatedDevice(driver, vm, detach, async); + ret =3D qemuDomainDetachMediatedDevice(vm, detach, async); break; default: virReportError(VIR_ERR_CONFIG_UNSUPPORTED, @@ -5762,7 +5742,6 @@ qemuDomainDetachShmemDevice(virQEMUDriverPtr driver, int ret =3D -1; ssize_t idx =3D -1; virDomainShmemDefPtr shmem =3D NULL; - qemuDomainObjPrivatePtr priv =3D vm->privateData; =20 if ((idx =3D virDomainShmemDefFind(vm->def, dev)) < 0) { virReportError(VIR_ERR_DEVICE_MISSING, @@ -5791,12 +5770,7 @@ qemuDomainDetachShmemDevice(virQEMUDriverPtr driver, if (!async) qemuDomainMarkDeviceForRemoval(vm, &shmem->info); =20 - qemuDomainObjEnterMonitor(driver, vm); - if (qemuMonitorDelDevice(priv->mon, shmem->info.alias) < 0) { - ignore_value(qemuDomainObjExitMonitor(driver, vm)); - goto cleanup; - } - if (qemuDomainObjExitMonitor(driver, vm) < 0) + if (qemuDomainDeleteDevice(vm, shmem->info.alias, true) < 0) goto cleanup; =20 if (async) { @@ -5821,7 +5795,6 @@ qemuDomainDetachWatchdog(virQEMUDriverPtr driver, { int ret =3D -1; virDomainWatchdogDefPtr watchdog =3D vm->def->watchdog; - qemuDomainObjPrivatePtr priv =3D vm->privateData; =20 if (!watchdog) { virReportError(VIR_ERR_DEVICE_MISSING, "%s", @@ -5852,12 +5825,7 @@ qemuDomainDetachWatchdog(virQEMUDriverPtr driver, if (!async) qemuDomainMarkDeviceForRemoval(vm, &watchdog->info); =20 - qemuDomainObjEnterMonitor(driver, vm); - if (qemuMonitorDelDevice(priv->mon, watchdog->info.alias) < 0) { - ignore_value(qemuDomainObjExitMonitor(driver, vm)); - goto cleanup; - } - if (qemuDomainObjExitMonitor(driver, vm) < 0) + if (qemuDomainDeleteDevice(vm, watchdog->info.alias, true) < 0) goto cleanup; =20 if (async) { @@ -5881,7 +5849,6 @@ qemuDomainDetachRedirdevDevice(virQEMUDriverPtr drive= r, bool async) { int ret =3D -1; - qemuDomainObjPrivatePtr priv =3D vm->privateData; virDomainRedirdevDefPtr tmpRedirdevDef; ssize_t idx; =20 @@ -5902,12 +5869,7 @@ qemuDomainDetachRedirdevDevice(virQEMUDriverPtr driv= er, if (!async) qemuDomainMarkDeviceForRemoval(vm, &tmpRedirdevDef->info); =20 - qemuDomainObjEnterMonitor(driver, vm); - if (qemuMonitorDelDevice(priv->mon, tmpRedirdevDef->info.alias) < 0) { - ignore_value(qemuDomainObjExitMonitor(driver, vm)); - goto cleanup; - } - if (qemuDomainObjExitMonitor(driver, vm) < 0) + if (qemuDomainDeleteDevice(vm, tmpRedirdevDef->info.alias, true) < 0) goto cleanup; =20 if (async) { @@ -5932,7 +5894,6 @@ qemuDomainDetachNetDevice(virQEMUDriverPtr driver, { int detachidx, ret =3D -1; virDomainNetDefPtr detach =3D NULL; - qemuDomainObjPrivatePtr priv =3D vm->privateData; =20 if ((detachidx =3D virDomainNetFindIdx(vm->def, dev->data.net)) < 0) goto cleanup; @@ -5973,15 +5934,11 @@ qemuDomainDetachNetDevice(virQEMUDriverPtr driver, if (!async) qemuDomainMarkDeviceForRemoval(vm, &detach->info); =20 - qemuDomainObjEnterMonitor(driver, vm); - if (qemuMonitorDelDevice(priv->mon, detach->info.alias) < 0) { - if (qemuDomainObjExitMonitor(driver, vm) < 0) - goto cleanup; - virDomainAuditNet(vm, detach, NULL, "detach", false); + if (qemuDomainDeleteDevice(vm, detach->info.alias, true) < 0) { + if (virDomainObjIsActive(vm)) + virDomainAuditNet(vm, detach, NULL, "detach", false); goto cleanup; } - if (qemuDomainObjExitMonitor(driver, vm) < 0) - goto cleanup; =20 if (async) { ret =3D 0; @@ -6144,20 +6101,19 @@ int qemuDomainDetachChrDevice(virQEMUDriverPtr driv= er, if (!async && !guestfwd) qemuDomainMarkDeviceForRemoval(vm, &tmpChr->info); =20 - qemuDomainObjEnterMonitor(driver, vm); if (guestfwd) { - if (qemuMonitorRemoveNetdev(priv->mon, tmpChr->info.alias) < 0) { - ignore_value(qemuDomainObjExitMonitor(driver, vm)); + int rc; + qemuDomainObjEnterMonitor(driver, vm); + rc =3D qemuMonitorRemoveNetdev(priv->mon, tmpChr->info.alias); + if (qemuDomainObjExitMonitor(driver, vm) < 0) + rc =3D -1; + + if (rc < 0) goto cleanup; - } } else { - if (qemuMonitorDelDevice(priv->mon, tmpChr->info.alias) < 0) { - ignore_value(qemuDomainObjExitMonitor(driver, vm)); + if (qemuDomainDeleteDevice(vm, tmpChr->info.alias, true) < 0) goto cleanup; - } } - if (qemuDomainObjExitMonitor(driver, vm) < 0) - goto cleanup; =20 if (guestfwd) { ret =3D qemuDomainRemoveChrDevice(driver, vm, tmpChr, false); @@ -6181,10 +6137,8 @@ qemuDomainDetachRNGDevice(virQEMUDriverPtr driver, virDomainRNGDefPtr rng, bool async) { - qemuDomainObjPrivatePtr priv =3D vm->privateData; ssize_t idx; virDomainRNGDefPtr tmpRNG; - int rc; int ret =3D -1; =20 if ((idx =3D virDomainRNGFind(vm->def, rng)) < 0) { @@ -6206,9 +6160,7 @@ qemuDomainDetachRNGDevice(virQEMUDriverPtr driver, if (!async) qemuDomainMarkDeviceForRemoval(vm, &tmpRNG->info); =20 - qemuDomainObjEnterMonitor(driver, vm); - rc =3D qemuMonitorDelDevice(priv->mon, tmpRNG->info.alias); - if (qemuDomainObjExitMonitor(driver, vm) || rc < 0) + if (qemuDomainDeleteDevice(vm, tmpRNG->info.alias, true) < 0) goto cleanup; =20 if (async) { @@ -6231,10 +6183,8 @@ qemuDomainDetachMemoryDevice(virQEMUDriverPtr driver, virDomainMemoryDefPtr memdef, bool async) { - qemuDomainObjPrivatePtr priv =3D vm->privateData; virDomainMemoryDefPtr mem; int idx; - int rc; int ret =3D -1; =20 qemuDomainMemoryDeviceAlignSize(vm->def, memdef); @@ -6258,9 +6208,7 @@ qemuDomainDetachMemoryDevice(virQEMUDriverPtr driver, if (!async) qemuDomainMarkDeviceForRemoval(vm, &mem->info); =20 - qemuDomainObjEnterMonitor(driver, vm); - rc =3D qemuMonitorDelDevice(priv->mon, mem->info.alias); - if (qemuDomainObjExitMonitor(driver, vm) < 0 || rc < 0) + if (qemuDomainDeleteDevice(vm, mem->info.alias, true) < 0) goto cleanup; =20 if (async) { @@ -6365,15 +6313,9 @@ qemuDomainHotplugDelVcpu(virQEMUDriverPtr driver, =20 qemuDomainMarkDeviceAliasForRemoval(vm, vcpupriv->alias); =20 - qemuDomainObjEnterMonitor(driver, vm); - - rc =3D qemuMonitorDelDevice(qemuDomainGetMonitor(vm), vcpupriv->alias); - - if (qemuDomainObjExitMonitor(driver, vm) < 0) - goto cleanup; - - if (rc < 0) { - virDomainAuditVcpu(vm, oldvcpus, oldvcpus - nvcpus, "update", fals= e); + if (qemuDomainDeleteDevice(vm, vcpupriv->alias, true) < 0) { + if (virDomainObjIsActive(vm)) + virDomainAuditVcpu(vm, oldvcpus, oldvcpus - nvcpus, "update", = false); goto cleanup; } =20 @@ -6943,8 +6885,6 @@ qemuDomainDetachInputDevice(virDomainObjPtr vm, virDomainInputDefPtr def, bool async) { - qemuDomainObjPrivatePtr priv =3D vm->privateData; - virQEMUDriverPtr driver =3D priv->driver; virDomainInputDefPtr input; int ret =3D -1; int idx; @@ -6974,12 +6914,7 @@ qemuDomainDetachInputDevice(virDomainObjPtr vm, if (!async) qemuDomainMarkDeviceForRemoval(vm, &input->info); =20 - qemuDomainObjEnterMonitor(driver, vm); - if (qemuMonitorDelDevice(priv->mon, input->info.alias) < 0) { - ignore_value(qemuDomainObjExitMonitor(driver, vm)); - goto cleanup; - } - if (qemuDomainObjExitMonitor(driver, vm) < 0) + if (qemuDomainDeleteDevice(vm, input->info.alias, true) < 0) goto cleanup; =20 if (async) { @@ -7001,8 +6936,6 @@ qemuDomainDetachVsockDevice(virDomainObjPtr vm, virDomainVsockDefPtr dev, bool async) { - qemuDomainObjPrivatePtr priv =3D vm->privateData; - virQEMUDriverPtr driver =3D priv->driver; virDomainVsockDefPtr vsock =3D vm->def->vsock; int ret =3D -1; =20 @@ -7017,12 +6950,7 @@ qemuDomainDetachVsockDevice(virDomainObjPtr vm, if (!async) qemuDomainMarkDeviceForRemoval(vm, &vsock->info); =20 - qemuDomainObjEnterMonitor(driver, vm); - if (qemuMonitorDelDevice(priv->mon, vsock->info.alias) < 0) { - ignore_value(qemuDomainObjExitMonitor(driver, vm)); - goto cleanup; - } - if (qemuDomainObjExitMonitor(driver, vm) < 0) + if (qemuDomainDeleteDevice(vm, vsock->info.alias, true) < 0) goto cleanup; =20 if (async) { --=20 2.19.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 26 06:49:14 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; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1552566168615749.1336101824987; Thu, 14 Mar 2019 05:22:48 -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 E40CE3169B37; Thu, 14 Mar 2019 12:22:46 +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 BA2191001DF0; Thu, 14 Mar 2019 12:22: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 76C3224C15; Thu, 14 Mar 2019 12:22:46 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x2ECMinj030467 for ; Thu, 14 Mar 2019 08:22:44 -0400 Received: by smtp.corp.redhat.com (Postfix) id C4C575D75C; Thu, 14 Mar 2019 12:22:44 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 485325D706 for ; Thu, 14 Mar 2019 12:22:44 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Thu, 14 Mar 2019 13:22:36 +0100 Message-Id: <6689c9af6381c7cc06e2037bfb5595cb1d2888b5.1552565982.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 2/5] DO NOT APPLY: Simple reproducer 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.41]); Thu, 14 Mar 2019 12:22:47 +0000 (UTC) Content-Type: text/plain; charset="utf-8" https://bugzilla.redhat.com/show_bug.cgi?id=3D1623389 Steps to reproduce: 1) cat shmem.xml 4 2) virsh attach-device vm1 shmem.xml 3) virsh detach-device-alias vm1 ua-123; virsh detach-device vm1 shmem.xml 4) observe that the device is still in the domain: virsh dumpxml vm1 4
5) But qemu has the device no more: virsh detach-device-alias vm1 ua-123 error: Failed to detach device with alias ua-123 error: internal error: unable to execute QEMU command 'device_del': Devi= ce 'ua-123' not found This reproducer is to make sure that DELETE_DEVICE event arrives while monitor is unlocked. It is very hard to time qemu and libvirt so that the event comes exactly at the time when detach-device from 3) is doing the monitor call. Simulate this by unlocking monitor, waiting a few seconds and locking the monitor again. Signed-off-by: Michal Privoznik --- src/qemu/qemu_hotplug.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index baa4713cf4..59a5d21a5b 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -96,6 +96,11 @@ qemuDomainDeleteDevice(virDomainObjPtr vm, qemuDomainObjEnterMonitor(driver, vm); =20 rc =3D qemuMonitorDelDevice(priv->mon, alias); + if (rc < 0) { + virObjectUnlock(priv->mon); + sleep(10); + virObjectLock(priv->mon); + } =20 if (enterMonitor && qemuDomainObjExitMonitor(driver, vm) < 0) --=20 2.19.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 26 06:49:14 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; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1552566173075435.6355674945805; Thu, 14 Mar 2019 05:22:53 -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 E366DC098D2B; Thu, 14 Mar 2019 12:22:50 +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 ABCFF1001E62; Thu, 14 Mar 2019 12:22:50 +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 613EB24C19; Thu, 14 Mar 2019 12:22:50 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x2ECMjIe030474 for ; Thu, 14 Mar 2019 08:22:45 -0400 Received: by smtp.corp.redhat.com (Postfix) id 9B4225D73F; Thu, 14 Mar 2019 12:22:45 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1FDF35D706 for ; Thu, 14 Mar 2019 12:22:44 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Thu, 14 Mar 2019 13:22:37 +0100 Message-Id: <67f16f145a0adb8dd520ba1ca81673e1db149cdc.1552565982.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 3/5] qemuMonitorJSONDelDevice: Return -2 on DeviceNotFound error 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.31]); Thu, 14 Mar 2019 12:22:51 +0000 (UTC) Content-Type: text/plain; charset="utf-8" A caller might be interested in differentiating the cause for error, especially if DeviceNotFound error occurred. Signed-off-by: Michal Privoznik --- src/qemu/qemu_monitor.c | 10 ++++++++++ src/qemu/qemu_monitor_json.c | 5 +++++ 2 files changed, 15 insertions(+) diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c index 8bd4d4d761..5602a20ee4 100644 --- a/src/qemu/qemu_monitor.c +++ b/src/qemu/qemu_monitor.c @@ -3008,6 +3008,16 @@ qemuMonitorDriveDel(qemuMonitorPtr mon, } =20 =20 +/** + * @mon: monitor object + * @devalias: alias of the device to detach + * + * Sends device detach request to qemu. + * + * Returns: 0 on success, + * -2 if DeviceNotFound error encountered + * -1 otherwise + */ int qemuMonitorDelDevice(qemuMonitorPtr mon, const char *devalias) diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index 0236323a51..5c16e1f3a1 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -4191,6 +4191,11 @@ int qemuMonitorJSONDelDevice(qemuMonitorPtr mon, if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) goto cleanup; =20 + if (qemuMonitorJSONHasError(reply, "DeviceNotFound")) { + ret =3D -2; + goto cleanup; + } + if (qemuMonitorJSONCheckError(cmd, reply) < 0) goto cleanup; =20 --=20 2.19.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 26 06:49:14 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; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1552566176557102.1351796373707; Thu, 14 Mar 2019 05:22:56 -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 A82213023916; Thu, 14 Mar 2019 12:22:54 +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 7A8F65D75C; Thu, 14 Mar 2019 12:22:54 +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 3A3DF181A137; Thu, 14 Mar 2019 12:22:54 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x2ECMk5W030482 for ; Thu, 14 Mar 2019 08:22:46 -0400 Received: by smtp.corp.redhat.com (Postfix) id 7212B5D73F; Thu, 14 Mar 2019 12:22:46 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id EB69C5D706 for ; Thu, 14 Mar 2019 12:22:45 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Thu, 14 Mar 2019 13:22:38 +0100 Message-Id: <17d9e71cc39812053fc25175a40f02672a0dc803.1552565982.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 4/5] qemu_hotplug: Fix a rare race condition when detaching a device twice 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.43]); Thu, 14 Mar 2019 12:22:55 +0000 (UTC) Content-Type: text/plain; charset="utf-8" https://bugzilla.redhat.com/show_bug.cgi?id=3D1623389 If a device is detached twice from the same domain the following race condition may happen: 1) The first DetachDevice() call will issue "device_del" on qemu monitor, but since the DEVICE_DELETED event did not arrive in time, the API ends claiming "Device detach request sent successfully". 2) The second DetachDevice() therefore still find the device in the domain and thus proceeds to detaching it again. It calls EnterMonitor() and qemuMonitorSend() trying to issue "device_del" command again. This gets both domain lock and monitor lock released. 3) At this point, qemu sends us the DEVICE_DELETED event which is going to be handled by the event loop which ends up calling qemuDomainSignalDeviceRemoval() to determine who is going to remove the device from domain definition. Whether it is the caller that marked the device for removal or whether it is going to be the event processing thread. 4) Because the device was marked for removal, qemuDomainSignalDeviceRemoval() returns true, which means the event is to be processed by the thread that has marked the device for removal (and is currently still trying to issue "device_del" command) 5) The thread finally issues the "device_del" command, which fails (obviously) and therefore it calls qemuDomainResetDeviceRemoval() to reset the device marking and quits immediately after, NOT removing any device from the domain definition. At this point, the device is still present in the domain definition but doesn't exist in qemu anymore. Worse, there is no way to remove it from the domain definition. Solution is to note down that we've seen the event and if the second "device_del" fails, not take it as a failure but carry on with the usual execution. Signed-off-by: Michal Privoznik --- src/qemu/qemu_domain.h | 1 + src/qemu/qemu_hotplug.c | 52 +++++++++++++++++++++++++++++++++++++++-- 2 files changed, 51 insertions(+), 2 deletions(-) diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h index 9f468e5661..fb361515ba 100644 --- a/src/qemu/qemu_domain.h +++ b/src/qemu/qemu_domain.h @@ -218,6 +218,7 @@ typedef qemuDomainUnpluggingDevice *qemuDomainUnpluggin= gDevicePtr; struct _qemuDomainUnpluggingDevice { const char *alias; qemuDomainUnpluggingDeviceStatus status; + bool eventSeen; /* True if DEVICE_DELETED event arrived. */ }; =20 =20 diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 59a5d21a5b..6b5b37bda5 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -67,6 +67,9 @@ VIR_LOG_INIT("qemu.qemu_hotplug"); unsigned long long qemuDomainRemoveDeviceWaitTime =3D 1000ull * 5; =20 =20 +static void +qemuDomainResetDeviceRemoval(virDomainObjPtr vm); + /** * qemuDomainDeleteDevice: * @vm: domain object @@ -103,8 +106,51 @@ qemuDomainDeleteDevice(virDomainObjPtr vm, } =20 if (enterMonitor && - qemuDomainObjExitMonitor(driver, vm) < 0) - rc =3D -1; + qemuDomainObjExitMonitor(driver, vm) < 0) { + /* Domain is no longer running. No cleanup needed. */ + return -1; + } + + if (rc < 0) { + bool eventSeen; + + /* Deleting device failed. Let's check if DEVICE_DELETED + * even arrived. If it did, we need to claim success to + * make the caller remove device from domain XML. */ + if (enterMonitor) { + /* Here @vm is locked again. It's safe to access + * private data directly. */ + } else { + /* Here @vm is not locked. Do some locking magic to + * be able to access private data. It is safe to lock + * and unlock both @mon and @vm here because: + * a) qemuDomainObjEnterMonitor() ensures @mon is ref()'d + * b) The API that is calling us ensures that @vm is ref()'d + */ + virObjectUnlock(priv->mon); + virObjectLock(vm); + virObjectLock(priv->mon); + } + + eventSeen =3D priv->unplug.eventSeen; + if (eventSeen) { + /* The event arrived. Return success. */ + VIR_DEBUG("Detaching of device %s failed, but event arrived", = alias); + qemuDomainResetDeviceRemoval(vm); + rc =3D 0; + } else if (rc =3D=3D -2) { + /* The device does not exist in qemu, but it still + * exists in libvirt. Claim success to make caller + * qemuDomainWaitForDeviceRemoval(). Otherwise if + * domain XML is queried right after detach API the + * device would still be there. */ + VIR_DEBUG("Detaching of device %s failed and no event arrived"= , alias); + rc =3D 0; + } + + if (!enterMonitor) + virObjectUnlock(vm); + } =20 return rc; } @@ -5186,6 +5232,7 @@ qemuDomainResetDeviceRemoval(virDomainObjPtr vm) { qemuDomainObjPrivatePtr priv =3D vm->privateData; priv->unplug.alias =3D NULL; + priv->unplug.eventSeen =3D false; } =20 /* Returns: @@ -5245,6 +5292,7 @@ qemuDomainSignalDeviceRemoval(virDomainObjPtr vm, VIR_DEBUG("Removal of device '%s' continues in waiting thread", de= vAlias); qemuDomainResetDeviceRemoval(vm); priv->unplug.status =3D status; + priv->unplug.eventSeen =3D true; virDomainObjBroadcast(vm); return true; } --=20 2.19.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 26 06:49:14 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; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1552566172945436.46037290648303; Thu, 14 Mar 2019 05:22:52 -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 40DDC307D764; Thu, 14 Mar 2019 12:22:51 +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 19FC15D706; Thu, 14 Mar 2019 12:22:51 +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 C918C24C1E; Thu, 14 Mar 2019 12:22:50 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x2ECMllx030492 for ; Thu, 14 Mar 2019 08:22:47 -0400 Received: by smtp.corp.redhat.com (Postfix) id 4768D5D75C; Thu, 14 Mar 2019 12:22:47 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id C11675D73F for ; Thu, 14 Mar 2019 12:22:46 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Thu, 14 Mar 2019 13:22:39 +0100 Message-Id: <8b3d780528f725c9bb2c19dd97be619a064fc942.1552565982.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 5/5] DO NOT APPLY: Revert simple reproducer 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.45]); Thu, 14 Mar 2019 12:22:51 +0000 (UTC) Content-Type: text/plain; charset="utf-8" This reverts previous commit. Signed-off-by: Michal Privoznik --- src/qemu/qemu_hotplug.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 6b5b37bda5..576bf1db26 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -99,11 +99,6 @@ qemuDomainDeleteDevice(virDomainObjPtr vm, qemuDomainObjEnterMonitor(driver, vm); =20 rc =3D qemuMonitorDelDevice(priv->mon, alias); - if (rc < 0) { - virObjectUnlock(priv->mon); - sleep(10); - virObjectLock(priv->mon); - } =20 if (enterMonitor && qemuDomainObjExitMonitor(driver, vm) < 0) { --=20 2.19.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list