From nobody Sun Feb 8 12:13:59 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.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 63.128.21.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=1609862107; cv=none; d=zohomail.com; s=zohoarc; b=aWBLSEIf3iycpGKz0CWZ1WPG7jeOGRh49fFOfcFzjanNbPvj481g0ctUpR3gkR2Kxngks5m/jh9klpEAEBp3r503yc7VwaRtbFwxeW7B0CGPMqWvHYqR/p1JfYwCdoIpzLO0Vij8wbyGxIdUG16tU/lVeZOmX3S7a0kIehFNrSA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1609862107; 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=Zvkpmr/NEv6x+5uTzOkFAEdG8CqFLSUMmpjFtPcMk5Q=; b=T6TsZwSeWNaBdeq3bMY/RwCDcCyarVUEBy+gvp/Iclqmj5KC0oYdGVhVX+tvraK303SDhTRIugGoN+Drbkt1la3tebtbbSulgnbnBRzDOaET6qIuWZ+G8YGJRZnHwyFKvwyI71ekYJSuHMFrg4u0R72On7GEbssredum/kSW7VM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.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 [63.128.21.124]) by mx.zohomail.com with SMTPS id 160986210734184.21174871501103; Tue, 5 Jan 2021 07:55:07 -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-272-Wpse5AjlNCmYTzhnmEFUIw-1; Tue, 05 Jan 2021 10:55:03 -0500 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 B0D7B100C676; Tue, 5 Jan 2021 15:54:57 +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 7E1CE1002391; Tue, 5 Jan 2021 15:54:57 +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 0136D4A7C6; Tue, 5 Jan 2021 15:54:53 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 105FsqZV020933 for ; Tue, 5 Jan 2021 10:54:52 -0500 Received: by smtp.corp.redhat.com (Postfix) id A34311001B2C; Tue, 5 Jan 2021 15:54:52 +0000 (UTC) Received: from carol.localdomain (unknown [10.40.193.241]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4DCDB10016DB for ; Tue, 5 Jan 2021 15:54:49 +0000 (UTC) Received: from carol.redhat.com (carol.k8r.cz [127.0.0.1]) by carol.localdomain (Postfix) with ESMTP id D8D1EC20022 for ; Tue, 5 Jan 2021 16:54:47 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1609862106; 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=Zvkpmr/NEv6x+5uTzOkFAEdG8CqFLSUMmpjFtPcMk5Q=; b=Wsb2vJWnM5EV6YBlbyY7hVYcDAa4CxfYtNlS53wRIqtBoCb84Hp0zKB3WalEbPrqjlkZNV 6BclaL//6+/yw3bXUXwyxTSn6r44S5IPrZpcWLqN4RH6rSLH/tCCaOPUkJi5OFyz/tJwfV wi2FLRUS/hEKYsouR44SA+RwTlVV2ck= X-MC-Unique: Wpse5AjlNCmYTzhnmEFUIw-1 From: Martin Kletzander To: libvir-list@redhat.com Subject: [libvirt PATCH v3 1/8] esx: Unindent unnecessary conditional branch Date: Tue, 5 Jan 2021 16:54:40 +0100 Message-Id: <22eea866384b579aa5f1b3673f222bf79fc68d41.1609862070.git.mkletzan@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Clacks-Overhead: GNU Terry Pratchett X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 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" 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.30.0