From nobody Wed May 1 04:00:06 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1560863167; cv=none; d=zoho.com; s=zohoarc; b=VPca4aL7aGFs4hWN/rp1Q8NlyshYR5e+NR3a8dp8nFKcO1/fEedSyekeW8dU0v/S2wOMckSRg/tu3dRlrD9GiBOSvbq8+9gqcHiLB+lZUoEZA2Er/XFp9mDoIepnJ2ZjiEyLaimJu6WwhLaZRI6tfZRuf643INwMV74zagGZ4rs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1560863167; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=TJlCwHXebxKzh4SzEvB5RQ324Hnkc1tjuvQjK/sFPvU=; b=Qk93RXU2VKsaSyu25OyeIBQjI4yF4fia0I3w2qUuIuiJo6/9J2iRl6gkYDmqtYIwo3jr2cvdHrDAK8WYYTG1yVYdcw6eQa+XIz837/0ol69OMFrqxwMMpDWHliHRzep0SX9yWHygydagOA+5fANszuL35fx5KNNL0H7fcFD6qs0= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1560863167938436.2966185861536; Tue, 18 Jun 2019 06:06:07 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id E8229B2DDB; Tue, 18 Jun 2019 13:05:50 +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 BD803608C2; Tue, 18 Jun 2019 13:05:49 +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 6FA6A19727; Tue, 18 Jun 2019 13:05:47 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x5ID4Ya6017591 for ; Tue, 18 Jun 2019 09:04:34 -0400 Received: by smtp.corp.redhat.com (Postfix) id 6B28F7DE2C; Tue, 18 Jun 2019 13:04:34 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id EA80C7E669 for ; Tue, 18 Jun 2019 13:04:31 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Tue, 18 Jun 2019 15:04:20 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 1/8] virHostdevGetPCIHostDeviceList: Add @pci a bit later X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Tue, 18 Jun 2019 13:06:01 +0000 (UTC) Content-Type: text/plain; charset="utf-8" This function is a good candidate for VIR_AUTOPTR() conversion. But things conversion will be easier if we only add @pci device onto @pcidevs list after it was all set up. This is no functional change. Signed-off-by: Michal Privoznik Reviewed-by: J=C3=A1n Tomko --- src/util/virhostdev.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/util/virhostdev.c b/src/util/virhostdev.c index fe176f35e4..9c63d0aebd 100644 --- a/src/util/virhostdev.c +++ b/src/util/virhostdev.c @@ -240,11 +240,6 @@ virHostdevGetPCIHostDeviceList(virDomainHostdevDefPtr = *hostdevs, int nhostdevs) virObjectUnref(pcidevs); return NULL; } - if (virPCIDeviceListAdd(pcidevs, pci) < 0) { - virPCIDeviceFree(pci); - virObjectUnref(pcidevs); - return NULL; - } =20 virPCIDeviceSetManaged(pci, hostdev->managed); =20 @@ -254,6 +249,12 @@ virHostdevGetPCIHostDeviceList(virDomainHostdevDefPtr = *hostdevs, int nhostdevs) virPCIDeviceSetStubDriver(pci, VIR_PCI_STUB_DRIVER_XEN); else virPCIDeviceSetStubDriver(pci, VIR_PCI_STUB_DRIVER_KVM); + + if (virPCIDeviceListAdd(pcidevs, pci) < 0) { + virPCIDeviceFree(pci); + virObjectUnref(pcidevs); + return NULL; + } } =20 return pcidevs; --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 1 04:00:06 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1560863178; cv=none; d=zoho.com; s=zohoarc; b=b6Qbr3lisEpE2PrFJ37RUEmHzMgKjyh1sJ9/SXpvQ/eeLz9VRbWUZgaJcz6tQM5u1qrgKesTb6SGkhGVi3tgZjeN6a+wyhU6+DEl0/FpqrdCKeK2KPLta4TIPrtdPL+WplFXm2QmAkvqPds1RABW4US43+oHro0K/sUz0CSHTQE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1560863178; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=bVufoM5zFNVbD5tZAuOkCdaNUYk0jpuN7Xx28YALELs=; b=bDDxdmfIZb87RWV8yWF8JKBIxTz3Gp1FT283cAZznEL1OfN7r7VJhN9O31deK4xxm+IeeZeIpenxZJc/Vf04isoz4O2XWku+3nEETwkmB43nSsuH+sqzmtgTrKiVJbWGnQn8NVN+N9UlMVLu79YVUj12JnLWbxerfvKhNHdGOYY= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1560863178788552.056891636775; Tue, 18 Jun 2019 06:06:18 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C95A559469; Tue, 18 Jun 2019 13:06:08 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9E68D5F1B7; Tue, 18 Jun 2019 13:06: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 53F751806B18; Tue, 18 Jun 2019 13:06:03 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x5ID4dBS017602 for ; Tue, 18 Jun 2019 09:04:39 -0400 Received: by smtp.corp.redhat.com (Postfix) id 003417DE37; Tue, 18 Jun 2019 13:04:39 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6558A7EA41 for ; Tue, 18 Jun 2019 13:04:34 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Tue, 18 Jun 2019 15:04:21 +0200 Message-Id: <0d78560e05cdb77f70e1857030f8b0a2ce001049.1560862640.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 2/8] virHostdevGetPCIHostDeviceList: Use VIR_AUTOPTR for virPCIDevice X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Tue, 18 Jun 2019 13:06:17 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Signed-off-by: Michal Privoznik Reviewed-by: J=C3=A1n Tomko --- src/util/virhostdev.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/util/virhostdev.c b/src/util/virhostdev.c index 9c63d0aebd..5935d926aa 100644 --- a/src/util/virhostdev.c +++ b/src/util/virhostdev.c @@ -227,7 +227,7 @@ virHostdevGetPCIHostDeviceList(virDomainHostdevDefPtr *= hostdevs, int nhostdevs) for (i =3D 0; i < nhostdevs; i++) { virDomainHostdevDefPtr hostdev =3D hostdevs[i]; virDomainHostdevSubsysPCIPtr pcisrc =3D &hostdev->source.subsys.u.= pci; - virPCIDevicePtr pci; + VIR_AUTOPTR(virPCIDevice) pci =3D NULL; =20 if (hostdev->mode !=3D VIR_DOMAIN_HOSTDEV_MODE_SUBSYS) continue; @@ -251,10 +251,10 @@ virHostdevGetPCIHostDeviceList(virDomainHostdevDefPtr= *hostdevs, int nhostdevs) virPCIDeviceSetStubDriver(pci, VIR_PCI_STUB_DRIVER_KVM); =20 if (virPCIDeviceListAdd(pcidevs, pci) < 0) { - virPCIDeviceFree(pci); virObjectUnref(pcidevs); return NULL; } + pci =3D NULL; } =20 return pcidevs; --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 1 04:00:06 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1560863186; cv=none; d=zoho.com; s=zohoarc; b=hB8K4W+04YvgT/qd8cdAd0jzePtonv6MB8T2rC07liStN8O5DxeJ54UC+AKuYRNP6Z67p1qe7c1CBFbsxoe+wtYHl/AQBXeV0VAJpUB7+TSrx9jKpxmuLHuTnbSQIuH1sQ69SCbOSBqLR5kreUg7EiUSVQXLn0hPPQX6IuhJeW8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1560863186; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=toRDqdpULl3TrDd6bxhcxxDF5pO1zHUnCbQcRl2DYW8=; b=MYGmdxDECZIuj9WHxtDSt2IC2CHBSoAIbE+JD2LiiXZeqL7QTXADVbnvKJDg96o6Zc81+bHAms1w/GWlxoJmuj0K9smJjhx4dOigiKwHkhjHFTsVmXIHOVcR1FFge8zx75cUKXT9Pb+lAhDPHwRP6sO7RPSisxI3rz217P+WevI= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 15608631868741010.9533501216326; Tue, 18 Jun 2019 06:06:26 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2FFA92F8BFE; Tue, 18 Jun 2019 13:06:20 +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 2950D5F58A; Tue, 18 Jun 2019 13:06:16 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id CAA0D19729; Tue, 18 Jun 2019 13:06:12 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x5ID4eBN017608 for ; Tue, 18 Jun 2019 09:04:40 -0400 Received: by smtp.corp.redhat.com (Postfix) id 4EAFA7DE37; Tue, 18 Jun 2019 13:04:40 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id CDCE57EA33 for ; Tue, 18 Jun 2019 13:04:39 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Tue, 18 Jun 2019 15:04:22 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 3/8] virHostdevPreparePCIDevices: Construct pcidevs list earlier X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Tue, 18 Jun 2019 13:06:25 +0000 (UTC) Content-Type: text/plain; charset="utf-8" There's no need to translate virDomainHostdevDef-s into virPCIDevice-s with locked list of PCI devices. Signed-off-by: Michal Privoznik Reviewed-by: J=C3=A1n Tomko --- src/util/virhostdev.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/util/virhostdev.c b/src/util/virhostdev.c index 5935d926aa..7b5ccf2daf 100644 --- a/src/util/virhostdev.c +++ b/src/util/virhostdev.c @@ -639,11 +639,11 @@ virHostdevPreparePCIDevices(virHostdevManagerPtr mgr, if (!nhostdevs) return 0; =20 - virObjectLock(mgr->activePCIHostdevs); - virObjectLock(mgr->inactivePCIHostdevs); - if (!(pcidevs =3D virHostdevGetPCIHostDeviceList(hostdevs, nhostdevs))) - goto cleanup; + return -1; + + virObjectLock(mgr->activePCIHostdevs); + virObjectLock(mgr->inactivePCIHostdevs); =20 /* Detaching devices from the host involves several steps; each * of them is described at length below. @@ -912,9 +912,9 @@ virHostdevPreparePCIDevices(virHostdevManagerPtr mgr, } =20 cleanup: - virObjectUnref(pcidevs); virObjectUnlock(mgr->activePCIHostdevs); virObjectUnlock(mgr->inactivePCIHostdevs); + virObjectUnref(pcidevs); =20 return ret; } --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 1 04:00:06 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1560863202; cv=none; d=zoho.com; s=zohoarc; b=D8FeJhR1TThfXwBm3igL0sRz2j0i0YMxbLDwaEkX2EX1/+u82zjw1GZzvhKoQ/V2HkSVBK46Jv0cKsQwUed6CkkGMIfybBEyBHDuYnDAfKLeQkaKGagsiZrQoFWV8RWwANf2/IIrVekaBEpA9Zu70b9AdIn/NfFBeUBfJj6pXa4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1560863202; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=RwKszdLNslzmiqllFkxtbLTW0L0yzl0ggztDLIju2z0=; b=V9kjtfT5hx8zmNAIw7i8nr0vv64OtV66h4oVThsnm9BMnGKVYR0IXjqhS90t9F6NX2G4pAUbiUenYNx+2GyrUiztL0VKoMRYjWGItWtULKJkAwAhoaMkGaV1rxpnT2r2LjvPIw3Y4UcBoAa6iZKWeES6wUBynJBXAo/y8LxjhOc= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1560863202770733.4126247807494; Tue, 18 Jun 2019 06:06:42 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 10B5B821C7; Tue, 18 Jun 2019 13:06:36 +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 CF9C982EF6; Tue, 18 Jun 2019 13:06: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 8EE621806B1A; Tue, 18 Jun 2019 13:06:32 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x5ID4ftv017618 for ; Tue, 18 Jun 2019 09:04:41 -0400 Received: by smtp.corp.redhat.com (Postfix) id D13567C61C; Tue, 18 Jun 2019 13:04:41 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5C7A47EA33 for ; Tue, 18 Jun 2019 13:04:40 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Tue, 18 Jun 2019 15:04:23 +0200 Message-Id: <154aac43506382fc687536c40eeab2043c4bb4ac.1560862640.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 4/8] virHostdevReAttachPCIDevices: Construct pcidevs list earlier X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Tue, 18 Jun 2019 13:06:41 +0000 (UTC) Content-Type: text/plain; charset="utf-8" There's no need to translate virDomainHostdevDef-s into virPCIDevice-s with locked list of PCI devices. Signed-off-by: Michal Privoznik Reviewed-by: J=C3=A1n Tomko --- src/util/virhostdev.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/util/virhostdev.c b/src/util/virhostdev.c index 7b5ccf2daf..79a6ec86fe 100644 --- a/src/util/virhostdev.c +++ b/src/util/virhostdev.c @@ -963,16 +963,16 @@ virHostdevReAttachPCIDevices(virHostdevManagerPtr mgr, if (!nhostdevs) return; =20 - virObjectLock(mgr->activePCIHostdevs); - virObjectLock(mgr->inactivePCIHostdevs); - if (!(pcidevs =3D virHostdevGetPCIHostDeviceList(hostdevs, nhostdevs))= ) { VIR_ERROR(_("Failed to allocate PCI device list: %s"), virGetLastErrorMessage()); virResetLastError(); - goto cleanup; + return; } =20 + virObjectLock(mgr->activePCIHostdevs); + virObjectLock(mgr->inactivePCIHostdevs); + /* Reattaching devices to the host involves several steps; each * of them is described at length below */ =20 --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 1 04:00:06 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1560863134; cv=none; d=zoho.com; s=zohoarc; b=XP3R3NIPU34uHmbbwDnXv4vKGAW+6wLw3Wr9QGifUD2+bp8CB8CnHLDvS2sIeqV23KG2NPu1+9GLQw8CAeXVOihNtD6NCBLTlkR5dNNnNQBXLR+EJ6C+T6Q7YEFAQtSsA59PMjmuIG8krW1XXVP9oadn9qfwBbacEDIeeJrNCFQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1560863134; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=2Lfe59QtAhyCEjKgfFSfMztdldBEFnMLThOkKi3Mw50=; b=hcyG1KZ1rMf1wl+4fihItUseVElH6SrDrEu3UNuglZKS+oXOHnpqjq4P8seqfUw8cfOaOkP8FScH5AdVlUrhCSZRHzfpQcr+3UeyHXm0Wtmyagk34N74DS4j8GRX/MeErmeK0IMEBcomiXhmStkYyc6XsD5fMQ+PPNKHNtICxgg= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1560863134034113.81828987072436; Tue, 18 Jun 2019 06:05:34 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 681883086229; Tue, 18 Jun 2019 13:05: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 76DE2101E26A; Tue, 18 Jun 2019 13:04:58 +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 D18811806B18; Tue, 18 Jun 2019 13:04:47 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x5ID4kk7017633 for ; Tue, 18 Jun 2019 09:04:46 -0400 Received: by smtp.corp.redhat.com (Postfix) id BBBFC7C61C; Tue, 18 Jun 2019 13:04:46 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 463F77EA45 for ; Tue, 18 Jun 2019 13:04:42 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Tue, 18 Jun 2019 15:04:24 +0200 Message-Id: <6434e3770e48e475cb8bb36c923e82fabcad50a2.1560862640.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 5/8] virhostdev: Use VIR_AUTOUNREF more X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Tue, 18 Jun 2019 13:05:24 +0000 (UTC) Content-Type: text/plain; charset="utf-8" There are couple of functions which get shorter after the treatment. Signed-off-by: Michal Privoznik Reviewed-by: J=C3=A1n Tomko --- src/util/virhostdev.c | 105 ++++++++++++++++-------------------------- 1 file changed, 39 insertions(+), 66 deletions(-) diff --git a/src/util/virhostdev.c b/src/util/virhostdev.c index 79a6ec86fe..31ad287866 100644 --- a/src/util/virhostdev.c +++ b/src/util/virhostdev.c @@ -143,49 +143,49 @@ virHostdevManagerDispose(void *obj) static virHostdevManagerPtr virHostdevManagerNew(void) { - virHostdevManagerPtr hostdevMgr; + VIR_AUTOUNREF(virHostdevManagerPtr) hostdevMgr =3D NULL; bool privileged =3D geteuid() =3D=3D 0; =20 if (!(hostdevMgr =3D virObjectNew(virHostdevManagerClass))) return NULL; =20 if (!(hostdevMgr->activePCIHostdevs =3D virPCIDeviceListNew())) - goto error; + return NULL; =20 if (!(hostdevMgr->activeUSBHostdevs =3D virUSBDeviceListNew())) - goto error; + return NULL; =20 if (!(hostdevMgr->inactivePCIHostdevs =3D virPCIDeviceListNew())) - goto error; + return NULL; =20 if (!(hostdevMgr->activeSCSIHostdevs =3D virSCSIDeviceListNew())) - goto error; + return NULL; =20 if (!(hostdevMgr->activeSCSIVHostHostdevs =3D virSCSIVHostDeviceListNe= w())) - goto error; + return NULL; =20 if (!(hostdevMgr->activeMediatedHostdevs =3D virMediatedDeviceListNew(= ))) - goto error; + return NULL; =20 if (privileged) { if (VIR_STRDUP(hostdevMgr->stateDir, HOSTDEV_STATE_DIR) < 0) - goto error; + return NULL; =20 if (virFileMakePath(hostdevMgr->stateDir) < 0) { virReportError(VIR_ERR_OPERATION_FAILED, _("Failed to create state dir '%s'"), hostdevMgr->stateDir); - goto error; + return NULL; } } else { VIR_AUTOFREE(char *) rundir =3D NULL; mode_t old_umask; =20 if (!(rundir =3D virGetUserRuntimeDirectory())) - goto error; + return NULL; =20 if (virAsprintf(&hostdevMgr->stateDir, "%s/hostdevmgr", rundir) < = 0) - goto error; + return NULL; =20 old_umask =3D umask(077); =20 @@ -194,16 +194,12 @@ virHostdevManagerNew(void) virReportError(VIR_ERR_OPERATION_FAILED, _("Failed to create state dir '%s'"), hostdevMgr->stateDir); - goto error; + return NULL; } umask(old_umask); } =20 - return hostdevMgr; - - error: - virObjectUnref(hostdevMgr); - return NULL; + VIR_RETURN_PTR(hostdevMgr); } =20 virHostdevManagerPtr @@ -218,7 +214,7 @@ virHostdevManagerGetDefault(void) static virPCIDeviceListPtr virHostdevGetPCIHostDeviceList(virDomainHostdevDefPtr *hostdevs, int nhost= devs) { - virPCIDeviceListPtr pcidevs; + VIR_AUTOUNREF(virPCIDeviceListPtr) pcidevs =3D NULL; size_t i; =20 if (!(pcidevs =3D virPCIDeviceListNew())) @@ -236,10 +232,8 @@ virHostdevGetPCIHostDeviceList(virDomainHostdevDefPtr = *hostdevs, int nhostdevs) =20 pci =3D virPCIDeviceNew(pcisrc->addr.domain, pcisrc->addr.bus, pcisrc->addr.slot, pcisrc->addr.function); - if (!pci) { - virObjectUnref(pcidevs); + if (!pci) return NULL; - } =20 virPCIDeviceSetManaged(pci, hostdev->managed); =20 @@ -250,14 +244,12 @@ virHostdevGetPCIHostDeviceList(virDomainHostdevDefPtr= *hostdevs, int nhostdevs) else virPCIDeviceSetStubDriver(pci, VIR_PCI_STUB_DRIVER_KVM); =20 - if (virPCIDeviceListAdd(pcidevs, pci) < 0) { - virObjectUnref(pcidevs); + if (virPCIDeviceListAdd(pcidevs, pci) < 0) return NULL; - } pci =3D NULL; } =20 - return pcidevs; + VIR_RETURN_PTR(pcidevs); } =20 =20 @@ -630,7 +622,7 @@ virHostdevPreparePCIDevices(virHostdevManagerPtr mgr, int nhostdevs, unsigned int flags) { - virPCIDeviceListPtr pcidevs =3D NULL; + VIR_AUTOUNREF(virPCIDeviceListPtr) pcidevs =3D NULL; int last_processed_hostdev_vf =3D -1; size_t i; int ret =3D -1; @@ -914,7 +906,6 @@ virHostdevPreparePCIDevices(virHostdevManagerPtr mgr, cleanup: virObjectUnlock(mgr->activePCIHostdevs); virObjectUnlock(mgr->inactivePCIHostdevs); - virObjectUnref(pcidevs); =20 return ret; } @@ -957,7 +948,7 @@ virHostdevReAttachPCIDevices(virHostdevManagerPtr mgr, int nhostdevs, const char *oldStateDir) { - virPCIDeviceListPtr pcidevs; + VIR_AUTOUNREF(virPCIDeviceListPtr) pcidevs =3D NULL; size_t i; =20 if (!nhostdevs) @@ -1088,8 +1079,6 @@ virHostdevReAttachPCIDevices(virHostdevManagerPtr mgr, virPCIDeviceGetName(actual)); } =20 - cleanup: - virObjectUnref(pcidevs); virObjectUnlock(mgr->activePCIHostdevs); virObjectUnlock(mgr->inactivePCIHostdevs); } @@ -1407,7 +1396,7 @@ virHostdevFindUSBDevice(virDomainHostdevDefPtr hostde= v, * automatically found before. */ if (vendor) { - virUSBDeviceListPtr devs; + VIR_AUTOUNREF(virUSBDeviceListPtr) devs =3D NULL; =20 rc =3D virUSBDeviceFindByVendor(vendor, product, NULL, mandatory, = &devs); if (rc < 0) @@ -1417,7 +1406,6 @@ virHostdevFindUSBDevice(virDomainHostdevDefPtr hostde= v, *usb =3D virUSBDeviceListGet(devs, 0); virUSBDeviceListSteal(devs, *usb); } - virObjectUnref(devs); =20 if (rc =3D=3D 0) { goto out; @@ -1467,8 +1455,7 @@ virHostdevPrepareUSBDevices(virHostdevManagerPtr mgr, unsigned int flags) { size_t i; - int ret =3D -1; - virUSBDeviceListPtr list; + VIR_AUTOUNREF(virUSBDeviceListPtr) list =3D NULL; virUSBDevicePtr tmp; bool coldBoot =3D !!(flags & VIR_HOSTDEV_COLD_BOOT); =20 @@ -1481,7 +1468,7 @@ virHostdevPrepareUSBDevices(virHostdevManagerPtr mgr, * loop. See virHostdevPreparePCIDevices() */ if (!(list =3D virUSBDeviceListNew())) - goto cleanup; + return -1; =20 /* Loop 1: build temporary list */ @@ -1501,11 +1488,11 @@ virHostdevPrepareUSBDevices(virHostdevManagerPtr mg= r, required =3D false; =20 if (virHostdevFindUSBDevice(hostdev, required, &usb) < 0) - goto cleanup; + return -1; =20 if (usb && virUSBDeviceListAdd(list, &usb) < 0) { virUSBDeviceFree(usb); - goto cleanup; + return -1; } } =20 @@ -1514,7 +1501,7 @@ virHostdevPrepareUSBDevices(virHostdevManagerPtr mgr, * wrong, perform rollback. */ if (virHostdevMarkUSBDevices(mgr, drv_name, dom_name, list) < 0) - goto cleanup; + return -1; =20 /* Loop 2: Temporary list was successfully merged with * driver list, so steal all items to avoid freeing them @@ -1525,11 +1512,7 @@ virHostdevPrepareUSBDevices(virHostdevManagerPtr mgr, virUSBDeviceListSteal(list, tmp); } =20 - ret =3D 0; - - cleanup: - virObjectUnref(list); - return ret; + return 0; } =20 static int @@ -1569,7 +1552,7 @@ virHostdevPrepareSCSIDevices(virHostdevManagerPtr mgr, { size_t i, j; int count; - virSCSIDeviceListPtr list; + VIR_AUTOUNREF(virSCSIDeviceListPtr) list =3D NULL; virSCSIDevicePtr tmp; =20 if (!nhostdevs) @@ -1581,7 +1564,7 @@ virHostdevPrepareSCSIDevices(virHostdevManagerPtr mgr, * loop. See virHostdevPreparePCIDevices() */ if (!(list =3D virSCSIDeviceListNew())) - goto cleanup; + return -1; =20 /* Loop 1: build temporary list */ for (i =3D 0; i < nhostdevs; i++) { @@ -1595,7 +1578,7 @@ virHostdevPrepareSCSIDevices(virHostdevManagerPtr mgr, continue; /* Not supported for iSCSI */ } else { if (virHostdevPrepareSCSIHostDevices(hostdev, scsisrc, list) <= 0) - goto cleanup; + return -1; } } =20 @@ -1646,7 +1629,6 @@ virHostdevPrepareSCSIDevices(virHostdevManagerPtr mgr, virSCSIDeviceListSteal(list, tmp); } =20 - virObjectUnref(list); return 0; =20 error: @@ -1655,8 +1637,6 @@ virHostdevPrepareSCSIDevices(virHostdevManagerPtr mgr, virSCSIDeviceListSteal(mgr->activeSCSIHostdevs, tmp); } virObjectUnlock(mgr->activeSCSIHostdevs); - cleanup: - virObjectUnref(list); return -1; } =20 @@ -1669,7 +1649,7 @@ virHostdevPrepareSCSIVHostDevices(virHostdevManagerPt= r mgr, { size_t i, j; int count; - virSCSIVHostDeviceListPtr list; + VIR_AUTOUNREF(virSCSIVHostDeviceListPtr) list =3D NULL; virSCSIVHostDevicePtr host, tmp; =20 if (!nhostdevs) @@ -1681,7 +1661,7 @@ virHostdevPrepareSCSIVHostDevices(virHostdevManagerPt= r mgr, * loop. See virHostdevPreparePCIDevices() */ if (!(list =3D virSCSIVHostDeviceListNew())) - goto cleanup; + return -1; =20 /* Loop 1: build temporary list */ for (i =3D 0; i < nhostdevs; i++) { @@ -1696,11 +1676,11 @@ virHostdevPrepareSCSIVHostDevices(virHostdevManager= Ptr mgr, continue; /* Not supported */ =20 if (!(host =3D virSCSIVHostDeviceNew(hostsrc->wwpn))) - goto cleanup; + return -1; =20 if (virSCSIVHostDeviceListAdd(list, host) < 0) { virSCSIVHostDeviceFree(host); - goto cleanup; + return -1; } } =20 @@ -1743,7 +1723,6 @@ virHostdevPrepareSCSIVHostDevices(virHostdevManagerPt= r mgr, virSCSIVHostDeviceListSteal(list, tmp); } =20 - virObjectUnref(list); return 0; error: for (j =3D 0; j < i; j++) { @@ -1751,8 +1730,6 @@ virHostdevPrepareSCSIVHostDevices(virHostdevManagerPt= r mgr, virSCSIVHostDeviceListSteal(mgr->activeSCSIVHostHostdevs, tmp); } virObjectUnlock(mgr->activeSCSIVHostHostdevs); - cleanup: - virObjectUnref(list); return -1; } =20 @@ -1765,8 +1742,7 @@ virHostdevPrepareMediatedDevices(virHostdevManagerPtr= mgr, int nhostdevs) { size_t i; - int ret =3D -1; - virMediatedDeviceListPtr list; + VIR_AUTOUNREF(virMediatedDeviceListPtr) list =3D NULL; =20 if (!nhostdevs) return 0; @@ -1776,7 +1752,7 @@ virHostdevPrepareMediatedDevices(virHostdevManagerPtr= mgr, * A device is appended to the driver list after a series of preparati= ons. */ if (!(list =3D virMediatedDeviceListNew())) - goto cleanup; + return -1; =20 /* Loop 1: Build a temporary list of ALL mediated devices. */ for (i =3D 0; i < nhostdevs; i++) { @@ -1788,11 +1764,11 @@ virHostdevPrepareMediatedDevices(virHostdevManagerP= tr mgr, continue; =20 if (!(mdev =3D virMediatedDeviceNew(src->uuidstr, src->model))) - goto cleanup; + return -1; =20 if (virMediatedDeviceListAdd(list, &mdev) < 0) { virMediatedDeviceFree(mdev); - goto cleanup; + return -1; } } =20 @@ -1801,7 +1777,7 @@ virHostdevPrepareMediatedDevices(virHostdevManagerPtr= mgr, */ if (virMediatedDeviceListMarkDevices(mgr->activeMediatedHostdevs, list, drv_name, dom_name) < 0) - goto cleanup; + return -1; =20 /* Loop 2: Temporary list was successfully merged with * driver list, so steal all items to avoid freeing them @@ -1812,10 +1788,7 @@ virHostdevPrepareMediatedDevices(virHostdevManagerPt= r mgr, virMediatedDeviceListSteal(list, tmp); } =20 - ret =3D 0; - cleanup: - virObjectUnref(list); - return ret; + return 0; } =20 void --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 1 04:00:06 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1560863127; cv=none; d=zoho.com; s=zohoarc; b=AiNlC6DlstVANsxWmi3pTxL9Aj9jLDCW5RW8UiJkNpg2Rsw4TK8096fgL+NFOk9fBNURumHDuCYb+uUwKL5Hpk6Y/0AxUqBgUoIl+cdRY6/fLHy6LkIxjo2tEUUpLuM+90Afr/yVSYR5SrZeoMh0IteAipFXjf/8Z/tZu1Dopng= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1560863127; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=KKjfZHYWl4+RbD10OMb1JPuGZETQG1L/h66brMC7/qo=; b=EqMkunGuPfuhEBf/Z489EPP3GF8ruGFEOh/tyV+tfdnipxdSKTa8rVpMgzAyUp5Dd/OXLz7AbyjagzG8e1Irs+CW0obG/x2a2GqkkVJDmfJkxC5PXbhV4Je1+TFcwox9s9im0dFjm3zpKcMoPZIwsGvWXokC3rR2ZxDZzmAiOE4= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1560863127111279.8362802158888; Tue, 18 Jun 2019 06:05:27 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 1B1442F8BE0; Tue, 18 Jun 2019 13:05:05 +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 CA85D101E681; Tue, 18 Jun 2019 13:05:00 +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 340461806B1A; Tue, 18 Jun 2019 13:04:54 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x5ID4rDE017646 for ; Tue, 18 Jun 2019 09:04:53 -0400 Received: by smtp.corp.redhat.com (Postfix) id C41737EA4C; Tue, 18 Jun 2019 13:04:53 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4F54B7EA4E for ; Tue, 18 Jun 2019 13:04:46 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Tue, 18 Jun 2019 15:04:25 +0200 Message-Id: <7702d13e9d4bb1e98e121d4d0b9249120005cf05.1560862640.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 6/8] virHostdevFindUSBDevice: Simplify flow a bit X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Tue, 18 Jun 2019 13:05:17 +0000 (UTC) Content-Type: text/plain; charset="utf-8" When looking up a USB device by vendor the virUSBDeviceFindByVendor() is used. The function returns number of items found. But the logic in caller to process it is needlessly complicated. Signed-off-by: Michal Privoznik Reviewed-by: J=C3=A1n Tomko --- src/util/virhostdev.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/util/virhostdev.c b/src/util/virhostdev.c index 31ad287866..9817c6571b 100644 --- a/src/util/virhostdev.c +++ b/src/util/virhostdev.c @@ -1399,15 +1399,9 @@ virHostdevFindUSBDevice(virDomainHostdevDefPtr hostd= ev, VIR_AUTOUNREF(virUSBDeviceListPtr) devs =3D NULL; =20 rc =3D virUSBDeviceFindByVendor(vendor, product, NULL, mandatory, = &devs); - if (rc < 0) + if (rc < 0) { return -1; - - if (rc =3D=3D 1) { - *usb =3D virUSBDeviceListGet(devs, 0); - virUSBDeviceListSteal(devs, *usb); - } - - if (rc =3D=3D 0) { + } else if (rc =3D=3D 0) { goto out; } else if (rc > 1) { if (autoAddress) { @@ -1424,6 +1418,9 @@ virHostdevFindUSBDevice(virDomainHostdevDefPtr hostde= v, return -1; } =20 + *usb =3D virUSBDeviceListGet(devs, 0); + virUSBDeviceListSteal(devs, *usb); + usbsrc->bus =3D virUSBDeviceGetBus(*usb); usbsrc->device =3D virUSBDeviceGetDevno(*usb); usbsrc->autoAddress =3D true; --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 1 04:00:06 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1560863206; cv=none; d=zoho.com; s=zohoarc; b=GP1cEATWMQ23R2fOpMrs+8fj453N+Q+8wM9iN6PHwHc4zSow7T7bssoB3iSB5l4AMNiMzBhCDSw8Y3H/U1HDyQd16Vg5qcwQd/5PXacCZ+ugnH15TJ50XWdiwTlIJFGWh99S9LmRsW4q7FL1Pg+S2glABoCpuNpKCZoNKS/fq1Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1560863206; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=FKf9yFNwAxKXJjFYMvHvSs2/e3vEs4wqbv0afcfNRfk=; b=G7vX2IVo+M+oq0O+k24bQpvs+Q8ahYnlfkBuMDBROg0OH9fzLWC2ePxD002g2UHM3Iw8r1zy7TDZq5Tj/uGk5jjqzknIB7vnPKj1Oju3CJy8PZZb2WhNb0dsvhTl3c8wF9ujIVmZ/vI+SBRPP3cIfPJMjta80YCalRQ8h4Lb5vc= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1560863206694303.25478257806947; Tue, 18 Jun 2019 06:06:46 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E2F9B772F9; Tue, 18 Jun 2019 13:06:44 +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 8191D5F1BB; Tue, 18 Jun 2019 13:06:43 +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 44AE119726; Tue, 18 Jun 2019 13:06:42 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x5ID4tj6017656 for ; Tue, 18 Jun 2019 09:04:55 -0400 Received: by smtp.corp.redhat.com (Postfix) id A1B8D7DE38; Tue, 18 Jun 2019 13:04:55 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2D2F87EE69 for ; Tue, 18 Jun 2019 13:04:53 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Tue, 18 Jun 2019 15:04:26 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 7/8] virHostdevPrepareSCSIVHostDevices: Simplify logic X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Tue, 18 Jun 2019 13:06:45 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Couple of things happening in this patch: 1) We can mark the device we're adding onto active list as used way before - when adding it onto temporary list. 2) When actually moving device from a temporary helper list onto the list of active devices we check if the device isn't already there. The same check is performed by virSCSIVHostDeviceListAdd() later. Drop this duplicity. 3) The 'error' label is renamed to 'rollback' to reflect what it is actually doing. While in the rest of the code we don't allow random label names, this source file is different. Signed-off-by: Michal Privoznik Reviewed-by: J=C3=A1n Tomko --- src/util/virhostdev.c | 41 ++++++++++++++++------------------------- 1 file changed, 16 insertions(+), 25 deletions(-) diff --git a/src/util/virhostdev.c b/src/util/virhostdev.c index 9817c6571b..fe2d774857 100644 --- a/src/util/virhostdev.c +++ b/src/util/virhostdev.c @@ -1644,10 +1644,9 @@ virHostdevPrepareSCSIVHostDevices(virHostdevManagerP= tr mgr, virDomainHostdevDefPtr *hostdevs, int nhostdevs) { - size_t i, j; - int count; VIR_AUTOUNREF(virSCSIVHostDeviceListPtr) list =3D NULL; - virSCSIVHostDevicePtr host, tmp; + virSCSIVHostDevicePtr tmp; + size_t i, j; =20 if (!nhostdevs) return 0; @@ -1664,6 +1663,7 @@ virHostdevPrepareSCSIVHostDevices(virHostdevManagerPt= r mgr, for (i =3D 0; i < nhostdevs; i++) { virDomainHostdevDefPtr hostdev =3D hostdevs[i]; virDomainHostdevSubsysSCSIVHostPtr hostsrc =3D &hostdev->source.su= bsys.u.scsi_host; + VIR_AUTOPTR(virSCSIVHostDevice) host =3D NULL; =20 if (hostdev->mode !=3D VIR_DOMAIN_HOSTDEV_MODE_SUBSYS || hostdev->source.subsys.type !=3D VIR_DOMAIN_HOSTDEV_SUBSYS_TYP= E_SCSI_HOST) @@ -1675,10 +1675,12 @@ virHostdevPrepareSCSIVHostDevices(virHostdevManager= Ptr mgr, if (!(host =3D virSCSIVHostDeviceNew(hostsrc->wwpn))) return -1; =20 - if (virSCSIVHostDeviceListAdd(list, host) < 0) { - virSCSIVHostDeviceFree(host); + if (virSCSIVHostDeviceSetUsedBy(host, drv_name, dom_name) < 0) return -1; - } + + if (virSCSIVHostDeviceListAdd(list, host) < 0) + return -1; + host =3D NULL; } =20 /* Loop 2: Mark devices in temporary list as used by @name @@ -1686,27 +1688,15 @@ virHostdevPrepareSCSIVHostDevices(virHostdevManager= Ptr mgr, * wrong, perform rollback. */ virObjectLock(mgr->activeSCSIVHostHostdevs); - count =3D virSCSIVHostDeviceListCount(list); =20 - for (i =3D 0; i < count; i++) { - host =3D virSCSIVHostDeviceListGet(list, i); - if ((tmp =3D virSCSIVHostDeviceListFind(mgr->activeSCSIVHostHostde= vs, - host))) { - virReportError(VIR_ERR_OPERATION_INVALID, - _("SCSI_host device %s is already in use by " - "another domain"), - virSCSIVHostDeviceGetName(tmp)); - goto error; - } else { - if (virSCSIVHostDeviceSetUsedBy(host, drv_name, dom_name) < 0) - goto error; + for (i =3D 0; i < virSCSIVHostDeviceListCount(list); i++) { + tmp =3D virSCSIVHostDeviceListGet(list, i); =20 - VIR_DEBUG("Adding %s to activeSCSIVHostHostdevs", - virSCSIVHostDeviceGetName(host)); + VIR_DEBUG("Adding %s to activeSCSIVHostHostdevs", + virSCSIVHostDeviceGetName(tmp)); =20 - if (virSCSIVHostDeviceListAdd(mgr->activeSCSIVHostHostdevs, ho= st) < 0) - goto error; - } + if (virSCSIVHostDeviceListAdd(mgr->activeSCSIVHostHostdevs, tmp) <= 0) + goto rollback; } =20 virObjectUnlock(mgr->activeSCSIVHostHostdevs); @@ -1721,7 +1711,8 @@ virHostdevPrepareSCSIVHostDevices(virHostdevManagerPt= r mgr, } =20 return 0; - error: + + rollback: for (j =3D 0; j < i; j++) { tmp =3D virSCSIVHostDeviceListGet(list, i); virSCSIVHostDeviceListSteal(mgr->activeSCSIVHostHostdevs, tmp); --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 1 04:00:06 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1560863167; cv=none; d=zoho.com; s=zohoarc; b=muEHeBFYqosbNSCN7TkmBnmp66c04MFDiK2Gnew9gVIOCUSCAwIOxTo1CSH4SBVN/hulEP8msANoKxSb9xKQo7kG34aQGhbpSAoPJ3fhabL9gBezGHVc22+hb8uhs4CF1R1LummL640LJCQysaAsTnB4OhdFW5PsEB6raUIAbWg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1560863167; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=V0JOIsZc5rsd02mza/qijcMCu8d/TDXSqC7ett7TR8Q=; b=bglHkpiCg8ucuo6IqcQQvifDgIopr3xRhS/VXHqF3eqShuEJPKkemg0Zf0OLHalLTh4TcRdx+EL8QnITPqXYaroFqoQDY7UCVtZyiIjaYwQGjOyj1n6172aUI4ToA74TIBdl82cET6t+J1m5tv7hSwp9Inc0ld2XoRUm7U5k2fs= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1560863167982296.2479326500578; Tue, 18 Jun 2019 06:06:07 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6230D7FDF6; Tue, 18 Jun 2019 13:05:59 +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 378F036FA; Tue, 18 Jun 2019 13:05:58 +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 E946819728; Tue, 18 Jun 2019 13:05:55 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x5ID4w5P017667 for ; Tue, 18 Jun 2019 09:04:58 -0400 Received: by smtp.corp.redhat.com (Postfix) id 41E4A7D56C; Tue, 18 Jun 2019 13:04:58 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id C12677E66D for ; Tue, 18 Jun 2019 13:04:55 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Tue, 18 Jun 2019 15:04:27 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 8/8] virhostdev: Use VIR_AUTOPTR more X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Tue, 18 Jun 2019 13:06:06 +0000 (UTC) Content-Type: text/plain; charset="utf-8" There are couple of functions which get shorter after the treatment. Signed-off-by: Michal Privoznik Reviewed-by: J=C3=A1n Tomko --- src/util/virhostdev.c | 40 ++++++++++++++++------------------------ 1 file changed, 16 insertions(+), 24 deletions(-) diff --git a/src/util/virhostdev.c b/src/util/virhostdev.c index fe2d774857..271a654a28 100644 --- a/src/util/virhostdev.c +++ b/src/util/virhostdev.c @@ -1161,7 +1161,7 @@ virHostdevUpdateActiveUSBDevices(virHostdevManagerPtr= mgr, virObjectLock(mgr->activeUSBHostdevs); for (i =3D 0; i < nhostdevs; i++) { virDomainHostdevSubsysUSBPtr usbsrc; - virUSBDevicePtr usb =3D NULL; + VIR_AUTOPTR(virUSBDevice) usb =3D NULL; hostdev =3D hostdevs[i]; usbsrc =3D &hostdev->source.subsys.u.usb; =20 @@ -1178,10 +1178,9 @@ virHostdevUpdateActiveUSBDevices(virHostdevManagerPt= r mgr, =20 virUSBDeviceSetUsedBy(usb, drv_name, dom_name); =20 - if (virUSBDeviceListAdd(mgr->activeUSBHostdevs, &usb) < 0) { - virUSBDeviceFree(usb); + if (virUSBDeviceListAdd(mgr->activeUSBHostdevs, &usb) < 0) goto cleanup; - } + usb =3D NULL; } ret =3D 0; cleanup: @@ -1197,7 +1196,7 @@ virHostdevUpdateActiveSCSIHostDevices(virHostdevManag= erPtr mgr, const char *dom_name) { virDomainHostdevSubsysSCSIHostPtr scsihostsrc =3D &scsisrc->u.host; - virSCSIDevicePtr scsi =3D NULL; + VIR_AUTOPTR(virSCSIDevice) scsi =3D NULL; virSCSIDevicePtr tmp =3D NULL; =20 if (!(scsi =3D virSCSIDeviceNew(NULL, @@ -1207,17 +1206,13 @@ virHostdevUpdateActiveSCSIHostDevices(virHostdevMan= agerPtr mgr, return -1; =20 if ((tmp =3D virSCSIDeviceListFind(mgr->activeSCSIHostdevs, scsi))) { - if (virSCSIDeviceSetUsedBy(tmp, drv_name, dom_name) < 0) { - virSCSIDeviceFree(scsi); + if (virSCSIDeviceSetUsedBy(tmp, drv_name, dom_name) < 0) return -1; - } - virSCSIDeviceFree(scsi); } else { if (virSCSIDeviceSetUsedBy(scsi, drv_name, dom_name) < 0 || - virSCSIDeviceListAdd(mgr->activeSCSIHostdevs, scsi) < 0) { - virSCSIDeviceFree(scsi); + virSCSIDeviceListAdd(mgr->activeSCSIHostdevs, scsi) < 0) return -1; - } + scsi =3D NULL; } return 0; } @@ -1472,7 +1467,7 @@ virHostdevPrepareUSBDevices(virHostdevManagerPtr mgr, for (i =3D 0; i < nhostdevs; i++) { virDomainHostdevDefPtr hostdev =3D hostdevs[i]; bool required =3D true; - virUSBDevicePtr usb; + VIR_AUTOPTR(virUSBDevice) usb =3D NULL; =20 if (hostdev->mode !=3D VIR_DOMAIN_HOSTDEV_MODE_SUBSYS) continue; @@ -1487,10 +1482,9 @@ virHostdevPrepareUSBDevices(virHostdevManagerPtr mgr, if (virHostdevFindUSBDevice(hostdev, required, &usb) < 0) return -1; =20 - if (usb && virUSBDeviceListAdd(list, &usb) < 0) { - virUSBDeviceFree(usb); + if (usb && virUSBDeviceListAdd(list, &usb) < 0) return -1; - } + usb =3D NULL; } =20 /* Mark devices in temporary list as used by @dom_name @@ -1518,7 +1512,7 @@ virHostdevPrepareSCSIHostDevices(virDomainHostdevDefP= tr hostdev, virSCSIDeviceListPtr list) { virDomainHostdevSubsysSCSIHostPtr scsihostsrc =3D &scsisrc->u.host; - virSCSIDevicePtr scsi; + VIR_AUTOPTR(virSCSIDevice) scsi =3D NULL; =20 if (hostdev->managed) { virReportError(VIR_ERR_XML_ERROR, "%s", @@ -1532,10 +1526,9 @@ virHostdevPrepareSCSIHostDevices(virDomainHostdevDef= Ptr hostdev, hostdev->readonly, hostdev->shareable))) return -1; =20 - if (virSCSIDeviceListAdd(list, scsi) < 0) { - virSCSIDeviceFree(scsi); + if (virSCSIDeviceListAdd(list, scsi) < 0) return -1; - } + scsi =3D NULL; =20 return 0; } @@ -1746,7 +1739,7 @@ virHostdevPrepareMediatedDevices(virHostdevManagerPtr= mgr, for (i =3D 0; i < nhostdevs; i++) { virDomainHostdevDefPtr hostdev =3D hostdevs[i]; virDomainHostdevSubsysMediatedDevPtr src =3D &hostdev->source.subs= ys.u.mdev; - virMediatedDevicePtr mdev; + VIR_AUTOPTR(virMediatedDevice) mdev =3D NULL; =20 if (!virHostdevIsMdevDevice(hostdev)) continue; @@ -1754,10 +1747,9 @@ virHostdevPrepareMediatedDevices(virHostdevManagerPt= r mgr, if (!(mdev =3D virMediatedDeviceNew(src->uuidstr, src->model))) return -1; =20 - if (virMediatedDeviceListAdd(list, &mdev) < 0) { - virMediatedDeviceFree(mdev); + if (virMediatedDeviceListAdd(list, &mdev) < 0) return -1; - } + mdev =3D NULL; } =20 /* Mark the devices in the list as used by @drv_name-@dom_name and cop= y the --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list