[PATCH 8/9] esx: Allow disk images in subdirectories

Michal Privoznik via Devel posted 9 patches 1 day, 1 hour ago
[PATCH 8/9] esx: Allow disk images in subdirectories
Posted by Michal Privoznik via Devel 1 day, 1 hour ago
From: Michal Privoznik <mprivozn@redhat.com>

The esxParseVMXFileName() function parses path to a disk image
trying to replace some "known" patterns (e.g. datastore paths).
A simple filename is treated as a path relative to .vmx file. But
disk images (and thus filenames) can be in a subdirectory,
relative to the .vmx file. For instance:

  subfolder/disk.vmdk

Adapt our parser to this fact.

Resolves: https://issues.redhat.com/browse/RHEL-122751
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
---
 src/esx/esx_driver.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c
index 6452a33b7c..9f965811b1 100644
--- a/src/esx/esx_driver.c
+++ b/src/esx/esx_driver.c
@@ -72,9 +72,11 @@ esxFreePrivate(esxPrivate **priv)
  * Parse a file name from a .vmx file and convert it to datastore path format
  * if possible. A .vmx file can contain file names in various formats:
  *
- * - A single name referencing a file in the same directory as the .vmx file:
+ * - A single name referencing a file in the same directory as the .vmx file,
+ *   or in a subdirectory:
  *
  *     test1.vmdk
+ *     subdir/test2.vmdk
  *
  * - An absolute file name referencing a file in a datastore that is mounted at
  *   /vmfs/volumes/<datastore>:
@@ -106,8 +108,9 @@ esxFreePrivate(esxPrivate **priv)
  *
  * Firstly this functions checks if the given file name contains a separator.
  * If it doesn't then the referenced file is in the same directory as the .vmx
- * file. The datastore name and directory of the .vmx file are passed to this
- * function via the opaque parameter by the caller of virVMXParseConfig.
+ * file, or in a subdirectory. The datastore name and directory of the .vmx
+ * file are passed to this function via the opaque parameter by the caller of
+ * virVMXParseConfig.
  *
  * Otherwise query for all known datastores and their mount directories. Then
  * try to find a datastore with a mount directory that is a prefix to the given
@@ -138,7 +141,7 @@ esxParseVMXFileName(const char *fileName,
 
     *out = NULL;
 
-    if (!strchr(fileName, '/') && !strchr(fileName, '\\')) {
+    if (*fileName != '/' && !strchr(fileName, '\\')) {
         /* Plain file name, use same directory as for the .vmx file */
         *out = g_strdup_printf("%s/%s", data->datastorePathWithoutFileName,
                                fileName);
-- 
2.51.0
Re: [PATCH 8/9] esx: Allow disk images in subdirectories
Posted by Martin Kletzander via Devel 20 hours ago
On Thu, Nov 20, 2025 at 09:32:53AM +0100, Michal Privoznik via Devel wrote:
>From: Michal Privoznik <mprivozn@redhat.com>
>
>The esxParseVMXFileName() function parses path to a disk image
>trying to replace some "known" patterns (e.g. datastore paths).
>A simple filename is treated as a path relative to .vmx file. But
>disk images (and thus filenames) can be in a subdirectory,
>relative to the .vmx file. For instance:
>
>  subfolder/disk.vmdk
>
>Adapt our parser to this fact.
>
>Resolves: https://issues.redhat.com/browse/RHEL-122751
>Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
>---
> src/esx/esx_driver.c | 11 +++++++----
> 1 file changed, 7 insertions(+), 4 deletions(-)
>
>diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c
>index 6452a33b7c..9f965811b1 100644
>--- a/src/esx/esx_driver.c
>+++ b/src/esx/esx_driver.c
>@@ -138,7 +141,7 @@ esxParseVMXFileName(const char *fileName,
>
>     *out = NULL;
>
>-    if (!strchr(fileName, '/') && !strchr(fileName, '\\')) {
>+    if (*fileName != '/' && !strchr(fileName, '\\')) {
>         /* Plain file name, use same directory as for the .vmx file */
>         *out = g_strdup_printf("%s/%s", data->datastorePathWithoutFileName,
>                                fileName);

Now when I'm thinking about it, there probably should be some check that
it's not referring to too many parent directories?  Although once we get
it from the VMX it means it's already there...  And we probably leave
the checking to the server in the other (xml2vmx) case since we happily
forward any subdir/../../../../filename.vmdk there.  So I guess it's
fine.

Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
>