]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
storage: Break out storageDriverLoadPoolState
authorCole Robinson <crobinso@redhat.com>
Mon, 27 Apr 2015 14:43:22 +0000 (10:43 -0400)
committerCole Robinson <crobinso@redhat.com>
Tue, 28 Apr 2015 13:37:57 +0000 (09:37 -0400)
Will simplify a future patch

src/storage/storage_driver.c

index 06686bf6743d98b6366e068db72cee31623a74b4..9abdc6876a92b5bf269272c066e7ad7bd54c0187 100644 (file)
@@ -74,15 +74,59 @@ static void storageDriverUnlock(void)
     virMutexUnlock(&driver->lock);
 }
 
+static void
+storagePoolUpdateState(virStoragePoolObjPtr pool)
+{
+    bool active;
+    virStorageBackendPtr backend;
+
+    if ((backend = virStorageBackendForType(pool->def->type)) == NULL) {
+        VIR_ERROR(_("Missing backend %d"), pool->def->type);
+        goto error;
+    }
+
+    /* Backends which do not support 'checkPool' are considered
+     * inactive by default.
+     */
+    active = false;
+    if (backend->checkPool &&
+        backend->checkPool(pool, &active) < 0) {
+        virErrorPtr err = virGetLastError();
+        VIR_ERROR(_("Failed to initialize storage pool '%s': %s"),
+                  pool->def->name, err ? err->message :
+                  _("no error message found"));
+        goto error;
+    }
+
+    /* We can pass NULL as connection, most backends do not use
+     * it anyway, but if they do and fail, we want to log error and
+     * continue with other pools.
+     */
+    if (active) {
+        virStoragePoolObjClearVols(pool);
+        if (backend->refreshPool(NULL, pool) < 0) {
+            virErrorPtr err = virGetLastError();
+            if (backend->stopPool)
+                backend->stopPool(NULL, pool);
+            VIR_ERROR(_("Failed to restart storage pool '%s': %s"),
+                      pool->def->name, err ? err->message :
+                      _("no error message found"));
+            goto error;
+        }
+    }
+
+    pool->active = active;
+ error:
+    return;
+}
+
 static void
 storagePoolUpdateAllState(void)
 {
     size_t i;
-    bool active;
 
     for (i = 0; i < driver->pools.count; i++) {
         virStoragePoolObjPtr pool = driver->pools.objs[i];
-        virStorageBackendPtr backend;
 
         virStoragePoolObjLock(pool);
         if (!virStoragePoolObjIsActive(pool)) {
@@ -90,45 +134,7 @@ storagePoolUpdateAllState(void)
             continue;
         }
 
-        if ((backend = virStorageBackendForType(pool->def->type)) == NULL) {
-            VIR_ERROR(_("Missing backend %d"), pool->def->type);
-            virStoragePoolObjUnlock(pool);
-            continue;
-        }
-
-        /* Backends which do not support 'checkPool' are considered
-         * inactive by default.
-         */
-        active = false;
-        if (backend->checkPool &&
-            backend->checkPool(pool, &active) < 0) {
-            virErrorPtr err = virGetLastError();
-            VIR_ERROR(_("Failed to initialize storage pool '%s': %s"),
-                      pool->def->name, err ? err->message :
-                      _("no error message found"));
-            virStoragePoolObjUnlock(pool);
-            continue;
-        }
-
-        /* We can pass NULL as connection, most backends do not use
-         * it anyway, but if they do and fail, we want to log error and
-         * continue with other pools.
-         */
-        if (active) {
-            virStoragePoolObjClearVols(pool);
-            if (backend->refreshPool(NULL, pool) < 0) {
-                virErrorPtr err = virGetLastError();
-                if (backend->stopPool)
-                    backend->stopPool(NULL, pool);
-                VIR_ERROR(_("Failed to restart storage pool '%s': %s"),
-                          pool->def->name, err ? err->message :
-                          _("no error message found"));
-                virStoragePoolObjUnlock(pool);
-                continue;
-            }
-        }
-
-        pool->active = active;
+        storagePoolUpdateState(pool);
         virStoragePoolObjUnlock(pool);
     }
 }