]>
Commit | Line | Data |
---|---|---|
1 | From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 | |
2 | From: Wolfgang Bumiller <w.bumiller@proxmox.com> | |
3 | Date: Mon, 6 Apr 2020 12:16:37 +0200 | |
4 | Subject: [PATCH] PVE: [Up] qmp: add get_link_status | |
5 | ||
6 | Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com> | |
7 | --- | |
8 | net/net.c | 27 +++++++++++++++++++++++++++ | |
9 | qapi/net.json | 15 +++++++++++++++ | |
10 | qapi/pragma.json | 1 + | |
11 | 3 files changed, 43 insertions(+) | |
12 | ||
13 | diff --git a/net/net.c b/net/net.c | |
14 | index 6a2c3d9567..a1e9514fb8 100644 | |
15 | --- a/net/net.c | |
16 | +++ b/net/net.c | |
17 | @@ -1277,6 +1277,33 @@ void hmp_info_network(Monitor *mon, const QDict *qdict) | |
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_DRIVER__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_DRIVER_NIC) { | |
42 | + ret = ncs[0]->peer->link_down; | |
43 | + } | |
44 | + | |
45 | + return (int64_t) ret ? 0 : 1; | |
46 | +} | |
47 | + | |
48 | void colo_notify_filters_event(int event, Error **errp) | |
49 | { | |
50 | NetClientState *nc; | |
51 | diff --git a/qapi/net.json b/qapi/net.json | |
52 | index a3a1336001..b8092c4e20 100644 | |
53 | --- a/qapi/net.json | |
54 | +++ b/qapi/net.json | |
55 | @@ -35,6 +35,21 @@ | |
56 | ## | |
57 | { 'command': 'set_link', 'data': {'name': 'str', 'up': 'bool'} } | |
58 | ||
59 | +## | |
60 | +# @get_link_status: | |
61 | +# | |
62 | +# Get the current link state of the nics or nic. | |
63 | +# | |
64 | +# @name: name of the nic you get the state of | |
65 | +# | |
66 | +# Return: If link is up 1 | |
67 | +# If link is down 0 | |
68 | +# If an error occure an empty string. | |
69 | +# | |
70 | +# Notes: this is an Proxmox VE extension and not offical part of Qemu. | |
71 | +## | |
72 | +{ 'command': 'get_link_status', 'data': {'name': 'str'} , 'returns': 'int' } | |
73 | + | |
74 | ## | |
75 | # @netdev_add: | |
76 | # | |
77 | diff --git a/qapi/pragma.json b/qapi/pragma.json | |
78 | index cffae27666..5a3e3de95f 100644 | |
79 | --- a/qapi/pragma.json | |
80 | +++ b/qapi/pragma.json | |
81 | @@ -5,6 +5,7 @@ | |
82 | { 'pragma': { | |
83 | # Commands allowed to return a non-dictionary: | |
84 | 'returns-whitelist': [ | |
85 | + 'get_link_status', | |
86 | 'human-monitor-command', | |
87 | 'qom-get', | |
88 | 'query-migrate-cache-size', |