diff options
author | Lee Duncan <leeman.duncan@gmail.com> | 2019-03-26 10:07:28 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-03-26 10:07:28 -0700 |
commit | d1f75b6d912ab03c0897a8cfdc378d3bdc563f13 (patch) | |
tree | ebc3bf681eb92b078cd0a76d605d750ecd3f1d33 | |
parent | eea99b8d6928997827de49e9e767936e0f79564e (diff) | |
parent | 05b4d14cb855526c10f65d2b36cd239d7f1ec3b4 (diff) | |
download | open-iscsi-d1f75b6d912ab03c0897a8cfdc378d3bdc563f13.tar.gz |
Merge pull request #161 from gonzoleeman/fix-node-mode-return-v2
Fix printing of node database again.
-rw-r--r-- | usr/iscsiadm.c | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/usr/iscsiadm.c b/usr/iscsiadm.c index ef9ea84..22d62db 100644 --- a/usr/iscsiadm.c +++ b/usr/iscsiadm.c @@ -681,6 +681,14 @@ static int login_portals(struct node_rec *pattern_rec) return rc; } +static void print_node_flat(struct iscsi_node *node) +{ + printf("%s,%" PRIu16 " %s\n", + iscsi_node_portal_get(node), + iscsi_node_tpgt_get(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, @@ -710,6 +718,40 @@ static void print_nodes_tree(struct iscsi_node **nodes, uint32_t node_count, } } +static int print_nodes(struct iscsi_context *ctx, int info_level) +{ + struct iscsi_node **nodes = NULL; + uint32_t node_count = 0; + uint32_t i = 0; + int rc = 0; + + if ((info_level != 0) && (info_level != -1) && (info_level != 1)) { + log_error("Invalid info level %d. Try 0 or 1.", info_level); + rc = ISCSI_ERR_INVAL; + goto out; + } + + rc = iscsi_nodes_get(ctx, &nodes, &node_count); + if (rc != LIBISCSI_OK) + goto out; + + if (!node_count) { + log_error("No records found"); + rc = ISCSI_ERR_NO_OBJS_FOUND; + goto out; + } + + if (info_level == 1) + print_nodes_tree(nodes, node_count, _PRINT_MODE_NODE); + else + for (i = 0; i < node_count; ++i) + print_node_flat(nodes[i]); + +out: + iscsi_nodes_free(nodes, node_count); + return rc; +} + static int print_nodes_config(struct iscsi_context *ctx, bool show_secret, const char *target_name, const char *address, int32_t port, const char *iface_name) @@ -2780,6 +2822,14 @@ static int exec_node_op(struct iscsi_context *ctx, int op, int do_login, goto out; } + if ((!do_login && !do_logout && op == OP_NOOP) && + ((rec == NULL) || + (!strlen(rec->name) && !strlen(rec->conn[0].address) && + !strlen(rec->iface.name)))) { + rc = print_nodes(ctx, info_level); + goto out; + } + if (do_login) { rc = login_portals(rec); goto out; |