From nobody Mon Feb 9 05:38:36 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; dkim=fail; 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=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1563480627; cv=none; d=zoho.com; s=zohoarc; b=Sb8RiR+X7NHPu23zraihsRxJLz/IDCpxdKPjZU8eLVYMKiYX0ZVVf5+9PnIFMlIENFYnDjt2UyCEqvAcCzGpouGm9w+0Scs62ZCo9f8A1Fy9o5oR/7ggmRG7UEppd4RFMEbLOmtT12cu6++j0GD1H27iy3jio7VQ8RACBmlSQdk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1563480627; 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:ARC-Authentication-Results; bh=OXlS+8Z0KktcVAEIMwDIGqQcAiUWfd7fAaDfcJEsnj4=; b=eF2hzSfWP0mkHxE1D9HVjfacj/MdWFWomW6vWn2RmzEJRuMnTvDobvdKCyASp/xcnyF95gIPJPJmvMVm4tR0rum7yz2OguFVF9Aa2XVt34i9R2DW+LUPcPDYWeOLbWOz8/MZGdJ5psYPV2hoNPXni7EkIxpLqLgXFgkdWMRsQd0= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; 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 1563480627175181.66452038926047; Thu, 18 Jul 2019 13:10:27 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 26A1C317916D; Thu, 18 Jul 2019 20:10:25 +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 E84B119D70; Thu, 18 Jul 2019 20:10:24 +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 A554A41F66; Thu, 18 Jul 2019 20:10:24 +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 x6IKALG9013519 for ; Thu, 18 Jul 2019 16:10:21 -0400 Received: by smtp.corp.redhat.com (Postfix) id 9637419D7A; Thu, 18 Jul 2019 20:10:21 +0000 (UTC) Received: from mx1.redhat.com (ext-mx20.extmail.prod.ext.phx2.redhat.com [10.5.110.49]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9055E19D70 for ; Thu, 18 Jul 2019 20:10:21 +0000 (UTC) Received: from mail-qt1-f193.google.com (mail-qt1-f193.google.com [209.85.160.193]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6F5A9308FF23 for ; Thu, 18 Jul 2019 20:10:20 +0000 (UTC) Received: by mail-qt1-f193.google.com with SMTP id d17so28528348qtj.8 for ; Thu, 18 Jul 2019 13:10:20 -0700 (PDT) Received: from rekt.ibmuc.com ([2804:431:c7c7:94cf:6a36:8ff2:a855:c9e6]) by smtp.gmail.com with ESMTPSA id h26sm17586605qta.58.2019.07.18.13.10.18 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 18 Jul 2019 13:10:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ECplWw3nxpe6QxUZyxCGiPtMquL//yl4BjR+xdjS3Z4=; b=jdNM1FDFfGAzEfI3BUn5J0dUvdAS/wvyi6CrGmFuTwELZhZXaRRY7qYlKft2iI1nd0 9mK2FacWhW4Zwe/wrM8sNTtdYjg1xmWlgp5o7pwm34ci1f92kJIb4VeJ72uQjSI5YCg0 IGUfNhmBwo9YiNxgztxygW7ltXboEQJXom0oUJcF70+b9nHK3lsikMpa6Gv+Gbrp6YOP sQjiOfLsPI5o31Qtm9wfMKJ58DcDapp8Lnh6ejf9cEtDjxzMEwiC1FoOnog8EfmThNxm khJBoQ9m/qYVACdkHabRaUaGc8y5JnLEhWgjVwbsJGZVmU9BZDKTVcCdGg3A/3NWIK84 1kbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ECplWw3nxpe6QxUZyxCGiPtMquL//yl4BjR+xdjS3Z4=; b=fXk/kR1Qz2vthdKU+p/WCbh4AJ+5trpFI7GTYQ+WMBCwdUeWE5y+8QsSfOi06F7nO6 bbPJ2kUWMkVlnStq0AoDTidP+p4jTG9WIsBnEEfZ0aHvaSOdoJcPXKjkpkq/Y4GQzy1T A9Vo3QjOI/aJpNtVMZnMBuC1ajFE6dBAJncIm2hTA3sxN5KcXujTQMYxcqcCyYK3vvTo D04Vlu0eONVFp4JiiTrPxUMgfUrLiNWjkD8N4jnolmVpxVc3pCFK2+KtdiCjpKpMJdEy YHGQBHMsz6l5kicXSebJrbF8/ol9bDDtjSagVuapx89km2JnGpawbNrzd1/RmsQR+hGy gWyw== X-Gm-Message-State: APjAAAW+VIHpI2qBhYkMnMx7NNZo1LP1TnHokMpqRgeKp/f1SYgHTftm H2TSmr5WMoIBNkCrRPO8/12eEPJw X-Google-Smtp-Source: APXvYqwnIVIRIPHHY0/g8jniRfp9DRnyaQAJuCfx8wKAwuuAlwR6pfg1ZphemP5aDJe6ZTcKNry7XQ== X-Received: by 2002:ac8:6898:: with SMTP id m24mr33821712qtq.362.1563480619653; Thu, 18 Jul 2019 13:10:19 -0700 (PDT) From: Daniel Henrique Barboza To: libvir-list@redhat.com Date: Thu, 18 Jul 2019 17:10:07 -0300 Message-Id: <20190718201007.28571-4-danielhb413@gmail.com> In-Reply-To: <20190718201007.28571-1-danielhb413@gmail.com> References: <20190718201007.28571-1-danielhb413@gmail.com> MIME-Version: 1.0 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Thu, 18 Jul 2019 20:10:20 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Thu, 18 Jul 2019 20:10:20 +0000 (UTC) for IP:'209.85.160.193' DOMAIN:'mail-qt1-f193.google.com' HELO:'mail-qt1-f193.google.com' FROM:'danielhb413@gmail.com' RCPT:'' X-RedHat-Spam-Score: 0.153 (DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS) 209.85.160.193 mail-qt1-f193.google.com 209.85.160.193 mail-qt1-f193.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.49 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza Subject: [libvirt] [PATCH v1 3/3] virhostdev: remove virHostdevReattachPCIDevice 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.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Thu, 18 Jul 2019 20:10:25 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" We have 3 pieces of code that do slightly the same thing, but it varies depending on where it is called: - virPCIDeviceReattach(). This is where the actual re-attach work happens; - virHostdevReattachPCIDevice(). This is a static function from virhostdev.c that calls virPCIDeviceReattach() after waiting for device cleanup for the KVM PCI stub driver; - virHostdevPCINodeDeviceReAttach(). This function also calls virPCIDeviceReattach(), but setting some device properties beforehand. All these extra operations that are done before virPCIDeviceReattach() can be moved inside the function itself, allowing for the same re-attach behavior everywhere. This patch consolidates all these pre-conditions inside the body of virPCIDeviceReattach(). With that, virHostdevReattachPCIDevice() can be removed and the callers can use virPCIDeviceReattach() directly instead. Signed-off-by: Daniel Henrique Barboza --- src/util/virhostdev.c | 43 +++++++++---------------------------------- src/util/virpci.c | 29 ++++++++++++++++++++++++++--- 2 files changed, 35 insertions(+), 37 deletions(-) diff --git a/src/util/virhostdev.c b/src/util/virhostdev.c index 53aacb59b4..23be037a39 100644 --- a/src/util/virhostdev.c +++ b/src/util/virhostdev.c @@ -613,33 +613,6 @@ virHostdevRestoreNetConfig(virDomainHostdevDefPtr host= dev, } } =20 -/* - * Pre-condition: inactivePCIHostdevs & activePCIHostdevs - * are locked - */ -static void -virHostdevReattachPCIDevice(virHostdevManagerPtr mgr, - virPCIDevicePtr actual) -{ - /* Wait for device cleanup if it is qemu/kvm */ - if (virPCIDeviceGetStubDriver(actual) =3D=3D VIR_PCI_STUB_DRIVER_KVM) { - int retries =3D 100; - while (virPCIDeviceWaitForCleanup(actual, "kvm_assigned_device") - && retries) { - usleep(100*1000); - retries--; - } - } - - VIR_DEBUG("Reattaching PCI device %s", virPCIDeviceGetName(actual)); - if (virPCIDeviceReattach(actual, mgr->activePCIHostdevs, - mgr->inactivePCIHostdevs) < 0) { - VIR_ERROR(_("Failed to re-attach PCI device: %s"), - virGetLastErrorMessage()); - virResetLastError(); - } -} - static void virHostdevReattachAllPCIDevices(virPCIDeviceListPtr pcidevs, virHostdevManagerPtr mgr) @@ -655,11 +628,17 @@ virHostdevReattachAllPCIDevices(virPCIDeviceListPtr p= cidevs, if (!(actual =3D virPCIDeviceListFind(mgr->inactivePCIHostdevs, pc= i))) continue; =20 - if (virPCIDeviceGetManaged(actual)) - virHostdevReattachPCIDevice(mgr, actual); - else + if (virPCIDeviceGetManaged(actual)) { + if (virPCIDeviceReattach(actual, mgr->activePCIHostdevs, + mgr->inactivePCIHostdevs) < 0) { + VIR_ERROR(_("Failed to re-attach PCI device: %s"), + virGetLastErrorMessage()); + virResetLastError(); + } + } else { VIR_DEBUG("Not reattaching unmanaged PCI device %s", virPCIDeviceGetName(actual)); + } } } =20 @@ -2050,10 +2029,6 @@ virHostdevPCINodeDeviceReAttach(virHostdevManagerPtr= mgr, if (virHostdevIsPCINodeDeviceUsed(virPCIDeviceGetAddress(pci), &data)) goto cleanup; =20 - virPCIDeviceSetUnbindFromStub(pci, true); - virPCIDeviceSetRemoveSlot(pci, true); - virPCIDeviceSetReprobe(pci, true); - if (virPCIDeviceReattach(pci, mgr->activePCIHostdevs, mgr->inactivePCIHostdevs) < 0) goto cleanup; diff --git a/src/util/virpci.c b/src/util/virpci.c index 75e8daadd5..4594643d3c 100644 --- a/src/util/virpci.c +++ b/src/util/virpci.c @@ -1509,19 +1509,39 @@ virPCIDeviceDetach(virPCIDevicePtr dev, return 0; } =20 +/* + * Pre-condition: inactivePCIHostdevs & activePCIHostdevs + * are locked + */ int virPCIDeviceReattach(virPCIDevicePtr dev, virPCIDeviceListPtr activeDevs, virPCIDeviceListPtr inactiveDevs) { + int ret =3D -1; + if (activeDevs && virPCIDeviceListFind(activeDevs, dev)) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Not reattaching active device %s"), dev->name); - return -1; + goto exit; + } + + virPCIDeviceSetUnbindFromStub(dev, true); + virPCIDeviceSetRemoveSlot(dev, true); + virPCIDeviceSetReprobe(dev, true); + + /* Wait for device cleanup if it is qemu/kvm */ + if (virPCIDeviceGetStubDriver(dev) =3D=3D VIR_PCI_STUB_DRIVER_KVM) { + int retries =3D 100; + while (virPCIDeviceWaitForCleanup(dev, "kvm_assigned_device") + && retries) { + usleep(100*1000); + retries--; + } } =20 if (virPCIDeviceUnbindFromStub(dev) < 0) - return -1; + goto exit; =20 /* Steal the dev from list inactiveDevs */ if (inactiveDevs) { @@ -1529,7 +1549,10 @@ virPCIDeviceReattach(virPCIDevicePtr dev, virPCIDeviceListDel(inactiveDevs, dev); } =20 - return 0; + ret =3D 0; + + exit: + return ret; } =20 /* Certain hypervisors (like qemu/kvm) map the PCI bar(s) on --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list