From nobody Sat May 4 15:06:47 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=fail(p=none dis=none) header.from=virtuozzo.com ARC-Seal: i=1; a=rsa-sha256; t=1571150020; cv=none; d=zoho.com; s=zohoarc; b=D3IvQWK6+0wkB5jD3skWSJZm7dsKzXEElbSiclSDV5h1PDMciYual+uXsDK8n7t/HduDTvtMnP1cVUo2hVQbOBD5zksduZVAVINFsgsYANq21e991wH/YrOFvnej7AHYFvDRE/8d47xu0FPid07Qoxv8R6eJXejEhfYE+tqnzcI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571150020; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=+jLiChfgkh0j17O1Li8pRGRDvPehc5SqsevKZpmcQfk=; b=kOiVJKcNXuQZ9NjM7lvKRm7P2Ui/6dauLkVZpZrEL50XTUyexyCVJSJ/yJbQK9goRyKq8XwqH4H7wVMmcsyUlpdKVOPfJXDEawLx/Q78P/UIRbQ3JRUxN4I106cJ/oM4Jdu2vueBou8zSpEiPOp2+Gh0q7v00tYCuOtnZnFnTMs= 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 1571150020241291.18058134098953; Tue, 15 Oct 2019 07:33:40 -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 ACDA51802189; Tue, 15 Oct 2019 14:33:38 +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 8148360A9D; Tue, 15 Oct 2019 14:33: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 37EDC180B536; Tue, 15 Oct 2019 14:33:38 +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 x9FEUBaD020789 for ; Tue, 15 Oct 2019 10:30:11 -0400 Received: by smtp.corp.redhat.com (Postfix) id E7B1060C5D; Tue, 15 Oct 2019 14:30:11 +0000 (UTC) Received: from mx1.redhat.com (ext-mx30.extmail.prod.ext.phx2.redhat.com [10.5.110.71]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E029460C57 for ; Tue, 15 Oct 2019 14:30:11 +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 CABA620E4 for ; Tue, 15 Oct 2019 14:30:09 +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 1iKNpv-0002Ve-Kr for libvir-list@redhat.com; Tue, 15 Oct 2019 17:30:07 +0300 From: Nikolay Shirokovskiy To: libvir-list@redhat.com Date: Tue, 15 Oct 2019 17:29:45 +0300 Message-Id: <20191015142956.30963-2-nshirokovskiy@virtuozzo.com> In-Reply-To: <20191015142956.30963-1-nshirokovskiy@virtuozzo.com> References: <20191015142956.30963-1-nshirokovskiy@virtuozzo.com> MIME-Version: 1.0 X-Greylist: Sender passed SPF test, ACL 264 matched, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.71]); Tue, 15 Oct 2019 14:30:10 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.71]); Tue, 15 Oct 2019 14:30:10 +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.84 on 10.5.110.71 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 REBASE 01/12] conf: add replug option for usb hostdev 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.6.2 (mx1.redhat.com [10.5.110.70]); Tue, 15 Oct 2019 14:33:39 +0000 (UTC) Content-Type: text/plain; charset="utf-8" If usb device attached to a domain is unplugged from host and then plugged back then it will no longer be available in guest. We are going to support this case so that device will be detached from qemu on unplug and attached back on replug. As sometimes this behaviour is not desirable and for backcompat too let's add 'replug' option for usb hostdev. Signed-off-by: Nikolay Shirokovskiy --- docs/formatdomain.html.in | 10 ++++- docs/schemas/domaincommon.rng | 5 +++ src/conf/domain_conf.c | 30 ++++++++++++++ src/conf/domain_conf.h | 2 + tests/qemuxml2argvdata/hostdev-usb-replug.xml | 36 +++++++++++++++++ .../qemuxml2xmloutdata/hostdev-usb-replug.xml | 40 +++++++++++++++++++ tests/qemuxml2xmltest.c | 1 + 7 files changed, 122 insertions(+), 2 deletions(-) create mode 100644 tests/qemuxml2argvdata/hostdev-usb-replug.xml create mode 100644 tests/qemuxml2xmloutdata/hostdev-usb-replug.xml diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in index 500f114f41..8e1c0bf6fa 100644 --- a/docs/formatdomain.html.in +++ b/docs/formatdomain.html.in @@ -4688,7 +4688,7 @@
 ...
 <devices>
-  <hostdev mode=3D'subsystem' type=3D'usb'>
+  <hostdev mode=3D'subsystem' type=3D'usb' replug=3D'yes'>
     <source startupPolicy=3D'optional'>
       <vendor id=3D'0x1234'/>
       <product id=3D'0xbeef'/>
@@ -4787,7 +4787,13 @@
           
