From nobody Thu Apr 25 09:37:29 2024 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 From nobody Thu Apr 25 09:37:29 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 207.211.31.120 as permitted sender) client-ip=207.211.31.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 207.211.31.120 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=1572337158; cv=none; d=zoho.com; s=zohoarc; b=YEEqfvX9KNEABQEGtFq+Ue4qifV/ZtYp2VZh6Wpy0RjpMcrpxFutnd7rlupGwMPu4JTFaHkzoYXlYovGLNuFVK5FGBjRJkTr14xPXQzYbLuxTfEIdFaPebJUH5oLoiUB/Nn1PpqW70UKSgnuIOhOKN2CY0+gBYwT6nI73AxJdl4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1572337158; 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=d3NwRmOyLYkB8QMhUED1uX4C6w302OICmGfFVGbkDZc=; b=CPerX3XJH1DMbAHapGd8+LTxLy+RDp296UNNne9hf92yEyju6nquH6cAftmau+LpquZDMhHmtnSjg1t2BfOrIKSeOp18Y8r/wTpuxWY2CFgrPIgVUtE3ur/WoKHc2mzruRGc9TTU+XS1eaUra35yERpFPzrBdz03vGbQrfClLdY= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 207.211.31.120 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-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by mx.zohomail.com with SMTPS id 1572337158002174.7946128235916; Tue, 29 Oct 2019 01:19:18 -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-71-TyVtuHbFMPK6pSRHKhQKZg-1; Tue, 29 Oct 2019 04:19:12 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1B1E785B6EE; Tue, 29 Oct 2019 08:19:07 +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 E5C4A5D6D2; Tue, 29 Oct 2019 08:19:06 +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 9B5B024F37; Tue, 29 Oct 2019 08:19:06 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x9T8IWg7022963 for ; Tue, 29 Oct 2019 04:18:32 -0400 Received: by smtp.corp.redhat.com (Postfix) id B9B542634B; Tue, 29 Oct 2019 08:18:32 +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 B497A2633A for ; Tue, 29 Oct 2019 08:18:29 +0000 (UTC) Received: from relay.sw.ru (relay.sw.ru [185.231.240.75]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E8FF589F301 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 1iPMhu-0003PU-6i for libvir-list@redhat.com; Tue, 29 Oct 2019 11:18:26 +0300 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1572337157; 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=d3NwRmOyLYkB8QMhUED1uX4C6w302OICmGfFVGbkDZc=; b=ikMnXDUUxRf8A857adt8mqi/ToJ+WC/3drvCk859InZJhWExWXPTEpi0cLfPy/HXNdTrG/ gWwsv0mwQdJJ0uXOAEB/1ZGqUL5IdYm0H6aw8WTdclfpvrjT6wgbZss0iHAtnxqkn1Hyza yMdWJU2jndUhmwAfQ5GPqZR/PU8FnAk= From: Nikolay Shirokovskiy To: libvir-list@redhat.com Date: Tue, 29 Oct 2019 11:17:53 +0300 Message-Id: <20191029081803.28274-3-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.6.2 (mx1.redhat.com [10.5.110.68]); Tue, 29 Oct 2019 08:18:28 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.68]); 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.84 on 10.5.110.68 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 REBASE 2 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-MC-Unique: TyVtuHbFMPK6pSRHKhQKZg-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" 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 f455996d1a..1e3e500360 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 d17c18705b..d89676efc8 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -8914,7 +8914,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) @@ -9001,7 +9001,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 fd4bafef0c..5770ce3482 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -5340,7 +5340,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; @@ -5412,6 +5413,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 @@ -5713,7 +5728,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; @@ -5758,7 +5774,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 4ff2b38c83..47fc4b0461 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 Thu Apr 25 09:37:29 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; 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 205.139.110.61 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=1572337150; cv=none; d=zoho.com; s=zohoarc; b=JKZF6gS+dIjZYZtyWffbrQ/oyeo5Lvh0FvHZ9XyMu6Y+Vf2YloFn67Dm8CsZE7Y/GbqpfehSUjNWfzSrMeyBO8CtypSjarKYNyoAEd1ILwEN6fFTU97rX/DYReEqop2xbsTbS3iXYnrPs3Pc90MqZU6iBjbZfL69972qJliyXx0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1572337150; 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=5hrhx/6brqHgzhxgkXp3iE9MuF9TkjL+ACwsZ7N/5gM=; b=FeWu7cyiktcHPCpXLI4jdlKf0zJzQpDmLr55bpBn6wRAD1ot846TW66oMtcv/tKaoDBPgbtzq/cXJEE1m+I5yMXqFRJeC2yu07fcTvS4R75odDlKd+M/YaUkPxDmSEGPOBMW3AwVVaetffxhB/zaCviFhhUMoS9nvzMVYLDE68s= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.61 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-2.mimecast.com [205.139.110.61]) by mx.zohomail.com with SMTPS id 1572337150460107.27481545649164; Tue, 29 Oct 2019 01:19:10 -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-154-PE67cy-aNB-4xTaweXH1dQ-1; Tue, 29 Oct 2019 04:19:06 -0400 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 18D1C5F4; Tue, 29 Oct 2019 08:18:59 +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 E764060874; Tue, 29 Oct 2019 08:18:58 +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 A127A1819AD1; Tue, 29 Oct 2019 08:18:58 +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 x9T8IW1m022954 for ; Tue, 29 Oct 2019 04:18:32 -0400 Received: by smtp.corp.redhat.com (Postfix) id 80FE41001DD7; Tue, 29 Oct 2019 08:18:32 +0000 (UTC) Received: from mx1.redhat.com (ext-mx02.extmail.prod.ext.phx2.redhat.com [10.5.110.26]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2E0941001B28 for ; Tue, 29 Oct 2019 08:18:29 +0000 (UTC) Received: from relay.sw.ru (relay.sw.ru [185.231.240.75]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 048F185A03 for ; Tue, 29 Oct 2019 08:18:28 +0000 (UTC) Received: from [172.16.24.106] (helo=shiny.sw.ru) by relay.sw.ru with esmtp (Exim 4.92.2) (envelope-from ) id 1iPMhu-0003PU-DH; Tue, 29 Oct 2019 11:18:26 +0300 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1572337149; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc: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=5hrhx/6brqHgzhxgkXp3iE9MuF9TkjL+ACwsZ7N/5gM=; b=GNHkbs3jkYGcAdUfmzlIiW0/rIOge7g0YbzvBQuz+7p3EV35tPXmYoArkXVnKAO1EQYE+D XHFxL3Hth91bGTgfE5McJLpDfu61GBIyDpoOUAynRgkxZlRgXgERCgR6Td3mgAgp8JgTAm uvWfXpT8WsvScnqHAzVAsgvu2Ba/NQ4= From: Nikolay Shirokovskiy To: libvir-list@redhat.com Date: Tue, 29 Oct 2019 11:17:54 +0300 Message-Id: <20191029081803.28274-4-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.26]); Tue, 29 Oct 2019 08:18:28 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); 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.26 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 2 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: , 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-MC-Unique: PE67cy-aNB-4xTaweXH1dQ-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" 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 5770ce3482..1a5b9aa0c2 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -4397,7 +4397,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 @@ -4437,6 +4438,7 @@ qemuDomainRemoveHostDevice(virQEMUDriverPtr driver, qemuDomainObjPrivatePtr priv =3D vm->privateData; g_autofree char *drivealias =3D NULL; g_autofree char *objAlias =3D NULL; + 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); @@ -4479,16 +4481,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 (!virHostdevIsVFIODevice(hostdev) && + /* + * 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 (!virHostdevIsVFIODevice(hostdev) && !unplug && qemuSecurityRestoreHostdevLabel(driver, vm, hostdev) < 0) VIR_WARN("Failed to restore host device labelling"); =20 @@ -4522,7 +4532,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) { @@ -4537,6 +4553,8 @@ qemuDomainRemoveHostDevice(virQEMUDriverPtr driver, virDomainNetDefFree(net); } =20 + hostdev->deleteAction =3D VIR_DOMAIN_HOSTDEV_DELETE_ACTION_NONE; + return 0; } =20 @@ -4975,6 +4993,7 @@ qemuDomainRemoveDevice(virQEMUDriverPtr driver, virDomainDeviceInfoPtr info; virObjectEventPtr event; g_autofree char *alias =3D NULL; + bool unplug; =20 /* * save the alias to use when sending a DEVICE_REMOVED event after @@ -5013,8 +5032,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 Thu Apr 25 09:37:29 2024 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=1572337142; cv=none; d=zoho.com; s=zohoarc; b=nZFV5fsACekvFDZK/1/6zsvr4siKGjWEBmccVopFNenlDiYmjlMybzfWrTM0jgviRXBlvo/0KaBmEAVpg1SZkMIcAVBc6oIAuSdPiaTAhjlGrf2xS5rSsENBX5JmS+2wiRQaxNFftgbIYQver6ExSxt920xFY2T1OFUYN780+Os= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1572337142; 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=4nc5pORug/Oye6zaAJaUUi4hXJE49p2XyoquYepdHxE=; b=S5fddeilsnpPwxXPcJbp8RMpA2ql5AVremn+p8kwkM/cpmeKOnhWLNeRu684sXOykBUcNShWRKGP4POUuuvq+a9F8vY8k6ywKT1NKVdOPJFR6d3SfyBLpi0di1zequEiREJRFuClvfntInRQMpz554qth1yLFVBX3Y1ot9x5rUM= 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 1572337142648431.3961431778738; Tue, 29 Oct 2019 01:19:02 -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-369-QkTmfH_fMe6ckv8HGMx0-Q-1; Tue, 29 Oct 2019 04:18:59 -0400 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7F0175E4; Tue, 29 Oct 2019 08:18:55 +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 53F7D5D9C8; Tue, 29 Oct 2019 08:18:55 +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 0EE2824F2F; Tue, 29 Oct 2019 08:18:55 +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 x9T8IWEg022929 for ; Tue, 29 Oct 2019 04:18:32 -0400 Received: by smtp.corp.redhat.com (Postfix) id 343881001DE1; Tue, 29 Oct 2019 08:18:32 +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 2E3321001B35 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 2387858380 for ; Tue, 29 Oct 2019 08:18:28 +0000 (UTC) Received: from [172.16.24.106] (helo=shiny.sw.ru) by relay.sw.ru with esmtp (Exim 4.92.2) (envelope-from ) id 1iPMhu-0003PU-Km; Tue, 29 Oct 2019 11:18:26 +0300 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1572337141; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc: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=4nc5pORug/Oye6zaAJaUUi4hXJE49p2XyoquYepdHxE=; b=gPY70zQ5xMIbjhubno5jkoUaivz5EpKX6h+9NzXx+dAEqTNxGO4C51YQJVEPdBAax43yr7 lm/Q+cRDmaolViB5D9qdTmgUYxNwjiabn0iLjAKcXqgB1qftYLv7Hhfswr3lFIhZE4rqAC R0J3edX9PRp6Upu3cyG1ZgK1o2MwJhk= From: Nikolay Shirokovskiy To: libvir-list@redhat.com Date: Tue, 29 Oct 2019 11:17:55 +0300 Message-Id: <20191029081803.28274-5-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.6.2 (mx1.redhat.com [10.5.110.71]); Tue, 29 Oct 2019 08:18:28 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.71]); 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.84 on 10.5.110.71 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 2 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: , 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-MC-Unique: QkTmfH_fMe6ckv8HGMx0-Q-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" 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 1a5b9aa0c2..a2dd37f630 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 Thu Apr 25 09:37:29 2024 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=1572337152; cv=none; d=zoho.com; s=zohoarc; b=e5Dfvv61F9a0LUouONCL/Ba+8zxLPjDoTKnk3sQ1qumEMbk9FcnXsagrr4pYEltyVg5T/4g1Rb/MjJhPngcgNTtjFnDOlD869wLwI2qPCG+J6IjasrPhyHV3ulleO+HmSEoGXE8Dt89r6JzXjrklr0fjUc4LQVngX7S1H4C3FF0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1572337152; 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=QZIgg7nG5ta+7rYLCRfPekjnMnwO/nZzmEVHAiw4hVc=; b=M+MBgifdiq7Ln8/pyL5DReQrruDrb9PrprF8ZUm5rnVXhN81pHJMi264KWza6AdWfqM/O7pizKtcdPLZw/JCLn6ynpF0ZzXhD6aueg781unDtCAgLZK5AbQAbpzu+k28t6+51VOZYaoQiIB+Otrlltr5+J5+L69fgO1i1Vw8918= 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-2.mimecast.com [207.211.31.81]) by mx.zohomail.com with SMTPS id 1572337152812627.2664984534583; Tue, 29 Oct 2019 01:19:12 -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-29-pcuX2Rd6O7GbpfQj3zcM_Q-1; Tue, 29 Oct 2019 04:19:10 -0400 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4995C107AD3A; Tue, 29 Oct 2019 08:19:03 +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 16E251001DD7; Tue, 29 Oct 2019 08:19:03 +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 9C07D24F33; Tue, 29 Oct 2019 08:19:02 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x9T8IWVs022965 for ; Tue, 29 Oct 2019 04:18:32 -0400 Received: by smtp.corp.redhat.com (Postfix) id BAB522633A; Tue, 29 Oct 2019 08:18:32 +0000 (UTC) Received: from mx1.redhat.com (ext-mx08.extmail.prod.ext.phx2.redhat.com [10.5.110.32]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B4AF526348 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 47620C057EC6 for ; Tue, 29 Oct 2019 08:18:28 +0000 (UTC) Received: from [172.16.24.106] (helo=shiny.sw.ru) by relay.sw.ru with esmtp (Exim 4.92.2) (envelope-from ) id 1iPMhu-0003PU-PP for libvir-list@redhat.com; Tue, 29 Oct 2019 11:18:26 +0300 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1572337151; 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=QZIgg7nG5ta+7rYLCRfPekjnMnwO/nZzmEVHAiw4hVc=; b=E+5bFaZ5ZiVeC1i/R3F8wbWxW/9JHu3S8idJ61HFlyIzaKrTHGngcZzGRdpGczahN2IkJ8 PELzRG8t+h3AmfOGdB5wOtW6bzTWXxUuADUOLU8Z/yTAPHi5LZB4w2tE/7S5S8HBJCMyZC d9mw0gbFNpNh4VJgrvYEfoFfIbYIZjc= From: Nikolay Shirokovskiy To: libvir-list@redhat.com Date: Tue, 29 Oct 2019 11:17:56 +0300 Message-Id: <20191029081803.28274-6-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.32]); Tue, 29 Oct 2019 08:18:29 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Tue, 29 Oct 2019 08:18:29 +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.32 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 REBASE 2 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: , 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-MC-Unique: pcuX2Rd6O7GbpfQj3zcM_Q-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" 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 2074a5f54f..085a41d14f 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 667cc89072..3d8e642625 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -15337,6 +15337,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 b23912ee98..9571328c5c 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 d89676efc8..bcc3ff11e0 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" @@ -640,6 +641,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: * @@ -960,6 +1176,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, @@ -1169,6 +1388,8 @@ qemuStateCleanup(void) =20 virLockManagerPluginUnref(qemu_driver->lockManager); =20 + qemuUdevCleanup(); + virMutexDestroy(&qemu_driver->lock); VIR_FREE(qemu_driver); =20 @@ -4839,7 +5060,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; @@ -4885,6 +5201,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 Thu Apr 25 09:37:29 2024 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-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=1572337128; cv=none; d=zoho.com; s=zohoarc; b=mLotZoyeUDbqk7dlVGQRHcdny32Qaybhs1fb+r7o+0ppF7uZCv9aawzpLv2+K4oy3SSw1y+1Ojezchm2Yqd6wkxrutCN1PyTbTndxOc3QDsoQk07NGkviJ0NWb95YWxwXA0Kx7gP/q4ZpdPQnvsKTDuUF/s3m8WKMHlzUBZR/J4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1572337128; 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=K09Qf3v2od5lch1e9TzxwyTNg87fKAFC/VAwRCUBjv0=; b=KXnmMBNJaqiWawUzO0RDKo/dQy5LPLHLgEz75urcW5KywB/zottMiJDKRRRHGwv7SFY85FSnv/A3hN3HPZ2WP0smaynPcqiKK9cxox5RhoReNNgJXc2ZFEP14OQibXDt9G/+vD+1NRNgoCGUWR52AKPv6wKSovqI/IdGSmoRIcU= 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-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) by mx.zohomail.com with SMTPS id 1572337128263691.2393972831838; Tue, 29 Oct 2019 01:18:48 -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-3-g9l43jp8MZOBiVqyVQI1QA-1; Tue, 29 Oct 2019 04:18:43 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 58850107AD28; Tue, 29 Oct 2019 08:18:39 +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 9B5E45D6C3; Tue, 29 Oct 2019 08:18: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 2EFA52551D; Tue, 29 Oct 2019 08:18:34 +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 x9T8IW2s022925 for ; Tue, 29 Oct 2019 04:18:32 -0400 Received: by smtp.corp.redhat.com (Postfix) id 0C15A5DA60; Tue, 29 Oct 2019 08:18:32 +0000 (UTC) Received: from mx1.redhat.com (ext-mx29.extmail.prod.ext.phx2.redhat.com [10.5.110.70]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 054435D9C8 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 7DF6218C890D for ; Tue, 29 Oct 2019 08:18:28 +0000 (UTC) Received: from [172.16.24.106] (helo=shiny.sw.ru) by relay.sw.ru with esmtp (Exim 4.92.2) (envelope-from ) id 1iPMhu-0003PU-UH; Tue, 29 Oct 2019 11:18:27 +0300 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1572337127; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc: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=K09Qf3v2od5lch1e9TzxwyTNg87fKAFC/VAwRCUBjv0=; b=iNSq43KTAnLKKHR7cs/HoU5VOBDzfJBTEm3//JVD7Wb+dNz+J/tdbRtygN/Zaskz4dIiFB i89LcrVB/6+GwERtse4fMRFpefh5CtC7iv3KeqOvoAcSMGuH0dwWmm2usu/vRj46exaANn RTdUKAHyFSTEth+7Iz0Cb36jjcrkzeQ= From: Nikolay Shirokovskiy To: libvir-list@redhat.com Date: Tue, 29 Oct 2019 11:17:57 +0300 Message-Id: <20191029081803.28274-7-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.6.2 (mx1.redhat.com [10.5.110.70]); Tue, 29 Oct 2019 08:18:28 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.70]); 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.84 on 10.5.110.70 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza Subject: [libvirt] [PATCH v3 REBASE 2 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-MC-Unique: g9l43jp8MZOBiVqyVQI1QA-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" 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 781764225e..06a23cd127 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, "", @@ -7585,6 +7592,7 @@ virDomainHostdevSubsysUSBDefParseXML(xmlNodePtr node, virDomainHostdevSubsysUSBPtr usbsrc =3D &def->source.subsys.u.usb; g_autofree char *startupPolicy =3D NULL; g_autofree char *autoAddress =3D NULL; + g_autofree char *deleteAction =3D NULL; =20 if ((startupPolicy =3D virXMLPropString(node, "startupPolicy"))) { def->startupPolicy =3D @@ -7602,6 +7610,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; @@ -25024,6 +25044,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 1e3e500360..652ce669a6 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 bcc3ff11e0..fe6b94045b 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -5067,10 +5067,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"); @@ -5098,8 +5101,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 @@ -5111,9 +5119,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"); @@ -5149,8 +5160,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 Thu Apr 25 09:37:29 2024 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=1572337152; cv=none; d=zoho.com; s=zohoarc; b=AW6YZQfpgR7LlFPTMHkrA52ZBaK/fmc19/KGC0aFfPGYbJuIXB80JvxuxawFFf9mUon8w08OFhtl+XeA2wRYwIGmTO8UF8vARBZ3wnX92bH6lKgIGzAcABBY0skPWAPWDYpOFdN56oa2X+jnXOtgEfB83DrRd2gXkoecvg4OWQE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1572337152; 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=9r8Kvd43gvDSWu8krZ4MsGIohutZkNVnYoayG9/15bQ=; b=WtoBxD6ZiawHa0lq92if3ISB83P2gaBl6sIxqAwOwUs6q/U6gR+IS2ie2Hojg1BE1JHn0cJwqQvLiUswGSibx2W3ayCh1elRyaymnFfqFJLNlOODUcWGSZmhIIk9N10G93tVX0o7L8r/XAAK5G6tNd3IAiSe7+4SDV0gje1Uis8= 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 1572337152739207.37435605987298; Tue, 29 Oct 2019 01:19:12 -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-150-ObNVBMzlONGg8pA1QQCGzw-1; Tue, 29 Oct 2019 04:19:00 -0400 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id ACB62107AD33; Tue, 29 Oct 2019 08:18:55 +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 827751001B28; Tue, 29 Oct 2019 08:18:55 +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 18BC71819ACF; Tue, 29 Oct 2019 08:18:55 +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 x9T8IW9P022926 for ; Tue, 29 Oct 2019 04:18:32 -0400 Received: by smtp.corp.redhat.com (Postfix) id 100465D9C3; Tue, 29 Oct 2019 08:18:32 +0000 (UTC) Received: from mx1.redhat.com (ext-mx19.extmail.prod.ext.phx2.redhat.com [10.5.110.48]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 058615DA32 for ; Tue, 29 Oct 2019 08:18:29 +0000 (UTC) Received: from relay.sw.ru (relay.sw.ru [185.231.240.75]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BCAB2307D88C for ; Tue, 29 Oct 2019 08:18:28 +0000 (UTC) Received: from [172.16.24.106] (helo=shiny.sw.ru) by relay.sw.ru with esmtp (Exim 4.92.2) (envelope-from ) id 1iPMhv-0003PU-4u; Tue, 29 Oct 2019 11:18:27 +0300 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1572337151; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc: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=9r8Kvd43gvDSWu8krZ4MsGIohutZkNVnYoayG9/15bQ=; b=BT5j1Ia+V6W1Qnv+dbeO08u6ozebj1uq3daZPTMCyFMUKdXymW+2SAdXK8qXXCy5KgJhGE EL4F5dTKS+zB76mAPBG9x+SHc8uQEF0NUQBbclB3tD1sCn9bytf8LJ3Yip4XPtFtr1B1x/ XOPMelRSDCJEnEar167AN70HdRnj5A0= From: Nikolay Shirokovskiy To: libvir-list@redhat.com Date: Tue, 29 Oct 2019 11:17:58 +0300 Message-Id: <20191029081803.28274-8-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.48]); Tue, 29 Oct 2019 08:18:29 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Tue, 29 Oct 2019 08:18:29 +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.48 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza Subject: [libvirt] [PATCH v3 REBASE 2 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: , 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-MC-Unique: ObNVBMzlONGg8pA1QQCGzw-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" 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 fe6b94045b..1a5bf449bf 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -4474,6 +4474,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, @@ -4501,6 +4539,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) @@ -5098,6 +5141,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 Thu Apr 25 09:37:29 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.120 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=1572337128; cv=none; d=zoho.com; s=zohoarc; b=Clw8MwgpRwZ7NEZVqjoU40q7UcK/7zEAbbRHXJGBVEZqqDkw68q+kzVB3eaBoGrKofliAN1mEN7o0EKzETjoGoQ1itN80M3PEG9S+HncWkImlIJKKGpB2d7rXrZd0V2Lreate6IPtKAqsgu/qlddLckENzAJPJU2wGcvQbIQmCo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1572337128; 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=AQ7hUbapNLo3xIqpZlNqohZwiwurgHYGRWqtywqJOHc=; b=oaXQWhXLevHdDQUsAdevZyMSllJiAZtAryM+qhqcZY+bEWzbVflHNzFPM8kDh/eOcXTDbc2R1pAYD5XnxJBYWDawFp17S150xqY4BmjQ1C+wHonK/4hdXJQwEENuqYO/V7zRKABiIxV0fWDBCbUxIC7X+iZMH0tnPXxUysEcGMs= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.120 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-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by mx.zohomail.com with SMTPS id 157233712791952.5244098906295; Tue, 29 Oct 2019 01:18:47 -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-60-HSw9VmdyMrqIiVhbFdQdcw-1; Tue, 29 Oct 2019 04:18:44 -0400 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6D8B11800D56; Tue, 29 Oct 2019 08:18:39 +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 9932160863; Tue, 29 Oct 2019 08:18: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 2EE911819AC0; Tue, 29 Oct 2019 08:18:34 +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 x9T8IWXc022924 for ; Tue, 29 Oct 2019 04:18:32 -0400 Received: by smtp.corp.redhat.com (Postfix) id 0B2885DA5B; Tue, 29 Oct 2019 08:18:32 +0000 (UTC) Received: from mx1.redhat.com (ext-mx24.extmail.prod.ext.phx2.redhat.com [10.5.110.65]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 051335D9C3 for ; Tue, 29 Oct 2019 08:18:29 +0000 (UTC) Received: from relay.sw.ru (relay.sw.ru [185.231.240.75]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DD67610C030B for ; Tue, 29 Oct 2019 08:18:28 +0000 (UTC) Received: from [172.16.24.106] (helo=shiny.sw.ru) by relay.sw.ru with esmtp (Exim 4.92.2) (envelope-from ) id 1iPMhv-0003PU-Dd for libvir-list@redhat.com; Tue, 29 Oct 2019 11:18:27 +0300 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1572337126; 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=AQ7hUbapNLo3xIqpZlNqohZwiwurgHYGRWqtywqJOHc=; b=L8CJjGghVDsCDCD3KSJY9DpX+xbqkXV+hDqRMj3kdoAGBo0nlJvoN5IySMiHTvda5+BH+h MzoJ5RZfoaP4yFp8rrvWaHRktPBcMd9k9X1n+G3zMB2GW9l7QyJVuTOTCwwwHCnZmLZtdd t4Mj0LlNE+lKvAbXI8oK9yk6ORkuBFA= From: Nikolay Shirokovskiy To: libvir-list@redhat.com Date: Tue, 29 Oct 2019 11:17:59 +0300 Message-Id: <20191029081803.28274-9-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.6.2 (mx1.redhat.com [10.5.110.65]); Tue, 29 Oct 2019 08:18:29 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.65]); Tue, 29 Oct 2019 08:18:29 +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.65 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 REBASE 2 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: , 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-MC-Unique: HSw9VmdyMrqIiVhbFdQdcw-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" 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 1a5bf449bf..9e35427354 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -4534,6 +4534,9 @@ processDeviceDeletedEvent(virQEMUDriverPtr driver, if (STRPREFIX(devAlias, "vcpu")) { qemuDomainRemoveVcpuAlias(driver, vm, devAlias); } else { + if (qemuDomainUpdateDeviceList(driver, vm, QEMU_ASYNC_JOB_NONE) < = 0) + goto endjob; + 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 Thu Apr 25 09:37:29 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; 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 205.139.110.61 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=1572337128; cv=none; d=zoho.com; s=zohoarc; b=aBOztd7RJX+Gby2INs/49TFPfhcxFQZ1/RnoVZXCPBumSN/lt9pwPHUmhlSPorwcDW7g6nuNcgky1MbyLTa4NJSeIs37VBSjZdt/cqgg+0RWESUWJp+8G699q69azHGm3KpQQD6MTi8lSxFwzAJmNQQz7RTWW7DY5uZEEyoD2T4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1572337128; 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=A9tKOdHBOoPvWUD79+o21U9asDAVSsYbj30U+0aRNto=; b=Tx2Ep0c0wkbBK7pALoq47oBhEP5BXLTqOs3VIimClKzpIId5ibrsboAyA1chnfsTpCxt4X9U97uC1VtkjUsd21hjZGN7uoi0mtDfrUiJ9/Vtsj6f1gpT1tW8HX5ufPLUgTuR7X4xuxf11pcf8YqrLWewvqY7n3vFnGTlIllOi04= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.61 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-2.mimecast.com [205.139.110.61]) by mx.zohomail.com with SMTPS id 1572337128239604.0002672782017; Tue, 29 Oct 2019 01:18:48 -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-204-Z7_Z6gSOMk6WoVEf2qy8hw-1; Tue, 29 Oct 2019 04:18:43 -0400 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6AAD481A334; Tue, 29 Oct 2019 08:18:39 +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 980891001B03; Tue, 29 Oct 2019 08:18: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 2EE6C2551B; Tue, 29 Oct 2019 08:18: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 x9T8IWgX022927 for ; Tue, 29 Oct 2019 04:18:32 -0400 Received: by smtp.corp.redhat.com (Postfix) id 3415860C4B; Tue, 29 Oct 2019 08:18:32 +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 2EB9960BF1 for ; Tue, 29 Oct 2019 08:18:29 +0000 (UTC) Received: from relay.sw.ru (relay.sw.ru [185.231.240.75]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id F1C9689F302 for ; Tue, 29 Oct 2019 08:18:28 +0000 (UTC) Received: from [172.16.24.106] (helo=shiny.sw.ru) by relay.sw.ru with esmtp (Exim 4.92.2) (envelope-from ) id 1iPMhv-0003PU-Hd; Tue, 29 Oct 2019 11:18:27 +0300 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1572337126; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc: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=A9tKOdHBOoPvWUD79+o21U9asDAVSsYbj30U+0aRNto=; b=Ys+9cPMxiDRlYLk8R6WfIPJoW7b/DupreDLQbRJ97WdNFTK7//rC+9rP+6aC318jxzatND gulUQfozpfemzViNBeAo3b1YRSyMqlS5rauSTMKoHveWskOb/LSRD6IPRuuDA+5Z/JBbSu qKB952yPb8jwCvw5rnWTGKONqtYBoAk= From: Nikolay Shirokovskiy To: libvir-list@redhat.com Date: Tue, 29 Oct 2019 11:18:00 +0300 Message-Id: <20191029081803.28274-10-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.6.2 (mx1.redhat.com [10.5.110.68]); Tue, 29 Oct 2019 08:18:29 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.68]); Tue, 29 Oct 2019 08:18:29 +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.12 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza Subject: [libvirt] [PATCH v3 REBASE 2 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: , 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-MC-Unique: Z7_Z6gSOMk6WoVEf2qy8hw-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" 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 ed8666e9d1..46f04eff44 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -3726,6 +3726,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) { @@ -8199,6 +8252,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 Thu Apr 25 09:37:29 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; 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 205.139.110.61 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=1572337142; cv=none; d=zoho.com; s=zohoarc; b=hUk7QxI0FPcZVzlLGqRACanHrEoNqX6Ob3d1DbX+0c9kyk6zXs4SYS80BBH+c2UMjP0ZYKxfdCuRWF9/TdpUBb0TF+HnRCnatDy9QfxMXLfncGBxU3z92nLw0C1VziBeJChSuEsc712Pq24J2xUuEll6RcCBgC7Iir3JDfaNKig= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1572337142; 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=kxlcaAfiyYInqluuY7u1Frd/vcl9jrvesNxFseU8Ssk=; b=hdO8YHecIPvv4d6/uRdzkI242XbOhtD1Spux7zw0cY6L26qj7kniz45DafxkPzjY0mxtkFCcQptV6QSCKYW3Ii3qnQHB6XJrsV1fU9PAhfZnspGhi+2EYohkh2he/5plYji0gO5Yuv95d9JWMJLeenXGtHF1Xa8ev0DFI0PJ2iI= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.61 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 [205.139.110.61]) by mx.zohomail.com with SMTPS id 1572337142622930.5376867718128; Tue, 29 Oct 2019 01:19:02 -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-424--Jwr6Te3NJm1Gs78lqzKCg-1; Tue, 29 Oct 2019 04:19:00 -0400 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 826EE1005510; Tue, 29 Oct 2019 08:18:55 +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 5F3BB60870; Tue, 29 Oct 2019 08:18:55 +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 1005924F30; Tue, 29 Oct 2019 08:18:55 +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 x9T8IWF1022928 for ; Tue, 29 Oct 2019 04:18:32 -0400 Received: by smtp.corp.redhat.com (Postfix) id 341591001DD7; Tue, 29 Oct 2019 08:18:32 +0000 (UTC) Received: from mx1.redhat.com (ext-mx15.extmail.prod.ext.phx2.redhat.com [10.5.110.44]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2E0101001B23 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 26CAC3083363 for ; Tue, 29 Oct 2019 08:18:29 +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 1iPMhv-0003PU-Kb; Tue, 29 Oct 2019 11:18:27 +0300 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1572337141; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc: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=kxlcaAfiyYInqluuY7u1Frd/vcl9jrvesNxFseU8Ssk=; b=U6McYQLBsGkTnCSRO+H+JF2C4bEOySVE5D8FsjrgpPVdYXrP7BfyjDtikERH3XfSXOch4M laRic81+XWGWPUuGkaKRss+IX6+e1JJJe5CixfMNIqrzds9djJlw9MbPxboLc7PvLL/9tE 73KYozw7qYPVV5e8WACXPh6KU5KspjQ= From: Nikolay Shirokovskiy To: libvir-list@redhat.com Date: Tue, 29 Oct 2019 11:18:01 +0300 Message-Id: <20191029081803.28274-11-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.44]); Tue, 29 Oct 2019 08:18:29 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Tue, 29 Oct 2019 08:18:29 +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.44 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 2 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: , 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-MC-Unique: -Jwr6Te3NJm1Gs78lqzKCg-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" 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 9e35427354..1227072bb8 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -5132,6 +5132,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) @@ -5190,6 +5194,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 46f04eff44..881bee79a0 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -3747,6 +3747,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 Thu Apr 25 09:37:29 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.120 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=1572337155; cv=none; d=zoho.com; s=zohoarc; b=ZgVtoRGfiPghdhtQg00prgCaVJpmKxvKA70PCveH6fSjE2dtpSycpZ6dLKlsDrHLT0TU9vJzQ/4eWrQQsrxBgcjBBAIY9a4BqDJ66b4xQzXXgqNZA8InJuXYtyVcStNzj+n2BdUJSWqNiYo2HgL5JSK3sb5voTnV2OfaOG4icxY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1572337155; 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=TD+80ulRNr6lkUMDMe+Mpi/w2eoRSYyOdP/R0qV/eUk=; b=FJaKtoceZvUbamoy3Ogemkg8WsIYoQZObRzurhN3Zr37l0R0KSs5q7meMZZ/NC877ZBjUmz12HenhbhURZzEja5aEXKhOtrLthzxsrEqiqX9KdfZCGFHiEx2gxdThtIbgFRAxSTdZOfgYK+ofPkeADg/uku4x1taOgu8ZPTYSSs= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.120 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-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by mx.zohomail.com with SMTPS id 1572337155924287.1783719250062; Tue, 29 Oct 2019 01:19:15 -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-32-9KP0M2S9MPCcqzM9iM9Zaw-1; Tue, 29 Oct 2019 04:19:10 -0400 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9F3A6107AD3B; Tue, 29 Oct 2019 08:19:03 +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 4A3111001DE1; Tue, 29 Oct 2019 08:19:03 +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 E501C1819AD3; Tue, 29 Oct 2019 08:19:02 +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 x9T8IWSI022974 for ; Tue, 29 Oct 2019 04:18:32 -0400 Received: by smtp.corp.redhat.com (Postfix) id D82DB60870; Tue, 29 Oct 2019 08:18:32 +0000 (UTC) Received: from mx1.redhat.com (ext-mx06.extmail.prod.ext.phx2.redhat.com [10.5.110.30]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D318F60863 for ; Tue, 29 Oct 2019 08:18:29 +0000 (UTC) Received: from relay.sw.ru (relay.sw.ru [185.231.240.75]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 42CAF368CF for ; Tue, 29 Oct 2019 08:18:29 +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 1iPMhv-0003PU-PR for libvir-list@redhat.com; Tue, 29 Oct 2019 11:18:27 +0300 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1572337154; 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=TD+80ulRNr6lkUMDMe+Mpi/w2eoRSYyOdP/R0qV/eUk=; b=idgdKeinItZPqzj+GNc7p2Kf3aUMhh1/a/USJPrRLAfiqG6eOLgkTpUdiA1VQeJWLoqKxf FoXZG2azCZ9xejBl0UxZeXGQC6gJqXL2rrdNi3cSJNqWFWYapyRDhCaf+tRwzsYU9jTds8 AJ2t8ivmUypfFzPB751aki1WUzLRJ5A= From: Nikolay Shirokovskiy To: libvir-list@redhat.com Date: Tue, 29 Oct 2019 11:18:02 +0300 Message-Id: <20191029081803.28274-12-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.30]); Tue, 29 Oct 2019 08:18:29 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Tue, 29 Oct 2019 08:18:29 +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.30 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 REBASE 2 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: , 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-MC-Unique: 9KP0M2S9MPCcqzM9iM9Zaw-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 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 a2dd37f630..1e623f8763 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -4458,6 +4458,7 @@ qemuDomainRemoveHostDevice(virQEMUDriverPtr driver, g_autofree char *drivealias =3D NULL; g_autofree char *objAlias =3D NULL; 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); @@ -4511,13 +4512,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 (!virHostdevIsVFIODevice(hostdev) && !unplug && + if (!virHostdevIsVFIODevice(hostdev) && !unplug && !unplugged && qemuSecurityRestoreHostdevLabel(driver, vm, hostdev) < 0) VIR_WARN("Failed to restore host device labelling"); =20 @@ -5821,6 +5826,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 010eb551a9..c28633921b 100644 --- a/src/util/virhostdev.c +++ b/src/util/virhostdev.c @@ -1807,6 +1807,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 Thu Apr 25 09:37:29 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; 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 205.139.110.61 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=1572337150; cv=none; d=zoho.com; s=zohoarc; b=LopllcwBTy3KOb97UgJl4dg/jvYGDl+IdtMvdl0JIzEynBPXdysPkrzqu48xOpQCiOsbum7hXJpFSj2xpTO0COU5nfLt9cp4gkU+7eThJuNVUmaaUwilObQkQNe38aUFDTYCmtg5iu8AjjBZO2bR3sAuNYZaqOTtwQz+A2lVECM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1572337150; 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=+vrC0hno7kpOYCaQLB26X9mO4whIHV+p22lchoeZ5VE=; b=feHC+A5MvVAvHYfDQtso7hrehvKfkDeCnYu3MeSs1zKTZ8SSptYD9V92zKTGxCjMdr6UBsT8tC3L2kru3/h8OhW1HZDy1rCn3KflLl/ZWqfRBiEoL9p3b6AFFfikm2TvT1ewKn2grNhFSmoakiXnDPIp13nRh0zE/KOqi+vHYWQ= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.61 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 [205.139.110.61]) by mx.zohomail.com with SMTPS id 1572337150934384.60789647962065; Tue, 29 Oct 2019 01:19:10 -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-74-OCpLmtFlMweWdoR7P5P1Cg-1; Tue, 29 Oct 2019 04:19:06 -0400 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 513B210052E2; Tue, 29 Oct 2019 08:18:59 +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 2A12C26357; Tue, 29 Oct 2019 08:18:59 +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 D93941819AD3; Tue, 29 Oct 2019 08:18:58 +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 x9T8IWJX022959 for ; Tue, 29 Oct 2019 04:18:32 -0400 Received: by smtp.corp.redhat.com (Postfix) id ADA675D6C5; Tue, 29 Oct 2019 08:18:32 +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 A7E6C5D6C3 for ; Tue, 29 Oct 2019 08:18:30 +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 77B5710C0928 for ; Tue, 29 Oct 2019 08:18:29 +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 1iPMhv-0003PU-Tf; Tue, 29 Oct 2019 11:18:27 +0300 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1572337149; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc: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=+vrC0hno7kpOYCaQLB26X9mO4whIHV+p22lchoeZ5VE=; b=QNhgtkNoJs4CQ4OoSXYEtsuh1gxqV0mKiNeV5po2RGN90wkOiX94HXCOUQGUDn/ax7rBOg F67pGS3Ci5R+bPbwvaq2SIEngkZIvc5k7t7oStuXKyFmaY6sHWjGAaEW+WagR2r1HGM6tp /BPHOIAyqLiKlzhlCxVOaAab5yQzv60= From: Nikolay Shirokovskiy To: libvir-list@redhat.com Date: Tue, 29 Oct 2019 11:18:03 +0300 Message-Id: <20191029081803.28274-13-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.6.2 (mx1.redhat.com [10.5.110.66]); Tue, 29 Oct 2019 08:18:29 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.66]); Tue, 29 Oct 2019 08:18:29 +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.15 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza Subject: [libvirt] [PATCH v3 REBASE 2 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: , 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-MC-Unique: OCpLmtFlMweWdoR7P5P1Cg-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" 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 06a23cd127..a57de9354a 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -7593,6 +7593,7 @@ virDomainHostdevSubsysUSBDefParseXML(xmlNodePtr node, g_autofree char *startupPolicy =3D NULL; g_autofree char *autoAddress =3D NULL; g_autofree char *deleteAction =3D NULL; + g_autofree char *missing =3D NULL; =20 if ((startupPolicy =3D virXMLPropString(node, "startupPolicy"))) { def->startupPolicy =3D @@ -7622,6 +7623,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