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