From nobody Sun Feb 8 15:42:46 2026 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=fail(p=none dis=none) header.from=virtuozzo.com ARC-Seal: i=1; a=rsa-sha256; t=1568728468; cv=none; d=zoho.com; s=zohoarc; b=gd3Gl9Nqn+2WFUHKEQuIBXxJcDMbkAMa82GVENKA+flzx6IIWZvkgvcs/LDo9cK+tiIqcw1fzMp2IS3L+8Cmv/uepfOoD8/B87eAWnmculzAJ+v49vNCYh8INYo6eotXD+HavF8CTFyAKvowk3UFeFN5ujG4fG1jZph6dNO90Uo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568728468; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=VoGuTQE++CV2bl2D9W0E2YPRUOiaRWhFQoPP11lrQLs=; b=QmlYL1oOI03lMfzaLh9+qsO+4ESVV+RWyNuKKZIRn61UqSH0psedPm02/co0Ip7+pF9x67N0x82DtYJM+NC4kQOB2fz04eeuMTYyljLyOzZ5gRZi1PHOHgcK1B0wdLZ7ZT7pGT+cEB0ri0NTGa7mlU2+/m7m8opfGxa4pa+18fE= ARC-Authentication-Results: i=1; mx.zoho.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=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1568728468173187.52852874908228; Tue, 17 Sep 2019 06:54:28 -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 04D973B71F; Tue, 17 Sep 2019 13:54:25 +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 B2B2E5C3FA; Tue, 17 Sep 2019 13:54:24 +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 A0AD64E58B; Tue, 17 Sep 2019 13:54:23 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x8HDmYVX002298 for ; Tue, 17 Sep 2019 09:48:34 -0400 Received: by smtp.corp.redhat.com (Postfix) id 1CE8A60C18; Tue, 17 Sep 2019 13:48:34 +0000 (UTC) Received: from mx1.redhat.com (ext-mx04.extmail.prod.ext.phx2.redhat.com [10.5.110.28]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0EA6F60C83 for ; Tue, 17 Sep 2019 13:48:29 +0000 (UTC) Received: from relay.sw.ru (relay.sw.ru [185.231.240.75]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3D5F28553D for ; Tue, 17 Sep 2019 13:48:28 +0000 (UTC) Received: from [172.16.24.106] (helo=shiny.sw.ru) by relay.sw.ru with esmtp (Exim 4.92.2) (envelope-from ) id 1iADqE-0001xB-Bq; Tue, 17 Sep 2019 16:48:26 +0300 From: Nikolay Shirokovskiy To: libvir-list@redhat.com Date: Tue, 17 Sep 2019 16:47:38 +0300 Message-Id: <20190917134747.13868-4-nshirokovskiy@virtuozzo.com> In-Reply-To: <20190917134747.13868-1-nshirokovskiy@virtuozzo.com> References: <20190917134747.13868-1-nshirokovskiy@virtuozzo.com> MIME-Version: 1.0 X-Greylist: Sender passed SPF test, ACL 264 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Tue, 17 Sep 2019 13:48:28 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Tue, 17 Sep 2019 13:48:28 +0000 (UTC) for IP:'185.231.240.75' DOMAIN:'relay.sw.ru' HELO:'relay.sw.ru' FROM:'nshirokovskiy@virtuozzo.com' RCPT:'' X-RedHat-Spam-Score: 0 (SPF_HELO_NONE, SPF_PASS) 185.231.240.75 relay.sw.ru 185.231.240.75 relay.sw.ru X-Scanned-By: MIMEDefang 2.78 on 10.5.110.28 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza Subject: [libvirt] [PATCH v3 03/12] qemu: support host usb device unplug 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.30]); Tue, 17 Sep 2019 13:54:27 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Handle host usb device unplug in DEVICE_DELETED handle execution path. Signed-off-by: Nikolay Shirokovskiy Reviewed-by: Daniel Henrique Barboza --- src/qemu/qemu_hotplug.c | 38 +++++++++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 5b65963f86..121e4b2821 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -4465,7 +4465,8 @@ qemuDomainRemoveUSBHostDevice(virQEMUDriverPtr driver, virDomainHostdevDefPtr hostdev) { qemuHostdevReAttachUSBDevices(driver, vm->def->name, &hostdev, 1); - qemuDomainReleaseDeviceAddress(vm, hostdev->info); + if (hostdev->deleteAction !=3D VIR_DOMAIN_HOSTDEV_DELETE_ACTION_UNPLUG) + qemuDomainReleaseDeviceAddress(vm, hostdev->info); } =20 static void @@ -4507,6 +4508,7 @@ qemuDomainRemoveHostDevice(virQEMUDriverPtr driver, char *drivealias =3D NULL; char *objAlias =3D NULL; bool is_vfio =3D false; + bool unplug =3D hostdev->deleteAction =3D=3D VIR_DOMAIN_HOSTDEV_DELETE= _ACTION_UNPLUG; =20 VIR_DEBUG("Removing host device %s from domain %p %s", hostdev->info->alias, vm, vm->def->name); @@ -4554,16 +4556,24 @@ qemuDomainRemoveHostDevice(virQEMUDriverPtr driver, } } =20 - for (i =3D 0; i < vm->def->nhostdevs; i++) { - if (vm->def->hostdevs[i] =3D=3D hostdev) { - virDomainHostdevRemove(vm->def, i); - break; + if (!unplug) { + for (i =3D 0; i < vm->def->nhostdevs; i++) { + if (vm->def->hostdevs[i] =3D=3D hostdev) { + virDomainHostdevRemove(vm->def, i); + break; + } } } =20 virDomainAuditHostdev(vm, hostdev, "detach", true); =20 - if (!is_vfio && + /* + * In case of unplug the attempt to restore label will fail. But we do= n't + * need to restore the label! In case of separate mount namespace for = the + * domain we remove device file later in this function. In case of glo= bal + * mount namespace the device file is deleted or being deleted by syst= emd. + */ + if (!is_vfio && !unplug && qemuSecurityRestoreHostdevLabel(driver, vm, hostdev) < 0) VIR_WARN("Failed to restore host device labelling"); =20 @@ -4597,7 +4607,13 @@ qemuDomainRemoveHostDevice(virQEMUDriverPtr driver, break; } =20 - virDomainHostdevDefFree(hostdev); + if (unplug) { + virDomainHostdevSubsysUSBPtr usbsrc =3D &hostdev->source.subsys.u.= usb; + usbsrc->bus =3D 0; + usbsrc->device =3D 0; + } else { + virDomainHostdevDefFree(hostdev); + } =20 if (net) { if (net->type =3D=3D VIR_DOMAIN_NET_TYPE_NETWORK) { @@ -4612,6 +4628,8 @@ qemuDomainRemoveHostDevice(virQEMUDriverPtr driver, virDomainNetDefFree(net); } =20 + hostdev->deleteAction =3D VIR_DOMAIN_HOSTDEV_DELETE_ACTION_NONE; + ret =3D 0; =20 cleanup: @@ -5084,6 +5102,7 @@ qemuDomainRemoveDevice(virQEMUDriverPtr driver, virDomainDeviceInfoPtr info; virObjectEventPtr event; VIR_AUTOFREE(char *) alias =3D NULL; + bool unplug; =20 /* * save the alias to use when sending a DEVICE_REMOVED event after @@ -5124,8 +5143,13 @@ qemuDomainRemoveDevice(virQEMUDriverPtr driver, return -1; break; case VIR_DOMAIN_DEVICE_HOSTDEV: + unplug =3D dev->data.hostdev->deleteAction =3D=3D VIR_DOMAIN_HOSTD= EV_DELETE_ACTION_UNPLUG; + if (qemuDomainRemoveHostDevice(driver, vm, dev->data.hostdev) < 0) return -1; + + if (unplug) + return 0; break; case VIR_DOMAIN_DEVICE_RNG: if (qemuDomainRemoveRNGDevice(driver, vm, dev->data.rng) < 0) --=20 2.23.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list