From nobody Tue May 14 22:21:41 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 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=1609764918; cv=none; d=zohomail.com; s=zohoarc; b=GUN8QP/Iiat3vH5rY2kQGGZTEWmYMWyoLrhfcbj0DEOvJz+4AUZ13MEUG08AjLbVxgw8bbdizHo8afmg6Os+1+YEswEmWyuBdbu6fBbAxq8BYJokBl6kMOtWTlpF14n874Ek9CCHM/CfYy7G0Q58zFFSwwB6krnKLJ99CwFrjvE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1609764918; 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=Bokd43D6looJO/ok370S4znnatsp67iE8pGMnaCul1I=; b=lOhsalJ5jrR9s7+pF038TX14O/s0xK8SHMHvK0+oWJIi2M8GJjPsWlc7kWPVv2CASUwK3FvGMLxb7tx6DWyCEK2EVB45A2Qkhjp3Vdg4zxczEd4Rhqw6nbKVgPJ4rTl1dZZUD9X02iJZzkb/awnzo2ZXvgCuCDRoDczFpJmMS7g= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 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-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1609764918344214.56154251121166; Mon, 4 Jan 2021 04:55:18 -0800 (PST) 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-405-JcIHDa-yPm2-DCfuTjFL3g-1; Mon, 04 Jan 2021 07:55:14 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 969E5190A7A1; Mon, 4 Jan 2021 12:55:08 +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 76A3E5D751; Mon, 4 Jan 2021 12:55:07 +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 DF3A8180954D; Mon, 4 Jan 2021 12:55:04 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 104Ct3nO014115 for ; Mon, 4 Jan 2021 07:55:03 -0500 Received: by smtp.corp.redhat.com (Postfix) id 7CCA8112D407; Mon, 4 Jan 2021 12:55:03 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast02.extmail.prod.ext.rdu2.redhat.com [10.11.55.18]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 78C26112D405 for ; Mon, 4 Jan 2021 12:55:01 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 71CD680120A for ; Mon, 4 Jan 2021 12:55:01 +0000 (UTC) Received: from mail-qk1-f171.google.com (mail-qk1-f171.google.com [209.85.222.171]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-214-UxESVP3qOMaS_07mBPdCtQ-1; Mon, 04 Jan 2021 07:54:59 -0500 Received: by mail-qk1-f171.google.com with SMTP id c7so23212329qke.1 for ; Mon, 04 Jan 2021 04:54:59 -0800 (PST) Received: from rekt.ibmuc.com ([2804:431:c7c6:ca55:7a5d:da5b:906f:bedd]) by smtp.gmail.com with ESMTPSA id m64sm2342866qkb.90.2021.01.04.04.54.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Jan 2021 04:54:58 -0800 (PST) X-MC-Unique: JcIHDa-yPm2-DCfuTjFL3g-1 X-MC-Unique: UxESVP3qOMaS_07mBPdCtQ-1 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=Bokd43D6looJO/ok370S4znnatsp67iE8pGMnaCul1I=; b=G9dtq7PWdIj+7omEq7iL3h7bBs+I+4S1dY8uFFsSmns0XRxRmW/FRjZ2RBSuqr03t2 CntJ3pOHFhCGNenqgBBfWVppgXNeVR94L5A/FBeuqxqQ3FfLle8dI2nSdukh2KZSpw5N 2iMvVK8OeRbDFt2M3ncPJGvVdNTxh5T099BqC6y0jZQ2QiBkWXVL8fl11oYa7bI5gDL9 xhbdIXnd+PKtNievss/Vh10LrNA8wAkD7SHBJ96KihiP/hIv0NHFErSS6En23LaBmSzX dZxYciHYfbSEvoBN3NZODMISgt/WEHQ059qsEwKqp/JOtmQ4LK+uS3o+QUWrVEBf1sDr 9FEg== X-Gm-Message-State: AOAM5325MheyEcn1qY+RLlbqdwt+RxW7JE4urymzO4ji+psmrKiiorfX 1dBKFDiJs5d9NlQUu8qyqqXHyh1KG6fzrw== X-Google-Smtp-Source: ABdhPJx8AtLAxGvgqUyobM+tsQ8VhCq48F1kQbv/HGDbRHdTvd6qYqnxUcQ6bN7fFRSe7NDieNpVRQ== X-Received: by 2002:ae9:e010:: with SMTP id m16mr50960268qkk.442.1609764898996; Mon, 04 Jan 2021 04:54:58 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH 01/20] virpci, domain_audit: use virPCIDeviceAddressAsString() Date: Mon, 4 Jan 2021 09:54:25 -0300 Message-Id: <20210104125444.200536-2-danielhb413@gmail.com> In-Reply-To: <20210104125444.200536-1-danielhb413@gmail.com> References: <20210104125444.200536-1-danielhb413@gmail.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza 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.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" There is no need to open code the PCI address string format when we have a function that does exactly that. Signed-off-by: Daniel Henrique Barboza --- src/conf/domain_audit.c | 6 +----- src/util/virpci.c | 6 ++---- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/src/conf/domain_audit.c b/src/conf/domain_audit.c index 8bc6633af4..5fa65a8078 100644 --- a/src/conf/domain_audit.c +++ b/src/conf/domain_audit.c @@ -361,11 +361,7 @@ virDomainAuditHostdev(virDomainObjPtr vm, virDomainHos= tdevDefPtr hostdev, case VIR_DOMAIN_HOSTDEV_MODE_SUBSYS: switch ((virDomainHostdevSubsysType) hostdev->source.subsys.type) { case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI: - address =3D g_strdup_printf(VIR_PCI_DEVICE_ADDRESS_FMT, - pcisrc->addr.domain, - pcisrc->addr.bus, - pcisrc->addr.slot, - pcisrc->addr.function); + address =3D virPCIDeviceAddressAsString(&pcisrc->addr); break; case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB: address =3D g_strdup_printf("%.3d.%.3d", usbsrc->bus, usbsrc->= device); diff --git a/src/util/virpci.c b/src/util/virpci.c index 9bfc743fbd..3d9d583622 100644 --- a/src/util/virpci.c +++ b/src/util/virpci.c @@ -1471,8 +1471,7 @@ virPCIDeviceNew(unsigned int domain, dev->address.slot =3D slot; dev->address.function =3D function; =20 - dev->name =3D g_strdup_printf(VIR_PCI_DEVICE_ADDRESS_FMT, domain, bus,= slot, - function); + dev->name =3D virPCIDeviceAddressAsString(&dev->address); =20 dev->path =3D g_strdup_printf(PCI_SYSFS "devices/%s/config", dev->name= ); =20 @@ -1998,8 +1997,7 @@ virPCIDeviceAddressGetIOMMUGroupNum(virPCIDeviceAddre= ssPtr addr) g_autofree char *groupNumStr =3D NULL; unsigned int groupNum; =20 - devName =3D g_strdup_printf(VIR_PCI_DEVICE_ADDRESS_FMT, addr->domain, = addr->bus, - addr->slot, addr->function); + devName =3D virPCIDeviceAddressAsString(addr); =20 devPath =3D virPCIFile(devName, "iommu_group"); =20 --=20 2.26.2 From nobody Tue May 14 22:21:41 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 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=1609764925; cv=none; d=zohomail.com; s=zohoarc; b=LXneeeBapAG0Ll5lg44WIQGsLQ/z43JZbIZLzn+NE56dR49t3XbYSetgbMlkd2Av9OQ3WaHO1i1hWBrzFKaJMnaoUiLRyc4qvWqKp7XY8zSE+Gz6EWhCMAbPo+SgtW0ikeuXPDjJTTBHaiEo1io7fmqD+y6HpCY5xOZnDfOPoIo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1609764925; 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=ZQeAblgKeP6GhqIp6BxH1+MbUbLUiRhkE1nXnKpla3c=; b=lwtyWpG4I+t6HHSiUW2F/yXVx/jBs0CKP0bgAmmc49gTWOT8h4E7COKSZRFq9qpggpydRD3pFWi8OwVE/waw99yV2gePDFDuOkiWBkqJfRaXhIX01kCwOt7Hi4v15mopXcn3xxRU/hgAo0vS1UuYAUTfBYn71fTkbCMtlvOoxUE= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 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-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 160976492533241.378387315689224; Mon, 4 Jan 2021 04:55:25 -0800 (PST) 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-180-cCnXgzV7Nb-a0pr7tspNjw-1; Mon, 04 Jan 2021 07:55:21 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6C522107AD24; Mon, 4 Jan 2021 12:55:16 +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 472E25C1A3; Mon, 4 Jan 2021 12:55:16 +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 D08545002D; Mon, 4 Jan 2021 12:55:15 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 104Ct4nE014124 for ; Mon, 4 Jan 2021 07:55:04 -0500 Received: by smtp.corp.redhat.com (Postfix) id A570C112D404; Mon, 4 Jan 2021 12:55:04 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast01.extmail.prod.ext.rdu2.redhat.com [10.11.55.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A03EF10031E7 for ; Mon, 4 Jan 2021 12:55:04 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 89938858EEC for ; Mon, 4 Jan 2021 12:55:04 +0000 (UTC) Received: from mail-qt1-f174.google.com (mail-qt1-f174.google.com [209.85.160.174]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-333-iDAOCfFuP-yzyS7p_adINA-1; Mon, 04 Jan 2021 07:55:01 -0500 Received: by mail-qt1-f174.google.com with SMTP id h19so18299461qtq.13 for ; Mon, 04 Jan 2021 04:55:01 -0800 (PST) Received: from rekt.ibmuc.com ([2804:431:c7c6:ca55:7a5d:da5b:906f:bedd]) by smtp.gmail.com with ESMTPSA id m64sm2342866qkb.90.2021.01.04.04.54.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Jan 2021 04:55:00 -0800 (PST) X-MC-Unique: cCnXgzV7Nb-a0pr7tspNjw-1 X-MC-Unique: iDAOCfFuP-yzyS7p_adINA-1 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=ZQeAblgKeP6GhqIp6BxH1+MbUbLUiRhkE1nXnKpla3c=; b=X0H7laIiWsIYWFnpEzb+GP4+UfJgkQPcGxNY3gA4IfuQlHp5+dZbD+Y7XCrCC8qXx2 wjH+2dTEKEEscnz3OODqlnHdRly/MV/sb0stq72R3c3mLvdbPJBDQSdNddiOQvV8X1O4 LjPeQvf9n1erlCgcYvqoS1cKmzNlghmQXUnc/k5EL3GB6hhbVE3Jabt4Hb8m9jThx0fm Gs+sxZxywdTxYctcaJ0sZbTET6/EBn1aoG0LIIvbOwx2YWRlMgm/gVDKYTh4AQWHxSPg fR9ypqbQFdSAJYbTF7UWnroXyonOr2gG6uOKuKuacjMSW8UVssmZ1znTSBUKCzK2Y2/I vekg== X-Gm-Message-State: AOAM533drewEVvYjQYRyoQRoZkkhCmWovuOvNIuXsUVYkpVyPeYieLkd fmaYZyTBlnzfsDbAanOit4SqOiohHJVE3Q== X-Google-Smtp-Source: ABdhPJyYP7g6cwjs2eNVgXeNPZItiNEZ6ogeX6NpQipXDQ9B7Ika2HT0hinHiu/sYodUjF0281EDnA== X-Received: by 2002:ac8:5d4f:: with SMTP id g15mr71583600qtx.260.1609764901084; Mon, 04 Jan 2021 04:55:01 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH 02/20] qemu, lxc: move NodeDeviceGetPCIInfo() function to domain_driver.c Date: Mon, 4 Jan 2021 09:54:26 -0300 Message-Id: <20210104125444.200536-3-danielhb413@gmail.com> In-Reply-To: <20210104125444.200536-1-danielhb413@gmail.com> References: <20210104125444.200536-1-danielhb413@gmail.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza 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.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" libxlNodeDeviceGetPCIInfo() and qemuNodeDeviceGetPCIInfo() are equal. Let's move the logic to a new virDomainDriverNodeDeviceGetPCIInfo() info to be used by libxl_driver.c and qemu_driver.c. Signed-off-by: Daniel Henrique Barboza --- src/hypervisor/domain_driver.c | 33 +++++++++++++++++++++++++++++ src/hypervisor/domain_driver.h | 7 +++++++ src/libvirt_private.syms | 1 + src/libxl/libxl_driver.c | 38 ++++------------------------------ src/qemu/qemu_driver.c | 37 +++------------------------------ 5 files changed, 48 insertions(+), 68 deletions(-) diff --git a/src/hypervisor/domain_driver.c b/src/hypervisor/domain_driver.c index 8dc5870a61..68dbf10ac6 100644 --- a/src/hypervisor/domain_driver.c +++ b/src/hypervisor/domain_driver.c @@ -21,6 +21,7 @@ #include =20 #include "domain_driver.h" +#include "node_device_conf.h" #include "viralloc.h" #include "virstring.h" #include "vircrypto.h" @@ -336,3 +337,35 @@ virDomainDriverSetupPersistentDefBlkioParams(virDomain= DefPtr persistentDef, =20 return ret; } + + +int +virDomainDriverNodeDeviceGetPCIInfo(virNodeDeviceDefPtr def, + unsigned *domain, + unsigned *bus, + unsigned *slot, + unsigned *function) +{ + virNodeDevCapsDefPtr cap; + + cap =3D def->caps; + while (cap) { + if (cap->data.type =3D=3D VIR_NODE_DEV_CAP_PCI_DEV) { + *domain =3D cap->data.pci_dev.domain; + *bus =3D cap->data.pci_dev.bus; + *slot =3D cap->data.pci_dev.slot; + *function =3D cap->data.pci_dev.function; + break; + } + + cap =3D cap->next; + } + + if (!cap) { + virReportError(VIR_ERR_INVALID_ARG, + _("device %s is not a PCI device"), def->name); + return -1; + } + + return 0; +} diff --git a/src/hypervisor/domain_driver.h b/src/hypervisor/domain_driver.h index b66ae2d421..2bb053d559 100644 --- a/src/hypervisor/domain_driver.h +++ b/src/hypervisor/domain_driver.h @@ -21,6 +21,7 @@ #pragma once =20 #include "domain_conf.h" +#include "node_device_conf.h" =20 char * virDomainDriverGenerateRootHash(const char *drivername, @@ -45,3 +46,9 @@ int virDomainDriverParseBlkioDeviceStr(char *blkioDeviceS= tr, const char *type, int virDomainDriverSetupPersistentDefBlkioParams(virDomainDefPtr persisten= tDef, virTypedParameterPtr para= ms, int nparams); + +int virDomainDriverNodeDeviceGetPCIInfo(virNodeDeviceDefPtr def, + unsigned *domain, + unsigned *bus, + unsigned *slot, + unsigned *function); diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 583fc5800e..fe4ee25f3a 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1445,6 +1445,7 @@ virDomainCgroupSetupMemtune; virDomainDriverGenerateMachineName; virDomainDriverGenerateRootHash; virDomainDriverMergeBlkioDevice; +virDomainDriverNodeDeviceGetPCIInfo; virDomainDriverParseBlkioDeviceStr; virDomainDriverSetupPersistentDefBlkioParams; =20 diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index d58af1a869..ac2564a563 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -56,6 +56,7 @@ #include "cpu/cpu.h" #include "virutil.h" #include "domain_validate.h" +#include "domain_driver.h" =20 #define VIR_FROM_THIS VIR_FROM_LIBXL =20 @@ -5779,37 +5780,6 @@ libxlConnectSupportsFeature(virConnectPtr conn, int = feature) } } =20 -static int -libxlNodeDeviceGetPCIInfo(virNodeDeviceDefPtr def, - unsigned *domain, - unsigned *bus, - unsigned *slot, - unsigned *function) -{ - virNodeDevCapsDefPtr cap; - - cap =3D def->caps; - while (cap) { - if (cap->data.type =3D=3D VIR_NODE_DEV_CAP_PCI_DEV) { - *domain =3D cap->data.pci_dev.domain; - *bus =3D cap->data.pci_dev.bus; - *slot =3D cap->data.pci_dev.slot; - *function =3D cap->data.pci_dev.function; - break; - } - - cap =3D cap->next; - } - - if (!cap) { - virReportError(VIR_ERR_INVALID_ARG, - _("device %s is not a PCI device"), def->name); - return -1; - } - - return 0; -} - static int libxlNodeDeviceDetachFlags(virNodeDevicePtr dev, const char *driverName, @@ -5851,7 +5821,7 @@ libxlNodeDeviceDetachFlags(virNodeDevicePtr dev, if (virNodeDeviceDetachFlagsEnsureACL(dev->conn, def) < 0) goto cleanup; =20 - if (libxlNodeDeviceGetPCIInfo(def, &domain, &bus, &slot, &function) < = 0) + if (virDomainDriverNodeDeviceGetPCIInfo(def, &domain, &bus, &slot, &fu= nction) < 0) goto cleanup; =20 pci =3D virPCIDeviceNew(domain, bus, slot, function); @@ -5922,7 +5892,7 @@ libxlNodeDeviceReAttach(virNodeDevicePtr dev) if (virNodeDeviceReAttachEnsureACL(dev->conn, def) < 0) goto cleanup; =20 - if (libxlNodeDeviceGetPCIInfo(def, &domain, &bus, &slot, &function) < = 0) + if (virDomainDriverNodeDeviceGetPCIInfo(def, &domain, &bus, &slot, &fu= nction) < 0) goto cleanup; =20 pci =3D virPCIDeviceNew(domain, bus, slot, function); @@ -5980,7 +5950,7 @@ libxlNodeDeviceReset(virNodeDevicePtr dev) if (virNodeDeviceResetEnsureACL(dev->conn, def) < 0) goto cleanup; =20 - if (libxlNodeDeviceGetPCIInfo(def, &domain, &bus, &slot, &function) < = 0) + if (virDomainDriverNodeDeviceGetPCIInfo(def, &domain, &bus, &slot, &fu= nction) < 0) goto cleanup; =20 pci =3D virPCIDeviceNew(domain, bus, slot, function); diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 62b0852c33..6c09d95164 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -11951,37 +11951,6 @@ qemuDomainMigrateConfirm3Params(virDomainPtr domai= n, } =20 =20 -static int -qemuNodeDeviceGetPCIInfo(virNodeDeviceDefPtr def, - unsigned *domain, - unsigned *bus, - unsigned *slot, - unsigned *function) -{ - virNodeDevCapsDefPtr cap; - - cap =3D def->caps; - while (cap) { - if (cap->data.type =3D=3D VIR_NODE_DEV_CAP_PCI_DEV) { - *domain =3D cap->data.pci_dev.domain; - *bus =3D cap->data.pci_dev.bus; - *slot =3D cap->data.pci_dev.slot; - *function =3D cap->data.pci_dev.function; - break; - } - - cap =3D cap->next; - } - - if (!cap) { - virReportError(VIR_ERR_INVALID_ARG, - _("device %s is not a PCI device"), def->name); - return -1; - } - - return 0; -} - static int qemuNodeDeviceDetachFlags(virNodeDevicePtr dev, const char *driverName, @@ -12024,7 +11993,7 @@ qemuNodeDeviceDetachFlags(virNodeDevicePtr dev, if (virNodeDeviceDetachFlagsEnsureACL(dev->conn, def) < 0) goto cleanup; =20 - if (qemuNodeDeviceGetPCIInfo(def, &domain, &bus, &slot, &function) < 0) + if (virDomainDriverNodeDeviceGetPCIInfo(def, &domain, &bus, &slot, &fu= nction) < 0) goto cleanup; =20 pci =3D virPCIDeviceNew(domain, bus, slot, function); @@ -12105,7 +12074,7 @@ qemuNodeDeviceReAttach(virNodeDevicePtr dev) if (virNodeDeviceReAttachEnsureACL(dev->conn, def) < 0) goto cleanup; =20 - if (qemuNodeDeviceGetPCIInfo(def, &domain, &bus, &slot, &function) < 0) + if (virDomainDriverNodeDeviceGetPCIInfo(def, &domain, &bus, &slot, &fu= nction) < 0) goto cleanup; =20 pci =3D virPCIDeviceNew(domain, bus, slot, function); @@ -12159,7 +12128,7 @@ qemuNodeDeviceReset(virNodeDevicePtr dev) if (virNodeDeviceResetEnsureACL(dev->conn, def) < 0) goto cleanup; =20 - if (qemuNodeDeviceGetPCIInfo(def, &domain, &bus, &slot, &function) < 0) + if (virDomainDriverNodeDeviceGetPCIInfo(def, &domain, &bus, &slot, &fu= nction) < 0) goto cleanup; =20 pci =3D virPCIDeviceNew(domain, bus, slot, function); --=20 2.26.2 From nobody Tue May 14 22:21:41 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 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=1609764919; cv=none; d=zohomail.com; s=zohoarc; b=j6a6F0Nfv16nNyWrU1NbIgpXtC2LFL1RvomouKAuLKt0hP4UvgACRJHUPz9MRu1gtKkCoplHIIkImq1wiVndoiIdHGlDcZS2LYIa4p5DSuEoqpOu606TDiwD3Uc+Ce/LWCkKAr3Z2gK6w3zP7q0sEoy9T7HDdexiTyvTG7DDwlM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1609764919; 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=RMIiVPhm3Yi18swULl3vaWuGiqnWrb240ygN3rQgjyU=; b=TohtshdJpZ0wwxcgDvggwIA84NiLS1NU/1Ps/ziiLfkfha7WZWAgVNoGd+ydDnl46+ecq1agGPqWLkKQ1gYL8OP5cKUjcUqn9vDiSgH9+CvPm0y/Wf7vUUdsxHKQ4Yo1NsGZ+IKf/ehPEck73WJ+BJELhWB+pFQD2k3ulNUhE+o= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 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-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1609764919454706.7787194463268; Mon, 4 Jan 2021 04:55:19 -0800 (PST) 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-430-z8LloK5YPEmesMY_GBs0CQ-1; Mon, 04 Jan 2021 07:55:15 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5A0211034B21; Mon, 4 Jan 2021 12:55:10 +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 2D4A619714; Mon, 4 Jan 2021 12:55:10 +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 E1FA24E58E; Mon, 4 Jan 2021 12:55:09 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 104Ct7as014144 for ; Mon, 4 Jan 2021 07:55:07 -0500 Received: by smtp.corp.redhat.com (Postfix) id 8942E10BDF; Mon, 4 Jan 2021 12:55:07 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast05.extmail.prod.ext.rdu2.redhat.com [10.11.55.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8327D9D498 for ; Mon, 4 Jan 2021 12:55:05 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5B828805B2F for ; Mon, 4 Jan 2021 12:55:05 +0000 (UTC) Received: from mail-qk1-f170.google.com (mail-qk1-f170.google.com [209.85.222.170]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-169-ylqaXMPoMm-zrI8L5wZZIg-1; Mon, 04 Jan 2021 07:55:03 -0500 Received: by mail-qk1-f170.google.com with SMTP id z11so23219161qkj.7 for ; Mon, 04 Jan 2021 04:55:03 -0800 (PST) Received: from rekt.ibmuc.com ([2804:431:c7c6:ca55:7a5d:da5b:906f:bedd]) by smtp.gmail.com with ESMTPSA id m64sm2342866qkb.90.2021.01.04.04.55.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Jan 2021 04:55:02 -0800 (PST) X-MC-Unique: z8LloK5YPEmesMY_GBs0CQ-1 X-MC-Unique: ylqaXMPoMm-zrI8L5wZZIg-1 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=RMIiVPhm3Yi18swULl3vaWuGiqnWrb240ygN3rQgjyU=; b=g9BjA4B0p3Z6S7xxUgfbgYJbT/Io6UaL65Tz0Zly1mAutYpNKVWxrHlAkO2PlChghK eXCj+UDeZ8glIVH3QxENGYn0WjXpQEy6uSowWubXmYuZD6MW/KuFJJvMMLmedX63zVcC FpXDwaWK3OWNqwR8kU9qJXvWs/jueUuLBu2KSx0Kte7q157bAsplqqYHh9dxhMPoYIfK gIrfz3ONYp4Nnf+NyoY8PFnuW40wHCkcd0n4ZqtCCS/BrhDdh5h2f3r+sa4QnK4oSHzy zUrIHH4YIn5Y3SlYPm1ozwZJrwXpdOIHVjyTZl1UNeFZvMS/dtL+tea4fGE6q2sKriz9 O+Ug== X-Gm-Message-State: AOAM533wowdt2zSweu9F8Czh4aLd3JtUU+kZoFCx8LDFaTeVJuFvZ6qF Z1FIJoZeciZmb0Oe5Ee7icoQbfvIMxR/Qg== X-Google-Smtp-Source: ABdhPJyNdh6ysJVnxqI4nyvdpdGxMf+xcfEpb8sFMrVpzx/TbPE+hNJICARgIghRqK87eKvpxgBCzw== X-Received: by 2002:a37:8e04:: with SMTP id q4mr61309094qkd.22.1609764902684; Mon, 04 Jan 2021 04:55:02 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH 03/20] domain_driver.c: use PCI address with virDomainDriverNodeDeviceGetPCIInfo() Date: Mon, 4 Jan 2021 09:54:27 -0300 Message-Id: <20210104125444.200536-4-danielhb413@gmail.com> In-Reply-To: <20210104125444.200536-1-danielhb413@gmail.com> References: <20210104125444.200536-1-danielhb413@gmail.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza 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.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Instead of receiving 4 uints in order and write domain/bus/slot/function, receive a virPCIDeviceAddressPtr instead and write into it. This change will allow us to simplify the API for virPCIDeviceNew() in the next patch. Signed-off-by: Daniel Henrique Barboza --- src/hypervisor/domain_driver.c | 13 +++++-------- src/hypervisor/domain_driver.h | 5 +---- src/libxl/libxl_driver.c | 18 +++++++++--------- src/qemu/qemu_driver.c | 18 +++++++++--------- 4 files changed, 24 insertions(+), 30 deletions(-) diff --git a/src/hypervisor/domain_driver.c b/src/hypervisor/domain_driver.c index 68dbf10ac6..cdb53bcf3e 100644 --- a/src/hypervisor/domain_driver.c +++ b/src/hypervisor/domain_driver.c @@ -341,20 +341,17 @@ virDomainDriverSetupPersistentDefBlkioParams(virDomai= nDefPtr persistentDef, =20 int virDomainDriverNodeDeviceGetPCIInfo(virNodeDeviceDefPtr def, - unsigned *domain, - unsigned *bus, - unsigned *slot, - unsigned *function) + virPCIDeviceAddressPtr devAddr) { virNodeDevCapsDefPtr cap; =20 cap =3D def->caps; while (cap) { if (cap->data.type =3D=3D VIR_NODE_DEV_CAP_PCI_DEV) { - *domain =3D cap->data.pci_dev.domain; - *bus =3D cap->data.pci_dev.bus; - *slot =3D cap->data.pci_dev.slot; - *function =3D cap->data.pci_dev.function; + devAddr->domain =3D cap->data.pci_dev.domain; + devAddr->bus =3D cap->data.pci_dev.bus; + devAddr->slot =3D cap->data.pci_dev.slot; + devAddr->function =3D cap->data.pci_dev.function; break; } =20 diff --git a/src/hypervisor/domain_driver.h b/src/hypervisor/domain_driver.h index 2bb053d559..86b92d0284 100644 --- a/src/hypervisor/domain_driver.h +++ b/src/hypervisor/domain_driver.h @@ -48,7 +48,4 @@ int virDomainDriverSetupPersistentDefBlkioParams(virDomai= nDefPtr persistentDef, int nparams); =20 int virDomainDriverNodeDeviceGetPCIInfo(virNodeDeviceDefPtr def, - unsigned *domain, - unsigned *bus, - unsigned *slot, - unsigned *function); + virPCIDeviceAddressPtr devAddr); diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index ac2564a563..691cecb1e9 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -5786,7 +5786,7 @@ libxlNodeDeviceDetachFlags(virNodeDevicePtr dev, unsigned int flags) { virPCIDevicePtr pci =3D NULL; - unsigned domain =3D 0, bus =3D 0, slot =3D 0, function =3D 0; + virPCIDeviceAddress devAddr; int ret =3D -1; virNodeDeviceDefPtr def =3D NULL; char *xml =3D NULL; @@ -5821,10 +5821,10 @@ libxlNodeDeviceDetachFlags(virNodeDevicePtr dev, if (virNodeDeviceDetachFlagsEnsureACL(dev->conn, def) < 0) goto cleanup; =20 - if (virDomainDriverNodeDeviceGetPCIInfo(def, &domain, &bus, &slot, &fu= nction) < 0) + if (virDomainDriverNodeDeviceGetPCIInfo(def, &devAddr) < 0) goto cleanup; =20 - pci =3D virPCIDeviceNew(domain, bus, slot, function); + pci =3D virPCIDeviceNew(devAddr.domain, devAddr.bus, devAddr.slot, dev= Addr.function); if (!pci) goto cleanup; =20 @@ -5859,7 +5859,7 @@ static int libxlNodeDeviceReAttach(virNodeDevicePtr dev) { virPCIDevicePtr pci =3D NULL; - unsigned domain =3D 0, bus =3D 0, slot =3D 0, function =3D 0; + virPCIDeviceAddress devAddr; int ret =3D -1; virNodeDeviceDefPtr def =3D NULL; char *xml =3D NULL; @@ -5892,10 +5892,10 @@ libxlNodeDeviceReAttach(virNodeDevicePtr dev) if (virNodeDeviceReAttachEnsureACL(dev->conn, def) < 0) goto cleanup; =20 - if (virDomainDriverNodeDeviceGetPCIInfo(def, &domain, &bus, &slot, &fu= nction) < 0) + if (virDomainDriverNodeDeviceGetPCIInfo(def, &devAddr) < 0) goto cleanup; =20 - pci =3D virPCIDeviceNew(domain, bus, slot, function); + pci =3D virPCIDeviceNew(devAddr.domain, devAddr.bus, devAddr.slot, dev= Addr.function); if (!pci) goto cleanup; =20 @@ -5917,7 +5917,7 @@ static int libxlNodeDeviceReset(virNodeDevicePtr dev) { virPCIDevicePtr pci =3D NULL; - unsigned domain =3D 0, bus =3D 0, slot =3D 0, function =3D 0; + virPCIDeviceAddress devAddr; int ret =3D -1; virNodeDeviceDefPtr def =3D NULL; char *xml =3D NULL; @@ -5950,10 +5950,10 @@ libxlNodeDeviceReset(virNodeDevicePtr dev) if (virNodeDeviceResetEnsureACL(dev->conn, def) < 0) goto cleanup; =20 - if (virDomainDriverNodeDeviceGetPCIInfo(def, &domain, &bus, &slot, &fu= nction) < 0) + if (virDomainDriverNodeDeviceGetPCIInfo(def, &devAddr) < 0) goto cleanup; =20 - pci =3D virPCIDeviceNew(domain, bus, slot, function); + pci =3D virPCIDeviceNew(devAddr.domain, devAddr.bus, devAddr.slot, dev= Addr.function); if (!pci) goto cleanup; =20 diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 6c09d95164..8c59a5e589 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -11958,7 +11958,7 @@ qemuNodeDeviceDetachFlags(virNodeDevicePtr dev, { virQEMUDriverPtr driver =3D dev->conn->privateData; virPCIDevicePtr pci =3D NULL; - unsigned domain =3D 0, bus =3D 0, slot =3D 0, function =3D 0; + virPCIDeviceAddress devAddr; int ret =3D -1; virNodeDeviceDefPtr def =3D NULL; g_autofree char *xml =3D NULL; @@ -11993,10 +11993,10 @@ qemuNodeDeviceDetachFlags(virNodeDevicePtr dev, if (virNodeDeviceDetachFlagsEnsureACL(dev->conn, def) < 0) goto cleanup; =20 - if (virDomainDriverNodeDeviceGetPCIInfo(def, &domain, &bus, &slot, &fu= nction) < 0) + if (virDomainDriverNodeDeviceGetPCIInfo(def, &devAddr) < 0) goto cleanup; =20 - pci =3D virPCIDeviceNew(domain, bus, slot, function); + pci =3D virPCIDeviceNew(devAddr.domain, devAddr.bus, devAddr.slot, dev= Addr.function); if (!pci) goto cleanup; =20 @@ -12042,7 +12042,7 @@ qemuNodeDeviceReAttach(virNodeDevicePtr dev) { virQEMUDriverPtr driver =3D dev->conn->privateData; virPCIDevicePtr pci =3D NULL; - unsigned domain =3D 0, bus =3D 0, slot =3D 0, function =3D 0; + virPCIDeviceAddress devAddr; int ret =3D -1; virNodeDeviceDefPtr def =3D NULL; g_autofree char *xml =3D NULL; @@ -12074,10 +12074,10 @@ qemuNodeDeviceReAttach(virNodeDevicePtr dev) if (virNodeDeviceReAttachEnsureACL(dev->conn, def) < 0) goto cleanup; =20 - if (virDomainDriverNodeDeviceGetPCIInfo(def, &domain, &bus, &slot, &fu= nction) < 0) + if (virDomainDriverNodeDeviceGetPCIInfo(def, &devAddr) < 0) goto cleanup; =20 - pci =3D virPCIDeviceNew(domain, bus, slot, function); + pci =3D virPCIDeviceNew(devAddr.domain, devAddr.bus, devAddr.slot, dev= Addr.function); if (!pci) goto cleanup; =20 @@ -12096,7 +12096,7 @@ qemuNodeDeviceReset(virNodeDevicePtr dev) { virQEMUDriverPtr driver =3D dev->conn->privateData; virPCIDevicePtr pci; - unsigned domain =3D 0, bus =3D 0, slot =3D 0, function =3D 0; + virPCIDeviceAddress devAddr; int ret =3D -1; virNodeDeviceDefPtr def =3D NULL; g_autofree char *xml =3D NULL; @@ -12128,10 +12128,10 @@ qemuNodeDeviceReset(virNodeDevicePtr dev) if (virNodeDeviceResetEnsureACL(dev->conn, def) < 0) goto cleanup; =20 - if (virDomainDriverNodeDeviceGetPCIInfo(def, &domain, &bus, &slot, &fu= nction) < 0) + if (virDomainDriverNodeDeviceGetPCIInfo(def, &devAddr) < 0) goto cleanup; =20 - pci =3D virPCIDeviceNew(domain, bus, slot, function); + pci =3D virPCIDeviceNew(devAddr.domain, devAddr.bus, devAddr.slot, dev= Addr.function); if (!pci) goto cleanup; =20 --=20 2.26.2 From nobody Tue May 14 22:21:41 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 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=1609764925; cv=none; d=zohomail.com; s=zohoarc; b=QGQyjg19VtnJN53yBTilwxlARZuOqify51JVpViWWsw5XzBL3goebL1ODNMarwPj4tfsAviL3BpbEfiospyNH+E6jAQEPulswV0J1V/cH8rrfvZ976R0T4pr59NcsH3TGwJgoUNMH/IlLgqGPfHAUaQ6RL7SxbngwD5UPcbO1jM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1609764925; 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=ziq0Za+qadaftSnfpUpWkjvjhYJ2axTj819/xWxfE2w=; b=d8zEEwIlRACXi1xkTvWvsRtpzl7ljd5nQhREoXWjK5MzZUgDeH6DabVywajqZ1osUU+Ye8XdUubIwzVL5zUHejaV9vc7jeYzxQNVSVJ/laUeD5QRUZHllnZEoJkTJDq3dOlhgzzn9m2YnUc/+jrUkgzkejQ2eVr+N6KZESPth2A= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 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-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1609764925115872.0164107763323; Mon, 4 Jan 2021 04:55:25 -0800 (PST) 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-418-fm6Lv2YEOiOm4jGyUJlrgw-1; Mon, 04 Jan 2021 07:55:21 -0500 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 746D4104FB62; Mon, 4 Jan 2021 12:55:16 +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 5111A5D9D3; Mon, 4 Jan 2021 12:55:16 +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 DAC9D1809CA2; Mon, 4 Jan 2021 12:55:15 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 104Ct9g7014157 for ; Mon, 4 Jan 2021 07:55:09 -0500 Received: by smtp.corp.redhat.com (Postfix) id AA1B82026D48; Mon, 4 Jan 2021 12:55:09 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast04.extmail.prod.ext.rdu2.redhat.com [10.11.55.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A4D622026D47 for ; Mon, 4 Jan 2021 12:55:07 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 07A69101A561 for ; Mon, 4 Jan 2021 12:55:07 +0000 (UTC) Received: from mail-qt1-f178.google.com (mail-qt1-f178.google.com [209.85.160.178]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-295-rwAu4rlTMjaJI_0TlIkZbg-1; Mon, 04 Jan 2021 07:55:05 -0500 Received: by mail-qt1-f178.google.com with SMTP id a6so18337970qtw.6 for ; Mon, 04 Jan 2021 04:55:04 -0800 (PST) Received: from rekt.ibmuc.com ([2804:431:c7c6:ca55:7a5d:da5b:906f:bedd]) by smtp.gmail.com with ESMTPSA id m64sm2342866qkb.90.2021.01.04.04.55.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Jan 2021 04:55:03 -0800 (PST) X-MC-Unique: fm6Lv2YEOiOm4jGyUJlrgw-1 X-MC-Unique: rwAu4rlTMjaJI_0TlIkZbg-1 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=ziq0Za+qadaftSnfpUpWkjvjhYJ2axTj819/xWxfE2w=; b=F8KkbXUjGex083Y301TT7rCrgNbaU0uz9QD56rlvK5TTQsAfEiKFl3FpLuONwkRInd Uqhyk0aEARFTn54HKLvFUSpC1VSr1BGFiq0gvwJoQCMUGnaYDQ9vX2F7IpVAVNhw4U9W PybFT0oxdCi1DkuTNbXqiSlqJB3cE5Z+B+eGvWgzwtRHmkFHbfDbtglTGfqparI4C8P6 jes9NsPeMadCvAWtrql5b0ZiPxUt0wxVd3hw32tzlAxnx4r6yynyggdhlRHh8xoH/S3y aaAQVrITC9g/4m+Db2G9bg7plhq32cmHfZ33Zqt874vHlHaqMJmn3Z3SarSZLwIonnLg +v4Q== X-Gm-Message-State: AOAM530ilvc0b0SDCnXBKKO71UBOpa+Z6qX0muD6JbsQOsYPOHTz5M2j FHosXzjDN9WBH52mxxPZfCLcjJW7BiHdtw== X-Google-Smtp-Source: ABdhPJyQeSdlO6t5dGQM1rRrkEneprmxY/kRgJii04oBljcltuZr7OMIsnQU6odYIbwQoV75IZN5EA== X-Received: by 2002:ac8:5741:: with SMTP id 1mr70072733qtx.294.1609764904153; Mon, 04 Jan 2021 04:55:04 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH 04/20] virpci.c: simplify virPCIDeviceNew() signature Date: Mon, 4 Jan 2021 09:54:28 -0300 Message-Id: <20210104125444.200536-5-danielhb413@gmail.com> In-Reply-To: <20210104125444.200536-1-danielhb413@gmail.com> References: <20210104125444.200536-1-danielhb413@gmail.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza 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 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The current virPCIDeviceNew() signature, receiving 4 uints in sequence (domain, bus, slot, function), is not neat. We already have a way to represent a PCI address in virPCIDeviceAddress that is used in the code. Aside from the test files, most of virPCIDeviceNew() callers have access to a virPCIDeviceAddress reference, but then we need to retrieve the 4 required uints (addr.domain, addr.bus, addr.slot, addr.function) to satisfy virPCIDeviceNew(). The result is that we have extra verbosity/boilerplate to retrieve an information that is already available in virPCIDeviceAddress. A better way is presented by virNVMEDeviceNew(), where the caller just supplies a virPCIDeviceAddress pointer and the function handles the details internally. This patch changes virPCIDeviceNew() to receive a virPCIDeviceAddress pointer instead of 4 uints. Signed-off-by: Daniel Henrique Barboza --- src/hypervisor/virhostdev.c | 3 +-- src/libxl/libxl_driver.c | 6 ++--- src/node_device/node_device_udev.c | 11 +++++--- src/qemu/qemu_domain_address.c | 5 +--- src/qemu/qemu_driver.c | 6 ++--- src/security/security_apparmor.c | 3 +-- src/security/security_dac.c | 6 ++--- src/security/security_selinux.c | 6 ++--- src/security/virt-aa-helper.c | 6 +---- src/util/virnetdev.c | 3 +-- src/util/virnvme.c | 5 +--- src/util/virpci.c | 40 +++++++++--------------------- src/util/virpci.h | 5 +--- tests/virhostdevtest.c | 3 ++- tests/virpcitest.c | 35 +++++++++++++++++++------- 15 files changed, 64 insertions(+), 79 deletions(-) diff --git a/src/hypervisor/virhostdev.c b/src/hypervisor/virhostdev.c index 120187b07a..7338ac0700 100644 --- a/src/hypervisor/virhostdev.c +++ b/src/hypervisor/virhostdev.c @@ -235,8 +235,7 @@ virHostdevGetPCIHostDevice(const virDomainHostdevDef *h= ostdev, hostdev->source.subsys.type !=3D VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PC= I) return 0; =20 - actual =3D virPCIDeviceNew(pcisrc->addr.domain, pcisrc->addr.bus, - pcisrc->addr.slot, pcisrc->addr.function); + actual =3D virPCIDeviceNew(&pcisrc->addr); =20 if (!actual) return -1; diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index 691cecb1e9..9b93fd77d2 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -5824,7 +5824,7 @@ libxlNodeDeviceDetachFlags(virNodeDevicePtr dev, if (virDomainDriverNodeDeviceGetPCIInfo(def, &devAddr) < 0) goto cleanup; =20 - pci =3D virPCIDeviceNew(devAddr.domain, devAddr.bus, devAddr.slot, dev= Addr.function); + pci =3D virPCIDeviceNew(&devAddr); if (!pci) goto cleanup; =20 @@ -5895,7 +5895,7 @@ libxlNodeDeviceReAttach(virNodeDevicePtr dev) if (virDomainDriverNodeDeviceGetPCIInfo(def, &devAddr) < 0) goto cleanup; =20 - pci =3D virPCIDeviceNew(devAddr.domain, devAddr.bus, devAddr.slot, dev= Addr.function); + pci =3D virPCIDeviceNew(&devAddr); if (!pci) goto cleanup; =20 @@ -5953,7 +5953,7 @@ libxlNodeDeviceReset(virNodeDevicePtr dev) if (virDomainDriverNodeDeviceGetPCIInfo(def, &devAddr) < 0) goto cleanup; =20 - pci =3D virPCIDeviceNew(devAddr.domain, devAddr.bus, devAddr.slot, dev= Addr.function); + pci =3D virPCIDeviceNew(&devAddr); if (!pci) goto cleanup; =20 diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_devi= ce_udev.c index 55a2731681..fceb135aa5 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -367,6 +367,7 @@ udevProcessPCI(struct udev_device *device, virNodeDevCapPCIDevPtr pci_dev =3D &def->caps->data.pci_dev; virPCIEDeviceInfoPtr pci_express =3D NULL; virPCIDevicePtr pciDev =3D NULL; + virPCIDeviceAddress devAddr; int ret =3D -1; char *p; bool privileged; @@ -416,10 +417,12 @@ udevProcessPCI(struct udev_device *device, if (virNodeDeviceGetPCIDynamicCaps(def->sysfs_path, pci_dev) < 0) goto cleanup; =20 - if (!(pciDev =3D virPCIDeviceNew(pci_dev->domain, - pci_dev->bus, - pci_dev->slot, - pci_dev->function))) + devAddr.domain =3D pci_dev->domain; + devAddr.bus =3D pci_dev->bus; + devAddr.slot =3D pci_dev->slot; + devAddr.function =3D pci_dev->function; + + if (!(pciDev =3D virPCIDeviceNew(&devAddr))) goto cleanup; =20 /* We need to be root to read PCI device configs */ diff --git a/src/qemu/qemu_domain_address.c b/src/qemu/qemu_domain_address.c index f0ba318cc8..ae4ad6677c 100644 --- a/src/qemu/qemu_domain_address.c +++ b/src/qemu/qemu_domain_address.c @@ -857,10 +857,7 @@ qemuDomainDeviceCalculatePCIConnectFlags(virDomainDevi= ceDefPtr dev, return 0; } =20 - if (!(pciDev =3D virPCIDeviceNew(hostAddr->domain, - hostAddr->bus, - hostAddr->slot, - hostAddr->function))) { + if (!(pciDev =3D virPCIDeviceNew(hostAddr))) { /* libvirt should be able to perform all the * operations in virPCIDeviceNew() even if it's * running unprivileged, so if this fails, the device diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 8c59a5e589..c450501c4d 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -11996,7 +11996,7 @@ qemuNodeDeviceDetachFlags(virNodeDevicePtr dev, if (virDomainDriverNodeDeviceGetPCIInfo(def, &devAddr) < 0) goto cleanup; =20 - pci =3D virPCIDeviceNew(devAddr.domain, devAddr.bus, devAddr.slot, dev= Addr.function); + pci =3D virPCIDeviceNew(&devAddr); if (!pci) goto cleanup; =20 @@ -12077,7 +12077,7 @@ qemuNodeDeviceReAttach(virNodeDevicePtr dev) if (virDomainDriverNodeDeviceGetPCIInfo(def, &devAddr) < 0) goto cleanup; =20 - pci =3D virPCIDeviceNew(devAddr.domain, devAddr.bus, devAddr.slot, dev= Addr.function); + pci =3D virPCIDeviceNew(&devAddr); if (!pci) goto cleanup; =20 @@ -12131,7 +12131,7 @@ qemuNodeDeviceReset(virNodeDevicePtr dev) if (virDomainDriverNodeDeviceGetPCIInfo(def, &devAddr) < 0) goto cleanup; =20 - pci =3D virPCIDeviceNew(devAddr.domain, devAddr.bus, devAddr.slot, dev= Addr.function); + pci =3D virPCIDeviceNew(&devAddr); if (!pci) goto cleanup; =20 diff --git a/src/security/security_apparmor.c b/src/security/security_appar= mor.c index 1b035cce2f..b564866678 100644 --- a/src/security/security_apparmor.c +++ b/src/security/security_apparmor.c @@ -876,8 +876,7 @@ AppArmorSetSecurityHostdevLabel(virSecurityManagerPtr m= gr, =20 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI: { virPCIDevicePtr pci =3D - virPCIDeviceNew(pcisrc->addr.domain, pcisrc->addr.bus, - pcisrc->addr.slot, pcisrc->addr.function); + virPCIDeviceNew(&pcisrc->addr); =20 if (!pci) goto done; diff --git a/src/security/security_dac.c b/src/security/security_dac.c index 4f4a0a069e..b5e56feaa8 100644 --- a/src/security/security_dac.c +++ b/src/security/security_dac.c @@ -1268,8 +1268,7 @@ virSecurityDACSetHostdevLabel(virSecurityManagerPtr m= gr, =20 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI: { virPCIDevicePtr pci =3D - virPCIDeviceNew(pcisrc->addr.domain, pcisrc->addr.bus, - pcisrc->addr.slot, pcisrc->addr.function); + virPCIDeviceNew(&pcisrc->addr); =20 if (!pci) return -1; @@ -1437,8 +1436,7 @@ virSecurityDACRestoreHostdevLabel(virSecurityManagerP= tr mgr, =20 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI: { virPCIDevicePtr pci =3D - virPCIDeviceNew(pcisrc->addr.domain, pcisrc->addr.bus, - pcisrc->addr.slot, pcisrc->addr.function); + virPCIDeviceNew(&pcisrc->addr); =20 if (!pci) return -1; diff --git a/src/security/security_selinux.c b/src/security/security_selinu= x.c index e9cd95916e..c43d326314 100644 --- a/src/security/security_selinux.c +++ b/src/security/security_selinux.c @@ -2104,8 +2104,7 @@ virSecuritySELinuxSetHostdevSubsysLabel(virSecurityMa= nagerPtr mgr, =20 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI: { virPCIDevicePtr pci =3D - virPCIDeviceNew(pcisrc->addr.domain, pcisrc->addr.bus, - pcisrc->addr.slot, pcisrc->addr.function); + virPCIDeviceNew(&pcisrc->addr); =20 if (!pci) return -1; @@ -2344,8 +2343,7 @@ virSecuritySELinuxRestoreHostdevSubsysLabel(virSecuri= tyManagerPtr mgr, =20 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI: { virPCIDevicePtr pci =3D - virPCIDeviceNew(pcisrc->addr.domain, pcisrc->addr.bus, - pcisrc->addr.slot, pcisrc->addr.function); + virPCIDeviceNew(&pcisrc->addr); =20 if (!pci) return -1; diff --git a/src/security/virt-aa-helper.c b/src/security/virt-aa-helper.c index 5a6f4a5f7d..5efdb61e59 100644 --- a/src/security/virt-aa-helper.c +++ b/src/security/virt-aa-helper.c @@ -1104,11 +1104,7 @@ get_files(vahControl * ctl) } =20 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI: { - virPCIDevicePtr pci =3D virPCIDeviceNew( - dev->source.subsys.u.pci.addr.domain, - dev->source.subsys.u.pci.addr.bus, - dev->source.subsys.u.pci.addr.slot, - dev->source.subsys.u.pci.addr.function); + virPCIDevicePtr pci =3D virPCIDeviceNew(&dev->source.subsy= s.u.pci.addr); =20 virDomainHostdevSubsysPCIBackendType backend =3D dev->sour= ce.subsys.u.pci.backend; if (backend =3D=3D VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO || diff --git a/src/util/virnetdev.c b/src/util/virnetdev.c index a73e5f72f1..acb3ec960c 100644 --- a/src/util/virnetdev.c +++ b/src/util/virnetdev.c @@ -1141,8 +1141,7 @@ virNetDevGetPCIDevice(const char *devName) if (!vfPCIAddr) return NULL; =20 - return virPCIDeviceNew(vfPCIAddr->domain, vfPCIAddr->bus, - vfPCIAddr->slot, vfPCIAddr->function); + return virPCIDeviceNew(vfPCIAddr); } # endif =20 diff --git a/src/util/virnvme.c b/src/util/virnvme.c index b8179aa431..66b73cd1d1 100644 --- a/src/util/virnvme.c +++ b/src/util/virnvme.c @@ -290,10 +290,7 @@ virNVMeDeviceCreatePCIDevice(const virNVMeDevice *nvme) { g_autoptr(virPCIDevice) pci =3D NULL; =20 - if (!(pci =3D virPCIDeviceNew(nvme->address.domain, - nvme->address.bus, - nvme->address.slot, - nvme->address.function))) + if (!(pci =3D virPCIDeviceNew(&nvme->address))) return NULL; =20 /* NVMe devices must be bound to vfio */ diff --git a/src/util/virpci.c b/src/util/virpci.c index 3d9d583622..545b2650a0 100644 --- a/src/util/virpci.c +++ b/src/util/virpci.c @@ -475,24 +475,24 @@ virPCIDeviceIterDevices(virPCIDeviceIterPredicate pre= dicate, return -1; =20 while ((ret =3D virDirRead(dir, &entry, PCI_SYSFS "devices")) > 0) { - unsigned int domain, bus, slot, function; g_autoptr(virPCIDevice) check =3D NULL; + virPCIDeviceAddress devAddr; char *tmp; =20 /* expected format: ::. */ if (/* domain */ - virStrToLong_ui(entry->d_name, &tmp, 16, &domain) < 0 || *tmp = !=3D ':' || + virStrToLong_ui(entry->d_name, &tmp, 16, &devAddr.domain) < 0 = || *tmp !=3D ':' || /* bus */ - virStrToLong_ui(tmp + 1, &tmp, 16, &bus) < 0 || *tmp !=3D ':' = || + virStrToLong_ui(tmp + 1, &tmp, 16, &devAddr.bus) < 0 || *tmp != =3D ':' || /* slot */ - virStrToLong_ui(tmp + 1, &tmp, 16, &slot) < 0 || *tmp !=3D '.'= || + virStrToLong_ui(tmp + 1, &tmp, 16, &devAddr.slot) < 0 || *tmp = !=3D '.' || /* function */ - virStrToLong_ui(tmp + 1, NULL, 16, &function) < 0) { + virStrToLong_ui(tmp + 1, NULL, 16, &devAddr.function) < 0) { VIR_WARN("Unusual entry in " PCI_SYSFS "devices: %s", entry->d= _name); continue; } =20 - check =3D virPCIDeviceNew(domain, bus, slot, function); + check =3D virPCIDeviceNew(&devAddr); if (!check) { ret =3D -1; break; @@ -767,10 +767,7 @@ virPCIDeviceIsParent(virPCIDevicePtr dev, virPCIDevice= Ptr check, void *data) */ if (dev->address.bus > secondary && dev->address.bus <=3D subordinate)= { if (*best =3D=3D NULL) { - *best =3D virPCIDeviceNew(check->address.domain, - check->address.bus, - check->address.slot, - check->address.function); + *best =3D virPCIDeviceNew(&check->address); if (*best =3D=3D NULL) { ret =3D -1; goto cleanup; @@ -790,10 +787,7 @@ virPCIDeviceIsParent(virPCIDevicePtr dev, virPCIDevice= Ptr check, void *data) =20 if (secondary > best_secondary) { virPCIDeviceFree(*best); - *best =3D virPCIDeviceNew(check->address.domain, - check->address.bus, - check->address.slot, - check->address.function); + *best =3D virPCIDeviceNew(&check->address); if (*best =3D=3D NULL) { ret =3D -1; goto cleanup; @@ -1455,10 +1449,7 @@ virPCIDeviceAddressAsString(const virPCIDeviceAddres= s *addr) } =20 virPCIDevicePtr -virPCIDeviceNew(unsigned int domain, - unsigned int bus, - unsigned int slot, - unsigned int function) +virPCIDeviceNew(const virPCIDeviceAddress *address) { g_autoptr(virPCIDevice) dev =3D NULL; g_autofree char *vendor =3D NULL; @@ -1466,10 +1457,7 @@ virPCIDeviceNew(unsigned int domain, =20 dev =3D g_new0(virPCIDevice, 1); =20 - dev->address.domain =3D domain; - dev->address.bus =3D bus; - dev->address.slot =3D slot; - dev->address.function =3D function; + virPCIDeviceAddressCopy(&dev->address, address); =20 dev->name =3D virPCIDeviceAddressAsString(&dev->address); =20 @@ -1896,8 +1884,7 @@ virPCIDeviceGetIOMMUGroupAddOne(virPCIDeviceAddressPt= r newDevAddr, void *opaque) virPCIDeviceListPtr groupList =3D opaque; g_autoptr(virPCIDevice) newDev =3D NULL; =20 - if (!(newDev =3D virPCIDeviceNew(newDevAddr->domain, newDevAddr->bus, - newDevAddr->slot, newDevAddr->function)= )) + if (!(newDev =3D virPCIDeviceNew(newDevAddr))) return -1; =20 if (virPCIDeviceListAdd(groupList, newDev) < 0) @@ -2028,10 +2015,7 @@ virPCIDeviceAddressGetIOMMUGroupDev(const virPCIDevi= ceAddress *devAddr) { g_autoptr(virPCIDevice) pci =3D NULL; =20 - if (!(pci =3D virPCIDeviceNew(devAddr->domain, - devAddr->bus, - devAddr->slot, - devAddr->function))) + if (!(pci =3D virPCIDeviceNew(devAddr))) return NULL; =20 return virPCIDeviceGetIOMMUGroupDev(pci); diff --git a/src/util/virpci.h b/src/util/virpci.h index 43828b0a8a..d4451848c1 100644 --- a/src/util/virpci.h +++ b/src/util/virpci.h @@ -113,10 +113,7 @@ struct _virPCIEDeviceInfo { virPCIELink *link_sta; /* Actually negotiated capabilities */ }; =20 -virPCIDevicePtr virPCIDeviceNew(unsigned int domain, - unsigned int bus, - unsigned int slot, - unsigned int function); +virPCIDevicePtr virPCIDeviceNew(const virPCIDeviceAddress *address); virPCIDevicePtr virPCIDeviceCopy(virPCIDevicePtr dev); void virPCIDeviceFree(virPCIDevicePtr dev); const char *virPCIDeviceGetName(virPCIDevicePtr dev); diff --git a/tests/virhostdevtest.c b/tests/virhostdevtest.c index 385db0849a..40c14a5281 100644 --- a/tests/virhostdevtest.c +++ b/tests/virhostdevtest.c @@ -138,7 +138,8 @@ myInit(void) } =20 for (i =3D 0; i < nhostdevs; i++) { - if (!(dev[i] =3D virPCIDeviceNew(0, 0, i + 1, 0))) + virDomainHostdevSubsys subsys =3D hostdevs[i]->source.subsys; + if (!(dev[i] =3D virPCIDeviceNew(&subsys.u.pci.addr))) goto cleanup; =20 virPCIDeviceSetStubDriver(dev[i], VIR_PCI_STUB_DRIVER_VFIO); diff --git a/tests/virpcitest.c b/tests/virpcitest.c index 6f064a3f85..6a4bd5518d 100644 --- a/tests/virpcitest.c +++ b/tests/virpcitest.c @@ -60,8 +60,9 @@ testVirPCIDeviceNew(const void *opaque G_GNUC_UNUSED) int ret =3D -1; virPCIDevicePtr dev; const char *devName; + virPCIDeviceAddress devAddr =3D {.domain =3D 0, .bus =3D 0, .slot =3D = 0, .function =3D 0}; =20 - if (!(dev =3D virPCIDeviceNew(0, 0, 0, 0))) + if (!(dev =3D virPCIDeviceNew(&devAddr))) goto cleanup; =20 devName =3D virPCIDeviceGetName(dev); @@ -103,7 +104,9 @@ testVirPCIDeviceDetach(const void *opaque G_GNUC_UNUSED) CHECK_LIST_COUNT(inactiveDevs, 0); =20 for (i =3D 0; i < nDev; i++) { - if (!(dev[i] =3D virPCIDeviceNew(0, 0, i + 1, 0))) + virPCIDeviceAddress devAddr =3D {.domain =3D 0, .bus =3D 0, + .slot =3D i + 1, .function =3D 0}; + if (!(dev[i] =3D virPCIDeviceNew(&devAddr))) goto cleanup; =20 virPCIDeviceSetStubDriver(dev[i], VIR_PCI_STUB_DRIVER_VFIO); @@ -144,7 +147,9 @@ testVirPCIDeviceReset(const void *opaque G_GNUC_UNUSED) CHECK_LIST_COUNT(inactiveDevs, 0); =20 for (i =3D 0; i < nDev; i++) { - if (!(dev[i] =3D virPCIDeviceNew(0, 0, i + 1, 0))) + virPCIDeviceAddress devAddr =3D {.domain =3D 0, .bus =3D 0, + .slot =3D i + 1, .function =3D 0}; + if (!(dev[i] =3D virPCIDeviceNew(&devAddr))) goto cleanup; =20 virPCIDeviceSetStubDriver(dev[i], VIR_PCI_STUB_DRIVER_VFIO); @@ -176,7 +181,9 @@ testVirPCIDeviceReattach(const void *opaque G_GNUC_UNUS= ED) goto cleanup; =20 for (i =3D 0; i < nDev; i++) { - if (!(dev[i] =3D virPCIDeviceNew(0, 0, i + 1, 0))) + virPCIDeviceAddress devAddr =3D {.domain =3D 0, .bus =3D 0, + .slot =3D i + 1, .function =3D 0}; + if (!(dev[i] =3D virPCIDeviceNew(&devAddr))) goto cleanup; =20 if (virPCIDeviceListAdd(inactiveDevs, dev[i]) < 0) { @@ -222,8 +229,10 @@ testVirPCIDeviceIsAssignable(const void *opaque) const struct testPCIDevData *data =3D opaque; int ret =3D -1; virPCIDevicePtr dev; + virPCIDeviceAddress devAddr =3D {.domain =3D data->domain, .bus =3D da= ta->bus, + .slot =3D data->slot, .function =3D dat= a->function}; =20 - if (!(dev =3D virPCIDeviceNew(data->domain, data->bus, data->slot, dat= a->function))) + if (!(dev =3D virPCIDeviceNew(&devAddr))) return -1; =20 if (virPCIDeviceIsAssignable(dev, true)) @@ -239,8 +248,10 @@ testVirPCIDeviceDetachSingle(const void *opaque) const struct testPCIDevData *data =3D opaque; int ret =3D -1; virPCIDevicePtr dev; + virPCIDeviceAddress devAddr =3D {.domain =3D data->domain, .bus =3D da= ta->bus, + .slot =3D data->slot, .function =3D dat= a->function}; =20 - dev =3D virPCIDeviceNew(data->domain, data->bus, data->slot, data->fun= ction); + dev =3D virPCIDeviceNew(&devAddr); if (!dev) goto cleanup; =20 @@ -261,8 +272,10 @@ testVirPCIDeviceReattachSingle(const void *opaque) const struct testPCIDevData *data =3D opaque; int ret =3D -1; virPCIDevicePtr dev; + virPCIDeviceAddress devAddr =3D {.domain =3D data->domain, .bus =3D da= ta->bus, + .slot =3D data->slot, .function =3D dat= a->function}; =20 - dev =3D virPCIDeviceNew(data->domain, data->bus, data->slot, data->fun= ction); + dev =3D virPCIDeviceNew(&devAddr); if (!dev) goto cleanup; =20 @@ -285,8 +298,10 @@ testVirPCIDeviceCheckDriverTest(const void *opaque) const struct testPCIDevData *data =3D opaque; int ret =3D -1; virPCIDevicePtr dev; + virPCIDeviceAddress devAddr =3D {.domain =3D data->domain, .bus =3D da= ta->bus, + .slot =3D data->slot, .function =3D dat= a->function}; =20 - dev =3D virPCIDeviceNew(data->domain, data->bus, data->slot, data->fun= ction); + dev =3D virPCIDeviceNew(&devAddr); if (!dev) goto cleanup; =20 @@ -305,8 +320,10 @@ testVirPCIDeviceUnbind(const void *opaque) const struct testPCIDevData *data =3D opaque; int ret =3D -1; virPCIDevicePtr dev; + virPCIDeviceAddress devAddr =3D {.domain =3D data->domain, .bus =3D da= ta->bus, + .slot =3D data->slot, .function =3D dat= a->function}; =20 - dev =3D virPCIDeviceNew(data->domain, data->bus, data->slot, data->fun= ction); + dev =3D virPCIDeviceNew(&devAddr); if (!dev) goto cleanup; =20 --=20 2.26.2 From nobody Tue May 14 22:21:41 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 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=1609764929; cv=none; d=zohomail.com; s=zohoarc; b=g1GsVWBm95IY6idJdEBihDFace1A2OCb8P3OGeF49jKPj7CNMUrbdYwE8G1ZkRXvq2mGHapWEM6WmeKkKzRGcFESedDEGZzbTHaGZPJf/PNBBtXEx66s6iOBoQv0pPGHF6GrTMZjbneVMbZjMzWi+bMbDYuF/4yEMDHPTSdVkJM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1609764929; 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=/WM1lQBxI4H1SkZ3Qj2kNpQhU+WgytRtjBNVNmO1zaI=; b=WqL+J28LL3cB2n5kI1GNK5MpdGs4tIO7Ndju0Gy4wlHLJSlRPzyN7SjlOYTbyJCPhtMDbe6rFLv5bx0xhmWycOxf8VUSLz2oPWoX9OEzQh4DgnfvyjskYtbUnWBSTxb1T81iez+ECavhAeH0J4SrEpn0AlnH0tBWJgDQ1HWm03s= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 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-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1609764929187351.18853157599926; Mon, 4 Jan 2021 04:55:29 -0800 (PST) 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-429-bUlW7ecLNq2GAS5K7YHvgA-1; Mon, 04 Jan 2021 07:55:24 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 271CD85C73B; Mon, 4 Jan 2021 12:55:19 +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 051A55D761; Mon, 4 Jan 2021 12:55:19 +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 C3D3A1809CA6; Mon, 4 Jan 2021 12:55:18 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 104CtBM4014175 for ; Mon, 4 Jan 2021 07:55:11 -0500 Received: by smtp.corp.redhat.com (Postfix) id 702FE2166B2B; Mon, 4 Jan 2021 12:55:11 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast04.extmail.prod.ext.rdu2.redhat.com [10.11.55.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6AC4C2166B2A for ; Mon, 4 Jan 2021 12:55:08 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 83A29101A560 for ; Mon, 4 Jan 2021 12:55:08 +0000 (UTC) Received: from mail-qk1-f182.google.com (mail-qk1-f182.google.com [209.85.222.182]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-199-VL9LTp9xMx6lu9UQUCzaJA-1; Mon, 04 Jan 2021 07:55:06 -0500 Received: by mail-qk1-f182.google.com with SMTP id z11so23219280qkj.7 for ; Mon, 04 Jan 2021 04:55:06 -0800 (PST) Received: from rekt.ibmuc.com ([2804:431:c7c6:ca55:7a5d:da5b:906f:bedd]) by smtp.gmail.com with ESMTPSA id m64sm2342866qkb.90.2021.01.04.04.55.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Jan 2021 04:55:05 -0800 (PST) X-MC-Unique: bUlW7ecLNq2GAS5K7YHvgA-1 X-MC-Unique: VL9LTp9xMx6lu9UQUCzaJA-1 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=/WM1lQBxI4H1SkZ3Qj2kNpQhU+WgytRtjBNVNmO1zaI=; b=b8rJ5ev435Gb1pWzfrxYlgVUHVejdY09ONoifp2Cc5A0EzP7AXUttu9CIEIlpNqgoI Ai9gSN2qIMnwzj1NDI4Gs4vJzSBtxJGRW+NFPr/AuWCDYIjyO8WVD2xL/PFcrE0hKnMd ENE1Z5U2BhicCIi+sCPUC3wf37LaP1DqxFJ5iQ44ftLxWHQlZvuP5AEFd4h5jH1xVuMR yJpeIjGAEJrlT6HbJwOsw9YgJl+tGXwFSPMcuVOkr9NgYeWSVxowR2eD51hFh5arO1od L6UnyS+U2kwbBNevOELsumfLWTMhI56ynjPhKWjqDv5XOYYNR2wEVH9wG/JjbeLykAt7 qfgg== X-Gm-Message-State: AOAM531MLOuWlxkNEP/2j7EEVVcddqggQFcRUab1+FangApRyU41gjR5 /H38k4W/hmz/lRXIX5ik4ECN3tZLL2wDNA== X-Google-Smtp-Source: ABdhPJwCMarq3niIEhvWgUpUzkENJuH/b6XYm4FjSUaJSx0pV0zdeKMB/UKNkZluhPGenVvbREFIMw== X-Received: by 2002:a37:4e50:: with SMTP id c77mr70089099qkb.252.1609764905845; Mon, 04 Jan 2021 04:55:05 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH 05/20] virpci: introduce virPCIDeviceExists() Date: Mon, 4 Jan 2021 09:54:29 -0300 Message-Id: <20210104125444.200536-6-danielhb413@gmail.com> In-Reply-To: <20210104125444.200536-1-danielhb413@gmail.com> References: <20210104125444.200536-1-danielhb413@gmail.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza 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.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" We're going to add logic to handle the case where a previously existing PCI device does not longer exist in the host. The logic was copied from virPCIDeviceNew(), which verifies if a PCI device exists in the host, returning NULL and throwing an error if it doesn't. The NULL is used for other errors as well (product/vendor id read errors, dev id overflow), meaning that we can't re-use virPCIDeviceNew() for the purpose of detecting if the device exists. Signed-off-by: Daniel Henrique Barboza --- src/libvirt_private.syms | 1 + src/util/virpci.c | 10 ++++++++++ src/util/virpci.h | 1 + 3 files changed, 12 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index fe4ee25f3a..81ce142635 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2817,6 +2817,7 @@ virPCIDeviceAddressIsValid; virPCIDeviceAddressParse; virPCIDeviceCopy; virPCIDeviceDetach; +virPCIDeviceExists; virPCIDeviceFileIterate; virPCIDeviceFree; virPCIDeviceGetAddress; diff --git a/src/util/virpci.c b/src/util/virpci.c index 545b2650a0..1a542b18b6 100644 --- a/src/util/virpci.c +++ b/src/util/virpci.c @@ -1448,6 +1448,16 @@ virPCIDeviceAddressAsString(const virPCIDeviceAddres= s *addr) return str; } =20 +bool +virPCIDeviceExists(const virPCIDeviceAddress *addr) +{ + g_autofree char *devName =3D virPCIDeviceAddressAsString(addr); + g_autofree char *devPath =3D g_strdup_printf(PCI_SYSFS "devices/%s/con= fig", + devName); + + return virFileExists(devPath); +} + virPCIDevicePtr virPCIDeviceNew(const virPCIDeviceAddress *address) { diff --git a/src/util/virpci.h b/src/util/virpci.h index d4451848c1..a9c597a428 100644 --- a/src/util/virpci.h +++ b/src/util/virpci.h @@ -201,6 +201,7 @@ int virPCIDeviceAddressGetIOMMUGroupAddresses(virPCIDev= iceAddressPtr devAddr, size_t *nIommuGroupDevices); int virPCIDeviceAddressGetIOMMUGroupNum(virPCIDeviceAddressPtr addr); char *virPCIDeviceAddressGetIOMMUGroupDev(const virPCIDeviceAddress *devAd= dr); +bool virPCIDeviceExists(const virPCIDeviceAddress *addr); char *virPCIDeviceGetIOMMUGroupDev(virPCIDevicePtr dev); =20 int virPCIDeviceIsAssignable(virPCIDevicePtr dev, --=20 2.26.2 From nobody Tue May 14 22:21:41 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 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=1609764929; cv=none; d=zohomail.com; s=zohoarc; b=UpBC5yMl45LsH508bUypy/34zc0Pm/2z9jiOcg6LgyrS/GgMXsrLf1huGA+0pCwv8z9bYUA8Kc03WlYeYOS42/IxpjDTnONihVyl9yeDqVi8054AUsWNGSEgRWkQy16Qk3aXto8SOEU+atL2c6iHsQlN2TShFIBQISw1UzcIIZY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1609764929; 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=z19WsnDE7LVSTMUd6oVQKk7YJflEz2zp60QXJXfAjmc=; b=YeiaLrdE7o90dDStaI1LhaT9QycjIxwas0RuzfI9/OrWeICOUJgoHvbaf8vP1Z0QVT6q8vFrgPpenl3T+BVf3f3VeckKCR5GIbRAxsdZLOBZBSlLuuItJhvhSaDOTAAuv2a1tRudVPOnEijJoBsMH6J0wzKsKbfnl/XCZV3wKwQ= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 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-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1609764929251126.76147173322158; Mon, 4 Jan 2021 04:55:29 -0800 (PST) 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-22-w59dSmqjNuKj2s6R86P_wA-1; Mon, 04 Jan 2021 07:55:24 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id B3FD9107ACE4; Mon, 4 Jan 2021 12:55:19 +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 8AC9B19717; Mon, 4 Jan 2021 12:55:19 +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 24EA55002F; Mon, 4 Jan 2021 12:55:19 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 104CtAIi014163 for ; Mon, 4 Jan 2021 07:55:10 -0500 Received: by smtp.corp.redhat.com (Postfix) id 9DF25112D405; Mon, 4 Jan 2021 12:55:10 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast02.extmail.prod.ext.rdu2.redhat.com [10.11.55.18]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9A0AA112D404 for ; Mon, 4 Jan 2021 12:55:10 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 87F9580122E for ; Mon, 4 Jan 2021 12:55:10 +0000 (UTC) Received: from mail-qt1-f175.google.com (mail-qt1-f175.google.com [209.85.160.175]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-283-vsIsVeK9MDy-w_1_wGl38Q-1; Mon, 04 Jan 2021 07:55:08 -0500 Received: by mail-qt1-f175.google.com with SMTP id c14so18360855qtn.0 for ; Mon, 04 Jan 2021 04:55:08 -0800 (PST) Received: from rekt.ibmuc.com ([2804:431:c7c6:ca55:7a5d:da5b:906f:bedd]) by smtp.gmail.com with ESMTPSA id m64sm2342866qkb.90.2021.01.04.04.55.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Jan 2021 04:55:07 -0800 (PST) X-MC-Unique: w59dSmqjNuKj2s6R86P_wA-1 X-MC-Unique: vsIsVeK9MDy-w_1_wGl38Q-1 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=z19WsnDE7LVSTMUd6oVQKk7YJflEz2zp60QXJXfAjmc=; b=X4kPeq6HVvcOgC5zNGYUp5iZ0K1//3eCl1DTFXzfCGR5dfKLd8cdHcv8Bd7R9NN4Qp WSft1FN9RS5GkiB6EiboQebD02HEOO/DbU0l60OQl97iYCMmaye7IqxIbLkoF1nUs24K 3i5fxnfB94oHetPkXJKIWc3uo9ful7Tu3ors9chJM6KJ3WxlGiee1kYz6YOQOG8FbjRx NjoXq0HUdUrWm4a2woT1NIxLKEx02SxdgOiBWe6uI9X4gyc4if2AxsHjQ+Iq7HTTHvYx AbMHPfFgBGqKgGuqicosgua271EG/b/tAkjFCbtiF3pZgHxuc1Ic2IrozmAiUlHFv7zY DsdQ== X-Gm-Message-State: AOAM531jZrf89U4gi5oMdbhA1nsY1PqGFwXbjDI2b72O8dWeJqDKHEKG 5mNik607dnLUmxfJp1MhJhzweM5RU6N7mA== X-Google-Smtp-Source: ABdhPJwjINXkBKXFIZy4S0vOkULswlcXVyBd6a0gWGqCoCNwsvTo8tte7Wqtd/FmDa6nry/ZTShRSg== X-Received: by 2002:ac8:5a0f:: with SMTP id n15mr72114434qta.88.1609764907762; Mon, 04 Jan 2021 04:55:07 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH 06/20] virhostdev.c: virHostdevGetPCIHostDevice() now reports missing device Date: Mon, 4 Jan 2021 09:54:30 -0300 Message-Id: <20210104125444.200536-7-danielhb413@gmail.com> In-Reply-To: <20210104125444.200536-1-danielhb413@gmail.com> References: <20210104125444.200536-1-danielhb413@gmail.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza 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.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Gitlab issue #72 [1] reports that removing SR-IOVs VFs before removing the devices from the running domains can have strange consequences. QEMU might be able to hotunplug the device inside the guest, but Libvirt will not be aware of that, and then the guest is now inconsistent with the domain definition. There's also the possibility of the VFs removal not succeeding while the domain is running but then, as soon as the domain is shutdown, all the VFs are removed. Libvirt can't handle the removal of the PCI devices while trying to reattach the hostdevs, and the Libvirt daemon can be left in an inconsistent state (see [2]). This patch starts to address the issue related in Gitlab #72, most notably the issue described in [2]. When shutting down a domain with SR-IOV hostdevs that got missing, virHostdevReAttachPCIDevices() is failing the whole process and failing to reattach all the PCI devices, including the ones that aren't related to the VFs that went missing. Let's make it more resilient with host changes by changing virHostdevGetPCIHostDevice() to return an exclusive error code '-2' for this case. virHostdevGetPCIHostDeviceList() can then tell when virHostdevGetPCIHostDevice() failed to find the PCI device of a hostdev and continue to make the list of PCI devices. virHostdevReAttachPCIDevices() will now be able to proceed reattaching all other valid PCI devices, at least. The 'ghost hostdevs' will be handled later on. [1] https://gitlab.com/libvirt/libvirt/-/issues/72 [2] https://gitlab.com/libvirt/libvirt/-/issues/72#note_459032148 Signed-off-by: Daniel Henrique Barboza --- src/hypervisor/virhostdev.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/hypervisor/virhostdev.c b/src/hypervisor/virhostdev.c index 7338ac0700..18373deb41 100644 --- a/src/hypervisor/virhostdev.c +++ b/src/hypervisor/virhostdev.c @@ -220,7 +220,8 @@ virHostdevManagerGetDefault(void) * is returned. * * Returns: 0 on success (@pci might be NULL though), - * -1 otherwise (with error reported). + * -1 otherwise (with error reported), + * -2 PCI device not found. @pci will be NULL */ static int virHostdevGetPCIHostDevice(const virDomainHostdevDef *hostdev, @@ -235,6 +236,9 @@ virHostdevGetPCIHostDevice(const virDomainHostdevDef *h= ostdev, hostdev->source.subsys.type !=3D VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PC= I) return 0; =20 + if (!virPCIDeviceExists(&pcisrc->addr)) + return -2; + actual =3D virPCIDeviceNew(&pcisrc->addr); =20 if (!actual) @@ -270,7 +274,7 @@ virHostdevGetPCIHostDeviceList(virDomainHostdevDefPtr *= hostdevs, int nhostdevs) virDomainHostdevDefPtr hostdev =3D hostdevs[i]; g_autoptr(virPCIDevice) pci =3D NULL; =20 - if (virHostdevGetPCIHostDevice(hostdev, &pci) < 0) + if (virHostdevGetPCIHostDevice(hostdev, &pci) =3D=3D -1) return NULL; =20 if (!pci) --=20 2.26.2 From nobody Tue May 14 22:21:41 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 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=1609764930; cv=none; d=zohomail.com; s=zohoarc; b=iMS3gFBHRWgx4xVxPe/6wPNnSoxDmsJEg0Rtq6f5HtHokQ41DY9RnTUo2XMxFFockiBF4CbEUQ3sMvxyGCxalx2aMw6kjlYLJtS+gcYjMXcJaJXfz/WsWE/UH4ufRsqkR7aqcZUv+Uws9Rzu+t0/bxPKyfSWOvBbCz9AVOl7C14= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1609764930; 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=MpuBZWrkJlYtDmUT0hu4LKujruVaBq4a04ooDfgwiZI=; b=gc0iLP+seBC2CjwgfVL058+6aglNXf2L0hO/D/8tYkJ5OVdTTplX2bp1khbNOD+HguNuhQnLVIO+IzbIcb/VkZKCop88iIMUNp1oqahupjzcRUzckcVURR+A7u7mJwBppaK4Q6tw9NS6H86387TbTYB2DOXjeWV3FvDUrsjymn8= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 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-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1609764930977943.5415945256225; Mon, 4 Jan 2021 04:55:30 -0800 (PST) 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-578-rCO7dbLjN6msIINEjXLkcw-1; Mon, 04 Jan 2021 07:55:27 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1129883DC6E; Mon, 4 Jan 2021 12:55:22 +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 E14F55D761; Mon, 4 Jan 2021 12:55:21 +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 AD6FB1809CA8; Mon, 4 Jan 2021 12:55:21 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 104CtCc7014184 for ; Mon, 4 Jan 2021 07:55:12 -0500 Received: by smtp.corp.redhat.com (Postfix) id 574659D498; Mon, 4 Jan 2021 12:55:12 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast03.extmail.prod.ext.rdu2.redhat.com [10.11.55.19]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 522CB7AF6 for ; Mon, 4 Jan 2021 12:55:12 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3F5AE811E78 for ; Mon, 4 Jan 2021 12:55:12 +0000 (UTC) Received: from mail-qk1-f172.google.com (mail-qk1-f172.google.com [209.85.222.172]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-524-eU_DHXhDNfaf2iRn0aX04g-1; Mon, 04 Jan 2021 07:55:10 -0500 Received: by mail-qk1-f172.google.com with SMTP id 186so23231327qkj.3 for ; Mon, 04 Jan 2021 04:55:10 -0800 (PST) Received: from rekt.ibmuc.com ([2804:431:c7c6:ca55:7a5d:da5b:906f:bedd]) by smtp.gmail.com with ESMTPSA id m64sm2342866qkb.90.2021.01.04.04.55.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Jan 2021 04:55:08 -0800 (PST) X-MC-Unique: rCO7dbLjN6msIINEjXLkcw-1 X-MC-Unique: eU_DHXhDNfaf2iRn0aX04g-1 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=MpuBZWrkJlYtDmUT0hu4LKujruVaBq4a04ooDfgwiZI=; b=RezkoOMZniKSIxl1KN0/8zCj7enHRETzDCTzT9QvU8rJG0buCu2F7C3V81hLjFnUok X6OCr26v3EszWnORx8yGSq1bQWlfnSD3lfjr9igHDNJqGfy5Pq+onB3FfdR0qZPJ3K1x ac9QP4jY8WtiumX3XEd1dUBb9j6KLOszL1NascrYs+hT114a6692SgF9fGlX4c8+ZqJX 5v/o5Z1H4aJ4y4Y7gupCJ0sXXNe7D9nkPX0lu8sH8ppQ7HUYlXs5VwtjlRMTGgGCXCri h7J5xtav51sNyl5ntF4YRS0pqibCR1NNtxBxvpO/WQV5k9m9ItMO30siJ3jtiGI3zZ+w ybLQ== X-Gm-Message-State: AOAM532w21DgASdQeJbj7ifi7pK/ZwpT79sTiX6L/xZIJ1+ClVRSkIMQ TbftvdrRv9OAx3UNEW0CPbHKaVX6MmQQnA== X-Google-Smtp-Source: ABdhPJyQ3+nMdTPMlknglrVGnv6WrXCIn+buBA/PIx0TDYTib2nDv1b1Woq3jQ8Pv+OiQYEwbzlGbA== X-Received: by 2002:a37:8703:: with SMTP id j3mr63333147qkd.455.1609764909434; Mon, 04 Jan 2021 04:55:09 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH 07/20] security_selinux.c: modernize set/restore hostdev subsys label functions Date: Mon, 4 Jan 2021 09:54:31 -0300 Message-Id: <20210104125444.200536-8-danielhb413@gmail.com> In-Reply-To: <20210104125444.200536-1-danielhb413@gmail.com> References: <20210104125444.200536-1-danielhb413@gmail.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza 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.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use g_auto* cleanup to avoid free() calls. Signed-off-by: Daniel Henrique Barboza --- src/security/security_selinux.c | 54 ++++++++++----------------------- 1 file changed, 16 insertions(+), 38 deletions(-) diff --git a/src/security/security_selinux.c b/src/security/security_selinu= x.c index c43d326314..bf53932ccc 100644 --- a/src/security/security_selinux.c +++ b/src/security/security_selinux.c @@ -2086,7 +2086,7 @@ virSecuritySELinuxSetHostdevSubsysLabel(virSecurityMa= nagerPtr mgr, =20 switch ((virDomainHostdevSubsysType)dev->source.subsys.type) { case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB: { - virUSBDevicePtr usb; + g_autoptr(virUSBDevice) usb =3D NULL; =20 if (dev->missing) return 0; @@ -2098,39 +2098,34 @@ virSecuritySELinuxSetHostdevSubsysLabel(virSecurity= ManagerPtr mgr, return -1; =20 ret =3D virUSBDeviceFileIterate(usb, virSecuritySELinuxSetUSBLabel= , &data); - virUSBDeviceFree(usb); break; } =20 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI: { - virPCIDevicePtr pci =3D - virPCIDeviceNew(&pcisrc->addr); + g_autoptr(virPCIDevice) pci =3D virPCIDeviceNew(&pcisrc->addr); =20 if (!pci) return -1; =20 if (pcisrc->backend =3D=3D VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO) { - char *vfioGroupDev =3D virPCIDeviceGetIOMMUGroupDev(pci); + g_autofree char *vfioGroupDev =3D virPCIDeviceGetIOMMUGroupDev= (pci); =20 - if (!vfioGroupDev) { - virPCIDeviceFree(pci); + if (!vfioGroupDev) return -1; - } + ret =3D virSecuritySELinuxSetHostdevLabelHelper(vfioGroupDev, false, &data); - VIR_FREE(vfioGroupDev); } else { ret =3D virPCIDeviceFileIterate(pci, virSecuritySELinuxSetPCIL= abel, &data); } - virPCIDeviceFree(pci); break; } =20 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI: { virDomainHostdevSubsysSCSIHostPtr scsihostsrc =3D &scsisrc->u.host; =20 - virSCSIDevicePtr scsi =3D + g_autoptr(virSCSIDevice) scsi =3D virSCSIDeviceNew(NULL, scsihostsrc->adapter, scsihostsrc->bus, scsihostsrc->target, scsihostsrc->unit, @@ -2142,13 +2137,11 @@ virSecuritySELinuxSetHostdevSubsysLabel(virSecurity= ManagerPtr mgr, ret =3D virSCSIDeviceFileIterate(scsi, virSecuritySELinuxSetSCSILabel, &data); - virSCSIDeviceFree(scsi); - break; } =20 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI_HOST: { - virSCSIVHostDevicePtr host =3D virSCSIVHostDeviceNew(hostsrc->wwpn= ); + g_autoptr(virSCSIVHostDevice) host =3D virSCSIVHostDeviceNew(hosts= rc->wwpn); =20 if (!host) return -1; @@ -2156,19 +2149,16 @@ virSecuritySELinuxSetHostdevSubsysLabel(virSecurity= ManagerPtr mgr, ret =3D virSCSIVHostDeviceFileIterate(host, virSecuritySELinuxSetHostLabel, &data); - virSCSIVHostDeviceFree(host); break; } =20 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV: { - char *vfiodev =3D NULL; + g_autofree char *vfiodev =3D NULL; =20 if (!(vfiodev =3D virMediatedDeviceGetIOMMUGroupDev(mdevsrc->uuids= tr))) return ret; =20 ret =3D virSecuritySELinuxSetHostdevLabelHelper(vfiodev, true, &da= ta); - - VIR_FREE(vfiodev); break; } =20 @@ -2324,7 +2314,7 @@ virSecuritySELinuxRestoreHostdevSubsysLabel(virSecuri= tyManagerPtr mgr, =20 switch ((virDomainHostdevSubsysType)dev->source.subsys.type) { case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB: { - virUSBDevicePtr usb; + g_autoptr(virUSBDevice) usb =3D NULL; =20 if (dev->missing) return 0; @@ -2336,37 +2326,31 @@ virSecuritySELinuxRestoreHostdevSubsysLabel(virSecu= rityManagerPtr mgr, return -1; =20 ret =3D virUSBDeviceFileIterate(usb, virSecuritySELinuxRestoreUSBL= abel, mgr); - virUSBDeviceFree(usb); - break; } =20 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI: { - virPCIDevicePtr pci =3D - virPCIDeviceNew(&pcisrc->addr); + g_autoptr(virPCIDevice) pci =3D virPCIDeviceNew(&pcisrc->addr); =20 if (!pci) return -1; =20 if (pcisrc->backend =3D=3D VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO) { - char *vfioGroupDev =3D virPCIDeviceGetIOMMUGroupDev(pci); + g_autofree char *vfioGroupDev =3D virPCIDeviceGetIOMMUGroupDev= (pci); =20 - if (!vfioGroupDev) { - virPCIDeviceFree(pci); + if (!vfioGroupDev) return -1; - } + ret =3D virSecuritySELinuxRestoreFileLabel(mgr, vfioGroupDev, = false); - VIR_FREE(vfioGroupDev); } else { ret =3D virPCIDeviceFileIterate(pci, virSecuritySELinuxRestore= PCILabel, mgr); } - virPCIDeviceFree(pci); break; } =20 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI: { virDomainHostdevSubsysSCSIHostPtr scsihostsrc =3D &scsisrc->u.host; - virSCSIDevicePtr scsi =3D + g_autoptr(virSCSIDevice) scsi =3D virSCSIDeviceNew(NULL, scsihostsrc->adapter, scsihostsrc->bus, scsihostsrc->target, scsihostsrc->unit, @@ -2376,13 +2360,11 @@ virSecuritySELinuxRestoreHostdevSubsysLabel(virSecu= rityManagerPtr mgr, return -1; =20 ret =3D virSCSIDeviceFileIterate(scsi, virSecuritySELinuxRestoreSC= SILabel, mgr); - virSCSIDeviceFree(scsi); - break; } =20 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI_HOST: { - virSCSIVHostDevicePtr host =3D virSCSIVHostDeviceNew(hostsrc->wwpn= ); + g_autoptr(virSCSIVHostDevice) host =3D virSCSIVHostDeviceNew(hosts= rc->wwpn); =20 if (!host) return -1; @@ -2390,20 +2372,16 @@ virSecuritySELinuxRestoreHostdevSubsysLabel(virSecu= rityManagerPtr mgr, ret =3D virSCSIVHostDeviceFileIterate(host, virSecuritySELinuxRestoreHostL= abel, mgr); - virSCSIVHostDeviceFree(host); - break; } =20 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV: { - char *vfiodev =3D NULL; + g_autofree char *vfiodev =3D NULL; =20 if (!(vfiodev =3D virMediatedDeviceGetIOMMUGroupDev(mdevsrc->uuids= tr))) return -1; =20 ret =3D virSecuritySELinuxRestoreFileLabel(mgr, vfiodev, true); - - VIR_FREE(vfiodev); break; } =20 --=20 2.26.2 From nobody Tue May 14 22:21:41 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 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=1609764932; cv=none; d=zohomail.com; s=zohoarc; b=Hid/XNJsEWniinUzP4/MSWSooVXUniY8Phq277tgPjoIxNqzEgQFf3zQYscWu7HQgA/HHpqe8e4vRITK9EywAuU5tYKZMLfVptLGM0LQLScZniAPtME/cMG7Bk1wD2s/4WvLgyBqP/dmJs5Vv0tooLgDOuTo0c2dCDrgiFNiXx0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1609764932; 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=7bXd3vvbW1wcOtNzLw1YhHuQoIuWrZfyTfg+yKVKq/M=; b=WW6w812ay193xofGXntVnitEnj288DW4WeZbOnF2BolFuod8YATWLR1IWNFW5dQ8Lu2ATXqr+3gEfGMCmIavTB9pU3RvvstEBIf3Q2OSOBHo8HcOiUxoL6eLIcH2J755xT23xkj9WdyYEZLAB451pdNRmAuTtoCEc0Y0VYX8874= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 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-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1609764932891258.14660142858145; Mon, 4 Jan 2021 04:55:32 -0800 (PST) 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-525-HSy2nSTHN8CaiUxn9CjMZA-1; Mon, 04 Jan 2021 07:55:28 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id CD201190A7A1; Mon, 4 Jan 2021 12:55:22 +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 A18A319726; Mon, 4 Jan 2021 12:55:22 +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 6C7E71809CA9; Mon, 4 Jan 2021 12:55:22 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 104CtE3X014201 for ; Mon, 4 Jan 2021 07:55:14 -0500 Received: by smtp.corp.redhat.com (Postfix) id 0A6212166B2B; Mon, 4 Jan 2021 12:55:14 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast05.extmail.prod.ext.rdu2.redhat.com [10.11.55.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 04EA42166B2A for ; Mon, 4 Jan 2021 12:55:14 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E3DA8800157 for ; Mon, 4 Jan 2021 12:55:13 +0000 (UTC) Received: from mail-qt1-f182.google.com (mail-qt1-f182.google.com [209.85.160.182]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-482-jZRy8nilMuK985HqfXkFug-1; Mon, 04 Jan 2021 07:55:11 -0500 Received: by mail-qt1-f182.google.com with SMTP id h19so18299776qtq.13 for ; Mon, 04 Jan 2021 04:55:11 -0800 (PST) Received: from rekt.ibmuc.com ([2804:431:c7c6:ca55:7a5d:da5b:906f:bedd]) by smtp.gmail.com with ESMTPSA id m64sm2342866qkb.90.2021.01.04.04.55.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Jan 2021 04:55:10 -0800 (PST) X-MC-Unique: HSy2nSTHN8CaiUxn9CjMZA-1 X-MC-Unique: jZRy8nilMuK985HqfXkFug-1 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=7bXd3vvbW1wcOtNzLw1YhHuQoIuWrZfyTfg+yKVKq/M=; b=AFB5AqdRPBCChV089tma7QQTAlQwVSCQTBVKd0gahKNEwtku6rWj3gd6sIRUyBUWst qVctZPBC/tHFRw1pqup9jUg9UAIVLyiGk5Vb7iBGv0ZpkN/ZZ/li4tokfp3SgzQNBgmn 0nIwRGG8a9v6AgvnqXMWvsoXvKzEpEs3fTXr4wyy6cMDhcHDz1FgkMJpfPKl5MBwF+lA ZehcoNmMowBOq+LL6JpVrJ9Yw9vP4uyzM9f35w77QSG1iCuOKhLC7N6ZNhyuJEufzi/j ECL+PDe1SKuvoCN7+vW2LyYC61ZPJOYyJTwnhuLhWtxYJc41+U4gpqHXZV7kQGjl0NcP jkTA== X-Gm-Message-State: AOAM533PeK+PTIX80vX2ZzcQFLMpn2sQxSvbGndy+inyLJAZTyTnjDpG oj5HECFhmD4ty3BTooauVxaVsqcuZ2iTTg== X-Google-Smtp-Source: ABdhPJxUF03zJw8PFtHiadbkjgyj3Fsj85UuUatGPO5cAHvlpG9ijXVfDy1tyu/oUH8/06I4bjNCQQ== X-Received: by 2002:a05:622a:242:: with SMTP id c2mr69086717qtx.39.1609764911182; Mon, 04 Jan 2021 04:55:11 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH 08/20] security_dac.c: modernize hostdev label set/restore functions Date: Mon, 4 Jan 2021 09:54:32 -0300 Message-Id: <20210104125444.200536-9-danielhb413@gmail.com> In-Reply-To: <20210104125444.200536-1-danielhb413@gmail.com> References: <20210104125444.200536-1-danielhb413@gmail.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza 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.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use g_auto* cleanup to avoid free() calls. Signed-off-by: Daniel Henrique Barboza --- src/security/security_dac.c | 49 +++++++++++-------------------------- 1 file changed, 14 insertions(+), 35 deletions(-) diff --git a/src/security/security_dac.c b/src/security/security_dac.c index b5e56feaa8..0085982bb1 100644 --- a/src/security/security_dac.c +++ b/src/security/security_dac.c @@ -1251,7 +1251,7 @@ virSecurityDACSetHostdevLabel(virSecurityManagerPtr m= gr, =20 switch ((virDomainHostdevSubsysType)dev->source.subsys.type) { case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB: { - virUSBDevicePtr usb; + g_autoptr(virUSBDevice) usb =3D NULL; =20 if (dev->missing) return 0; @@ -1262,41 +1262,35 @@ virSecurityDACSetHostdevLabel(virSecurityManagerPtr= mgr, ret =3D virUSBDeviceFileIterate(usb, virSecurityDACSetUSBLabel, &cbdata); - virUSBDeviceFree(usb); break; } =20 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI: { - virPCIDevicePtr pci =3D - virPCIDeviceNew(&pcisrc->addr); + g_autoptr(virPCIDevice) pci =3D virPCIDeviceNew(&pcisrc->addr); =20 if (!pci) return -1; =20 if (pcisrc->backend =3D=3D VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO) { - char *vfioGroupDev =3D virPCIDeviceGetIOMMUGroupDev(pci); + g_autofree char *vfioGroupDev =3D virPCIDeviceGetIOMMUGroupDev= (pci); =20 - if (!vfioGroupDev) { - virPCIDeviceFree(pci); + if (!vfioGroupDev) return -1; - } + ret =3D virSecurityDACSetHostdevLabelHelper(vfioGroupDev, false, &cbdata); - VIR_FREE(vfioGroupDev); } else { ret =3D virPCIDeviceFileIterate(pci, virSecurityDACSetPCILabel, &cbdata); } - - virPCIDeviceFree(pci); break; } =20 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI: { virDomainHostdevSubsysSCSIHostPtr scsihostsrc =3D &scsisrc->u.host; - virSCSIDevicePtr scsi =3D + g_autoptr(virSCSIDevice) scsi =3D virSCSIDeviceNew(NULL, scsihostsrc->adapter, scsihostsrc->bus, scsihostsrc->target, scsihostsrc->unit, @@ -1308,13 +1302,11 @@ virSecurityDACSetHostdevLabel(virSecurityManagerPtr= mgr, ret =3D virSCSIDeviceFileIterate(scsi, virSecurityDACSetSCSILabel, &cbdata); - virSCSIDeviceFree(scsi); - break; } =20 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI_HOST: { - virSCSIVHostDevicePtr host =3D virSCSIVHostDeviceNew(hostsrc->wwpn= ); + g_autoptr(virSCSIVHostDevice) host =3D virSCSIVHostDeviceNew(hosts= rc->wwpn); =20 if (!host) return -1; @@ -1322,19 +1314,16 @@ virSecurityDACSetHostdevLabel(virSecurityManagerPtr= mgr, ret =3D virSCSIVHostDeviceFileIterate(host, virSecurityDACSetHostLabel, &cbdata); - virSCSIVHostDeviceFree(host); break; } =20 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV: { - char *vfiodev =3D NULL; + g_autofree char *vfiodev =3D NULL; =20 if (!(vfiodev =3D virMediatedDeviceGetIOMMUGroupDev(mdevsrc->uuids= tr))) return -1; =20 ret =3D virSecurityDACSetHostdevLabelHelper(vfiodev, true, &cbdata= ); - - VIR_FREE(vfiodev); break; } =20 @@ -1420,7 +1409,7 @@ virSecurityDACRestoreHostdevLabel(virSecurityManagerP= tr mgr, =20 switch ((virDomainHostdevSubsysType)dev->source.subsys.type) { case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB: { - virUSBDevicePtr usb; + g_autoptr(virUSBDevice) usb =3D NULL; =20 if (dev->missing) return 0; @@ -1429,20 +1418,17 @@ virSecurityDACRestoreHostdevLabel(virSecurityManage= rPtr mgr, return -1; =20 ret =3D virUSBDeviceFileIterate(usb, virSecurityDACRestoreUSBLabel= , mgr); - virUSBDeviceFree(usb); - break; } =20 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI: { - virPCIDevicePtr pci =3D - virPCIDeviceNew(&pcisrc->addr); + g_autoptr(virPCIDevice) pci =3D virPCIDeviceNew(&pcisrc->addr); =20 if (!pci) return -1; =20 if (pcisrc->backend =3D=3D VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO) { - char *vfioGroupDev =3D virPCIDeviceGetIOMMUGroupDev(pci); + g_autofree char *vfioGroupDev =3D virPCIDeviceGetIOMMUGroupDev= (pci); =20 if (!vfioGroupDev) { virPCIDeviceFree(pci); @@ -1450,17 +1436,15 @@ virSecurityDACRestoreHostdevLabel(virSecurityManage= rPtr mgr, } ret =3D virSecurityDACRestoreFileLabelInternal(mgr, NULL, vfioGroupDev, fal= se); - VIR_FREE(vfioGroupDev); } else { ret =3D virPCIDeviceFileIterate(pci, virSecurityDACRestorePCIL= abel, mgr); } - virPCIDeviceFree(pci); break; } =20 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI: { virDomainHostdevSubsysSCSIHostPtr scsihostsrc =3D &scsisrc->u.host; - virSCSIDevicePtr scsi =3D + g_autoptr(virSCSIDevice) scsi =3D virSCSIDeviceNew(NULL, scsihostsrc->adapter, scsihostsrc->bus, scsihostsrc->target, scsihostsrc->unit, @@ -1470,13 +1454,11 @@ virSecurityDACRestoreHostdevLabel(virSecurityManage= rPtr mgr, return -1; =20 ret =3D virSCSIDeviceFileIterate(scsi, virSecurityDACRestoreSCSILa= bel, mgr); - virSCSIDeviceFree(scsi); - break; } =20 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI_HOST: { - virSCSIVHostDevicePtr host =3D virSCSIVHostDeviceNew(hostsrc->wwpn= ); + g_autoptr(virSCSIVHostDevice) host =3D virSCSIVHostDeviceNew(hosts= rc->wwpn); =20 if (!host) return -1; @@ -1484,19 +1466,16 @@ virSecurityDACRestoreHostdevLabel(virSecurityManage= rPtr mgr, ret =3D virSCSIVHostDeviceFileIterate(host, virSecurityDACRestoreHostLabel, mgr); - virSCSIVHostDeviceFree(host); - break; } =20 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV: { - char *vfiodev =3D NULL; + g_autofree char *vfiodev =3D NULL; =20 if (!(vfiodev =3D virMediatedDeviceGetIOMMUGroupDev(mdevsrc->uuids= tr))) return -1; =20 ret =3D virSecurityDACRestoreFileLabel(mgr, vfiodev); - VIR_FREE(vfiodev); break; } =20 --=20 2.26.2 From nobody Tue May 14 22:21:41 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 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=1609764938; cv=none; d=zohomail.com; s=zohoarc; b=Az5EsdrgKcANS1kQubeFZWReb+1pq8uFU+lAyRNdoBTcMJ36MsfiHM8JccrkPKOYV04UleJB/MGbP8OLKyF+A6RXmB4pnj/gcVBu8WD4tXJONXH68m7lLSPAXBhKI2ngQ8NeG5KO9xQ/oVgwh9Z9E/Hnl+yBKFx+bb3zjXNEQu0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1609764938; 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=ExHhpnQXdnlWzeq1Ys3fUvyqcnqysdfF/JXQQMPG6+8=; b=MCWHf3RGP+LsZVD/Yljl9N/uqXOdRRc/8diqQjsj0iTZtFZmbzTmTHvz1T9x6Lf+qTnemJ421uWQZDpNvmACxkax0r2xRlQcpG7OqbSbcQ0hAgBbLiY9WaXMt6tGYGYuHZpAXQv/zZZju/qPcwURWXP9k+/wAOlX/P9oTG1sEFw= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 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-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1609764938681489.21260110577396; Mon, 4 Jan 2021 04:55:38 -0800 (PST) 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-561-bUiG3vRPPdSVOijU4OTOAA-1; Mon, 04 Jan 2021 07:55:32 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 743A5190A7A3; Mon, 4 Jan 2021 12:55:25 +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 4F05271C80; Mon, 4 Jan 2021 12:55:25 +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 198DF1809CAD; Mon, 4 Jan 2021 12:55:25 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 104CtGZY014216 for ; Mon, 4 Jan 2021 07:55:16 -0500 Received: by smtp.corp.redhat.com (Postfix) id 89BCD2166B2A; Mon, 4 Jan 2021 12:55:16 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast04.extmail.prod.ext.rdu2.redhat.com [10.11.55.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 841932166B2C for ; Mon, 4 Jan 2021 12:55:15 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id AEBB7101A561 for ; Mon, 4 Jan 2021 12:55:15 +0000 (UTC) Received: from mail-qt1-f181.google.com (mail-qt1-f181.google.com [209.85.160.181]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-395-n5_TkPR4PraurU16u4lxnw-1; Mon, 04 Jan 2021 07:55:13 -0500 Received: by mail-qt1-f181.google.com with SMTP id y15so18324515qtv.5 for ; Mon, 04 Jan 2021 04:55:13 -0800 (PST) Received: from rekt.ibmuc.com ([2804:431:c7c6:ca55:7a5d:da5b:906f:bedd]) by smtp.gmail.com with ESMTPSA id m64sm2342866qkb.90.2021.01.04.04.55.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Jan 2021 04:55:12 -0800 (PST) X-MC-Unique: bUiG3vRPPdSVOijU4OTOAA-1 X-MC-Unique: n5_TkPR4PraurU16u4lxnw-1 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=ExHhpnQXdnlWzeq1Ys3fUvyqcnqysdfF/JXQQMPG6+8=; b=RNgKZ5xgcS5SXu7DNlM/5RlxIB9a45+kZdr0f4x8x35LkrkZPpYB8phyfWOuf5SEbV 5sQRibmzGMq4kcYRQNMai67fbux0+M0BjzoiO9IEluPVYaF7aqi3LbcS2ziazG9tAnjd o98hnjwxCdbvu0MCULUCWYLKACEHvRbarTMytBKJruiIsJ1DSUPT+6YlZTc/r/4y5pb+ Hn1nFhpLlWVk5dl3QSoV8YXFYeg4eQRy+0nP3WhdkjW4+t/9v9gWQ9fEOWd/ttxjeI6J gy7al1Nl0yqax7TOZzTmUu5MeYP4g0PNqPyLCkaiTkygNa1yzFVGfK/K7ySrnWoMERBJ xvmQ== X-Gm-Message-State: AOAM531kLw5WfFZ7oiAGVCRgyCVfUcieYMIFFeJTGFtluBqo148DsYGW xwkPi/T7tUL2SmZ0LsFBAr2nu/SgmCEDrw== X-Google-Smtp-Source: ABdhPJxd8kovmlkXZt8LTJA4IetnZ5u55ByPq0vmwRoyyCCc9f4veT/Q0vYOrwq6uymT4V690b4ZUw== X-Received: by 2002:a05:622a:301:: with SMTP id q1mr69655741qtw.237.1609764912877; Mon, 04 Jan 2021 04:55:12 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH 09/20] dac, selinux: skip setting/restoring label for absent PCI devices Date: Mon, 4 Jan 2021 09:54:33 -0300 Message-Id: <20210104125444.200536-10-danielhb413@gmail.com> In-Reply-To: <20210104125444.200536-1-danielhb413@gmail.com> References: <20210104125444.200536-1-danielhb413@gmail.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza 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.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" If the underlying PCI device of a hostdev does not exist in the host (e.g. a SR-IOV VF that was removed while the domain was running), skip security label handling for it. This will avoid errors that happens during qemuProcessStop() time, where a VF that was being used by the domain is not present anymore. The restore label functions of both DAC and SELinux drivers will trigger errors in virPCIDeviceNew(). Signed-off-by: Daniel Henrique Barboza --- src/security/security_dac.c | 14 ++++++++++++-- src/security/security_selinux.c | 14 ++++++++++++-- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/security/security_dac.c b/src/security/security_dac.c index 0085982bb1..a2528aeb2d 100644 --- a/src/security/security_dac.c +++ b/src/security/security_dac.c @@ -1266,7 +1266,12 @@ virSecurityDACSetHostdevLabel(virSecurityManagerPtr = mgr, } =20 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI: { - g_autoptr(virPCIDevice) pci =3D virPCIDeviceNew(&pcisrc->addr); + g_autoptr(virPCIDevice) pci =3D NULL; + + if (!virPCIDeviceExists(&pcisrc->addr)) + break; + + pci =3D virPCIDeviceNew(&pcisrc->addr); =20 if (!pci) return -1; @@ -1422,7 +1427,12 @@ virSecurityDACRestoreHostdevLabel(virSecurityManager= Ptr mgr, } =20 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI: { - g_autoptr(virPCIDevice) pci =3D virPCIDeviceNew(&pcisrc->addr); + g_autoptr(virPCIDevice) pci =3D NULL; + + if (!virPCIDeviceExists(&pcisrc->addr)) + break; + + pci =3D virPCIDeviceNew(&pcisrc->addr); =20 if (!pci) return -1; diff --git a/src/security/security_selinux.c b/src/security/security_selinu= x.c index bf53932ccc..cf4984d8b1 100644 --- a/src/security/security_selinux.c +++ b/src/security/security_selinux.c @@ -2102,7 +2102,12 @@ virSecuritySELinuxSetHostdevSubsysLabel(virSecurityM= anagerPtr mgr, } =20 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI: { - g_autoptr(virPCIDevice) pci =3D virPCIDeviceNew(&pcisrc->addr); + g_autoptr(virPCIDevice) pci =3D NULL; + + if (!virPCIDeviceExists(&pcisrc->addr)) + break; + + pci =3D virPCIDeviceNew(&pcisrc->addr); =20 if (!pci) return -1; @@ -2330,7 +2335,12 @@ virSecuritySELinuxRestoreHostdevSubsysLabel(virSecur= ityManagerPtr mgr, } =20 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI: { - g_autoptr(virPCIDevice) pci =3D virPCIDeviceNew(&pcisrc->addr); + g_autoptr(virPCIDevice) pci =3D NULL; + + if (!virPCIDeviceExists(&pcisrc->addr)) + break; + + pci =3D virPCIDeviceNew(&pcisrc->addr); =20 if (!pci) return -1; --=20 2.26.2 From nobody Tue May 14 22:21:41 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 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=1609764943; cv=none; d=zohomail.com; s=zohoarc; b=VxK7AvbrcwehMBH+JgidOILsn+wNZwiGYCWitWzmKng8S0JPc9JwAqz/UBoW3tzJ368d/LXxYkPiiDNHHh1FUyqFtPfWN3JhP+DQoB93majCcs/v1/pDy1gQkGQwVObdeUkMJq8otzZUvOC0J3RCepL6dEjbtTuk+E1kb4USimk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1609764943; 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=KkXA8nbHEmyOoA1A/iVV767Uffh2WISvLLS7+4w4WrY=; b=hN8kciRZ39KT4r6jorktnuJ1R3t8wn/+qD/pNMQBfexgla6RryEJWlFOIr98xDw0+yposF1Il4ze3CwmSj3ruVlIqsw3T0rF+GI0PhKKFkSQy/Oi6MjePnNteWoM4qzVwz9YkqIk+/npLgzLDxwJUFnU7mfEdtR25tvm4eOteqI= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 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-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1609764943861683.0744932312105; Mon, 4 Jan 2021 04:55:43 -0800 (PST) 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-80-bteOlenhNJGuosStyJERGA-1; Mon, 04 Jan 2021 07:55:40 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A6D8D107ACE8; Mon, 4 Jan 2021 12:55:33 +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 83ADB6E50A; Mon, 4 Jan 2021 12:55:33 +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 4ECDD5003D; Mon, 4 Jan 2021 12:55:33 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 104CtMZl014248 for ; Mon, 4 Jan 2021 07:55:22 -0500 Received: by smtp.corp.redhat.com (Postfix) id EECF1112D407; Mon, 4 Jan 2021 12:55:21 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast03.extmail.prod.ext.rdu2.redhat.com [10.11.55.19]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EACF2112D405 for ; Mon, 4 Jan 2021 12:55:17 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9EE19811E78 for ; Mon, 4 Jan 2021 12:55:17 +0000 (UTC) Received: from mail-qv1-f43.google.com (mail-qv1-f43.google.com [209.85.219.43]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-179-2Gan9IVNOfKPmHWcVBru3A-1; Mon, 04 Jan 2021 07:55:15 -0500 Received: by mail-qv1-f43.google.com with SMTP id et9so12885059qvb.10 for ; Mon, 04 Jan 2021 04:55:15 -0800 (PST) Received: from rekt.ibmuc.com ([2804:431:c7c6:ca55:7a5d:da5b:906f:bedd]) by smtp.gmail.com with ESMTPSA id m64sm2342866qkb.90.2021.01.04.04.55.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Jan 2021 04:55:14 -0800 (PST) X-MC-Unique: bteOlenhNJGuosStyJERGA-1 X-MC-Unique: 2Gan9IVNOfKPmHWcVBru3A-1 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=KkXA8nbHEmyOoA1A/iVV767Uffh2WISvLLS7+4w4WrY=; b=HnCfEYPpoHC8eR4LVWE4/T5qGmD9kGIPBt5tGRpWDtc4OzaAbWKP6newFkP5goADuD 1vEr2k2UhHxiJ9Cyv7K+9pzudXYmh0k0FCpvZrgYSGhpbypvRZGFW+/SEwrRhXj8+K6N jN3lteY/sbKwj/voFiaLDXKSzJIo3iTgHezLMqx8UzqSrVQ1VxiUC8Hwd2Nfeg/9huxp ptQgxN4eFs/oUXGrKVa7khNh2Al9/p3zKA0jH83+8GQtq95pmUIUC+XXMjdpxSx3N5Ef 6+1HScBVAl/7Z5KPkFKPEjp8ybbyCs5v1I7/WffxrjAu8/9S2pEsYgsXTTfwfj32sjWI nNQQ== X-Gm-Message-State: AOAM531TStWynVIZ5rDpotqSDHUE9o67r54yQyKYYcpKzb63whhjvdIb Nal0yJDCKK7CONT7fAqcSHcRVRc/rGk5Aw== X-Google-Smtp-Source: ABdhPJz709QrQxRJYDtrJSFaRpw23s6oTBOsNBMnzJ56WPFrwFZe+LqBqd+C+jonmh/tLcOIl6hhFw== X-Received: by 2002:a05:6214:302:: with SMTP id i2mr77251945qvu.14.1609764914674; Mon, 04 Jan 2021 04:55:14 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH 10/20] libvirt-nodedev.c: remove return value from virNodeDeviceFree() Date: Mon, 4 Jan 2021 09:54:34 -0300 Message-Id: <20210104125444.200536-11-danielhb413@gmail.com> In-Reply-To: <20210104125444.200536-1-danielhb413@gmail.com> References: <20210104125444.200536-1-danielhb413@gmail.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza 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.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The function returns -1 on error, but no caller is actually checking the return value. Making it 'void' makes more sense with its current use. Signed-off-by: Daniel Henrique Barboza --- include/libvirt/libvirt-nodedev.h | 2 +- src/libvirt-nodedev.c | 15 +++++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/include/libvirt/libvirt-nodedev.h b/include/libvirt/libvirt-no= dedev.h index eab8abf6ab..5634980a75 100644 --- a/include/libvirt/libvirt-nodedev.h +++ b/include/libvirt/libvirt-nodedev.h @@ -114,7 +114,7 @@ char * virNodeDeviceGetXMLDesc (virNod= eDevicePtr dev, unsigned int flags); =20 int virNodeDeviceRef (virNodeDevicePtr dev); -int virNodeDeviceFree (virNodeDevicePtr dev); +void virNodeDeviceFree (virNodeDevicePtr dev); =20 int virNodeDeviceDettach (virNodeDevicePtr dev); int virNodeDeviceDetachFlags(virNodeDevicePtr dev, diff --git a/src/libvirt-nodedev.c b/src/libvirt-nodedev.c index eb8c735a8c..fcca40f47b 100644 --- a/src/libvirt-nodedev.c +++ b/src/libvirt-nodedev.c @@ -445,19 +445,26 @@ virNodeDeviceListCaps(virNodeDevicePtr dev, * Drops a reference to the node device, freeing it if * this was the last reference. * - * Returns the 0 for success, -1 for error. + * Throws a VIR_ERR_INVALID_NODE_DEVICE error if @dev is + * not a valid node device. Does nothing if @dev is + * NULL. */ -int +void virNodeDeviceFree(virNodeDevicePtr dev) { + if (!dev) + return; + VIR_DEBUG("dev=3D%p, conn=3D%p", dev, dev ? dev->conn : NULL); =20 virResetLastError(); =20 - virCheckNodeDeviceReturn(dev, -1); + virCheckNodeDeviceGoto(dev, invalid_device); =20 virObjectUnref(dev); - return 0; + + invalid_device: + return; } =20 =20 --=20 2.26.2 From nobody Tue May 14 22:21:41 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 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=1609764939; cv=none; d=zohomail.com; s=zohoarc; b=EfojbKF0OsuhjoEBn5edvYIWACSbYfuE18QESqqZC4S6CWPbKiEKr+OSU3mAVpBX/0qtPO0f4GT4a/t0DOLhNwvnaNYEcCd/FUkFe/PEoufvhRbkliLMQO6qKLTlbgbzzM6oH3qdeoW3r31VIbQzIxFEk2n4iN0jJjUAQ+wr7bY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1609764939; 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=mU6JXVxWXI1r8w5+sHUToc4p/D6vMgwMTfi7GhUCM9I=; b=K1pzqJOVcgS7pKkTCMDGLxaeBFMLH7edKxqlLLRF9UcPajSdkUfYZNy6YZlHAgncDhKfy6Miz5oBol1FID9LR3ayApoeyvS1znjsQ8aQc9D4PkIbCL/ZO0T1RTdqxcOXXLJt9aUOttuy0n+sQQOyufxl4JYjwtDYBb5T9XxZzVs= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 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-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1609764939166439.411840929998; Mon, 4 Jan 2021 04:55:39 -0800 (PST) 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-181-M2yzvlP5O1eURJyK_i4lqA-1; Mon, 04 Jan 2021 07:55:35 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 39F04C73BC; Mon, 4 Jan 2021 12:55:28 +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 1875760C13; Mon, 4 Jan 2021 12:55:28 +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 DB0711809CB1; Mon, 4 Jan 2021 12:55:27 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 104CtJBd014229 for ; Mon, 4 Jan 2021 07:55:19 -0500 Received: by smtp.corp.redhat.com (Postfix) id E7D4B2026D48; Mon, 4 Jan 2021 12:55:18 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast03.extmail.prod.ext.rdu2.redhat.com [10.11.55.19]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E27B92026D47 for ; Mon, 4 Jan 2021 12:55:18 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id CEB93811E76 for ; Mon, 4 Jan 2021 12:55:18 +0000 (UTC) Received: from mail-qk1-f179.google.com (mail-qk1-f179.google.com [209.85.222.179]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-373--uwzxZ51Ohuqztyat9oslw-1; Mon, 04 Jan 2021 07:55:16 -0500 Received: by mail-qk1-f179.google.com with SMTP id b64so23161808qkc.12 for ; Mon, 04 Jan 2021 04:55:16 -0800 (PST) Received: from rekt.ibmuc.com ([2804:431:c7c6:ca55:7a5d:da5b:906f:bedd]) by smtp.gmail.com with ESMTPSA id m64sm2342866qkb.90.2021.01.04.04.55.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Jan 2021 04:55:15 -0800 (PST) X-MC-Unique: M2yzvlP5O1eURJyK_i4lqA-1 X-MC-Unique: -uwzxZ51Ohuqztyat9oslw-1 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=mU6JXVxWXI1r8w5+sHUToc4p/D6vMgwMTfi7GhUCM9I=; b=VDgm0dReeoLHqTnYMVaY2YCZDj4uWp69lS50CN6GaUEC1s2wSpaAGwWLcKPJLQ/+FR RHiCtAxEjdv09ejK8wyW+a1GsCUolQKWoRPn9dwEPLVPsHnQWbO8C0V5DUqKn4oSFeId LBprvt2QCL30ZOywvjclZ40R9QrZgfOI27o8FXZoyH0Cc0HRDW2mhu1q6+ApYP50fJPz OqAqh3CZ4SK4WYYX1ko18DzhGt6TtkKh3InKl95lbZ5RDl+qwmAqNdco1ED0R5MkFY2B SYDAw1oDkhGUXak4csJPxcoUHmZ5/iZHKF6cZ+q1B0JSDpdiRH0os0afqHwXG2B9ENpW hxvw== X-Gm-Message-State: AOAM5324IJgLTvEaELDHeWSpym9EpaUeqz6jQyNTGY2CMazrkVw1RS8G HOGk4Fzn8wCX9cUv6y9e6gwK2x6Zvmn5TA== X-Google-Smtp-Source: ABdhPJxm+SFLqRZvahRbgF18ICa+ntY0wasO22GmGBJovT2/OHQLLotMWlyUFtJB+o1/D079jUDmQg== X-Received: by 2002:ae9:c013:: with SMTP id u19mr70772064qkk.59.1609764916244; Mon, 04 Jan 2021 04:55:16 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH 11/20] qemu_driver.c: modernize qemuNodeDeviceReAttach() Date: Mon, 4 Jan 2021 09:54:35 -0300 Message-Id: <20210104125444.200536-12-danielhb413@gmail.com> In-Reply-To: <20210104125444.200536-1-danielhb413@gmail.com> References: <20210104125444.200536-1-danielhb413@gmail.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza 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.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add virObjectUnref an autoptr cleanup func for virNodeDevice, then remove all unref and free calls from qemuNodeDeviceReAttach(). Signed-off-by: Daniel Henrique Barboza --- src/datatypes.h | 2 ++ src/qemu/qemu_driver.c | 32 ++++++++++++-------------------- 2 files changed, 14 insertions(+), 20 deletions(-) diff --git a/src/datatypes.h b/src/datatypes.h index ade3779e43..7a88aba0df 100644 --- a/src/datatypes.h +++ b/src/datatypes.h @@ -707,6 +707,8 @@ struct _virNodeDevice { char *parentName; /* parent device name */ }; =20 +G_DEFINE_AUTOPTR_CLEANUP_FUNC(virNodeDevice, virObjectUnref); + /** * _virSecret: * diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index c450501c4d..7b8350dff3 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -12041,17 +12041,16 @@ static int qemuNodeDeviceReAttach(virNodeDevicePtr dev) { virQEMUDriverPtr driver =3D dev->conn->privateData; - virPCIDevicePtr pci =3D NULL; + g_autoptr(virPCIDevice) pci =3D NULL; virPCIDeviceAddress devAddr; - int ret =3D -1; - virNodeDeviceDefPtr def =3D NULL; + g_autoptr(virNodeDeviceDef) def =3D NULL; g_autofree char *xml =3D NULL; virHostdevManagerPtr hostdev_mgr =3D driver->hostdevMgr; - virConnectPtr nodeconn =3D NULL; - virNodeDevicePtr nodedev =3D NULL; + g_autoptr(virConnect) nodeconn =3D NULL; + g_autoptr(virNodeDevice) nodedev =3D NULL; =20 if (!(nodeconn =3D virGetConnectNodeDev())) - goto cleanup; + return -1; =20 /* 'dev' is associated with the QEMU virConnectPtr, * so for split daemons, we need to get a copy that @@ -12059,36 +12058,29 @@ qemuNodeDeviceReAttach(virNodeDevicePtr dev) */ if (!(nodedev =3D virNodeDeviceLookupByName( nodeconn, virNodeDeviceGetName(dev)))) - goto cleanup; + return -1; =20 xml =3D virNodeDeviceGetXMLDesc(nodedev, 0); if (!xml) - goto cleanup; + return -1; =20 def =3D virNodeDeviceDefParseString(xml, EXISTING_DEVICE, NULL); if (!def) - goto cleanup; + return -1; =20 /* ACL check must happen against original 'dev', * not the new 'nodedev' we acquired */ if (virNodeDeviceReAttachEnsureACL(dev->conn, def) < 0) - goto cleanup; + return -1; =20 if (virDomainDriverNodeDeviceGetPCIInfo(def, &devAddr) < 0) - goto cleanup; + return -1; =20 pci =3D virPCIDeviceNew(&devAddr); if (!pci) - goto cleanup; - - ret =3D virHostdevPCINodeDeviceReAttach(hostdev_mgr, pci); + return -1; =20 - virPCIDeviceFree(pci); - cleanup: - virNodeDeviceDefFree(def); - virObjectUnref(nodedev); - virObjectUnref(nodeconn); - return ret; + return virHostdevPCINodeDeviceReAttach(hostdev_mgr, pci); } =20 static int --=20 2.26.2 From nobody Tue May 14 22:21:41 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 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=1609764941; cv=none; d=zohomail.com; s=zohoarc; b=QL++ncqZpxwo3s9etKMe/0+5Yj8miksqeLM9XFpBVnas09XXfMTxZa+J/jeQuhHYZLLUJwotOESJTaqMU8wdB9W21X79bzm5Fda7PU2JLhOrzfHucDbRiYBzjofXMO9DALkZNB7f7UDnNcbNTQWqnhDmHkbmkUN+znPTMJ2/93k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1609764941; 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=tcfXPkqizLLGhV3KAEqalPOD7Z72UvlIZw4RN40kfG0=; b=aThGIctNmKnkxS1vAOBP77GRySr8uw4Xyi8648uosL58Ile/JzfqHKSTgGqTultSDcP6CGitwoPcvBAz804uURw4fqWO7Hsn03GBetPg69/tIVD/zjkvY/ptDfcW8Iprs/tWD9NAtqIfwwv92KO4L13fElEuPLaXS13TzI6eYhc= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 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-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1609764941018879.2238356209682; Mon, 4 Jan 2021 04:55:41 -0800 (PST) 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-442-36xFQX9jPXOJbNnimcLamQ-1; Mon, 04 Jan 2021 07:55:37 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 22B10879500; Mon, 4 Jan 2021 12:55:31 +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 EED29106D5B0; Mon, 4 Jan 2021 12:55:30 +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 B766550037; Mon, 4 Jan 2021 12:55:30 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 104CtLm2014241 for ; Mon, 4 Jan 2021 07:55:21 -0500 Received: by smtp.corp.redhat.com (Postfix) id 09A062166B2B; Mon, 4 Jan 2021 12:55:21 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast06.extmail.prod.ext.rdu2.redhat.com [10.11.55.22]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 046492166B2A for ; Mon, 4 Jan 2021 12:55:21 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E4755186E120 for ; Mon, 4 Jan 2021 12:55:20 +0000 (UTC) Received: from mail-qk1-f177.google.com (mail-qk1-f177.google.com [209.85.222.177]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-5-K6axvgDINiioqAszPucQPw-1; Mon, 04 Jan 2021 07:55:18 -0500 Received: by mail-qk1-f177.google.com with SMTP id b64so23161860qkc.12 for ; Mon, 04 Jan 2021 04:55:18 -0800 (PST) Received: from rekt.ibmuc.com ([2804:431:c7c6:ca55:7a5d:da5b:906f:bedd]) by smtp.gmail.com with ESMTPSA id m64sm2342866qkb.90.2021.01.04.04.55.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Jan 2021 04:55:17 -0800 (PST) X-MC-Unique: 36xFQX9jPXOJbNnimcLamQ-1 X-MC-Unique: K6axvgDINiioqAszPucQPw-1 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=tcfXPkqizLLGhV3KAEqalPOD7Z72UvlIZw4RN40kfG0=; b=iBxKlwc02WQXp8yBcsoEKnzdI92uMqiEVaugUQL+S2YOzXMZxeqSqBXeedjMVo95JQ ZudE6w6pJsRnHKnfKQQzK7BOKes8O0rTlXUwuybs4K0/zhXhE9sMRhyQYmBaUfrClubT 79+sbOuoVCJwk83V6DrrekCJNlyLWi0LvrXiKEBZTiWnIOa/u3Mf3FduNvAt4+z4bAfy IgeV2f6yUm1YzbTWp2KQOhddw5sTgaICFBbYKmD61QDFJKZUKZz/VcfqplYlVqQDNa/b jJ7UeqiHdn+j/5Ey74G9m8+8o8pydASv6L98Vya/AofiEczKr1xCEmRpsmrZHLAyEu4Z buEQ== X-Gm-Message-State: AOAM532tsLUecfZt4l9CyitjNP+7vlSF8H8dXlR2kWm7ZI0jkupb2AaX XAbMfUbkQO1P1QJEx80mTsTGT13BxlpY8w== X-Google-Smtp-Source: ABdhPJzBremH+ICzVdI8PTS2dIgAyfoxU222m2jNDHWzWr7sSxVuHMNCzJJnihPIouDExW9kXhz2fQ== X-Received: by 2002:a37:a44:: with SMTP id 65mr71465630qkk.478.1609764917827; Mon, 04 Jan 2021 04:55:17 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH 12/20] libxl_driver.c: modernize libxlNodeDeviceReAttach() Date: Mon, 4 Jan 2021 09:54:36 -0300 Message-Id: <20210104125444.200536-13-danielhb413@gmail.com> In-Reply-To: <20210104125444.200536-1-danielhb413@gmail.com> References: <20210104125444.200536-1-danielhb413@gmail.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza 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.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use g_auto* wherever we can and remove the 'cleanup' label. Signed-off-by: Daniel Henrique Barboza --- src/libxl/libxl_driver.c | 37 ++++++++++++++----------------------- 1 file changed, 14 insertions(+), 23 deletions(-) diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index 9b93fd77d2..b83e35f67d 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -5858,18 +5858,17 @@ libxlNodeDeviceDettach(virNodeDevicePtr dev) static int libxlNodeDeviceReAttach(virNodeDevicePtr dev) { - virPCIDevicePtr pci =3D NULL; + g_autoptr(virPCIDevice) pci =3D NULL; virPCIDeviceAddress devAddr; - int ret =3D -1; - virNodeDeviceDefPtr def =3D NULL; - char *xml =3D NULL; + g_autoptr(virNodeDeviceDef) def =3D NULL; + g_autofree char *xml =3D NULL; libxlDriverPrivatePtr driver =3D dev->conn->privateData; virHostdevManagerPtr hostdev_mgr =3D driver->hostdevMgr; - virConnectPtr nodeconn =3D NULL; - virNodeDevicePtr nodedev =3D NULL; + g_autoptr(virConnect) nodeconn =3D NULL; + g_autoptr(virNodeDevice) nodedev =3D NULL; =20 if (!(nodeconn =3D virGetConnectNodeDev())) - goto cleanup; + return -1; =20 /* 'dev' is associated with the QEMU virConnectPtr, * so for split daemons, we need to get a copy that @@ -5877,40 +5876,32 @@ libxlNodeDeviceReAttach(virNodeDevicePtr dev) */ if (!(nodedev =3D virNodeDeviceLookupByName( nodeconn, virNodeDeviceGetName(dev)))) - goto cleanup; + return -1; =20 xml =3D virNodeDeviceGetXMLDesc(nodedev, 0); if (!xml) - goto cleanup; + return -1; =20 def =3D virNodeDeviceDefParseString(xml, EXISTING_DEVICE, NULL); if (!def) - goto cleanup; + return -1; =20 /* ACL check must happen against original 'dev', * not the new 'nodedev' we acquired */ if (virNodeDeviceReAttachEnsureACL(dev->conn, def) < 0) - goto cleanup; + return -1; =20 if (virDomainDriverNodeDeviceGetPCIInfo(def, &devAddr) < 0) - goto cleanup; + return -1; =20 pci =3D virPCIDeviceNew(&devAddr); if (!pci) - goto cleanup; + return -1; =20 if (virHostdevPCINodeDeviceReAttach(hostdev_mgr, pci) < 0) - goto cleanup; - - ret =3D 0; + return -1; =20 - cleanup: - virPCIDeviceFree(pci); - virNodeDeviceDefFree(def); - virObjectUnref(nodedev); - virObjectUnref(nodeconn); - VIR_FREE(xml); - return ret; + return 0; } =20 static int --=20 2.26.2 From nobody Tue May 14 22:21:41 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 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=1609764937; cv=none; d=zohomail.com; s=zohoarc; b=SvMdowYKY2Tefc//OHrhMnMbZXWYoi2H95K0Iex5oXL+vJpfVwhrBZ7lNImsZXJVv5g7JraaPzy16BJGT1PPRXx/5AECo0wu5E181NVL3Y+lLrDxw8yqwLf2zeuxiWkv0ObBULnCCrFpcLYin627L6+n8/yNStE9zjSoKLw03tE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1609764937; 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=QUKfVeV4vfUQe3XNg2GhBwCpSLHlaiNhrse3+AV82io=; b=AsAvDEJreGCv7GtjOcunnNyR5jtgKrqxhgX3q9wptUAnD1kNKX1LpVs+jL5vBcXJdpjvNur8vSKyFzWDnkppIqg2BhWl88EARjUBtEQOsD7TjBbzBsY6PS7Fr1jXb1A3F1srUWT1rdORyOZqSI11BjMXBrhFLUD10qcLN9ZmyQc= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 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-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 160976493759825.627639917640863; Mon, 4 Jan 2021 04:55:37 -0800 (PST) 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-535-o3vzMvwMOAuSaYvCtiO9Cw-1; Mon, 04 Jan 2021 07:55:33 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3B4D51054F8E; Mon, 4 Jan 2021 12:55: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 158F010023AE; Mon, 4 Jan 2021 12:55:25 +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 D238A50033; Mon, 4 Jan 2021 12:55:24 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 104CtMOC014262 for ; Mon, 4 Jan 2021 07:55:22 -0500 Received: by smtp.corp.redhat.com (Postfix) id 3E973111F6; Mon, 4 Jan 2021 12:55:22 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast02.extmail.prod.ext.rdu2.redhat.com [10.11.55.18]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 369C89D498 for ; Mon, 4 Jan 2021 12:55:22 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id BA765800B3B for ; Mon, 4 Jan 2021 12:55:21 +0000 (UTC) Received: from mail-qk1-f177.google.com (mail-qk1-f177.google.com [209.85.222.177]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-574-QBWf3U1zNO-eJ_xGfiakHw-1; Mon, 04 Jan 2021 07:55:19 -0500 Received: by mail-qk1-f177.google.com with SMTP id d14so23149166qkc.13 for ; Mon, 04 Jan 2021 04:55:19 -0800 (PST) Received: from rekt.ibmuc.com ([2804:431:c7c6:ca55:7a5d:da5b:906f:bedd]) by smtp.gmail.com with ESMTPSA id m64sm2342866qkb.90.2021.01.04.04.55.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Jan 2021 04:55:18 -0800 (PST) X-MC-Unique: o3vzMvwMOAuSaYvCtiO9Cw-1 X-MC-Unique: QBWf3U1zNO-eJ_xGfiakHw-1 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=QUKfVeV4vfUQe3XNg2GhBwCpSLHlaiNhrse3+AV82io=; b=Y7eEFkOo+vqFKK9MSOyK1fXE/il4jozowb8V5SHwMSPU2o/S7cFc47kTy0B1gsHLKS 4nnH4S2Ha85gumU7PThthNQSId0GAMnk00kOX4cGN7/tUJRrzB1s7aj5Xr4ZM+I2FSkg FC927veQu7dJ55c1MwcqM86qq8uv2LNh4hwGKtqrFejYHYTbY/DCGdpnfOsH3jHjSm7K ebj0cuBlouZfPuFooZamLs5qeRgL5PJJakIerygGgeuLsCI0UXMjoQKqxA3Wi2qwrHIB XWDRUztdSgiDpGkeB3j2an3FArYTS/rNctfp1v7Ye4KoBOw1XFMCqcSj/u8xxRfU2/4a Qytw== X-Gm-Message-State: AOAM533225eMmPkILHmDbkceFnwT5r2gN0nYJzSizl91vaqb/c2jQEE/ YgHvgsYy/giYYUEPZwJEHOmvMqlhsmF+qQ== X-Google-Smtp-Source: ABdhPJzjBl01ENET/yhP7k9dB9rY+vMAXbOcuIR19jDw8NV0kpn441y3yv3Jo/y75bp0Yeckefg7vA== X-Received: by 2002:a37:9b42:: with SMTP id d63mr71331760qke.449.1609764919181; Mon, 04 Jan 2021 04:55:19 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH 13/20] virsh-domain.c: modernize cmdDetachDevice() Date: Mon, 4 Jan 2021 09:54:37 -0300 Message-Id: <20210104125444.200536-14-danielhb413@gmail.com> In-Reply-To: <20210104125444.200536-1-danielhb413@gmail.com> References: <20210104125444.200536-1-danielhb413@gmail.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza 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.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use g_auto* pointers to avoid the need of a cleanup label. The type of the pointer 'virDomainPtr dom' was changed to its alias 'virshDomainPtr' to allow the use of g_autoptr(). Signed-off-by: Daniel Henrique Barboza --- tools/virsh-domain.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 1ef9b8d606..a8a0f1d3cc 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -11953,11 +11953,10 @@ static const vshCmdOptDef opts_detach_device[] = =3D { static bool cmdDetachDevice(vshControl *ctl, const vshCmd *cmd) { - virDomainPtr dom =3D NULL; + g_autoptr(virshDomain) dom =3D NULL; const char *from =3D NULL; - char *buffer =3D NULL; + g_autofree char *buffer =3D NULL; int ret; - bool funcRet =3D false; bool current =3D vshCommandOptBool(cmd, "current"); bool config =3D vshCommandOptBool(cmd, "config"); bool live =3D vshCommandOptBool(cmd, "live"); @@ -11982,11 +11981,11 @@ cmdDetachDevice(vshControl *ctl, const vshCmd *cm= d) flags |=3D VIR_DOMAIN_AFFECT_LIVE; =20 if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0) - goto cleanup; + return false; =20 if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0) { vshReportError(ctl); - goto cleanup; + return false; } =20 if (flags !=3D 0 || current) @@ -11996,16 +11995,11 @@ cmdDetachDevice(vshControl *ctl, const vshCmd *cm= d) =20 if (ret < 0) { vshError(ctl, _("Failed to detach device from %s"), from); - goto cleanup; + return false; } =20 vshPrintExtra(ctl, "%s", _("Device detached successfully\n")); - funcRet =3D true; - - cleanup: - VIR_FREE(buffer); - virshDomainFree(dom); - return funcRet; + return true; } =20 =20 --=20 2.26.2 From nobody Tue May 14 22:21:41 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 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=1609764946; cv=none; d=zohomail.com; s=zohoarc; b=lByZgI9R0l1BoyRiu1DJ7MyWfv80lAcFxy+v058vthGmCxs8e4luR6zRKgEGg9iUTV4MwDiEKNvfdcDmH5ctX5rszf0iLFRfTirrk8LcZjhZnB0HdwciMlNSHbEGl8TfzavTySPBHtIC5DjaDb6U8IidOYKWwwivc8geLGAifsY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1609764946; 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=TxbvS2AAKI40FZuVgfS5VeN2bqpOPkOB9E5C9jzLg0Y=; b=ZYMPBPKdj+fnjn9nspV4gpq1lOlNeYBdSiSJ5IdlWWvICAtykX6FpFjN0jtWM/XwB2DFhnk9zLKeodvVorfTNjxY4ihkOd/b58JgRgCX1hvK7dribkNKLhHMQJQJfqXw3x9uuJ4h69NipIkZGc/QUu62s26KjOorzulkBK5Pnoo= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 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-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1609764946278216.30562086853172; Mon, 4 Jan 2021 04:55:46 -0800 (PST) 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-149-VbkP0LQ0MGed3K7Oc4Lv8w-1; Mon, 04 Jan 2021 07:55:43 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 05482190A7A5; Mon, 4 Jan 2021 12:55:37 +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 0CB3119CBC; Mon, 4 Jan 2021 12:55:36 +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 CC2331809CB5; Mon, 4 Jan 2021 12:55:35 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 104CtNs0014293 for ; Mon, 4 Jan 2021 07:55:23 -0500 Received: by smtp.corp.redhat.com (Postfix) id 272DF112D405; Mon, 4 Jan 2021 12:55:23 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast01.extmail.prod.ext.rdu2.redhat.com [10.11.55.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 23348112D404 for ; Mon, 4 Jan 2021 12:55:23 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 11232858281 for ; Mon, 4 Jan 2021 12:55:23 +0000 (UTC) Received: from mail-qk1-f173.google.com (mail-qk1-f173.google.com [209.85.222.173]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-400-dV95g83MPOi8jDxYR0_JDw-1; Mon, 04 Jan 2021 07:55:21 -0500 Received: by mail-qk1-f173.google.com with SMTP id p14so23218747qke.6 for ; Mon, 04 Jan 2021 04:55:21 -0800 (PST) Received: from rekt.ibmuc.com ([2804:431:c7c6:ca55:7a5d:da5b:906f:bedd]) by smtp.gmail.com with ESMTPSA id m64sm2342866qkb.90.2021.01.04.04.55.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Jan 2021 04:55:20 -0800 (PST) X-MC-Unique: VbkP0LQ0MGed3K7Oc4Lv8w-1 X-MC-Unique: dV95g83MPOi8jDxYR0_JDw-1 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=TxbvS2AAKI40FZuVgfS5VeN2bqpOPkOB9E5C9jzLg0Y=; b=CWa6zWK4FKQulci4JX+Ree4ldlb69GefUbGm0K8JRU21sF+YB2MMuEfbP43SQyIAG8 qXsnYhDmOREVcecHBJT8j0lNMxmhQoqvT16jG3izLG4ZbZH2KrGUp3/A7Hd/SQW+dDiw 3m0kp1Z0aZEgzmCDEzy/hbsU/CHL0moRmoI0DUz6GMjQSXrHXH4zV+UYDV1+V0lcZoEn X9NbfNW1HMMCtFY81ujOR8IOs1GnFNv352WEymjiURZP9n/kpTugADsKa/P4DJh3Q6aW CSNEtfXed8G6rfyIQJepC5eyFvLyBbYrklOEsPm5BrlcqD3pdGWC1CqeMb+C8dpTefFf Xizg== X-Gm-Message-State: AOAM533bg9UXUmZ6vfSdfOFu8OfYNlUuq9xfNTVkrCzerMOMAyhx2B43 B1i7iY9DPUQYdW5NkfIfWiawQItuc1lwAw== X-Google-Smtp-Source: ABdhPJyJ2xh79FAywTteUw9vViFNOL8XhyZMMwTWwoMj84O7x86SM4zllnQFajQJF8eRwYpfDoDNew== X-Received: by 2002:a37:88c2:: with SMTP id k185mr56618337qkd.474.1609764920486; Mon, 04 Jan 2021 04:55:20 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH 14/20] virhostdev.c: add virHostdevIsPCIDevice() helper Date: Mon, 4 Jan 2021 09:54:38 -0300 Message-Id: <20210104125444.200536-15-danielhb413@gmail.com> In-Reply-To: <20210104125444.200536-1-danielhb413@gmail.com> References: <20210104125444.200536-1-danielhb413@gmail.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza 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.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add a helper to quickly determine if a hostdev is a PCI device, instead of doing a tedius 'if' check with hostdev mode and subsys type. Signed-off-by: Daniel Henrique Barboza --- src/hypervisor/virhostdev.c | 12 +++++++++--- src/hypervisor/virhostdev.h | 2 ++ src/libvirt_private.syms | 1 + 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/hypervisor/virhostdev.c b/src/hypervisor/virhostdev.c index 18373deb41..16a21f240b 100644 --- a/src/hypervisor/virhostdev.c +++ b/src/hypervisor/virhostdev.c @@ -347,12 +347,18 @@ virHostdevNetDevice(virDomainHostdevDefPtr hostdev, } =20 =20 +bool +virHostdevIsPCIDevice(const virDomainHostdevDef *hostdev) +{ + return hostdev->mode =3D=3D VIR_DOMAIN_HOSTDEV_MODE_SUBSYS && + hostdev->source.subsys.type =3D=3D VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_= PCI; +} + + static bool virHostdevIsPCINetDevice(const virDomainHostdevDef *hostdev) { - return hostdev->mode =3D=3D VIR_DOMAIN_HOSTDEV_MODE_SUBSYS && - hostdev->source.subsys.type =3D=3D VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_= PCI && - hostdev->parentnet !=3D NULL; + return virHostdevIsPCIDevice(hostdev) && hostdev->parentnet !=3D NULL; } =20 =20 diff --git a/src/hypervisor/virhostdev.h b/src/hypervisor/virhostdev.h index 811bda40ed..b9407cd837 100644 --- a/src/hypervisor/virhostdev.h +++ b/src/hypervisor/virhostdev.h @@ -235,3 +235,5 @@ virHostdevUpdateActiveNVMeDevices(virHostdevManagerPtr = hostdev_mgr, const char *dom_name, virDomainDiskDefPtr *disks, size_t ndisks); + +bool virHostdevIsPCIDevice(const virDomainHostdevDef *hostdev); diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 81ce142635..ac72a384ed 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1461,6 +1461,7 @@ virCloseCallbacksUnset; =20 # hypervisor/virhostdev.h virHostdevFindUSBDevice; +virHostdevIsPCIDevice; virHostdevManagerGetDefault; virHostdevPCINodeDeviceDetach; virHostdevPCINodeDeviceReAttach; --=20 2.26.2 From nobody Tue May 14 22:21:41 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 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=1609764940; cv=none; d=zohomail.com; s=zohoarc; b=gZjNc9MFNqSPD+9jveTlxeIg6S0Ay8olhcDx9sxvF6tDTPzIf6MbBENm3Nj7c4xGAIREaOjHtiPE3bGjd63VG5Wc1zEZsnF2Vw3Yl8tyRrPNLU1oPQ2oxYZko2Dma4tYk/fo5AIaDkPEcvRyDzE502GNNZGi48MuoweTbKIzq2c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1609764940; 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=RXYvG3wNH96yi/DI9Tz5FIUptb6wzgY9M3GX1dmbGgY=; b=B36sRXKRVPsyPRZU49Bkenu7Ce6LRxtJwUPGwbkLbDD4ZNlG5clZDehXde4OH3K7ApLRlt53pNDZygWBlOt2gAQ7pLw0iaGJTOTooVkqVe41ZGelsCKQcA3yFZjDqwWzEcEBMHwlChHE5pTngW3dl5ZACZDLl3WjzJSGZoGcJbU= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 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-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1609764940212201.46740078539915; Mon, 4 Jan 2021 04:55:40 -0800 (PST) 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-440-BvsUAzxKMGemTffolnQFcg-1; Mon, 04 Jan 2021 07:55:36 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id A8284C73A4; Mon, 4 Jan 2021 12:55:29 +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 84D0F71C80; Mon, 4 Jan 2021 12:55:29 +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 21C9F1809CB3; Mon, 4 Jan 2021 12:55:29 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 104CtS0Y014371 for ; Mon, 4 Jan 2021 07:55:28 -0500 Received: by smtp.corp.redhat.com (Postfix) id DD4D89D498; Mon, 4 Jan 2021 12:55:27 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast01.extmail.prod.ext.rdu2.redhat.com [10.11.55.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D7D7B7AF6 for ; Mon, 4 Jan 2021 12:55:25 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B18EF858EEC for ; Mon, 4 Jan 2021 12:55:25 +0000 (UTC) Received: from mail-qk1-f177.google.com (mail-qk1-f177.google.com [209.85.222.177]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-358-kRHIe-LrO7GZ3hMH9Ub0IQ-1; Mon, 04 Jan 2021 07:55:22 -0500 Received: by mail-qk1-f177.google.com with SMTP id d14so23149277qkc.13 for ; Mon, 04 Jan 2021 04:55:22 -0800 (PST) Received: from rekt.ibmuc.com ([2804:431:c7c6:ca55:7a5d:da5b:906f:bedd]) by smtp.gmail.com with ESMTPSA id m64sm2342866qkb.90.2021.01.04.04.55.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Jan 2021 04:55:21 -0800 (PST) X-MC-Unique: BvsUAzxKMGemTffolnQFcg-1 X-MC-Unique: kRHIe-LrO7GZ3hMH9Ub0IQ-1 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=RXYvG3wNH96yi/DI9Tz5FIUptb6wzgY9M3GX1dmbGgY=; b=UoCePk9D3tLBl+6gX4LnVVv2w/zztS645g7TMg3P3rXMDn1917MyXXOvx5ekG4UuKj NgArCQ5o0zoGrFBYgskHI3c5B1v+quJn50WEqOo2CCBNEK9FRYg7R5E82iyA/jVwDR1R SlYyb/PhTcIjLn0lH47OiA+Qr1bk7n6dVqg8wVGbN24dRCskn9491F3AYVQ3ZCrSs01C S457gzMMyoBv42k5aAvSKIq3FYj+1LmkxrRMNDA/0z71z1CaN4upPwnpqxN0ThxIiqaL aXt+cl/WTQXQ7++juU/JZHZcAKOfeYyRjQVy99D5sc23lxXhd3L24gLPUxHjnI73VDBq H/YQ== X-Gm-Message-State: AOAM5331t0Hxm2QmPn4q3Z36unnPJAhIdlEI/QgE4n4fMypFgW+raf03 CypouMaYgPPLqR4pjMAf8DTCwaQR5x3Pwg== X-Google-Smtp-Source: ABdhPJyZaG+04VEkschSdKKYfsHcItMWso/5aj4bHnevQlYknrk1/pvNZMV+ruPPeUNYceSHhxKZfg== X-Received: by 2002:a37:a40d:: with SMTP id n13mr70634976qke.47.1609764922161; Mon, 04 Jan 2021 04:55:22 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH 15/20] qemu_cgroup.c: skip absent PCI devices in qemuTeardownHostdevCgroup() Date: Mon, 4 Jan 2021 09:54:39 -0300 Message-Id: <20210104125444.200536-16-danielhb413@gmail.com> In-Reply-To: <20210104125444.200536-1-danielhb413@gmail.com> References: <20210104125444.200536-1-danielhb413@gmail.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza 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.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" There is no need to bother with cgroup tearing down for absent PCI devices, given that their entries in the sysfs are already gone. Signed-off-by: Daniel Henrique Barboza --- src/qemu/qemu_cgroup.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c index f7146a71c9..050df21d87 100644 --- a/src/qemu/qemu_cgroup.c +++ b/src/qemu/qemu_cgroup.c @@ -467,6 +467,16 @@ qemuTeardownHostdevCgroup(virDomainObjPtr vm, if (!virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_DEVICE= S)) return 0; =20 + /* Skip tearing down Cgroup for hostdevs that represents absent + * PCI devices, e.g. SR-IOV virtual functions that were removed from + * the host while the domain was still running. */ + if (virHostdevIsPCIDevice(dev)) { + const virDomainHostdevSubsysPCI *pcisrc =3D &dev->source.subsys.u.= pci; + + if (!virPCIDeviceExists(&pcisrc->addr)) + return 0; + } + if (qemuDomainGetHostdevPath(dev, &path, NULL) < 0) return -1; =20 --=20 2.26.2 From nobody Tue May 14 22:21:41 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 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=1609764944; cv=none; d=zohomail.com; s=zohoarc; b=iTYKzcMrqcMqln33FBCDm4UnqrEYBwkgCmIVxoMu8ZDMf3Bkh5oLae0yiuD8RT5aYwaLUGjUfJJYoUJ40ElnHQf6P9aI/KuP4A1aUJtmZFDWNY55RwFAX4iIuG0Mtwd4oxYlC1xKKfjcvgCkTl75B3JuesT8BObEjMQedsxkNVw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1609764944; 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=cnwV2MyDhVntT4+1lWYmzLYkOrj5jaHTbeB35GuRHTk=; b=Xvs4sVP+0boYk5GoWLmmZBkg0cC2niWiJVu2J7wGWEt3j0Y9CzlfFUlmBo+MnpuOvcG59jJuQHBJa66XhCCJkoUc1GaOCrdGHvnfgNynDyyUbphgjYn+tSTnP9izppKzWxDCYO1CF2c/WFeqP51bKEeunLm5toLSoK1wd+VBges= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 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-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1609764944397453.0977840018252; Mon, 4 Jan 2021 04:55:44 -0800 (PST) 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-391-km8R7y8_P2OkfD40zH5NBA-1; Mon, 04 Jan 2021 07:55:41 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 021F087952E; Mon, 4 Jan 2021 12:55:35 +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 CF190106D5B6; Mon, 4 Jan 2021 12:55:34 +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 9A14A50040; Mon, 4 Jan 2021 12:55:34 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 104CtSNd014425 for ; Mon, 4 Jan 2021 07:55:29 -0500 Received: by smtp.corp.redhat.com (Postfix) id DD2412026DE8; Mon, 4 Jan 2021 12:55:28 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast06.extmail.prod.ext.rdu2.redhat.com [10.11.55.22]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D4A6A2026D11 for ; Mon, 4 Jan 2021 12:55:26 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 49CC2186E125 for ; Mon, 4 Jan 2021 12:55:26 +0000 (UTC) Received: from mail-qk1-f178.google.com (mail-qk1-f178.google.com [209.85.222.178]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-257-aET2ytYdPMum8AACNlSs1A-1; Mon, 04 Jan 2021 07:55:24 -0500 Received: by mail-qk1-f178.google.com with SMTP id v126so23149419qkd.11 for ; Mon, 04 Jan 2021 04:55:24 -0800 (PST) Received: from rekt.ibmuc.com ([2804:431:c7c6:ca55:7a5d:da5b:906f:bedd]) by smtp.gmail.com with ESMTPSA id m64sm2342866qkb.90.2021.01.04.04.55.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Jan 2021 04:55:23 -0800 (PST) X-MC-Unique: km8R7y8_P2OkfD40zH5NBA-1 X-MC-Unique: aET2ytYdPMum8AACNlSs1A-1 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=cnwV2MyDhVntT4+1lWYmzLYkOrj5jaHTbeB35GuRHTk=; b=NYIZdJhN4zqfF76l1SJOXSCaRtgh8W0Q0BEVfYTBPmOGrOKq+Dmiv9Y3hvRg1tjdM/ 4LrS/yG9L7jFBlMVO/bw2spYWCdzvTUSFsv6vmbjrjWW/vZEC2Y824NPLsYB8TdpEUaV L38uPtfwTiNNM8Tip3JwVgDeqGX0Vyo+cytB8CKg5HVYa47e43VOC9SG14lmQIhSx8NP g1gSpKUOrM55ZJUI2kmNnu/F/Zj471V3GRuaj01D5gvHiluo87yG/NtROel+KVRxdZSH lSjmMZjGzx1/isKd6/I5NSQ3WhC+Q2cGvQORm9OIPiOB5cChto6PFCAKSh3/oEeMS0A+ lC4w== X-Gm-Message-State: AOAM5334180yxiVplhhJOwNAAzlFCxhHlCJemp0uxA/jcWrt/uRaGzOg P2c+kAA2ypNvcWoQjr1LegHmnRiSdr1Gwg== X-Google-Smtp-Source: ABdhPJyCFY6JSyb7z8kQkqzH8BoGp2SpPUiBwnkv7R2kQ0L70RH3z38LAlI8MvHLna+XVcLsOJg9hA== X-Received: by 2002:a37:a516:: with SMTP id o22mr72320478qke.17.1609764923761; Mon, 04 Jan 2021 04:55:23 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH 16/20] virpci.c: use virPCIDeviceAddressPtr in virPCIDeviceListFindIndex() Date: Mon, 4 Jan 2021 09:54:40 -0300 Message-Id: <20210104125444.200536-17-danielhb413@gmail.com> In-Reply-To: <20210104125444.200536-1-danielhb413@gmail.com> References: <20210104125444.200536-1-danielhb413@gmail.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza 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.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" We're going to need a way to remove a PCI Device from a list without having a valid virPCIDevicePtr, because the device is missing from the host. This means that virPCIDevicesListDel() must operate with a PCI Device address instead. Turns out that virPCIDevicesListDel() and its related functions only use the virPCIDeviceAddressPtr of the virPCIDevicePtr, so this change is simple to do and will not cause hassle in all other callers. Let's start adapting virPCIDeviceListFindIndex() and crawl our way up to virPCIDevicesListDel(). Signed-off-by: Daniel Henrique Barboza --- src/util/virpci.c | 15 ++++++++------- src/util/virpci.h | 2 +- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/util/virpci.c b/src/util/virpci.c index 1a542b18b6..122056dbe0 100644 --- a/src/util/virpci.c +++ b/src/util/virpci.c @@ -1745,7 +1745,7 @@ virPCIDevicePtr virPCIDeviceListSteal(virPCIDeviceListPtr list, virPCIDevicePtr dev) { - return virPCIDeviceListStealIndex(list, virPCIDeviceListFindIndex(list= , dev)); + return virPCIDeviceListStealIndex(list, virPCIDeviceListFindIndex(list= , &dev->address)); } =20 void @@ -1756,16 +1756,17 @@ virPCIDeviceListDel(virPCIDeviceListPtr list, } =20 int -virPCIDeviceListFindIndex(virPCIDeviceListPtr list, virPCIDevicePtr dev) +virPCIDeviceListFindIndex(virPCIDeviceListPtr list, + virPCIDeviceAddressPtr devAddr) { size_t i; =20 for (i =3D 0; i < list->count; i++) { virPCIDevicePtr other =3D list->devs[i]; - if (other->address.domain =3D=3D dev->address.domain && - other->address.bus =3D=3D dev->address.bus && - other->address.slot =3D=3D dev->address.slot && - other->address.function =3D=3D dev->address.function) + if (other->address.domain =3D=3D devAddr->domain && + other->address.bus =3D=3D devAddr->bus && + other->address.slot =3D=3D devAddr->slot && + other->address.function =3D=3D devAddr->function) return i; } return -1; @@ -1798,7 +1799,7 @@ virPCIDeviceListFind(virPCIDeviceListPtr list, virPCI= DevicePtr dev) { int idx; =20 - if ((idx =3D virPCIDeviceListFindIndex(list, dev)) >=3D 0) + if ((idx =3D virPCIDeviceListFindIndex(list, &dev->address)) >=3D 0) return list->devs[idx]; else return NULL; diff --git a/src/util/virpci.h b/src/util/virpci.h index a9c597a428..8c6776da21 100644 --- a/src/util/virpci.h +++ b/src/util/virpci.h @@ -175,7 +175,7 @@ virPCIDeviceListFindByIDs(virPCIDeviceListPtr list, unsigned int slot, unsigned int function); int virPCIDeviceListFindIndex(virPCIDeviceListPtr list, - virPCIDevicePtr dev); + virPCIDeviceAddressPtr devAddr); =20 /* * Callback that will be invoked once for each file --=20 2.26.2 From nobody Tue May 14 22:21:41 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 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=1609764942; cv=none; d=zohomail.com; s=zohoarc; b=ewNHzzR6lrSeF9+Vxy0UWeJOWxblselztxTKQw3Nv0oXs3PX1sLS8lfsvDCe8/YMCt7Rem+uabuCr1JU7mW8w1ZSfZS0tLOBPzWvtfpixQLqBlMymh4tzcRGOe9gnRa0FptKbX/2wq5k28hYTqqfMfBsIQGvQ6Ioq29Nbhx4jLQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1609764942; 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=VcWPFlrVLBqbmpSXomFczTa5GDC5tYyyQx67dGBgU7s=; b=KVhMc0McUNmhpg0or7w5Ap4y6rd15FTTmAFXm8Pkr2eJ62dYbZLGaxBHKHwQQN5Exq3mrrLQ2c8IzNUYZcycIdLQuyPxCkbUQfD+KfDQADwGvylx9ZwxXOIvhy+3eY0d/EsV4MgK6+qRW+67p3UCxCu5yw7FS/C1kdLvGh+BPnU= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 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-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1609764942879920.2062477811116; Mon, 4 Jan 2021 04:55:42 -0800 (PST) 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-387-bpWP8i8lPJK5mGuxZJv3Iw-1; Mon, 04 Jan 2021 07:55:39 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6AD43190A7A0; Mon, 4 Jan 2021 12:55:32 +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 455A85D764; Mon, 4 Jan 2021 12:55:32 +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 1038E5002D; Mon, 4 Jan 2021 12:55:32 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 104CtSaL014378 for ; Mon, 4 Jan 2021 07:55:28 -0500 Received: by smtp.corp.redhat.com (Postfix) id 3B4201000DB4; Mon, 4 Jan 2021 12:55:28 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast04.extmail.prod.ext.rdu2.redhat.com [10.11.55.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3454F112D404 for ; Mon, 4 Jan 2021 12:55:28 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 201A7101A561 for ; Mon, 4 Jan 2021 12:55:28 +0000 (UTC) Received: from mail-qk1-f176.google.com (mail-qk1-f176.google.com [209.85.222.176]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-537-QYyfauzBP5uGKDIZri0G-w-1; Mon, 04 Jan 2021 07:55:25 -0500 Received: by mail-qk1-f176.google.com with SMTP id 19so23179811qkm.8 for ; Mon, 04 Jan 2021 04:55:25 -0800 (PST) Received: from rekt.ibmuc.com ([2804:431:c7c6:ca55:7a5d:da5b:906f:bedd]) by smtp.gmail.com with ESMTPSA id m64sm2342866qkb.90.2021.01.04.04.55.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Jan 2021 04:55:24 -0800 (PST) X-MC-Unique: bpWP8i8lPJK5mGuxZJv3Iw-1 X-MC-Unique: QYyfauzBP5uGKDIZri0G-w-1 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=VcWPFlrVLBqbmpSXomFczTa5GDC5tYyyQx67dGBgU7s=; b=HS0kSBgc1YNw4cXiFQJixfT5ZyfuYa2IDIgBTtiHXpg8Y20hzsso3cJwRKdHZCRBUL VKRnkMHrO28+XVHH7tc8rU1FyOXBvUXeNBmqormuPK5P8g0TqPv6mI4nE2OVAZDBtS48 X84LAzJNg6yacnJ/5ehQUo/z6adALPj4O8YgeWiR89Og3FJ9cwP8fjUV0ht2ZCzD2MSs k0J/1VreXtkE/SFr4aNK4ZTXMiPhqKH1O/ogoBFezQoAbfV3iCILC/7UCwWvDGIJSYUW Y1Qy6+HgZtSa73VrvdTiMV790qBOugblE/IecGetnbs77TvxBLPWfKsdO2Or7JOA5S4g 7Tbw== X-Gm-Message-State: AOAM5312EcpO4jzFkCHoOGsOCV5h2Mh0VSEesj2UgEjhgiboSc6qAKqr r30gijr03z6QIWTN9FT/j9aQ9+lKr7DgCA== X-Google-Smtp-Source: ABdhPJyXEOSaufb8DFPZ3fBNejBz4dm1gmxSrEfb0+U4DPYAhrvXPSL53ttfhS1jcQo74O69m8VGCQ== X-Received: by 2002:a37:6c06:: with SMTP id h6mr61296142qkc.115.1609764925105; Mon, 04 Jan 2021 04:55:25 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH 17/20] virpci.c: use virPCIDeviceAddressPtr in virPCIDeviceListFind() Date: Mon, 4 Jan 2021 09:54:41 -0300 Message-Id: <20210104125444.200536-18-danielhb413@gmail.com> In-Reply-To: <20210104125444.200536-1-danielhb413@gmail.com> References: <20210104125444.200536-1-danielhb413@gmail.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza 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.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Signed-off-by: Daniel Henrique Barboza --- src/hypervisor/virhostdev.c | 12 ++++++++---- src/util/virpci.c | 16 ++++++++-------- src/util/virpci.h | 2 +- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/hypervisor/virhostdev.c b/src/hypervisor/virhostdev.c index 16a21f240b..e7ef615f60 100644 --- a/src/hypervisor/virhostdev.c +++ b/src/hypervisor/virhostdev.c @@ -657,7 +657,8 @@ virHostdevReattachAllPCIDevices(virHostdevManagerPtr mg= r, =20 /* 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))) + if (!(actual =3D virPCIDeviceListFind(mgr->inactivePCIHostdevs, + virPCIDeviceGetAddress(pci)))) continue; =20 if (virPCIDeviceGetManaged(actual)) { @@ -777,7 +778,8 @@ virHostdevPreparePCIDevicesImpl(virHostdevManagerPtr mg= r, =20 /* Unmanaged devices should already have been marked as * inactive: if that's the case, we can simply move on */ - if (virPCIDeviceListFind(mgr->inactivePCIHostdevs, pci)) { + if (virPCIDeviceListFind(mgr->inactivePCIHostdevs, + virPCIDeviceGetAddress(pci))) { VIR_DEBUG("Not detaching unmanaged PCI device %s", virPCIDeviceGetName(pci)); continue; @@ -860,7 +862,8 @@ virHostdevPreparePCIDevicesImpl(virHostdevManagerPtr mg= r, * there because 'pci' only contain address information and will * be released at the end of the function */ pci =3D virPCIDeviceListGet(pcidevs, i); - actual =3D virPCIDeviceListFind(mgr->activePCIHostdevs, pci); + actual =3D virPCIDeviceListFind(mgr->activePCIHostdevs, + virPCIDeviceGetAddress(pci)); =20 VIR_DEBUG("Setting driver and domain information for PCI device %s= ", virPCIDeviceGetName(pci)); @@ -992,7 +995,8 @@ virHostdevReAttachPCIDevicesImpl(virHostdevManagerPtr m= gr, * information such as by which domain and driver it is used. As a * side effect, by looking it up we can also tell whether it was * really active in the first place */ - actual =3D virPCIDeviceListFind(mgr->activePCIHostdevs, pci); + actual =3D virPCIDeviceListFind(mgr->activePCIHostdevs, + virPCIDeviceGetAddress(pci)); if (actual) { const char *actual_drvname; const char *actual_domname; diff --git a/src/util/virpci.c b/src/util/virpci.c index 122056dbe0..938ffeaaed 100644 --- a/src/util/virpci.c +++ b/src/util/virpci.c @@ -705,7 +705,7 @@ virPCIDeviceSharesBusWithActive(virPCIDevicePtr dev, vi= rPCIDevicePtr check, void return 0; =20 /* same bus, but inactive, i.e. about to be assigned to guest */ - if (inactiveDevs && virPCIDeviceListFind(inactiveDevs, check)) + if (inactiveDevs && virPCIDeviceListFind(inactiveDevs, &check->address= )) return 0; =20 return 1; @@ -1022,7 +1022,7 @@ virPCIDeviceReset(virPCIDevicePtr dev, return -1; } =20 - if (activeDevs && virPCIDeviceListFind(activeDevs, dev)) { + if (activeDevs && virPCIDeviceListFind(activeDevs, &dev->address)) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Not resetting active device %s"), dev->name); return -1; @@ -1294,7 +1294,7 @@ virPCIDeviceDetach(virPCIDevicePtr dev, if (virPCIProbeStubDriver(dev->stubDriver) < 0) return -1; =20 - if (activeDevs && virPCIDeviceListFind(activeDevs, dev)) { + if (activeDevs && virPCIDeviceListFind(activeDevs, &dev->address)) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Not detaching active device %s"), dev->name); return -1; @@ -1306,7 +1306,7 @@ virPCIDeviceDetach(virPCIDevicePtr dev, /* Add *a copy of* the dev into list inactiveDevs, if * it's not already there. */ - if (inactiveDevs && !virPCIDeviceListFind(inactiveDevs, dev)) { + if (inactiveDevs && !virPCIDeviceListFind(inactiveDevs, &dev->address)= ) { VIR_DEBUG("Adding PCI device %s to inactive list", dev->name); if (virPCIDeviceListAddCopy(inactiveDevs, dev) < 0) return -1; @@ -1324,7 +1324,7 @@ virPCIDeviceReattach(virPCIDevicePtr dev, virPCIDeviceListPtr activeDevs, virPCIDeviceListPtr inactiveDevs) { - if (activeDevs && virPCIDeviceListFind(activeDevs, dev)) { + if (activeDevs && virPCIDeviceListFind(activeDevs, &dev->address)) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Not reattaching active device %s"), dev->name); return -1; @@ -1684,7 +1684,7 @@ int virPCIDeviceListAdd(virPCIDeviceListPtr list, virPCIDevicePtr dev) { - if (virPCIDeviceListFind(list, dev)) { + if (virPCIDeviceListFind(list, &dev->address)) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Device %s is already in use"), dev->name); return -1; @@ -1795,11 +1795,11 @@ virPCIDeviceListFindByIDs(virPCIDeviceListPtr list, =20 =20 virPCIDevicePtr -virPCIDeviceListFind(virPCIDeviceListPtr list, virPCIDevicePtr dev) +virPCIDeviceListFind(virPCIDeviceListPtr list, virPCIDeviceAddressPtr devA= ddr) { int idx; =20 - if ((idx =3D virPCIDeviceListFindIndex(list, &dev->address)) >=3D 0) + if ((idx =3D virPCIDeviceListFindIndex(list, devAddr)) >=3D 0) return list->devs[idx]; else return NULL; diff --git a/src/util/virpci.h b/src/util/virpci.h index 8c6776da21..628a293972 100644 --- a/src/util/virpci.h +++ b/src/util/virpci.h @@ -167,7 +167,7 @@ virPCIDevicePtr virPCIDeviceListStealIndex(virPCIDevice= ListPtr list, void virPCIDeviceListDel(virPCIDeviceListPtr list, virPCIDevicePtr dev); virPCIDevicePtr virPCIDeviceListFind(virPCIDeviceListPtr list, - virPCIDevicePtr dev); + virPCIDeviceAddressPtr devAddr); virPCIDevicePtr virPCIDeviceListFindByIDs(virPCIDeviceListPtr list, unsigned int domain, --=20 2.26.2 From nobody Tue May 14 22:21:41 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 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=1609764967; cv=none; d=zohomail.com; s=zohoarc; b=FcD08BzPrO2IPofQDjuY/10PBxangfNPHmlutfk0h8vQmrkqSg29r67SadVAcPdGbBYc8r3grJK36hZy5NeL8kojxBB65Lz09I+hUhhhvYc+OxRJcECG3CzWw8xv0WRKunCz8268SPViWePT/rSdCm3ZVHoeopDdi0Nji0M5TDM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1609764967; 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=zxmtwsnO6piRvAquCHlG98YNKaTBCfJbsPZYG53Ga7A=; b=e+Eq2X1Mz4MpwbRKHhJMh0/gpnc+7zcm3ud+UPq/Rs6F8VliPg/vkkfAuGTfH6/Of7PNY1W2WIIiYTo2e16wA8xE0A6d3d722IYGFYvSJiT2k/2KgJSAgBwLiV1bECRL3BsS6v5wNI6QUgFD4meC9FwTPxHnXZWuXFiHfjt92yc= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 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-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 160976496789231.04986368231141; Mon, 4 Jan 2021 04:56:07 -0800 (PST) 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-459-gFXnk5sgPIabspFL337cVg-1; Mon, 04 Jan 2021 07:55:44 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id AAFDA84A5E9; Mon, 4 Jan 2021 12:55:37 +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 89C8D5C1A3; Mon, 4 Jan 2021 12:55:37 +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 566241809CB8; Mon, 4 Jan 2021 12:55:37 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 104CtTY1014443 for ; Mon, 4 Jan 2021 07:55:29 -0500 Received: by smtp.corp.redhat.com (Postfix) id 49A2E112D407; Mon, 4 Jan 2021 12:55:29 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast04.extmail.prod.ext.rdu2.redhat.com [10.11.55.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 43A65112D405 for ; Mon, 4 Jan 2021 12:55:29 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 314F5101A569 for ; Mon, 4 Jan 2021 12:55:29 +0000 (UTC) Received: from mail-qk1-f176.google.com (mail-qk1-f176.google.com [209.85.222.176]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-576-qVadSHN5OCSnXaFZ6TIYWg-1; Mon, 04 Jan 2021 07:55:27 -0500 Received: by mail-qk1-f176.google.com with SMTP id v126so23149519qkd.11 for ; Mon, 04 Jan 2021 04:55:27 -0800 (PST) Received: from rekt.ibmuc.com ([2804:431:c7c6:ca55:7a5d:da5b:906f:bedd]) by smtp.gmail.com with ESMTPSA id m64sm2342866qkb.90.2021.01.04.04.55.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Jan 2021 04:55:26 -0800 (PST) X-MC-Unique: gFXnk5sgPIabspFL337cVg-1 X-MC-Unique: qVadSHN5OCSnXaFZ6TIYWg-1 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=zxmtwsnO6piRvAquCHlG98YNKaTBCfJbsPZYG53Ga7A=; b=snJFT3T5kfNMPf9w6tRkDFLvVVl+5/X3qznk9v9nH+y7xw+pMM6i23jUqLDNZ9v0D+ K75ruJSgM/zWZys5wTV/7pCQP2tymR+PQrC5OmZ2TjPg1xGhQqKtxz5FZSyHAbLwUfot mTUYBkhNnCuXLOHNEqjPyYmJfxKHdbVd1bmVNtMdAqau8rUSUjiq+p/xfbHIZ0rhe9Is rHVQ0d1yMLsuTYM/K0GarXyoY88a8kEMAkXNKfSjomrC6twjhmPgPezH5cz0dzHXgigB +BFHO4587hgUEGuAPGswDw4UO1Yuz5QQy9gRXL6Qig11ehcSGSCduhi/vITk3zCzsUts ifVA== X-Gm-Message-State: AOAM530ADiEZWWPtPeZatDUJZvqV2Arqufkvehj360n9PXLFTDPEAOt0 WDNHGVdvwBjBRSBXc42IhyDwDrS/Czoc8Q== X-Google-Smtp-Source: ABdhPJzZTu3V3q0k4pm6esXxztSiy7UrAJm0hnR/FZzSTVi4sT/sBjU3sc5ZowESY/ZvrTA3gpHf8Q== X-Received: by 2002:a05:620a:1526:: with SMTP id n6mr72529167qkk.334.1609764926458; Mon, 04 Jan 2021 04:55:26 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH 18/20] virpci.c: use virPCIDeviceAddressPtr in virPCIDeviceListSteal() Date: Mon, 4 Jan 2021 09:54:42 -0300 Message-Id: <20210104125444.200536-19-danielhb413@gmail.com> In-Reply-To: <20210104125444.200536-1-danielhb413@gmail.com> References: <20210104125444.200536-1-danielhb413@gmail.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza 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.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Signed-off-by: Daniel Henrique Barboza --- src/hypervisor/virhostdev.c | 8 +++++--- src/util/virpci.c | 6 +++--- src/util/virpci.h | 2 +- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/hypervisor/virhostdev.c b/src/hypervisor/virhostdev.c index e7ef615f60..4539c55e09 100644 --- a/src/hypervisor/virhostdev.c +++ b/src/hypervisor/virhostdev.c @@ -846,7 +846,7 @@ virHostdevPreparePCIDevicesImpl(virHostdevManagerPtr mg= r, =20 VIR_DEBUG("Removing PCI device %s from inactive list", virPCIDeviceGetName(pci)); - actual =3D virPCIDeviceListSteal(mgr->inactivePCIHostdevs, pci); + actual =3D virPCIDeviceListSteal(mgr->inactivePCIHostdevs, virPCID= eviceGetAddress(pci)); =20 VIR_DEBUG("Adding PCI device %s to active list", virPCIDeviceGetName(pci)); @@ -918,7 +918,8 @@ virHostdevPreparePCIDevicesImpl(virHostdevManagerPtr mg= r, =20 VIR_DEBUG("Removing PCI device %s from active list", virPCIDeviceGetName(pci)); - if (!(actual =3D virPCIDeviceListSteal(mgr->activePCIHostdevs, pci= ))) + if (!(actual =3D virPCIDeviceListSteal(mgr->activePCIHostdevs, + virPCIDeviceGetAddress(pci)))) continue; =20 VIR_DEBUG("Adding PCI device %s to inactive list", @@ -1022,7 +1023,8 @@ virHostdevReAttachPCIDevicesImpl(virHostdevManagerPtr= mgr, =20 VIR_DEBUG("Removing PCI device %s from active list", virPCIDeviceGetName(pci)); - actual =3D virPCIDeviceListSteal(mgr->activePCIHostdevs, pci); + actual =3D virPCIDeviceListSteal(mgr->activePCIHostdevs, + virPCIDeviceGetAddress(pci)); =20 VIR_DEBUG("Adding PCI device %s to inactive list", virPCIDeviceGetName(pci)); diff --git a/src/util/virpci.c b/src/util/virpci.c index 938ffeaaed..8973c7c754 100644 --- a/src/util/virpci.c +++ b/src/util/virpci.c @@ -1743,16 +1743,16 @@ virPCIDeviceListStealIndex(virPCIDeviceListPtr list, =20 virPCIDevicePtr virPCIDeviceListSteal(virPCIDeviceListPtr list, - virPCIDevicePtr dev) + virPCIDeviceAddressPtr devAddr) { - return virPCIDeviceListStealIndex(list, virPCIDeviceListFindIndex(list= , &dev->address)); + return virPCIDeviceListStealIndex(list, virPCIDeviceListFindIndex(list= , devAddr)); } =20 void virPCIDeviceListDel(virPCIDeviceListPtr list, virPCIDevicePtr dev) { - virPCIDeviceFree(virPCIDeviceListSteal(list, dev)); + virPCIDeviceFree(virPCIDeviceListSteal(list, &dev->address)); } =20 int diff --git a/src/util/virpci.h b/src/util/virpci.h index 628a293972..e3458a75fa 100644 --- a/src/util/virpci.h +++ b/src/util/virpci.h @@ -161,7 +161,7 @@ virPCIDevicePtr virPCIDeviceListGet(virPCIDeviceListPtr= list, int idx); size_t virPCIDeviceListCount(virPCIDeviceListPtr list); virPCIDevicePtr virPCIDeviceListSteal(virPCIDeviceListPtr list, - virPCIDevicePtr dev); + virPCIDeviceAddressPtr devAddr); virPCIDevicePtr virPCIDeviceListStealIndex(virPCIDeviceListPtr list, int idx); void virPCIDeviceListDel(virPCIDeviceListPtr list, --=20 2.26.2 From nobody Tue May 14 22:21:41 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 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=1609764949; cv=none; d=zohomail.com; s=zohoarc; b=MqbK/xrICb97jhJi6h4+o5e0BRYPvwxAypIU4FbYNGiobKUXLXT/Rpwd+wj7kGjufYwNzAagsh3a1GBjiSMlOTwHGuX3ONdpSOUH+kseeWIknaYrkKWf0MY9L9CIcf+/wfExHyqKWIppu06C/47s0PXSkLwlbVVgctdn7oPo4Tc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1609764949; 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=EjbEfAed2K+HMHV/XZcX9bWas/cLjN98h+t+5Z6wnAU=; b=KCOAtQZYXOe80fXiVZnxkFRO/ErJf3U8+nPuivJ5TBdoRYl7g+kb/AeUy/m+OL0mm6lWIp2zegbqpK3Renc8QVT+XrZefPFMLuk9b+M5d7uMOyNcUZhkZi9ez6UFYADbzSo7hN+Sq84bQEpYEvAWrMt33UaIFuJqDd84FrOWIjc= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 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-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1609764949557526.5791480362769; Mon, 4 Jan 2021 04:55:49 -0800 (PST) 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-410-jElOaFt9PLS50aG3gi3ESw-1; Mon, 04 Jan 2021 07:55:46 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id EF5BAC73AA; Mon, 4 Jan 2021 12:55:40 +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 C36C46E50A; Mon, 4 Jan 2021 12:55:40 +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 89BF550045; Mon, 4 Jan 2021 12:55:40 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 104CtUqw014453 for ; Mon, 4 Jan 2021 07:55:30 -0500 Received: by smtp.corp.redhat.com (Postfix) id C06AF112D405; Mon, 4 Jan 2021 12:55:30 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast06.extmail.prod.ext.rdu2.redhat.com [10.11.55.22]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BBF23112D404 for ; Mon, 4 Jan 2021 12:55:30 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A9F84185A794 for ; Mon, 4 Jan 2021 12:55:30 +0000 (UTC) Received: from mail-qk1-f180.google.com (mail-qk1-f180.google.com [209.85.222.180]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-299-JUKK9G_mPiORq6W32nus8A-1; Mon, 04 Jan 2021 07:55:28 -0500 Received: by mail-qk1-f180.google.com with SMTP id d14so23149497qkc.13 for ; Mon, 04 Jan 2021 04:55:28 -0800 (PST) Received: from rekt.ibmuc.com ([2804:431:c7c6:ca55:7a5d:da5b:906f:bedd]) by smtp.gmail.com with ESMTPSA id m64sm2342866qkb.90.2021.01.04.04.55.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Jan 2021 04:55:27 -0800 (PST) X-MC-Unique: jElOaFt9PLS50aG3gi3ESw-1 X-MC-Unique: JUKK9G_mPiORq6W32nus8A-1 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=EjbEfAed2K+HMHV/XZcX9bWas/cLjN98h+t+5Z6wnAU=; b=MdNngcy0VkMLMDEdUOO3gB/TpHsNbUDo9CQKIeIEDmWH7mO9fVTkRs0AsgWdgvk88n h6InQdjrtZ/9XYg4g2nRa2yAUXVKZA2xLLbTg/nfGiccUXcVEqk7vrtoWqph1miEfQAg ddYz9evsT54Fp7wUxjKvn6AUmgL+VJiL7kGsg3T1ZQlUHobGSGDwTMCSlWrmJOnWs6Pw Pd49UwSnCDHCuX1JRXvUMJ30dxqDVot/OGh0C5JU1YLhYEfiBVwjVz+T+X6Ky24hcaU2 f51uuy6cZQfjZtRG9vIbynDi6cDTAqRmWdYVR7p0bVaYkskBfLCypMo+058ACqe1cwnU ew3Q== X-Gm-Message-State: AOAM532mNuimn2gfXz08G4wtiPm4vXqER8lUvbve5LTJx5o+VAPJ0kzw eWJkVja+1qUmD1jYsGQnFIvJ4GBam/0wyw== X-Google-Smtp-Source: ABdhPJyqZBZenCFDr/F5NYmubXjPxnADZn9aEzIIqXoLIztPH4Pw+2ZkA3kfgFv4ZCGegiftJtQv5g== X-Received: by 2002:ae9:c013:: with SMTP id u19mr70772695qkk.59.1609764928133; Mon, 04 Jan 2021 04:55:28 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH 19/20] virpci.c: use virPCIDeviceAddressPtr in virPCIDeviceListDel() Date: Mon, 4 Jan 2021 09:54:43 -0300 Message-Id: <20210104125444.200536-20-danielhb413@gmail.com> In-Reply-To: <20210104125444.200536-1-danielhb413@gmail.com> References: <20210104125444.200536-1-danielhb413@gmail.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza 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.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This change will allow us to remove PCI devices from a list without the need of a PCI Device object, which will be need in the next patch. Signed-off-by: Daniel Henrique Barboza --- src/hypervisor/virhostdev.c | 7 ++++--- src/util/virpci.c | 6 +++--- src/util/virpci.h | 2 +- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/hypervisor/virhostdev.c b/src/hypervisor/virhostdev.c index 4539c55e09..0510eb020c 100644 --- a/src/hypervisor/virhostdev.c +++ b/src/hypervisor/virhostdev.c @@ -1005,11 +1005,11 @@ virHostdevReAttachPCIDevicesImpl(virHostdevManagerP= tr mgr, if (STRNEQ_NULLABLE(drv_name, actual_drvname) || STRNEQ_NULLABLE(dom_name, actual_domname)) { =20 - virPCIDeviceListDel(pcidevs, pci); + virPCIDeviceListDel(pcidevs, virPCIDeviceGetAddress(pci)); continue; } } else { - virPCIDeviceListDel(pcidevs, pci); + virPCIDeviceListDel(pcidevs, virPCIDeviceGetAddress(pci)); continue; } =20 @@ -2524,7 +2524,8 @@ virHostdevUpdateActiveNVMeDevices(virHostdevManagerPt= r hostdev_mgr, while (lastGoodPCIIdx >=3D 0) { virPCIDevicePtr actual =3D virPCIDeviceListGet(pciDevices, i); =20 - virPCIDeviceListDel(hostdev_mgr->activePCIHostdevs, actual); + virPCIDeviceListDel(hostdev_mgr->activePCIHostdevs, + virPCIDeviceGetAddress(actual)); =20 lastGoodPCIIdx--; } diff --git a/src/util/virpci.c b/src/util/virpci.c index 8973c7c754..cbf49357c6 100644 --- a/src/util/virpci.c +++ b/src/util/virpci.c @@ -1336,7 +1336,7 @@ virPCIDeviceReattach(virPCIDevicePtr dev, /* Steal the dev from list inactiveDevs */ if (inactiveDevs) { VIR_DEBUG("Removing PCI device %s from inactive list", dev->name); - virPCIDeviceListDel(inactiveDevs, dev); + virPCIDeviceListDel(inactiveDevs, &dev->address); } =20 return 0; @@ -1750,9 +1750,9 @@ virPCIDeviceListSteal(virPCIDeviceListPtr list, =20 void virPCIDeviceListDel(virPCIDeviceListPtr list, - virPCIDevicePtr dev) + virPCIDeviceAddressPtr devAddr) { - virPCIDeviceFree(virPCIDeviceListSteal(list, &dev->address)); + virPCIDeviceFree(virPCIDeviceListSteal(list, devAddr)); } =20 int diff --git a/src/util/virpci.h b/src/util/virpci.h index e3458a75fa..eb71eb4451 100644 --- a/src/util/virpci.h +++ b/src/util/virpci.h @@ -165,7 +165,7 @@ virPCIDevicePtr virPCIDeviceListSteal(virPCIDeviceListP= tr list, virPCIDevicePtr virPCIDeviceListStealIndex(virPCIDeviceListPtr list, int idx); void virPCIDeviceListDel(virPCIDeviceListPtr list, - virPCIDevicePtr dev); + virPCIDeviceAddressPtr devAddr); virPCIDevicePtr virPCIDeviceListFind(virPCIDeviceListPtr list, virPCIDeviceAddressPtr devAddr); virPCIDevicePtr --=20 2.26.2 From nobody Tue May 14 22:21:41 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 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=1609764947; cv=none; d=zohomail.com; s=zohoarc; b=Rjgawj8JtwLKJ8aHTdPTriSdwctiK8UEPLTI6FKX1w1vzDzVGaTEOp5Nt8Yh3HwhkbFTMHJ5FGSTIAVkIiu+FYlPfX2G2At2atz352XBukNU+zqkyiCZF+ICWAEj3LliOoDZPl6MmrRPQamDvMugd1RJCMiG+scDTkclCBenIz4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1609764947; 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=d40kdyDzJLqsvoVN9rZ9v9PYfnzO2WmbDooBKcdveL0=; b=FnIYs8SOKXOdRJ1oXzvRvwosp8gnuVlvEBhSMWb6OCKI1rx9w4RVmiO5fhiRcm95khQzQbEJ0vgs2PCZRKv3xEtQNpBACLj+2jDoluNOdoGsxTOEXu+2W7FpDmqnaQvnNKU2ul1xomx08E5yiJ0q+Vt0WCJUbgVkylazzzMqB0U= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 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-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1609764947641460.9482371405916; Mon, 4 Jan 2021 04:55:47 -0800 (PST) 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-459-mVwmZY8fN_id75g9yp7XkA-1; Mon, 04 Jan 2021 07:55:44 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0920B190A7AE; Mon, 4 Jan 2021 12:55:38 +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 D87A15D747; Mon, 4 Jan 2021 12:55:37 +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 A44B950042; Mon, 4 Jan 2021 12:55:37 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 104CtZvs014557 for ; Mon, 4 Jan 2021 07:55:35 -0500 Received: by smtp.corp.redhat.com (Postfix) id 40E722166B2B; Mon, 4 Jan 2021 12:55:35 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast05.extmail.prod.ext.rdu2.redhat.com [10.11.55.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3B8F92166B2A for ; Mon, 4 Jan 2021 12:55:32 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B6643800157 for ; Mon, 4 Jan 2021 12:55:32 +0000 (UTC) Received: from mail-qv1-f42.google.com (mail-qv1-f42.google.com [209.85.219.42]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-408-rofp2AoZNZGTmzL6ZWr5qg-1; Mon, 04 Jan 2021 07:55:30 -0500 Received: by mail-qv1-f42.google.com with SMTP id az16so12880558qvb.5 for ; Mon, 04 Jan 2021 04:55:30 -0800 (PST) Received: from rekt.ibmuc.com ([2804:431:c7c6:ca55:7a5d:da5b:906f:bedd]) by smtp.gmail.com with ESMTPSA id m64sm2342866qkb.90.2021.01.04.04.55.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Jan 2021 04:55:29 -0800 (PST) X-MC-Unique: mVwmZY8fN_id75g9yp7XkA-1 X-MC-Unique: rofp2AoZNZGTmzL6ZWr5qg-1 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=d40kdyDzJLqsvoVN9rZ9v9PYfnzO2WmbDooBKcdveL0=; b=ZnaZi8KDWspMC9leWbLSko2f/l3jNmGPxVt/zYwrwYaU2a4WQVkcOAMh41NpN3Ad58 fhEdhNuE9tzaSaj6GoHDOFCpzP/OOEQ5jTnBQph79SSMTbF+7qlTDsgghQiFcJPny3yF nxaN9UjFveRvmUfs2xsJv6MaSDY14dMbmBlR0m8gMfGVnTDV7rY0Cax9gI3Fq6Yeq8LY 0awNU1dj7vcOfeRmnzobBbZ8HIMdXNqOi5BfNUEDmYKSF7/UrJAIvmXMPSerstFZtxmr /iv7bAbvKi2rgcpmgvZ3Fo7+lKX5bbijvS1bJ4Gadzx3h0QKEGsEIBUxOkhFLRztlGbp ZJhA== X-Gm-Message-State: AOAM5307SgEX8DzjWH/fxU/5wNcVr7MiAC4xf+qS6iKLDNmqPCar+OEx 5j5hR8EPylxOnKcwrm0HIGb097SbigHTIQ== X-Google-Smtp-Source: ABdhPJxxjXuhIddYj8B8B25sVQU7zMwjuq5gRPOp2RKrC6l1/lgIiOcyTrVQ75nGQiA1/moEpeT1Fw== X-Received: by 2002:a05:6214:7aa:: with SMTP id v10mr30388987qvz.2.1609764929891; Mon, 04 Jan 2021 04:55:29 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH 20/20] virhostdev.c: remove missing PCI devs from hostdev manager Date: Mon, 4 Jan 2021 09:54:44 -0300 Message-Id: <20210104125444.200536-21-danielhb413@gmail.com> In-Reply-To: <20210104125444.200536-1-danielhb413@gmail.com> References: <20210104125444.200536-1-danielhb413@gmail.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza 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.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" virHostdevReAttachPCIDevices() is called when we want to re-attach a list of hostdevs back to the host, either on the shutdown path or via a 'virsh detach-device' call. This function always count on the existence of the device in the host to work, but this can lead to problems. For example, a SR-IOV device can be removed via an admin "echo 0 > /sys/bus/pci/devices//sriov_numvfs", making the kernel fire up and eventfd_signal() to the process, asking for the process to release the device. The result might vary depending on the device driver and OS/arch, but two possible outcomes are: 1) the hypervisor driver will detach the device from the VM, issuing a delete event to Libvirt. This can be observed in QEMU; 2) the 'echo 0 > ...' will hang waiting for the device to be unplugged. This means that the VM process failed/refused to release the hostdev back to the host, and the hostdev will be detached during VM shutdown. Today we don't behave well for both cases. We'll fail to remove the PCI dev= ice reference from mgr->activePCIHostdevs and mgr->inactivePCIHostdevs because we rely on the existence of the PCI device conf file in the sysfs. Attempti= ng to re-utilize the same device (assuming it is now present back in the host) can result in an error like this: $ ./run tools/virsh start vm1-sriov --console error: Failed to start domain vm1-sriov error: Requested operation is not valid: PCI device 0000:01:00.2 is in use = by driver QEMU, domain vm1-sriov For (1), a VM destroy/start cycle is needed to re-use the VF in the guest. For (2), the effect is more nefarious, requiring a Libvirtd daemon restart to use the VF again in any guest. We can make it a bit better by checking, during virHostdevReAttachPCIDevice= s(), if there is any missing PCI device that will be left behind in activePCIHos= tdevs and inactivePCIHostdevs lists. Remove any missing device found from both li= sts, unconditionally, matching the current state of the host. This change affects the code path in (1) (processDeviceDeletedEvent into qemuDomainRemoveDevice= , all the way back to qemuHostdevReAttachPCIDevices) and also in (b) (qemuProcess= Stop into qemuHostdevReAttachDomainDevices). NB: this patch does **NOT** intend to implement support for surprise hotunp= lug of PCI devices in Libvirt. Although this can now be achieved if the hypervi= sor and the PCI driver copes with it, our goal is to mitigate what it is still = considered an user oopsie. For all supported purposes, the admin must remove the SR-IO= V VFs from all running domains before removing the VFs from the host. Resolves: https://gitlab.com/libvirt/libvirt/-/issues/72 Signed-off-by: Daniel Henrique Barboza --- src/hypervisor/virhostdev.c | 38 +++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/src/hypervisor/virhostdev.c b/src/hypervisor/virhostdev.c index 0510eb020c..50fe29f142 100644 --- a/src/hypervisor/virhostdev.c +++ b/src/hypervisor/virhostdev.c @@ -1077,6 +1077,40 @@ virHostdevReAttachPCIDevicesImpl(virHostdevManagerPt= r mgr, } =20 =20 +static void +virHostdevDeleteMissingPCIDevices(virHostdevManagerPtr mgr, + virDomainHostdevDefPtr *hostdevs, + int nhostdevs) +{ + size_t i; + + if (nhostdevs =3D=3D 0) + return; + + virObjectLock(mgr->activePCIHostdevs); + virObjectLock(mgr->inactivePCIHostdevs); + + for (i =3D 0; i < nhostdevs; i++) { + virDomainHostdevDef *hostdev =3D hostdevs[i]; + virDomainHostdevSubsysPCI *pcisrc =3D &hostdev->source.subsys.u.pc= i; + g_autoptr(virPCIDevice) pci =3D NULL; + + if (virHostdevGetPCIHostDevice(hostdev, &pci) !=3D -2) + continue; + + /* The PCI device from 'hostdev' does not exist in the host + * anymore. Delete it from both active and inactive lists to + * reflect the current host state. + */ + virPCIDeviceListDel(mgr->activePCIHostdevs, &pcisrc->addr); + virPCIDeviceListDel(mgr->inactivePCIHostdevs, &pcisrc->addr); + } + + virObjectUnlock(mgr->activePCIHostdevs); + virObjectUnlock(mgr->inactivePCIHostdevs); +} + + /* @oldStateDir: * For upgrade purpose: see virHostdevRestoreNetConfig */ @@ -1102,6 +1136,10 @@ virHostdevReAttachPCIDevices(virHostdevManagerPtr mg= r, =20 virHostdevReAttachPCIDevicesImpl(mgr, drv_name, dom_name, pcidevs, hostdevs, nhostdevs, oldStateDir); + + /* Handle the case where PCI devices from the host went missing + * during the domain lifetime */ + virHostdevDeleteMissingPCIDevices(mgr, hostdevs, nhostdevs); } =20 =20 --=20 2.26.2