]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
ESX: Check if a datastore is accessible first
authorMatthias Bolte <matthias.bolte@googlemail.com>
Wed, 23 Sep 2009 13:08:25 +0000 (15:08 +0200)
committerDaniel Veillard <veillard@redhat.com>
Wed, 23 Sep 2009 13:08:25 +0000 (15:08 +0200)
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
src/esx/esx_vmx.c

index 6cc23498a885361c8b66b50618cc0b915d4fc5ee..fa971d8230e0fe937095a8b3e66f02fa435bc08b 100644 (file)
@@ -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;
     }
 
index f1c1a4ddf78b4cc0d7aa0a5ce2fe8cb1cee168dd..8e2bdec4f22904cb9f3c18d45441e81d5341c3aa 100644 (file)
@@ -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);