Part of a series of cleanups to use new accessor methods. While writing this, I also discovered that conversion from XML to vmware modified the disk source in place; if the same code is reached twice, the second call behaves differently because the first call didn't clean up its mess. * src/vmware/vmware_conf.c (vmwareVmxPath): Use accessors. (vmwareParsePath): Avoid munging input string. * src/vmware/vmware_conf.h (vmwareParsePath): Make static. Signed-off-by: Eric Blake <eblake@xxxxxxxxxx> --- src/vmware/vmware_conf.c | 18 ++++++++++-------- src/vmware/vmware_conf.h | 6 +++--- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/vmware/vmware_conf.c b/src/vmware/vmware_conf.c index c96bd62..2de24a7 100644 --- a/src/vmware/vmware_conf.c +++ b/src/vmware/vmware_conf.c @@ -331,15 +331,15 @@ vmwareDomainConfigDisplay(vmwareDomainPtr pDomain, virDomainDefPtr def) } } -int -vmwareParsePath(char *path, char **directory, char **filename) +static int +vmwareParsePath(const char *path, char **directory, char **filename) { char *separator; separator = strrchr(path, '/'); if (separator != NULL) { - *separator++ = '\0'; + separator++; if (*separator == '\0') { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -347,7 +347,7 @@ vmwareParsePath(char *path, char **directory, char **filename) return -1; } - if (VIR_STRDUP(*directory, path) < 0) + if (VIR_STRNDUP(*directory, path, separator - path - 1) < 0) goto error; if (VIR_STRDUP(*filename, separator) < 0) { VIR_FREE(*directory); @@ -388,6 +388,7 @@ vmwareVmxPath(virDomainDefPtr vmdef, char **vmxPath) char *fileName = NULL; int ret = -1; size_t i; + const char *src; /* * Build VMX URL. Use the source of the first file-based harddisk @@ -405,7 +406,7 @@ vmwareVmxPath(virDomainDefPtr vmdef, char **vmxPath) for (i = 0; i < vmdef->ndisks; ++i) { if (vmdef->disks[i]->device == VIR_DOMAIN_DISK_DEVICE_DISK && - vmdef->disks[i]->type == VIR_DOMAIN_DISK_TYPE_FILE) { + virDomainDiskGetType(vmdef->disks[i]) == VIR_DOMAIN_DISK_TYPE_FILE) { disk = vmdef->disks[i]; break; } @@ -418,21 +419,22 @@ vmwareVmxPath(virDomainDefPtr vmdef, char **vmxPath) goto cleanup; } - if (disk->src == NULL) { + src = virDomainDiskGetSource(disk); + if (!src) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("First file-based harddisk has no source, cannot " "deduce datastore and path for VMX file")); goto cleanup; } - if (vmwareParsePath(disk->src, &directoryName, &fileName) < 0) { + if (vmwareParsePath(src, &directoryName, &fileName) < 0) { goto cleanup; } if (!virFileHasSuffix(fileName, ".vmdk")) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Expecting source '%s' of first file-based harddisk " - "to be a VMDK image"), disk->src); + "to be a VMDK image"), src); goto cleanup; } diff --git a/src/vmware/vmware_conf.h b/src/vmware/vmware_conf.h index b9fca6c..b039f9e 100644 --- a/src/vmware/vmware_conf.h +++ b/src/vmware/vmware_conf.h @@ -1,5 +1,7 @@ /*---------------------------------------------------------------------------*/ -/* Copyright 2010, diateam (www.diateam.net) +/* + * Copyright (C) 2014, Red Hat, Inc. + * Copyright 2010, diateam (www.diateam.net) * Copyright (c) 2013, Doug Goldstein (cardoe@xxxxxxxxxx) * * This library is free software; you can redistribute it and/or @@ -71,8 +73,6 @@ int vmwareParseVersionStr(int type, const char *buf, unsigned long *version); int vmwareDomainConfigDisplay(vmwareDomainPtr domain, virDomainDefPtr vmdef); -int vmwareParsePath(char *path, char **directory, char **filename); - int vmwareConstructVmxPath(char *directoryName, char *name, char **vmxPath); -- 1.8.5.3 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list