From nobody Sun Feb 8 12:33:05 2026 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=1608568007; cv=none; d=zohomail.com; s=zohoarc; b=dTYa+6jJYOooqSDQy50r3uit7XU9RrphDGVLNRyT+jtqlY5u165sTdsGZuItRCMBOLEXlSDyhYaBwGJK9Py5q0DcbTV/zhhtuU1a0ziLYmhUjdif4xamUr2BBjzfF+zQbI6iR7Zrr1nVgum5PVcN53UWiohPSYsCN6BMc7z7aeI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608568007; 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=Z8bGHxvkYFIf8OK2etOxAkB2AmEhAIucX9jWhQ0yKuQ=; b=WvWM4rINxAQ6aq+JwY1uztwJcfn3fQ/hyFzMcJNBQmHJW/lHeSn9EHcq+sJXL/WL2d1M1zMFWT6uK3Y8HapPqGJoPD7ewlmzzBPiTPO1ai/1sdUJlkTSRwNv47Uao8AaIW9Od7GD1u8YZueeofe2U6lpmndVl6Y7aGmnbm5pXtQ= 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) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 160856800763562.62613002470823; Mon, 21 Dec 2020 08:26:47 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-523-H71vxe8FMIu3dhoUHhx1ng-1; Mon, 21 Dec 2020 11:21:43 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 34B6A9CC3F; Mon, 21 Dec 2020 16:21:34 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 11BE26F96F; Mon, 21 Dec 2020 16:21:34 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id CB43F5002C; Mon, 21 Dec 2020 16:21:33 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0BLGJMnw010609 for ; Mon, 21 Dec 2020 11:19:22 -0500 Received: by smtp.corp.redhat.com (Postfix) id 974AE5D9D3; Mon, 21 Dec 2020 16:19:22 +0000 (UTC) Received: from carol.localdomain (ovpn-117-30.ams2.redhat.com [10.36.117.30]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 44A325D9D7 for ; Mon, 21 Dec 2020 16:19:19 +0000 (UTC) Received: from carol.redhat.com (carol.k8r.cz [127.0.0.1]) by carol.localdomain (Postfix) with ESMTP id C58A4C227B1 for ; Mon, 21 Dec 2020 17:19:17 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1608567706; 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=Z8bGHxvkYFIf8OK2etOxAkB2AmEhAIucX9jWhQ0yKuQ=; b=DYtVSC1+150Plv+nnJpVLR2YYLMgnV0HKuRJoMzpoUBpp7vzH/fEZ1zBrUillWaxRP0gj3 h9MO8mEK8aakvYV8efE9koAoIebzkR9I+2Jnx+pPbiBgNhHzfG3+Jq64hWvyvq35bm21ld FCHtu+g1iJrw4R9ep7ov8MgSL7sqyh8= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1608568006; 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=Z8bGHxvkYFIf8OK2etOxAkB2AmEhAIucX9jWhQ0yKuQ=; b=GL2OFg9imVmwQsG8mwG6B6aLU6+vuCLtECHZvGvL2BXfTegdOMuyLCK+Ez3ZCYshOIt8jk 6MPKkTzmxVmmqikRdCI71ZSW72GtqcxPbek0TPAwEtOwmlVpNzQLUVayitJZ/0GrgjKDtH 3Cj8TUpREWr3SodzbAlmrb1FmAwq1IY= X-MC-Unique: H71vxe8FMIu3dhoUHhx1ng-1 From: Martin Kletzander To: libvir-list@redhat.com Subject: [libvirt PATCH v2 1/5] esx: Unindent unnecessary conditional branch Date: Mon, 21 Dec 2020 17:19:13 +0100 Message-Id: <8ef595e1e6ab812687e0280e1f4cbc638892d455.1608567530.git.mkletzan@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Clacks-Overhead: GNU Terry Pratchett X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 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.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) (identity @redhat.com) Content-Type: text/plain; charset="utf-8" The positive branch can just return and the huge negative part does not nee= d to be indented an extra level. Best viewed with `-w`. Signed-off-by: Martin Kletzander --- src/esx/esx_driver.c | 144 +++++++++++++++++++++---------------------- 1 file changed, 72 insertions(+), 72 deletions(-) diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c index a17bf58a5124..51c26e29c65e 100644 --- a/src/esx/esx_driver.c +++ b/src/esx/esx_driver.c @@ -143,100 +143,100 @@ esxParseVMXFileName(const char *fileName, void *opa= que) =20 if (!strchr(fileName, '/') && !strchr(fileName, '\\')) { /* Plain file name, use same directory as for the .vmx file */ - result =3D g_strdup_printf("%s/%s", data->datastorePathWithoutFile= Name, - fileName); - } else { - if (esxVI_String_AppendValueToList(&propertyNameList, - "summary.name") < 0 || - esxVI_LookupDatastoreList(data->ctx, propertyNameList, - &datastoreList) < 0) { - return NULL; - } + return g_strdup_printf("%s/%s", data->datastorePathWithoutFileName, + fileName); + } =20 - /* Search for datastore by mount path */ - for (datastore =3D datastoreList; datastore; - datastore =3D datastore->_next) { - esxVI_DatastoreHostMount_Free(&hostMount); - datastoreName =3D NULL; - - if (esxVI_LookupDatastoreHostMount(data->ctx, datastore->obj, - &hostMount, - esxVI_Occurrence_RequiredIt= em) < 0 || - esxVI_GetStringValue(datastore, "summary.name", &datastore= Name, - esxVI_Occurrence_RequiredItem) < 0) { - goto cleanup; - } + if (esxVI_String_AppendValueToList(&propertyNameList, + "summary.name") < 0 || + esxVI_LookupDatastoreList(data->ctx, propertyNameList, + &datastoreList) < 0) { + return NULL; + } =20 - tmp =3D (char *)STRSKIP(fileName, hostMount->mountInfo->path); + /* Search for datastore by mount path */ + for (datastore =3D datastoreList; datastore; + datastore =3D datastore->_next) { + esxVI_DatastoreHostMount_Free(&hostMount); + datastoreName =3D NULL; =20 - if (!tmp) - continue; + if (esxVI_LookupDatastoreHostMount(data->ctx, datastore->obj, + &hostMount, + esxVI_Occurrence_RequiredItem) = < 0 || + esxVI_GetStringValue(datastore, "summary.name", &datastoreName, + esxVI_Occurrence_RequiredItem) < 0) { + goto cleanup; + } =20 - /* Found a match. Strip leading separators */ - while (*tmp =3D=3D '/' || *tmp =3D=3D '\\') - ++tmp; + tmp =3D (char *)STRSKIP(fileName, hostMount->mountInfo->path); =20 - strippedFileName =3D g_strdup(tmp); + if (!tmp) + continue; =20 - tmp =3D strippedFileName; + /* Found a match. Strip leading separators */ + while (*tmp =3D=3D '/' || *tmp =3D=3D '\\') + ++tmp; =20 - /* Convert \ to / */ - while (*tmp !=3D '\0') { - if (*tmp =3D=3D '\\') - *tmp =3D '/'; + strippedFileName =3D g_strdup(tmp); =20 - ++tmp; - } + tmp =3D strippedFileName; =20 - result =3D g_strdup_printf("[%s] %s", datastoreName, strippedF= ileName); + /* Convert \ to / */ + while (*tmp !=3D '\0') { + if (*tmp =3D=3D '\\') + *tmp =3D '/'; =20 - break; + ++tmp; } =20 - /* Fallback to direct datastore name match */ - if (!result && STRPREFIX(fileName, "/vmfs/volumes/")) { - copyOfFileName =3D g_strdup(fileName); - - /* Expected format: '/vmfs/volumes//' */ - if (!(tmp =3D STRSKIP(copyOfFileName, "/vmfs/volumes/")) || - !(datastoreName =3D strtok_r(tmp, "/", &saveptr)) || - !(directoryAndFileName =3D strtok_r(NULL, "", &saveptr))) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("File name '%s' doesn't have expected for= mat " - "'/vmfs/volumes//'"), fi= leName); - goto cleanup; - } - - esxVI_ObjectContent_Free(&datastoreList); + result =3D g_strdup_printf("[%s] %s", datastoreName, strippedFileN= ame); =20 - if (esxVI_LookupDatastoreByName(data->ctx, datastoreName, - NULL, &datastoreList, - esxVI_Occurrence_OptionalItem)= < 0) { - goto cleanup; - } + break; + } =20 - if (!datastoreList) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("File name '%s' refers to non-existing da= tastore '%s'"), - fileName, datastoreName); - goto cleanup; - } + /* Fallback to direct datastore name match */ + if (!result && STRPREFIX(fileName, "/vmfs/volumes/")) { + copyOfFileName =3D g_strdup(fileName); =20 - result =3D g_strdup_printf("[%s] %s", datastoreName, - directoryAndFileName); + /* Expected format: '/vmfs/volumes//' */ + if (!(tmp =3D STRSKIP(copyOfFileName, "/vmfs/volumes/")) || + !(datastoreName =3D strtok_r(tmp, "/", &saveptr)) || + !(directoryAndFileName =3D strtok_r(NULL, "", &saveptr))) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("File name '%s' doesn't have expected format " + "'/vmfs/volumes//'"), fileNa= me); + goto cleanup; } =20 - /* If it's an absolute path outside of a datastore just use it as = is */ - if (!result && *fileName =3D=3D '/') { - /* FIXME: need to deal with Windows paths here too */ - result =3D g_strdup(fileName); + esxVI_ObjectContent_Free(&datastoreList); + + if (esxVI_LookupDatastoreByName(data->ctx, datastoreName, + NULL, &datastoreList, + esxVI_Occurrence_OptionalItem) < 0= ) { + goto cleanup; } =20 - if (!result) { + if (!datastoreList) { virReportError(VIR_ERR_INTERNAL_ERROR, - _("Could not handle file name '%s'"), fileName); + _("File name '%s' refers to non-existing datast= ore '%s'"), + fileName, datastoreName); goto cleanup; } + + result =3D g_strdup_printf("[%s] %s", datastoreName, + directoryAndFileName); + } + + /* If it's an absolute path outside of a datastore just use it as is */ + if (!result && *fileName =3D=3D '/') { + /* FIXME: need to deal with Windows paths here too */ + result =3D g_strdup(fileName); + } + + if (!result) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Could not handle file name '%s'"), fileName); + goto cleanup; } =20 cleanup: --=20 2.29.2