return esxStorageVolumeLookupByPath(conn, key);
}
+ if (!priv->primary->hasQueryVirtualDiskUuid) {
+ ESX_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("QueryVirtualDiskUuid not avialable, cannot lookup storage "
+ "volume by UUID"));
+ return NULL;
+ }
+
if (esxVI_EnsureSession(priv->primary) < 0) {
return NULL;
}
esxVI_ManagedObjectReference *task = NULL;
esxVI_TaskInfoState taskInfoState;
char *uuid_string = NULL;
- char key[VIR_UUID_STRING_BUFLEN] = "";
+ char *key = NULL;
virCheckFlags(0, NULL);
goto cleanup;
}
- if (esxVI_QueryVirtualDiskUuid(priv->primary, datastorePath,
- priv->primary->datacenter->_reference,
- &uuid_string) < 0) {
- goto cleanup;
- }
+ if (priv->primary->hasQueryVirtualDiskUuid) {
+ if (VIR_ALLOC_N(key, VIR_UUID_STRING_BUFLEN) < 0) {
+ virReportOOMError();
+ goto cleanup;
+ }
- if (esxUtil_ReformatUuid(uuid_string, key) < 0) {
- goto cleanup;
+ if (esxVI_QueryVirtualDiskUuid(priv->primary, datastorePath,
+ priv->primary->datacenter->_reference,
+ &uuid_string) < 0) {
+ goto cleanup;
+ }
+
+ if (esxUtil_ReformatUuid(uuid_string, key) < 0) {
+ goto cleanup;
+ }
+ } else {
+ /* Fall back to the path as key */
+ if (esxVI_String_DeepCopyValue(&key, datastorePath) < 0) {
+ goto cleanup;
+ }
}
} else {
ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
esxVI_FileBackedVirtualDiskSpec_Free(&virtualDiskSpec);
esxVI_ManagedObjectReference_Free(&task);
VIR_FREE(uuid_string);
+ VIR_FREE(key);
return volume;
}
return -1;
}
+ if (ctx->productVersion & esxVI_ProductVersion_ESX) {
+ /*
+ * FIXME: Actually this should be detected by really calling
+ * QueryVirtualDiskUuid and checking if a NotImplemented fault is
+ * returned. But currently we don't deserialized the details of a
+ * possbile fault and therefore we don't know if the fault was a
+ * NotImplemented fault or not.
+ */
+ ctx->hasQueryVirtualDiskUuid = true;
+ }
+
if (esxVI_Login(ctx, username, password, NULL, &ctx->session) < 0 ||
esxVI_BuildSelectSetCollection(ctx) < 0) {
return -1;
return -1;
}
- if (esxVI_LookupFileInfoByDatastorePath(ctx, datastorePath, false, &fileInfo,
- esxVI_Occurrence_RequiredItem) < 0) {
- goto cleanup;
- }
-
- if (esxVI_VmDiskFileInfo_DynamicCast(fileInfo) != NULL) {
- /* VirtualDisks have a UUID, use it as key */
- if (esxVI_QueryVirtualDiskUuid(ctx, datastorePath,
- ctx->datacenter->_reference,
- &uuid_string) < 0) {
+ if (ctx->hasQueryVirtualDiskUuid) {
+ if (esxVI_LookupFileInfoByDatastorePath
+ (ctx, datastorePath, false, &fileInfo,
+ esxVI_Occurrence_RequiredItem) < 0) {
goto cleanup;
}
- if (VIR_ALLOC_N(*key, VIR_UUID_STRING_BUFLEN) < 0) {
- virReportOOMError();
- goto cleanup;
- }
+ if (esxVI_VmDiskFileInfo_DynamicCast(fileInfo) != NULL) {
+ /* VirtualDisks have a UUID, use it as key */
+ if (esxVI_QueryVirtualDiskUuid(ctx, datastorePath,
+ ctx->datacenter->_reference,
+ &uuid_string) < 0) {
+ goto cleanup;
+ }
- if (esxUtil_ReformatUuid(uuid_string, *key) < 0) {
- goto cleanup;
+ if (VIR_ALLOC_N(*key, VIR_UUID_STRING_BUFLEN) < 0) {
+ virReportOOMError();
+ goto cleanup;
+ }
+
+ if (esxUtil_ReformatUuid(uuid_string, *key) < 0) {
+ goto cleanup;
+ }
}
- } else {
+ }
+
+ if (*key == NULL) {
/* Other files don't have a UUID, fall back to the path as key */
if (esxVI_String_DeepCopyValue(key, datastorePath) < 0) {
goto cleanup;