Received: from eggs.gnu.org ([2001:4830:134:3::10]:52579) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xz4UB-00022D-Qn for qemu-devel@nongnu.org; Thu, 11 Dec 2014 09:13:00 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Xz4U7-0000UU-3P for qemu-devel@nongnu.org; Thu, 11 Dec 2014 09:12:55 -0500 Received: from uplink-gw.mit.1050.kapper.net ([94.136.31.129]:55959 helo=ella.proxmox.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xz4U6-0000UE-T1 for qemu-devel@nongnu.org; Thu, 11 Dec 2014 09:12:51 -0500 From: Wolfgang Link Date: Thu, 11 Dec 2014 14:36:14 +0100 Message-Id: <1418304974-15117-1-git-send-email-wolfgang@linksystems.org> Subject: [Qemu-devel] [PATCH] qmp: implement a qmp command get_link_status List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: aliguori@amazon.com, Wolfgang Link , armbru@redhat.com, lcapitulino@redhat.com, stefanha@redhat.com this qmp command returns the current link state from the given nic this is impotent if the set_link failed or get an timeout. Signed-off-by: Wolfgang Link --- net/net.c | 26 ++++++++++++++++++++++++++ qapi-schema.json | 15 +++++++++++++++ qmp-commands.hx | 22 ++++++++++++++++++++++ 3 files changed, 63 insertions(+) diff --git a/net/net.c b/net/net.c index 7acc162..57c6f1e 100644 --- a/net/net.c +++ b/net/net.c @@ -1141,6 +1141,32 @@ void do_info_network(Monitor *mon, const QDict *qdict) } } +int64_t qmp_get_link_status(const char *name, Error **errp) +{ + NetClientState *ncs[MAX_QUEUE_NUM]; + NetClientState *nc; + int queues; + bool ret; + + queues = qemu_find_net_clients_except(name, ncs, + NET_CLIENT_OPTIONS_KIND_MAX, + MAX_QUEUE_NUM); + + if (queues == 0) { + error_set(errp, QERR_DEVICE_NOT_FOUND, name); + return (int64_t) -1; + } + + nc = ncs[0]; + ret = ncs[0]->link_down; + + if (nc->peer->info->type == NET_CLIENT_OPTIONS_KIND_NIC) { + ret = ncs[0]->peer->link_down; + } + + return (int64_t) ret ? 0 : 1; +} + void qmp_set_link(const char *name, bool up, Error **errp) { NetClientState *ncs[MAX_QUEUE_NUM]; diff --git a/qapi-schema.json b/qapi-schema.json index 9ffdcf8..c5321e6 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -1200,6 +1200,21 @@ { 'command': 'inject-nmi' } ## +# @get_link_status +# +# Get the current link state of the nics or nic. +# +# @name: name of the nic you get the state of +# +# Return: If link is up 1 +# If link is down 0 +# If an error occure an empty string. +# +# Notes: this is an Proxmox VE extension and not offical part of Qemu. +## +{ 'command': 'get_link_status', 'data': {'name': 'str'}, 'returns': 'int'} + +## # @set_link: # # Sets the link status of a virtual network adapter. diff --git a/qmp-commands.hx b/qmp-commands.hx index 718dd92..ecc501a 100644 --- a/qmp-commands.hx +++ b/qmp-commands.hx @@ -1431,6 +1431,28 @@ Example: EQMP { + .name = "get_link_status", + .args_type = "name:s", + .mhandler.cmd_new = qmp_marshal_input_get_link_status, + }, + +SQMP +get_link_status +-------- + +Get the link status of a network adapter. + +Arguments: + +- "name": network device name (json-string) + +Example: + +-> { "execute": "set_link", "arguments": { "name": "e1000.0" } } +<- { "return": {1} } +EQMP + + { .name = "set_link", .args_type = "name:s,up:b", .mhandler.cmd_new = qmp_marshal_input_set_link, -- 1.7.10.4