added hmp command used for getting link status of specific network adapter.
Change-Id: I82fef064788cbebf0c227ef584c4bfa06b578f7c
Signed-off-by: Munkyu Im <munkyu.im@samsung.com>
@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
{
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");
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);
}
}
+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;
##
{ '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:
#
-> { "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
{