[PATCH] virsh: Fix net-desc --config output

K Shiva Kiran posted 1 patch 8 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/20230831181712.42261-1-shiva._5Fkr@riseup.net
There is a newer version of this series
tools/virsh-network.c | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
[PATCH] virsh: Fix net-desc --config output
Posted by K Shiva Kiran 8 months ago
Fixes the following bug:
Command:          `net-desc --config [--title] my_network`
Expected Output:  Title/Description of persistent config
Output:           Title/Description of live config

This was caused due to the usage of a single `flags` variable in
`virshGetNetworkDescription()` which ended up in a wrong enum being
passed to `virNetworkGetMetadata()` (enum being that of LIVE instead of
CONFIG).

Although the domain object has the same code, this didn't cause a problem
there because the enum values of `VIR_DOMAIN_INACTIVE_XML` and
`VIR_DOMAIN_METADATA_CONFIG` turn out to be the same (1 << 1), whereas
they are not for network equivalent ones (1 << 0, 1 << 1).

Signed-off-by: K Shiva Kiran <shiva_kr@riseup.net>
---
 tools/virsh-network.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/tools/virsh-network.c b/tools/virsh-network.c
index 49778d0f4f..8965d87c9c 100644
--- a/tools/virsh-network.c
+++ b/tools/virsh-network.c
@@ -366,7 +366,8 @@ static const vshCmdOptDef opts_network_desc[] = {
 /* extract description or title from network xml */
 static char *
 virshGetNetworkDescription(vshControl *ctl, virNetworkPtr net,
-                           bool title, unsigned int flags)
+                           bool title, unsigned int flags,
+                           unsigned int queryflags)
 {
     char *desc = NULL;
     g_autoptr(xmlDoc) doc = NULL;
@@ -394,7 +395,7 @@ virshGetNetworkDescription(vshControl *ctl, virNetworkPtr net,
     }
 
     /* fall back to xml */
-    if (virshNetworkGetXMLFromNet(ctl, net, flags, &doc, &ctxt) < 0)
+    if (virshNetworkGetXMLFromNet(ctl, net, queryflags, &doc, &ctxt) < 0)
         return NULL;
 
     if (title)
@@ -454,7 +455,7 @@ cmdNetworkDesc(vshControl *ctl, const vshCmd *cmd)
         g_autofree char *descNet = NULL;
         g_autofree char *descNew = NULL;
 
-        if (!(descNet = virshGetNetworkDescription(ctl, net, title, queryflags)))
+        if (!(descNet = virshGetNetworkDescription(ctl, net, title, flags, queryflags)))
             return false;
 
         if (!descArg)
@@ -515,7 +516,7 @@ cmdNetworkDesc(vshControl *ctl, const vshCmd *cmd)
             vshPrintExtra(ctl, "%s", _("Network description updated successfully"));
 
     } else {
-        g_autofree char *desc = virshGetNetworkDescription(ctl, net, title, queryflags);
+        g_autofree char *desc = virshGetNetworkDescription(ctl, net, title, flags, queryflags);
         if (!desc)
             return false;
 
@@ -1128,7 +1129,7 @@ cmdNetworkList(vshControl *ctl, const vshCmd *cmd G_GNUC_UNUSED)
             if (optTitle) {
                 g_autofree char *title = NULL;
 
-                if (!(title = virshGetNetworkDescription(ctl, network, true, 0)))
+                if (!(title = virshGetNetworkDescription(ctl, network, true, 0, 0)))
                     goto cleanup;
                 if (vshTableRowAppend(table,
                             virNetworkGetName(network),
-- 
2.42.0
Re: [PATCH] virsh: Fix net-desc --config output
Posted by Jiri Denemark 8 months ago
On Thu, Aug 31, 2023 at 23:46:57 +0530, K Shiva Kiran wrote:
> Fixes the following bug:
> Command:          `net-desc --config [--title] my_network`
> Expected Output:  Title/Description of persistent config
> Output:           Title/Description of live config
> 
> This was caused due to the usage of a single `flags` variable in
> `virshGetNetworkDescription()` which ended up in a wrong enum being
> passed to `virNetworkGetMetadata()` (enum being that of LIVE instead of
> CONFIG).
> 
> Although the domain object has the same code, this didn't cause a problem
> there because the enum values of `VIR_DOMAIN_INACTIVE_XML` and
> `VIR_DOMAIN_METADATA_CONFIG` turn out to be the same (1 << 1), whereas
> they are not for network equivalent ones (1 << 0, 1 << 1).
> 
> Signed-off-by: K Shiva Kiran <shiva_kr@riseup.net>
> ---
>  tools/virsh-network.c | 11 ++++++-----
>  1 file changed, 6 insertions(+), 5 deletions(-)
...

Reviewed-by: Jiri Denemark <jdenemar@redhat.com>