]> xenbits.xensource.com Git - libvirt.git/commitdiff
link-state: qemu: Add monitor handling for link state modification
authorPeter Krempa <pkrempa@redhat.com>
Tue, 6 Sep 2011 08:18:57 +0000 (16:18 +0800)
committerDaniel Veillard <veillard@redhat.com>
Tue, 6 Sep 2011 08:18:57 +0000 (16:18 +0800)
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
src/qemu/qemu_monitor.h
src/qemu/qemu_monitor_json.c
src/qemu/qemu_monitor_json.h
src/qemu/qemu_monitor_text.c
src/qemu/qemu_monitor_text.h

index 16bdc594d3b58412f1374c601c1ba167e6234044..fca8fa41ab8cb070b329ee07b2e84b4f989c77ac 100644 (file)
@@ -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)
index 95956041ae2331478c9ed2be96d613c62ccedfb7..390eeff7840395be4ac8ba2f7405c57c88aefd4a 100644 (file)
@@ -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,
index b6368a239c58ca0eaa1758570b75a9dac8bd4502..3a81ec8b069fff0c0b7e1586628cafa2c796d847 100644 (file)
@@ -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)
 {
index 28c4a093a3f147e4a4a1dd6f0ea639a5d81342fd..dfeba7ec8b4f069bbb1c9105b2c4765a83af250a 100644 (file)
@@ -241,4 +241,8 @@ int qemuMonitorJSONBlockJob(qemuMonitorPtr mon,
                             virDomainBlockJobInfoPtr info,
                             int mode);
 
+int qemuMonitorJSONSetLink(qemuMonitorPtr mon,
+                           const char *name,
+                           enum virDomainNetInterfaceLinkState state);
+
 #endif /* QEMU_MONITOR_JSON_H */
index b2a29e030bac70acede4b81a82b1b3d3aee22999..0b50ba2d4207cf69827140b1461253c357418e96 100644 (file)
@@ -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;
index 96d5d78c4cc6e4fe25c36e651cadf9665f7687da..7cc317223f520926b424bcf1cdc95131de8ead9d 100644 (file)
@@ -234,4 +234,8 @@ int qemuMonitorTextBlockJob(qemuMonitorPtr mon,
                             virDomainBlockJobInfoPtr info,
                             int mode);
 
+int qemuMonitorTextSetLink(qemuMonitorPtr mon,
+                           const char *name,
+                           enum virDomainNetInterfaceLinkState state);
+
 #endif /* QEMU_MONITOR_TEXT_H */