usb
USB devices are detached from the host on guest startup and reattached after the guest exits or the device is - hot-unplugged. + hot-unplugged. If optional replug + (since 5.8.0) is "yes" then libvi= rt + tracks USB device unplug/plug on host. On unplug the correspon= dent + QEMU device will be be deleted but device stays in libvirt con= fig. + On plug the device will be added back to QEMU. This applies on= ly + for USB devices with product/vendor pair specified. Default va= lue + is "no".
pci
For PCI devices, when managed is "yes" it is diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng index ead5a25068..caba7f4e24 100644 --- a/docs/schemas/domaincommon.rng +++ b/docs/schemas/domaincommon.rng @@ -4658,6 +4658,11 @@ usb + + + + + diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 6bd2d4935d..c99758d9f5 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -7702,6 +7702,13 @@ virDomainHostdevSubsysUSBDefParseXML(xmlNodePtr node, goto out; } =20 + if (usbsrc->replug && (!got_vendor || !got_product)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("replug is only possible if vendor/product " + "pair is specified")); + goto out; + } + ret =3D 0; out: return ret; @@ -8155,12 +8162,14 @@ virDomainHostdevDefParseXMLSubsys(xmlNodePtr node, virDomainHostdevSubsysSCSIPtr scsisrc =3D &def->source.subsys.u.scsi; virDomainHostdevSubsysSCSIVHostPtr scsihostsrc =3D &def->source.subsys= .u.scsi_host; virDomainHostdevSubsysMediatedDevPtr mdevsrc =3D &def->source.subsys.u= .mdev; + virDomainHostdevSubsysUSBPtr usbsrc =3D &def->source.subsys.u.usb; VIR_AUTOFREE(char *) managed =3D NULL; VIR_AUTOFREE(char *) sgio =3D NULL; VIR_AUTOFREE(char *) rawio =3D NULL; VIR_AUTOFREE(char *) backendStr =3D NULL; VIR_AUTOFREE(char *) model =3D NULL; VIR_AUTOFREE(char *) display =3D NULL; + VIR_AUTOFREE(char *) replug =3D NULL; =20 /* @managed can be read from the xml document - it is always an * attribute of the toplevel element, no matter what type of @@ -8176,6 +8185,7 @@ virDomainHostdevDefParseXMLSubsys(xmlNodePtr node, rawio =3D virXMLPropString(node, "rawio"); model =3D virXMLPropString(node, "model"); display =3D virXMLPropString(node, "display"); + replug =3D virXMLPropString(node, "replug"); =20 /* @type is passed in from the caller rather than read from the * xml document, because it is specified in different places for @@ -8242,6 +8252,20 @@ virDomainHostdevDefParseXMLSubsys(xmlNodePtr node, } } =20 + if (replug) { + if (def->source.subsys.type !=3D VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_US= B) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("replug is only supported for usb host device= ")); + return -1; + } + + if ((usbsrc->replug =3D virTristateBoolTypeFromString(replug)) <= =3D 0) { + virReportError(VIR_ERR_XML_ERROR, + _("unknown hostdev replug setting '%s'"), rawio= ); + return -1; + } + } + if (def->source.subsys.type !=3D VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV && def->source.subsys.type !=3D VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI_H= OST) { if (model) { @@ -27220,6 +27244,7 @@ virDomainHostdevDefFormat(virBufferPtr buf, virDomainHostdevSubsysSCSIPtr scsisrc =3D &def->source.subsys.u.scsi; virDomainHostdevSubsysMediatedDevPtr mdevsrc =3D &def->source.subsys.u= .mdev; virDomainHostdevSubsysSCSIVHostPtr scsihostsrc =3D &def->source.subsys= .u.scsi_host; + virDomainHostdevSubsysUSBPtr usbsrc =3D &def->source.subsys.u.usb; const char *type; =20 if (!mode) { @@ -27284,6 +27309,11 @@ virDomainHostdevDefFormat(virBufferPtr buf, virTristateSwitchTypeToString(mdevsrc->d= isplay)); } =20 + if (def->source.subsys.type =3D=3D VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_= USB && + usbsrc->replug) { + virBufferAsprintf(buf, " replug=3D'%s'", + virTristateBoolTypeToString(usbsrc->replug)); + } } virBufferAddLit(buf, ">\n"); virBufferAdjustIndent(buf, 2); diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index e2edca149a..da3eff242b 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -230,6 +230,8 @@ struct _virDomainHostdevSubsysUSB { =20 unsigned vendor; unsigned product; + + bool replug; }; =20 struct _virDomainHostdevSubsysPCI { diff --git a/tests/qemuxml2argvdata/hostdev-usb-replug.xml b/tests/qemuxml2= argvdata/hostdev-usb-replug.xml new file mode 100644 index 0000000000..9647385667 --- /dev/null +++ b/tests/qemuxml2argvdata/hostdev-usb-replug.xml @@ -0,0 +1,36 @@ + + QEMUGuest1 + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219136 + 219136 + 1 + + hvm + + + + destroy + restart + destroy + + /usr/bin/qemu-system-i686 + + + + +
+ + + + + + + + + + + + + + + diff --git a/tests/qemuxml2xmloutdata/hostdev-usb-replug.xml b/tests/qemuxm= l2xmloutdata/hostdev-usb-replug.xml new file mode 100644 index 0000000000..5f4e39e2c4 --- /dev/null +++ b/tests/qemuxml2xmloutdata/hostdev-usb-replug.xml @@ -0,0 +1,40 @@ + + QEMUGuest1 + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219136 + 219136 + 1 + + hvm + + + + destroy + restart + destroy + + /usr/bin/qemu-system-i686 + + + + +
+ + +
+ + +
+ + + + + + + + + + + + + diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c index b9364f942f..4c275a939d 100644 --- a/tests/qemuxml2xmltest.c +++ b/tests/qemuxml2xmltest.c @@ -439,6 +439,7 @@ mymain(void) DO_TEST("channel-unix-source-path", NONE); =20 DO_TEST("hostdev-usb-address", NONE); + DO_TEST("hostdev-usb-replug", NONE); DO_TEST("hostdev-pci-address", NONE); DO_TEST("hostdev-pci-multifunction", NONE); DO_TEST("hostdev-vfio", NONE); --=20 2.23.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat May 4 15:06:47 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=fail(p=none dis=none) header.from=virtuozzo.com ARC-Seal: i=1; a=rsa-sha256; t=1571150142; cv=none; d=zoho.com; s=zohoarc; b=NlJYFGgEoLII05lTfHjYuEFXMv7NGInwR3Y+ToCgD3MTBn3vxHFow29NFsgw40yv/fMqwbCJXRCd/H6/z5phmdCn0rFzITpxPXXbNrf4D423I85zakk2C+YlNZJs0wrF0Mz5E3MjvDsOowXNt74N1meY4FG4jn0n6VB/2zrCNh8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571150142; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ncLVEi2mpVlbI+6ZhhpCSRvH09oLQoutq1aubshZPgQ=; b=L1aylhHZXooAB/hpk+x4ZDzN7GM8pqmFKDBgvgCla/60CaLf9PZsfpa9JqOYJI+gwzyU2woVjFnMi2pGARa380G9rKzrincFyNpV6icYsM/uHfx7+xoWyB1xdimaQaWf3Ps/Lk3uJmC/PyB+l1nOuQ446URKg/5Vv3SXRy0fhxQ= 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 1571150142573108.80871339846419; Tue, 15 Oct 2019 07:35:42 -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 C091410C0941; Tue, 15 Oct 2019 14:35:40 +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 8AE8860C5D; Tue, 15 Oct 2019 14:35: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 12A39180B536; Tue, 15 Oct 2019 14:35:40 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x9FEUEIf020823 for ; Tue, 15 Oct 2019 10:30:14 -0400 Received: by smtp.corp.redhat.com (Postfix) id 0DFF85DC1E; Tue, 15 Oct 2019 14:30:14 +0000 (UTC) Received: from mx1.redhat.com (ext-mx22.extmail.prod.ext.phx2.redhat.com [10.5.110.63]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 06A265DA8D for ; Tue, 15 Oct 2019 14:30:11 +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 CE32D18CB90F for ; Tue, 15 Oct 2019 14:30:09 +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 1iKNpv-0002Ve-S7 for libvir-list@redhat.com; Tue, 15 Oct 2019 17:30:07 +0300 From: Nikolay Shirokovskiy To: libvir-list@redhat.com Date: Tue, 15 Oct 2019 17:29:46 +0300 Message-Id: <20191015142956.30963-3-nshirokovskiy@virtuozzo.com> In-Reply-To: <20191015142956.30963-1-nshirokovskiy@virtuozzo.com> References: <20191015142956.30963-1-nshirokovskiy@virtuozzo.com> MIME-Version: 1.0 X-Greylist: Sender passed SPF test, ACL 264 matched, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.63]); Tue, 15 Oct 2019 14:30:10 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.63]); Tue, 15 Oct 2019 14:30:10 +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.84 on 10.5.110.63 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 REBASE 02/12] qemu: track hostdev delete intention 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.6.2 (mx1.redhat.com [10.5.110.66]); Tue, 15 Oct 2019 14:35:41 +0000 (UTC) Content-Type: text/plain; charset="utf-8" So we are going to support replug of usb device on host. We need to delete device from qemu when the device is unplugged on host and to add device when the device is plugged back. As to deleting let's use same code as when we detach device from domain. But we need to keep the usb hostdev etc in libvirt config when handle DEVICE_DELETED event from qemu. For this purpose let's save delete intention in device config. Signed-off-by: Nikolay Shirokovskiy --- src/conf/domain_conf.h | 14 ++++++++++++++ src/qemu/qemu_driver.c | 4 ++-- src/qemu/qemu_hotplug.c | 23 ++++++++++++++++++++--- src/qemu/qemu_hotplug.h | 3 ++- tests/qemuhotplugtest.c | 2 +- 5 files changed, 39 insertions(+), 7 deletions(-) diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index da3eff242b..0a16413852 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -328,6 +328,19 @@ struct _virDomainHostdevCaps { } u; }; =20 +typedef enum { + VIR_DOMAIN_HOSTDEV_DELETE_ACTION_NONE =3D 0, + /* delete associated device from libvirt config + * as intended by client API call */ + VIR_DOMAIN_HOSTDEV_DELETE_ACTION_DELETE, + /* keep associated device in libvirt config as + * qemu device is deleted as a result of unplugging + * device from host */ + VIR_DOMAIN_HOSTDEV_DELETE_ACTION_UNPLUG, + + VIR_DOMAIN_HOSTDEV_DELETE_ACTION_LAST +} virDomainHostdevDeleteActionType; + =20 /* basic device for direct passthrough */ struct _virDomainHostdevDef { @@ -345,6 +358,7 @@ struct _virDomainHostdevDef { bool missing; bool readonly; bool shareable; + virDomainHostdevDeleteActionType deleteAction; union { virDomainHostdevSubsys subsys; virDomainHostdevCaps caps; diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 681b26814b..ca40879977 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -9078,7 +9078,7 @@ qemuDomainDetachDeviceLiveAndConfig(virQEMUDriverPtr = driver, if (flags & VIR_DOMAIN_AFFECT_LIVE) { int rc; =20 - if ((rc =3D qemuDomainDetachDeviceLive(vm, dev_copy, driver, false= )) < 0) + if ((rc =3D qemuDomainDetachDeviceLive(vm, dev_copy, driver, false= , false)) < 0) goto cleanup; =20 if (rc =3D=3D 0 && qemuDomainUpdateDeviceList(driver, vm, QEMU_ASY= NC_JOB_NONE) < 0) @@ -9167,7 +9167,7 @@ qemuDomainDetachDeviceAliasLiveAndConfig(virQEMUDrive= rPtr driver, if (virDomainDefFindDevice(def, alias, &dev, true) < 0) goto cleanup; =20 - if ((rc =3D qemuDomainDetachDeviceLive(vm, &dev, driver, true)) < = 0) + if ((rc =3D qemuDomainDetachDeviceLive(vm, &dev, driver, true, fal= se)) < 0) goto cleanup; =20 if (rc =3D=3D 0 && qemuDomainUpdateDeviceList(driver, vm, QEMU_ASY= NC_JOB_NONE) < 0) diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 88984dff67..4f7858da71 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -5351,7 +5351,8 @@ qemuDomainDetachPrepController(virDomainObjPtr vm, static int qemuDomainDetachPrepHostdev(virDomainObjPtr vm, virDomainHostdevDefPtr match, - virDomainHostdevDefPtr *detach) + virDomainHostdevDefPtr *detach, + bool unplug) { virDomainHostdevSubsysPtr subsys =3D &match->source.subsys; virDomainHostdevSubsysUSBPtr usbsrc =3D &subsys->u.usb; @@ -5423,6 +5424,20 @@ qemuDomainDetachPrepHostdev(virDomainObjPtr vm, return -1; } =20 + /* + * Why having additional check in second branch? Suppose client + * asks for device detaching and we delete device from qemu + * but don't get DEVICE_DELETED event yet. Next USB is unplugged + * from host and we have this function called again. If we reset + * delete action to 'unplug' then device will be left in + * libvirt config after handling DEVICE_DELETED event while + * it should not as client asked to detach the device before. + */ + if (!unplug) + hostdev->deleteAction =3D VIR_DOMAIN_HOSTDEV_DELETE_ACTION_DELETE; + else if (hostdev->deleteAction !=3D VIR_DOMAIN_HOSTDEV_DELETE_ACTION_D= ELETE) + hostdev->deleteAction =3D VIR_DOMAIN_HOSTDEV_DELETE_ACTION_UNPLUG; + return 0; } =20 @@ -5724,7 +5739,8 @@ int qemuDomainDetachDeviceLive(virDomainObjPtr vm, virDomainDeviceDefPtr match, virQEMUDriverPtr driver, - bool async) + bool async, + bool unplug) { virDomainDeviceDef detach =3D { .type =3D match->type }; virDomainDeviceInfoPtr info =3D NULL; @@ -5769,7 +5785,8 @@ qemuDomainDetachDeviceLive(virDomainObjPtr vm, break; case VIR_DOMAIN_DEVICE_HOSTDEV: if (qemuDomainDetachPrepHostdev(vm, match->data.hostdev, - &detach.data.hostdev) < 0) { + &detach.data.hostdev, + unplug) < 0) { return -1; } break; diff --git a/src/qemu/qemu_hotplug.h b/src/qemu/qemu_hotplug.h index 6d2cd34dbc..647f617355 100644 --- a/src/qemu/qemu_hotplug.h +++ b/src/qemu/qemu_hotplug.h @@ -116,7 +116,8 @@ int qemuDomainAttachRNGDevice(virQEMUDriverPtr driver, int qemuDomainDetachDeviceLive(virDomainObjPtr vm, virDomainDeviceDefPtr match, virQEMUDriverPtr driver, - bool async); + bool async, + bool unplug); =20 void qemuDomainRemoveVcpuAlias(virQEMUDriverPtr driver, virDomainObjPtr vm, diff --git a/tests/qemuhotplugtest.c b/tests/qemuhotplugtest.c index 76b131295a..ec58d89e01 100644 --- a/tests/qemuhotplugtest.c +++ b/tests/qemuhotplugtest.c @@ -158,7 +158,7 @@ testQemuHotplugDetach(virDomainObjPtr vm, case VIR_DOMAIN_DEVICE_SHMEM: case VIR_DOMAIN_DEVICE_WATCHDOG: case VIR_DOMAIN_DEVICE_HOSTDEV: - ret =3D qemuDomainDetachDeviceLive(vm, dev, &driver, async); + ret =3D qemuDomainDetachDeviceLive(vm, dev, &driver, async, false); break; default: VIR_TEST_VERBOSE("device type '%s' cannot be detached", --=20 2.23.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat May 4 15:06:47 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=fail(p=none dis=none) header.from=virtuozzo.com ARC-Seal: i=1; a=rsa-sha256; t=1571150016; cv=none; d=zoho.com; s=zohoarc; b=naMuGEufb8lqZMDK0CnJOADjQF+SsJ3Bq809BJfAB/Z6kumF6VtqVjuIZ7qV0j+CtWNqQRndLM30Neqc4PIyrXXUVQ/PUmNbHz8Truxubd5qNTCvLkV9ZZyYAwXh9KNYRSYSINCR+7faXBwInAf3KOMvX4JnqmtCJrIDU4Dphy0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571150016; 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; bh=8+3Is1ZKhvsBS4jldRiQFo/XjO3IEnMNpwQoGDLGS/U=; b=kU5e1nlhUe1V9RknhAw4vYnn7FxSA/RIDJjxCUFvFijjPkkA9tuTT1/lFDxHQtQ2lWQUyIVi7lnRwfCHtUOIvFQxpSwH97dOorZBzF1JH9RH514H6CWk27IVvjO7Off+4PvSWLU6tWDnidKy2SghwD8A+PZk5ADodcAISUtmqOY= 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 1571150016515278.7342859706007; Tue, 15 Oct 2019 07:33:36 -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 E94EDC057F2E; Tue, 15 Oct 2019 14:33:34 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BBAE760605; Tue, 15 Oct 2019 14:33:34 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 71A1F4EE68; Tue, 15 Oct 2019 14:33:34 +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 x9FEUBsi020776 for ; Tue, 15 Oct 2019 10:30:11 -0400 Received: by smtp.corp.redhat.com (Postfix) id A566760C57; Tue, 15 Oct 2019 14:30:11 +0000 (UTC) Received: from mx1.redhat.com (ext-mx28.extmail.prod.ext.phx2.redhat.com [10.5.110.69]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9A5F860BE2 for ; Tue, 15 Oct 2019 14:30:11 +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 F232F8E1CEF for ; Tue, 15 Oct 2019 14:30:09 +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 1iKNpv-0002Ve-Vl; Tue, 15 Oct 2019 17:30:08 +0300 From: Nikolay Shirokovskiy To: libvir-list@redhat.com Date: Tue, 15 Oct 2019 17:29:47 +0300 Message-Id: <20191015142956.30963-4-nshirokovskiy@virtuozzo.com> In-Reply-To: <20191015142956.30963-1-nshirokovskiy@virtuozzo.com> References: <20191015142956.30963-1-nshirokovskiy@virtuozzo.com> MIME-Version: 1.0 X-Greylist: Sender passed SPF test, ACL 264 matched, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.69]); Tue, 15 Oct 2019 14:30:10 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.69]); Tue, 15 Oct 2019 14:30:10 +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.84 on 10.5.110.69 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 REBASE 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.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Tue, 15 Oct 2019 14:33:35 +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 4f7858da71..0e161bfd5a 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -4400,7 +4400,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 @@ -4441,6 +4442,7 @@ qemuDomainRemoveHostDevice(virQEMUDriverPtr driver, VIR_AUTOFREE(char *) drivealias =3D NULL; VIR_AUTOFREE(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); @@ -4488,16 +4490,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 @@ -4531,7 +4541,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) { @@ -4546,6 +4562,8 @@ qemuDomainRemoveHostDevice(virQEMUDriverPtr driver, virDomainNetDefFree(net); } =20 + hostdev->deleteAction =3D VIR_DOMAIN_HOSTDEV_DELETE_ACTION_NONE; + return 0; } =20 @@ -4984,6 +5002,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 @@ -5024,8 +5043,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 From nobody Sat May 4 15:06:47 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=fail(p=none dis=none) header.from=virtuozzo.com ARC-Seal: i=1; a=rsa-sha256; t=1571150013; cv=none; d=zoho.com; s=zohoarc; b=TvbSsBtdzANtxSEEfsYuUEcXC7t2hlcGvnv3DjiKsIytEQzKEGB2ASU1kd/WcLXuiuhk0iieETSgJ187nSuEoD05Wcclqz/46Kgp2UKuN8mtuClwFmQ+f3kgHtX30QsBnM0lx+cSsXQlEkLrjOFvdHWjK8FPimdPQ/nv69d0IxQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571150013; 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; bh=n8rXUzXUC3Kfb5BAY7oVtG/YHHD5Rs2ZRGC15+wesU4=; b=I/eCx78J95Nbcf3nFlCI0apersMyuEdRgUTyQ45hpWGuOBcV6+9KNvi1+C2ePYYAL7SSipSfU25k80a9g0ZX47aKoVN//miCCoFB4VpJMV/9VFYupB1yDvjTWaFai8GZAyZPSOa3lm4TyLSNLOawJEEk2S9FNa4X6w5bEzTGk9I= 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 1571150013408296.6499016138648; Tue, 15 Oct 2019 07:33:33 -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 6AC481801EC9; Tue, 15 Oct 2019 14:33: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 34A5A60166; Tue, 15 Oct 2019 14:33:31 +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 C92AA1803518; Tue, 15 Oct 2019 14:33:30 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x9FEUDdR020807 for ; Tue, 15 Oct 2019 10:30:14 -0400 Received: by smtp.corp.redhat.com (Postfix) id C989C6031D; Tue, 15 Oct 2019 14:30:13 +0000 (UTC) Received: from mx1.redhat.com (ext-mx12.extmail.prod.ext.phx2.redhat.com [10.5.110.41]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BF271601A5 for ; Tue, 15 Oct 2019 14:30:11 +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 C85DC315C036 for ; Tue, 15 Oct 2019 14:30:09 +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 1iKNpw-0002Ve-22; Tue, 15 Oct 2019 17:30:08 +0300 From: Nikolay Shirokovskiy To: libvir-list@redhat.com Date: Tue, 15 Oct 2019 17:29:48 +0300 Message-Id: <20191015142956.30963-5-nshirokovskiy@virtuozzo.com> In-Reply-To: <20191015142956.30963-1-nshirokovskiy@virtuozzo.com> References: <20191015142956.30963-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.41]); Tue, 15 Oct 2019 14:30:10 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Tue, 15 Oct 2019 14:30:10 +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.84 on 10.5.110.41 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza Subject: [libvirt] [PATCH v3 REBASE 04/12] qemu: support usb hostdev plugging back 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.6.2 (mx1.redhat.com [10.5.110.70]); Tue, 15 Oct 2019 14:33:32 +0000 (UTC) Content-Type: text/plain; charset="utf-8" We are going to use qemuDomainAttachHostUSBDevice when host usb device is plugged back to node. Signed-off-by: Nikolay Shirokovskiy Reviewed-by: Daniel Henrique Barboza --- src/qemu/qemu_hotplug.c | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 0e161bfd5a..920e0cb72b 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -2478,8 +2478,18 @@ qemuDomainAttachHostUSBDevice(virQEMUDriverPtr drive= r, bool teardownlabel =3D false; bool teardowndevice =3D false; int ret =3D -1; + bool replug =3D false; + size_t i; + + for (i =3D 0; i < vm->def->nhostdevs; i++) { + if (vm->def->hostdevs[i] =3D=3D hostdev) { + replug =3D true; + break; + } + } =20 - if (virDomainUSBAddressEnsure(priv->usbaddrs, hostdev->info) < 0) + if (!replug && + virDomainUSBAddressEnsure(priv->usbaddrs, hostdev->info) < 0) return -1; =20 if (qemuHostdevPrepareUSBDevices(driver, vm->def->name, &hostdev, 1, 0= ) < 0) @@ -2504,7 +2514,7 @@ qemuDomainAttachHostUSBDevice(virQEMUDriverPtr driver, if (!(devstr =3D qemuBuildUSBHostdevDevStr(vm->def, hostdev, priv->qem= uCaps))) goto cleanup; =20 - if (VIR_REALLOC_N(vm->def->hostdevs, vm->def->nhostdevs+1) < 0) + if (!replug && VIR_REALLOC_N(vm->def->hostdevs, vm->def->nhostdevs+1) = < 0) goto cleanup; =20 qemuDomainObjEnterMonitor(driver, vm); @@ -2517,7 +2527,8 @@ qemuDomainAttachHostUSBDevice(virQEMUDriverPtr driver, if (ret < 0) goto cleanup; =20 - vm->def->hostdevs[vm->def->nhostdevs++] =3D hostdev; + if (!replug) + vm->def->hostdevs[vm->def->nhostdevs++] =3D hostdev; =20 ret =3D 0; cleanup: @@ -2530,9 +2541,17 @@ qemuDomainAttachHostUSBDevice(virQEMUDriverPtr drive= r, if (teardowndevice && qemuDomainNamespaceTeardownHostdev(vm, hostdev) < 0) VIR_WARN("Unable to remove host device from /dev"); - if (added) + if (added) { qemuHostdevReAttachUSBDevices(driver, vm->def->name, &hostdev,= 1); - virDomainUSBAddressRelease(priv->usbaddrs, hostdev->info); + + if (replug) { + virDomainHostdevSubsysUSBPtr usbsrc =3D &hostdev->source.s= ubsys.u.usb; + usbsrc->bus =3D 0; + usbsrc->device =3D 0; + } + } + if (!replug) + virDomainUSBAddressRelease(priv->usbaddrs, hostdev->info); } return ret; } --=20 2.23.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat May 4 15:06:47 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=fail(p=none dis=none) header.from=virtuozzo.com ARC-Seal: i=1; a=rsa-sha256; t=1571150024; cv=none; d=zoho.com; s=zohoarc; b=KMsMhHmMD8Ml8OdXYLPivsAiOcx30bOGDTGr7QkurRZG9CywG0Mo7OJU9wISTcoi7ztLFMqri5Azfvbx5oHgb12SxAQwAU+pQU7hb7NQSbcHGJnNJ1PCBEKz62/ASe3XG/I7WZWwar9FL2cwWNQGk2nQqZ/X9PA4CmjWbI0BQxE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571150024; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=o4sG3KShm2TR7AYMJTsCPyJOjabaRj5g3xseERK0RZg=; b=UWyrb8G6YMkGpw9HcR6fNXzh9O6lEo+ca6d0ozg0cBE/jIpNW6ECkp/Zo+hhpXqQyJL6Cz5Cl5XBkQkD4tSNCTEWpIfkUQfZ0cf8iJXTwUeqqRYxVTIhRX5XKOuqnxxdoP5W38phYm7l9w9VAGQYypF0MCxzoUr/MOPcz7ZzM/U= 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 1571150024215728.4281147085991; Tue, 15 Oct 2019 07:33:44 -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 96782A3CD8E; Tue, 15 Oct 2019 14:33: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 67B88100EBD7; Tue, 15 Oct 2019 14:33: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 200B3180BA99; Tue, 15 Oct 2019 14:33:42 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x9FEUDO3020804 for ; Tue, 15 Oct 2019 10:30:13 -0400 Received: by smtp.corp.redhat.com (Postfix) id C6D95601AF; Tue, 15 Oct 2019 14:30:13 +0000 (UTC) Received: from mx1.redhat.com (ext-mx23.extmail.prod.ext.phx2.redhat.com [10.5.110.64]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BE1FF6013A for ; Tue, 15 Oct 2019 14:30:11 +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 CE28D1056F91 for ; Tue, 15 Oct 2019 14:30:09 +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 1iKNpw-0002Ve-5t for libvir-list@redhat.com; Tue, 15 Oct 2019 17:30:08 +0300 From: Nikolay Shirokovskiy To: libvir-list@redhat.com Date: Tue, 15 Oct 2019 17:29:49 +0300 Message-Id: <20191015142956.30963-6-nshirokovskiy@virtuozzo.com> In-Reply-To: <20191015142956.30963-1-nshirokovskiy@virtuozzo.com> References: <20191015142956.30963-1-nshirokovskiy@virtuozzo.com> MIME-Version: 1.0 X-Greylist: Sender passed SPF test, ACL 264 matched, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.64]); Tue, 15 Oct 2019 14:30:10 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.64]); Tue, 15 Oct 2019 14:30:10 +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.84 on 10.5.110.64 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 REBASE 05/12] qemu: handle host usb device add/del udev events 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.6.2 (mx1.redhat.com [10.5.110.68]); Tue, 15 Oct 2019 14:33:43 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Now when code handling attaching/detaching usb hostdev is appropriately changed use it to handle host usb device udev add/del events. As device adding/deleting needs acquiring job condition it is done in thread pool rather in event loop thread itself where udev events are delivered. However implementation in this patch is a bit different from other places as we instead of finding right domain in event loop thread and creating a single thread pool job create job for every vm. Such a strategy allows us to avoid taking domain lock in event loop thread so we have little chances to block event loop thread because some API handler grabs domain lock for a significant amount of time. Signed-off-by: Nikolay Shirokovskiy --- src/qemu/Makefile.inc.am | 2 + src/qemu/qemu_conf.h | 3 + src/qemu/qemu_domain.c | 2 + src/qemu/qemu_domain.h | 2 + src/qemu/qemu_driver.c | 324 ++++++++++++++++++++++++++++++++++++++- 5 files changed, 332 insertions(+), 1 deletion(-) diff --git a/src/qemu/Makefile.inc.am b/src/qemu/Makefile.inc.am index e66da76c0a..49b0202a11 100644 --- a/src/qemu/Makefile.inc.am +++ b/src/qemu/Makefile.inc.am @@ -98,6 +98,7 @@ libvirt_driver_qemu_impl_la_CFLAGS =3D \ -I$(srcdir)/conf \ -I$(srcdir)/secret \ $(AM_CFLAGS) \ + $(UDEV_CFLAGS) \ $(NULL) libvirt_driver_qemu_impl_la_LDFLAGS =3D $(AM_LDFLAGS) libvirt_driver_qemu_impl_la_LIBADD =3D \ @@ -106,6 +107,7 @@ libvirt_driver_qemu_impl_la_LIBADD =3D \ $(LIBNL_LIBS) \ $(SELINUX_LIBS) \ $(LIBXML_LIBS) \ + $(UDEV_LIBS) \ $(NULL) libvirt_driver_qemu_impl_la_SOURCES =3D $(QEMU_DRIVER_SOURCES) =20 diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h index 7247199d3e..23c9b4d9fa 100644 --- a/src/qemu/qemu_conf.h +++ b/src/qemu/qemu_conf.h @@ -299,6 +299,9 @@ struct _virQEMUDriver { =20 /* Immutable pointer, self-locking APIs */ virHashAtomicPtr migrationErrors; + + struct udev_monitor *udev_monitor; + int udev_watch; }; =20 virQEMUDriverConfigPtr virQEMUDriverConfigNew(bool privileged); diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index a6c95b7208..61c0c0e143 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -15335,6 +15335,8 @@ qemuProcessEventFree(struct qemuProcessEvent *event) case QEMU_PROCESS_EVENT_SERIAL_CHANGED: case QEMU_PROCESS_EVENT_BLOCK_JOB: case QEMU_PROCESS_EVENT_MONITOR_EOF: + case QEMU_PROCESS_EVENT_USB_REMOVED: + case QEMU_PROCESS_EVENT_USB_ADDED: VIR_FREE(event->data); break; case QEMU_PROCESS_EVENT_JOB_STATUS_CHANGE: diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h index 282ab2c3ec..3ba8b059ec 100644 --- a/src/qemu/qemu_domain.h +++ b/src/qemu/qemu_domain.h @@ -549,6 +549,8 @@ typedef enum { QEMU_PROCESS_EVENT_MONITOR_EOF, QEMU_PROCESS_EVENT_PR_DISCONNECT, QEMU_PROCESS_EVENT_RDMA_GID_STATUS_CHANGED, + QEMU_PROCESS_EVENT_USB_REMOVED, + QEMU_PROCESS_EVENT_USB_ADDED, =20 QEMU_PROCESS_EVENT_LAST } qemuProcessEventType; diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index ca40879977..1110e11c14 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -34,6 +34,7 @@ #include #include #include +#include =20 =20 #include "qemu_driver.h" @@ -657,6 +658,221 @@ qemuDomainFindMaxID(virDomainObjPtr vm, } =20 =20 +struct qemuUdevUSBRemoveData { + unsigned int bus; + unsigned int device; +}; + +struct qemuUdevUSBAddData { + unsigned int vendor; + unsigned int product; +}; + +struct qemuUdevUSBEventData { + union { + struct qemuUdevUSBRemoveData remove; + struct qemuUdevUSBAddData add; + } data; + bool remove; +}; + +static int +qemuUdevUSBHandleEvent(virDomainObjPtr vm, void *opaque) +{ + struct qemuUdevUSBEventData *data =3D opaque; + struct qemuProcessEvent *event =3D NULL; + + if (VIR_ALLOC(event) < 0) + return 0; + + if (data->remove) { + struct qemuUdevUSBRemoveData *rm_data; + + + if (VIR_ALLOC(rm_data) < 0) + goto cleanup; + + *rm_data =3D data->data.remove; + event->data =3D rm_data; + event->eventType =3D QEMU_PROCESS_EVENT_USB_REMOVED; + } else { + struct qemuUdevUSBAddData *add_data; + + if (VIR_ALLOC(add_data) < 0) + goto cleanup; + + *add_data =3D data->data.add; + event->data =3D add_data; + event->eventType =3D QEMU_PROCESS_EVENT_USB_ADDED; + } + + event->vm =3D virObjectRef(vm); + + if (virThreadPoolSendJob(qemu_driver->workerPool, 0, event) < 0) { + virObjectUnref(vm); + goto cleanup; + } + + event =3D NULL; + + cleanup: + qemuProcessEventFree(event); + + return 0; +} + + +static void +qemuUdevEventHandleCallback(int watch G_GNUC_UNUSED, + int fd G_GNUC_UNUSED, + int events G_GNUC_UNUSED, + void *data G_GNUC_UNUSED) +{ + struct qemuUdevUSBEventData event_data; + struct udev_device *dev =3D NULL; + const char *action; + const char *devtype; + const char *tmp; + + /* libvirtd daemon do not run event loop before full state drivers + * initialization. Also state drivers uninitialized only after + * full stop of event loop. In short driver initialization/uninitializ= ation + * and handling events occurs in same main loop thread. Thus we + * don't need any locking here. */ + + if (!(dev =3D udev_monitor_receive_device(qemu_driver->udev_monitor)))= { + VIR_WARNINGS_NO_WLOGICALOP_EQUAL_EXPR + if (errno =3D=3D EAGAIN || errno =3D=3D EWOULDBLOCK) { + VIR_WARNINGS_RESET + return; + } + + virReportSystemError(errno, "%s", + _("failed to receive device from udev monitor= ")); + return; + } + + devtype =3D udev_device_get_devtype(dev); + + if (STRNEQ_NULLABLE(devtype, "usb_device")) + goto cleanup; + + if (!(action =3D udev_device_get_action(dev))) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("failed to receive action from udev monitor")); + goto cleanup; + } + + if (STREQ(action, "remove")) { + struct qemuUdevUSBRemoveData *rm_data =3D &event_data.data.remove; + + if (!(tmp =3D udev_device_get_property_value(dev, "BUSNUM"))) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("failed to receive busnum from udev monitor")= ); + goto cleanup; + } + if (virStrToLong_ui(tmp, NULL, 10, &rm_data->bus) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Failed to convert busnum to int")); + goto cleanup; + } + + if (!(tmp =3D udev_device_get_property_value(dev, "DEVNUM"))) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("failed to receive devnum from udev monitor")= ); + goto cleanup; + } + if (virStrToLong_ui(tmp, NULL, 10, &rm_data->device) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Failed to convert devnum to int")); + goto cleanup; + } + event_data.remove =3D true; + } else if (STREQ(action, "add")) { + struct qemuUdevUSBAddData *add_data =3D &event_data.data.add; + + if (!(tmp =3D udev_device_get_property_value(dev, "ID_VENDOR_ID"))= ) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("failed to receive vendor from udev monitor")= ); + goto cleanup; + } + if (virStrToLong_ui(tmp, NULL, 16, &add_data->vendor) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Failed to convert vendor to int")); + goto cleanup; + } + + if (!(tmp =3D udev_device_get_property_value(dev, "ID_MODEL_ID")))= { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("failed to receive product from udev monitor"= )); + goto cleanup; + } + if (virStrToLong_ui(tmp, NULL, 16, &add_data->product) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Failed to convert product to int")); + goto cleanup; + } + event_data.remove =3D false; + } else { + goto cleanup; + } + + virDomainObjListForEach(qemu_driver->domains, false, qemuUdevUSBHandle= Event, &event_data); + + cleanup: + udev_device_unref(dev); +} + + +static int +qemuUdevInitialize(void) +{ + struct udev *udev; + + if (!(udev =3D udev_new())) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("failed to create udev context")); + return -1; + } + + if (!(qemu_driver->udev_monitor =3D udev_monitor_new_from_netlink(udev= , "udev"))) { + udev_unref(udev); + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("udev_monitor_new_from_netlink returned NULL")); + return -1; + } + + udev_monitor_enable_receiving(qemu_driver->udev_monitor); + + qemu_driver->udev_watch =3D virEventAddHandle(udev_monitor_get_fd(qemu= _driver->udev_monitor), + VIR_EVENT_HANDLE_READABLE, + qemuUdevEventHandleCallbac= k, NULL, NULL); + + if (qemu_driver->udev_watch < 0) + return -1; + + return 0; +} + + +static void +qemuUdevCleanup(void) +{ + if (qemu_driver->udev_monitor) { + struct udev *udev =3D udev_monitor_get_udev(qemu_driver->udev_moni= tor); + + udev_monitor_unref(qemu_driver->udev_monitor); + udev_unref(udev); + qemu_driver->udev_monitor =3D NULL; + } + + if (qemu_driver->udev_watch > 0) { + virEventRemoveHandle(qemu_driver->udev_watch); + qemu_driver->udev_watch =3D 0; + } +} + + /** * qemuStateInitialize: * @@ -981,6 +1197,9 @@ qemuStateInitialize(bool privileged, if (!(qemu_driver->closeCallbacks =3D virCloseCallbacksNew())) goto error; =20 + if (qemuUdevInitialize() < 0) + goto error; + /* Get all the running persistent or transient configs first */ if (virDomainObjListLoadAllConfigs(qemu_driver->domains, cfg->stateDir, @@ -1199,6 +1418,8 @@ qemuStateCleanup(void) =20 virLockManagerPluginUnref(qemu_driver->lockManager); =20 + qemuUdevCleanup(); + virMutexDestroy(&qemu_driver->lock); VIR_FREE(qemu_driver); =20 @@ -4959,7 +5180,102 @@ processRdmaGidStatusChangedEvent(virDomainObjPtr vm, } =20 =20 -static void qemuProcessEventHandler(void *data, void *opaque) +static void +processUSBAddedEvent(virQEMUDriverPtr driver, + virDomainObjPtr vm, + struct qemuUdevUSBAddData *data) +{ + virDomainHostdevDefPtr hostdev; + virDomainHostdevSubsysUSBPtr usbsrc; + size_t i; + + if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY) < 0) + return; + + if (!virDomainObjIsActive(vm)) { + VIR_DEBUG("Domain is not running"); + goto cleanup; + } + + for (i =3D 0; i < vm->def->nhostdevs; i++) { + hostdev =3D vm->def->hostdevs[i]; + + if (hostdev->source.subsys.type !=3D VIR_DOMAIN_HOSTDEV_SUBSYS_TYP= E_USB) + continue; + + usbsrc =3D &hostdev->source.subsys.u.usb; + + if (!usbsrc->replug) + continue; + + if (usbsrc->vendor =3D=3D data->vendor && usbsrc->product =3D=3D d= ata->product) + break; + } + + if (i =3D=3D vm->def->nhostdevs) + goto cleanup; + + if (qemuDomainAttachHostDevice(driver, vm, hostdev) < 0) + goto cleanup; + + cleanup: + qemuDomainObjEndJob(driver, vm); +} + + +static void +processUSBRemovedEvent(virQEMUDriverPtr driver, + virDomainObjPtr vm, + struct qemuUdevUSBRemoveData *data) +{ + size_t i; + virDomainHostdevDefPtr hostdev; + virDomainDeviceDef dev =3D { .type =3D VIR_DOMAIN_DEVICE_HOSTDEV }; + + if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY) < 0) + return; + + if (!virDomainObjIsActive(vm)) { + VIR_DEBUG("Domain is not running"); + goto cleanup; + } + + for (i =3D 0; i < vm->def->nhostdevs; i++) { + virDomainHostdevSubsysUSBPtr usbsrc; + + hostdev =3D vm->def->hostdevs[i]; + if (hostdev->source.subsys.type !=3D VIR_DOMAIN_HOSTDEV_SUBSYS_TYP= E_USB) + continue; + + usbsrc =3D &hostdev->source.subsys.u.usb; + + if (!usbsrc->replug) + continue; + + /* don't mess with devices that don't use stable host addressing + * with respect to unplug/plug to host + */ + if (!usbsrc->vendor || !usbsrc->product) + continue; + + if (usbsrc->bus =3D=3D data->bus && usbsrc->device =3D=3D data->de= vice) + break; + } + + if (i =3D=3D vm->def->nhostdevs) + goto cleanup; + + dev.data.hostdev =3D hostdev; + if (qemuDomainDetachDeviceLive(vm, &dev, driver, true, true) < 0) + goto cleanup; + + cleanup: + qemuDomainObjEndJob(driver, vm); +} + + +static void +qemuProcessEventHandler(void *data, void *opaque) { struct qemuProcessEvent *processEvent =3D data; virDomainObjPtr vm =3D processEvent->vm; @@ -5005,6 +5321,12 @@ static void qemuProcessEventHandler(void *data, void= *opaque) case QEMU_PROCESS_EVENT_RDMA_GID_STATUS_CHANGED: processRdmaGidStatusChangedEvent(vm, processEvent->data); break; + case QEMU_PROCESS_EVENT_USB_REMOVED: + processUSBRemovedEvent(driver, vm, processEvent->data); + break; + case QEMU_PROCESS_EVENT_USB_ADDED: + processUSBAddedEvent(driver, vm, processEvent->data); + break; case QEMU_PROCESS_EVENT_LAST: break; } --=20 2.23.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat May 4 15:06:47 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=fail(p=none dis=none) header.from=virtuozzo.com ARC-Seal: i=1; a=rsa-sha256; t=1571150027; cv=none; d=zoho.com; s=zohoarc; b=XRYzbgPisSfyNwcZoqV/+OJ/anHkBFancdZh4P0cofcdVB+LU52MJnzPSE4es6YHqeqpYgu7el0oZBSesuT+U7ZmQP0VW5VrvciK9a3roVkgDfuVVL1UiaxSQihJTqSjObXX+GQiIo8Qljo7RN+3mFLCYSRC+YLjYF3Tk+glx3E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571150027; 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; bh=J5xqGPLkxRhMKLqAeC1fnx6wa6Xy/At1/BiFQNrVdLs=; b=D5yMlDWQrVNObjRg0xr21wvH6NjQU2hZ3jbKf0dLVFLDOpMvcyTiQUbIRSD773sJW4AjaLw+cx5vz0QjuRUkcm6bR8hPXqLvGYY1yCSrXVttOh2f2a5bPi9ko/8miUisx+CrMsppTKyADmaaTdWRs2FK4bgQui0I71zrPnrBj2s= 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 1571150027858376.9538126680102; Tue, 15 Oct 2019 07:33:47 -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 356A918C427E; Tue, 15 Oct 2019 14:33: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 07C0B100EBD5; Tue, 15 Oct 2019 14:33: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 B07244EE6A; Tue, 15 Oct 2019 14:33:45 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x9FEUDR1020805 for ; Tue, 15 Oct 2019 10:30:13 -0400 Received: by smtp.corp.redhat.com (Postfix) id C662560127; Tue, 15 Oct 2019 14:30:13 +0000 (UTC) Received: from mx1.redhat.com (ext-mx23.extmail.prod.ext.phx2.redhat.com [10.5.110.64]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BE4E860166 for ; Tue, 15 Oct 2019 14:30:11 +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 DA6C81056F94 for ; Tue, 15 Oct 2019 14:30:09 +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 1iKNpw-0002Ve-AN; Tue, 15 Oct 2019 17:30:08 +0300 From: Nikolay Shirokovskiy To: libvir-list@redhat.com Date: Tue, 15 Oct 2019 17:29:50 +0300 Message-Id: <20191015142956.30963-7-nshirokovskiy@virtuozzo.com> In-Reply-To: <20191015142956.30963-1-nshirokovskiy@virtuozzo.com> References: <20191015142956.30963-1-nshirokovskiy@virtuozzo.com> MIME-Version: 1.0 X-Greylist: Sender passed SPF test, ACL 264 matched, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.64]); Tue, 15 Oct 2019 14:30:10 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.64]); Tue, 15 Oct 2019 14:30:10 +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.84 on 10.5.110.64 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza Subject: [libvirt] [PATCH v3 REBASE 06/12] qemu: handle libvirtd restart after 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.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.62]); Tue, 15 Oct 2019 14:33:46 +0000 (UTC) Content-Type: text/plain; charset="utf-8" It is possible for libvirtd to go down before DEVICE_DELETED event is delivered upon usb hostdev unplug and to receive the event after the libvirtd is up. In order to handle this case we need to save usb hostdev deleteAction in status file. Signed-off-by: Nikolay Shirokovskiy Reviewed-by: Daniel Henrique Barboza --- src/conf/domain_conf.c | 26 ++++++++++++++++++++++++++ src/conf/domain_conf.h | 1 + src/qemu/qemu_driver.c | 20 ++++++++++++++++++-- 3 files changed, 45 insertions(+), 2 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index c99758d9f5..d185730023 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -1244,6 +1244,13 @@ VIR_ENUM_IMPL(virDomainShmemModel, "ivshmem-doorbell", ); =20 +VIR_ENUM_IMPL(virDomainHostdevDeleteAction, + VIR_DOMAIN_HOSTDEV_DELETE_ACTION_LAST, + "none", + "delete", + "unplug" +); + VIR_ENUM_IMPL(virDomainLaunchSecurity, VIR_DOMAIN_LAUNCH_SECURITY_LAST, "", @@ -7588,6 +7595,7 @@ virDomainHostdevSubsysUSBDefParseXML(xmlNodePtr node, virDomainHostdevSubsysUSBPtr usbsrc =3D &def->source.subsys.u.usb; VIR_AUTOFREE(char *) startupPolicy =3D NULL; VIR_AUTOFREE(char *) autoAddress =3D NULL; + VIR_AUTOFREE(char *) deleteAction =3D NULL; =20 if ((startupPolicy =3D virXMLPropString(node, "startupPolicy"))) { def->startupPolicy =3D @@ -7605,6 +7613,18 @@ virDomainHostdevSubsysUSBDefParseXML(xmlNodePtr node, usbsrc->autoAddress =3D true; } =20 + if ((deleteAction =3D virXMLPropString(node, "deleteAction"))) { + def->deleteAction =3D + virDomainHostdevDeleteActionTypeFromString(deleteAction); + + if (def->deleteAction <=3D 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("Unknown deleteAction '%s'"), + deleteAction); + goto out; + } + } + /* Product can validly be 0, so we need some extra help to determine * if it is uninitialized*/ got_product =3D false; @@ -25055,6 +25075,12 @@ virDomainHostdevDefFormatSubsys(virBufferPtr buf, =20 if (def->missing && !(flags & VIR_DOMAIN_DEF_FORMAT_INACTIVE)) virBufferAddLit(buf, " missing=3D'yes'"); + + if (def->deleteAction && (flags & VIR_DOMAIN_DEF_FORMAT_STATUS)) { + const char *deleteAction; + deleteAction =3D virDomainHostdevDeleteActionTypeToString(def-= >deleteAction); + virBufferAsprintf(buf, " deleteAction=3D'%s'", deleteAction); + } } =20 if (def->source.subsys.type =3D=3D VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI= && diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 0a16413852..8055debe56 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -340,6 +340,7 @@ typedef enum { =20 VIR_DOMAIN_HOSTDEV_DELETE_ACTION_LAST } virDomainHostdevDeleteActionType; +VIR_ENUM_DECL(virDomainHostdevDeleteAction); =20 =20 /* basic device for direct passthrough */ diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 1110e11c14..d7b44dab2c 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -5187,10 +5187,13 @@ processUSBAddedEvent(virQEMUDriverPtr driver, { virDomainHostdevDefPtr hostdev; virDomainHostdevSubsysUSBPtr usbsrc; + virQEMUDriverConfigPtr cfg =3D virQEMUDriverGetConfig(driver); size_t i; =20 - if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY) < 0) + if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY) < 0) { + virObjectUnref(cfg); return; + } =20 if (!virDomainObjIsActive(vm)) { VIR_DEBUG("Domain is not running"); @@ -5218,8 +5221,13 @@ processUSBAddedEvent(virQEMUDriverPtr driver, if (qemuDomainAttachHostDevice(driver, vm, hostdev) < 0) goto cleanup; =20 + if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm, driver->cap= s) < 0) + VIR_WARN("unable to save domain status after plugging device %s", + hostdev->info->alias); + cleanup: qemuDomainObjEndJob(driver, vm); + virObjectUnref(cfg); } =20 =20 @@ -5231,9 +5239,12 @@ processUSBRemovedEvent(virQEMUDriverPtr driver, size_t i; virDomainHostdevDefPtr hostdev; virDomainDeviceDef dev =3D { .type =3D VIR_DOMAIN_DEVICE_HOSTDEV }; + virQEMUDriverConfigPtr cfg =3D virQEMUDriverGetConfig(driver); =20 - if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY) < 0) + if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY) < 0) { + virObjectUnref(cfg); return; + } =20 if (!virDomainObjIsActive(vm)) { VIR_DEBUG("Domain is not running"); @@ -5269,8 +5280,13 @@ processUSBRemovedEvent(virQEMUDriverPtr driver, if (qemuDomainDetachDeviceLive(vm, &dev, driver, true, true) < 0) goto cleanup; =20 + if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm, driver->cap= s) < 0) + VIR_WARN("unable to save domain status after unplugging device %s", + hostdev->info->alias); + cleanup: qemuDomainObjEndJob(driver, vm); + virObjectUnref(cfg); } =20 =20 --=20 2.23.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat May 4 15:06:47 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=fail(p=none dis=none) header.from=virtuozzo.com ARC-Seal: i=1; a=rsa-sha256; t=1571150151; cv=none; d=zoho.com; s=zohoarc; b=JW6amigQkDKFgs7r0iPiw3UY7vlrIZcUVpZCbtjZyagEZj87fYPRw4pTF9/YFg6VCJV+GLhFH1N2SRRngcOc5YZL8J817q1QSuUSHo6zpWP6L5WNBgoHG8itBTcqPpYzOiHTbXqvdxXnJzPa/Z7ZxIL+jMR2eT+nx/xnCl/JSq0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571150151; 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; bh=9EhxR97p4pKc6mUe6+v7gsHtLNCkV0Y/Wf3QK5R6irY=; b=bWIqq4hXDRFNgmeXRCBflpmtZtELXVLv4ZIt8gUHEi57X5Hz7J+fCkmc+BbgOMVXD3WUIkMWpc9g55ZMVpLhBp72keV3tPO6xGkDPSfImmxjzx4/mnMa6FHb0RfarVqpGSIWCPflriZQP8t/RuH2f/4tX3/B/8uOXTh4GiPU+Hs= 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 1571150151931447.02183809476674; Tue, 15 Oct 2019 07:35:51 -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 4168930983DE; Tue, 15 Oct 2019 14:35: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 103E15C231; Tue, 15 Oct 2019 14:35: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 B333B4EE68; Tue, 15 Oct 2019 14:35:49 +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 x9FEUFge020854 for ; Tue, 15 Oct 2019 10:30:15 -0400 Received: by smtp.corp.redhat.com (Postfix) id 23FBA5D70D; Tue, 15 Oct 2019 14:30:15 +0000 (UTC) Received: from mx1.redhat.com (ext-mx26.extmail.prod.ext.phx2.redhat.com [10.5.110.67]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1CE3A5D6A9 for ; Tue, 15 Oct 2019 14:30:12 +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 08B428980EF for ; Tue, 15 Oct 2019 14:30:10 +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 1iKNpw-0002Ve-Du; Tue, 15 Oct 2019 17:30:08 +0300 From: Nikolay Shirokovskiy To: libvir-list@redhat.com Date: Tue, 15 Oct 2019 17:29:51 +0300 Message-Id: <20191015142956.30963-8-nshirokovskiy@virtuozzo.com> In-Reply-To: <20191015142956.30963-1-nshirokovskiy@virtuozzo.com> References: <20191015142956.30963-1-nshirokovskiy@virtuozzo.com> MIME-Version: 1.0 X-Greylist: Sender passed SPF test, ACL 264 matched, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.67]); Tue, 15 Oct 2019 14:30:10 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.67]); Tue, 15 Oct 2019 14:30:10 +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.84 on 10.5.110.67 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza Subject: [libvirt] [PATCH v3 REBASE 07/12] qemu: handle race on device deletion and usb host device plugging 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.42]); Tue, 15 Oct 2019 14:35:50 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Imagine host usb device is unplugged from host and as a result we send command to qemu to delete appropriate device. Then before qemu device is deleted host usb device is plugged back. Currently code supposes there is no remnant device in qemu and will try to add new device and the attempt will fail. Instead let's check the device is not yet deleted and postpone adding qemu device to device_deleted event handler. Signed-off-by: Nikolay Shirokovskiy Reviewed-by: Daniel Henrique Barboza --- src/qemu/qemu_driver.c | 49 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index d7b44dab2c..030fe8a6c4 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -4586,6 +4586,44 @@ processGuestPanicEvent(virQEMUDriverPtr driver, } =20 =20 +static int +qemuCheckHostdevPlugged(virQEMUDriverPtr driver, + virDomainObjPtr vm, + const char *devAlias) +{ + virDomainHostdevDefPtr hostdev; + virDomainHostdevSubsysUSBPtr usbsrc; + virDomainDeviceDef dev; + int num; + + if (virDomainDefFindDevice(vm->def, devAlias, &dev, false) < 0) + return 0; + + if (dev.type !=3D VIR_DOMAIN_DEVICE_HOSTDEV) + return 0; + + hostdev =3D dev.data.hostdev; + if (hostdev->source.subsys.type !=3D VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_US= B) + return 0; + + usbsrc =3D &hostdev->source.subsys.u.usb; + if (!usbsrc->vendor || !usbsrc->product) + return 0; + + if ((num =3D virUSBDeviceFindByVendor(usbsrc->vendor, usbsrc->product, + NULL, false, NULL)) < 0) + return -1; + + if (num =3D=3D 0) + return 0; + + if (qemuDomainAttachHostDevice(driver, vm, hostdev) < 0) + return -1; + + return 0; +} + + static void processDeviceDeletedEvent(virQEMUDriverPtr driver, virDomainObjPtr vm, @@ -4613,6 +4651,11 @@ processDeviceDeletedEvent(virQEMUDriverPtr driver, =20 if (qemuDomainRemoveDevice(driver, vm, &dev) < 0) goto endjob; + + /* Fall thru and save status file even on error condition because + * device is removed successfully and changed configuration need + * to be saved in status file. */ + qemuCheckHostdevPlugged(driver, vm, devAlias); } =20 if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm, driver->cap= s) < 0) @@ -5218,6 +5261,12 @@ processUSBAddedEvent(virQEMUDriverPtr driver, if (i =3D=3D vm->def->nhostdevs) goto cleanup; =20 + /* if device is not yet even deleted from qemu then handle plugging la= ter. + * Or we failed handling host usb device unplugging, then another atte= mpt of + * unplug/plug could help. */ + if (usbsrc->bus || usbsrc->device) + goto cleanup; + if (qemuDomainAttachHostDevice(driver, vm, hostdev) < 0) goto cleanup; =20 --=20 2.23.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat May 4 15:06:47 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=fail(p=none dis=none) header.from=virtuozzo.com ARC-Seal: i=1; a=rsa-sha256; t=1571150012; cv=none; d=zoho.com; s=zohoarc; b=FdOMNANxrlaylsqvEWVh4vf0qE0RJQua1EXYWe9AQ3m4K5/h66wknkER5wQtRMvTAeVSHvCczNr9PsO+QZ4yCBMlcgnGUnLrSzuNhuQxRs7eGXRbij+gQbMXQBVuhEm8391Xv6t96G5gLAL7e6CDcqb0oDRsSFUI9Dt89m34qIo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571150012; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=EUrO613nfjS2i6lsvqRUSpMspchsPqp2jeadPqJnHLs=; b=QOz2b4XVr7dNlooDi7nKswzEi1Jml4a73TKJKkASyESYmUqfzp5MKdyqn6x75FqxHjcGEIYxXd8WsZRWNcZrKxm515XwfvbKaDO5sPu7pi6lQupsK5xo/U3xkltX/KpntJaiQ/nbDszGL0Y0UOl37p+kIu48KcmzjmQIO3N5kxY= 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 1571150012469408.0294812413923; Tue, 15 Oct 2019 07:33:32 -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 77F432A09BA; Tue, 15 Oct 2019 14:33:30 +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 3DAFA60C57; Tue, 15 Oct 2019 14:33: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 E735E18005A0; Tue, 15 Oct 2019 14:33:29 +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 x9FEUBnX020774 for ; Tue, 15 Oct 2019 10:30:11 -0400 Received: by smtp.corp.redhat.com (Postfix) id 8729F60C5D; Tue, 15 Oct 2019 14:30:11 +0000 (UTC) Received: from mx1.redhat.com (ext-mx07.extmail.prod.ext.phx2.redhat.com [10.5.110.31]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7FF4E60BE2 for ; Tue, 15 Oct 2019 14:30:11 +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 2A7E7C065128 for ; Tue, 15 Oct 2019 14:30:10 +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 1iKNpw-0002Ve-G1 for libvir-list@redhat.com; Tue, 15 Oct 2019 17:30:08 +0300 From: Nikolay Shirokovskiy To: libvir-list@redhat.com Date: Tue, 15 Oct 2019 17:29:52 +0300 Message-Id: <20191015142956.30963-9-nshirokovskiy@virtuozzo.com> In-Reply-To: <20191015142956.30963-1-nshirokovskiy@virtuozzo.com> References: <20191015142956.30963-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.31]); Tue, 15 Oct 2019 14:30:10 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Tue, 15 Oct 2019 14:30:10 +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.31 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 REBASE 08/12] qemu: hotplug: update device list on device deleted event 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]); Tue, 15 Oct 2019 14:33:31 +0000 (UTC) Content-Type: text/plain; charset="utf-8" I guess this is the missing piece for [1]. It did not hurt before (like we didn't even see any errors/warns in logs) because in qemuProcessUpdateDevices function virDomainDefFindDevice does not find device deleted from libvirt config. But now in case of unpluggind usb device from host we leave device in config and thus needlessly try to call qemuDomainRemoveDevice second time. [1] 0dfb8a1b9: qemu: Unplug devices that disappeared when libvirtd was down Signed-off-by: Nikolay Shirokovskiy --- src/qemu/qemu_driver.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 030fe8a6c4..e268e2fd1e 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -4646,6 +4646,9 @@ processDeviceDeletedEvent(virQEMUDriverPtr driver, if (STRPREFIX(devAlias, "vcpu")) { qemuDomainRemoveVcpuAlias(driver, vm, devAlias); } else { + if (qemuDomainUpdateDeviceList(driver, vm, QEMU_ASYNC_JOB_NONE) < = 0) + goto cleanup; + if (virDomainDefFindDevice(vm->def, devAlias, &dev, true) < 0) goto endjob; =20 --=20 2.23.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat May 4 15:06:47 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=fail(p=none dis=none) header.from=virtuozzo.com ARC-Seal: i=1; a=rsa-sha256; t=1571150002; cv=none; d=zoho.com; s=zohoarc; b=OMW3K+uYiblbkpaI4h2Bf36uDC0HHsLXq+9iSVde4ymj/LRVEY/EEQbnB21uYhlQoHJ23+rhh2J3tFoRtS1RtyICerz8bSVnibb01L4IpZC8YgEIYInSNok0kJ6+4mEh4uUKvaW88YOV1acnmLPz3hIn9zqqRUnqsOrkeGFJZwM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571150002; 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; bh=peuc1ywD8zdpSkw8KuAirqOaKYCvQGOmu1/MyiNvaqc=; b=f1r/CWTjubouU2RxoWjkgZZmQvcA7MgCBi8oAckuxxo7ljAOacEG7/Bo33b9DBBEzSP1b3V2DHUhSJ09A5s9WEJRxxpLl9miMgIY5aLQDluFxyJbczxRTMaLq14PuHRI+YuOC9rEFxybK5pPXU789Bw79839q6jUB2q/Twa02AU= 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 1571150002479723.7536477181902; Tue, 15 Oct 2019 07:33:22 -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 25E9A3091DC4; Tue, 15 Oct 2019 14:33:20 +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 B555619C58; Tue, 15 Oct 2019 14:33: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 D63BC4EE69; Tue, 15 Oct 2019 14:33: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 x9FEUBCu020775 for ; Tue, 15 Oct 2019 10:30:11 -0400 Received: by smtp.corp.redhat.com (Postfix) id 890851001E75; Tue, 15 Oct 2019 14:30:11 +0000 (UTC) Received: from mx1.redhat.com (ext-mx14.extmail.prod.ext.phx2.redhat.com [10.5.110.43]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 83F131001947 for ; Tue, 15 Oct 2019 14:30:11 +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 45423308FBA6 for ; Tue, 15 Oct 2019 14:30:10 +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 1iKNpw-0002Ve-KL; Tue, 15 Oct 2019 17:30:08 +0300 From: Nikolay Shirokovskiy To: libvir-list@redhat.com Date: Tue, 15 Oct 2019 17:29:53 +0300 Message-Id: <20191015142956.30963-10-nshirokovskiy@virtuozzo.com> In-Reply-To: <20191015142956.30963-1-nshirokovskiy@virtuozzo.com> References: <20191015142956.30963-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.43]); Tue, 15 Oct 2019 14:30:10 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Tue, 15 Oct 2019 14:30:10 +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.84 on 10.5.110.43 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza Subject: [libvirt] [PATCH v3 REBASE 09/12] qemu: handle host usb device plug/unplug when libvirtd is down 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.42]); Tue, 15 Oct 2019 14:33:20 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Somebody can easily unplug usb device from host while libvirtd is being stopped. Also usb device can be plugged or unplugged/plugged back and so forth. Let's handle such cases. Signed-off-by: Nikolay Shirokovskiy Reviewed-by: Daniel Henrique Barboza --- src/qemu/qemu_process.c | 56 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 0afb7c79e4..82e10f4743 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -3734,6 +3734,59 @@ qemuProcessUpdateDevices(virQEMUDriverPtr driver, return ret; } =20 + +static int +qemuProcessReattachUSBDevices(virQEMUDriverPtr driver, + virDomainObjPtr vm) +{ + size_t i; + + for (i =3D 0; i < vm->def->nhostdevs; i++) { + virDomainHostdevDefPtr hostdev =3D vm->def->hostdevs[i]; + virDomainHostdevSubsysUSBPtr usbsrc =3D &hostdev->source.subsys.u.= usb; + + if (hostdev->source.subsys.type !=3D VIR_DOMAIN_HOSTDEV_SUBSYS_TYP= E_USB || + !usbsrc->replug) + continue; + + /* don't mess with devices that don't use stable host addressing + * with respect to unplug/plug to host + */ + if (!usbsrc->vendor || !usbsrc->product) + continue; + + if (!usbsrc->bus && !usbsrc->device) { + int num; + + if ((num =3D virUSBDeviceFindByVendor(usbsrc->vendor, usbsrc->= product, + NULL, false, NULL)) < 0) + return -1; + + if (num > 0 && + qemuDomainAttachHostDevice(driver, vm, hostdev) < 0) + return -1; + } else { + virUSBDevicePtr usb; + + if (virUSBDeviceFindByBus(usbsrc->bus, usbsrc->device, + NULL, false, &usb) < 0) + return -1; + + if (!usb) { + virDomainDeviceDef dev =3D { .type =3D VIR_DOMAIN_DEVICE_H= OSTDEV }; + + dev.data.hostdev =3D hostdev; + if (qemuDomainDetachDeviceLive(vm, &dev, driver, true, tru= e) < 0) + return -1; + } + virUSBDeviceFree(usb); + } + } + + return 0; +} + + static int qemuDomainPerfRestart(virDomainObjPtr vm) { @@ -8220,6 +8273,9 @@ qemuProcessReconnect(void *opaque) if (qemuProcessUpdateDevices(driver, obj) < 0) goto error; =20 + if (qemuProcessReattachUSBDevices(driver, obj) < 0) + goto error; + if (qemuRefreshPRManagerState(driver, obj) < 0) goto error; =20 --=20 2.23.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat May 4 15:06:47 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=fail(p=none dis=none) header.from=virtuozzo.com ARC-Seal: i=1; a=rsa-sha256; t=1571150020; cv=none; d=zoho.com; s=zohoarc; b=A6g7kkBlusEwf3SyiHt7OVIXT3qbaZro9xfoqF52Nn+kMwLCgtQcmLRqlA5/g6Orw4U38l+EKdGs1DRPsVNSe8NUP7P0O5E9xZ7m7/+m1KIq1aF1Py/Kpoo8OwnYydmPgiY4tkSNYSSNbOvewdMFMjWLiLgSZzwKaAXRwMlDlzY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571150020; 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; bh=mpQxDAREV7aEZHE3h07Fj/56aEjNbWU2lD2DaVLo3+g=; b=JIn3dA5IhTWIgL8AGMYK3jCTHeeRQl0+hPgPlrzc2UhXvPR1F+wWQsCYPO85v7WLxOeHFm+DWuFCWNf6x3AogrAo8CZ+u+ZBfCxRQ6FzdiwpMYWa7VAOitnaZQg2xA2uJyPcykrEKFZta7xkjgynmx73cCVUdHO8KgD+2ish0CY= 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 1571150020895673.4915228179036; Tue, 15 Oct 2019 07:33:40 -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 EA37C3090FC2; Tue, 15 Oct 2019 14:33:37 +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 C1ADD60F88; Tue, 15 Oct 2019 14:33:37 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 835834EE70; Tue, 15 Oct 2019 14:33:37 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x9FEUEpT020835 for ; Tue, 15 Oct 2019 10:30:14 -0400 Received: by smtp.corp.redhat.com (Postfix) id 3ABFA60A9D; Tue, 15 Oct 2019 14:30:14 +0000 (UTC) Received: from mx1.redhat.com (ext-mx14.extmail.prod.ext.phx2.redhat.com [10.5.110.43]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 32B6460A97 for ; Tue, 15 Oct 2019 14:30:11 +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 871EA308FB9D for ; Tue, 15 Oct 2019 14:30:10 +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 1iKNpw-0002Ve-QQ; Tue, 15 Oct 2019 17:30:08 +0300 From: Nikolay Shirokovskiy To: libvir-list@redhat.com Date: Tue, 15 Oct 2019 17:29:54 +0300 Message-Id: <20191015142956.30963-11-nshirokovskiy@virtuozzo.com> In-Reply-To: <20191015142956.30963-1-nshirokovskiy@virtuozzo.com> References: <20191015142956.30963-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.43]); Tue, 15 Oct 2019 14:30:10 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Tue, 15 Oct 2019 14:30:10 +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.84 on 10.5.110.43 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza Subject: [libvirt] [PATCH v3 REBASE 10/12] qemu: don't mess with non mandatory hostdevs on reattaching 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.43]); Tue, 15 Oct 2019 14:33:38 +0000 (UTC) Content-Type: text/plain; charset="utf-8" First I don't want to add code to handle dummy device that is used when host usb device is not present at the moment of starting/migrating etc. Second supporting non mandatory policies would require to handle races when host usb device is plugged to host and libvirtd starts adding device but if in the meanwhile host usb device it unplugged back then current code will use dummy device which is not desired in this case. Signed-off-by: Nikolay Shirokovskiy Reviewed-by: Daniel Henrique Barboza --- src/qemu/qemu_driver.c | 8 ++++++++ src/qemu/qemu_process.c | 4 ++++ 2 files changed, 12 insertions(+) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index e268e2fd1e..f3aae2ba1a 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -5252,6 +5252,10 @@ processUSBAddedEvent(virQEMUDriverPtr driver, if (hostdev->source.subsys.type !=3D VIR_DOMAIN_HOSTDEV_SUBSYS_TYP= E_USB) continue; =20 + if (hostdev->startupPolicy =3D=3D VIR_DOMAIN_STARTUP_POLICY_OPTION= AL || + hostdev->startupPolicy =3D=3D VIR_DOMAIN_STARTUP_POLICY_REQUIS= ITE) + continue; + usbsrc =3D &hostdev->source.subsys.u.usb; =20 if (!usbsrc->replug) @@ -5310,6 +5314,10 @@ processUSBRemovedEvent(virQEMUDriverPtr driver, if (hostdev->source.subsys.type !=3D VIR_DOMAIN_HOSTDEV_SUBSYS_TYP= E_USB) continue; =20 + if (hostdev->startupPolicy =3D=3D VIR_DOMAIN_STARTUP_POLICY_OPTION= AL || + hostdev->startupPolicy =3D=3D VIR_DOMAIN_STARTUP_POLICY_REQUIS= ITE) + continue; + usbsrc =3D &hostdev->source.subsys.u.usb; =20 if (!usbsrc->replug) diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 82e10f4743..2ab3b6f0b9 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -3755,6 +3755,10 @@ qemuProcessReattachUSBDevices(virQEMUDriverPtr drive= r, if (!usbsrc->vendor || !usbsrc->product) continue; =20 + if (hostdev->startupPolicy =3D=3D VIR_DOMAIN_STARTUP_POLICY_OPTION= AL || + hostdev->startupPolicy =3D=3D VIR_DOMAIN_STARTUP_POLICY_REQUIS= ITE) + continue; + if (!usbsrc->bus && !usbsrc->device) { int num; =20 --=20 2.23.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat May 4 15:06:47 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=fail(p=none dis=none) header.from=virtuozzo.com ARC-Seal: i=1; a=rsa-sha256; t=1571150147; cv=none; d=zoho.com; s=zohoarc; b=BqF62rHLZP62I/z7pxgFVAf1VjcrgFn1oEZQ0nr2YhOuysQc0MwYpGL0G5CR3adBPwk9MOhLKvvt0rt6zglh9b6DrZD6q37jGi/+06S9ExAvotyHL+0TDeyO+S9VGPq/h4nlCx5WHCjBopZqRnsfpYsdS9LPKagGD7mtU72+Byw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571150147; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Hb+pwjDUTFxD25YMExuGWzQJYuU4RWy6X1jPwbfVSss=; b=D1Nm6R4dRvt+lvlA1dwpiYJRY7Es4s9fGyZrjL+kHfGBoUzzupvCVgW8hShI47+HluPh5hjD4kOfhxmVT8nOH019SG/mS5iB8AkHBZkw6XdFd5h81zI8hdF90Ej0gKiqEoq/9TlVoGgM1beHSeL0HkRvOIgDxj4TDS9K9CoWFFE= 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 1571150147684781.8595533816001; Tue, 15 Oct 2019 07:35: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 EA9E330715F9; Tue, 15 Oct 2019 14:35:45 +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 C502D5DC1E; Tue, 15 Oct 2019 14:35:45 +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 8177018037CD; Tue, 15 Oct 2019 14:35:45 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x9FEUEd9020836 for ; Tue, 15 Oct 2019 10:30:14 -0400 Received: by smtp.corp.redhat.com (Postfix) id 3FAA76060D; Tue, 15 Oct 2019 14:30:14 +0000 (UTC) Received: from mx1.redhat.com (ext-mx27.extmail.prod.ext.phx2.redhat.com [10.5.110.68]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3251C60925 for ; Tue, 15 Oct 2019 14:30:11 +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 9E084A3CD83 for ; Tue, 15 Oct 2019 14:30:10 +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 1iKNpx-0002Ve-2H for libvir-list@redhat.com; Tue, 15 Oct 2019 17:30:09 +0300 From: Nikolay Shirokovskiy To: libvir-list@redhat.com Date: Tue, 15 Oct 2019 17:29:55 +0300 Message-Id: <20191015142956.30963-12-nshirokovskiy@virtuozzo.com> In-Reply-To: <20191015142956.30963-1-nshirokovskiy@virtuozzo.com> References: <20191015142956.30963-1-nshirokovskiy@virtuozzo.com> MIME-Version: 1.0 X-Greylist: Sender passed SPF test, ACL 264 matched, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.68]); Tue, 15 Oct 2019 14:30:10 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.68]); Tue, 15 Oct 2019 14:30:10 +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.84 on 10.5.110.68 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 REBASE 11/12] qemu: handle detaching of unplugged hostdev 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.49]); Tue, 15 Oct 2019 14:35:46 +0000 (UTC) Content-Type: text/plain; charset="utf-8" If hostdev is unplugged we don't need to delete it's correspondent device from qemu etc. Just remove it from config immediately. Signed-off-by: Nikolay Shirokovskiy --- src/qemu/qemu_hotplug.c | 16 +++++++++++++++- src/util/virhostdev.c | 2 ++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 920e0cb72b..8ba0235dbc 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -4462,6 +4462,7 @@ qemuDomainRemoveHostDevice(virQEMUDriverPtr driver, VIR_AUTOFREE(char *) objAlias =3D NULL; bool is_vfio =3D false; bool unplug =3D hostdev->deleteAction =3D=3D VIR_DOMAIN_HOSTDEV_DELETE= _ACTION_UNPLUG; + bool unplugged =3D false; =20 VIR_DEBUG("Removing host device %s from domain %p %s", hostdev->info->alias, vm, vm->def->name); @@ -4520,13 +4521,17 @@ qemuDomainRemoveHostDevice(virQEMUDriverPtr driver, =20 virDomainAuditHostdev(vm, hostdev, "detach", true); =20 + if (hostdev->source.subsys.type =3D=3D VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_= USB) { + virDomainHostdevSubsysUSBPtr usbsrc =3D &hostdev->source.subsys.u.= usb; + unplugged =3D !usbsrc->bus && !usbsrc->device; + } /* * 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 && + if (!is_vfio && !unplug && !unplugged && qemuSecurityRestoreHostdevLabel(driver, vm, hostdev) < 0) VIR_WARN("Failed to restore host device labelling"); =20 @@ -5832,6 +5837,15 @@ qemuDomainDetachDeviceLive(virDomainObjPtr vm, unplug) < 0) { return -1; } + if (!unplug) { + virDomainHostdevDefPtr hostdev =3D detach.data.hostdev; + virDomainHostdevSubsysUSBPtr usbsrc =3D &hostdev->source.subsy= s.u.usb; + + if (hostdev->startupPolicy !=3D VIR_DOMAIN_STARTUP_POLICY_OPTI= ONAL && + hostdev->startupPolicy !=3D VIR_DOMAIN_STARTUP_POLICY_REQU= ISITE && + usbsrc->device =3D=3D 0 && usbsrc->bus =3D=3D 0) + return qemuDomainRemoveDevice(driver, vm, &detach); + } break; case VIR_DOMAIN_DEVICE_RNG: if (qemuDomainDetachPrepRNG(vm, match->data.rng, diff --git a/src/util/virhostdev.c b/src/util/virhostdev.c index 41fcab7222..ed9bc09e14 100644 --- a/src/util/virhostdev.c +++ b/src/util/virhostdev.c @@ -1793,6 +1793,8 @@ virHostdevReAttachUSBDevices(virHostdevManagerPtr mgr, continue; if (hostdev->missing) continue; + if (!usbsrc->bus && !usbsrc->device) + continue; =20 if (!(usb =3D virUSBDeviceNew(usbsrc->bus, usbsrc->device, NULL)))= { VIR_WARN("Unable to reattach USB device %03d.%03d on domain %s= ", --=20 2.23.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat May 4 15:06:47 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=fail(p=none dis=none) header.from=virtuozzo.com ARC-Seal: i=1; a=rsa-sha256; t=1571150031; cv=none; d=zoho.com; s=zohoarc; b=EdJwFPj6g3e2YRV0jPDQk87s4/nCUojMwXsKF+bNsMPkdWbF1mUa20FUxjkOsA3UUmIiH3WYeYqpZ34HjZsH9Bg/A0cfSAwA/XkLjgM9mU1eUbFoaHJ03iGFhVWPBeqE/4Xh5cWeVLsmczBBtK1PaJEkw9Fqn5W3mF29ZIs2nAw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571150031; 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; bh=F06z5HLf+hv+I1o21jVo2WvQ7mSAUvKJwQQgQpjVqfw=; b=noAXS1QDwAr6UgkFzBvJ0XzqXjh1Z/2Ef/rexnII5qjq1nhGrp1YzQ2pPiHKl6nfGICkxCwK+xJcczyMnLLp75bD/FrcPd5mPGTAJi1sk/tp1ArsD04RBafXQjJDFxU4+uzs2JoQfniHb5c5k9gm0hZCSYcW/6DctsMe+4VDrOc= 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 1571150031456778.3140034518766; Tue, 15 Oct 2019 07:33: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 CBDA918C4287; Tue, 15 Oct 2019 14:33: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 A88593782; Tue, 15 Oct 2019 14:33: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 66C43180BA9E; Tue, 15 Oct 2019 14:33:49 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x9FEUEf4020834 for ; Tue, 15 Oct 2019 10:30:14 -0400 Received: by smtp.corp.redhat.com (Postfix) id 3AC4960605; Tue, 15 Oct 2019 14:30:14 +0000 (UTC) Received: from mx1.redhat.com (ext-mx25.extmail.prod.ext.phx2.redhat.com [10.5.110.66]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 31E0B608C2 for ; Tue, 15 Oct 2019 14:30:11 +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 B9BE410F2E86 for ; Tue, 15 Oct 2019 14:30:10 +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 1iKNpx-0002Ve-6s; Tue, 15 Oct 2019 17:30:09 +0300 From: Nikolay Shirokovskiy To: libvir-list@redhat.com Date: Tue, 15 Oct 2019 17:29:56 +0300 Message-Id: <20191015142956.30963-13-nshirokovskiy@virtuozzo.com> In-Reply-To: <20191015142956.30963-1-nshirokovskiy@virtuozzo.com> References: <20191015142956.30963-1-nshirokovskiy@virtuozzo.com> MIME-Version: 1.0 X-Greylist: Sender passed SPF test, ACL 264 matched, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.66]); Tue, 15 Oct 2019 14:30:11 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.66]); Tue, 15 Oct 2019 14:30:11 +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.84 on 10.5.110.66 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza Subject: [libvirt] [PATCH v3 REBASE 12/12] conf: parse hostdev missing flag 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.6.2 (mx1.redhat.com [10.5.110.62]); Tue, 15 Oct 2019 14:33:50 +0000 (UTC) Content-Type: text/plain; charset="utf-8" We want to keep this flag across libvirtd restarts. Signed-off-by: Nikolay Shirokovskiy Reviewed-by: Daniel Henrique Barboza --- src/conf/domain_conf.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index d185730023..35006cac8c 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -7596,6 +7596,7 @@ virDomainHostdevSubsysUSBDefParseXML(xmlNodePtr node, VIR_AUTOFREE(char *) startupPolicy =3D NULL; VIR_AUTOFREE(char *) autoAddress =3D NULL; VIR_AUTOFREE(char *) deleteAction =3D NULL; + VIR_AUTOFREE(char *) missing =3D NULL; =20 if ((startupPolicy =3D virXMLPropString(node, "startupPolicy"))) { def->startupPolicy =3D @@ -7625,6 +7626,11 @@ virDomainHostdevSubsysUSBDefParseXML(xmlNodePtr node, } } =20 + if ((missing =3D virXMLPropString(node, "missing"))) { + if (STREQ(missing, "yes")) + def->missing =3D true; + } + /* Product can validly be 0, so we need some extra help to determine * if it is uninitialized*/ got_product =3D false; --=20 2.23.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list