提交 8fdb0b0c 编写于 作者: M Matthias Bolte

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.
上级 af32c355
...@@ -783,6 +783,13 @@ esxStorageVolumeLookupByKey(virConnectPtr conn, const char *key) ...@@ -783,6 +783,13 @@ esxStorageVolumeLookupByKey(virConnectPtr conn, const char *key)
return esxStorageVolumeLookupByPath(conn, 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) { if (esxVI_EnsureSession(priv->primary) < 0) {
return NULL; return NULL;
} }
...@@ -916,7 +923,7 @@ esxStorageVolumeCreateXML(virStoragePoolPtr pool, const char *xmldesc, ...@@ -916,7 +923,7 @@ esxStorageVolumeCreateXML(virStoragePoolPtr pool, const char *xmldesc,
esxVI_ManagedObjectReference *task = NULL; esxVI_ManagedObjectReference *task = NULL;
esxVI_TaskInfoState taskInfoState; esxVI_TaskInfoState taskInfoState;
char *uuid_string = NULL; char *uuid_string = NULL;
char key[VIR_UUID_STRING_BUFLEN] = ""; char *key = NULL;
virCheckFlags(0, NULL); virCheckFlags(0, NULL);
...@@ -1068,14 +1075,26 @@ esxStorageVolumeCreateXML(virStoragePoolPtr pool, const char *xmldesc, ...@@ -1068,14 +1075,26 @@ esxStorageVolumeCreateXML(virStoragePoolPtr pool, const char *xmldesc,
goto cleanup; goto cleanup;
} }
if (esxVI_QueryVirtualDiskUuid(priv->primary, datastorePath, if (priv->primary->hasQueryVirtualDiskUuid) {
priv->primary->datacenter->_reference, if (VIR_ALLOC_N(key, VIR_UUID_STRING_BUFLEN) < 0) {
&uuid_string) < 0) { virReportOOMError();
goto cleanup; goto cleanup;
} }
if (esxUtil_ReformatUuid(uuid_string, key) < 0) { if (esxVI_QueryVirtualDiskUuid(priv->primary, datastorePath,
goto cleanup; 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 { } else {
ESX_ERROR(VIR_ERR_INTERNAL_ERROR, ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
...@@ -1103,6 +1122,7 @@ esxStorageVolumeCreateXML(virStoragePoolPtr pool, const char *xmldesc, ...@@ -1103,6 +1122,7 @@ esxStorageVolumeCreateXML(virStoragePoolPtr pool, const char *xmldesc,
esxVI_FileBackedVirtualDiskSpec_Free(&virtualDiskSpec); esxVI_FileBackedVirtualDiskSpec_Free(&virtualDiskSpec);
esxVI_ManagedObjectReference_Free(&task); esxVI_ManagedObjectReference_Free(&task);
VIR_FREE(uuid_string); VIR_FREE(uuid_string);
VIR_FREE(key);
return volume; return volume;
} }
......
...@@ -453,6 +453,17 @@ esxVI_Context_Connect(esxVI_Context *ctx, const char *url, ...@@ -453,6 +453,17 @@ esxVI_Context_Connect(esxVI_Context *ctx, const char *url,
return -1; 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 || if (esxVI_Login(ctx, username, password, NULL, &ctx->session) < 0 ||
esxVI_BuildSelectSetCollection(ctx) < 0) { esxVI_BuildSelectSetCollection(ctx) < 0) {
return -1; return -1;
...@@ -3267,28 +3278,33 @@ esxVI_LookupStorageVolumeKeyByDatastorePath(esxVI_Context *ctx, ...@@ -3267,28 +3278,33 @@ esxVI_LookupStorageVolumeKeyByDatastorePath(esxVI_Context *ctx,
return -1; return -1;
} }
if (esxVI_LookupFileInfoByDatastorePath(ctx, datastorePath, false, &fileInfo, if (ctx->hasQueryVirtualDiskUuid) {
esxVI_Occurrence_RequiredItem) < 0) { if (esxVI_LookupFileInfoByDatastorePath
goto cleanup; (ctx, datastorePath, false, &fileInfo,
} esxVI_Occurrence_RequiredItem) < 0) {
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; goto cleanup;
} }
if (VIR_ALLOC_N(*key, VIR_UUID_STRING_BUFLEN) < 0) { if (esxVI_VmDiskFileInfo_DynamicCast(fileInfo) != NULL) {
virReportOOMError(); /* VirtualDisks have a UUID, use it as key */
goto cleanup; if (esxVI_QueryVirtualDiskUuid(ctx, datastorePath,
} ctx->datacenter->_reference,
&uuid_string) < 0) {
goto cleanup;
}
if (esxUtil_ReformatUuid(uuid_string, *key) < 0) { if (VIR_ALLOC_N(*key, VIR_UUID_STRING_BUFLEN) < 0) {
goto cleanup; 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 */ /* Other files don't have a UUID, fall back to the path as key */
if (esxVI_String_DeepCopyValue(key, datastorePath) < 0) { if (esxVI_String_DeepCopyValue(key, datastorePath) < 0) {
goto cleanup; goto cleanup;
......
...@@ -167,6 +167,7 @@ struct _esxVI_Context { ...@@ -167,6 +167,7 @@ struct _esxVI_Context {
esxVI_SelectionSpec *selectSet_hostSystemToDatastore; esxVI_SelectionSpec *selectSet_hostSystemToDatastore;
esxVI_SelectionSpec *selectSet_computeResourceToHost; esxVI_SelectionSpec *selectSet_computeResourceToHost;
esxVI_SelectionSpec *selectSet_computeResourceToParentToParent; esxVI_SelectionSpec *selectSet_computeResourceToParentToParent;
bool hasQueryVirtualDiskUuid;
}; };
int esxVI_Context_Alloc(esxVI_Context **ctx); int esxVI_Context_Alloc(esxVI_Context **ctx);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册