From 1f145b2f0f32b0f2d00d1926fc17c01432ef2fa2 Mon Sep 17 00:00:00 2001 From: Laine Stump Date: Mon, 4 Jun 2012 14:45:16 -0400 Subject: [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 opportunities: 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 ++++++++++++++++++-- tools/virsh.pod | 2 +- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index 5f3132c4cd..79d3010f05 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 90ea43d827..98305c0d7e 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -15823,13 +15823,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; @@ -15838,7 +15854,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)); \ diff --git a/tools/virsh.pod b/tools/virsh.pod index 6553825d7b..6ca316e746 100644 --- a/tools/virsh.pod +++ b/tools/virsh.pod @@ -1823,7 +1823,7 @@ Edit the XML configuration file for a network. This is equivalent to: - virsh net-dumpxml network > network.xml + virsh net-dumpxml --inactive network > network.xml vi network.xml (or make changes with your other text editor) virsh net-define network.xml -- GitLab