From af9dc75c1faf23565345d7a653a85a09efee0ac0 Mon Sep 17 00:00:00 2001 From: Cole Robinson Date: Mon, 27 Apr 2015 10:43:22 -0400 Subject: [PATCH] storage: Break out storageDriverLoadPoolState Will simplify a future patch --- src/storage/storage_driver.c | 88 +++++++++++++++++++----------------- 1 file changed, 47 insertions(+), 41 deletions(-) diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c index 06686bf674..9abdc6876a 100644 --- a/src/storage/storage_driver.c +++ b/src/storage/storage_driver.c @@ -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); } } -- GitLab