net: get link status
authorMunkyu Im <munkyu.im@samsung.com>
Tue, 9 Jun 2015 05:33:21 +0000 (14:33 +0900)
committerSeokYeon Hwang <syeon.hwang@samsung.com>
Fri, 31 Jul 2015 12:27:08 +0000 (21:27 +0900)
added hmp command used for getting link status of specific network adapter.

Change-Id: I82fef064788cbebf0c227ef584c4bfa06b578f7c
Signed-off-by: Munkyu Im <munkyu.im@samsung.com>
hmp-commands.hx
hmp.c
hmp.h
net/net.c
qapi-schema.json
qmp-commands.hx

index e37bc8b010e2754a7aa7e33678f9fff1e355a856..a217cea04c0dced7dfe0b2cb789041dfe71da56c 100644 (file)
@@ -1354,6 +1354,20 @@ STEXI
 @item set_link @var{name} [on|off]
 @findex set_link
 Switch link @var{name} on (i.e. up) or off (i.e. down).
+ETEXI
+    {
+        .name       = "get_link",
+        .args_type  = "name:s",
+        .params     = "name",
+        .help       = "get the link status of a network adapter",
+        .mhandler.cmd = hmp_get_link,
+    },
+
+STEXI
+
+@item get_link @var{name}
+@findex get_link
+Get the link status of @var{name}.
 ETEXI
 
     {
diff --git a/hmp.c b/hmp.c
index 63d76868b9bf7ea9cbc3ddb05d9b82331379546f..17fa8ca18b1b93cffd813a2f4e94f5013d1a6815 100644 (file)
--- a/hmp.c
+++ b/hmp.c
@@ -880,6 +880,19 @@ void hmp_set_link(Monitor *mon, const QDict *qdict)
     hmp_handle_error(mon, &err);
 }
 
+void hmp_get_link(Monitor *mon, const QDict *qdict)
+{
+    const char *name = qdict_get_str(qdict, "name");
+    Error *errp = NULL;
+
+    bool is_up = qmp_get_link(name, &errp);
+    if (errp) {
+        hmp_handle_error(mon, &errp);
+        return;
+    }
+    monitor_printf(mon, "%s\n", is_up ? "on": "off");
+}
+
 void hmp_block_passwd(Monitor *mon, const QDict *qdict)
 {
     const char *device = qdict_get_str(qdict, "device");
diff --git a/hmp.h b/hmp.h
index 4bb5dca45d0c127047fb3aef051734137a877eb8..0b000d197cbe967cdfa593ed7d4c1c5fa4ceb7d8 100644 (file)
--- a/hmp.h
+++ b/hmp.h
@@ -51,6 +51,7 @@ void hmp_cont(Monitor *mon, const QDict *qdict);
 void hmp_system_wakeup(Monitor *mon, const QDict *qdict);
 void hmp_inject_nmi(Monitor *mon, const QDict *qdict);
 void hmp_set_link(Monitor *mon, const QDict *qdict);
+void hmp_get_link(Monitor *mon, const QDict *qdict);
 void hmp_block_passwd(Monitor *mon, const QDict *qdict);
 void hmp_balloon(Monitor *mon, const QDict *qdict);
 void hmp_block_resize(Monitor *mon, const QDict *qdict);
index 7acc162b4400648158a08320573586a17a52f391..bd6d528a14e89841901538c690326b45251c1a8e 100644 (file)
--- a/net/net.c
+++ b/net/net.c
@@ -1201,6 +1201,27 @@ static void net_vm_change_state_handler(void *opaque, int running,
     }
 }
 
+bool qmp_get_link(const char *name, Error **errp)
+{
+    NetClientState *ncs[MAX_QUEUE_NUM];
+    int queues, i;
+    bool down = false;
+
+    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 false;
+    }
+
+    for (i = 0; i < queues; i++) {
+        down = ncs[i]->link_down;
+    }
+    return !down;
+}
+
 void net_cleanup(void)
 {
     NetClientState *nc;
index 8fd42bbd65773ff805c24c47169cb141a6e94bd2..6e02e030f5ec9f000711a8416058c144c2f5c294 100644 (file)
 ##
 { 'command': 'set_link', 'data': {'name': 'str', 'up': 'bool'} }
 
+##
+# @get_link:
+#
+# Gets the link status of a virtual network adapter.
+#
+# @name: the device name of the virtual network adapter
+#
+# Returns: on|off on success
+#          If @name is not a valid network device, DeviceNotFound
+#
+# Since: 2.0.0
+#
+# Notes: Not all network adapters support setting link status.  This command
+#        will succeed even if the network adapter does not support link status
+#        notification.
+##
+{ 'command': 'get_link', 'data': {'name': 'str'}, 'returns': 'bool' }
+
 ##
 # @balloon:
 #
index 718dd92f6a27ab8633c9064fc120a7748c91008e..70c3fbd0251e204cc6078693c805753cf5f164ae 100644 (file)
@@ -1452,6 +1452,30 @@ Example:
 -> { "execute": "set_link", "arguments": { "name": "e1000.0", "up": false } }
 <- { "return": {} }
 
+EQMP
+
+
+    {
+        .name       = "get_link",
+        .args_type  = "name:s",
+        .mhandler.cmd_new = qmp_marshal_input_get_link,
+    },
+
+SQMP
+get_link
+--------
+
+Get the link status of a network adapter.
+
+Arguments:
+
+- "name": network device name (json-string)
+
+Example:
+
+-> { "execute": "get_link", "arguments": { "name": "e1000.0" } }
+<- { "return": {on|off} }
+
 EQMP
 
     {