From nobody Mon May 6 00:01:25 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=1610999655; cv=none; d=zohomail.com; s=zohoarc; b=CDCRslHdvor0Ji2z6fB18qAW0ZIbh5MhfiejLc1hhvWniD1Jy6vbgOV7l4omXEUV9/Kd+SwHj4+MGCfGVGZa+EdMDvvAmE+vldbOwSBh5xN0xgRz+QmKIabTaLn/OMlRCG9356bVTjs+pWQwLGz/rZ+k9Ffo2htn7jPXrWYEMtE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610999655; 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=Y6R2XKHwgDed7POHwQwVJ8Nh9OQrD43KfYHNWA/YCf0=; b=QyLUb6uJgfD4rahOJcOcXsTbzPdT/c2pffTvSrfBJUqyeZ1fSbicGSUDmVYHCAEamg3q7XlZ6y7+UaczvGjcHHb0Ogsmi5Jbs612Apg7uQlfoArL0SCqmwFwjiyqn6J0FbvfTlbg9Aj39U254quKZUeLKQj/WiP9c0OrN+n0yyE= 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 1610999655497796.86658634134; Mon, 18 Jan 2021 11:54:15 -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-323-PnDDYfGjN6CL82lg0m7rJw-1; Mon, 18 Jan 2021 14:54:11 -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 6068180A5C1; Mon, 18 Jan 2021 19:54:06 +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 CF2F310013BD; Mon, 18 Jan 2021 19:54:05 +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 3E29A4BB7B; Mon, 18 Jan 2021 19:54:02 +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 10IJrsVc032444 for ; Mon, 18 Jan 2021 14:53:54 -0500 Received: by smtp.corp.redhat.com (Postfix) id 6C7A22026D16; Mon, 18 Jan 2021 19:53:54 +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 66D772026D11 for ; Mon, 18 Jan 2021 19:53:52 +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 EC73E800969 for ; Mon, 18 Jan 2021 19:53:51 +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-231-QPG7px1JNquZClxYCgFpIg-1; Mon, 18 Jan 2021 14:53:49 -0500 Received: by mail-qt1-f175.google.com with SMTP id e17so3000665qto.3 for ; Mon, 18 Jan 2021 11:53:49 -0800 (PST) Received: from rekt.ibmuc.com ([2804:431:c7c7:a75a:cb34:ba60:6de6:be1d]) by smtp.gmail.com with ESMTPSA id 16sm11309085qkf.112.2021.01.18.11.53.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Jan 2021 11:53:48 -0800 (PST) X-MC-Unique: PnDDYfGjN6CL82lg0m7rJw-1 X-MC-Unique: QPG7px1JNquZClxYCgFpIg-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=Y6R2XKHwgDed7POHwQwVJ8Nh9OQrD43KfYHNWA/YCf0=; b=Met8I+I2L7jaSLj9/Ud+YQf3rhcBo3HSHq3WhOJhB7Lvk/FtztLjROu3+nc/hwMafZ 3/V52XfbrEO9c+PA5ET6+Gq/EbzB9ObbcngSNuCui8qMuZSVA/uQDaaXOYiYpVAOlT1m Y0EqPd3DJTrQrxtCtoWEaOmjMRCq/V7fhaxAdcUJzYnHDqN0EBbKKcIZxj3kuEzi9tUK Rdaxb2BMAxis70l7vt6ZTLncw2QAzKn+T3Xn6kHeroVjJtvahCX2TSHJ22JMwCh8Gy7I 7WDsOUybNu0Yq5mnzHj6w550FB615IGclu0+f7RKl77t8xlURITLS4op0zQulNHr/bYv Xvew== X-Gm-Message-State: AOAM531dgEJ4HFdx/Wd4IYThkwZWmfo1exWnRXqD+KAH+gdgrbiZUYFt RIRCS6nbLJw73fkC5eXXf6yxYFbFF744EQ== X-Google-Smtp-Source: ABdhPJypF4loVthtDiUPYGXq1bJj4JLuxQY/+7FdX9eZMceMN5kXmEYri1FfpyWgdfJXZJR3z1UALg== X-Received: by 2002:aed:3629:: with SMTP id e38mr1192016qtb.354.1610999628950; Mon, 18 Jan 2021 11:53:48 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH RESEND 01/20] virpci, domain_audit: use virPCIDeviceAddressAsString() Date: Mon, 18 Jan 2021 16:53:17 -0300 Message-Id: <20210118195336.2090823-2-danielhb413@gmail.com> In-Reply-To: <20210118195336.2090823-1-danielhb413@gmail.com> References: <20210118195336.2090823-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" 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 Reviewed-by: Laine Stump --- 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 50fd5ef7ea..5f50f92abb 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 Mon May 6 00:01:25 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.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 170.10.133.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=1610999655; cv=none; d=zohomail.com; s=zohoarc; b=N0Fa9hHvld1R1g7bV/1Tfuue3f2nENG1KJRS8FXH1uHhw6GyR4yvlftYBO3wM28ZFixy/mTIVSPbH1SEMM7iPInwJeqKw0JWLsTjMsKAibP1lG5+f4i2n4wBXzETTx9EZ/zYd0bZhNsn5xG1OBU10KLREvwJ7hfHG9ijIU5W94E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610999655; 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=FeRID3gmXUvEDAbcsFfjvKqnY9P0F2tJM74qOms94GA=; b=NNaFRS7venQY2JSpgJkPhwIiJxKSk+sJAlkJMA5ruZyMXCRzhq7grTDieEMz0VyPkdN63ziac/uaEHYtU9RbzPOvcwmutw7ndVeK5sblSoX0mLE3ZazzdhUWfcMXtgUQU8/e7QtPHT70Q8EofZbGUEwsEUPnKuZQqW9n7c/fvfs= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.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 [170.10.133.124]) by mx.zohomail.com with SMTPS id 1610999655072256.88392484369; Mon, 18 Jan 2021 11:54:15 -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-12-jFpqeW2ZMNq_5mvMVn5VlA-1; Mon, 18 Jan 2021 14:54:11 -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 5ED3210054FF; Mon, 18 Jan 2021 19:54:06 +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 CEDE61962F; Mon, 18 Jan 2021 19:54:05 +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 29CA11809C9F; Mon, 18 Jan 2021 19:54:02 +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 10IJs0Gt032463 for ; Mon, 18 Jan 2021 14:54:00 -0500 Received: by smtp.corp.redhat.com (Postfix) id 0093F111143C; Mon, 18 Jan 2021 19:54:00 +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 EEDAA1111434 for ; Mon, 18 Jan 2021 19:53:53 +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 5C3D0858280 for ; Mon, 18 Jan 2021 19:53:53 +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-272-vS3XrlVaOQqptP5Gi_-GzQ-1; Mon, 18 Jan 2021 14:53:51 -0500 Received: by mail-qk1-f170.google.com with SMTP id v126so19738958qkd.11 for ; Mon, 18 Jan 2021 11:53:51 -0800 (PST) Received: from rekt.ibmuc.com ([2804:431:c7c7:a75a:cb34:ba60:6de6:be1d]) by smtp.gmail.com with ESMTPSA id 16sm11309085qkf.112.2021.01.18.11.53.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Jan 2021 11:53:49 -0800 (PST) X-MC-Unique: jFpqeW2ZMNq_5mvMVn5VlA-1 X-MC-Unique: vS3XrlVaOQqptP5Gi_-GzQ-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=FeRID3gmXUvEDAbcsFfjvKqnY9P0F2tJM74qOms94GA=; b=TWmhf+Mrl9rk+SPvP6+WjZJ0PWP3WuE8Um5v58WL1bdbO9jHlZXU31ukhoi9gwkDQ0 w2D+DRbf4EF9h4T4gPu+G/LmXkKt4wiHrpMOnkbaaKUDhdTRH/FFdSfYoVzLmdbofIng 7bCYS7/yBcm4ZZ1+1albLxHiYJsFZgQcJSHhq/Kg9sRUk/zj9viVyIAN3bE7KHh9GgFR KoB5C0qUN45zESUTngON1tLk3LgPxql7mz74UlHeLRMqnOMcaG9tGJnFvUBOvcj/W87V aGstK5+zmZIkNNVmr4m1wO6ez/d9C1235LPClw/a1/9HVTX6goxI5rgaDC8I9j1jruPN cGVg== X-Gm-Message-State: AOAM530RC4LUE1Cr2rQJ5s3DQ8NKO3A1/GxFND/045e98Dir8dVocXZd L3GPhG9PsypcC1+YWMjWX9X5Czhz29nPEg== X-Google-Smtp-Source: ABdhPJwYcUQ8d1Bm8B48zVSphVlJckGHOutcNtYUJgNMZYw5sVWco6k6AaX00L4AAh19pdwy8F61lw== X-Received: by 2002:a37:8b81:: with SMTP id n123mr1240765qkd.242.1610999630422; Mon, 18 Jan 2021 11:53:50 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH RESEND 02/20] qemu, lxc: move NodeDeviceGetPCIInfo() function to domain_driver.c Date: Mon, 18 Jan 2021 16:53:18 -0300 Message-Id: <20210118195336.2090823-3-danielhb413@gmail.com> In-Reply-To: <20210118195336.2090823-1-danielhb413@gmail.com> References: <20210118195336.2090823-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" 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 Reviewed-by: Laine Stump --- 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 c325040b60..55284577b0 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 5bd3614e21..0821d39c9b 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 @@ -5773,37 +5774,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, @@ -5845,7 +5815,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); @@ -5916,7 +5886,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); @@ -5974,7 +5944,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 027617deef..0a732a241d 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -11955,37 +11955,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, @@ -12028,7 +11997,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); @@ -12109,7 +12078,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); @@ -12163,7 +12132,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 Mon May 6 00:01:25 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=1610999686; cv=none; d=zohomail.com; s=zohoarc; b=cB1SLW2/mkb0RMHgn52alAMlqfM399GBAIl76kFOf4yB9NRnLTT0j7sNPkN6kLkV2v03oFMO8ssyF0V/7CVkdWj5jxNPkWe1y+8qtT3J5va5ukFACIajzBXKinUci+eblD/5/lA9riBH1kYInzZSG5G4ShtvZiqxe3RqfVKZiME= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610999686; 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=FZXurWTdm4Ly6GwqLwDAG3x2PFpZvziK7HUh7r3/Gu0=; b=Gi0XpHhc7h5woz23B5kEIwBXwCqhHb8GWxwipVWRael8LtTJDSsInyxHXMaZNZsx47K5b88b8slV0D60aHqFjJHwegokFACugHmxfhNX/fB+m1GN5Xk2R1RUTRl6ubO8ON3w0jlGRTygDZtWYwzSC7goGlRzchSwH0DXPcMYPDQ= 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 1610999686202340.0674682298592; Mon, 18 Jan 2021 11:54: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-333-1PCQodf3NFqlIpqmZSVLiQ-1; Mon, 18 Jan 2021 14:54:43 -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 9310C1005D4C; Mon, 18 Jan 2021 19:54:31 +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 695C727C30; Mon, 18 Jan 2021 19:54:31 +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 278051809CAC; Mon, 18 Jan 2021 19:54:31 +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 10IJs3f0032493 for ; Mon, 18 Jan 2021 14:54:03 -0500 Received: by smtp.corp.redhat.com (Postfix) id 4071563796; Mon, 18 Jan 2021 19:54:03 +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 382346D9DB for ; Mon, 18 Jan 2021 19:53:54 +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 9F60D187504C for ; Mon, 18 Jan 2021 19:53:54 +0000 (UTC) Received: from mail-qv1-f41.google.com (mail-qv1-f41.google.com [209.85.219.41]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-39-PCYcxLJ6MeWbCwljwWYk6Q-1; Mon, 18 Jan 2021 14:53:52 -0500 Received: by mail-qv1-f41.google.com with SMTP id l7so8075599qvt.4 for ; Mon, 18 Jan 2021 11:53:52 -0800 (PST) Received: from rekt.ibmuc.com ([2804:431:c7c7:a75a:cb34:ba60:6de6:be1d]) by smtp.gmail.com with ESMTPSA id 16sm11309085qkf.112.2021.01.18.11.53.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Jan 2021 11:53:51 -0800 (PST) X-MC-Unique: 1PCQodf3NFqlIpqmZSVLiQ-1 X-MC-Unique: PCYcxLJ6MeWbCwljwWYk6Q-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=FZXurWTdm4Ly6GwqLwDAG3x2PFpZvziK7HUh7r3/Gu0=; b=ecXVlJTYC3A0TigBxBJz3entlCDYaOVZ3WRSFEBw7E2yEC2j32ea574KAZvcTS+Ky5 EYdx4/07M1AX/1HHiyX85riP0gjbKyKyy28B+PIj2lO0UWzxr8HvMG4W3Z6nMJCnPCXT PMSyeUb09HZ3pcndJTCRHUQ5z8CPe06PpQyLetsAg0SYY/CtbZPpfioHDHCYJr0PfTqA 85XGXpcMgUNJjyqEe3ErjeRO+IeDoIqIg93kMzuka5xSV9LoqUthMR4eV5iMidF0ouAW EK3v3vUyuKQ0Fwq6v+MAKHuthXPXeOVIOy/g9u3I3PUzydoGF548cog47lJmkAlh5pTi KLYg== X-Gm-Message-State: AOAM531C2mO6HUvxRN8G9FDf4jdELEgFTHoDi+Um5GWAuhjVbhbSSWLY rKbuAIwyXEtpIU5xg9F+KlTYfFyouWfLOQ== X-Google-Smtp-Source: ABdhPJz74o8oe137ABg3QFqeDiA9GK0UBOl1Xv7yctA9hlJZqdhbiMdgSieit41f5lSF/3ZLHW8PbQ== X-Received: by 2002:a0c:e9c2:: with SMTP id q2mr1328166qvo.1.1610999631847; Mon, 18 Jan 2021 11:53:51 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH RESEND 03/20] domain_driver.c: use PCI address with virDomainDriverNodeDeviceGetPCIInfo() Date: Mon, 18 Jan 2021 16:53:19 -0300 Message-Id: <20210118195336.2090823-4-danielhb413@gmail.com> In-Reply-To: <20210118195336.2090823-1-danielhb413@gmail.com> References: <20210118195336.2090823-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 Reviewed-by: Laine Stump --- 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 0821d39c9b..360d553a22 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -5780,7 +5780,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; @@ -5815,10 +5815,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 @@ -5853,7 +5853,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; @@ -5886,10 +5886,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 @@ -5911,7 +5911,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; @@ -5944,10 +5944,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 0a732a241d..28781cc34b 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -11962,7 +11962,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; @@ -11997,10 +11997,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 @@ -12046,7 +12046,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; @@ -12078,10 +12078,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 @@ -12100,7 +12100,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; @@ -12132,10 +12132,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 Mon May 6 00:01:25 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=1610999671; cv=none; d=zohomail.com; s=zohoarc; b=JpxFHZbNba7H9T/GqFZizpqyGif1t0nSqB5lcUZom//GxGH17eWSuj22cEYRMaI5264ukKIMTfO01Ei/tswRGt98xfgeQaeGf0JMnDyYE/TYD2Knpb7bEJhsayn1fTXddP26q+tZ1THKky8MBxQBPQ5MQTIF3+JLW3FJf0eOV2g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610999671; 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=F4zqy8Mxzni5wHUjcGSSsy3iCRAC5OGcrBapKdIO75E=; b=N7EnptEjqlSqcTMyi90A7hlWhfXjARe2GO+cca5RgJxPfQ3Kos0C60WjiFpLK9/GdGXLeJP6J+zaYbEOZ+WOTRkGCIqcuA8GE9yBEw4NFg5beAsRX53bB/ZFbfLl4DkFulvzNO6Ul9j1xh+C/W+wHA52KeVHoAwxMS1PYRqMkiM= 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 1610999671330651.256838099429; Mon, 18 Jan 2021 11:54:31 -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-541-KkNuRnwnPi-RHZkqq8Jy8g-1; Mon, 18 Jan 2021 14:54:27 -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 BF59B800D53; Mon, 18 Jan 2021 19:54:21 +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 99D9A60C75; Mon, 18 Jan 2021 19:54: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 6099D4E590; Mon, 18 Jan 2021 19:54:21 +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 10IJs0rg032464 for ; Mon, 18 Jan 2021 14:54:00 -0500 Received: by smtp.corp.redhat.com (Postfix) id 00817111143B; Mon, 18 Jan 2021 19:54:00 +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 EF987111143A for ; Mon, 18 Jan 2021 19:53:56 +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 A78AD858281 for ; Mon, 18 Jan 2021 19:53:56 +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-567-kKKoR84GO1aWUu5DgtWDkw-1; Mon, 18 Jan 2021 14:53:54 -0500 Received: by mail-qk1-f179.google.com with SMTP id w79so19772603qkb.5 for ; Mon, 18 Jan 2021 11:53:54 -0800 (PST) Received: from rekt.ibmuc.com ([2804:431:c7c7:a75a:cb34:ba60:6de6:be1d]) by smtp.gmail.com with ESMTPSA id 16sm11309085qkf.112.2021.01.18.11.53.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Jan 2021 11:53:52 -0800 (PST) X-MC-Unique: KkNuRnwnPi-RHZkqq8Jy8g-1 X-MC-Unique: kKKoR84GO1aWUu5DgtWDkw-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=F4zqy8Mxzni5wHUjcGSSsy3iCRAC5OGcrBapKdIO75E=; b=tlnK7kw5HvU05SK8otbmgC1bj79dEVivGdWmnBA+vwvUUFccrWrKWUR1vHkGsstPVU FR+/PKC5/cehxMIGNt54esDewBSaC4V5t6x2i2Hpem21czFXn4/NREuUvhajvHUIpXJA e6Jp2L6ZSuNJaB2UHV0kysFENoUehFXywt1eMevXdpgQ2QU8vgLvuOrJkf/D1gXpC2cD ipKOcwRUIWZMiPRonLEnAKUtymM6fUbSFysBmrq0SKj99lqj2H+mBYeqoND/GgzKmyIO YrOt4O3+PS9SiSvnlhWZx0UW7UMGf6i6ZKix/7TwfsWTa9D58/hDPxNmo2M99+krTDy3 vkMg== X-Gm-Message-State: AOAM5334p3In1gzRb6czfvmRuQq6spczpcSXVWQNoWAyRkalQvrj10qc isr+OEaNy606hzFC0fvQP0ewF2INPAs1mQ== X-Google-Smtp-Source: ABdhPJwQbeeJKK2zzEPWOzg7mpz+WF0AmhTIlELr//wC+iHboQdNpAAYN6aG/6mCRDU4d90/kjccwg== X-Received: by 2002:a37:506:: with SMTP id 6mr1239668qkf.168.1610999633364; Mon, 18 Jan 2021 11:53:53 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH RESEND 04/20] virpci.c: simplify virPCIDeviceNew() signature Date: Mon, 18 Jan 2021 16:53:20 -0300 Message-Id: <20210118195336.2090823-5-danielhb413@gmail.com> In-Reply-To: <20210118195336.2090823-1-danielhb413@gmail.com> References: <20210118195336.2090823-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.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" 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 Reviewed-by: Laine Stump --- 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 be32a26164..bd35397f2c 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 360d553a22..3eaf106006 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -5818,7 +5818,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 @@ -5889,7 +5889,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 @@ -5947,7 +5947,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 28781cc34b..7581e3c8cb 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -12000,7 +12000,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 @@ -12081,7 +12081,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 @@ -12135,7 +12135,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 2fc6ef2616..76edaed027 100644 --- a/src/security/security_selinux.c +++ b/src/security/security_selinux.c @@ -2103,8 +2103,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; @@ -2343,8 +2342,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 5f50f92abb..5a91553b5f 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 Mon May 6 00:01:25 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=1610999672; cv=none; d=zohomail.com; s=zohoarc; b=LQ25W792/+xUuRFgyBe/UgL394P+gSysKp7th5XxkjRhdzs701WW3cGefzFJHSTCMjDsyKjjZQ/B58st+7FMELOxhYsMu0Cp/jAHDp1VEhppxMsqNMWh+tKtTHtoINytQrhrXu50ohWtT7OIgYqTweG+3QFqPBN5XHCoI2QA2fQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610999672; 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=bq38eevbRUqKYViZ57Xaj/8QkojkC8atwHXWCZ8lWas=; b=gb4I53crHqsyEXOo0TXw0eElhyqsb99/gM7ihEZuW0rv4gPbvdsqd3W5ZTNxOH4w8DbK6wZM4KKlelW0yJxmQF7VkkfzczqWI5XerEZleBhCYl+B/ppgk3Ih7VaqGzBVplwxRKVHmfaVWU4JDi8+tGyPkBNN3QfL5JqEHs1dILo= 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 1610999672341561.5302052411798; Mon, 18 Jan 2021 11:54: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-108-YQtzUQK0MCiM8mLkopuonA-1; Mon, 18 Jan 2021 14:54:28 -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 8D4BCE745; Mon, 18 Jan 2021 19:54:22 +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 636245D71B; Mon, 18 Jan 2021 19:54: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 302174EDB6; Mon, 18 Jan 2021 19:54:22 +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 10IJs3Rh032494 for ; Mon, 18 Jan 2021 14:54:03 -0500 Received: by smtp.corp.redhat.com (Postfix) id 5E0FD6B5BD; Mon, 18 Jan 2021 19:54:03 +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 569DF6D9E2 for ; Mon, 18 Jan 2021 19:53:58 +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 DA129101A562 for ; Mon, 18 Jan 2021 19:53:58 +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-513-XuxKp0eSNJOo8XKwyQkfBQ-1; Mon, 18 Jan 2021 14:53:55 -0500 Received: by mail-qk1-f179.google.com with SMTP id v126so19739140qkd.11 for ; Mon, 18 Jan 2021 11:53:55 -0800 (PST) Received: from rekt.ibmuc.com ([2804:431:c7c7:a75a:cb34:ba60:6de6:be1d]) by smtp.gmail.com with ESMTPSA id 16sm11309085qkf.112.2021.01.18.11.53.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Jan 2021 11:53:54 -0800 (PST) X-MC-Unique: YQtzUQK0MCiM8mLkopuonA-1 X-MC-Unique: XuxKp0eSNJOo8XKwyQkfBQ-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=bq38eevbRUqKYViZ57Xaj/8QkojkC8atwHXWCZ8lWas=; b=PqBYrvsL8OxQ+Mr1GFm50tnh9HrKThkCKM2GQfpa6mjKkJYPHSpQlSPOk/e5zs3jjf YlFc/DUDu6osNnzHBo4kTxNm59F714lkm/QpdPHE6U1NjLbiMz/AxeeqpkdNH5IiMfOV PLV/wPFHb9hp9geb/rHHkxzx7n07WFa3dWcii/OWjkJb3iBP3UVpZGzE/CMhJ+OivSpe P0nucYd4k2ip0kF9rp5i0eZVOR+Dd6wrCwI7HrJR2Y2pLSRB0cGFkdS2dS4zFOXcRhLb MuYDyBpizxY93IgRNpSLU/KwSZ6IKPT/IeAmpWoYBizIB3mzd1fM/bvssmYSotYFvSsG 42VQ== X-Gm-Message-State: AOAM531J2HN4jL3dDVpzIj9qfkRbsK69rtFWyRj8qEmN+kuhWslT/W5H nZtKZ5xIL/xPcfpg0Yznn02/tolLzofRFQ== X-Google-Smtp-Source: ABdhPJx0XE0EkoAJsaX1PXkTtzJQXHXTzWk/k4ZoqVUEaqoP8DQuYnGpA0kSkF8CRaQsisTaksLVWQ== X-Received: by 2002:a37:a44:: with SMTP id 65mr1202873qkk.478.1610999634754; Mon, 18 Jan 2021 11:53:54 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH RESEND 05/20] virpci: introduce virPCIDeviceExists() Date: Mon, 18 Jan 2021 16:53:21 -0300 Message-Id: <20210118195336.2090823-6-danielhb413@gmail.com> In-Reply-To: <20210118195336.2090823-1-danielhb413@gmail.com> References: <20210118195336.2090823-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" 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 Reviewed-by: Laine Stump --- 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 55284577b0..36635e6de7 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2819,6 +2819,7 @@ virPCIDeviceAddressIsValid; virPCIDeviceAddressParse; virPCIDeviceCopy; virPCIDeviceDetach; +virPCIDeviceExists; virPCIDeviceFileIterate; virPCIDeviceFree; virPCIDeviceGetAddress; diff --git a/src/util/virpci.c b/src/util/virpci.c index 5a91553b5f..7143380348 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 Mon May 6 00:01:25 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=1610999671; cv=none; d=zohomail.com; s=zohoarc; b=ZpoMW9y6i2luGVBkIAE+MEMIzYp+7DamqQa5acMeoafFx2YZv3MQYH3KHyn3OMLgwhg1tAa+CiHCFIR96yzB2Mm78MKVRtytnYOP/UBCqxel9Wt8l67qlos5G8QrVaK05jp5KXd5rZIpw82dAn/6IPqVkqK+X+fiaqGRE19l9sc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610999671; 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=Em4N8vO2u3DBfCQSpZpgpQL2Jqk/cBxrSYgNVCXtNXw=; b=VbvNy3Hr23YBKHjAsF20rgQrx9Zc8iFlvfhfigxeqo8I221c5z7Yfmmg/TTl4ObIITpE1upEyVGM8iu9IX/K0tMbA93T+f11P+yLeHjnLDJS1nkyd+yMv40KP6VOqDOVtd4/w2bWwFlNmisJDs5SvUCOg+VYQU6pATUy/LSuzzA= 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 16109996713621021.819337450023; Mon, 18 Jan 2021 11:54:31 -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-168-sHHkbnMiMVKHem0a0FtvlA-1; Mon, 18 Jan 2021 14:54:27 -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 B27B680A5C2; Mon, 18 Jan 2021 19:54:21 +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 8F6F95D9CD; Mon, 18 Jan 2021 19:54: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 5AD261809CA4; Mon, 18 Jan 2021 19:54:21 +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 10IJrxbL032457 for ; Mon, 18 Jan 2021 14:53:59 -0500 Received: by smtp.corp.redhat.com (Postfix) id 505762166B29; Mon, 18 Jan 2021 19:53:59 +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 4A7E32166B28 for ; Mon, 18 Jan 2021 19:53:59 +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 35EA5187504B for ; Mon, 18 Jan 2021 19:53:59 +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-479-7RzOJY93N-SK8_UkxmPz3A-1; Mon, 18 Jan 2021 14:53:57 -0500 Received: by mail-qk1-f177.google.com with SMTP id w79so19772732qkb.5 for ; Mon, 18 Jan 2021 11:53:56 -0800 (PST) Received: from rekt.ibmuc.com ([2804:431:c7c7:a75a:cb34:ba60:6de6:be1d]) by smtp.gmail.com with ESMTPSA id 16sm11309085qkf.112.2021.01.18.11.53.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Jan 2021 11:53:55 -0800 (PST) X-MC-Unique: sHHkbnMiMVKHem0a0FtvlA-1 X-MC-Unique: 7RzOJY93N-SK8_UkxmPz3A-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=Em4N8vO2u3DBfCQSpZpgpQL2Jqk/cBxrSYgNVCXtNXw=; b=WUjUjQDFNov0YYkxCIYnRBwbHNXsvWSaIyvO0WgAJhhUUSVsh7zNxhMlGY421ns71L DS8NH+zklsdQFZNHdz82HJlmOQUCOhD3VKFmOxBBQ/bOQ1DBt9w4ju0YV9NS2OrwLE1X 2d41XhWQqrk0FQzIB98eR/EYg6nuBUixENDgVNaHf1hdY1iy4VArhD81Vs5TzKMK9hjE 5RljsAhg2S4r1eHALQbIDEW0tB0EBrsLn6sWolaDTURcekC8DU67vXFq5oQtDA2k7Mz6 FF588nPe/5wZdr43St6NNOX9i1RsecCz6UlithiJK+le+jTR3N+Y0ZwEyCE0Hj8bUGVc KV1g== X-Gm-Message-State: AOAM5338wtQ13rCerV1fIt3dki1OW2GKmM6tDXTjICJpzlIjt6MX/AwJ hyPVvNqAaPQvR+vTCuTMzfzJWyioRz62Ng== X-Google-Smtp-Source: ABdhPJz8rx79wH0AYe5v+dGk16T6rlaSXnB0O1rkRpghH0B7R8n4TFS/tAIWSVHx79Yw+O86nXcFsw== X-Received: by 2002:a37:9c8a:: with SMTP id f132mr1181660qke.189.1610999636131; Mon, 18 Jan 2021 11:53:56 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH RESEND 06/20] virhostdev.c: virHostdevGetPCIHostDevice() now reports missing device Date: Mon, 18 Jan 2021 16:53:22 -0300 Message-Id: <20210118195336.2090823-7-danielhb413@gmail.com> In-Reply-To: <20210118195336.2090823-1-danielhb413@gmail.com> References: <20210118195336.2090823-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.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" 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 Reviewed-by: Laine Stump --- 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 bd35397f2c..dbba36193b 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 Mon May 6 00:01:25 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=1610999674; cv=none; d=zohomail.com; s=zohoarc; b=JMnV1kd6S1SOf4g7u7c+AwYdBb7O5K2YqI8PJie9DNw+THWsjNQBMw9ar1duNWQnm97zpZLM1IpeXF8ukahHHo4qAdIa8ASEjgaaHL5ARGf5ZW3C46aJgwe8XRsd0ld2SJT1mL5NNe98kopEId+AaavzK+vGBqQJHvNBy0lNXVU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610999674; 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=ilXQ+8IGnXDBvRvY9tJecQBYik1Jp63mErQD25NxvCc=; b=E6Yir3Bco+KY7tuNQtqE24JE1WzzVGmTQt3PBO8Cubn05kMV/jtgSaiuuvvvmVSMmdLfxvNTRdBkaew3C4mqu3Fn5SexC7XVwmkwjjgnsY7nSZhmrrj4PfFV6krz4cmX8PYzw/kMo/ne8uqpkicui5Dh8g+jYk1AcJf4hsgwfNw= 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 1610999674018200.77521304346533; Mon, 18 Jan 2021 11:54:34 -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-425-k9fw65mLPWGM6YH5cfD0VQ-1; Mon, 18 Jan 2021 14:54:30 -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 BFDAA107ACE6; Mon, 18 Jan 2021 19:54:24 +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 4550410023B4; Mon, 18 Jan 2021 19:54:24 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 11DAD1809CA6; Mon, 18 Jan 2021 19:54:24 +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 10IJs0Ro032465 for ; Mon, 18 Jan 2021 14:54:00 -0500 Received: by smtp.corp.redhat.com (Postfix) id 5598B1111439; Mon, 18 Jan 2021 19:54:00 +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 517D71111437 for ; Mon, 18 Jan 2021 19:54:00 +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 3FB148039DD for ; Mon, 18 Jan 2021 19:54:00 +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-476-xtCqJLvrMgO9JgS4x4uA_A-1; Mon, 18 Jan 2021 14:53:58 -0500 Received: by mail-qt1-f182.google.com with SMTP id c1so12134506qtc.1 for ; Mon, 18 Jan 2021 11:53:58 -0800 (PST) Received: from rekt.ibmuc.com ([2804:431:c7c7:a75a:cb34:ba60:6de6:be1d]) by smtp.gmail.com with ESMTPSA id 16sm11309085qkf.112.2021.01.18.11.53.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Jan 2021 11:53:57 -0800 (PST) X-MC-Unique: k9fw65mLPWGM6YH5cfD0VQ-1 X-MC-Unique: xtCqJLvrMgO9JgS4x4uA_A-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=ilXQ+8IGnXDBvRvY9tJecQBYik1Jp63mErQD25NxvCc=; b=JlOAbbtvmbVxfqDXwLRGX0ds1A4CdlPM63Y10JvtMh180v8XOYNzmH/oZfVMPU+y6J yDYMeQsthidCVNUlAMkgg+3xUPa+//RKfqoblchH2P2tFsvYaZikWERCrv9eLbCsrA9a ujUR5QgyzxOvTdbhnpAGiWnY34a9Q+AYLnFkjnaEMtjIe/4A3K/Cs05CjzJjQC7fss0h Rl/sHghZoB6CYr1ONCvSuf9aOHSQ2d5LwDxr5oUOxUJvmcr7SmLEflu11m974hC7uBlF gLG5Slgh0yA8TpgIowuQkGrwiQmZ6wG84laY4l6mbbV42FYjqWmYhdoIHs5oDqnmbZH4 LyRg== X-Gm-Message-State: AOAM5330Y8kGbuwWM7NZ3z/XnzDK86lc1PFYLx28XQq/DbIudgNu1DdT Hc5Mr/6o5SSVqmdcbMa9setrIbT7PeBfug== X-Google-Smtp-Source: ABdhPJyIHrRgq73jw5tEh9G3qzNx0lTxaK1OiD9MjJbZpP0RWbTaNOGtH3yDz/CCAuILy9bYRcwgVg== X-Received: by 2002:aed:2088:: with SMTP id 8mr1238093qtb.174.1610999637572; Mon, 18 Jan 2021 11:53:57 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH RESEND 07/20] security_selinux.c: modernize set/restore hostdev subsys label functions Date: Mon, 18 Jan 2021 16:53:23 -0300 Message-Id: <20210118195336.2090823-8-danielhb413@gmail.com> In-Reply-To: <20210118195336.2090823-1-danielhb413@gmail.com> References: <20210118195336.2090823-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.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* cleanup to avoid free() calls. Signed-off-by: Daniel Henrique Barboza Reviewed-by: Laine Stump --- 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 76edaed027..99adf08a15 100644 --- a/src/security/security_selinux.c +++ b/src/security/security_selinux.c @@ -2085,7 +2085,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; @@ -2097,39 +2097,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, @@ -2141,13 +2136,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; @@ -2155,19 +2148,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 @@ -2323,7 +2313,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; @@ -2335,37 +2325,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, @@ -2375,13 +2359,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; @@ -2389,20 +2371,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 Mon May 6 00:01:25 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=1610999682; cv=none; d=zohomail.com; s=zohoarc; b=FfdtIgLzSYAzdCAPWpym7YFAkxuzTntWHFmnlm0v76BuZiXd4239LYB0uOlaziK5C86792qYc0mxBfg2tOR1m6OY621kD1Gfxc3ZY2wTITBeyP/hmw7y487+Vh/dyaJwQ+b+BbVlnv4RS3eKffQS38O4XqyCElKfXKQO0wVMExM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610999682; 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=RMaRSBEEEYj5a4BQznFGJbUfrlYu8f3uyEbuxYxf3zq+RkHYJEriCuqkM8sU1ThVNdNLzw2NJcheCFiLgtowpc7rjcV9GZ+V7hoF8Ak+ratnLSpFqOWZYLg0jQBBzaWGUrL0T8G7DWocTQ3sCYrThHORZkZdu4HMsHm+FzZ9gYg= 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 1610999682990982.3408325179978; Mon, 18 Jan 2021 11:54: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-253-2-gsRtMPN9iXDmfzhX0C6w-1; Mon, 18 Jan 2021 14:54:39 -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 C25A010054FF; Mon, 18 Jan 2021 19:54:28 +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 A28B560C9C; Mon, 18 Jan 2021 19:54: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 6F7DC50034; Mon, 18 Jan 2021 19:54:28 +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 10IJs24O032488 for ; Mon, 18 Jan 2021 14:54:02 -0500 Received: by smtp.corp.redhat.com (Postfix) id 566F72166B29; Mon, 18 Jan 2021 19:54:02 +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 5146E2166B28 for ; Mon, 18 Jan 2021 19:54:02 +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 3D3931875040 for ; Mon, 18 Jan 2021 19:54:02 +0000 (UTC) Received: from mail-qv1-f49.google.com (mail-qv1-f49.google.com [209.85.219.49]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-379-unv3jI4EMuS4mc256QO28Q-1; Mon, 18 Jan 2021 14:54:00 -0500 Received: by mail-qv1-f49.google.com with SMTP id d11so8058739qvo.11 for ; Mon, 18 Jan 2021 11:54:00 -0800 (PST) Received: from rekt.ibmuc.com ([2804:431:c7c7:a75a:cb34:ba60:6de6:be1d]) by smtp.gmail.com with ESMTPSA id 16sm11309085qkf.112.2021.01.18.11.53.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Jan 2021 11:53:58 -0800 (PST) X-MC-Unique: 2-gsRtMPN9iXDmfzhX0C6w-1 X-MC-Unique: unv3jI4EMuS4mc256QO28Q-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=Za1EJ+Lsdq3FFNhLRbFiSFlAOVmNJejgjjx//JsgMnjTaqwogFYKalPa4OIOFxw0wc 2ThJbn3Urm8dkxfJBwBK0qkVBJVzj8Ffs7I7igL1dKktqUpbMOLGk1EniL5RcmQkcZMB U+WbcaV5wsjiMdOOsAQu/YnpjoDhdiJfZjVte8c57lDINoYehv14hX3MrjgY42nXI8vg U+KCSSGWzjU3aulRB3h1FDSkUz+bqfIixrU6wixZpq6mOn0aFVKnViR7TndqamMEPjEZ U6v3JfJ5weyZmZUekt8yzGLNTIRKCIFY54/DkMBxYrHwiB79Ah2OMd+WHyHog7/Tuyty W+sQ== X-Gm-Message-State: AOAM531KSKyLOILfzVGS/uzJ5WXMbk4gtI6l2lKikwD0N6GlZpwFnpan 9crzD56T3DpQ7bIPIKjRK5mrZoSS94mkUg== X-Google-Smtp-Source: ABdhPJzZKGbU3MI2vRxauR4yQCs9kXpLntSHnaXOI+cIABsjACq168w7iNUK9X3DS1was7AbDsaxeA== X-Received: by 2002:a0c:bd2b:: with SMTP id m43mr1354079qvg.32.1610999639574; Mon, 18 Jan 2021 11:53:59 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH RESEND 08/20] security_dac.c: modernize hostdev label set/restore functions Date: Mon, 18 Jan 2021 16:53:24 -0300 Message-Id: <20210118195336.2090823-9-danielhb413@gmail.com> In-Reply-To: <20210118195336.2090823-1-danielhb413@gmail.com> References: <20210118195336.2090823-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.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" 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 Mon May 6 00:01:25 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=1610999677; cv=none; d=zohomail.com; s=zohoarc; b=dhRpjYlds3ESHposmiv3M4Kiox54oXSc8WmR5WeP7vkmC7+xqmop7zY1sAq3nVgXbe9XW4r7Ti7bNabkMFwRjuUaYCiaL7LkK2g4hkatCYOVUUm5xJY9E027tP7Hui1TfGIWuzHi1yZ7t+KXAXm/GBTYmVT15Tt3Qm4hJg+fICg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610999677; 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=KWBhR/yrX0zchMDIDlPA4xIigD/+ElXzB45HbW3FIME=; b=dfjuocvUaYr/NHnXu6xA7P2YsBGFbfXUB3X+b5dL1PAln2hFNRovNJ8ZFzx6tWVw+4nxZoqSq4q8eYJdnZMSH4MQ2RG4r/h0xOn/izA3cZyHpOGd2IWyu9R6E/42NKlJRw1PEt5jb30wb6Y9EXKAE4c/juS6xcaX4u7LXXQ68TQ= 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 1610999677343330.7681689638338; Mon, 18 Jan 2021 11:54: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-26-S4dUTL9mP9OEFTJsXLURiw-1; Mon, 18 Jan 2021 14:54:33 -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 3E75C80A5D4; Mon, 18 Jan 2021 19:54:27 +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 1B0F15D9CD; Mon, 18 Jan 2021 19:54:27 +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 D616C50033; Mon, 18 Jan 2021 19:54:26 +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 10IJs7d9032511 for ; Mon, 18 Jan 2021 14:54:07 -0500 Received: by smtp.corp.redhat.com (Postfix) id F268E2166B28; Mon, 18 Jan 2021 19:54:06 +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 ED1C72166B2B for ; Mon, 18 Jan 2021 19:54:03 +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 C7854800161 for ; Mon, 18 Jan 2021 19:54:03 +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-62-8Rf2U5HUPyORLtcmS5ukiQ-1; Mon, 18 Jan 2021 14:54:01 -0500 Received: by mail-qk1-f173.google.com with SMTP id d14so19742197qkc.13 for ; Mon, 18 Jan 2021 11:54:01 -0800 (PST) Received: from rekt.ibmuc.com ([2804:431:c7c7:a75a:cb34:ba60:6de6:be1d]) by smtp.gmail.com with ESMTPSA id 16sm11309085qkf.112.2021.01.18.11.53.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Jan 2021 11:54:00 -0800 (PST) X-MC-Unique: S4dUTL9mP9OEFTJsXLURiw-1 X-MC-Unique: 8Rf2U5HUPyORLtcmS5ukiQ-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=KWBhR/yrX0zchMDIDlPA4xIigD/+ElXzB45HbW3FIME=; b=VZG9UObVvOV2hIcR37hZkw2YsQLlCMDWh5kO+YiLx4te6+tmMR9wdwF0YFtboA0Wlw Vf9eqUvl4vnX5ynpklhlf8RvsGUZSi8OP1OGI+tVaM0Wr+bmZHKQS4c+ak/h7fv5/CJI ltf21rau15XmkvVGCRScSxvlwxQEDRJnci9dXDtZexjWNLnroEsvO/i+illdopM/PE+x nem4dKQTQ41rDk9wfzLiBmoxpdXqIz6ULkv9Jybs09uL1EN+8Im4343MpyLQ/Mg3p+b6 WpZbP0X+FQZ+BU4ETdWlJ3Yh1grzxETkCujZQhDtKXJiMKixP92nQ4zAstdUTyZOQW66 tXGg== X-Gm-Message-State: AOAM533Yedmaadx92k2vIZ1j/5QTRDg1yNU8kjVsdWiUVw8Nzq8JpOq1 XlLlfZXihjC2d0Xeny1zn1xs6+PiHiFJxw== X-Google-Smtp-Source: ABdhPJyshIdH7oqDewjWejkiQ+moPKriTsCwETDp+FFvALuK7oL9cDAibos7vdeFb70hWJGdo+v+YA== X-Received: by 2002:ae9:e308:: with SMTP id v8mr1173938qkf.339.1610999641157; Mon, 18 Jan 2021 11:54:01 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH RESEND 09/20] dac, selinux: skip setting/restoring label for absent PCI devices Date: Mon, 18 Jan 2021 16:53:25 -0300 Message-Id: <20210118195336.2090823-10-danielhb413@gmail.com> In-Reply-To: <20210118195336.2090823-1-danielhb413@gmail.com> References: <20210118195336.2090823-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.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" 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 Reviewed-by: Laine Stump --- 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 99adf08a15..c018c0708a 100644 --- a/src/security/security_selinux.c +++ b/src/security/security_selinux.c @@ -2101,7 +2101,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; @@ -2329,7 +2334,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 Mon May 6 00:01:25 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=1610999676; cv=none; d=zohomail.com; s=zohoarc; b=gUAac3rRDoVfnRZFf2+CKOfi1WkKp9Ymr9aOFt9IYmjfT9jpGw8Me70QafTjMoB+C9Rt9/km0g3Z3GEY1O/6QKfJ6VuguGpPHBvGrUcoyfuO44rWR8waNksmm9aQyCC+vNRgUpklaIQp5YLBrETKmOmmJz1yGy8iIfxcy4DS060= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610999676; 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=N/KKA43vz2ETBl0P3q+w7Z+rCG2mmaaOZDETfjyahq6Td4z4g8ZPUuiNrvB7dO7TYsfD0Pl1ZP2MBU06XqEgLF5MoKUtJWPNTD9LdpxCFfPSkNWQyUAbx3hJLAYF4hvtJSFuEuDDjKt2e2SEV0qQ3nd6JKr7Jf6UX+zpUPbttsM= 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 1610999676557999.744947978007; Mon, 18 Jan 2021 11:54:36 -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-285-TehnZyt3Ofy476J1bwpnsg-1; Mon, 18 Jan 2021 14:54:33 -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 7006780A5C4; Mon, 18 Jan 2021 19:54:24 +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 4D6BF63633; Mon, 18 Jan 2021 19:54:24 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 1BAFA50030; Mon, 18 Jan 2021 19:54:24 +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 10IJs5Ew032504 for ; Mon, 18 Jan 2021 14:54:05 -0500 Received: by smtp.corp.redhat.com (Postfix) id 843562026D49; Mon, 18 Jan 2021 19:54:05 +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 7F8022026D46 for ; Mon, 18 Jan 2021 19:54:05 +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 6BE751875052 for ; Mon, 18 Jan 2021 19:54:05 +0000 (UTC) Received: from mail-qk1-f169.google.com (mail-qk1-f169.google.com [209.85.222.169]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-187-wCVlcIgcM5GBNSeCPtOFDA-1; Mon, 18 Jan 2021 14:54:03 -0500 Received: by mail-qk1-f169.google.com with SMTP id h4so19806495qkk.4 for ; Mon, 18 Jan 2021 11:54:03 -0800 (PST) Received: from rekt.ibmuc.com ([2804:431:c7c7:a75a:cb34:ba60:6de6:be1d]) by smtp.gmail.com with ESMTPSA id 16sm11309085qkf.112.2021.01.18.11.54.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Jan 2021 11:54:02 -0800 (PST) X-MC-Unique: TehnZyt3Ofy476J1bwpnsg-1 X-MC-Unique: wCVlcIgcM5GBNSeCPtOFDA-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=LCK2egEbf6BHFYsYCFVIAmbaWtvZGgnFTKQyUFXyrbjAC5XVSsjzW5mz0lPqoXpOuL NoxrWyjuy8knh9hm0Gy+bsDlYArzW05QvGisNdsSwa0ZywZzjohAs4C0B0PvULFnS+s7 Pn1vhruFoxFQsa4d21/HLsEM5yvUrgXXcE7hxVYAsy8lvMtG5DocFAViiYywFFJTYF7t bDXDqo6moBz5DSNJf3uYc9VUd2UWwmg2SXsTwmGV81W7+oC+legz3VlF4wBYP558lFqj 1RmmU83zA9fX8S2u7o+KDxFu+VlAyw5PWdFV68bIxZQrEmQL808v1++HOXULaYvSQbuj rXLQ== X-Gm-Message-State: AOAM531e6RIuuR/nWvZqDraqR7aaSEz+17sbqUQ9JoWQ/AIwOqk5h9z7 aW+8O+/e05M4pFZud/9wqNkqnqoaXqnKYQ== X-Google-Smtp-Source: ABdhPJyMb1PnJvi4qopSPgHJ5C4sFoEGs6fxcOZEWeVBDRyKlYQxzy7drVbGoSN3fwE077LzQH7Xng== X-Received: by 2002:a05:620a:126a:: with SMTP id b10mr1208171qkl.354.1610999642568; Mon, 18 Jan 2021 11:54:02 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH RESEND 10/20] libvirt-nodedev.c: remove return value from virNodeDeviceFree() Date: Mon, 18 Jan 2021 16:53:26 -0300 Message-Id: <20210118195336.2090823-11-danielhb413@gmail.com> In-Reply-To: <20210118195336.2090823-1-danielhb413@gmail.com> References: <20210118195336.2090823-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.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" 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 Mon May 6 00:01:25 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=1610999685; cv=none; d=zohomail.com; s=zohoarc; b=AcJPhyvq1xruMXqPqnSlPCX/k4/xSD2r5v1hOS74D3yNRq6bASzSTs7klE7dxqdQFTjlWQjyf85TPpyqbB8S/8U1M5bfL3COwoJVpMshCPwWeMC92XzOHCXTqSoWVN92ROI/hm6+IPAv9mhwyxCuh3jaTM7XGTgu1QfFOCwnfrY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610999685; 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=RXEpUj6R80UTqnaahHIsmCpGZa6Z9tksKjbg5FKhESg=; b=R+qB+9Ryt1xBZO2RFLKT8kl5ctg6mCtayvr4iKTZ+wcdwcmd84uRU2zS4szK8YolJWpcdx6UO+U59RzB6lpiR8SHE8oMlnnVsnfnUwSxFNtFA30PFg4mKjxSjoK+h2S2/NFM5q3oPD2ANO6a4GIVC4xttUgLhhAUGnoEbx5HaoQ= 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 1610999685596626.8948003973344; Mon, 18 Jan 2021 11:54:45 -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-73-Rd1vKBEoOoe5Z0WtIM8FQg-1; Mon, 18 Jan 2021 14:54:42 -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 828AD1005D51; Mon, 18 Jan 2021 19:54:34 +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 60BCA5D9D7; Mon, 18 Jan 2021 19:54: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 2EACD5003D; Mon, 18 Jan 2021 19:54: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 10IJs7J2032520 for ; Mon, 18 Jan 2021 14:54:07 -0500 Received: by smtp.corp.redhat.com (Postfix) id 4FC752026D49; Mon, 18 Jan 2021 19:54:07 +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 480F02026D46 for ; Mon, 18 Jan 2021 19:54:07 +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 34994101A561 for ; Mon, 18 Jan 2021 19:54:07 +0000 (UTC) Received: from mail-qv1-f52.google.com (mail-qv1-f52.google.com [209.85.219.52]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-73-vVGKukESPNG_5jGm3mrsUw-1; Mon, 18 Jan 2021 14:54:04 -0500 Received: by mail-qv1-f52.google.com with SMTP id h13so8089865qvo.1 for ; Mon, 18 Jan 2021 11:54:04 -0800 (PST) Received: from rekt.ibmuc.com ([2804:431:c7c7:a75a:cb34:ba60:6de6:be1d]) by smtp.gmail.com with ESMTPSA id 16sm11309085qkf.112.2021.01.18.11.54.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Jan 2021 11:54:03 -0800 (PST) X-MC-Unique: Rd1vKBEoOoe5Z0WtIM8FQg-1 X-MC-Unique: vVGKukESPNG_5jGm3mrsUw-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=RXEpUj6R80UTqnaahHIsmCpGZa6Z9tksKjbg5FKhESg=; b=bgSGwKUlfIhnITpbB19uQo0v+wbx9unSGine7xx5ULiTXL/43rTqnRJyHV7kBmlB7A 1FjMAW9cr4xDkoqzjynMb+1rTifJHp2OkoP9F3+MyJaBFH03V/NL5PJGFJCtyK9Fxbk+ F+KxQKxhvjVsiOle3qIIKbD0HI6Ql+i7pGdRQIHSRoDrl4jABaeDJmDLFL6aA+LbiT69 UEyj5jA0o5vdyMvJhIk0RZS0g72YjQpgHO6JMEfbR41qSIs4OsYWVyEsq278OhHQ16hF Kl70804a7d6pLrjsPltx/ibHCPICcJ752ciV8cOFSKk7q7xZDk+D955gLR+fMNVEaYa7 Vtjw== X-Gm-Message-State: AOAM531kUspQzfUCyih13+whGKysH535tfuN/GpZ3xJkuQUfeMeaDgow WHqA1BqxEBouElMaRIbT2zHQ3B6Qw5JeNA== X-Google-Smtp-Source: ABdhPJzkHD03PtGHfly902VQ7d3py7lwBAJ+Dv1jjG7jsPTh6i3l1pU+DesIOGoa53u2NkJ7Hxzmgw== X-Received: by 2002:a05:6214:321:: with SMTP id j1mr1379287qvu.32.1610999644039; Mon, 18 Jan 2021 11:54:04 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH RESEND 11/20] qemu_driver.c: modernize qemuNodeDeviceReAttach() Date: Mon, 18 Jan 2021 16:53:27 -0300 Message-Id: <20210118195336.2090823-12-danielhb413@gmail.com> In-Reply-To: <20210118195336.2090823-1-danielhb413@gmail.com> References: <20210118195336.2090823-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" Add virObjectUnref an autoptr cleanup func for virNodeDevice, then remove all unref and free calls from qemuNodeDeviceReAttach(). Signed-off-by: Daniel Henrique Barboza Reviewed-by: Laine Stump --- 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 7581e3c8cb..f9aa93fa3e 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -12045,17 +12045,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 @@ -12063,36 +12062,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 Mon May 6 00:01:25 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=1610999688; cv=none; d=zohomail.com; s=zohoarc; b=FZB7DD2dkbgvZmZ9ToOfuq+FF54rjdzgLNmnwCEfbYAVk0FHlJy/XHeNFJ+lKz2x4PToaSsh4QV1XbF6s+PZPUkrJVti47aN34AFZnr/Ex/OHzIakdYnZm/6IMmkydfikH8IBbXBTRqFJUzLs8N3K8b1UEC+Cu11938W1AbxLvc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610999688; 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=DAUwvkLPLgs8kyvOQ2pLJoFVWNA+dNDDKYN6xT1vjD8=; b=BKslGyiz8JWffxsZTzYemXmoRDemFNuNLX8zfP+RCIhxv6lngXN8BMZE3SLMhknaLDqp0Rd00kNW0z5Gs36YJ5ncwgNA9IZFdscHQeR6ssc5QmcnnHbfjZWW7/GflVbo0zW21wD3KYVROwuivK8xJjSImCGosxSTFvdFZAALMQk= 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 1610999688797200.5886615403988; Mon, 18 Jan 2021 11:54:48 -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-529-WowP4ySDNmOHJyZ1-36RRQ-1; Mon, 18 Jan 2021 14:54:44 -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 5AC99800D53; Mon, 18 Jan 2021 19:54:37 +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 34A4210023B4; Mon, 18 Jan 2021 19:54: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 F1C8F50044; Mon, 18 Jan 2021 19:54:36 +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 10IJs8bA032534 for ; Mon, 18 Jan 2021 14:54:08 -0500 Received: by smtp.corp.redhat.com (Postfix) id 952412166B29; Mon, 18 Jan 2021 19:54:08 +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 900202166B28 for ; Mon, 18 Jan 2021 19:54:08 +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 7B186800161 for ; Mon, 18 Jan 2021 19:54:08 +0000 (UTC) Received: from mail-qt1-f179.google.com (mail-qt1-f179.google.com [209.85.160.179]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-418-nTOGV-YQNFOV8p0i2ggewg-1; Mon, 18 Jan 2021 14:54:06 -0500 Received: by mail-qt1-f179.google.com with SMTP id z9so2203549qtv.6 for ; Mon, 18 Jan 2021 11:54:06 -0800 (PST) Received: from rekt.ibmuc.com ([2804:431:c7c7:a75a:cb34:ba60:6de6:be1d]) by smtp.gmail.com with ESMTPSA id 16sm11309085qkf.112.2021.01.18.11.54.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Jan 2021 11:54:05 -0800 (PST) X-MC-Unique: WowP4ySDNmOHJyZ1-36RRQ-1 X-MC-Unique: nTOGV-YQNFOV8p0i2ggewg-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=DAUwvkLPLgs8kyvOQ2pLJoFVWNA+dNDDKYN6xT1vjD8=; b=GtlGRRoS2r8YNEPHVh3raVHW5ahDoAcFROy1xKhXOsgWkwiSxfnh8XFt1yzsGtFfoo PtW8v5pa7DEM89rTPYxVmviIKNXcGXoTiDqM0B2YlgNqxZE5su7Ijlxx7+S+7AROCvgK Pi6AEepjZX7wtNZ5OjGyM5nUhdtXqXL/hHUlq0YSEGK6odYGo3IBtPwE8DQZDgr7W2ZO hbnTwF4yCyDIAGMgfAawosksZ6fOrD8jUqV5OqJ5nd7SC3Q9t+Ug5Ky7duNR6r7tqAxB 2tDALC0mFYXHQHohAgB7inqZ+XMf5pS/CduSSqvlGks9qiwDmknIlbjWqxWEYy/8FUc5 cUnw== X-Gm-Message-State: AOAM533pDs/+qfCGzm34dj4vmhUiwTJc5vTqm7Xq/R6wljPrpNwXUPPz 5DEzyhqjgJwPGhmA64L3qkfJ312vOBYlkA== X-Google-Smtp-Source: ABdhPJzK+8xqi5UNQZdivVW/4RbHy7MAHRmU124WLk9H4mQXJ6Sv68OD8JDjhaQcy3eAZJ3oMswNaQ== X-Received: by 2002:ac8:6edd:: with SMTP id f29mr1174784qtv.213.1610999645522; Mon, 18 Jan 2021 11:54:05 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH RESEND 12/20] libxl_driver.c: modernize libxlNodeDeviceReAttach() Date: Mon, 18 Jan 2021 16:53:28 -0300 Message-Id: <20210118195336.2090823-13-danielhb413@gmail.com> In-Reply-To: <20210118195336.2090823-1-danielhb413@gmail.com> References: <20210118195336.2090823-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 3eaf106006..fbb67e9ed6 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -5852,18 +5852,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 @@ -5871,40 +5870,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 Mon May 6 00:01:25 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=1610999705; cv=none; d=zohomail.com; s=zohoarc; b=bi9ffDQ8sf4ZXEtraP193vBDiIb0WnYKcAFLkmnhhb67XYcnhmvT56E69vk5CVIpYal+13UCA93OpnipDYeEyDGJ97hAKxf7+kC5wv0qhUF4i7xZn2+AVX6uh2M26KAVrtWrkZhYgHtdPkrW1L3QiSmiVmY5vALpsyRTQ0F+jHM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610999705; 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=9mWesCcSlIeAhjIb4IgM1f6nY5aoZZbIIKE5Q5olxps=; b=hp77giSecSweBfRD+IMBlESrJI09DNDpmDO/k1J5Qz5uOzmq3YiCrOqslKgD716ZMQbPZEqJM2UUrj9lcHheyDZ1IZoo5MDkj0XmyEMoCFRTICScl7QVt7X1XboeDh3jBE+T1ce4bFbJEmi+PPbt2zWuOJtSKLfwGkoeod5zuww= 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 1610999705236587.0547005484996; Mon, 18 Jan 2021 11:55:05 -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-475-Vgj89nn8NheXJY4JMjuqqA-1; Mon, 18 Jan 2021 14:54:40 -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 0A6E91005513; Mon, 18 Jan 2021 19:54:30 +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 DEB225D9D3; Mon, 18 Jan 2021 19:54: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 A954F50039; Mon, 18 Jan 2021 19:54:29 +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 10IJs9Qx032539 for ; Mon, 18 Jan 2021 14:54:09 -0500 Received: by smtp.corp.redhat.com (Postfix) id B04C91111439; Mon, 18 Jan 2021 19:54:09 +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 AC63A1111434 for ; Mon, 18 Jan 2021 19:54:09 +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 98450800161 for ; Mon, 18 Jan 2021 19:54:09 +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-410-yIelGElyNPifMO_f1JAX_w-1; Mon, 18 Jan 2021 14:54:07 -0500 Received: by mail-qt1-f175.google.com with SMTP id h19so12087533qtq.13 for ; Mon, 18 Jan 2021 11:54:07 -0800 (PST) Received: from rekt.ibmuc.com ([2804:431:c7c7:a75a:cb34:ba60:6de6:be1d]) by smtp.gmail.com with ESMTPSA id 16sm11309085qkf.112.2021.01.18.11.54.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Jan 2021 11:54:06 -0800 (PST) X-MC-Unique: Vgj89nn8NheXJY4JMjuqqA-1 X-MC-Unique: yIelGElyNPifMO_f1JAX_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=9mWesCcSlIeAhjIb4IgM1f6nY5aoZZbIIKE5Q5olxps=; b=rAfGEnxa8ofOZHSiYjoXxUiqNgoaVOO5qvGlh4py6Ik8y8o3A8p78OUox4VDNqnTQZ 8OWUCOrfRoMISXdexZAczi63iDXvJlNTcmpcL7xSWNsoG+PllWuWuSb3aHCiwT96z+CS btupOWwLOoALChL+q7EZszykbwKTbUOSdomvUlP00OC6tU98zrXU8VvJCDW1wrngGFDr +NneWlkKLq67Z2DUg7Ni7GrbG6QdQCozoxPU9ijZlN3IKMdzMfUfLi2hl0hxEs750v5N AxIgtzfEC2pzMlVuaON1guopBHUwqUkKX0gC2V1rBb29SZ6pfUx7POsHIkINbeDrn8d6 XpKA== X-Gm-Message-State: AOAM533D39sP0UcSCiQzZB64m0iNqazPftYANubqvoSdmaApPRuBFpQ0 KksFrBgqFldyCpMrrBuUCbmIN/5HuaypIw== X-Google-Smtp-Source: ABdhPJx6pgigkbwMvo9GkU+fpYfwaa48TH2SHsW5GUoi4rD2UpJMNx/V0wVthpT0+SBQQZ0WHas+QA== X-Received: by 2002:ac8:4553:: with SMTP id z19mr1209915qtn.278.1610999647048; Mon, 18 Jan 2021 11:54:07 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH RESEND 13/20] virsh-domain.c: modernize cmdDetachDevice() Date: Mon, 18 Jan 2021 16:53:29 -0300 Message-Id: <20210118195336.2090823-14-danielhb413@gmail.com> In-Reply-To: <20210118195336.2090823-1-danielhb413@gmail.com> References: <20210118195336.2090823-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.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" 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 Reviewed-by: Laine Stump --- 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 2bb136333f..b32529f073 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 Mon May 6 00:01:25 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=1610999689; cv=none; d=zohomail.com; s=zohoarc; b=e39LJ2KTYCQ6Dcm+ay4kTty3ksxfKvv0bEKoesQbM4zSONv0U9Zaiun2ncbYVd7qJLhzPYxoVW/Sn3zVQwpeqSeOcd4TCbc4ExvcdccTuHTVLwHS5q4wDeReBAzIly+y7cp6kuZOfrXsNL1A3nd/Fb/7zh10/ayPqeZ702chmpU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610999689; 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=W9k3q2LPOCz9xY/BVCWkh40aMNMV9imfbaHhatDNGNM=; b=ZGah2dLhRdboicxxhS8jiMD8OEqLHEIxQWlS6ByP3ZBvvdXlUZkBOJ5m2LUtFVr4yH/9S9/NaaPVSRu4xWUFR+/2/OKEy2NPm6o3LMLTttHp0AOMvbpQ4Oqk0jUO4cTu9b6B0OQ6w808uii14rQZVQWk/nzFOzQdsPGfZH/3rtM= 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 1610999689081685.8822027203903; Mon, 18 Jan 2021 11:54: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-512-d6czZrYgOZK5ft044snzYg-1; Mon, 18 Jan 2021 14:54:45 -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 20ABC107ACF8; Mon, 18 Jan 2021 19:54: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 F217760C75; Mon, 18 Jan 2021 19:54:39 +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 BEB1D50047; Mon, 18 Jan 2021 19:54:39 +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 10IJsDFm032572 for ; Mon, 18 Jan 2021 14:54:14 -0500 Received: by smtp.corp.redhat.com (Postfix) id BDD0C2026D11; Mon, 18 Jan 2021 19:54:13 +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 B857E2026D46 for ; Mon, 18 Jan 2021 19:54:11 +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 5562880120A for ; Mon, 18 Jan 2021 19:54:11 +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-187-6A39ddFsNviTkmaQFomsWw-1; Mon, 18 Jan 2021 14:54:09 -0500 Received: by mail-qt1-f181.google.com with SMTP id e17so3001358qto.3 for ; Mon, 18 Jan 2021 11:54:09 -0800 (PST) Received: from rekt.ibmuc.com ([2804:431:c7c7:a75a:cb34:ba60:6de6:be1d]) by smtp.gmail.com with ESMTPSA id 16sm11309085qkf.112.2021.01.18.11.54.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Jan 2021 11:54:07 -0800 (PST) X-MC-Unique: d6czZrYgOZK5ft044snzYg-1 X-MC-Unique: 6A39ddFsNviTkmaQFomsWw-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=W9k3q2LPOCz9xY/BVCWkh40aMNMV9imfbaHhatDNGNM=; b=BMRwER9y4PgzTrIteLhU2wisAuvwhFygFLrR0uihDPfnakIy78rvB7jQIMSPAbuSKz GPE5ISWSKARTEegNWugcqYp/hK0qNwFGkuqOqqmAxiUUoCQ01JZTZQY29tBwlUGreLfj R6IHg3uv9WFSbYTYsQvRxUHZAPbPi/g5it3yV86noTbEau3S4M5LtOOVZTMMjTa6vLH5 o8JrZh3awRHq2vn8wZCB4zWISf9ZaDloEnfVAv8z9DgS7jKa3aG65Jd6y3rii7u47AK9 j1uuJCdORhOnCV0QTfs28g+fQAUnb8TMMZ4uodV2ggVbuAJlgUudJkXMJ3BPi2JDy/d+ CZtQ== X-Gm-Message-State: AOAM533R3L4Z4VSEs42Cn2KirArD+CvsD/yDVVnxn+zihETlmTr2d6pR aTiJN4Nz2V81K9T20Tq4bBKTFT/Ygzw0yg== X-Google-Smtp-Source: ABdhPJwyT+u6sPmVcrWAn8/k+ZlJZrQD7gXyEZXrtLnGEJBzQwDta4o52XuCWzd6eCBryT5CalxiKw== X-Received: by 2002:a05:622a:1c5:: with SMTP id t5mr1199210qtw.129.1610999648525; Mon, 18 Jan 2021 11:54:08 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH RESEND 14/20] virhostdev.c: add virHostdevIsPCIDevice() helper Date: Mon, 18 Jan 2021 16:53:30 -0300 Message-Id: <20210118195336.2090823-15-danielhb413@gmail.com> In-Reply-To: <20210118195336.2090823-1-danielhb413@gmail.com> References: <20210118195336.2090823-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 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 Reviewed-by: Laine Stump --- 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 dbba36193b..402d7be42d 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 36635e6de7..01fc50b687 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 Mon May 6 00:01:25 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=1610999705; cv=none; d=zohomail.com; s=zohoarc; b=WhWm5Lh+SqJgh+fhBfMy32zPjmjJoYdoDFeYTotyLOftAM33sb6EelThbJ2Dpvw8zv0IxbGxwV/6gLjOHUL5aBViBMN0pyU/ogNWAyPsdTKqgSJY0/FODt0KHwvAsguySknkNAloS94ez4zpp3v8Shz1Mdk4iNzN9JlFavJ3IT4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610999705; 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=imqx0QVxFyAaoMNop/p8HxPSnsBQKWo++dMrKaVac5RhZRve3ZUBOLHlt/YEZWUiLWxlGNg8RMTu0Gb125t2vrO98Fu0v7mjL7asq8X0mhHrWEitIKKUFvDnt2C6G971VCHtOYmz4tRlAQwHZ2LGcUQVhXqZ3XNKeTFgUTvp4jg= 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 1610999705035279.4049359647689; Mon, 18 Jan 2021 11:55:05 -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-223-_gUW5A7DO7GrZZyI9WdMxQ-1; Mon, 18 Jan 2021 14:54:43 -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 AAC5B1005D63; Mon, 18 Jan 2021 19:54: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 8773D5D9D7; Mon, 18 Jan 2021 19:54: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 53D835003B; Mon, 18 Jan 2021 19:54:32 +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 10IJsDIg032573 for ; Mon, 18 Jan 2021 14:54:14 -0500 Received: by smtp.corp.redhat.com (Postfix) id BDEB22026D12; Mon, 18 Jan 2021 19:54:13 +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 B87C82026D49 for ; Mon, 18 Jan 2021 19:54:12 +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 831A0800969 for ; Mon, 18 Jan 2021 19:54:12 +0000 (UTC) Received: from mail-qt1-f173.google.com (mail-qt1-f173.google.com [209.85.160.173]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-200-4LtQgpx2MH2PHIEvsWLgmA-1; Mon, 18 Jan 2021 14:54:10 -0500 Received: by mail-qt1-f173.google.com with SMTP id r9so12119269qtp.11 for ; Mon, 18 Jan 2021 11:54:10 -0800 (PST) Received: from rekt.ibmuc.com ([2804:431:c7c7:a75a:cb34:ba60:6de6:be1d]) by smtp.gmail.com with ESMTPSA id 16sm11309085qkf.112.2021.01.18.11.54.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Jan 2021 11:54:09 -0800 (PST) X-MC-Unique: _gUW5A7DO7GrZZyI9WdMxQ-1 X-MC-Unique: 4LtQgpx2MH2PHIEvsWLgmA-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=gK3nVGhLFj14wP5TCz5Ka56eSSm7O67fc5/GR2S3ixtBl+KMOJsWZlK2XqIum66VI4 Q5cBOLqsMw2RpWZ+PWf5BG7ronFeuOvQYZoceNGZtE+h4sK3i1ezsNWextc5ARLr8nLk 1ZML3DoRFuFvq8bqVlK/yR89SYlX6DvxOSkxcy43AKTJ/+K6M5YK2I6Xo59oihtOAayQ 8/xXHaiSjcsWb6py64vMDwmnlSlrvI+Up88Xv7o0yDPOzXOe7aBg01/wB4tNKyBqONCQ N/RQtmSwo/cxNtxu+QLS596G85G8EXnwxY4b1NAJMAjXneJrx5Lyv7IHC6r6YrT12apI ak6Q== X-Gm-Message-State: AOAM532lZlA2HqV5aOErDvorfCGhDdBMp5Yco0SpZl77iZgHNADsad7i hbqLK6jl+goh7MNDIyso7Lb5uPHl/3D5YA== X-Google-Smtp-Source: ABdhPJyW6wC6LSytr+RUtFmoZtxvvZNWSuLjdw4T6+pocrANtZKhouoZvwHNNa0lYZbKYW5Xu3VKSA== X-Received: by 2002:aed:3b24:: with SMTP id p33mr1157094qte.299.1610999649976; Mon, 18 Jan 2021 11:54:09 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH RESEND 15/20] qemu_cgroup.c: skip absent PCI devices in qemuTeardownHostdevCgroup() Date: Mon, 18 Jan 2021 16:53:31 -0300 Message-Id: <20210118195336.2090823-16-danielhb413@gmail.com> In-Reply-To: <20210118195336.2090823-1-danielhb413@gmail.com> References: <20210118195336.2090823-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" 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 Reviewed-by: Laine Stump --- 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 Mon May 6 00:01:25 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=1610999692; cv=none; d=zohomail.com; s=zohoarc; b=Hdgg3+jx53Gni71Z57V0YaiVlWbVdu01MVD86ijFIJQKeJtxaOhNvrWTcI1u7no/aYhkFoFgRT0f/uHawoihB3iECB5+9N0tus0z0PCZk219xBzFBuRHgNKtlDf3T8/vFjxvNYzQGPfahIS/neYoIBqGbYEYMNkBCos49fJwrWo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610999692; 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=AGS754Fcl6tTJ1DAiiiCVizLey0bqGvMTusOYCKAojo=; b=Xy22CP19GWmMday6ZoL45Utd5RCXZ/V0FymLl0l5W/WoIUyoTSB9fqRFbrUOj8SNqDi/YbuDwgNlWBsoPF9Wwq5W2qt7MBqAtnL5AR3srCQathrOtNrFcMHdU3XqK1ipGZWrNdDh/fNqDxTTgMEbThrQaM3Iae0YCenOr6/+unA= 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 1610999692266356.33206175629505; Mon, 18 Jan 2021 11:54:52 -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-263-iBsy5vLoOwW6mjR3T3aUWg-1; Mon, 18 Jan 2021 14:54:49 -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 BD7B6E757; Mon, 18 Jan 2021 19:54:42 +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 96B516A8E9; Mon, 18 Jan 2021 19:54:42 +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 5778D5004A; Mon, 18 Jan 2021 19:54:42 +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 10IJsFaI032596 for ; Mon, 18 Jan 2021 14:54:15 -0500 Received: by smtp.corp.redhat.com (Postfix) id 8ECDF2026D11; Mon, 18 Jan 2021 19:54:15 +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 89DC12026D49 for ; Mon, 18 Jan 2021 19:54:14 +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 38E3A858280 for ; Mon, 18 Jan 2021 19:54:14 +0000 (UTC) Received: from mail-qt1-f171.google.com (mail-qt1-f171.google.com [209.85.160.171]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-356-xvelToM0PUqo34fME6xavg-1; Mon, 18 Jan 2021 14:54:12 -0500 Received: by mail-qt1-f171.google.com with SMTP id j26so12115576qtq.8 for ; Mon, 18 Jan 2021 11:54:12 -0800 (PST) Received: from rekt.ibmuc.com ([2804:431:c7c7:a75a:cb34:ba60:6de6:be1d]) by smtp.gmail.com with ESMTPSA id 16sm11309085qkf.112.2021.01.18.11.54.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Jan 2021 11:54:10 -0800 (PST) X-MC-Unique: iBsy5vLoOwW6mjR3T3aUWg-1 X-MC-Unique: xvelToM0PUqo34fME6xavg-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=AGS754Fcl6tTJ1DAiiiCVizLey0bqGvMTusOYCKAojo=; b=CbSg3+gZhTeGTFSuCfGxEGhaQrq0aN/2vzizKa9xRrrqyKUr28yvMZTROw/knT2tmz RPp4OSY2XZ+Ant5uG+LlRqkYnucWNSpvMlTXsL8h+haCe7iAI10FZVX6k6fTjx4LMADj vDJiI45CU1qw4lbzztWJ52uruQau2xlMnkFEPBNefkFjdPVjBLW1EmCsphE6wD0U9QQ4 qRvCgIXLwEU7+PZE1qoWFAZcLr1gbN0Www9AdSZeKMPSCataE8iPsl8UxiLOUe/QVZYG WwSsprLzoMxXlV2DjpGWYqy/VI1GVd60VcaTEzlCYwKPYFWn4fqbxrkqymHbkGqpRWCB IL1A== X-Gm-Message-State: AOAM532OkiAW6Osa6kLaDi8pchWkwuj1XYTsdl5zTsdyw6aDc93S/glP GmMq8pCMKHq9lk8GPOKqfENiIkuAvxT2hw== X-Google-Smtp-Source: ABdhPJzAhWG4FQb2u5xRnd2pSiVqwxly4GKj7Wdu7Z9TWLzX78o98VRuH8Fe6GmpPFu9Pqre3PyOgw== X-Received: by 2002:ac8:7655:: with SMTP id i21mr1146815qtr.315.1610999651562; Mon, 18 Jan 2021 11:54:11 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH RESEND 16/20] virpci.c: use virPCIDeviceAddressPtr in virPCIDeviceListFindIndex() Date: Mon, 18 Jan 2021 16:53:32 -0300 Message-Id: <20210118195336.2090823-17-danielhb413@gmail.com> In-Reply-To: <20210118195336.2090823-1-danielhb413@gmail.com> References: <20210118195336.2090823-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.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 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 Reviewed-by: Laine Stump --- 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 7143380348..1554acffb6 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 Mon May 6 00:01:25 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.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 170.10.133.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=1610999677; cv=none; d=zohomail.com; s=zohoarc; b=AEabrVd4dLqK6eWkzv40BCezHm3gNIrnX6LVew3G1YjsnQdSxUMH2kxd958AES9srQwzf3IYSFLc0tvskZ0Sp6Z+fOaFo+mnl1y42Iy32+/5rMDVaNxieEv2xiXF5mib22nNPeUeo6d7V8HVY/4TrPmjF0DQq/E9FVGLIdGYR7s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610999677; 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=a4fkQ8uTLpm9Iz+mfj61nkPI1HqeO22VaZwKSsuBe4A=; b=dFO8ddSwQfNJVQIaUV3NVlX7AvpaaPkrHUtqv3rQ3OKhDgm9ibT6lqMBnaE4b5KqrRKbBR7YFMb8XCmBNdogAsGssfe6LfXbtZWLlflGPWwZy6IRKJi3K4Fj1CtfnwKW+4u8KjitCs4TpmFVrRYJwBEaOWfJLh9+AvtDfRilvyg= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.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 [170.10.133.124]) by mx.zohomail.com with SMTPS id 1610999677392808.2918202110113; Mon, 18 Jan 2021 11:54: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-12-iPLVCANXM_SFS1XmPp2OUQ-1; Mon, 18 Jan 2021 14:54:34 -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 4D452180A09B; Mon, 18 Jan 2021 19:54: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 2C4E35D9D3; Mon, 18 Jan 2021 19:54: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 EC7751809CAA; Mon, 18 Jan 2021 19:54:27 +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 10IJsJW2032643 for ; Mon, 18 Jan 2021 14:54:19 -0500 Received: by smtp.corp.redhat.com (Postfix) id 338881111439; Mon, 18 Jan 2021 19:54:19 +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 2D2B2111143C for ; Mon, 18 Jan 2021 19:54:16 +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 E8DAF187504D for ; Mon, 18 Jan 2021 19:54:15 +0000 (UTC) Received: from mail-qv1-f45.google.com (mail-qv1-f45.google.com [209.85.219.45]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-359-iSXIyJlkMKmnYmlIARa6GA-1; Mon, 18 Jan 2021 14:54:14 -0500 Received: by mail-qv1-f45.google.com with SMTP id h1so8050227qvy.12 for ; Mon, 18 Jan 2021 11:54:13 -0800 (PST) Received: from rekt.ibmuc.com ([2804:431:c7c7:a75a:cb34:ba60:6de6:be1d]) by smtp.gmail.com with ESMTPSA id 16sm11309085qkf.112.2021.01.18.11.54.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Jan 2021 11:54:12 -0800 (PST) X-MC-Unique: iPLVCANXM_SFS1XmPp2OUQ-1 X-MC-Unique: iSXIyJlkMKmnYmlIARa6GA-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=a4fkQ8uTLpm9Iz+mfj61nkPI1HqeO22VaZwKSsuBe4A=; b=PXePmZ7X49CEX2z6lcIW8g69MHXPZVajmWaDv/GOMpJZ+xG2crozkqWjoKSZ9vIB3L Znbta/IC7rVSTGu/S5Qtg2auvkO2Vxhlsgxj+iJRDPAmgrbQ4ECFyWq+/c/qSWNhgqeo 2AWR8n/pYPfd0yuEjdD8bJ+Qpedo5DOJjE/idTZ8H151yYV+NOxf01hhAOHiBVCQZen6 T/4OYKSpkZ1aEHR/zFzramBp//3copperBJUkNIstxEdmYFzFseW130XzejtITSOnKj6 99YfLeZEeYnEaY4QpWNsx2jPkhAaalufIhxG9uySNzYHSbhaVLnFX9Ef8M2gXc4qPNgT 34XQ== X-Gm-Message-State: AOAM533G4FzCRJKg7H8i47GLP/PVad2QWuWaheszBt3/zd0LPZBkams3 emS6SH1rpcoDFyXztZolMp+zPEFJh+zSMg== X-Google-Smtp-Source: ABdhPJwlLBBNGq7FgHVry+WxJ7QtWKAw51xq6pKsR4T+x/D/L9ezlHhnEzVX0hLA4uDW8ix23Si7tg== X-Received: by 2002:a0c:a789:: with SMTP id v9mr980810qva.41.1610999653171; Mon, 18 Jan 2021 11:54:13 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH RESEND 17/20] virpci.c: use virPCIDeviceAddressPtr in virPCIDeviceListFind() Date: Mon, 18 Jan 2021 16:53:33 -0300 Message-Id: <20210118195336.2090823-18-danielhb413@gmail.com> In-Reply-To: <20210118195336.2090823-1-danielhb413@gmail.com> References: <20210118195336.2090823-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.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" Signed-off-by: Daniel Henrique Barboza Reviewed-by: Laine Stump --- 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 402d7be42d..3bfb04c674 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 1554acffb6..9544275c31 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 Mon May 6 00:01:25 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=1610999705; cv=none; d=zohomail.com; s=zohoarc; b=Rt9kcmlYMKH7Q2s8gH2uRdTunIwNp6W5Q5Wxz5iwQ6Zi1NqQe9RKgJsW/8ZpSQRfnW74a2AeSkxu7ei0968jWctX9Xv8s58YZWATZHarq1LYqLJe/Kox0fVGRosT4HGNo5gQpKYV+4cVqCDfsnb2RcFsNOjixwEsa1f9Kfa2jPE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610999705; 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=mLxLQsjIyz8HdC9M4WZsqIEgZwpWhe94zoLYYMExaAk=; b=mSJSoqXAguRbs1CMuKhTmpK/qaUhK5VlmuFppmuEKRATxuU68ly5bKXTQdFhgGNZffLsGKT4lgMRYab+i/+d2e0L1OgLJuVHQ7bsaQn8AJXWJYDw76nUc53ScUU+TVhgQ8xXGTFMBBdPQdkV9DWAFbqkI8I76jwLMtTrUg4lFcw= 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 1610999705238120.218832509089; Mon, 18 Jan 2021 11:55:05 -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-385-on8CXbsENZKBeJ3JfVxspQ-1; Mon, 18 Jan 2021 14:54:42 -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 5A30D1005D44; Mon, 18 Jan 2021 19:54: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 391075D9D7; Mon, 18 Jan 2021 19:54:35 +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 01E1A50041; Mon, 18 Jan 2021 19:54:35 +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 10IJsH6i032615 for ; Mon, 18 Jan 2021 14:54:17 -0500 Received: by smtp.corp.redhat.com (Postfix) id 539042026D16; Mon, 18 Jan 2021 19:54:17 +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 4ED6A2026D11 for ; Mon, 18 Jan 2021 19:54:17 +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 3B7581875040 for ; Mon, 18 Jan 2021 19:54:17 +0000 (UTC) Received: from mail-qv1-f52.google.com (mail-qv1-f52.google.com [209.85.219.52]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-403-k7Lmv9G0OVCsA-SNVHamZA-1; Mon, 18 Jan 2021 14:54:15 -0500 Received: by mail-qv1-f52.google.com with SMTP id h1so8050261qvy.12 for ; Mon, 18 Jan 2021 11:54:15 -0800 (PST) Received: from rekt.ibmuc.com ([2804:431:c7c7:a75a:cb34:ba60:6de6:be1d]) by smtp.gmail.com with ESMTPSA id 16sm11309085qkf.112.2021.01.18.11.54.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Jan 2021 11:54:14 -0800 (PST) X-MC-Unique: on8CXbsENZKBeJ3JfVxspQ-1 X-MC-Unique: k7Lmv9G0OVCsA-SNVHamZA-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=mLxLQsjIyz8HdC9M4WZsqIEgZwpWhe94zoLYYMExaAk=; b=FQMnk4JV3OFOHAwHYgnu6IpApwk81CYyG52GYOlsPhE2u4H9AmNP56c3bCOcBCtXEe +aATw0pNGKUYmA59Qz9eUGhJKpqgUkPxlRNcBsQcrJNBbBJeIiyQ+rNjagydKImUmTon ujLpZw4RF1V058Ykd3Z/byjDvbCaZ08g8DKCmnti+dEgX2AINXnMDquCsTZqvrMGyG7/ GoWIYedJKm/DJcBFg14NA6zXWAsiGohqf1eaHy+xajCzuOmyeKYQ5XI4C20oL/Ru1xy/ m7/K1h4wYfKkldWp0isBOIPW6dvbXjmf15lWcpIJsn37emF3mLyh+7QzUNUlsKoVkdKS tIZw== X-Gm-Message-State: AOAM532kjhrX/e62Vqi1lg2Qykn/sH/KciZDuKp7yOZ0QABAxugicMNM LlBpMvy8ssH15wPaPYuD8C3NQ14TK16eAA== X-Google-Smtp-Source: ABdhPJxlGgDepQ4bx9XQidEa7yKIb/26lKOXrunsU/ncUD8dQRUIS8yzAaU1WEp0uxYNoRcokDPsLA== X-Received: by 2002:a0c:f601:: with SMTP id r1mr994608qvm.39.1610999654647; Mon, 18 Jan 2021 11:54:14 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH RESEND 18/20] virpci.c: use virPCIDeviceAddressPtr in virPCIDeviceListSteal() Date: Mon, 18 Jan 2021 16:53:34 -0300 Message-Id: <20210118195336.2090823-19-danielhb413@gmail.com> In-Reply-To: <20210118195336.2090823-1-danielhb413@gmail.com> References: <20210118195336.2090823-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" Signed-off-by: Daniel Henrique Barboza Reviewed-by: Laine Stump --- 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 3bfb04c674..4042f874d6 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 9544275c31..332e681c43 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 Mon May 6 00:01:25 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=1610999694; cv=none; d=zohomail.com; s=zohoarc; b=FWKmAToj9PMHR5izD+UFNpD9UOIdPCMDf0Y87h2YlKSSXQAJ2z3mPOKLWt6cN9S0HpPpHaM7FrlJ7jz31zjR0RGGvjDdIEPRLLArbtsUit/o3rH0Sd7otzRO1yaR7OvNMYeyQA9PSDsKcfWsnKeARKNgqtdhvKG8uWoDwKwkMyg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610999694; 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=gosnU1ZfOoPuzn8m+Da2mtmkvv9fOhCjLWrNcgsz548=; b=AeCZ4C+1Ez0qK9bngbrSEAm/j0Ts32lRPMqsILxCrHRfj70wwbTSCQ1PbzJ5AQFa5Njh5u+Q6P0KGXs82fDFYaCn2krb/9k8+vspF/mzyVxn5xrUUIiN9OH624TaR3TmncBXRAxi3cYmo6K4Uu+78XFb6mW223hX61AExQfr2rA= 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 1610999694377749.7560518098664; Mon, 18 Jan 2021 11:54:54 -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-541-eoVHBUWhNeyoG-ajnRamUQ-1; Mon, 18 Jan 2021 14:54:51 -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 61B8D802B4A; Mon, 18 Jan 2021 19:54:45 +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 3B23F10023B4; Mon, 18 Jan 2021 19:54:45 +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 048501809CB2; Mon, 18 Jan 2021 19:54:45 +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 10IJsNuv032695 for ; Mon, 18 Jan 2021 14:54:23 -0500 Received: by smtp.corp.redhat.com (Postfix) id 2E82063796; Mon, 18 Jan 2021 19:54:23 +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 2884B6379F for ; Mon, 18 Jan 2021 19:54:19 +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 CC9BF802D2A for ; Mon, 18 Jan 2021 19:54:19 +0000 (UTC) Received: from mail-qv1-f45.google.com (mail-qv1-f45.google.com [209.85.219.45]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-476-7pNU9XOROAy8hbr6qTmP2Q-1; Mon, 18 Jan 2021 14:54:16 -0500 Received: by mail-qv1-f45.google.com with SMTP id h13so8090137qvo.1 for ; Mon, 18 Jan 2021 11:54:16 -0800 (PST) Received: from rekt.ibmuc.com ([2804:431:c7c7:a75a:cb34:ba60:6de6:be1d]) by smtp.gmail.com with ESMTPSA id 16sm11309085qkf.112.2021.01.18.11.54.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Jan 2021 11:54:15 -0800 (PST) X-MC-Unique: eoVHBUWhNeyoG-ajnRamUQ-1 X-MC-Unique: 7pNU9XOROAy8hbr6qTmP2Q-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=gosnU1ZfOoPuzn8m+Da2mtmkvv9fOhCjLWrNcgsz548=; b=s0J3eieOHW806VFMv5H5Xxmurhesx/cCWdvUJ6CLBismGUjxD5qntBVJ0v1QiBslzw MDxiUoFr5MHu+xkC/xFBl2EGaSyEkLRsiYHDmLapNoeXHugfc6w6M9a0oSCnbvTyc/py OGCHQ8S+F0G3vhe4he4VrEbzhEetSBRprN28PSOttBeFHIRC1Hnfs3i2yGKyIyYKW1uz xxmm20CwKiyB270fE6BJG9n9BvTjb4w0Y63X21YPfWRUsXfZ9/rqXDkctD1m6f3eHeKr QuRR1Uw4ZMNPShekbIH09PqqkUeNXClee1YbKaqttjzg1CI6wEGlA03z/Oc3ojXCucZm hxWw== X-Gm-Message-State: AOAM531rAj8HD9VVMRLzEcamFdTK7gNVIlnf8d1TIsvwQvjcd418FKm9 Q3L6hvSIESri+p0RgEKxByCNPEPD7VeStw== X-Google-Smtp-Source: ABdhPJxBqpBIAsI8KliyB9j+1un7lCB/6L2pnobHsixGDCtkRiJIEcqLsLbY+gHCgY8KXCyzizPGlw== X-Received: by 2002:a05:6214:80d:: with SMTP id df13mr1066332qvb.10.1610999656101; Mon, 18 Jan 2021 11:54:16 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH RESEND 19/20] virpci.c: use virPCIDeviceAddressPtr in virPCIDeviceListDel() Date: Mon, 18 Jan 2021 16:53:35 -0300 Message-Id: <20210118195336.2090823-20-danielhb413@gmail.com> In-Reply-To: <20210118195336.2090823-1-danielhb413@gmail.com> References: <20210118195336.2090823-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" 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 Reviewed-by: Laine Stump --- 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 4042f874d6..c708791eec 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 @@ -2522,7 +2522,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 332e681c43..76dfd71802 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 Mon May 6 00:01:25 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=1610999689; cv=none; d=zohomail.com; s=zohoarc; b=nGw1c8byEIkxkxmINgr4iOyyKLkYduel6n5EZAgRbZjjGWlOTHIim0Ys4LBuy6Fsa6N6rrueJmFIoHIvp0lp6ZkS22EuybuVn358nmMoyZk2wZiY8JKOiELDDLlx2Pym1AyRKJyw4jTP4L2XFFWAcCo2JMGu212Oq5xMbR83tZ4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610999689; 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=RN0b4xXHBvTUjZD9X0sSwVpYOYR/7Fb2Gb4sLY/2hFg=; b=CS0KQaDZLWLFj0DheFHrkzVs1K3mfgCXpu4v2lUxS2FCRlGNEMkvcpIcBB187+T5qIjAp+5pvlK/i3N0gntFFk77v/FnJuCBKKMGtjZY0g2K3/um83Kuf6J1pkcKoUy9vJRP9zE1BhIv9lju9r99PbOFyeHwbuoBkkl1SHk93SE= 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 1610999689254515.4574290465144; Mon, 18 Jan 2021 11:54: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-219-T9XOAf75Mc-vHiLRepIZug-1; Mon, 18 Jan 2021 14:54:45 -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 99DEDE767; Mon, 18 Jan 2021 19:54:38 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7641963633; Mon, 18 Jan 2021 19:54:38 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 42B311809CB0; Mon, 18 Jan 2021 19:54:38 +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 10IJsNjv032700 for ; Mon, 18 Jan 2021 14:54:23 -0500 Received: by smtp.corp.redhat.com (Postfix) id 711EA2166B28; Mon, 18 Jan 2021 19:54:23 +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 6BFFD2166B29 for ; Mon, 18 Jan 2021 19:54:20 +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 4BC77805B05 for ; Mon, 18 Jan 2021 19:54:20 +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-101-owSjEeALNIuTE8rBytAG6w-1; Mon, 18 Jan 2021 14:54:18 -0500 Received: by mail-qt1-f174.google.com with SMTP id z6so5060209qtn.0 for ; Mon, 18 Jan 2021 11:54:18 -0800 (PST) Received: from rekt.ibmuc.com ([2804:431:c7c7:a75a:cb34:ba60:6de6:be1d]) by smtp.gmail.com with ESMTPSA id 16sm11309085qkf.112.2021.01.18.11.54.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Jan 2021 11:54:17 -0800 (PST) X-MC-Unique: T9XOAf75Mc-vHiLRepIZug-1 X-MC-Unique: owSjEeALNIuTE8rBytAG6w-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=RN0b4xXHBvTUjZD9X0sSwVpYOYR/7Fb2Gb4sLY/2hFg=; b=OpI5bjbdvBySlFb80xvnHoXLdVCuS7NCEXtiGrK2Tuf54020NYpi1EMjjtinpMgbAg 1j4dAHsix+35wovJ5wN4IQp11av8YKShNp7dnI66imaf/OPN9mSwKaD5F+pwAe8HGGQK nFOcHJvJVOBtpc0Cpiodpzbmt8UiQSw282jXlH8+qnSXNIWb/xYqcyusn8TQ2rr6hfF0 It8RH9Vsw4ljoIvAjayy7dK6/dhJAssE2HWYCGxlIPhvJ1grnAwBWCol8LZgLgy0KR/F SlLd5ZTEMziugslp55sOHHzBpp92SgNdJuiLtTaKsV7pZsxYGn0Fs+3SvaRrCZf0SFdH vpkw== X-Gm-Message-State: AOAM532t562c7nrC/yjK5/vWsKtYE4JBi18z5J/tIGTDMQQz1VmSFi5n TU/p8tAT21VG7cJ352fXAXocFKAI/Of/PA== X-Google-Smtp-Source: ABdhPJwFO4jd6cn9xaaOdje2rsUm8ynj53/okFvCwFyvjWBV23QvN9v9vLeA5by71fEaFBs1ScRp8g== X-Received: by 2002:ac8:5ed5:: with SMTP id s21mr1240670qtx.114.1610999657634; Mon, 18 Jan 2021 11:54:17 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH RESEND 20/20] virhostdev.c: remove missing PCI devs from hostdev manager Date: Mon, 18 Jan 2021 16:53:36 -0300 Message-Id: <20210118195336.2090823-21-danielhb413@gmail.com> In-Reply-To: <20210118195336.2090823-1-danielhb413@gmail.com> References: <20210118195336.2090823-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: Although this patch enables the possibility of 'outside Libvirt' SR-IOV hotunplug of PCI devices, if the hypervisor and the PCI driver copes with i= t, our goal is to mitigate what it is still considered an user oopsie. For all supported purposes, the admin must remove the SR-IOV VFs from all running d= omains before removing the VFs from the host. Resolves: https://gitlab.com/libvirt/libvirt/-/issues/72 Signed-off-by: Daniel Henrique Barboza Reviewed-by: Laine Stump --- src/hypervisor/virhostdev.c | 38 +++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/src/hypervisor/virhostdev.c b/src/hypervisor/virhostdev.c index c708791eec..ed43733e71 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