]>
Commit | Line | Data |
---|---|---|
1ee59530 WB |
1 | Index: new/scripts/qapi.py |
2 | =================================================================== | |
3 | --- new.orig/scripts/qapi.py 2015-07-13 10:00:00.000000000 +0100 | |
4 | +++ new/scripts/qapi.py 2015-07-13 15:50:00.000000000 +0100 | |
5 | @@ -37,6 +37,8 @@ | |
6 | ||
7 | # Whitelist of commands allowed to return a non-dictionary | |
8 | returns_whitelist = [ | |
9 | + 'get_link_status', | |
10 | + | |
11 | # From QMP: | |
12 | 'human-monitor-command', | |
13 | 'query-migrate-cache-size', | |
1bd87f7c WL |
14 | Index: new/qapi-schema.json |
15 | =================================================================== | |
16 | --- new.orig/qapi-schema.json 2014-12-10 09:15:50.890262765 +0100 | |
17 | +++ new/qapi-schema.json 2014-12-11 09:20:31.072561486 +0100 | |
1ee59530 | 18 | @@ -1366,6 +1366,21 @@ |
1bd87f7c WL |
19 | ## |
20 | { 'command': 'set_link', 'data': {'name': 'str', 'up': 'bool'} } | |
21 | ||
1bd87f7c WL |
22 | +## |
23 | +# @get_link_status | |
24 | +# | |
25 | +# Get the current link state of the nics or nic. | |
26 | +# | |
27 | +# @name: name of the nic you get the state of | |
28 | +# | |
29 | +# Return: If link is up 1 | |
30 | +# If link is down 0 | |
31 | +# If an error occure an empty string. | |
32 | +# | |
33 | +# Notes: this is an Proxmox VE extension and not offical part of Qemu. | |
34 | +## | |
1ee59530 | 35 | +{ 'command': 'get_link_status', 'data': {'name': 'str'}, 'returns': 'int'} |
1bd87f7c WL |
36 | + |
37 | ## | |
38 | # @balloon: | |
39 | # | |
40 | Index: new/net/net.c | |
41 | =================================================================== | |
42 | --- new.orig/net/net.c 2014-12-10 10:24:39.790496356 +0100 | |
43 | +++ new/net/net.c 2014-12-11 09:37:55.971321170 +0100 | |
e647d55d | 44 | @@ -1141,6 +1141,33 @@ |
1bd87f7c WL |
45 | } |
46 | } | |
47 | ||
48 | +int64_t qmp_get_link_status(const char *name, Error **errp) | |
49 | +{ | |
50 | + NetClientState *ncs[MAX_QUEUE_NUM]; | |
51 | + NetClientState *nc; | |
52 | + int queues; | |
53 | + bool ret; | |
54 | + | |
55 | + queues = qemu_find_net_clients_except(name, ncs, | |
56 | + NET_CLIENT_OPTIONS_KIND_MAX, | |
57 | + MAX_QUEUE_NUM); | |
58 | + | |
59 | + if (queues == 0) { | |
e647d55d WB |
60 | + error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND, |
61 | + "Device '%s' not found", name); | |
62 | + return (int64_t) -1; | |
1bd87f7c WL |
63 | + } |
64 | + | |
65 | + nc = ncs[0]; | |
66 | + ret = ncs[0]->link_down; | |
67 | + | |
68 | + if (nc->peer->info->type == NET_CLIENT_OPTIONS_KIND_NIC) { | |
69 | + ret = ncs[0]->peer->link_down; | |
70 | + } | |
71 | + | |
72 | + return (int64_t) ret ? 0 : 1; | |
73 | +} | |
74 | + | |
75 | void qmp_set_link(const char *name, bool up, Error **errp) | |
76 | { | |
77 | NetClientState *ncs[MAX_QUEUE_NUM]; | |
78 | Index: new/qmp-commands.hx | |
79 | =================================================================== | |
80 | --- new.orig/qmp-commands.hx 2014-12-10 09:15:50.891262737 +0100 | |
81 | +++ new/qmp-commands.hx 2014-12-11 08:36:26.583532314 +0100 | |
82 | @@ -1473,6 +1473,29 @@ | |
83 | EQMP | |
84 | ||
85 | { | |
86 | + .name = "get_link_status", | |
87 | + .args_type = "name:s", | |
88 | + .mhandler.cmd_new = qmp_marshal_input_get_link_status, | |
89 | + }, | |
90 | + | |
91 | +SQMP | |
92 | +get_link_status | |
93 | +-------- | |
94 | + | |
95 | +Get the link status of a network adapter. | |
96 | + | |
97 | +Arguments: | |
98 | + | |
99 | +- "name": network device name (json-string) | |
100 | + | |
101 | +Example: | |
102 | + | |
1ee59530 | 103 | +-> { "execute": "get_link_status", "arguments": { "name": "e1000.0" } } |
1bd87f7c WL |
104 | +<- { "return": {1} } |
105 | + | |
106 | +EQMP | |
107 | + | |
108 | + { | |
109 | .name = "getfd", | |
110 | .args_type = "fdname:s", | |
111 | .params = "getfd name", |