[PATCH 12/19] storage: Introduce virStoragePoolObj{Get|Set}Autostart

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

 



Rather than have the logic in the storage driver, move it to virstorageobj.

NB: virStoragePoolObjGetAutostart can take liberties with not needing the
same if...else construct.  Also pass a NULL for testStoragePoolSetAutostart
to avoid the autostartLink setup using the autostartDir for the test driver.

Signed-off-by: John Ferlan <jferlan@xxxxxxxxxx>
---
 src/conf/virstorageobj.c     | 57 ++++++++++++++++++++++++++++++++++++++++++++
 src/conf/virstorageobj.h     |  8 +++++++
 src/libvirt_private.syms     |  2 ++
 src/storage/storage_driver.c | 41 +++----------------------------
 src/test/test_driver.c       | 13 ++--------
 5 files changed, 72 insertions(+), 49 deletions(-)

diff --git a/src/conf/virstorageobj.c b/src/conf/virstorageobj.c
index 0079472..9ce3840 100644
--- a/src/conf/virstorageobj.c
+++ b/src/conf/virstorageobj.c
@@ -111,6 +111,63 @@ virStoragePoolObjSetActive(virStoragePoolObjPtr obj,
 }
 
 
+int
+virStoragePoolObjGetAutostart(virStoragePoolObjPtr obj)
+{
+    if (!obj->configFile)
+        return 0;
+
+    return obj->autostart;
+}
+
+
+int
+virStoragePoolObjSetAutostart(virStoragePoolObjPtr obj,
+                              const char *autostartDir,
+                              int autostart)
+{
+    obj->autostart = autostart;
+
+    if (!obj->configFile) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       "%s", _("pool has no config file"));
+        return -1;
+    }
+
+    autostart = (autostart != 0);
+
+    if (obj->autostart != autostart) {
+        if (autostart && autostartDir) {
+            if (virFileMakePath(autostartDir) < 0) {
+                virReportSystemError(errno,
+                                     _("cannot create autostart directory %s"),
+                                     autostartDir);
+                return -1;
+            }
+
+            if (symlink(obj->configFile, obj->autostartLink) < 0) {
+                virReportSystemError(errno,
+                                     _("Failed to create symlink '%s' to '%s'"),
+                                     obj->autostartLink, obj->configFile);
+                return -1;
+            }
+        } else {
+            if (unlink(obj->autostartLink) < 0 &&
+                errno != ENOENT && errno != ENOTDIR) {
+                virReportSystemError(errno,
+                                     _("Failed to delete symlink '%s'"),
+                                     obj->autostartLink);
+                return -1;
+            }
+        }
+
+        obj->autostart = autostart;
+    }
+
+    return 0;
+}
+
+
 unsigned int
 virStoragePoolObjGetAsyncjobs(virStoragePoolObjPtr obj)
 {
diff --git a/src/conf/virstorageobj.h b/src/conf/virstorageobj.h
index d47b233..3b6e395 100644
--- a/src/conf/virstorageobj.h
+++ b/src/conf/virstorageobj.h
@@ -93,6 +93,14 @@ void
 virStoragePoolObjSetActive(virStoragePoolObjPtr obj,
                            bool active);
 
+int
+virStoragePoolObjGetAutostart(virStoragePoolObjPtr obj);
+
+int
+virStoragePoolObjSetAutostart(virStoragePoolObjPtr obj,
+                              const char *autostartDir,
+                              int autostart);
+
 unsigned int
 virStoragePoolObjGetAsyncjobs(virStoragePoolObjPtr obj);
 
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index edd3174..e8b4eda 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1014,6 +1014,7 @@ virStoragePoolObjDeleteDef;
 virStoragePoolObjFindByName;
 virStoragePoolObjFindByUUID;
 virStoragePoolObjGetAsyncjobs;
+virStoragePoolObjGetAutostart;
 virStoragePoolObjGetConfigFile;
 virStoragePoolObjGetDef;
 virStoragePoolObjGetNames;
@@ -1031,6 +1032,7 @@ virStoragePoolObjNumOfVolumes;
 virStoragePoolObjRemove;
 virStoragePoolObjSaveDef;
 virStoragePoolObjSetActive;
+virStoragePoolObjSetAutostart;
 virStoragePoolObjSetConfigFile;
 virStoragePoolObjSourceFindDuplicate;
 virStoragePoolObjStealNewDef;
diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c
index 6289314..c4e4e7b 100644
--- a/src/storage/storage_driver.c
+++ b/src/storage/storage_driver.c
@@ -1250,11 +1250,7 @@ storagePoolGetAutostart(virStoragePoolPtr pool,
     if (virStoragePoolGetAutostartEnsureACL(pool->conn, obj->def) < 0)
         goto cleanup;
 
-    if (!obj->configFile) {
-        *autostart = 0;
-    } else {
-        *autostart = obj->autostart;
-    }
+    *autostart = virStoragePoolObjGetAutostart(obj);
 
     ret = 0;
 
@@ -1277,39 +1273,8 @@ storagePoolSetAutostart(virStoragePoolPtr pool,
     if (virStoragePoolSetAutostartEnsureACL(pool->conn, obj->def) < 0)
         goto cleanup;
 
-    if (!obj->configFile) {
-        virReportError(VIR_ERR_INTERNAL_ERROR,
-                       "%s", _("pool has no config file"));
-    }
-
-    autostart = (autostart != 0);
-
-    if (obj->autostart != autostart) {
-        if (autostart) {
-            if (virFileMakePath(driver->autostartDir) < 0) {
-                virReportSystemError(errno,
-                                     _("cannot create autostart directory %s"),
-                                     driver->autostartDir);
-                goto cleanup;
-            }
-
-            if (symlink(obj->configFile, obj->autostartLink) < 0) {
-                virReportSystemError(errno,
-                                     _("Failed to create symlink '%s' to '%s'"),
-                                     obj->autostartLink, obj->configFile);
-                goto cleanup;
-            }
-        } else {
-            if (unlink(obj->autostartLink) < 0 &&
-                errno != ENOENT && errno != ENOTDIR) {
-                virReportSystemError(errno,
-                                     _("Failed to delete symlink '%s'"),
-                                     obj->autostartLink);
-                goto cleanup;
-            }
-        }
-        obj->autostart = autostart;
-    }
+    if (virStoragePoolObjSetAutostart(obj, driver->autostartDir, autostart) < 0)
+        goto cleanup;
 
     ret = 0;
 
diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index 68f1412..d68a18d 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -4690,11 +4690,7 @@ testStoragePoolGetAutostart(virStoragePoolPtr pool,
     if (!(obj = testStoragePoolObjFindByName(privconn, pool->name)))
         return -1;
 
-    if (!obj->configFile) {
-        *autostart = 0;
-    } else {
-        *autostart = obj->autostart;
-    }
+    *autostart = virStoragePoolObjGetAutostart(obj);
 
     virStoragePoolObjUnlock(obj);
     return 0;
@@ -4712,14 +4708,9 @@ testStoragePoolSetAutostart(virStoragePoolPtr pool,
     if (!(obj = testStoragePoolObjFindByName(privconn, pool->name)))
         return -1;
 
-    if (!obj->configFile) {
-        virReportError(VIR_ERR_INVALID_ARG,
-                       "%s", _("pool has no config file"));
+    if (virStoragePoolObjSetAutostart(obj, NULL, autostart) < 0)
         goto cleanup;
-    }
 
-    autostart = (autostart != 0);
-    obj->autostart = autostart;
     ret = 0;
 
  cleanup:
-- 
2.9.3

--
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