From nobody Sun Feb 8 19:59:40 2026 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