diff options
-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; |