diff --git a/lib/iscsi/conn.c b/lib/iscsi/conn.c index 868145cf5..82b9ccd25 100644 --- a/lib/iscsi/conn.c +++ b/lib/iscsi/conn.c @@ -1500,3 +1500,40 @@ SPDK_TRACE_REGISTER_FN(iscsi_conn_trace, "iscsi_conn", TRACE_GROUP_ISCSI) spdk_trace_register_description("ISCSI_PDU_COMPLETED", TRACE_ISCSI_PDU_COMPLETED, OWNER_ISCSI_CONN, OBJECT_ISCSI_PDU, 0, 0, ""); } + +void +spdk_iscsi_conn_info_json(struct spdk_json_write_ctx *w, struct spdk_iscsi_conn *conn) +{ + uint16_t tsih; + + if (!conn->is_valid) { + return; + } + + spdk_json_write_object_begin(w); + + spdk_json_write_named_int32(w, "id", conn->id); + + spdk_json_write_named_int32(w, "cid", conn->cid); + + /* + * If we try to return data for a connection that has not + * logged in yet, the session will not be set. So in this + * case, return -1 for the tsih rather than segfaulting + * on the null conn->sess. + */ + if (conn->sess == NULL) { + tsih = -1; + } else { + tsih = conn->sess->tsih; + } + spdk_json_write_named_int32(w, "tsih", tsih); + + spdk_json_write_named_string(w, "initiator_addr", conn->initiator_addr); + + spdk_json_write_named_string(w, "target_addr", conn->target_addr); + + spdk_json_write_named_string(w, "target_node_name", conn->target_short_name); + + spdk_json_write_object_end(w); +} diff --git a/lib/iscsi/conn.h b/lib/iscsi/conn.h index d79885799..d2c1ec484 100644 --- a/lib/iscsi/conn.h +++ b/lib/iscsi/conn.h @@ -189,4 +189,5 @@ void spdk_iscsi_conn_write_pdu(struct spdk_iscsi_conn *conn, struct spdk_iscsi_p void spdk_iscsi_conn_free_pdu(struct spdk_iscsi_conn *conn, struct spdk_iscsi_pdu *pdu); +void spdk_iscsi_conn_info_json(struct spdk_json_write_ctx *w, struct spdk_iscsi_conn *conn); #endif /* SPDK_ISCSI_CONN_H */ diff --git a/lib/iscsi/iscsi_rpc.c b/lib/iscsi/iscsi_rpc.c index 9b1b953c8..9d72a90c1 100644 --- a/lib/iscsi/iscsi_rpc.c +++ b/lib/iscsi/iscsi_rpc.c @@ -884,7 +884,6 @@ spdk_rpc_get_iscsi_connections(struct spdk_jsonrpc_request *request, struct spdk_json_write_ctx *w; struct spdk_iscsi_conn *conns = g_conns_array; int i; - uint16_t tsih; if (params != NULL) { spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, @@ -898,36 +897,7 @@ spdk_rpc_get_iscsi_connections(struct spdk_jsonrpc_request *request, for (i = 0; i < MAX_ISCSI_CONNECTIONS; i++) { struct spdk_iscsi_conn *c = &conns[i]; - if (!c->is_valid) { - continue; - } - - spdk_json_write_object_begin(w); - - spdk_json_write_named_int32(w, "id", c->id); - - spdk_json_write_named_int32(w, "cid", c->cid); - - /* - * If we try to return data for a connection that has not - * logged in yet, the session will not be set. So in this - * case, return -1 for the tsih rather than segfaulting - * on the null c->sess. - */ - if (c->sess == NULL) { - tsih = -1; - } else { - tsih = c->sess->tsih; - } - spdk_json_write_named_int32(w, "tsih", tsih); - - spdk_json_write_named_string(w, "initiator_addr", c->initiator_addr); - - spdk_json_write_named_string(w, "target_addr", c->target_addr); - - spdk_json_write_named_string(w, "target_node_name", c->target_short_name); - - spdk_json_write_object_end(w); + spdk_iscsi_conn_info_json(w, c); } spdk_json_write_array_end(w);