For autostarting a single pool. Lets us exit the function early
which simplifies the control flow, and it matches the pattern
of storagePoolUpdateAllState
---
src/storage/storage_driver.c | 84 +++++++++++++++++++++++---------------------
1 file changed, 43 insertions(+), 41 deletions(-)
diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c
index e2d729f..3bdc13f 100644
--- a/src/storage/storage_driver.c
+++ b/src/storage/storage_driver.c
@@ -149,6 +149,48 @@ storagePoolUpdateAllState(void)
}
static void
+storageDriverAutostartPool(virConnectPtr conn,
+ virStoragePoolObjPtr pool)
+{
+ virStorageBackendPtr backend;
+ char *stateFile = NULL;
+
+ if ((backend = virStorageBackendForType(pool->def->type)) == NULL)
+ goto cleanup;
+
+ if (virStoragePoolObjIsActive(pool) || !pool->autostart)
+ goto cleanup;
+
+ if (backend->startPool &&
+ backend->startPool(conn, pool) < 0) {
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Failed to autostart storage pool '%s': %s"),
+ pool->def->name, virGetLastErrorMessage());
+ goto cleanup;
+ }
+
+ virStoragePoolObjClearVols(pool);
+ stateFile = virFileBuildPath(driver->stateDir,
+ pool->def->name, ".xml");
+ if (!stateFile ||
+ virStoragePoolSaveState(stateFile, pool->def) < 0 ||
+ backend->refreshPool(conn, pool) < 0) {
+ if (stateFile)
+ unlink(stateFile);
+ if (backend->stopPool)
+ backend->stopPool(conn, pool);
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Failed to autostart storage pool '%s': %s"),
+ pool->def->name, virGetLastErrorMessage());
+ goto cleanup;
+ }
+
+ pool->active = true;
+ cleanup:
+ VIR_FREE(stateFile);
+}
+
+static void
storageDriverAutostart(void)
{
size_t i;
@@ -163,49 +205,9 @@ storageDriverAutostart(void)
for (i = 0; i < driver->pools.count; i++) {
virStoragePoolObjPtr pool = driver->pools.objs[i];
- virStorageBackendPtr backend;
- bool started = false;
virStoragePoolObjLock(pool);
- if ((backend = virStorageBackendForType(pool->def->type)) == NULL) {
- virStoragePoolObjUnlock(pool);
- continue;
- }
-
- if (pool->autostart &&
- !virStoragePoolObjIsActive(pool)) {
- if (backend->startPool &&
- backend->startPool(conn, pool) < 0) {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- _("Failed to autostart storage pool '%s':
%s"),
- pool->def->name, virGetLastErrorMessage());
- virStoragePoolObjUnlock(pool);
- continue;
- }
- started = true;
- }
-
- if (started) {
- char *stateFile;
-
- virStoragePoolObjClearVols(pool);
- stateFile = virFileBuildPath(driver->stateDir,
- pool->def->name, ".xml");
- if (!stateFile ||
- virStoragePoolSaveState(stateFile, pool->def) < 0 ||
- backend->refreshPool(conn, pool) < 0) {
- if (stateFile)
- unlink(stateFile);
- if (backend->stopPool)
- backend->stopPool(conn, pool);
- virReportError(VIR_ERR_INTERNAL_ERROR,
- _("Failed to autostart storage pool '%s':
%s"),
- pool->def->name, virGetLastErrorMessage());
- } else {
- pool->active = true;
- }
- VIR_FREE(stateFile);
- }
+ storageDriverAutostartPool(conn, pool);
virStoragePoolObjUnlock(pool);
}
--
2.7.4