From nobody Mon Feb 9 00:20:08 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1549651105606802.5365130304567; Fri, 8 Feb 2019 10:38:25 -0800 (PST) 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 mx1.redhat.com (Postfix) with ESMTPS id 8C7E82CD801; Fri, 8 Feb 2019 18:38: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 F32BD6012B; Fri, 8 Feb 2019 18:38: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 A80503F616; Fri, 8 Feb 2019 18:38:21 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x18IbeEW007619 for ; Fri, 8 Feb 2019 13:37:40 -0500 Received: by smtp.corp.redhat.com (Postfix) id EC6CD4250; Fri, 8 Feb 2019 18:37:40 +0000 (UTC) Received: from unknown0050b6a41c42.attlocal.net.com (ovpn-117-20.phx2.redhat.com [10.3.117.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9378560BE0; Fri, 8 Feb 2019 18:37:40 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Fri, 8 Feb 2019 13:37:07 -0500 Message-Id: <20190208183726.30903-14-jferlan@redhat.com> In-Reply-To: <20190208183726.30903-1-jferlan@redhat.com> References: <20190208183726.30903-1-jferlan@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Cc: Erik Skultety Subject: [libvirt] [PATCH v2 13/32] storage: Use VIR_AUTOFREE for storage driver 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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Fri, 08 Feb 2019 18:38:24 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Let's make use of the auto __cleanup capabilities cleaning up any now unnecessary goto paths. Signed-off-by: John Ferlan Reviewed-by: Erik Skultety Reviewed-by: J=C3=A1n Tomko --- src/storage/storage_driver.c | 70 ++++++++++++------------------------ 1 file changed, 23 insertions(+), 47 deletions(-) diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c index a71a16add1..34634e97d9 100644 --- a/src/storage/storage_driver.c +++ b/src/storage/storage_driver.c @@ -122,7 +122,7 @@ storagePoolUpdateStateCallback(virStoragePoolObjPtr obj, virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(obj); bool active =3D false; virStorageBackendPtr backend; - char *stateFile; + VIR_AUTOFREE(char *) stateFile =3D NULL; =20 if ((backend =3D virStorageBackendForType(def->type)) =3D=3D NULL) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -164,8 +164,6 @@ storagePoolUpdateStateCallback(virStoragePoolObjPtr obj, if (!virStoragePoolObjIsActive(obj)) virStoragePoolUpdateInactive(&obj); =20 - VIR_FREE(stateFile); - return; } =20 @@ -203,7 +201,7 @@ storageDriverAutostartCallback(virStoragePoolObjPtr obj, } =20 if (started) { - char *stateFile; + VIR_AUTOFREE(char *) stateFile =3D NULL; =20 virStoragePoolObjClearVols(obj); stateFile =3D virFileBuildPath(driver->stateDir, def->name, ".xml"= ); @@ -217,7 +215,6 @@ storageDriverAutostartCallback(virStoragePoolObjPtr obj, } else { virStoragePoolObjSetActive(obj, true); } - VIR_FREE(stateFile); } } =20 @@ -240,16 +237,15 @@ storageStateInitialize(bool privileged, virStateInhibitCallback callback ATTRIBUTE_UNUSED, void *opaque ATTRIBUTE_UNUSED) { - int ret =3D -1; - char *configdir =3D NULL; - char *rundir =3D NULL; + VIR_AUTOFREE(char *) configdir =3D NULL; + VIR_AUTOFREE(char *) rundir =3D NULL; =20 if (VIR_ALLOC(driver) < 0) - return ret; + return -1; =20 if (virMutexInit(&driver->lock) < 0) { VIR_FREE(driver); - return ret; + return -1; } storageDriverLock(); =20 @@ -302,16 +298,12 @@ storageStateInitialize(bool privileged, =20 storageDriverUnlock(); =20 - ret =3D 0; - cleanup: - VIR_FREE(configdir); - VIR_FREE(rundir); - return ret; + return 0; =20 error: storageDriverUnlock(); storageStateCleanup(); - goto cleanup; + return -1; } =20 /** @@ -695,9 +687,9 @@ storagePoolCreateXML(virConnectPtr conn, virStoragePoolPtr pool =3D NULL; virStorageBackendPtr backend; virObjectEventPtr event =3D NULL; - char *stateFile =3D NULL; unsigned int build_flags =3D 0; VIR_AUTOPTR(virStoragePoolDef) newDef =3D NULL; + VIR_AUTOFREE(char *) stateFile =3D NULL; =20 virCheckFlags(VIR_STORAGE_POOL_CREATE_WITH_BUILD | VIR_STORAGE_POOL_CREATE_WITH_BUILD_OVERWRITE | @@ -761,7 +753,6 @@ storagePoolCreateXML(virConnectPtr conn, pool =3D virGetStoragePool(conn, def->name, def->uuid, NULL, NULL); =20 cleanup: - VIR_FREE(stateFile); virObjectEventStateQueue(driver->storageEventState, event); virStoragePoolObjEndAPI(&obj); return pool; @@ -892,8 +883,8 @@ storagePoolCreate(virStoragePoolPtr pool, virStorageBackendPtr backend; virObjectEventPtr event =3D NULL; int ret =3D -1; - char *stateFile =3D NULL; unsigned int build_flags =3D 0; + VIR_AUTOFREE(char *) stateFile =3D NULL; =20 virCheckFlags(VIR_STORAGE_POOL_CREATE_WITH_BUILD | VIR_STORAGE_POOL_CREATE_WITH_BUILD_OVERWRITE | @@ -955,7 +946,6 @@ storagePoolCreate(virStoragePoolPtr pool, ret =3D 0; =20 cleanup: - VIR_FREE(stateFile); virObjectEventStateQueue(driver->storageEventState, event); virStoragePoolObjEndAPI(&obj); return ret; @@ -1013,8 +1003,8 @@ storagePoolDestroy(virStoragePoolPtr pool) virStoragePoolDefPtr def; virStorageBackendPtr backend; virObjectEventPtr event =3D NULL; - char *stateFile =3D NULL; int ret =3D -1; + VIR_AUTOFREE(char *) stateFile =3D NULL; =20 if (!(obj =3D storagePoolObjFindByUUID(pool->uuid, pool->name))) goto cleanup; @@ -1045,7 +1035,6 @@ storagePoolDestroy(virStoragePoolPtr pool) goto cleanup; =20 unlink(stateFile); - VIR_FREE(stateFile); =20 if (backend->stopPool && backend->stopPool(obj) < 0) @@ -1078,8 +1067,8 @@ storagePoolDelete(virStoragePoolPtr pool, virStoragePoolDefPtr def; virStorageBackendPtr backend; virObjectEventPtr event =3D NULL; - char *stateFile =3D NULL; int ret =3D -1; + VIR_AUTOFREE(char *) stateFile =3D NULL; =20 if (!(obj =3D virStoragePoolObjFromStoragePool(pool))) return -1; @@ -1111,7 +1100,6 @@ storagePoolDelete(virStoragePoolPtr pool, goto cleanup; =20 unlink(stateFile); - VIR_FREE(stateFile); =20 if (!backend->deletePool) { virReportError(VIR_ERR_NO_SUPPORT, @@ -1172,10 +1160,10 @@ storagePoolRefresh(virStoragePoolPtr pool, =20 virStoragePoolObjClearVols(obj); if (backend->refreshPool(obj) < 0) { - char *stateFile =3D virFileBuildPath(driver->stateDir, def->name, = ".xml"); + VIR_AUTOFREE(char *) stateFile =3D NULL; =20 + stateFile =3D virFileBuildPath(driver->stateDir, def->name, ".xml"= ); storagePoolRefreshFailCleanup(backend, obj, stateFile); - VIR_FREE(stateFile); =20 event =3D virStoragePoolEventLifecycleNew(def->name, def->uuid, @@ -1540,7 +1528,7 @@ storageVolLookupByPathCallback(virStoragePoolObjPtr o= bj, { struct storageVolLookupData *data =3D (struct storageVolLookupData *)o= paque; virStoragePoolDefPtr def; - char *stable_path =3D NULL; + VIR_AUTOFREE(char *) stable_path =3D NULL; =20 if (!virStoragePoolObjIsActive(obj)) return false; @@ -1579,7 +1567,6 @@ storageVolLookupByPathCallback(virStoragePoolObjPtr o= bj, } =20 data->voldef =3D virStorageVolDefFindByPath(obj, stable_path); - VIR_FREE(stable_path); =20 return !!data->voldef; } @@ -1649,7 +1636,7 @@ storagePoolLookupByTargetPath(virConnectPtr conn, virStoragePoolObjPtr obj; virStoragePoolDefPtr def; virStoragePoolPtr pool =3D NULL; - char *cleanpath; + VIR_AUTOFREE(char *) cleanpath =3D NULL; =20 cleanpath =3D virFileSanitizePath(path); if (!cleanpath) @@ -1660,7 +1647,7 @@ storagePoolLookupByTargetPath(virConnectPtr conn, cleanpath))) { def =3D virStoragePoolObjGetDef(obj); if (virStoragePoolLookupByTargetPathEnsureACL(conn, def) < 0) - goto cleanup; + return NULL; =20 pool =3D virGetStoragePool(conn, def->name, def->uuid, NULL, NULL); virStoragePoolObjEndAPI(&obj); @@ -1678,8 +1665,6 @@ storagePoolLookupByTargetPath(virConnectPtr conn, } } =20 - cleanup: - VIR_FREE(cleanpath); return pool; } =20 @@ -2206,40 +2191,31 @@ virStorageVolPoolRefreshDataFree(void *opaque) static int virStorageBackendPloopRestoreDesc(char *path) { - int ret =3D -1; - char *refresh_tool =3D NULL; - char *desc =3D NULL; VIR_AUTOPTR(virCommand) cmd =3D NULL; + VIR_AUTOFREE(char *) refresh_tool =3D NULL; + VIR_AUTOFREE(char *) desc =3D NULL; =20 if (virAsprintf(&desc, "%s/DiskDescriptor.xml", path) < 0) - return ret; + return -1; =20 if (virFileRemove(desc, 0, 0) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("refresh ploop failed:" " unable to delete DiskDescriptor.xml")); - goto cleanup; + return -1; } =20 refresh_tool =3D virFindFileInPath("ploop"); if (!refresh_tool) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("unable to find ploop, please install ploop tools= ")); - goto cleanup; + return -1; } =20 cmd =3D virCommandNewArgList(refresh_tool, "restore-descriptor", path, NULL); virCommandAddArgFormat(cmd, "%s/root.hds", path); - if (virCommandRun(cmd, NULL) < 0) - goto cleanup; - - ret =3D 0; - - cleanup: - VIR_FREE(refresh_tool); - VIR_FREE(desc); - return ret; + return virCommandRun(cmd, NULL); } =20 =20 --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list