From nobody Wed May 8 05:45:48 2024 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=1563480640; cv=none; d=zoho.com; s=zohoarc; b=O25knE6Uj8DLAjjrcgF61/Ix2pK3sNtEQT7pYqI+DLbyQmmq/jPsiWI1tXdUBPU6qdZQU2xeuj/62vYnknfO5mY1yEWtr9V0wzS/QLWkyQTkHZkcC96YU8gnOPRZVlUvEDzFMr9UdRpGIXitLglNAeMpVT7HqvWsp+O8kuq8Uk0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1563480640; 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=X7P2fwo3mcNyULgZ+AtiwGnQqJCsuGErJXDzk2ieQ+8=; b=OxIrBqbk4QfsvFl3enwlNyquHRD5QASUr/gXlzPr2Ir4ako5eRbIHZLZv5XMhr7vu3SR2l4qZJPqR7Z1lIwjdVsa1qm+WkwA5UXfMYCN2l9cdHUJPDXud/iVxyGq4HljxaPMBdmDQeIICsQ/W5Ws6e4JfJ+JiloWK3GVBwxvsAg= 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 1563480640443609.3802068963323; Thu, 18 Jul 2019 13:10:40 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CC6233162913; Thu, 18 Jul 2019 20:10:38 +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 A676C5C22F; Thu, 18 Jul 2019 20:10: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 6B672180020A; Thu, 18 Jul 2019 20:10:38 +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 x6IKALsv013514 for ; Thu, 18 Jul 2019 16:10:21 -0400 Received: by smtp.corp.redhat.com (Postfix) id 034C1607A1; Thu, 18 Jul 2019 20:10:21 +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 F19E85D9D6 for ; Thu, 18 Jul 2019 20:10:18 +0000 (UTC) Received: from mail-qt1-f196.google.com (mail-qt1-f196.google.com [209.85.160.196]) (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 D9B21285AE for ; Thu, 18 Jul 2019 20:10:17 +0000 (UTC) Received: by mail-qt1-f196.google.com with SMTP id h18so28574635qtm.9 for ; Thu, 18 Jul 2019 13:10:17 -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.15 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 18 Jul 2019 13:10:16 -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=laDRoW3qt6Z2qXzPUxX8H6Q3p/vpvg4jBs1y0PBhWWA=; b=trKCc44X6PYA+LWAOk9Ek6hTBrHRGdd3sTXqpmIkdU2THgABIhP75JPiOqOgFDniYx ZVlm/e7UiA67ucoO5RcJY5nJ9Nf54ZGIn/ZLh2k8lMa4Zs4IXFsgi6hWgMNwuD+Aeti3 2y7374k3F3PLxjSXLSKl/o6JLu0vx4Cgfp1kGX9B79TKjVZeO3ewUaeCF9QCum5ll8tz K/1qPsTWs1oQukZ4dfKASFZZeVr7XKyT2V8Mxf8Yqx88m0ucF6380sXF/RndTibOxjCO 5zqGqaZuf/xFCg/7xsYvmymRvgKz8oipy/+HGPOhMVIcJiWsHnDuICid8jnRu8RhRguB t2iw== 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=laDRoW3qt6Z2qXzPUxX8H6Q3p/vpvg4jBs1y0PBhWWA=; b=CtFJwownpezs+vCg01k0uB55mnd2eM322MjRYAEqxZVUKUcyciAuTtDHLbzTmtP7mk E29rqAlUFv+bR7C6QLacGRI+3WHXKbkguYmB3CzFsjPTPLLiAUPh4pYW7+9xfZtU3bf2 vgomxl6J5nn7NKm46J/kjRWT9jANEoQW8rcDXhAd4vwFmXvroWigE7/Ww72sv2T6DiRB /dbgtKgcqsH/nDA1JY0CVYzv6qW9pqvQUzyOswuKddGrutkxufRCLmg/HTRFRiwPF4Sl Nrtl7VdI8scE1KMqym6tkLxM7eElpp3cp1V1fo89yq+VRUhRUkcFSf9tV0ISzeqxSpOH dJog== X-Gm-Message-State: APjAAAVrCYjY8gXPNG/bz/iY5VPlGQIAnKdzxZ6gLhHMPgGknRDUpZ5R gPDqIDCLSq+iZcqLdx2Te1taYKoV X-Google-Smtp-Source: APXvYqx8WKZYkKIUzL+M4vsKCIvleusRpIrIP8gLgxVPuF8kpjSsAgehlWGRf2m3bTjhRrQDBD7sJQ== X-Received: by 2002:aed:220e:: with SMTP id n14mr34277224qtc.388.1563480617035; Thu, 18 Jul 2019 13:10:17 -0700 (PDT) From: Daniel Henrique Barboza To: libvir-list@redhat.com Date: Thu, 18 Jul 2019 17:10:05 -0300 Message-Id: <20190718201007.28571-2-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.30]); Thu, 18 Jul 2019 20:10:18 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Thu, 18 Jul 2019 20:10:18 +0000 (UTC) for IP:'209.85.160.196' DOMAIN:'mail-qt1-f196.google.com' HELO:'mail-qt1-f196.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.196 mail-qt1-f196.google.com 209.85.160.196 mail-qt1-f196.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.30 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza Subject: [libvirt] [PATCH v1 1/3] virhostdev: introduce virHostdevResetAllPCIDevices 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.16 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:39 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" This code that executes virPCIDeviceReset in all virPCIDevicePtr objects of a given virPCIDeviceListPtr list is replicated twice in the code. Putting it in a helper function helps with readability. Signed-off-by: Daniel Henrique Barboza --- src/util/virhostdev.c | 54 +++++++++++++++++++++++-------------------- 1 file changed, 29 insertions(+), 25 deletions(-) diff --git a/src/util/virhostdev.c b/src/util/virhostdev.c index a3647a6cf4..7cb0beb545 100644 --- a/src/util/virhostdev.c +++ b/src/util/virhostdev.c @@ -613,6 +613,32 @@ virHostdevRestoreNetConfig(virDomainHostdevDefPtr host= dev, } } =20 +static int +virHostdevResetAllPCIDevices(virPCIDeviceListPtr pcidevs, + virHostdevManagerPtr mgr) +{ + int ret =3D 0; + size_t i; + + for (i =3D 0; i < virPCIDeviceListCount(pcidevs); i++) { + virPCIDevicePtr pci =3D virPCIDeviceListGet(pcidevs, i); + + /* We can avoid looking up the actual device here, because perform= ing + * a PCI reset on a device doesn't require any information other t= han + * the address, which 'pci' already contains */ + VIR_DEBUG("Resetting PCI device %s", virPCIDeviceGetName(pci)); + if (virPCIDeviceReset(pci, mgr->activePCIHostdevs, + mgr->inactivePCIHostdevs) < 0) { + VIR_ERROR(_("Failed to reset PCI device: %s"), + virGetLastErrorMessage()); + virResetLastError(); + ret =3D -1; + } + } + + return ret; +} + int virHostdevPreparePCIDevices(virHostdevManagerPtr mgr, const char *drv_name, @@ -765,17 +791,8 @@ virHostdevPreparePCIDevices(virHostdevManagerPtr mgr, =20 /* Step 3: Now that all the PCI hostdevs have been detached, we * can safely reset them */ - for (i =3D 0; i < virPCIDeviceListCount(pcidevs); i++) { - virPCIDevicePtr pci =3D virPCIDeviceListGet(pcidevs, i); - - /* We can avoid looking up the actual device here, because perform= ing - * a PCI reset on a device doesn't require any information other t= han - * the address, which 'pci' already contains */ - VIR_DEBUG("Resetting PCI device %s", virPCIDeviceGetName(pci)); - if (virPCIDeviceReset(pci, mgr->activePCIHostdevs, - mgr->inactivePCIHostdevs) < 0) - goto reattachdevs; - } + if (virHostdevResetAllPCIDevices(pcidevs, mgr) < 0) + goto reattachdevs; =20 /* Step 4: For SRIOV network devices, Now that we have detached the * the network device, set the new netdev config */ @@ -1046,20 +1063,7 @@ virHostdevReAttachPCIDevices(virHostdevManagerPtr mg= r, } =20 /* Step 4: perform a PCI Reset on all devices */ - for (i =3D 0; i < virPCIDeviceListCount(pcidevs); i++) { - virPCIDevicePtr pci =3D virPCIDeviceListGet(pcidevs, i); - - /* We can avoid looking up the actual device here, because perform= ing - * a PCI reset on a device doesn't require any information other t= han - * the address, which 'pci' already contains */ - VIR_DEBUG("Resetting PCI device %s", virPCIDeviceGetName(pci)); - if (virPCIDeviceReset(pci, mgr->activePCIHostdevs, - mgr->inactivePCIHostdevs) < 0) { - VIR_ERROR(_("Failed to reset PCI device: %s"), - virGetLastErrorMessage()); - virResetLastError(); - } - } + virHostdevResetAllPCIDevices(pcidevs, mgr); =20 /* Step 5: Reattach managed devices to their host drivers; unmanaged * devices don't need to be processed further */ --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 8 05:45:48 2024 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=1563480625; cv=none; d=zoho.com; s=zohoarc; b=aKbOphtQu2p5f7yPv4ji7bToFE1RwxheNWHq4YtHFCNYg980WwFDiulZ886Sm9abtmXbpjoiRhG3SUHK7oTuz98qWXxbBgnWeLEocWK7b9D4AJBswd+ri2ZrTDJP52tByNZo35PJie25mUsL6MwnYbfml54YuDcYVDleqWCfHfs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1563480625; 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=molPGLqDwUzFkCKA9Wb+IcHXF5ZofOzKBE8FIN9uUpM=; b=jiZOSU3NIkBhDuhji1JBplqV/54jD8/lb8dK3kF7zrJZetW7SS7gyDcs2an88VD2cPsJS1f8i6ZwoOynRrbtel4a/elfnVl1JynpWLC6G/Rn8tCcdx1f63nmUsOZ5A+rwzxBXqTbLbHyJLcc3IC4IcqohOF0Ih1NZNWnmKhz2HM= 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 1563480625921998.2654981433947; Thu, 18 Jul 2019 13:10:25 -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 8DAF6300CA4E; Thu, 18 Jul 2019 20:10:23 +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 0ED5A19D70; Thu, 18 Jul 2019 20:10:23 +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 B6EDD1800206; Thu, 18 Jul 2019 20:10:21 +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 x6IKAKQX013507 for ; Thu, 18 Jul 2019 16:10:20 -0400 Received: by smtp.corp.redhat.com (Postfix) id 2367D19D7A; Thu, 18 Jul 2019 20:10:20 +0000 (UTC) Received: from mx1.redhat.com (ext-mx01.extmail.prod.ext.phx2.redhat.com [10.5.110.25]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1E01719D70 for ; Thu, 18 Jul 2019 20:10:20 +0000 (UTC) Received: from mail-qt1-f195.google.com (mail-qt1-f195.google.com [209.85.160.195]) (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 3280A81DFF for ; Thu, 18 Jul 2019 20:10:19 +0000 (UTC) Received: by mail-qt1-f195.google.com with SMTP id d23so28612711qto.2 for ; Thu, 18 Jul 2019 13:10:19 -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.17 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 18 Jul 2019 13:10:17 -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=DASxDvdtQv5CcI1onbIcfAgae9eRsShFS/4A++2zCWY=; b=HKrtJOC+BwiqrZs0iaNmGAUw1X/Bh73feB1oaPg4FkJM68lUSuToJcMOTJT+BssxSL p1ZB034PGaCTKFwzNxWkNrXOqxfXTdgYQl83oUvkZ9M9VZBwMpp3zghJFQ/tJIn9yhQq VKga6lzy2rHIk+FalAF2OI3UZ8zOa8J0bGCRYsNDnbiPW/JZJVva03f7hT7lP2WWchDV nDqugR7r0dge9z8fMW39CUZRlrqbAxTNYqhKA4OhI/FM3q/5hoyncIxWhVUCnptSMJh3 7Is6e0LNmj4645WFgw9t5fmf7D+0ow7N6Xflwc2WkzTEhF03/60swSPckfFm14roswc9 vXlA== 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=DASxDvdtQv5CcI1onbIcfAgae9eRsShFS/4A++2zCWY=; b=EVkbckcv4XBm+KfEIjo/Sf9jkkdb0N0bw8GSaSM6VFEbTEbdh1+i9X6nSyKGY0PslF dA23rwdqlfYAHYiQ2GQog8VHNH8CEsMJsuR9crRAhDVQn0zXydRc46w1VTTkkCRY7xOk m+ABnd6FVKfMi1NEhjISfx93x5I2M+EGWwr+lgraszU0izJf2dWjQBEb+Vvc7QQaiF4N NSiXIpjM74o01PV4aqq1XF8yWEwr1ImFiR2Rm2Wl2VsBjgMeebfCIsw+avp0pAr0teVk BKLaYkguN5lm9jvtsie0aZdHNzrtOve3Q8jF9nSdwJyc23EzcuEDU59g2iXOEaPa0OFE JRAw== X-Gm-Message-State: APjAAAW0qvdgpoP49zyOx2SVchoGjQrU+h5YIZPdTRbr8HKSSbKBxkON b0dEC7XwitAlKfFx4VegTDOMu/6U X-Google-Smtp-Source: APXvYqw5DrEiAmwgT0D3bjAoqIwDJtye5y2SaWMwBcrvFJlf2VehScjfArfha0+6xwasbn/rY6WXLA== X-Received: by 2002:ac8:23c5:: with SMTP id r5mr34876116qtr.319.1563480618335; Thu, 18 Jul 2019 13:10:18 -0700 (PDT) From: Daniel Henrique Barboza To: libvir-list@redhat.com Date: Thu, 18 Jul 2019 17:10:06 -0300 Message-Id: <20190718201007.28571-3-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.25]); Thu, 18 Jul 2019 20:10:19 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Thu, 18 Jul 2019 20:10:19 +0000 (UTC) for IP:'209.85.160.195' DOMAIN:'mail-qt1-f195.google.com' HELO:'mail-qt1-f195.google.com' FROM:'danielhb413@gmail.com' RCPT:'' X-RedHat-Spam-Score: 0.151 (DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS) 209.85.160.195 mail-qt1-f195.google.com 209.85.160.195 mail-qt1-f195.google.com X-Scanned-By: MIMEDefang 2.83 on 10.5.110.25 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 2/3] virhostdev: introduce virHostdevReattachAllPCIDevices 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.42]); Thu, 18 Jul 2019 20:10:24 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" There are two places in virhostdev that executes a re-attach operation in all pci devices of a virPCIDeviceListPtr array: virHostdevPreparePCIDevices and virHostdevReAttachPCIDevices. The difference is that the code inside virHostdevPreparePCIDevices uses virPCIDeviceReattach(), while inside virHostdevReAttachPCIDevices virHostdevReattachPCIDevice() is used. Both are called in the same manner inside a loop. To make the code easier to follow and to standardize it further, a new virHostdevReattachAllPCIDevices() helper function is created, which is now called in both places. virHostdevReattachPCIDevice() was chosen as re-attach function because it is an improved version of the raw virPCIDeviceReattach(), including a timer to wait for device cleanup in case of pci_stub_kvm. Signed-off-by: Daniel Henrique Barboza --- src/util/virhostdev.c | 114 +++++++++++++++++++----------------------- 1 file changed, 52 insertions(+), 62 deletions(-) diff --git a/src/util/virhostdev.c b/src/util/virhostdev.c index 7cb0beb545..53aacb59b4 100644 --- a/src/util/virhostdev.c +++ b/src/util/virhostdev.c @@ -613,6 +613,56 @@ 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) +{ + size_t i; + + for (i =3D 0; i < virPCIDeviceListCount(pcidevs); i++) { + virPCIDevicePtr pci =3D virPCIDeviceListGet(pcidevs, i); + virPCIDevicePtr actual; + + /* We need to look up the actual device because that's what + * virHostdevReattachPCIDevice() expects as its argument */ + if (!(actual =3D virPCIDeviceListFind(mgr->inactivePCIHostdevs, pc= i))) + continue; + + if (virPCIDeviceGetManaged(actual)) + virHostdevReattachPCIDevice(mgr, actual); + else + VIR_DEBUG("Not reattaching unmanaged PCI device %s", + virPCIDeviceGetName(actual)); + } +} + static int virHostdevResetAllPCIDevices(virPCIDeviceListPtr pcidevs, virHostdevManagerPtr mgr) @@ -899,26 +949,7 @@ virHostdevPreparePCIDevices(virHostdevManagerPtr mgr, } =20 reattachdevs: - for (i =3D 0; i < virPCIDeviceListCount(pcidevs); i++) { - virPCIDevicePtr pci =3D virPCIDeviceListGet(pcidevs, i); - virPCIDevicePtr actual; - - /* We need to look up the actual device because that's what - * virPCIDeviceReattach() expects as its argument */ - if (!(actual =3D virPCIDeviceListFind(mgr->inactivePCIHostdevs, pc= i))) - continue; - - if (virPCIDeviceGetManaged(actual)) { - VIR_DEBUG("Reattaching managed PCI device %s", - virPCIDeviceGetName(pci)); - ignore_value(virPCIDeviceReattach(actual, - mgr->activePCIHostdevs, - mgr->inactivePCIHostdevs)); - } else { - VIR_DEBUG("Not reattaching unmanaged PCI device %s", - virPCIDeviceGetName(pci)); - } - } + virHostdevReattachAllPCIDevices(pcidevs, mgr); =20 cleanup: virObjectUnlock(mgr->activePCIHostdevs); @@ -927,33 +958,6 @@ virHostdevPreparePCIDevices(virHostdevManagerPtr mgr, return ret; } =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(); - } -} - /* @oldStateDir: * For upgrade purpose: see virHostdevRestoreNetConfig */ @@ -1067,21 +1071,7 @@ virHostdevReAttachPCIDevices(virHostdevManagerPtr mg= r, =20 /* Step 5: Reattach managed devices to their host drivers; unmanaged * devices don't need to be processed further */ - for (i =3D 0; i < virPCIDeviceListCount(pcidevs); i++) { - virPCIDevicePtr pci =3D virPCIDeviceListGet(pcidevs, i); - virPCIDevicePtr actual; - - /* We need to look up the actual device because that's what - * virHostdevReattachPCIDevice() expects as its argument */ - if (!(actual =3D virPCIDeviceListFind(mgr->inactivePCIHostdevs, pc= i))) - continue; - - if (virPCIDeviceGetManaged(actual)) - virHostdevReattachPCIDevice(mgr, actual); - else - VIR_DEBUG("Not reattaching unmanaged PCI device %s", - virPCIDeviceGetName(actual)); - } + virHostdevReattachAllPCIDevices(pcidevs, mgr); =20 virObjectUnlock(mgr->activePCIHostdevs); virObjectUnlock(mgr->inactivePCIHostdevs); --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 8 05:45:48 2024 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