From b167672c748bd7d16cd5f450096232266583b851 Mon Sep 17 00:00:00 2001 From: Matthias Bolte Date: Wed, 23 Sep 2009 15:08:25 +0200 Subject: [PATCH] ESX: Check if a datastore is accessible first An inaccessible datastore has no valid URL property so don't access its URI property. * src/esx/esx_vi.c: esxVI_LookupDatastoreByName(): check if datastore is accessible before accessing its URL property * src/esx/esx_vmx.c: update to changed datastore properties --- src/esx/esx_vi.c | 58 ++++++++++++++++++++++++++++++++++++++++++----- src/esx/esx_vmx.c | 6 +++-- 2 files changed, 56 insertions(+), 8 deletions(-) diff --git a/src/esx/esx_vi.c b/src/esx/esx_vi.c index 6cc23498a8..fa971d8230 100644 --- a/src/esx/esx_vi.c +++ b/src/esx/esx_vi.c @@ -1833,7 +1833,9 @@ esxVI_LookupDatastoreByName(virConnectPtr conn, esxVI_Context *ctx, esxVI_ObjectContent *datastoreList = NULL; esxVI_ObjectContent *candidate = NULL; esxVI_DynamicProperty *dynamicProperty = NULL; + esxVI_Boolean accessible = esxVI_Boolean_Undefined; size_t offset = strlen("/vmfs/volumes/"); + int numInaccessibleDatastores = 0; if (datastore == NULL || *datastore != NULL) { ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR, "Invalid argument"); @@ -1844,8 +1846,9 @@ esxVI_LookupDatastoreByName(virConnectPtr conn, esxVI_Context *ctx, if (esxVI_String_DeepCopyList(conn, &completePropertyNameList, propertyNameList) < 0 || esxVI_String_AppendValueListToList(conn, &completePropertyNameList, - "info.name\0" - "info.url\0") < 0) { + "summary.accessible\0" + "summary.name\0" + "summary.url\0") < 0) { goto failure; } @@ -1868,9 +1871,37 @@ esxVI_LookupDatastoreByName(virConnectPtr conn, esxVI_Context *ctx, /* Search for a matching datastore */ for (candidate = datastoreList; candidate != NULL; candidate = candidate->_next) { + accessible = esxVI_Boolean_Undefined; + for (dynamicProperty = candidate->propSet; dynamicProperty != NULL; dynamicProperty = dynamicProperty->_next) { - if (STREQ(dynamicProperty->name, "info.name")) { + if (STREQ(dynamicProperty->name, "summary.accessible")) { + if (esxVI_AnyType_ExpectType(conn, dynamicProperty->val, + esxVI_Type_Boolean) < 0) { + goto failure; + } + + accessible = dynamicProperty->val->boolean; + break; + } + } + + if (accessible == esxVI_Boolean_Undefined) { + ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR, + "Got incomplete response while querying for the " + "datastore 'summary.accessible' property"); + goto failure; + } + + if (accessible == esxVI_Boolean_False) { + ++numInaccessibleDatastores; + } + + for (dynamicProperty = candidate->propSet; dynamicProperty != NULL; + dynamicProperty = dynamicProperty->_next) { + if (STREQ(dynamicProperty->name, "summary.accessible")) { + /* Ignore it */ + } else if (STREQ(dynamicProperty->name, "summary.name")) { if (esxVI_AnyType_ExpectType(conn, dynamicProperty->val, esxVI_Type_String) < 0) { goto failure; @@ -1885,7 +1916,15 @@ esxVI_LookupDatastoreByName(virConnectPtr conn, esxVI_Context *ctx, /* Found datastore with matching name */ goto cleanup; } - } else if (STREQ(dynamicProperty->name, "info.url")) { + } else if (STREQ(dynamicProperty->name, "summary.url")) { + if (accessible == esxVI_Boolean_False) { + /* + * The 'summary.url' property of an inaccessible datastore + * is invalid and cannot be used to identify the datastore. + */ + continue; + } + if (esxVI_AnyType_ExpectType(conn, dynamicProperty->val, esxVI_Type_String) < 0) { goto failure; @@ -1916,8 +1955,15 @@ esxVI_LookupDatastoreByName(virConnectPtr conn, esxVI_Context *ctx, } if (occurence != esxVI_Occurence_OptionalItem) { - ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR, - "Could not find datastore with name '%s'", name); + if (numInaccessibleDatastores > 0) { + ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR, + "Could not find datastore '%s', maybe it's " + "inaccessible", name); + } else { + ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR, + "Could not find datastore '%s'", name); + } + goto failure; } diff --git a/src/esx/esx_vmx.c b/src/esx/esx_vmx.c index f1c1a4ddf7..8e2bdec4f2 100644 --- a/src/esx/esx_vmx.c +++ b/src/esx/esx_vmx.c @@ -612,7 +612,9 @@ esxVMX_AbsolutePathToDatastoreRelatedPath(virConnectPtr conn, for (dynamicProperty = datastore->propSet; dynamicProperty != NULL; dynamicProperty = dynamicProperty->_next) { - if (STREQ(dynamicProperty->name, "info.name")) { + if (STREQ(dynamicProperty->name, "summary.accessible")) { + /* Ignore it */ + } else if (STREQ(dynamicProperty->name, "summary.name")) { if (esxVI_AnyType_ExpectType(conn, dynamicProperty->val, esxVI_Type_String) < 0) { goto failure; @@ -620,7 +622,7 @@ esxVMX_AbsolutePathToDatastoreRelatedPath(virConnectPtr conn, datastoreName = dynamicProperty->val->string; break; - } else if (STREQ(dynamicProperty->name, "info.url")) { + } else if (STREQ(dynamicProperty->name, "summary.url")) { /* Ignore it */ } else { VIR_WARN("Unexpected '%s' property", dynamicProperty->name); -- GitLab