735c6b
From f895d23743a65141a2db7f816e56d18c9c4de6df Mon Sep 17 00:00:00 2001
735c6b
Message-Id: <f895d23743a65141a2db7f816e56d18c9c4de6df@dist-git>
735c6b
From: Michal Privoznik <mprivozn@redhat.com>
735c6b
Date: Mon, 30 Jan 2023 10:55:22 +0100
735c6b
Subject: [PATCH] virsh: Make domif-setlink work more than once
735c6b
MIME-Version: 1.0
735c6b
Content-Type: text/plain; charset=UTF-8
735c6b
Content-Transfer-Encoding: 8bit
735c6b
735c6b
In virsh, we have this convenient domif-setlink command, which is
735c6b
just a wrapper over virDomainUpdateDeviceFlags() and which allows
735c6b
setting link state of given guest NIC. It does so by fetching
735c6b
corresponding <interface/> XML snippet and either putting 
735c6b
state=''/> into it, OR if the element already exists setting the
735c6b
attribute to desired value. The XML is then fed into the update
735c6b
API.
735c6b
735c6b
There's, however, a small bug in detecting the pre-existence of
735c6b
the element and its attribute. The code looks at "link"
735c6b
attribute, while in fact, the attribute is called "state".
735c6b
735c6b
Resolves: https://gitlab.com/libvirt/libvirt/-/issues/426
735c6b
Fixes: e575bf082ed4889280be07c986375f1ca15bb7ee
735c6b
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
735c6b
Reviewed-by: Ján Tomko <jtomko@redhat.com>
735c6b
(cherry picked from commit 6f3f6c0f763b9ffd8ef93eb124c88dd0b79138fc)
735c6b
https://bugzilla.redhat.com/show_bug.cgi?id=2165466
735c6b
---
735c6b
 tools/virsh-domain.c | 2 +-
735c6b
 1 file changed, 1 insertion(+), 1 deletion(-)
735c6b
735c6b
diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
735c6b
index 6b431bd1e5..59b2b3ce60 100644
735c6b
--- a/tools/virsh-domain.c
735c6b
+++ b/tools/virsh-domain.c
735c6b
@@ -3209,7 +3209,7 @@ cmdDomIfSetLink(vshControl *ctl, const vshCmd *cmd)
735c6b
         }
735c6b
     }
735c6b
 
735c6b
-    if (xmlHasProp(linkNode, BAD_CAST "link"))
735c6b
+    if (xmlHasProp(linkNode, BAD_CAST "state"))
735c6b
         stateAttr = xmlSetProp(linkNode, BAD_CAST "state", BAD_CAST state);
735c6b
     else
735c6b
         stateAttr = xmlNewProp(linkNode, BAD_CAST "state", BAD_CAST state);
735c6b
-- 
735c6b
2.39.1
735c6b