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

[libvirt] [PATCH] network: fully support/use VIR_NETWORK_XML_INACTIVE flag



commit 52d064f42dbc857f4096dc60c0335395ffac73aa added
VIR_NETWORK_XML_INACTIVE in order to allow suppressing the
auto-generated list of VFs in network definitions, and a --inactive
flag to virsh net-dumpxml to take advantage of the flag. However, it
missed out on two oppurtunities:

1) Use INACTIVE to get the current config of the network as it
   exists on disk, rather than the currently active config.

2) Add INACTIVE to the flags used for the virsh net-edit command, so
   that it won't include the forward-pool interfaces that were
   autogenerated, and so that a re-edit of the network prior to
   restarting it will show any other edits made since the last restart
   of the network. (prior to this patch, if you edited a network a 2nd
   time without restarting, all of the previous edits would magically
   disappear).

In order to fit with the new #define-based generic edit function in
virsh.c, a new function vshNetworkGetXMLDesc() was added. This
function first tries to call virNetworkGetXMLDesc with the INACTIVE
flag added, then retries without if the first attempt fails (in the
manner expected when the server doesn't support it).,
---
 src/network/bridge_driver.c |    8 +++++++-
 tools/virsh.c               |   20 ++++++++++++++++++--
 2 files changed, 25 insertions(+), 3 deletions(-)

diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c
index 5f3132c..79d3010 100644
--- a/src/network/bridge_driver.c
+++ b/src/network/bridge_driver.c
@@ -2533,6 +2533,7 @@ static char *networkGetXMLDesc(virNetworkPtr net,
 {
     struct network_driver *driver = net->conn->networkPrivateData;
     virNetworkObjPtr network;
+    virNetworkDefPtr def;
     char *ret = NULL;
 
     virCheckFlags(VIR_NETWORK_XML_INACTIVE, NULL);
@@ -2547,7 +2548,12 @@ static char *networkGetXMLDesc(virNetworkPtr net,
         goto cleanup;
     }
 
-    ret = virNetworkDefFormat(network->def, flags);
+    if ((flags & VIR_NETWORK_XML_INACTIVE) && network->newDef)
+        def = network->newDef;
+    else
+        def = network->def;
+
+    ret = virNetworkDefFormat(def, flags);
 
 cleanup:
     if (network)
diff --git a/tools/virsh.c b/tools/virsh.c
index 0453b95..1c9e44a 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -15806,13 +15806,29 @@ static const vshCmdOptDef opts_network_edit[] = {
     {NULL, 0, 0, NULL}
 };
 
+static char *vshNetworkGetXMLDesc(virNetworkPtr network)
+{
+    unsigned int flags = VIR_NETWORK_XML_INACTIVE;
+    char *doc = virNetworkGetXMLDesc(network, flags);
+
+    if (!doc && last_error->code == VIR_ERR_INVALID_ARG) {
+        /* The server side libvirt doesn't support
+         * VIR_NETWORK_XML_INACTIVE, so retry without it.
+         */
+        virFreeError(last_error);
+        last_error = NULL;
+        flags &= ~VIR_NETWORK_XML_INACTIVE;
+        doc = virNetworkGetXMLDesc(network, flags);
+    }
+    return doc;
+}
+
 static bool
 cmdNetworkEdit(vshControl *ctl, const vshCmd *cmd)
 {
     bool ret = false;
     virNetworkPtr network = NULL;
     virNetworkPtr network_edited = NULL;
-    unsigned int flags = 0;
 
     if (!vshConnectionUsability(ctl, ctl->conn))
         goto cleanup;
@@ -15821,7 +15837,7 @@ cmdNetworkEdit(vshControl *ctl, const vshCmd *cmd)
     if (network == NULL)
         goto cleanup;
 
-#define EDIT_GET_XML virNetworkGetXMLDesc(network, flags)
+#define EDIT_GET_XML vshNetworkGetXMLDesc(network)
 #define EDIT_NOT_CHANGED \
     vshPrint(ctl, _("Network %s XML configuration not changed.\n"), \
              virNetworkGetName (network));                          \
-- 
1.7.10.2


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