Commit 9a17b539 authored by Shuhei Matsumoto's avatar Shuhei Matsumoto Committed by Jim Harris
Browse files

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: default avatarShuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Change-Id: I3e92bcb4f21cc7a36af182f850c944b8c5dd559f
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/463568


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Reviewed-by: default avatarPaul Luse <paul.e.luse@intel.com>
Reviewed-by: default avatarBroadcom SPDK FC-NVMe CI <spdk-ci.pdl@broadcom.com>
parent fb641c4b
Loading
Loading
Loading
Loading
+37 −0
Original line number Diff line number Diff line
@@ -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);
}
+1 −0
Original line number Diff line number Diff line
@@ -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 */
+1 −31
Original line number Diff line number Diff line
@@ -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);