iscsi: Factor out JSON information of connection
Factor out writing connection information to JSON context into a helper function spdk_iscsi_conn_info_json. Signed-off-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com> Change-Id: I3e92bcb4f21cc7a36af182f850c944b8c5dd559f Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/463568 Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Reviewed-by: Ben Walker <benjamin.walker@intel.com> Reviewed-by: Jim Harris <james.r.harris@intel.com> Reviewed-by: Paul Luse <paul.e.luse@intel.com> Reviewed-by: Broadcom SPDK FC-NVMe CI <spdk-ci.pdl@broadcom.com>
This commit is contained in:
parent
fb641c4b54
commit
9a17b539f9
@ -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);
|
||||
}
|
||||
|
@ -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 */
|
||||
|
@ -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);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user