From nobody Mon Feb 9 10:27:13 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=virtuozzo.com ARC-Seal: i=1; a=rsa-sha256; t=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