[PATCH v2 6/8] storage_driver: Introduce storagePoolRefreshImpl()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a wrapper over refreshPool() call as at all places we are
doing basically the same. Might as well have a single function to
call.

Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx>
---
 src/storage/storage_driver.c | 61 +++++++++++++++++++-----------------
 1 file changed, 32 insertions(+), 29 deletions(-)

diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c
index cefffdfd64..8cb3c40e51 100644
--- a/src/storage/storage_driver.c
+++ b/src/storage/storage_driver.c
@@ -92,6 +92,21 @@ storagePoolRefreshFailCleanup(virStorageBackendPtr backend,
 }
 
 
+static int
+storagePoolRefreshImpl(virStorageBackendPtr backend,
+                       virStoragePoolObjPtr obj,
+                       const char *stateFile)
+{
+    virStoragePoolObjClearVols(obj);
+    if (backend->refreshPool(obj) < 0) {
+        storagePoolRefreshFailCleanup(backend, obj, stateFile);
+        return -1;
+    }
+
+    return 0;
+}
+
+
 /**
  * virStoragePoolUpdateInactive:
  * @poolptr: pointer to a variable holding the pool object pointer
@@ -148,15 +163,12 @@ storagePoolUpdateStateCallback(virStoragePoolObjPtr obj,
      * it anyway, but if they do and fail, we want to log error and
      * continue with other pools.
      */
-    if (active) {
-        virStoragePoolObjClearVols(obj);
-        if (backend->refreshPool(obj) < 0) {
-            storagePoolRefreshFailCleanup(backend, obj, stateFile);
-            virReportError(VIR_ERR_INTERNAL_ERROR,
-                           _("Failed to restart storage pool '%s': %s"),
-                           def->name, virGetLastErrorMessage());
-            active = false;
-        }
+    if (active &&
+        storagePoolRefreshImpl(backend, obj, stateFile) < 0) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("Failed to restart storage pool '%s': %s"),
+                       def->name, virGetLastErrorMessage());
+        active = false;
     }
 
     virStoragePoolObjSetActive(obj, active);
@@ -203,12 +215,10 @@ storageDriverAutostartCallback(virStoragePoolObjPtr obj,
     if (started) {
         VIR_AUTOFREE(char *) stateFile = NULL;
 
-        virStoragePoolObjClearVols(obj);
         stateFile = virFileBuildPath(driver->stateDir, def->name, ".xml");
         if (!stateFile ||
             virStoragePoolSaveState(stateFile, def) < 0 ||
-            backend->refreshPool(obj) < 0) {
-            storagePoolRefreshFailCleanup(backend, obj, stateFile);
+            storagePoolRefreshImpl(backend, obj, stateFile) < 0) {
             virReportError(VIR_ERR_INTERNAL_ERROR,
                            _("Failed to autostart storage pool '%s': %s"),
                            def->name, virGetLastErrorMessage());
@@ -721,10 +731,9 @@ storagePoolCreateXML(virConnectPtr conn,
 
     stateFile = virFileBuildPath(driver->stateDir, def->name, ".xml");
 
-    virStoragePoolObjClearVols(obj);
-    if (!stateFile || virStoragePoolSaveState(stateFile, def) < 0 ||
-        backend->refreshPool(obj) < 0) {
-        storagePoolRefreshFailCleanup(backend, obj, stateFile);
+    if (!stateFile ||
+        virStoragePoolSaveState(stateFile, def) < 0 ||
+        storagePoolRefreshImpl(backend, obj, stateFile) < 0) {
         goto error;
     }
 
@@ -916,10 +925,9 @@ storagePoolCreate(virStoragePoolPtr pool,
 
     stateFile = virFileBuildPath(driver->stateDir, def->name, ".xml");
 
-    virStoragePoolObjClearVols(obj);
-    if (!stateFile || virStoragePoolSaveState(stateFile, def) < 0 ||
-        backend->refreshPool(obj) < 0) {
-        storagePoolRefreshFailCleanup(backend, obj, stateFile);
+    if (!stateFile ||
+        virStoragePoolSaveState(stateFile, def) < 0 ||
+        storagePoolRefreshImpl(backend, obj, stateFile) < 0) {
         goto cleanup;
     }
 
@@ -1116,6 +1124,7 @@ storagePoolRefresh(virStoragePoolPtr pool,
     virStoragePoolObjPtr obj;
     virStoragePoolDefPtr def;
     virStorageBackendPtr backend;
+    VIR_AUTOFREE(char *) stateFile = NULL;
     int ret = -1;
     virObjectEventPtr event = NULL;
 
@@ -1144,13 +1153,8 @@ storagePoolRefresh(virStoragePoolPtr pool,
         goto cleanup;
     }
 
-    virStoragePoolObjClearVols(obj);
-    if (backend->refreshPool(obj) < 0) {
-        VIR_AUTOFREE(char *) stateFile = NULL;
-
-        stateFile = virFileBuildPath(driver->stateDir, def->name, ".xml");
-        storagePoolRefreshFailCleanup(backend, obj, stateFile);
-
+    stateFile = virFileBuildPath(driver->stateDir, def->name, ".xml");
+    if (storagePoolRefreshImpl(backend, obj, stateFile) < 0) {
         event = virStoragePoolEventLifecycleNew(def->name,
                                                 def->uuid,
                                                 VIR_STORAGE_POOL_EVENT_STOPPED,
@@ -2240,8 +2244,7 @@ virStorageVolPoolRefreshThread(void *opaque)
     if (!(backend = virStorageBackendForType(def->type)))
         goto cleanup;
 
-    virStoragePoolObjClearVols(obj);
-    if (backend->refreshPool(obj) < 0)
+    if (storagePoolRefreshImpl(backend, obj, NULL) < 0)
         VIR_DEBUG("Failed to refresh storage pool");
 
     event = virStoragePoolEventRefreshNew(def->name, def->uuid);
-- 
2.19.2

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux