From nobody Mon Feb 9 16:13:02 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=virtuozzo.com ARC-Seal: i=1; a=rsa-sha256; t=1571150147; cv=none; d=zoho.com; s=zohoarc; b=BqF62rHLZP62I/z7pxgFVAf1VjcrgFn1oEZQ0nr2YhOuysQc0MwYpGL0G5CR3adBPwk9MOhLKvvt0rt6zglh9b6DrZD6q37jGi/+06S9ExAvotyHL+0TDeyO+S9VGPq/h4nlCx5WHCjBopZqRnsfpYsdS9LPKagGD7mtU72+Byw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571150147; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Hb+pwjDUTFxD25YMExuGWzQJYuU4RWy6X1jPwbfVSss=; b=D1Nm6R4dRvt+lvlA1dwpiYJRY7Es4s9fGyZrjL+kHfGBoUzzupvCVgW8hShI47+HluPh5hjD4kOfhxmVT8nOH019SG/mS5iB8AkHBZkw6XdFd5h81zI8hdF90Ej0gKiqEoq/9TlVoGgM1beHSeL0HkRvOIgDxj4TDS9K9CoWFFE= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1571150147684781.8595533816001; Tue, 15 Oct 2019 07:35:47 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id EA9E330715F9; Tue, 15 Oct 2019 14:35:45 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C502D5DC1E; Tue, 15 Oct 2019 14:35:45 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 8177018037CD; Tue, 15 Oct 2019 14:35:45 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x9FEUEd9020836 for ; Tue, 15 Oct 2019 10:30:14 -0400 Received: by smtp.corp.redhat.com (Postfix) id 3FAA76060D; Tue, 15 Oct 2019 14:30:14 +0000 (UTC) Received: from mx1.redhat.com (ext-mx27.extmail.prod.ext.phx2.redhat.com [10.5.110.68]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3251C60925 for ; Tue, 15 Oct 2019 14:30:11 +0000 (UTC) Received: from relay.sw.ru (relay.sw.ru [185.231.240.75]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9E084A3CD83 for ; Tue, 15 Oct 2019 14:30:10 +0000 (UTC) Received: from [172.16.24.106] (helo=shiny.sw.ru) by relay.sw.ru with esmtp (Exim 4.92.2) (envelope-from ) id 1iKNpx-0002Ve-2H for libvir-list@redhat.com; Tue, 15 Oct 2019 17:30:09 +0300 From: Nikolay Shirokovskiy To: libvir-list@redhat.com Date: Tue, 15 Oct 2019 17:29:55 +0300 Message-Id: <20191015142956.30963-12-nshirokovskiy@virtuozzo.com> In-Reply-To: <20191015142956.30963-1-nshirokovskiy@virtuozzo.com> References: <20191015142956.30963-1-nshirokovskiy@virtuozzo.com> MIME-Version: 1.0 X-Greylist: Sender passed SPF test, ACL 264 matched, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.68]); Tue, 15 Oct 2019 14:30:10 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.68]); Tue, 15 Oct 2019 14:30:10 +0000 (UTC) for IP:'185.231.240.75' DOMAIN:'relay.sw.ru' HELO:'relay.sw.ru' FROM:'nshirokovskiy@virtuozzo.com' RCPT:'' X-RedHat-Spam-Score: 0 (SPF_HELO_NONE, SPF_PASS) 185.231.240.75 relay.sw.ru 185.231.240.75 relay.sw.ru X-Scanned-By: MIMEDefang 2.84 on 10.5.110.68 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 REBASE 11/12] qemu: handle detaching of unplugged hostdev X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Tue, 15 Oct 2019 14:35:46 +0000 (UTC) Content-Type: text/plain; charset="utf-8" If hostdev is unplugged we don't need to delete it's correspondent device from qemu etc. Just remove it from config immediately. Signed-off-by: Nikolay Shirokovskiy --- src/qemu/qemu_hotplug.c | 16 +++++++++++++++- src/util/virhostdev.c | 2 ++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 920e0cb72b..8ba0235dbc 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -4462,6 +4462,7 @@ qemuDomainRemoveHostDevice(virQEMUDriverPtr driver, VIR_AUTOFREE(char *) objAlias =3D NULL; bool is_vfio =3D false; bool unplug =3D hostdev->deleteAction =3D=3D VIR_DOMAIN_HOSTDEV_DELETE= _ACTION_UNPLUG; + bool unplugged =3D false; =20 VIR_DEBUG("Removing host device %s from domain %p %s", hostdev->info->alias, vm, vm->def->name); @@ -4520,13 +4521,17 @@ qemuDomainRemoveHostDevice(virQEMUDriverPtr driver, =20 virDomainAuditHostdev(vm, hostdev, "detach", true); =20 + if (hostdev->source.subsys.type =3D=3D VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_= USB) { + virDomainHostdevSubsysUSBPtr usbsrc =3D &hostdev->source.subsys.u.= usb; + unplugged =3D !usbsrc->bus && !usbsrc->device; + } /* * In case of unplug the attempt to restore label will fail. But we do= n't * need to restore the label! In case of separate mount namespace for = the * domain we remove device file later in this function. In case of glo= bal * mount namespace the device file is deleted or being deleted by syst= emd. */ - if (!is_vfio && !unplug && + if (!is_vfio && !unplug && !unplugged && qemuSecurityRestoreHostdevLabel(driver, vm, hostdev) < 0) VIR_WARN("Failed to restore host device labelling"); =20 @@ -5832,6 +5837,15 @@ qemuDomainDetachDeviceLive(virDomainObjPtr vm, unplug) < 0) { return -1; } + if (!unplug) { + virDomainHostdevDefPtr hostdev =3D detach.data.hostdev; + virDomainHostdevSubsysUSBPtr usbsrc =3D &hostdev->source.subsy= s.u.usb; + + if (hostdev->startupPolicy !=3D VIR_DOMAIN_STARTUP_POLICY_OPTI= ONAL && + hostdev->startupPolicy !=3D VIR_DOMAIN_STARTUP_POLICY_REQU= ISITE && + usbsrc->device =3D=3D 0 && usbsrc->bus =3D=3D 0) + return qemuDomainRemoveDevice(driver, vm, &detach); + } break; case VIR_DOMAIN_DEVICE_RNG: if (qemuDomainDetachPrepRNG(vm, match->data.rng, diff --git a/src/util/virhostdev.c b/src/util/virhostdev.c index 41fcab7222..ed9bc09e14 100644 --- a/src/util/virhostdev.c +++ b/src/util/virhostdev.c @@ -1793,6 +1793,8 @@ virHostdevReAttachUSBDevices(virHostdevManagerPtr mgr, continue; if (hostdev->missing) continue; + if (!usbsrc->bus && !usbsrc->device) + continue; =20 if (!(usb =3D virUSBDeviceNew(usbsrc->bus, usbsrc->device, NULL)))= { VIR_WARN("Unable to reattach USB device %03d.%03d on domain %s= ", --=20 2.23.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list