]> git.proxmox.com Git - pve-qemu-kvm.git/blame - debian/patches/pve/0028-qmp-add-get_link_status.patch
bump version to 2.6.2-2
[pve-qemu-kvm.git] / debian / patches / pve / 0028-qmp-add-get_link_status.patch
CommitLineData
6fb04df7 1From 9170833ae6e593326b1a37892282d4177ab7414e Mon Sep 17 00:00:00 2001
ca0fe5f5
WB
2From: Wolfgang Bumiller <w.bumiller@proxmox.com>
3Date: Wed, 9 Dec 2015 16:34:41 +0100
6fb04df7 4Subject: [PATCH 28/55] qmp: add get_link_status
ca0fe5f5
WB
5
6---
7 net/net.c | 27 +++++++++++++++++++++++++++
8 qapi-schema.json | 15 +++++++++++++++
9 qmp-commands.hx | 23 +++++++++++++++++++++++
10 scripts/qapi.py | 2 ++
11 4 files changed, 67 insertions(+)
12
13diff --git a/net/net.c b/net/net.c
6fb04df7 14index 6b0b375..0e3f231 100644
ca0fe5f5
WB
15--- a/net/net.c
16+++ b/net/net.c
6fb04df7 17@@ -1325,6 +1325,33 @@ void hmp_info_network(Monitor *mon, const QDict *qdict)
ca0fe5f5
WB
18 }
19 }
20
21+int64_t qmp_get_link_status(const char *name, Error **errp)
22+{
23+ NetClientState *ncs[MAX_QUEUE_NUM];
24+ NetClientState *nc;
25+ int queues;
26+ bool ret;
27+
28+ queues = qemu_find_net_clients_except(name, ncs,
29+ NET_CLIENT_OPTIONS_KIND_MAX,
30+ MAX_QUEUE_NUM);
31+
32+ if (queues == 0) {
33+ error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND,
34+ "Device '%s' not found", name);
35+ return (int64_t) -1;
36+ }
37+
38+ nc = ncs[0];
39+ ret = ncs[0]->link_down;
40+
41+ if (nc->peer->info->type == NET_CLIENT_OPTIONS_KIND_NIC) {
42+ ret = ncs[0]->peer->link_down;
43+ }
44+
45+ return (int64_t) ret ? 0 : 1;
46+}
47+
48 void qmp_set_link(const char *name, bool up, Error **errp)
49 {
50 NetClientState *ncs[MAX_QUEUE_NUM];
51diff --git a/qapi-schema.json b/qapi-schema.json
6fb04df7 52index 2392139..d1985d2 100644
ca0fe5f5
WB
53--- a/qapi-schema.json
54+++ b/qapi-schema.json
6fb04df7 55@@ -1725,6 +1725,21 @@
ca0fe5f5
WB
56 { 'command': 'set_link', 'data': {'name': 'str', 'up': 'bool'} }
57
58 ##
59+# @get_link_status
60+#
61+# Get the current link state of the nics or nic.
62+#
63+# @name: name of the nic you get the state of
64+#
65+# Return: If link is up 1
66+# If link is down 0
67+# If an error occure an empty string.
68+#
69+# Notes: this is an Proxmox VE extension and not offical part of Qemu.
70+##
71+{ 'command': 'get_link_status', 'data': {'name': 'str'}, 'returns': 'int'}
72+
73+##
74 # @balloon:
75 #
76 # Request the balloon driver to change its balloon size.
77diff --git a/qmp-commands.hx b/qmp-commands.hx
6fb04df7 78index 437ddd6..71c5d53 100644
ca0fe5f5
WB
79--- a/qmp-commands.hx
80+++ b/qmp-commands.hx
6fb04df7 81@@ -1844,6 +1844,29 @@ Example:
ca0fe5f5
WB
82 EQMP
83
84 {
85+ .name = "get_link_status",
86+ .args_type = "name:s",
87+ .mhandler.cmd_new = qmp_marshal_input_get_link_status,
88+ },
89+
90+SQMP
91+get_link_status
92+--------
93+
94+Get the link status of a network adapter.
95+
96+Arguments:
97+
98+- "name": network device name (json-string)
99+
100+Example:
101+
102+-> { "execute": "get_link_status", "arguments": { "name": "e1000.0" } }
103+<- { "return": {1} }
104+
105+EQMP
106+
107+ {
108 .name = "getfd",
109 .args_type = "fdname:s",
110 .params = "getfd name",
111diff --git a/scripts/qapi.py b/scripts/qapi.py
6fb04df7 112index b13ae47..088478a 100644
ca0fe5f5
WB
113--- a/scripts/qapi.py
114+++ b/scripts/qapi.py
6fb04df7 115@@ -39,6 +39,8 @@ builtin_types = {
ca0fe5f5
WB
116
117 # Whitelist of commands allowed to return a non-dictionary
118 returns_whitelist = [
119+ 'get_link_status',
120+
121 # From QMP:
122 'human-monitor-command',
123 'qom-get',
124--
1252.1.4
126