File 0014-teamdctl-add-command-for-easy-port-presention-checki.patch of Package libteam

From ef7b10e7de2af167c75ae00069d502b96e046527 Mon Sep 17 00:00:00 2001
From: Jiri Pirko <jiri@resnulli.us>
Date: Thu, 27 Mar 2014 13:17:48 +0100
Subject: [patch libteam 1/2] teamdctl: add command for easy port presention
 checking

Signed-off-by: Jiri Pirko <jiri@resnulli.us>
---
 man/teamdctl.8   |  3 +++
 utils/teamdctl.c | 30 ++++++++++++++++++++++++++++++
 2 files changed, 33 insertions(+)

diff --git a/man/teamdctl.8 b/man/teamdctl.8
index ff1fdee..81bb6ff 100644
--- a/man/teamdctl.8
+++ b/man/teamdctl.8
@@ -68,6 +68,9 @@ Takes port device name as argument. Adds port device into team.
 .BI "port remove " portdev
 Takes port device name as argument. Removes port device from team.
 .TP
+.BI "port present " portdev
+Takes port device name as argument. Checks if the port device is present in team.
+.TP
 .BI "port config update " "portdev portconfig-string"
 Takes port device name as the first argument and JSON format configuration
 string as the second argument. Updates port device configuration.
diff --git a/utils/teamdctl.c b/utils/teamdctl.c
index c1b9d7e..ee5be75 100644
--- a/utils/teamdctl.c
+++ b/utils/teamdctl.c
@@ -535,6 +535,22 @@ static int stateview_process_reply(char *reply)
 	return stateview_json_process(reply);
 }
 
+static int state_json_port_present(char *dump, const char *port_devname)
+{
+	json_t *dump_json;
+	json_t *port_json;
+	int err;
+
+	err = __jsonload(&dump_json, dump);
+	if (err)
+		return err;
+	err = json_unpack(dump_json, "{s:{s:o}}", "ports", port_devname, &port_json);
+	if (err)
+		err = -ENODEV;
+	json_decref(dump_json);
+	return err;
+}
+
 static int call_method_config_jsonsimpledump(struct teamdctl *tdc,
 					     int argc, char **argv)
 {
@@ -577,6 +593,12 @@ static int call_method_port_remove(struct teamdctl *tdc,
 	return teamdctl_port_remove(tdc, argv[0]);
 }
 
+static int call_method_port_present(struct teamdctl *tdc,
+				  int argc, char **argv)
+{
+	return state_json_port_present(teamdctl_state_get_raw(tdc), argv[0]);
+}
+
 static int call_method_port_config_update(struct teamdctl *tdc,
 					  int argc, char **argv)
 {
@@ -631,6 +653,7 @@ enum id_command_type {
 	ID_CMDTYPE_P,
 	ID_CMDTYPE_P_A,
 	ID_CMDTYPE_P_R,
+	ID_CMDTYPE_P_P,
 	ID_CMDTYPE_P_C,
 	ID_CMDTYPE_P_C_U,
 	ID_CMDTYPE_P_C_D,
@@ -729,6 +752,13 @@ static struct command_type command_types[] = {
 		.params = {"PORTDEV"},
 	},
 	{
+		.id = ID_CMDTYPE_P_P,
+		.parent_id = ID_CMDTYPE_P,
+		.name = "present",
+		.call_method = call_method_port_present,
+		.params = {"PORTDEV"},
+	},
+	{
 		.id = ID_CMDTYPE_P_C,
 		.parent_id = ID_CMDTYPE_P,
 		.name = "config",
-- 
1.8.5.3