From nobody Sun Feb 8 16:53:12 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=1608567772; cv=none; d=zohomail.com; s=zohoarc; b=byEaBCksqYwxhKHpbesoIkE0Ne4dbNAiLNJkly2MA2d2Ri6VMB4L670I+unxmgE4RvXuQb4yskm/WqKRTzkt15nGGotNV6GcsVTHOEs/9/bOdz4mccsjDtXt2ZzVqUa9kqLRn27Wtq8uIsgj3uix71AOB7cU+QwbZ028N18LRTc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608567772; 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=ddIr9ofPHz5hJ/3ssM3Lw1EX6P49xMYAg1K7Yk5hUxI=; b=hdDiUunC+NLmfNutQv+Cx8wr2lgiHdMGkKXWws6TIaz1ozQk/WRfkFKa8dzfI0lrghtzHDyXfO+UAh14txmpvudkIaqtIarx92dhscBdVGjYghnUbwn7LjlRAH+JsMId5s82SMdZjQ75C8uhNZzyZZGGGF+LvlUHXIWPenioboY= 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 1608567772435960.8639560228861; Mon, 21 Dec 2020 08:22:52 -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-246-EZxkwHZ3NAWDUsmckL7MwA-1; Mon, 21 Dec 2020 11:21:42 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3EB3A8018A9; Mon, 21 Dec 2020 16:21:37 +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 EF6B05D9E2; Mon, 21 Dec 2020 16:21:36 +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 B360D5002C; Mon, 21 Dec 2020 16:21:36 +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 0BLGJMxE010614 for ; Mon, 21 Dec 2020 11:19:22 -0500 Received: by smtp.corp.redhat.com (Postfix) id B1FEE5C1D1; 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 5F9865C728 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 C75ECC227B5 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=1608567771; 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=ddIr9ofPHz5hJ/3ssM3Lw1EX6P49xMYAg1K7Yk5hUxI=; b=Cbq7DV+RWL2pEyHnj0hjNO9clfRlMuy3Ve1hLSwhc/Y0gbaJnLVxiZe1jtN10W3Ct6YI9A c2D55KezQ6/d5jbdZSTCKeT7D4svomBdtzMLUfzu0yeMxIlLxTRXKR78aJ6XD8anKU+uXw BbNx4dTsJ5ldQgVB63ArjA0Nj05v+DU= X-MC-Unique: EZxkwHZ3NAWDUsmckL7MwA-1 From: Martin Kletzander To: libvir-list@redhat.com Subject: [libvirt PATCH v2 3/5] vmx: Make virVMXParseFileName return an integer Date: Mon, 21 Dec 2020 17:19:15 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Clacks-Overhead: GNU Terry Pratchett 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.14 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" And return the actual extracted value in a parameter. This way we can later return success even without any extracted value. Signed-off-by: Martin Kletzander --- src/esx/esx_driver.c | 31 ++++++++++++++++++------------- src/vmware/vmware_conf.c | 10 +++++----- src/vmx/vmx.c | 21 ++++++++++----------- src/vmx/vmx.h | 2 +- tests/vmx2xmltest.c | 19 ++++++++++--------- 5 files changed, 44 insertions(+), 39 deletions(-) diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c index 51c26e29c65e..86d5396147a3 100644 --- a/src/esx/esx_driver.c +++ b/src/esx/esx_driver.c @@ -125,10 +125,11 @@ esxFreePrivate(esxPrivate **priv) * exception and need special handling. Parse the datastore name and use it * to lookup the datastore by name to verify that it exists. */ -static char * -esxParseVMXFileName(const char *fileName, void *opaque) +static int +esxParseVMXFileName(const char *fileName, + void *opaque, + char **out) { - char *result =3D NULL; esxVMX_Data *data =3D opaque; esxVI_String *propertyNameList =3D NULL; esxVI_ObjectContent *datastoreList =3D NULL; @@ -140,18 +141,22 @@ esxParseVMXFileName(const char *fileName, void *opaqu= e) char *strippedFileName =3D NULL; char *copyOfFileName =3D NULL; char *directoryAndFileName; + int ret =3D -1; + + *out =3D NULL; =20 if (!strchr(fileName, '/') && !strchr(fileName, '\\')) { /* Plain file name, use same directory as for the .vmx file */ - return g_strdup_printf("%s/%s", data->datastorePathWithoutFileName, + *out =3D g_strdup_printf("%s/%s", data->datastorePathWithoutFileNa= me, fileName); + return 0; } =20 if (esxVI_String_AppendValueToList(&propertyNameList, "summary.name") < 0 || esxVI_LookupDatastoreList(data->ctx, propertyNameList, &datastoreList) < 0) { - return NULL; + return -1; } =20 /* Search for datastore by mount path */ @@ -189,13 +194,13 @@ esxParseVMXFileName(const char *fileName, void *opaqu= e) ++tmp; } =20 - result =3D g_strdup_printf("[%s] %s", datastoreName, strippedFileN= ame); + *out =3D g_strdup_printf("[%s] %s", datastoreName, strippedFileNam= e); =20 break; } =20 /* Fallback to direct datastore name match */ - if (!result && STRPREFIX(fileName, "/vmfs/volumes/")) { + if (!*out && STRPREFIX(fileName, "/vmfs/volumes/")) { copyOfFileName =3D g_strdup(fileName); =20 /* Expected format: '/vmfs/volumes//' */ @@ -223,22 +228,22 @@ esxParseVMXFileName(const char *fileName, void *opaqu= e) goto cleanup; } =20 - result =3D g_strdup_printf("[%s] %s", datastoreName, - directoryAndFileName); + *out =3D g_strdup_printf("[%s] %s", datastoreName, directoryAndFil= eName); } =20 /* If it's an absolute path outside of a datastore just use it as is */ - if (!result && *fileName =3D=3D '/') { + if (!*out && *fileName =3D=3D '/') { /* FIXME: need to deal with Windows paths here too */ - result =3D g_strdup(fileName); + *out =3D g_strdup(fileName); } =20 - if (!result) { + if (!*out) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Could not handle file name '%s'"), fileName); goto cleanup; } =20 + ret =3D 0; cleanup: esxVI_String_Free(&propertyNameList); esxVI_ObjectContent_Free(&datastoreList); @@ -246,7 +251,7 @@ esxParseVMXFileName(const char *fileName, void *opaque) VIR_FREE(strippedFileName); VIR_FREE(copyOfFileName); =20 - return result; + return ret; } =20 =20 diff --git a/src/vmware/vmware_conf.c b/src/vmware/vmware_conf.c index e44673247ff1..c90cb10faf7c 100644 --- a/src/vmware/vmware_conf.c +++ b/src/vmware/vmware_conf.c @@ -507,11 +507,11 @@ vmwareExtractPid(const char * vmxPath) return pid_value; } =20 -char * -vmwareCopyVMXFileName(const char *datastorePath, void *opaque G_GNUC_UNUSE= D) +int +vmwareCopyVMXFileName(const char *datastorePath, void *opaque G_GNUC_UNUSE= D, + char **out) { - char *path; + *out =3D g_strdup(datastorePath); =20 - path =3D g_strdup(datastorePath); - return path; + return *out ? 0 : -1; } diff --git a/src/vmx/vmx.c b/src/vmx/vmx.c index b86dbe9ca267..b2b2244415a1 100644 --- a/src/vmx/vmx.c +++ b/src/vmx/vmx.c @@ -2411,7 +2411,7 @@ virVMXParseDisk(virVMXContext *ctx, virDomainXMLOptio= nPtr xmlopt, virConfPtr con } =20 virDomainDiskSetType(*def, VIR_STORAGE_TYPE_FILE); - if (!(tmp =3D ctx->parseFileName(fileName, ctx->opaque))) + if (ctx->parseFileName(fileName, ctx->opaque, &tmp) < 0) goto cleanup; virDomainDiskSetSource(*def, tmp); VIR_FREE(tmp); @@ -2448,7 +2448,7 @@ virVMXParseDisk(virVMXContext *ctx, virDomainXMLOptio= nPtr xmlopt, virConfPtr con } =20 virDomainDiskSetType(*def, VIR_STORAGE_TYPE_FILE); - if (!(tmp =3D ctx->parseFileName(fileName, ctx->opaque))) + if (ctx->parseFileName(fileName, ctx->opaque, &tmp) < 0) goto cleanup; virDomainDiskSetSource(*def, tmp); VIR_FREE(tmp); @@ -2514,7 +2514,8 @@ virVMXParseDisk(virVMXContext *ctx, virDomainXMLOptio= nPtr xmlopt, virConfPtr con char *tmp =3D NULL; =20 virDomainDiskSetType(*def, VIR_STORAGE_TYPE_FILE); - if (fileName && !(tmp =3D ctx->parseFileName(fileName, ctx->op= aque))) + if (fileName && + ctx->parseFileName(fileName, ctx->opaque, &tmp) < 0) goto cleanup; virDomainDiskSetSource(*def, tmp); VIR_FREE(tmp); @@ -2974,10 +2975,9 @@ virVMXParseSerial(virVMXContext *ctx, virConfPtr con= f, int port, } else if (STRCASEEQ(fileType, "file")) { (*def)->target.port =3D port; (*def)->source->type =3D VIR_DOMAIN_CHR_TYPE_FILE; - (*def)->source->data.file.path =3D ctx->parseFileName(fileName, - ctx->opaque); - - if ((*def)->source->data.file.path =3D=3D NULL) + if (ctx->parseFileName(fileName, + ctx->opaque, + &(*def)->source->data.file.path) < 0) goto cleanup; } else if (STRCASEEQ(fileType, "pipe")) { /* @@ -3140,10 +3140,9 @@ virVMXParseParallel(virVMXContext *ctx, virConfPtr c= onf, int port, } else if (STRCASEEQ(fileType, "file")) { (*def)->target.port =3D port; (*def)->source->type =3D VIR_DOMAIN_CHR_TYPE_FILE; - (*def)->source->data.file.path =3D ctx->parseFileName(fileName, - ctx->opaque); - - if ((*def)->source->data.file.path =3D=3D NULL) + if (ctx->parseFileName(fileName, + ctx->opaque, + &(*def)->source->data.file.path) < 0) goto cleanup; } else { virReportError(VIR_ERR_INTERNAL_ERROR, diff --git a/src/vmx/vmx.h b/src/vmx/vmx.h index df5d39157b99..e5420c970a4b 100644 --- a/src/vmx/vmx.h +++ b/src/vmx/vmx.h @@ -36,7 +36,7 @@ virDomainXMLOptionPtr virVMXDomainXMLConfInit(virCapsPtr = caps); * Context */ =20 -typedef char * (*virVMXParseFileName)(const char *fileName, void *opaque); +typedef int (*virVMXParseFileName)(const char *fileName, void *opaque, cha= r **src); typedef char * (*virVMXFormatFileName)(const char *src, void *opaque); typedef int (*virVMXAutodetectSCSIControllerModel)(virDomainDiskDefPtr def, int *model, void *opaqu= e); diff --git a/tests/vmx2xmltest.c b/tests/vmx2xmltest.c index 8cc227bbedfc..412b201f0242 100644 --- a/tests/vmx2xmltest.c +++ b/tests/vmx2xmltest.c @@ -127,15 +127,16 @@ testCompareHelper(const void *data) return ret; } =20 -static char * -testParseVMXFileName(const char *fileName, void *opaque G_GNUC_UNUSED) +static int +testParseVMXFileName(const char *fileName, + void *opaque G_GNUC_UNUSED, + char **src) { g_autofree char *copyOfFileName =3D NULL; char *tmp =3D NULL; char *saveptr =3D NULL; char *datastoreName =3D NULL; char *directoryAndFileName =3D NULL; - char *src =3D NULL; =20 if (STRPREFIX(fileName, "/vmfs/volumes/")) { /* Found absolute path referencing a file inside a datastore */ @@ -145,22 +146,22 @@ testParseVMXFileName(const char *fileName, void *opaq= ue G_GNUC_UNUSED) if ((tmp =3D STRSKIP(copyOfFileName, "/vmfs/volumes/")) =3D=3D NUL= L || (datastoreName =3D strtok_r(tmp, "/", &saveptr)) =3D=3D NULL || (directoryAndFileName =3D strtok_r(NULL, "", &saveptr)) =3D=3D= NULL) { - return NULL; + return -1; } =20 - src =3D g_strdup_printf("[%s] %s", datastoreName, directoryAndFile= Name); + *src =3D g_strdup_printf("[%s] %s", datastoreName, directoryAndFil= eName); } else if (STRPREFIX(fileName, "/")) { /* Found absolute path referencing a file outside a datastore */ - src =3D g_strdup(fileName); + *src =3D g_strdup(fileName); } else if (strchr(fileName, '/') !=3D NULL) { /* Found relative path, this is not supported */ - return NULL; + return -1; } else { /* Found single file name referencing a file inside a datastore */ - src =3D g_strdup_printf("[datastore] directory/%s", fileName); + *src =3D g_strdup_printf("[datastore] directory/%s", fileName); } =20 - return src; + return 0; } =20 static int --=20 2.29.2