From nobody Mon Feb 9 19:04:36 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 207.211.31.81 as permitted sender) client-ip=207.211.31.81; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 207.211.31.81 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=1572337207; cv=none; d=zoho.com; s=zohoarc; b=Pj/C8kfeh7fyTFX8KRQQCzEqxRfJdUGTwp4hd+y8wxX5zHEc/sTiwxiGi26mtGSpzDu0ekISU9tj6x2ALL4RmpzDO4QBO/O9CDHvEluE9N1f+XUKiqxXtO+B4b9YAlTlP/Jd37jyLusNOgYs7k1ZmwHoC0QHlRm66mAHNMZ3Gdw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1572337207; 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=rtka8xAzuhwIgLO5xfKnAcUYS6LS+HNdMvsS0G9dUFo=; b=jtZWOL1XfJ/N40S50bRWUE4s25NAXL8m+C6/j1gH5Mq3lueYPprGc/XNYmWoJ9ACxalvvJpupYh5lJU8SaxD70dL+UiDGZw3lo4O1zemaRE0CUjsfzmI+2nim2dyDwlUd1xyoGAT3JPezlTGlwEq4/zF+k1OtPXatV8VxCg3vKo= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 207.211.31.81 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) by mx.zohomail.com with SMTPS id 1572337207372230.55287200943803; Tue, 29 Oct 2019 01:20:07 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-322-pPDNLTuHMIWfv1JuTVqkQg-1; Tue, 29 Oct 2019 04:19:16 -0400 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id E705E107AD33; Tue, 29 Oct 2019 08:19:10 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B3AF960C5E; Tue, 29 Oct 2019 08:19:10 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 56E601819ADC; Tue, 29 Oct 2019 08:19:10 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x9T8IZJo022993 for ; Tue, 29 Oct 2019 04:18:35 -0400 Received: by smtp.corp.redhat.com (Postfix) id 833055C1D8; Tue, 29 Oct 2019 08:18:35 +0000 (UTC) Received: from mx1.redhat.com (ext-mx04.extmail.prod.ext.phx2.redhat.com [10.5.110.28]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7E5495C1D6 for ; Tue, 29 Oct 2019 08:18:31 +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 BB9E28553D for ; Tue, 29 Oct 2019 08:18:27 +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 1iPMht-0003PU-Nj for libvir-list@redhat.com; Tue, 29 Oct 2019 11:18:25 +0300 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1572337205; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=rtka8xAzuhwIgLO5xfKnAcUYS6LS+HNdMvsS0G9dUFo=; b=FhXx5owQeF2Lle9X3dm/gZrj2mcCjl+kEdtScnf78r3kfH7wmGt9YUK5gDdnWMBn6Z0Q6Q TikZ4SrvipHqU7nFsI7UQ2sT91pFpgVrQVFg57UYE2h6ZLrwkxSX4TMJ6lP9/r7mJSMCgl aYMkW3eu+WgTEEkHZjeka0LTbng6yaI= From: Nikolay Shirokovskiy To: libvir-list@redhat.com Date: Tue, 29 Oct 2019 11:17:52 +0300 Message-Id: <20191029081803.28274-2-nshirokovskiy@virtuozzo.com> In-Reply-To: <20191029081803.28274-1-nshirokovskiy@virtuozzo.com> References: <20191029081803.28274-1-nshirokovskiy@virtuozzo.com> MIME-Version: 1.0 X-Greylist: Sender passed SPF test, ACL 264 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Tue, 29 Oct 2019 08:18:28 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Tue, 29 Oct 2019 08:18:28 +0000 (UTC) for IP:'185.231.240.75' DOMAIN:'relay.sw.ru' HELO:'relay.sw.ru' FROM:'nshirokovskiy@virtuozzo.com' RCPT:'' X-RedHat-Spam-Score: 0 (SPF_HELO_NONE, SPF_PASS) 185.231.240.75 relay.sw.ru 185.231.240.75 relay.sw.ru X-Scanned-By: MIMEDefang 2.78 on 10.5.110.28 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 REBASE 2 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: , 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-MC-Unique: pPDNLTuHMIWfv1JuTVqkQg-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) 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 962766b792..b95b62fea8 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 e06f892da3..051122586d 100644 --- a/docs/schemas/domaincommon.rng +++ b/docs/schemas/domaincommon.rng @@ -4668,6 +4668,11 @@ usb + + + + + diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index d5aba7336f..781764225e 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -7699,6 +7699,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; @@ -8139,12 +8146,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; g_autofree char *managed =3D NULL; g_autofree char *sgio =3D NULL; g_autofree char *rawio =3D NULL; g_autofree char *backendStr =3D NULL; g_autofree char *model =3D NULL; g_autofree char *display =3D NULL; + g_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 @@ -8160,6 +8169,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 @@ -8226,6 +8236,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) { @@ -27183,6 +27207,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) { @@ -27247,6 +27272,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 c69d1b7ef5..f455996d1a 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 89c9494e6c..b6793be908 100644 --- a/tests/qemuxml2xmltest.c +++ b/tests/qemuxml2xmltest.c @@ -437,6 +437,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