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

[libvirt] [PATCH 08/10] linkstate: qemu: Add monitor support for setting link state



Adds support for QMP and text monitor access to qemu.
---
 src/qemu/qemu_monitor.c      |   19 +++++++++++++++++
 src/qemu/qemu_monitor.h      |    3 ++
 src/qemu/qemu_monitor_json.c |   23 ++++++++++++++++++++
 src/qemu/qemu_monitor_json.h |    4 +++
 src/qemu/qemu_monitor_text.c |   47 ++++++++++++++++++++++++++++++++++++++++++
 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..53a0ce3 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,
+                       unsigned int state)
+{
+    int ret;
+    VIR_DEBUG("mon=%p, name=%p:%s, state=%u", mon, name, name, state);
+
+    if (!mon || !name) {
+        qemuReportError(VIR_ERR_INVALID_ARG, "%s",
+                        _("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..a42313c 100644
--- a/src/qemu/qemu_monitor.h
+++ b/src/qemu/qemu_monitor.h
@@ -145,6 +145,9 @@ void qemuMonitorUnlock(qemuMonitorPtr mon);
 int qemuMonitorRef(qemuMonitorPtr mon);
 int qemuMonitorUnref(qemuMonitorPtr mon) ATTRIBUTE_RETURN_CHECK;

+int qemuMonitorSetLink(qemuMonitorPtr mon, const char *name,
+                       unsigned int 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 2a9a078..f2f8dd5 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,
+                           unsigned int state)
+{
+
+    int ret;
+    virJSONValuePtr reply = NULL;
+    virJSONValuePtr cmd = qemuMonitorJSONMakeCommand("set_link",
+                                                     "s:name", name,
+                                                     "b:up", state==VIR_LINK_STATE_DOWN?false:true,
+                                                     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..a029f5d 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,
+                           unsigned int state);
+
 #endif /* QEMU_MONITOR_JSON_H */
diff --git a/src/qemu/qemu_monitor_text.c b/src/qemu/qemu_monitor_text.c
index 7bf733d..2739c50 100644
--- a/src/qemu/qemu_monitor_text.c
+++ b/src/qemu/qemu_monitor_text.c
@@ -416,6 +416,53 @@ int qemuMonitorTextSystemPowerdown(qemuMonitorPtr mon) {
     return 0;
 }

+int qemuMonitorTextSetLink(qemuMonitorPtr mon, const char *name, unsigned int state) {
+    char *info = NULL;
+    char *cmd = NULL;
+    const char *st_str = NULL;
+
+    /* determine state */
+    if (state == VIR_LINK_STATE_DEFAULT ||
+        state == VIR_LINK_STATE_UP)
+        st_str = "on";
+    else
+        st_str = "off";
+
+    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..43fc69d 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,
+                           unsigned int state);
+
 #endif /* QEMU_MONITOR_TEXT_H */
-- 
1.7.6


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