[PATCH 10/16] network: Introduce virNetworkObj{Get|Set}Autostart

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

 



In preparation for privatizing the virNetworkObj structure, move the guts
of the Get/Set Autostart from the driver into virnetworkobj. Alter the driver
to make the calls to the networkobj code.

Signed-off-by: John Ferlan <jferlan@xxxxxxxxxx>
---
 src/conf/virnetworkobj.c    | 74 +++++++++++++++++++++++++++++++++++++++++++++
 src/conf/virnetworkobj.h    | 11 ++++++-
 src/libvirt_private.syms    |  2 ++
 src/network/bridge_driver.c | 53 ++++----------------------------
 src/test/test_driver.c      |  6 ++--
 5 files changed, 96 insertions(+), 50 deletions(-)

diff --git a/src/conf/virnetworkobj.c b/src/conf/virnetworkobj.c
index 488fffd..a21aa26 100644
--- a/src/conf/virnetworkobj.c
+++ b/src/conf/virnetworkobj.c
@@ -121,6 +121,80 @@ virNetworkObjGetNewDef(virNetworkObjPtr obj)
 }
 
 
+int
+virNetworkObjGetAutostart(virNetworkObjPtr obj)
+{
+    return obj->autostart;
+}
+
+
+int
+virNetworkObjSetAutostart(virNetworkObjPtr obj,
+                          const char *configDir,
+                          const char *autostartDir,
+                          int autostart)
+{
+    virNetworkDefPtr def = obj->def;
+    char *configFile = NULL;
+    char *autostartLink = NULL;
+    int ret = -1;
+
+    if (!obj->persistent) {
+        virReportError(VIR_ERR_OPERATION_INVALID,
+                       _("cannot set autostart for transient network '%s'"),
+                       def->name);
+        return -1;
+    }
+
+    autostart = (autostart != 0);
+
+    if (obj->autostart != autostart) {
+        if (configDir && autostartDir) {
+            if (!(configFile = virNetworkConfigFile(configDir, def->name)))
+                goto cleanup;
+
+            if (!(autostartLink = virNetworkConfigFile(autostartDir,
+                                                       def->name)))
+                goto cleanup;
+
+            if (autostart) {
+                if (virFileMakePath(autostartDir) < 0) {
+                    virReportSystemError(errno,
+                                         _("cannot create autostart dir '%s'"),
+                                         autostartDir);
+                    goto cleanup;
+                }
+
+                if (symlink(configFile, autostartLink) < 0) {
+                    virReportSystemError(errno,
+                                         _("failed to create symlink '%s' "
+                                           "to '%s'"),
+                                         autostartLink, configFile);
+                    goto cleanup;
+                }
+            } else {
+                if (unlink(autostartLink) < 0 &&
+                    errno != ENOENT && errno != ENOTDIR) {
+                    virReportSystemError(errno,
+                                         _("failed to delete symlink '%s'"),
+                                         autostartLink);
+                    goto cleanup;
+                }
+            }
+        }
+
+        obj->autostart = autostart;
+    }
+
+    ret = 0;
+
+ cleanup:
+    VIR_FREE(configFile);
+    VIR_FREE(autostartLink);
+    return ret;
+}
+
+
 pid_t
 virNetworkObjGetDnsmasqPid(virNetworkObjPtr obj)
 {
diff --git a/src/conf/virnetworkobj.h b/src/conf/virnetworkobj.h
index 4b7c982..55a5331 100644
--- a/src/conf/virnetworkobj.h
+++ b/src/conf/virnetworkobj.h
@@ -32,7 +32,7 @@ struct _virNetworkObj {
     pid_t dnsmasqPid;
     pid_t radvdPid;
     unsigned int active : 1;
-    unsigned int autostart : 1;
+    int autostart;
     unsigned int persistent : 1;
 
     virNetworkDefPtr def; /* The current definition */
@@ -56,6 +56,15 @@ virNetworkObjGetDef(virNetworkObjPtr obj);
 virNetworkDefPtr
 virNetworkObjGetNewDef(virNetworkObjPtr obj);
 
+int
+virNetworkObjGetAutostart(virNetworkObjPtr obj);
+
+int
+virNetworkObjSetAutostart(virNetworkObjPtr obj,
+                          const char *configDir,
+                          const char *autostartDir,
+                          int autostart);
+
 virMacMapPtr
 virNetworkObjGetMacMap(virNetworkObjPtr obj);
 
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 6b4c37c..b148eeb 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -931,6 +931,7 @@ virNetworkObjFindByName;
 virNetworkObjFindByNameLocked;
 virNetworkObjFindByUUID;
 virNetworkObjFindByUUIDLocked;
+virNetworkObjGetAutostart;
 virNetworkObjGetClassIdMap;
 virNetworkObjGetDef;
 virNetworkObjGetDnsmasqPid;
@@ -954,6 +955,7 @@ virNetworkObjNew;
 virNetworkObjRemoveInactive;
 virNetworkObjReplacePersistentDef;
 virNetworkObjSaveStatus;
+virNetworkObjSetAutostart;
 virNetworkObjSetDefTransient;
 virNetworkObjSetDnsmasqPid;
 virNetworkObjSetFloorSum;
diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c
index f8e11e2..029f1b5 100644
--- a/src/network/bridge_driver.c
+++ b/src/network/bridge_driver.c
@@ -525,7 +525,7 @@ networkAutostartConfig(virNetworkObjPtr obj,
     int ret = -1;
 
     virObjectLock(obj);
-    if (obj->autostart &&
+    if (virNetworkObjGetAutostart(obj) &&
         !virNetworkObjIsActive(obj) &&
         networkStartNetwork(driver, obj) < 0)
         goto cleanup;
@@ -3963,7 +3963,7 @@ networkGetAutostart(virNetworkPtr net,
     if (virNetworkGetAutostartEnsureACL(net->conn, virNetworkObjGetDef(obj)) < 0)
         goto cleanup;
 
-    *autostart = obj->autostart;
+    *autostart = virNetworkObjGetAutostart(obj);
     ret = 0;
 
  cleanup:
@@ -3978,63 +3978,22 @@ networkSetAutostart(virNetworkPtr net,
 {
     virNetworkDriverStatePtr driver = networkGetDriver();
     virNetworkObjPtr obj;
-    virNetworkDefPtr def;
-    char *configFile = NULL, *autostartLink = NULL;
     int ret = -1;
 
     if (!(obj = networkObjFromNetwork(net)))
         goto cleanup;
-    def = virNetworkObjGetDef(obj);
 
-    if (virNetworkSetAutostartEnsureACL(net->conn, def) < 0)
+    if (virNetworkSetAutostartEnsureACL(net->conn,
+                                        virNetworkObjGetDef(obj)) < 0)
         goto cleanup;
 
-    if (!obj->persistent) {
-        virReportError(VIR_ERR_OPERATION_INVALID,
-                       "%s", _("cannot set autostart for transient network"));
+    if (virNetworkObjSetAutostart(obj, driver->networkConfigDir,
+                                  driver->networkAutostartDir, autostart) < 0)
         goto cleanup;
-    }
-
-    autostart = (autostart != 0);
 
-    if (obj->autostart != autostart) {
-        if ((configFile = virNetworkConfigFile(driver->networkConfigDir,
-                                               def->name)) == NULL)
-            goto cleanup;
-        if ((autostartLink = virNetworkConfigFile(driver->networkAutostartDir,
-                                                  def->name)) == NULL)
-            goto cleanup;
-
-        if (autostart) {
-            if (virFileMakePath(driver->networkAutostartDir) < 0) {
-                virReportSystemError(errno,
-                                     _("cannot create autostart directory '%s'"),
-                                     driver->networkAutostartDir);
-                goto cleanup;
-            }
-
-            if (symlink(configFile, autostartLink) < 0) {
-                virReportSystemError(errno,
-                                     _("Failed to create symlink '%s' to '%s'"),
-                                     autostartLink, configFile);
-                goto cleanup;
-            }
-        } else {
-            if (unlink(autostartLink) < 0 && errno != ENOENT && errno != ENOTDIR) {
-                virReportSystemError(errno,
-                                     _("Failed to delete symlink '%s'"),
-                                     autostartLink);
-                goto cleanup;
-            }
-        }
-
-        obj->autostart = autostart;
-    }
     ret = 0;
 
  cleanup:
-    VIR_FREE(configFile);
-    VIR_FREE(autostartLink);
     virNetworkObjEndAPI(&obj);
     return ret;
 }
diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index ee473ba..e14fc63 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -3644,7 +3644,7 @@ testNetworkGetAutostart(virNetworkPtr net,
     if (!(obj = testNetworkObjFindByName(privconn, net->name)))
         goto cleanup;
 
-    *autostart = obj->autostart;
+    *autostart = virNetworkObjGetAutostart(obj);
     ret = 0;
 
  cleanup:
@@ -3664,7 +3664,9 @@ testNetworkSetAutostart(virNetworkPtr net,
     if (!(obj = testNetworkObjFindByName(privconn, net->name)))
         goto cleanup;
 
-    obj->autostart = autostart ? 1 : 0;
+    if (virNetworkObjSetAutostart(obj, NULL, NULL, autostart) < 0)
+        goto cleanup;
+
     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