提交 14954fb8 编写于 作者: M Matthias Bolte

esx: Set storage pool target path to host.mountInfo.path

Now all storage pool types expose the target path.
上级 5254546b
...@@ -194,11 +194,8 @@ static virStoragePoolPtr ...@@ -194,11 +194,8 @@ static virStoragePoolPtr
esxStoragePoolLookupByName(virConnectPtr conn, const char *name) esxStoragePoolLookupByName(virConnectPtr conn, const char *name)
{ {
esxPrivate *priv = conn->storagePrivateData; esxPrivate *priv = conn->storagePrivateData;
esxVI_String *propertyNameList = NULL;
esxVI_ObjectContent *datastore = NULL; esxVI_ObjectContent *datastore = NULL;
esxVI_DynamicProperty *dynamicProperty = NULL; esxVI_DatastoreHostMount *hostMount = NULL;
esxVI_DatastoreHostMount *datastoreHostMountList = NULL;
esxVI_DatastoreHostMount *datastoreHostMount = NULL;
char *suffix = NULL; char *suffix = NULL;
int suffixLength; int suffixLength;
char uuid_string[VIR_UUID_STRING_BUFLEN] = "00000000-00000000-0000-000000000000"; char uuid_string[VIR_UUID_STRING_BUFLEN] = "00000000-00000000-0000-000000000000";
...@@ -209,9 +206,7 @@ esxStoragePoolLookupByName(virConnectPtr conn, const char *name) ...@@ -209,9 +206,7 @@ esxStoragePoolLookupByName(virConnectPtr conn, const char *name)
return NULL; return NULL;
} }
if (esxVI_String_AppendValueToList(&propertyNameList, "host") < 0 || if (esxVI_LookupDatastoreByName(priv->primary, name, NULL, &datastore,
esxVI_LookupDatastoreByName(priv->primary, name,
propertyNameList, &datastore,
esxVI_Occurrence_RequiredItem) < 0) { esxVI_Occurrence_RequiredItem) < 0) {
goto cleanup; goto cleanup;
} }
...@@ -232,30 +227,12 @@ esxStoragePoolLookupByName(virConnectPtr conn, const char *name) ...@@ -232,30 +227,12 @@ esxStoragePoolLookupByName(virConnectPtr conn, const char *name)
* The object name of virtual machine contains an integer, we use that as * The object name of virtual machine contains an integer, we use that as
* domain ID. * domain ID.
*/ */
for (dynamicProperty = datastore->propSet; dynamicProperty != NULL; if (esxVI_LookupDatastoreHostMount(priv->primary, datastore->obj,
dynamicProperty = dynamicProperty->_next) { &hostMount) < 0) {
if (STREQ(dynamicProperty->name, "host")) { goto cleanup;
if (esxVI_DatastoreHostMount_CastListFromAnyType
(dynamicProperty->val, &datastoreHostMountList) < 0) {
goto cleanup;
}
break;
}
} }
for (datastoreHostMount = datastoreHostMountList; datastoreHostMount != NULL; if ((suffix = STRSKIP(hostMount->mountInfo->path, "/vmfs/volumes/")) != NULL) {
datastoreHostMount = datastoreHostMount->_next) {
if (STRNEQ(priv->primary->hostSystem->_reference->value,
datastoreHostMount->key->value)) {
continue;
}
if ((suffix = STRSKIP(datastoreHostMount->mountInfo->path,
"/vmfs/volumes/")) == NULL) {
break;
}
suffixLength = strlen(suffix); suffixLength = strlen(suffix);
if ((suffixLength == 35 && /* = strlen("4b0beca7-7fd401f3-1d7f-000ae484a6a3") */ if ((suffixLength == 35 && /* = strlen("4b0beca7-7fd401f3-1d7f-000ae484a6a3") */
...@@ -284,9 +261,8 @@ esxStoragePoolLookupByName(virConnectPtr conn, const char *name) ...@@ -284,9 +261,8 @@ esxStoragePoolLookupByName(virConnectPtr conn, const char *name)
pool = virGetStoragePool(conn, name, uuid); pool = virGetStoragePool(conn, name, uuid);
cleanup: cleanup:
esxVI_String_Free(&propertyNameList);
esxVI_ObjectContent_Free(&datastore); esxVI_ObjectContent_Free(&datastore);
esxVI_DatastoreHostMount_Free(&datastoreHostMountList); esxVI_DatastoreHostMount_Free(&hostMount);
return pool; return pool;
} }
...@@ -481,13 +457,12 @@ esxStoragePoolGetXMLDesc(virStoragePoolPtr pool, unsigned int flags) ...@@ -481,13 +457,12 @@ esxStoragePoolGetXMLDesc(virStoragePoolPtr pool, unsigned int flags)
esxPrivate *priv = pool->conn->storagePrivateData; esxPrivate *priv = pool->conn->storagePrivateData;
esxVI_String *propertyNameList = NULL; esxVI_String *propertyNameList = NULL;
esxVI_ObjectContent *datastore = NULL; esxVI_ObjectContent *datastore = NULL;
esxVI_DatastoreHostMount *hostMount = NULL;
esxVI_DynamicProperty *dynamicProperty = NULL; esxVI_DynamicProperty *dynamicProperty = NULL;
esxVI_Boolean accessible = esxVI_Boolean_Undefined; esxVI_Boolean accessible = esxVI_Boolean_Undefined;
virStoragePoolDef def; virStoragePoolDef def;
esxVI_DatastoreInfo *info = NULL; esxVI_DatastoreInfo *info = NULL;
esxVI_LocalDatastoreInfo *localInfo = NULL;
esxVI_NasDatastoreInfo *nasInfo = NULL; esxVI_NasDatastoreInfo *nasInfo = NULL;
esxVI_VmfsDatastoreInfo *vmfsInfo = NULL;
char *xml = NULL; char *xml = NULL;
virCheckFlags(0, NULL); virCheckFlags(0, NULL);
...@@ -507,13 +482,17 @@ esxStoragePoolGetXMLDesc(virStoragePoolPtr pool, unsigned int flags) ...@@ -507,13 +482,17 @@ esxStoragePoolGetXMLDesc(virStoragePoolPtr pool, unsigned int flags)
propertyNameList, &datastore, propertyNameList, &datastore,
esxVI_Occurrence_RequiredItem) < 0 || esxVI_Occurrence_RequiredItem) < 0 ||
esxVI_GetBoolean(datastore, "summary.accessible", esxVI_GetBoolean(datastore, "summary.accessible",
&accessible, esxVI_Occurrence_RequiredItem) < 0) { &accessible, esxVI_Occurrence_RequiredItem) < 0 ||
esxVI_LookupDatastoreHostMount(priv->primary, datastore->obj,
&hostMount) < 0) {
goto cleanup; goto cleanup;
} }
def.name = pool->name; def.name = pool->name;
memcpy(def.uuid, pool->uuid, VIR_UUID_BUFLEN); memcpy(def.uuid, pool->uuid, VIR_UUID_BUFLEN);
def.target.path = hostMount->mountInfo->path;
if (accessible == esxVI_Boolean_True) { if (accessible == esxVI_Boolean_True) {
for (dynamicProperty = datastore->propSet; dynamicProperty != NULL; for (dynamicProperty = datastore->propSet; dynamicProperty != NULL;
dynamicProperty = dynamicProperty->_next) { dynamicProperty = dynamicProperty->_next) {
...@@ -531,46 +510,52 @@ esxStoragePoolGetXMLDesc(virStoragePoolPtr pool, unsigned int flags) ...@@ -531,46 +510,52 @@ esxStoragePoolGetXMLDesc(virStoragePoolPtr pool, unsigned int flags)
} }
def.available = dynamicProperty->val->int64; def.available = dynamicProperty->val->int64;
} else if (STREQ(dynamicProperty->name, "info")) {
if (esxVI_DatastoreInfo_CastFromAnyType(dynamicProperty->val,
&info) < 0) {
goto cleanup;
}
} }
} }
def.allocation = def.capacity - def.available; def.allocation = def.capacity - def.available;
}
/* See vSphere API documentation about HostDatastoreSystem for details */ for (dynamicProperty = datastore->propSet; dynamicProperty != NULL;
if ((localInfo = esxVI_LocalDatastoreInfo_DynamicCast(info)) != NULL) { dynamicProperty = dynamicProperty->_next) {
def.type = VIR_STORAGE_POOL_DIR; if (STREQ(dynamicProperty->name, "info")) {
def.target.path = localInfo->path; if (esxVI_DatastoreInfo_CastFromAnyType(dynamicProperty->val,
} else if ((nasInfo = esxVI_NasDatastoreInfo_DynamicCast(info)) != NULL) { &info) < 0) {
def.type = VIR_STORAGE_POOL_NETFS;
def.source.host.name = nasInfo->nas->remoteHost;
def.source.dir = nasInfo->nas->remotePath;
if (STRCASEEQ(nasInfo->nas->type, "NFS")) {
def.source.format = VIR_STORAGE_POOL_NETFS_NFS;
} else if (STRCASEEQ(nasInfo->nas->type, "CIFS")) {
def.source.format = VIR_STORAGE_POOL_NETFS_CIFS;
} else {
ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
_("Datastore has unexpected type '%s'"),
nasInfo->nas->type);
goto cleanup; goto cleanup;
} }
} else if ((vmfsInfo = esxVI_VmfsDatastoreInfo_DynamicCast(info)) != NULL) {
def.type = VIR_STORAGE_POOL_FS; break;
/* }
* FIXME: I'm not sure how to represent the source and target of a }
* VMFS based datastore in libvirt terms
*/ /* See vSphere API documentation about HostDatastoreSystem for details */
if (esxVI_LocalDatastoreInfo_DynamicCast(info) != NULL) {
def.type = VIR_STORAGE_POOL_DIR;
} else if ((nasInfo = esxVI_NasDatastoreInfo_DynamicCast(info)) != NULL) {
def.type = VIR_STORAGE_POOL_NETFS;
def.source.host.name = nasInfo->nas->remoteHost;
def.source.dir = nasInfo->nas->remotePath;
if (STRCASEEQ(nasInfo->nas->type, "NFS")) {
def.source.format = VIR_STORAGE_POOL_NETFS_NFS;
} else if (STRCASEEQ(nasInfo->nas->type, "CIFS")) {
def.source.format = VIR_STORAGE_POOL_NETFS_CIFS;
} else { } else {
ESX_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
_("DatastoreInfo has unexpected type")); _("Datastore has unexpected type '%s'"),
nasInfo->nas->type);
goto cleanup; goto cleanup;
} }
} else if (esxVI_VmfsDatastoreInfo_DynamicCast(info) != NULL) {
def.type = VIR_STORAGE_POOL_FS;
/*
* FIXME: I'm not sure how to represent the source and target of a
* VMFS based datastore in libvirt terms
*/
} else {
ESX_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
_("DatastoreInfo has unexpected type"));
goto cleanup;
} }
xml = virStoragePoolDefFormat(&def); xml = virStoragePoolDefFormat(&def);
...@@ -578,6 +563,7 @@ esxStoragePoolGetXMLDesc(virStoragePoolPtr pool, unsigned int flags) ...@@ -578,6 +563,7 @@ esxStoragePoolGetXMLDesc(virStoragePoolPtr pool, unsigned int flags)
cleanup: cleanup:
esxVI_String_Free(&propertyNameList); esxVI_String_Free(&propertyNameList);
esxVI_ObjectContent_Free(&datastore); esxVI_ObjectContent_Free(&datastore);
esxVI_DatastoreHostMount_Free(&hostMount);
esxVI_DatastoreInfo_Free(&info); esxVI_DatastoreInfo_Free(&info);
return xml; return xml;
......
...@@ -2565,6 +2565,74 @@ esxVI_LookupDatastoreByAbsolutePath(esxVI_Context *ctx, ...@@ -2565,6 +2565,74 @@ esxVI_LookupDatastoreByAbsolutePath(esxVI_Context *ctx,
int
esxVI_LookupDatastoreHostMount(esxVI_Context *ctx,
esxVI_ManagedObjectReference *datastore,
esxVI_DatastoreHostMount **hostMount)
{
int result = -1;
esxVI_String *propertyNameList = NULL;
esxVI_ObjectContent *objectContent = NULL;
esxVI_DynamicProperty *dynamicProperty = NULL;
esxVI_DatastoreHostMount *hostMountList = NULL;
esxVI_DatastoreHostMount *candidate = NULL;
if (hostMount == NULL || *hostMount != NULL) {
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
return -1;
}
if (esxVI_String_AppendValueToList(&propertyNameList, "host") < 0 ||
esxVI_LookupObjectContentByType(ctx, datastore, "Datastore",
propertyNameList, esxVI_Boolean_False,
&objectContent) < 0) {
goto cleanup;
}
for (dynamicProperty = objectContent->propSet; dynamicProperty != NULL;
dynamicProperty = dynamicProperty->_next) {
if (STREQ(dynamicProperty->name, "host")) {
if (esxVI_DatastoreHostMount_CastListFromAnyType
(dynamicProperty->val, &hostMountList) < 0) {
goto cleanup;
}
break;
} else {
VIR_WARN("Unexpected '%s' property", dynamicProperty->name);
}
}
for (candidate = hostMountList; candidate != NULL;
candidate = candidate->_next) {
if (STRNEQ(ctx->hostSystem->_reference->value, candidate->key->value)) {
continue;
}
if (esxVI_DatastoreHostMount_DeepCopy(hostMount, candidate) < 0) {
goto cleanup;
}
break;
}
if (*hostMount == NULL) {
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
_("Could not lookup datastore host mount"));
goto cleanup;
}
result = 0;
cleanup:
esxVI_String_Free(&propertyNameList);
esxVI_ObjectContent_Free(&objectContent);
esxVI_DatastoreHostMount_Free(&hostMountList);
return result;
}
int int
esxVI_LookupTaskInfoByTask(esxVI_Context *ctx, esxVI_LookupTaskInfoByTask(esxVI_Context *ctx,
esxVI_ManagedObjectReference *task, esxVI_ManagedObjectReference *task,
......
...@@ -370,6 +370,10 @@ int esxVI_LookupDatastoreByAbsolutePath(esxVI_Context *ctx, ...@@ -370,6 +370,10 @@ int esxVI_LookupDatastoreByAbsolutePath(esxVI_Context *ctx,
esxVI_ObjectContent **datastore, esxVI_ObjectContent **datastore,
esxVI_Occurrence occurrence); esxVI_Occurrence occurrence);
int esxVI_LookupDatastoreHostMount(esxVI_Context *ctx,
esxVI_ManagedObjectReference *datastore,
esxVI_DatastoreHostMount **hostMount);
int esxVI_LookupTaskInfoByTask(esxVI_Context *ctx, int esxVI_LookupTaskInfoByTask(esxVI_Context *ctx,
esxVI_ManagedObjectReference *task, esxVI_ManagedObjectReference *task,
esxVI_TaskInfo **taskInfo); esxVI_TaskInfo **taskInfo);
......
...@@ -1127,7 +1127,7 @@ additional_enum_features = { "ManagedEntityStatus" : Enum.FEATURE__ANY_TYPE ...@@ -1127,7 +1127,7 @@ additional_enum_features = { "ManagedEntityStatus" : Enum.FEATURE__ANY_TYPE
"VirtualMachinePowerState" : Enum.FEATURE__ANY_TYPE } "VirtualMachinePowerState" : Enum.FEATURE__ANY_TYPE }
additional_object_features = { "DatastoreHostMount" : Object.FEATURE__LIST | Object.FEATURE__ANY_TYPE, additional_object_features = { "DatastoreHostMount" : Object.FEATURE__DEEP_COPY | Object.FEATURE__LIST | Object.FEATURE__ANY_TYPE,
"DatastoreInfo" : Object.FEATURE__ANY_TYPE | Object.FEATURE__DYNAMIC_CAST, "DatastoreInfo" : Object.FEATURE__ANY_TYPE | Object.FEATURE__DYNAMIC_CAST,
"Event" : Object.FEATURE__LIST, "Event" : Object.FEATURE__LIST,
"FileInfo" : Object.FEATURE__DYNAMIC_CAST, "FileInfo" : Object.FEATURE__DYNAMIC_CAST,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册