From 7ee90fae96214c1d648a0edbb0c050235cd77517 Mon Sep 17 00:00:00 2001 From: Lee Duncan Date: Tue, 26 Mar 2019 10:19:03 -0700 Subject: Fix output of node printing for multiple paths. The output of "iscsiadmm -m node -P*" changed when libopeniscsiusr was merged, and an earlier attempt was made to clean it up (see commit 59806c99fb3f). This commit fixes output so that. Before this fix, if one had multiple paths to the same target, the output of "iscsiadm -m node -P1" would be: > Target: iqn.2008-04.net.gonzoleeman:01:disk1 > Portal: 10.0.0.1:3260,1 > Iface Name: default > Target: iqn.2008-04.net.gonzoleeman:01:disk1 > Portal: 10.0.1.1:3260,2 > Iface Name: default But this commit fixes the output to be that of iscsiadm before the libopeniscsiusr merge, i.e.: > Target: iqn.2008-04.net.gonzoleeman:01:disk1 > Portal: 10.0.0.1:3260,1 > Iface Name: default > Portal: 10.0.1.1:3260,2 > Iface Name: default --- usr/iscsiadm.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/usr/iscsiadm.c b/usr/iscsiadm.c index 22d62db..a8f6f4a 100644 --- a/usr/iscsiadm.c +++ b/usr/iscsiadm.c @@ -689,13 +689,12 @@ static void print_node_flat(struct iscsi_node *node) iscsi_node_target_name_get(node)); } -// The 'iface_mode' argument is only used for command -// `iscsiadm -m iface -P 1` static void print_nodes_tree(struct iscsi_node **nodes, uint32_t node_count, enum _print_node_tree_mode print_mode) { unsigned int i; struct iscsi_node *cur_node = NULL; + struct iscsi_node *prev_node = NULL; const char *prefix = NULL; if (print_mode == _PRINT_MODE_IFACE) @@ -707,14 +706,24 @@ static void print_nodes_tree(struct iscsi_node **nodes, uint32_t node_count, // is no need to create hash table for this. for (i = 0; i < node_count; ++i) { cur_node = nodes[i]; - printf("%sTarget: %s\n", prefix, - iscsi_node_target_name_get(cur_node)); + /* + * Print the target line if this is our first pass, or + * if if it does not match the prevous target. Always print + * the Portal line. The original code seemed to want to + * suppres duplicates here, as well, but it evidently + * didn't work that way, so let's not regress output format + */ + if (!prev_node || strcmp(iscsi_node_target_name_get(prev_node), + iscsi_node_target_name_get(cur_node))) + printf("%sTarget: %s\n", prefix, + iscsi_node_target_name_get(cur_node)); printf("%s\tPortal: %s,%d\n", prefix, iscsi_node_portal_get(cur_node), iscsi_node_tpgt_get(cur_node)); if (print_mode == _PRINT_MODE_NODE) printf("\t\tIface Name: %s\n", iscsi_node_iface_name_get(cur_node)); + prev_node = cur_node; } } -- cgit v1.2.1