From nobody Sat May 4 12:47:10 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=1563903361; cv=none; d=zoho.com; s=zohoarc; b=gEXpSRPzZO1nrzCLWy0N9javQfi94/wIllpB2Q7W9zSBi9JuWsRL903eVJWwN7gyVt3EemmmfsgwvpIZ2AB8qGKW3XOWgxWhqJ8THzlHvRUhHy+y5ZHXW/bEVYixSOlTSDqUb2kMvXMiC8f5VB7mIM0OSV7PpgmciyFPBzGM8Wo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1563903361; 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=JVo8lV0+/3gkPvg7ZwFI3hL8LqbPP0NnHjZZGAFftUc=; b=IZOO7+DFQylGCm3ER8bIfIDGIh37JGsgy4cGryJJicl/fV8WFXHow7E8OnX4VzXckq0aZfbl2aQ89h+HpnO5d1ZfQOBZeXFA6XTm2/sv5MtqHltOMsYquA1P8LinedJjpp3OBDK5fQGMzVBpan6DUkOVEjOzGtPgkcRKvHHKxYo= 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 1563903361623964.579249965721; Tue, 23 Jul 2019 10:36:01 -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 4EE513DBC5; Tue, 23 Jul 2019 17:36:00 +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 EC6D75C882; Tue, 23 Jul 2019 17:35: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 622B31972E; Tue, 23 Jul 2019 17:35:57 +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 x6NHZtbg008614 for ; Tue, 23 Jul 2019 13:35:55 -0400 Received: by smtp.corp.redhat.com (Postfix) id 67FAD17C52; Tue, 23 Jul 2019 17:35:55 +0000 (UTC) Received: from mx1.redhat.com (ext-mx17.extmail.prod.ext.phx2.redhat.com [10.5.110.46]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 603706266C; Tue, 23 Jul 2019 17:35:52 +0000 (UTC) Received: from mail-ua1-f65.google.com (mail-ua1-f65.google.com [209.85.222.65]) (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 CCF233082E42; Tue, 23 Jul 2019 17:35:51 +0000 (UTC) Received: by mail-ua1-f65.google.com with SMTP id c4so17263301uad.1; Tue, 23 Jul 2019 10:35:51 -0700 (PDT) Received: from rekt.ibmuc.com ([2804:431:c7c6:30ed:e8ca:caf:6199:5dc7]) by smtp.gmail.com with ESMTPSA id u5sm42910619uah.0.2019.07.23.10.35.49 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Tue, 23 Jul 2019 10:35:50 -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=DDlhto8w3BSoIPopIQEB6/YA4IKv7+qJ/WKgGZRdRnc=; b=Lb6J0JKwIlsoBlocMDAt+zloxaIxHF4cQqDyCykismUo09u3NFMrsCotOmYnHP/3Gq Z0KbB5a1srDveIDGqD2DLoLr4bcQsSs8jicaHAV78k3LuEiCHVxyf569cu1fLSMfbai/ ZCEIZis2dEiFcJ/JH0YSJX2oCLGEbPEY4a7+zdS0TY9Muen/82kEg+SXm/8UHuWMM8P5 ysAU7cW98YQQK+VlMi83I7AWLblosTzYBQVsKZBQMwWBLsGpG9/ElmjekHL6odyAkGJF ErcPt/Hml3W63a0cd/LQQ7aRAtzdwOuCcwNmQS2zLOrTonHci1rTPTpnh5RrDoKKGV/J 0nCA== 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=DDlhto8w3BSoIPopIQEB6/YA4IKv7+qJ/WKgGZRdRnc=; b=RiPYwWBiMaGV9qGa5klrCo68QNouIZliEZOq2Hut1SLPnk2VEIh3kG+EX/Dkm4rpi3 OpP/gH3H7toZMtF3DiPATBj/IYC/BEDd6S4rIJrfHwSl38Sd3116/NLA6PDP9QLaUiYX H4+w3JtemDbtnkCkL2ZYIihdk1QT7bi90FpeDmffGG8cfGN8X5+zZs3T7trGyGU1Nogw jsuBS8QAIQ5boUWu0QgJ/KAxpBQd8WNmjW2foupajuy94lLw0iNu7J/egSXWERNh8q7H DZfndgwVIno6vaG0iNOhSaopjvuXSjD2+Zc0//XrAx3/MbAyaQ0GTNcINZZR0epG0me8 IkPg== X-Gm-Message-State: APjAAAWic8tzgzfSsGsZ8rTKAZYffoxlY9VatzVL+Z7rlSlDzh+viAzs XIWYtrz2sQAxrd4MsubURwdtjmaASPQ= X-Google-Smtp-Source: APXvYqy8zlKGt8SA2pYhsLZAuGns4rqhlmjD0lUzlJ+Wna7V5v/Rpzk/r0dyRIE/R9RzJYNGM1g7pw== X-Received: by 2002:ab0:6896:: with SMTP id t22mr3302102uar.127.1563903350975; Tue, 23 Jul 2019 10:35:50 -0700 (PDT) From: Daniel Henrique Barboza To: libvir-list@redhat.com Date: Tue, 23 Jul 2019 14:35:39 -0300 Message-Id: <20190723173541.26501-2-danielhb413@gmail.com> In-Reply-To: <20190723173541.26501-1-danielhb413@gmail.com> References: <20190723173541.26501-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.46]); Tue, 23 Jul 2019 17:35:52 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Tue, 23 Jul 2019 17:35:52 +0000 (UTC) for IP:'209.85.222.65' DOMAIN:'mail-ua1-f65.google.com' HELO:'mail-ua1-f65.google.com' FROM:'danielhb413@gmail.com' RCPT:'' X-RedHat-Spam-Score: 0.15 (DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS) 209.85.222.65 mail-ua1-f65.google.com 209.85.222.65 mail-ua1-f65.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.46 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: mprivozn@redhat.com, Daniel Henrique Barboza Subject: [libvirt] [PATCH v2 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.30]); Tue, 23 Jul 2019 17:36:00 +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 Reviewed-by: Michal Privoznik --- 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..4dd24a8f65 100644 --- a/src/util/virhostdev.c +++ b/src/util/virhostdev.c @@ -613,6 +613,32 @@ virHostdevRestoreNetConfig(virDomainHostdevDefPtr host= dev, } } =20 +static int +virHostdevResetAllPCIDevices(virHostdevManagerPtr mgr, + virPCIDeviceListPtr pcidevs) +{ + 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(mgr, pcidevs) < 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(mgr, pcidevs); =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 Sat May 4 12:47:10 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=1563903374; cv=none; d=zoho.com; s=zohoarc; b=EDhuE85dUlIwVs3pfESejEOf7BiB9bpu9cv5AH10iFSg1EG9U7M1ohbbVBLshAYrXKwaEb3OFdqIu8TjMsyXr5g6z1zKRjZwliY6LWVug9zwMLgqwGOVkr7CspaYWQTXQ8wT1uQ9KMfq3Ql1rCQQQk4ZutIPkwaQCXgNEAuxnis= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1563903374; 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=gCD6ocaIzOFLUbJyBb3zJq7qEK6nfKUuhIE1EVJQ/QQ=; b=P+0YbwNnO75nzQyXte55Jvo5aZ8Q9lSmRWDjWPSZJbWPJCID+QX7G3yAmk97bbldgtiyau6VuWl7HuL8y6fGsatGRvGyU69TZK5d6Kzxsa08igzGoiIoKI0GlaZyZh5irPfahkEBxftQsyplANnyZXuzynAi23IyRc79Enw7sSQ= 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 1563903374926753.0269761081461; Tue, 23 Jul 2019 10:36:14 -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 BEDCB30A7C67; Tue, 23 Jul 2019 17:36:13 +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 9471E5DA2E; Tue, 23 Jul 2019 17:36:13 +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 59DC819734; Tue, 23 Jul 2019 17:36:13 +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 x6NHZuVL008619 for ; Tue, 23 Jul 2019 13:35:56 -0400 Received: by smtp.corp.redhat.com (Postfix) id 5FD2760BF7; Tue, 23 Jul 2019 17:35:56 +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 56FE260BEC; Tue, 23 Jul 2019 17:35:54 +0000 (UTC) Received: from mail-vs1-f66.google.com (mail-vs1-f66.google.com [209.85.217.66]) (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 47A1D8553A; Tue, 23 Jul 2019 17:35:53 +0000 (UTC) Received: by mail-vs1-f66.google.com with SMTP id a186so27772355vsd.7; Tue, 23 Jul 2019 10:35:53 -0700 (PDT) Received: from rekt.ibmuc.com ([2804:431:c7c6:30ed:e8ca:caf:6199:5dc7]) by smtp.gmail.com with ESMTPSA id u5sm42910619uah.0.2019.07.23.10.35.51 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Tue, 23 Jul 2019 10:35:52 -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=E8+X1JQbJltAn54zdDoo4ifjwVYzS8XCAIrFLF6m7Q4=; b=F2C+jZYZ0cwa4sVP7v/GDGest5iWf9u12IJJ05IPZJIhHmHr2+WT7nO7D7uu1eVQc4 BhN3USSQZTJRWbLgB4XeYx0XImMiYT5p2l1FQnX9WfUr/jUlozZeK0Dp+6teLTN3L5Gd tKUyyhQDZP5PvKq/Ic0Opkmj6xph1VsgMR234+y1MgWUMAnJ+ogdsyCdw9NNo4A+RtS/ u5c3vNBONhdEUGv6sEkZ5IwzTyk9ml5f5fKiunuwzaAg89vpgM+Mg03jzy+IfmBGP4b9 twIw6+Qi2l0XqRh1naHo0eebZcqybKq/mR/EyVDTeXlPtIl2oOwjY+BFFqFScI843YJa IzQw== 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=E8+X1JQbJltAn54zdDoo4ifjwVYzS8XCAIrFLF6m7Q4=; b=cp6bz0CanVhf/nsxOqMZvTMTuBdVI9DJ2s4ULcO4mMyrlf3ZzBii2HH4TfuSzyUGBW LegeeD3Uw2WYo0umukNxxa/UbNCqIREAUfJgENVJF6YBsG6UDB+38Q4ZsAPCfPkHhWax 3nSxeM5MJx6mK8Wt5ARofa7hELTotiMPeuNPpGUmz+B5n8Y5kPTns7LHAHj1Kjn69Xyz /fE7j92wS64GvU+eQ+vYdlccguP8ulOhytZnDg9KKKpp0rdy6eU8WNlY6c2g1ZO40hwJ hWaeH/D0m8bmGgtAjXSBAaaCIleUGzqSrj58sm+qknLztiBc+OHUYUd2mpo03S+MKkZl LILA== X-Gm-Message-State: APjAAAVHoW6x40vWlqvx74wZpRe4o+MdaUU6zA3+KRW/R01qP44xkBmG l64lbtv862GnCQbGiY60791w1+WBP60= X-Google-Smtp-Source: APXvYqyhZ894JPogGywD/RUB9kGoItB/zA57aAQIXyT7G1QbErFgZ0zOVaEqrU2KsZlzT9Jkz0SNKA== X-Received: by 2002:a67:68d4:: with SMTP id d203mr51760915vsc.28.1563903352410; Tue, 23 Jul 2019 10:35:52 -0700 (PDT) From: Daniel Henrique Barboza To: libvir-list@redhat.com Date: Tue, 23 Jul 2019 14:35:40 -0300 Message-Id: <20190723173541.26501-3-danielhb413@gmail.com> In-Reply-To: <20190723173541.26501-1-danielhb413@gmail.com> References: <20190723173541.26501-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.28]); Tue, 23 Jul 2019 17:35:53 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Tue, 23 Jul 2019 17:35:53 +0000 (UTC) for IP:'209.85.217.66' DOMAIN:'mail-vs1-f66.google.com' HELO:'mail-vs1-f66.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.217.66 mail-vs1-f66.google.com 209.85.217.66 mail-vs1-f66.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.28 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Cc: mprivozn@redhat.com, Daniel Henrique Barboza Subject: [libvirt] [PATCH v2 2/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.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.42]); Tue, 23 Jul 2019 17:36:14 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" virHostdevReattachPCIDevice() is a static that simply does a wait loop with virPCIDeviceWaitForCleanup() before calling virPCIDeviceReattach(). This loop traces back to commit d1e5676c0d, aiming to solve a race condition between Libvirt returning the device back to the host and QEMU trying to access it in the meantime, which resulted in QEMU exiting on error and killing the guest. This happens because device_del is asynchronous, returning OK even if the guest didn't release the device. Commit 01abc8a1b8 moved this code to qemu_hostdev.c, 82e8dd4cf8 added the pci-stub conditional for the loop, 899b261127 moved the code to virhostdev.c where it stood until now. The intent of this wait loop is still valid: device_del is still not bullet proof into preventing the conditions that commit d1e5676c0d aimed to fix, especially when considering all the architectures we must support. However, this loop is executed only in virHostdevReattachPCIDevice(), leaving every other virPCIDeviceReattach() call prone to that error. Let's move the wait loop code to virPCIDeviceReattach(). This will: - make every reattach call safe from this race condition with the pci-stub; - allow for a bit of code cleanup (virHostdevReattachPCIDevice() can be erased, and virHostdevReAttachPCIDevices() can use virPCIDeviceReattach() directly); - make it easier to understand the overall reattach mechanisms in Libvirt, without the risk of a newcomer wondering why reattach is done slightly different in some instances. Signed-off-by: Daniel Henrique Barboza Reviewed-by: Michal Privoznik --- src/util/virhostdev.c | 40 ++++++++++------------------------------ src/util/virpci.c | 14 ++++++++++++++ 2 files changed, 24 insertions(+), 30 deletions(-) diff --git a/src/util/virhostdev.c b/src/util/virhostdev.c index 4dd24a8f65..31d075a11a 100644 --- a/src/util/virhostdev.c +++ b/src/util/virhostdev.c @@ -927,33 +927,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 */ @@ -1072,12 +1045,19 @@ virHostdevReAttachPCIDevices(virHostdevManagerPtr m= gr, virPCIDevicePtr actual; =20 /* We need to look up the actual device because that's what - * virHostdevReattachPCIDevice() expects as its argument */ + * virPCIDeviceReattach() expects as its argument */ if (!(actual =3D virPCIDeviceListFind(mgr->inactivePCIHostdevs, pc= i))) continue; =20 - if (virPCIDeviceGetManaged(actual)) - virHostdevReattachPCIDevice(mgr, actual); + 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)); diff --git a/src/util/virpci.c b/src/util/virpci.c index 6dc0a2711c..05232888c3 100644 --- a/src/util/virpci.c +++ b/src/util/virpci.c @@ -1509,6 +1509,10 @@ virPCIDeviceDetach(virPCIDevicePtr dev, return 0; } =20 +/* + * Pre-condition: inactivePCIHostdevs & activePCIHostdevs + * are locked + */ int virPCIDeviceReattach(virPCIDevicePtr dev, virPCIDeviceListPtr activeDevs, @@ -1520,6 +1524,16 @@ virPCIDeviceReattach(virPCIDevicePtr dev, return -1; } =20 + /* 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--; + } + } + if (virPCIDeviceUnbindFromStub(dev) < 0) return -1; =20 --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat May 4 12:47:10 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=1563903379; cv=none; d=zoho.com; s=zohoarc; b=AUkzaFA4TDUl4yvYfgLBipNDbqxaInD5TDy2F+xuhOkgagmm8laeQaLNpVncwFe9WJNP/bnj1Jt+hrAFWWI+qB3KdJCV0hSOin3LiK/SOWOMBurv+stROc89JEirc1Di6Ry2oXm5QIghApQ3DRNBUEj/nDYeoU6p/wyncv9P9Pw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1563903379; 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=jyiiR8NeqRQuwF5TXjEOuhm178sQhtCRBcXRdk5/tik=; b=Zz2MaH8eWKlh+zr8sLFXqbiIhSS6Lmnayeqw+abCKgjkUs5fcahf1OAL+7lYxSQo8MMZJzH1AQI+K1lROC7tIouSEIEH4AeKhWH8gYSjPjbItNxhvBGcQ5Whvzfy9OMioQjzkToII0KwvFXih6y9D+Dv4vI5sEZ0zyvNC+/jH6w= 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 1563903379604316.15480763009634; Tue, 23 Jul 2019 10:36:19 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id CDA3119D04A; Tue, 23 Jul 2019 17:36:17 +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 9E12817B80; Tue, 23 Jul 2019 17:36:17 +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 534A51800206; Tue, 23 Jul 2019 17:36:17 +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 x6NHZw5l008629 for ; Tue, 23 Jul 2019 13:35:58 -0400 Received: by smtp.corp.redhat.com (Postfix) id 03D4C5DA2E; Tue, 23 Jul 2019 17:35:58 +0000 (UTC) Received: from mx1.redhat.com (ext-mx13.extmail.prod.ext.phx2.redhat.com [10.5.110.42]) by smtp.corp.redhat.com (Postfix) with ESMTPS id ED5FA5D9C5; Tue, 23 Jul 2019 17:35:55 +0000 (UTC) Received: from mail-vs1-f68.google.com (mail-vs1-f68.google.com [209.85.217.68]) (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 91CA23086211; Tue, 23 Jul 2019 17:35:54 +0000 (UTC) Received: by mail-vs1-f68.google.com with SMTP id u3so29371487vsh.6; Tue, 23 Jul 2019 10:35:54 -0700 (PDT) Received: from rekt.ibmuc.com ([2804:431:c7c6:30ed:e8ca:caf:6199:5dc7]) by smtp.gmail.com with ESMTPSA id u5sm42910619uah.0.2019.07.23.10.35.52 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Tue, 23 Jul 2019 10:35:53 -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=XvWmupm0siEwke4HFHX/9E/NpoXJ1TBu/btH9DC95uY=; b=ZAYyjt4S0cnAyKFh+fuLQrMT0oAPQK/poK7L8IwUghmkXoMPdQeSvBZ4kz8F5QEwYi QrXSdipXU6gYmXAFJeZixSU2zc30CNbE4k8Z1rq/JWnnqMXYobt27LhRYqLa/17XGeRy g6PQA6s3NDMPH6MllkaJQmwRZkvCZot3eQNw1ALdPRr50EiNiU0tclcmgLi5o5xxPsvW qgA26eN/jYRYfUh9fd9mNRLAq0p9j92zd+vgOVB5Q1MG7v8OCunDq8gMYoihiLMW0Gg8 Q9f0Pr7PjymIRjoBXaotH6aa4XKaWp22SFPXwK5v6fb4tGddpjOGam4TLVoCp6QS1yv3 VMcw== 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=XvWmupm0siEwke4HFHX/9E/NpoXJ1TBu/btH9DC95uY=; b=VmSfqfJQ5eexrQpg/Zki8yoDBrKu1bOUyXFQowg/Dc3GAEyeGqNFGVPSQB6lAgG8Q9 wBOYDi+1gYu4B1atltK8ADUrC9Jtwy4GHR8bWCpPQYYz37dDw4DGgyaaTQeOWzESE8f7 BbgWePj5Pf28O8o42iCv9CkmKJvze8NhGiHV3ogNZ+n7PolSPRk0NdAZRP7MO2LuKcyA pkFe6G+DS9yJWCZcb+gZ+huIoru6MCsNLqGuhP3thO38i0ef7fr19I/dpkf745Cyb20g PSysP5qaVhKTBGEfqV0zmhlbQrrx8rKa+ZQwtq/9i5o4ox12M2ts59sJmhIkjTzXtrhC 8OJw== X-Gm-Message-State: APjAAAXaiQnd7EevFadxL066Kdod0kGMJO8SPaISBw9omTThvaZUh9z9 e/KEMW+Nia0UdTnT3jxU72tv3rZxMDQ= X-Google-Smtp-Source: APXvYqyeW/64MwbSvGmOfiHAU/OyHxy6qVMP1ovSUdLFEMIgu1CojWjKBMwBElWDDJp/tBNNntcJVQ== X-Received: by 2002:a67:eecb:: with SMTP id o11mr49463408vsp.149.1563903353674; Tue, 23 Jul 2019 10:35:53 -0700 (PDT) From: Daniel Henrique Barboza To: libvir-list@redhat.com Date: Tue, 23 Jul 2019 14:35:41 -0300 Message-Id: <20190723173541.26501-4-danielhb413@gmail.com> In-Reply-To: <20190723173541.26501-1-danielhb413@gmail.com> References: <20190723173541.26501-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.42]); Tue, 23 Jul 2019 17:35:54 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Tue, 23 Jul 2019 17:35:54 +0000 (UTC) for IP:'209.85.217.68' DOMAIN:'mail-vs1-f68.google.com' HELO:'mail-vs1-f68.google.com' FROM:'danielhb413@gmail.com' RCPT:'' X-RedHat-Spam-Score: 0.15 (DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS) 209.85.217.68 mail-vs1-f68.google.com 209.85.217.68 mail-vs1-f68.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.42 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Cc: mprivozn@redhat.com, Daniel Henrique Barboza Subject: [libvirt] [PATCH v2 3/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.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Tue, 23 Jul 2019 17:36:18 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" This code that executes virPCIDeviceReattach 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 Reviewed-by: Michal Privoznik --- src/util/virhostdev.c | 74 +++++++++++++++++++------------------------ 1 file changed, 32 insertions(+), 42 deletions(-) diff --git a/src/util/virhostdev.c b/src/util/virhostdev.c index 31d075a11a..d2474aa140 100644 --- a/src/util/virhostdev.c +++ b/src/util/virhostdev.c @@ -639,6 +639,36 @@ virHostdevResetAllPCIDevices(virHostdevManagerPtr mgr, return ret; } =20 +static void +virHostdevReattachAllPCIDevices(virHostdevManagerPtr mgr, + virPCIDeviceListPtr pcidevs) +{ + 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 + * virPCIDeviceReattach() expects as its argument */ + if (!(actual =3D virPCIDeviceListFind(mgr->inactivePCIHostdevs, pc= i))) + continue; + + 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)); + } +} + int virHostdevPreparePCIDevices(virHostdevManagerPtr mgr, const char *drv_name, @@ -899,26 +929,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(mgr, pcidevs); =20 cleanup: virObjectUnlock(mgr->activePCIHostdevs); @@ -1040,28 +1051,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 - * virPCIDeviceReattach() expects as its argument */ - if (!(actual =3D virPCIDeviceListFind(mgr->inactivePCIHostdevs, pc= i))) - continue; - - 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)); - } + virHostdevReattachAllPCIDevices(mgr, pcidevs); =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