[spp] [PATCH 56/57] spp_vf: fix status command

x-fn-spp at sl.ntt-tx.co.jp x-fn-spp at sl.ntt-tx.co.jp
Thu Dec 28 05:56:03 CET 2017


From: Hiroyuki Nakamura <nakamura.hioryuki at po.ntt-tx.co.jp>

Fix to display "unuse" even when the core is unused.

Signed-off-by: Kentaro Watanabe <watanabe.kentaro.z01 at as.ntt-tx.co.jp>
Signed-off-by: Yasufum Ogawa <ogawa.yasufumi at lab.ntt.co.jp>
---
 src/vf/command_proc.c | 33 ++++++++++++++++++++-------------
 src/vf/spp_vf.c       | 28 +++++++++++++++++++++-------
 src/vf/spp_vf.h       |  1 +
 3 files changed, 42 insertions(+), 20 deletions(-)

diff --git a/src/vf/command_proc.c b/src/vf/command_proc.c
index 6159e87..ec2da51 100644
--- a/src/vf/command_proc.c
+++ b/src/vf/command_proc.c
@@ -349,6 +349,7 @@ append_core_element_value(
 		const int num_tx, const struct spp_port_index *tx_ports)
 {
 	int ret = -1;
+	int unuse_flg = 0;
 	json_t *parent_obj = (json_t *)opaque;
 	json_t *tab_obj;
 
@@ -356,16 +357,20 @@ append_core_element_value(
 	if (unlikely(tab_obj == NULL))
 		return -1;
 
+	unuse_flg = strcmp(type, SPP_TYPE_UNUSE_STR);
+
 	ret = json_object_set_new(tab_obj, "core", json_integer(lcore_id));
 	if (unlikely(ret != 0)) {
 		json_decref(tab_obj);
 		return -1;
 	}
 
-	ret = json_object_set_new(tab_obj, "name", json_string(name));
-	if (unlikely(ret != 0)) {
-		json_decref(tab_obj);
-		return -1;
+	if (unuse_flg) {
+		ret = json_object_set_new(tab_obj, "name", json_string(name));
+		if (unlikely(ret != 0)) {
+			json_decref(tab_obj);
+			return -1;
+		}
 	}
 
 	ret = json_object_set_new(tab_obj, "type", json_string(type));
@@ -374,16 +379,18 @@ append_core_element_value(
 		return -1;
 	}
 
-	ret = apeend_port_array(tab_obj, "rx_port", num_rx, rx_ports);
-	if (unlikely(ret != 0)) {
-		json_decref(tab_obj);
-		return -1;
-	}
+	if (unuse_flg) {
+		ret = apeend_port_array(tab_obj, "rx_port", num_rx, rx_ports);
+		if (unlikely(ret != 0)) {
+			json_decref(tab_obj);
+			return -1;
+		}
 
-	ret = apeend_port_array(tab_obj, "tx_port", num_tx, tx_ports);
-	if (unlikely(ret != 0)) {
-		json_decref(tab_obj);
-		return -1;
+		ret = apeend_port_array(tab_obj, "tx_port", num_tx, tx_ports);
+		if (unlikely(ret != 0)) {
+			json_decref(tab_obj);
+			return -1;
+		}
 	}
 
 	ret = json_array_append_new(parent_obj, tab_obj);
diff --git a/src/vf/spp_vf.c b/src/vf/spp_vf.c
index f97c348..7626ba7 100644
--- a/src/vf/spp_vf.c
+++ b/src/vf/spp_vf.c
@@ -1338,30 +1338,44 @@ int
 spp_iterate_core_info(struct spp_iterate_core_params *params)
 {
 	int ret;
-	int core_cnt, cnt;
+	int lcore_id, cnt;
 	struct core_info *core = NULL;
 
-	for (core_cnt = 0; core_cnt < RTE_MAX_LCORE; core_cnt++) {
-		if (spp_get_core_status(core_cnt) == SPP_CORE_UNUSE)
+	RTE_LCORE_FOREACH_SLAVE(lcore_id) {
+		if (spp_get_core_status(lcore_id) == SPP_CORE_UNUSE)
 			continue;
 
-		core = get_core_info(core_cnt);
+		core = get_core_info(lcore_id);
+		if (core->num == 0) {
+			ret = (*params->element_proc)(
+				params->opaque, lcore_id,
+				"", SPP_TYPE_UNUSE_STR,
+				0, NULL, 0, NULL);
+			if (unlikely(ret != 0)) {
+				RTE_LOG(ERR, APP, "Cannot iterate core information. "
+						"(core = %d, type = %d)\n",
+						lcore_id, SPP_COMPONENT_UNUSE);
+				return SPP_RET_NG;
+			}
+			continue;
+		}
+
 		for (cnt = 0; cnt < core->num; cnt++) {
 			if (core->type == SPP_COMPONENT_CLASSIFIER_MAC) {
 				ret = spp_classifier_component_info_iterate(
-						core_cnt,
+						lcore_id,
 						core->id[cnt],
 						params);
 			} else {
 				ret = spp_forward_core_info_iterate(
-						core_cnt,
+						lcore_id,
 						core->id[cnt],
 						params);
 			}
 			if (unlikely(ret != 0)) {
 				RTE_LOG(ERR, APP, "Cannot iterate core information. "
 						"(core = %d, type = %d)\n",
-						core_cnt, core->type);
+						lcore_id, core->type);
 				return SPP_RET_NG;
 			}
 		}
diff --git a/src/vf/spp_vf.h b/src/vf/spp_vf.h
index 9e846ef..ea2baf1 100644
--- a/src/vf/spp_vf.h
+++ b/src/vf/spp_vf.h
@@ -6,6 +6,7 @@
 #define SPP_TYPE_CLASSIFIER_MAC_STR "classifier_mac"
 #define SPP_TYPE_MERGE_STR          "merge"
 #define SPP_TYPE_FORWARD_STR        "forward"
+#define SPP_TYPE_UNUSE_STR          "unuse"
 
 #define SPP_IFTYPE_NIC_STR   "phy"
 #define SPP_IFTYPE_VHOST_STR "vhost"
-- 
1.9.1



More information about the spp mailing list