mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-23 06:05:27 +00:00
esx: Fall back to path as key when QueryVirtualDiskUuid isn't available
QueryVirtualDiskUuid is only available on an ESX(i) server. vCenter returns an NotImplemented fault and a GSX server is missing the VirtualDiskManager completely. Therefore only use QueryVirtualDiskUuid with an ESX(i) server and fall back to path as storage volume key for vCenter and GSX server.
This commit is contained in:
parent
af32c355c3
commit
8fdb0b0c84
@ -783,6 +783,13 @@ esxStorageVolumeLookupByKey(virConnectPtr conn, const char *key)
|
||||
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;
|
||||
}
|
||||
@ -916,7 +923,7 @@ esxStorageVolumeCreateXML(virStoragePoolPtr pool, const char *xmldesc,
|
||||
esxVI_ManagedObjectReference *task = NULL;
|
||||
esxVI_TaskInfoState taskInfoState;
|
||||
char *uuid_string = NULL;
|
||||
char key[VIR_UUID_STRING_BUFLEN] = "";
|
||||
char *key = NULL;
|
||||
|
||||
virCheckFlags(0, NULL);
|
||||
|
||||
@ -1068,14 +1075,26 @@ esxStorageVolumeCreateXML(virStoragePoolPtr pool, const char *xmldesc,
|
||||
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,
|
||||
@ -1103,6 +1122,7 @@ esxStorageVolumeCreateXML(virStoragePoolPtr pool, const char *xmldesc,
|
||||
esxVI_FileBackedVirtualDiskSpec_Free(&virtualDiskSpec);
|
||||
esxVI_ManagedObjectReference_Free(&task);
|
||||
VIR_FREE(uuid_string);
|
||||
VIR_FREE(key);
|
||||
|
||||
return volume;
|
||||
}
|
||||
|
@ -453,6 +453,17 @@ esxVI_Context_Connect(esxVI_Context *ctx, const char *url,
|
||||
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;
|
||||
@ -3267,28 +3278,33 @@ esxVI_LookupStorageVolumeKeyByDatastorePath(esxVI_Context *ctx,
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (esxVI_LookupFileInfoByDatastorePath(ctx, datastorePath, false, &fileInfo,
|
||||
esxVI_Occurrence_RequiredItem) < 0) {
|
||||
goto cleanup;
|
||||
if (ctx->hasQueryVirtualDiskUuid) {
|
||||
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) {
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (VIR_ALLOC_N(*key, VIR_UUID_STRING_BUFLEN) < 0) {
|
||||
virReportOOMError();
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (esxUtil_ReformatUuid(uuid_string, *key) < 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) {
|
||||
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;
|
||||
|
@ -167,6 +167,7 @@ struct _esxVI_Context {
|
||||
esxVI_SelectionSpec *selectSet_hostSystemToDatastore;
|
||||
esxVI_SelectionSpec *selectSet_computeResourceToHost;
|
||||
esxVI_SelectionSpec *selectSet_computeResourceToParentToParent;
|
||||
bool hasQueryVirtualDiskUuid;
|
||||
};
|
||||
|
||||
int esxVI_Context_Alloc(esxVI_Context **ctx);
|
||||
|
Loading…
Reference in New Issue
Block a user