]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virsh: Make domif-setlink work more than once
authorMichal Privoznik <mprivozn@redhat.com>
Mon, 30 Jan 2023 09:55:22 +0000 (10:55 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Mon, 30 Jan 2023 11:06:41 +0000 (12:06 +0100)
In virsh, we have this convenient domif-setlink command, which is
just a wrapper over virDomainUpdateDeviceFlags() and which allows
setting link state of given guest NIC. It does so by fetching
corresponding <interface/> XML snippet and either putting <link
state=''/> into it, OR if the element already exists setting the
attribute to desired value. The XML is then fed into the update
API.

There's, however, a small bug in detecting the pre-existence of
the element and its attribute. The code looks at "link"
attribute, while in fact, the attribute is called "state".

Resolves: https://gitlab.com/libvirt/libvirt/-/issues/426
Fixes: e575bf082ed4889280be07c986375f1ca15bb7ee
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
tools/virsh-domain.c

index 6b431bd1e5279e302ac451160ee2dc3348df17b1..59b2b3ce60a70f76fb2a96b7a46b761e9f57d3c4 100644 (file)
@@ -3209,7 +3209,7 @@ cmdDomIfSetLink(vshControl *ctl, const vshCmd *cmd)
         }
     }
 
-    if (xmlHasProp(linkNode, BAD_CAST "link"))
+    if (xmlHasProp(linkNode, BAD_CAST "state"))
         stateAttr = xmlSetProp(linkNode, BAD_CAST "state", BAD_CAST state);
     else
         stateAttr = xmlNewProp(linkNode, BAD_CAST "state", BAD_CAST state);