From nobody Wed May 8 07:55:31 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; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 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=1624021510; cv=none; d=zohomail.com; s=zohoarc; b=n4MQ1MOxlyMKPXdHNbCTaGe9KThs8v4Yx8AeSEfAIZpySzuFshCcPBuFKkwOeqW89ZUUf3tAP6+JF+kWafIMYxsyQgE1H2qzW5eYLQNzF9dZhK2m3+k8l75IRvRk1FJDMKrxAOVQizXJDLPqfuaRGCKFSynODKx9EHYZdbGXfVI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1624021510; 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; bh=UCadSFL3GmK81hbnEBdDpX9XvEELxu2cMh/5rTbwgGY=; b=hVMO1aCSW4HOuaQeY879K+b2t/RggoBkmwEUB7VBChP1khND+SLSimBpjbRiVT0MiGMWHykp0Lz4MF9YwU7B3qz7KdrBC6GkU9YzAeSnKvwJs4tWbDPSh/tXH6BzSHSxIHaU7wluXsweKAN5Q3xkzbU3WCkqYwmlHv87XSS1lGs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) 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 1624021510537348.5779695164522; Fri, 18 Jun 2021 06:05:10 -0700 (PDT) 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-485-WBXQ5sQWO12y31cuIc7hsg-1; Fri, 18 Jun 2021 09:05:07 -0400 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 CD03BFCB1; Fri, 18 Jun 2021 13:05:01 +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 7ABCF60FC2; Fri, 18 Jun 2021 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 75D611809C9A; Fri, 18 Jun 2021 13:04:56 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 15ID4thi032726 for ; Fri, 18 Jun 2021 09:04:55 -0400 Received: by smtp.corp.redhat.com (Postfix) id 80DFE5C224; Fri, 18 Jun 2021 13:04:55 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.13]) by smtp.corp.redhat.com (Postfix) with ESMTP id E5F215C233 for ; Fri, 18 Jun 2021 13:04:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1624021509; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=UCadSFL3GmK81hbnEBdDpX9XvEELxu2cMh/5rTbwgGY=; b=GaBTrcbshlImAgDEeRjcj5Lqz4lnsVcpxVztg4SDwROtORPXTkRl5nxE0CfnPA8AMJPwik EsNkDqcaQw2w4uV3VLH0U+IvyjsvjDZ+HInueK4f5pik520eh2Omxk3PwBnhkUMdJh2Lya kyh/CwCO6qP8zhsiZGAOgIWnothnAlU= X-MC-Unique: WBXQ5sQWO12y31cuIc7hsg-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 1/4] conf: storage: Introduce virStoragePoolSourceListFree Date: Fri, 18 Jun 2021 15:04:46 +0200 Message-Id: <2bfba48992b343c096dfd542cff7c3d03ddb788d.1624021457.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com 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 X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/conf/storage_conf.c | 16 ++++++++++++++++ src/conf/storage_conf.h | 5 +++++ src/libvirt_private.syms | 1 + 3 files changed, 22 insertions(+) diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c index 0ecdb0969a..2aa9a3d8f9 100644 --- a/src/conf/storage_conf.c +++ b/src/conf/storage_conf.c @@ -1803,3 +1803,19 @@ virStoragePoolSourceListFormat(virStoragePoolSourceL= ist *def) return virBufferContentAndReset(&buf); } + + +void +virStoragePoolSourceListFree(virStoragePoolSourceList *list) +{ + size_t i; + + if (!list) + return; + + for (i =3D 0; i < list->nsources; i++) + virStoragePoolSourceClear(&list->sources[i]); + + g_free(list->sources); + g_free(list); +} diff --git a/src/conf/storage_conf.h b/src/conf/storage_conf.h index 345026aa37..76efaac531 100644 --- a/src/conf/storage_conf.h +++ b/src/conf/storage_conf.h @@ -266,6 +266,11 @@ struct _virStoragePoolSourceList { virStoragePoolSource *sources; }; +void +virStoragePoolSourceListFree(virStoragePoolSourceList *list); +G_DEFINE_AUTOPTR_CLEANUP_FUNC(virStoragePoolSourceList, virStoragePoolSour= ceListFree); + + virStoragePoolDef * virStoragePoolDefParseXML(xmlXPathContextPtr ctxt); diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 2efa787664..68e4b6aab8 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1048,6 +1048,7 @@ virStoragePoolSourceClear; virStoragePoolSourceDeviceClear; virStoragePoolSourceFree; virStoragePoolSourceListFormat; +virStoragePoolSourceListFree; virStoragePoolSourceListNewSource; virStoragePoolTypeFromString; virStoragePoolTypeToString; --=20 2.31.1 From nobody Wed May 8 07:55:31 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; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 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=1624021511; cv=none; d=zohomail.com; s=zohoarc; b=dS7rlnnYVJA6oVxhJx2gwexuQIOUY7D/EwKlLx0x56H6jVH53QKjeRLC85fSG/MpMypbD3OzTuKQYSD4+n9qxynz4Xt4I1T8Q4rvO5JtYtsaScjetSx8f+LLXP7Wp+2/TCIyccLzGn+Ks4YjdwahQO13958X+c8hUDvbxegiLf4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1624021511; 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; bh=stnn3LZLFOntJm5JUatwqFx5LkcpGKje8z4s66xbxu4=; b=fQgQpJ+GA5yD1r6KEYH7h8csWZa5jS2r0MTRTd2nlew8wlAa3ksLBPRfTIawklYgX4tFYUD6RmsH99aGENOW+EeqVdqcoWdcH7y7JCnvI4/yeLaLtYT4gYVDkppO+ijJ2LeCzjCu7u8PmVd7zxVt9kJb9GYkGIiVnUzVaDfQDGY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) 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 1624021511762473.69108548069664; Fri, 18 Jun 2021 06:05:11 -0700 (PDT) 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-509-FUMA3z_PMciTF6L9yeL5SQ-1; Fri, 18 Jun 2021 09:05:09 -0400 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 81759100C61B; Fri, 18 Jun 2021 13:05:03 +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 4BF4E3AC3; Fri, 18 Jun 2021 13:05:03 +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 8AE6846F82; Fri, 18 Jun 2021 13:05:02 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 15ID4u63032733 for ; Fri, 18 Jun 2021 09:04:56 -0400 Received: by smtp.corp.redhat.com (Postfix) id 874D65C233; Fri, 18 Jun 2021 13:04:56 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.13]) by smtp.corp.redhat.com (Postfix) with ESMTP id DF0E85C224 for ; Fri, 18 Jun 2021 13:04:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1624021510; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=stnn3LZLFOntJm5JUatwqFx5LkcpGKje8z4s66xbxu4=; b=GscfBjfL7RUgfychwg+Khovmz9oLhq0kyMJBcLLTub4ioD4G0vuoxZHQjk4o5LIqcm5VaH z+O/HPnHOjR1zIn+UAk+0Oi6x7dHrou0uqfokiy59ZX/D7BWqPlv1U7g3A4oPx1NLohKwi Bf9uohSccbJ/nGjItYc0SbNCjGG5tJA= X-MC-Unique: FUMA3z_PMciTF6L9yeL5SQ-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 2/4] virStorageBackendISCSIDirectFindPoolSources: Use allocated virStoragePoolSourceList Date: Fri, 18 Jun 2021 15:04:47 +0200 Message-Id: <7251f7f8cb9d1d387cf88ce97ec40a3852e5624e.1624021457.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com 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 X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Using an allocated version together with copying the host/initiator/device portions into it allows us to switch to automatic clearing rather than open-coding it. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/storage/storage_backend_iscsi_direct.c | 42 ++++++++++------------ 1 file changed, 19 insertions(+), 23 deletions(-) diff --git a/src/storage/storage_backend_iscsi_direct.c b/src/storage/stora= ge_backend_iscsi_direct.c index e4a14c3fd6..263db835ae 100644 --- a/src/storage/storage_backend_iscsi_direct.c +++ b/src/storage/storage_backend_iscsi_direct.c @@ -495,23 +495,21 @@ virStorageBackendISCSIDirectFindPoolSources(const cha= r *srcSpec, char **targets =3D NULL; char *ret =3D NULL; size_t i; - virStoragePoolSourceList list =3D { - .type =3D VIR_STORAGE_POOL_ISCSI_DIRECT, - .nsources =3D 0, - .sources =3D NULL - }; + g_autoptr(virStoragePoolSourceList) list =3D g_new0(virStoragePoolSour= ceList, 1); g_autofree char *portal =3D NULL; g_autoptr(virStoragePoolSource) source =3D NULL; virCheckFlags(0, NULL); + list->type =3D VIR_STORAGE_POOL_ISCSI_DIRECT; + if (!srcSpec) { virReportError(VIR_ERR_INVALID_ARG, "%s", _("hostname must be specified for iscsi sources")); return NULL; } - if (!(source =3D virStoragePoolDefParseSourceString(srcSpec, list.type= ))) + if (!(source =3D virStoragePoolDefParseSourceString(srcSpec, list->typ= e))) return NULL; if (source->nhost !=3D 1) { @@ -532,30 +530,28 @@ virStorageBackendISCSIDirectFindPoolSources(const cha= r *srcSpec, if (virISCSIDirectScanTargets(source->initiator.iqn, portal, &ntargets= , &targets) < 0) goto cleanup; - list.sources =3D g_new0(virStoragePoolSource, ntargets); + list->sources =3D g_new0(virStoragePoolSource, ntargets); for (i =3D 0; i < ntargets; i++) { - list.sources[i].devices =3D g_new0(virStoragePoolSourceDevice, 1); - list.sources[i].hosts =3D g_new0(virStoragePoolSourceHost, 1); - list.sources[i].nhost =3D 1; - list.sources[i].hosts[0] =3D source->hosts[0]; - list.sources[i].initiator =3D source->initiator; - list.sources[i].ndevice =3D 1; - list.sources[i].devices[0].path =3D targets[i]; - list.nsources++; + list->sources[i].hosts =3D g_new0(virStoragePoolSourceHost, 1); + list->sources[i].nhost =3D 1; + list->sources[i].hosts[0].name =3D g_strdup(source->hosts[0].name); + list->sources[i].hosts[0].port =3D source->hosts[0].port; + + virStorageSourceInitiatorCopy(&list->sources[i].initiator, + &source->initiator); + + list->sources[i].devices =3D g_new0(virStoragePoolSourceDevice, 1); + list->sources[i].ndevice =3D 1; + list->sources[i].devices[0].path =3D g_strdup(targets[i]); + + list->nsources++; } - if (!(ret =3D virStoragePoolSourceListFormat(&list))) + if (!(ret =3D virStoragePoolSourceListFormat(list))) goto cleanup; cleanup: - if (list.sources) { - for (i =3D 0; i < ntargets; i++) { - VIR_FREE(list.sources[i].hosts); - VIR_FREE(list.sources[i].devices); - } - VIR_FREE(list.sources); - } for (i =3D 0; i < ntargets; i++) VIR_FREE(targets[i]); VIR_FREE(targets); --=20 2.31.1 From nobody Wed May 8 07:55:31 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; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 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=1624021525; cv=none; d=zohomail.com; s=zohoarc; b=abEAl5cvJm+IlKBvOBJm35y/4JkQrLVxi+BdxK+7rG3/jdCl+Bwi5YkV+p1AKiV93HBzMcxnbTNCmt6CdOlulMrQ/+oiRPQua8f3PvFCOzbuIPyd6PTepH467YIFBaoYlt6z1xZ8+KPHnjigK+0Dn0wkOr188NtLelWw7zlD9UI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1624021525; 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; bh=NxoGp5oE3UAMmdABjV0wR7uRzZtUYDA2mu46XZOYklA=; b=IdYjOKyYVmee4AWrMfndDfJvHZWVX2o53wKHf6kEX1sHD20D8JpDuruTq0Z2VOIQvnwqoZHKy6EyDNzRYYWKj7QFf09wp1zzp7fsqXu8Odcp3aYXdJaGL7MKwALwF8OkA93Zo2Jc6B2QzneWSiu7VcgyjJjsy8YIXDUjdLYd82w= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) 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 1624021525357796.9339017266602; Fri, 18 Jun 2021 06:05:25 -0700 (PDT) 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-3-Pi2tqFagNZi8ujF1216gPw-1; Fri, 18 Jun 2021 09:05:22 -0400 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 C30321084F42; Fri, 18 Jun 2021 13:05:16 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9A4401036D04; Fri, 18 Jun 2021 13:05: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 43CE046F5E; Fri, 18 Jun 2021 13:05:16 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 15ID4vS8032743 for ; Fri, 18 Jun 2021 09:04:57 -0400 Received: by smtp.corp.redhat.com (Postfix) id 8BE305C233; Fri, 18 Jun 2021 13:04:57 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.13]) by smtp.corp.redhat.com (Postfix) with ESMTP id EF49E5C224 for ; Fri, 18 Jun 2021 13:04:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1624021524; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=NxoGp5oE3UAMmdABjV0wR7uRzZtUYDA2mu46XZOYklA=; b=d2MUET9a6Q+/6MnxiyqXqfzwSMuTKtwXUURpNNmw/C2Y82bbcAd0cuSKPU2ENOO5U0nW3w A2ARIj8BKqTWn5kEDUSyChUf5rUkHVZwal/guQiMravi76sltFLEwbPwdCrZlyLDCh9xGj gwUt0B9Fvl8hmbfDFjTnGGVhIVWM4Jo= X-MC-Unique: Pi2tqFagNZi8ujF1216gPw-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 3/4] virISCSIDirectUpdateTargets: Rework to simplify cleanup and return GStrv Date: Fri, 18 Jun 2021 15:04:48 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com 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 X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Count the elements in advance rather than using VIR_APPEND_ELEMENT and ensure that there's a NULL terminator for the string list so it's GStrv compatible. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/storage/storage_backend_iscsi_direct.c | 29 ++++++++-------------- 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/src/storage/storage_backend_iscsi_direct.c b/src/storage/stora= ge_backend_iscsi_direct.c index 263db835ae..2073a6df38 100644 --- a/src/storage/storage_backend_iscsi_direct.c +++ b/src/storage/storage_backend_iscsi_direct.c @@ -420,37 +420,30 @@ virISCSIDirectUpdateTargets(struct iscsi_context *isc= si, size_t *ntargets, char ***targets) { - int ret =3D -1; struct iscsi_discovery_address *addr; struct iscsi_discovery_address *tmp_addr; - size_t tmp_ntargets =3D 0; - char **tmp_targets =3D NULL; + + *ntargets =3D 0; if (!(addr =3D iscsi_discovery_sync(iscsi))) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Failed to discover session: %s"), iscsi_get_error(iscsi)); - return ret; + return -1; } - for (tmp_addr =3D addr; tmp_addr; tmp_addr =3D tmp_addr->next) { - g_autofree char *target =3D NULL; - - target =3D g_strdup(tmp_addr->target_name); + for (tmp_addr =3D addr; tmp_addr; tmp_addr =3D tmp_addr->next) + (*ntargets)++; - if (VIR_APPEND_ELEMENT(tmp_targets, tmp_ntargets, target) < 0) - goto cleanup; - } + *targets =3D g_new0(char *, ntargets + 1); + *ntargets =3D 0; - *targets =3D g_steal_pointer(&tmp_targets); - *ntargets =3D tmp_ntargets; - tmp_ntargets =3D 0; + for (tmp_addr =3D addr; tmp_addr; tmp_addr =3D tmp_addr->next) + *targets[(*ntargets)++] =3D g_strdup(tmp_addr->target_name); - ret =3D 0; - cleanup: iscsi_free_discovery_data(iscsi, addr); - virStringListFreeCount(tmp_targets, tmp_ntargets); - return ret; + + return 0; } static int --=20 2.31.1 From nobody Wed May 8 07:55:31 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; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 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=1624021525; cv=none; d=zohomail.com; s=zohoarc; b=DmsSc1Q+yhYsoSPatMsbSfXkJvPk9fwXG4hS74UwFd+Pv/FB2aSwfG9bW6TAFVVv/2xA32vNCZp1sU0ajCk991rRWpRbEHD95TWFMAwPhMBng+y7uiLSoenyGDxZMFRC8ftVEvOvAFiwSSqHZbuU384KxzLnEurXDmuoMLIj0eg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1624021525; 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; bh=vvERl38SF4TGFLiJSDYvH54Gyr8jJjyXNPcRMN2TwYY=; b=baCWrzWHxuJn6ZaXZkeykgfA158bjZWA99SEiTd7wBRElnkcRMgPd1HkzeqhZlsVjKGfW+ca9Hmr8WQrkJyKl1nManeRQa111osnI+cuqE44a4VhdhaCcjy58akB394tkmf5k41i8hnXKj7vlbI1ycznm79fO2LLbsNNPEafBxk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) 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 1624021525148923.1347755169053; Fri, 18 Jun 2021 06:05:25 -0700 (PDT) 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-AtpoXgyTNyS2oER2LY5c-Q-1; Fri, 18 Jun 2021 09:05:22 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B5C6D100B3B2; Fri, 18 Jun 2021 13:05:16 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 92DAE5C224; Fri, 18 Jun 2021 13:05: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 3CBCE46F5D; Fri, 18 Jun 2021 13:05:16 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 15ID4wfN032751 for ; Fri, 18 Jun 2021 09:04:58 -0400 Received: by smtp.corp.redhat.com (Postfix) id 8F5D35C233; Fri, 18 Jun 2021 13:04:58 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.13]) by smtp.corp.redhat.com (Postfix) with ESMTP id EA1065C224 for ; Fri, 18 Jun 2021 13:04:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1624021524; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=vvERl38SF4TGFLiJSDYvH54Gyr8jJjyXNPcRMN2TwYY=; b=LOR2LH0I27qQ3MxfpIWcvgZmpdhrULo4qRIS2Oh+Up98UWHvj4reVeWufF2VpVVBufifef wYQ6cIOrqfJTmcIlS4fW2gTQSGxHgR1a45r7t7lP2NGelmAg5yIEA11i+YOiB41i7es9pD saTanEJLYw3jSmUoxbRWQxS9IIH946E= X-MC-Unique: AtpoXgyTNyS2oER2LY5c-Q-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 4/4] virStorageBackendISCSIDirectFindPoolSources: Rework cleanup Date: Fri, 18 Jun 2021 15:04:49 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" virISCSIDirectScanTargets now returns a GStrv, so we can use automatic cleanup for it and get rid of the cleanup section. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/storage/storage_backend_iscsi_direct.c | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/src/storage/storage_backend_iscsi_direct.c b/src/storage/stora= ge_backend_iscsi_direct.c index 2073a6df38..b108b12f7b 100644 --- a/src/storage/storage_backend_iscsi_direct.c +++ b/src/storage/storage_backend_iscsi_direct.c @@ -485,8 +485,7 @@ virStorageBackendISCSIDirectFindPoolSources(const char = *srcSpec, unsigned int flags) { size_t ntargets =3D 0; - char **targets =3D NULL; - char *ret =3D NULL; + g_auto(GStrv) targets =3D NULL; size_t i; g_autoptr(virStoragePoolSourceList) list =3D g_new0(virStoragePoolSour= ceList, 1); g_autofree char *portal =3D NULL; @@ -508,20 +507,20 @@ virStorageBackendISCSIDirectFindPoolSources(const cha= r *srcSpec, if (source->nhost !=3D 1) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("Expected exactly 1 host for the storage pool")); - goto cleanup; + return NULL; } if (!source->initiator.iqn) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("missing initiator IQN")); - goto cleanup; + return NULL; } if (!(portal =3D virStorageBackendISCSIDirectPortal(source))) - goto cleanup; + return NULL; if (virISCSIDirectScanTargets(source->initiator.iqn, portal, &ntargets= , &targets) < 0) - goto cleanup; + return NULL; list->sources =3D g_new0(virStoragePoolSource, ntargets); @@ -541,14 +540,7 @@ virStorageBackendISCSIDirectFindPoolSources(const char= *srcSpec, list->nsources++; } - if (!(ret =3D virStoragePoolSourceListFormat(list))) - goto cleanup; - - cleanup: - for (i =3D 0; i < ntargets; i++) - VIR_FREE(targets[i]); - VIR_FREE(targets); - return ret; + return virStoragePoolSourceListFormat(list); } static struct iscsi_context * --=20 2.31.1