[PATCH v2 3/5] link-state: qemu: Add monitor handling for link state modification

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

 



This patch adds handlers for modification of guest's interface
link state. Both HMP and QMP commands are supported, but as the
link state functionality is from the beginning supported in QMP
the HMP code will probably never be used.

  src/qemu/qemu_monitor.c        - Add command dispatcher
  src/qemu/qemu_monitor.h        - Add headar for command
  src/qemu/qemu_monitor_json.c   - Add QMP command handling
  src/qemu/qemu_monitor_json.h   - Add header for command
  src/qemu/qemu_monitor_text.c   - Add HMP command handling
  src/qemu/qemu_monitor_text.h   - Add header for command
---
 src/qemu/qemu_monitor.c      |   19 +++++++++++++++++
 src/qemu/qemu_monitor.h      |    4 +++
 src/qemu/qemu_monitor_json.c |   23 +++++++++++++++++++++
 src/qemu/qemu_monitor_json.h |    4 +++
 src/qemu/qemu_monitor_text.c |   46 ++++++++++++++++++++++++++++++++++++++++++
 src/qemu/qemu_monitor_text.h |    4 +++
 6 files changed, 100 insertions(+), 0 deletions(-)

diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index db6107c..5738116 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -1135,6 +1135,25 @@ int qemuMonitorGetCPUInfo(qemuMonitorPtr mon,
     return ret;
 }

+int qemuMonitorSetLink(qemuMonitorPtr mon,
+                       const char *name,
+                       enum virDomainNetInterfaceLinkState state)
+{
+    int ret;
+    VIR_DEBUG("mon=%p, name=%p:%s, state=%u", mon, name, name, state);
+
+    if (!mon || !name) {
+        qemuReportError(VIR_ERR_INVALID_ARG,
+                        _("monitor || name must not be NULL"));
+        return -1;
+    }
+
+    if (mon->json)
+        ret = qemuMonitorJSONSetLink(mon, name, state);
+    else
+        ret = qemuMonitorTextSetLink(mon, name, state);
+    return ret;
+}

 int qemuMonitorGetVirtType(qemuMonitorPtr mon,
                            int *virtType)
diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h
index f241c9e..cd46608 100644
--- a/src/qemu/qemu_monitor.h
+++ b/src/qemu/qemu_monitor.h
@@ -145,6 +145,10 @@ void qemuMonitorUnlock(qemuMonitorPtr mon);
 int qemuMonitorRef(qemuMonitorPtr mon);
 int qemuMonitorUnref(qemuMonitorPtr mon) ATTRIBUTE_RETURN_CHECK;

+int qemuMonitorSetLink(qemuMonitorPtr mon,
+                       const char *name,
+                       enum virDomainNetInterfaceLinkState state) ;
+
 /* These APIs are for use by the internal Text/JSON monitor impl code only */
 char *qemuMonitorNextCommandID(qemuMonitorPtr mon);
 int qemuMonitorSend(qemuMonitorPtr mon,
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index 715b26e..4736e50 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -955,6 +955,29 @@ int qemuMonitorJSONSystemPowerdown(qemuMonitorPtr mon)
     return ret;
 }

+int qemuMonitorJSONSetLink(qemuMonitorPtr mon,
+                           const char *name,
+                           enum virDomainNetInterfaceLinkState state)
+{
+
+    int ret;
+    virJSONValuePtr reply = NULL;
+    virJSONValuePtr cmd = qemuMonitorJSONMakeCommand("set_link",
+                                                     "s:name", name,
+                                                     "b:up", state != VIR_DOMAIN_NET_INTERFACE_LINK_STATE_DOWN,
+                                                     NULL);
+
+    if (!cmd)
+        return -1;
+
+    if ((ret = qemuMonitorJSONCommand(mon, cmd, &reply)) == 0)
+        ret = qemuMonitorJSONCheckError(cmd, reply);
+
+    virJSONValueFree(cmd);
+    virJSONValueFree(reply);
+
+    return ret;
+}

 int qemuMonitorJSONSystemReset(qemuMonitorPtr mon)
 {
diff --git a/src/qemu/qemu_monitor_json.h b/src/qemu/qemu_monitor_json.h
index 9512793..2611b07 100644
--- a/src/qemu/qemu_monitor_json.h
+++ b/src/qemu/qemu_monitor_json.h
@@ -231,4 +231,8 @@ int qemuMonitorJSONBlockJob(qemuMonitorPtr mon,
                             virDomainBlockJobInfoPtr info,
                             int mode);

+int qemuMonitorJSONSetLink(qemuMonitorPtr mon,
+                           const char *name,
+                           enum virDomainNetInterfaceLinkState state);
+
 #endif /* QEMU_MONITOR_JSON_H */
diff --git a/src/qemu/qemu_monitor_text.c b/src/qemu/qemu_monitor_text.c
index 4bd761d..2c0b460 100644
--- a/src/qemu/qemu_monitor_text.c
+++ b/src/qemu/qemu_monitor_text.c
@@ -433,6 +433,52 @@ int qemuMonitorTextSystemPowerdown(qemuMonitorPtr mon) {
     return 0;
 }

+int qemuMonitorTextSetLink(qemuMonitorPtr mon, const char *name, enum virDomainNetInterfaceLinkState state) {
+    char *info = NULL;
+    char *cmd = NULL;
+    const char *st_str = NULL;
+
+    /* determine state */
+    if (state == VIR_DOMAIN_NET_INTERFACE_LINK_STATE_DOWN)
+        st_str = "off";
+    else
+        st_str = "on";
+
+    if (virAsprintf(&cmd, "set_link %s %s", name, st_str) < 0) {
+        virReportOOMError();
+        goto error;
+    }
+    if (qemuMonitorHMPCommand(mon, cmd, &info) < 0) {
+        qemuReportError(VIR_ERR_OPERATION_FAILED,
+                        "%s", _("set_link operation failed"));
+        goto error;
+    }
+
+    /* check if set_link command is supported */
+    if (strstr(info, "\nunknown ")) {
+        qemuReportError(VIR_ERR_NO_SUPPORT,
+                        "%s",
+                        _("\'set_link\' not supported by this qemu"));
+        goto error;
+    }
+
+    /* check if qemu didn't reject device name */
+    if (strstr(info, "\nDevice ")) {
+        qemuReportError(VIR_ERR_OPERATION_FAILED,
+                        "%s", _("device name rejected"));
+        goto error;
+    }
+
+    VIR_FREE(info);
+    VIR_FREE(cmd);
+    return 0;
+
+error:
+    VIR_FREE(info);
+    VIR_FREE(cmd);
+
+    return -1;
+}

 int qemuMonitorTextSystemReset(qemuMonitorPtr mon) {
     char *info;
diff --git a/src/qemu/qemu_monitor_text.h b/src/qemu/qemu_monitor_text.h
index b250738..ddf89fe 100644
--- a/src/qemu/qemu_monitor_text.h
+++ b/src/qemu/qemu_monitor_text.h
@@ -224,4 +224,8 @@ int qemuMonitorTextBlockJob(qemuMonitorPtr mon,
                             virDomainBlockJobInfoPtr info,
                             int mode);

+int qemuMonitorTextSetLink(qemuMonitorPtr mon,
+                           const char *name,
+                           enum virDomainNetInterfaceLinkState state);
+
 #endif /* QEMU_MONITOR_TEXT_H */
-- 
1.7.3.4

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]