]> git.proxmox.com Git - ceph.git/blob - ceph/src/spdk/lib/iscsi/conn.h
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / spdk / lib / iscsi / conn.h
1 /*-
2 * BSD LICENSE
3 *
4 * Copyright (C) 2008-2012 Daisuke Aoyama <aoyama@peach.ne.jp>.
5 * Copyright (c) Intel Corporation.
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * * Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * * Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in
16 * the documentation and/or other materials provided with the
17 * distribution.
18 * * Neither the name of Intel Corporation nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 */
34
35 #ifndef SPDK_ISCSI_CONN_H
36 #define SPDK_ISCSI_CONN_H
37
38 #include "spdk/stdinc.h"
39
40 #include "iscsi/iscsi.h"
41 #include "spdk/queue.h"
42 #include "spdk/cpuset.h"
43 #include "spdk/scsi.h"
44
45 /*
46 * MAX_CONNECTION_PARAMS: The numbers of the params in conn_param_table
47 * MAX_SESSION_PARAMS: The numbers of the params in sess_param_table
48 */
49 #define MAX_CONNECTION_PARAMS 14
50 #define MAX_SESSION_PARAMS 19
51
52 #define MAX_ADDRBUF 64
53 #define MAX_INITIATOR_ADDR (MAX_ADDRBUF)
54 #define MAX_TARGET_ADDR (MAX_ADDRBUF)
55
56 #define OWNER_ISCSI_CONN 0x1
57
58 #define OBJECT_ISCSI_PDU 0x1
59
60 #define TRACE_GROUP_ISCSI 0x1
61 #define TRACE_ISCSI_READ_FROM_SOCKET_DONE SPDK_TPOINT_ID(TRACE_GROUP_ISCSI, 0x0)
62 #define TRACE_ISCSI_FLUSH_WRITEBUF_START SPDK_TPOINT_ID(TRACE_GROUP_ISCSI, 0x1)
63 #define TRACE_ISCSI_FLUSH_WRITEBUF_DONE SPDK_TPOINT_ID(TRACE_GROUP_ISCSI, 0x2)
64 #define TRACE_ISCSI_READ_PDU SPDK_TPOINT_ID(TRACE_GROUP_ISCSI, 0x3)
65 #define TRACE_ISCSI_TASK_DONE SPDK_TPOINT_ID(TRACE_GROUP_ISCSI, 0x4)
66 #define TRACE_ISCSI_TASK_QUEUE SPDK_TPOINT_ID(TRACE_GROUP_ISCSI, 0x5)
67 #define TRACE_ISCSI_TASK_EXECUTED SPDK_TPOINT_ID(TRACE_GROUP_ISCSI, 0x6)
68 #define TRACE_ISCSI_PDU_COMPLETED SPDK_TPOINT_ID(TRACE_GROUP_ISCSI, 0x7)
69
70 struct spdk_poller;
71
72 struct spdk_iscsi_conn {
73 int id;
74 int is_valid;
75 /*
76 * All fields below this point are reinitialized each time the
77 * connection object is allocated. Make sure to update the
78 * SPDK_ISCSI_CONNECTION_MEMSET() macro if changing which fields
79 * are initialized when allocated.
80 */
81 struct spdk_iscsi_portal *portal;
82 int pg_tag;
83 char *portal_host;
84 char *portal_port;
85 struct spdk_cpuset *portal_cpumask;
86 uint32_t lcore;
87 struct spdk_sock *sock;
88 struct spdk_iscsi_sess *sess;
89
90 enum iscsi_connection_state state;
91 int login_phase;
92
93 uint64_t last_flush;
94 uint64_t last_fill;
95 uint64_t last_nopin;
96
97 /* Timer used to destroy connection after logout if initiator does
98 * not close the connection.
99 */
100 struct spdk_poller *logout_timer;
101
102 /* Timer used to wait for connection to close
103 */
104 struct spdk_poller *shutdown_timer;
105
106 struct spdk_iscsi_pdu *pdu_in_progress;
107
108 TAILQ_HEAD(, spdk_iscsi_pdu) write_pdu_list;
109 TAILQ_HEAD(, spdk_iscsi_pdu) snack_pdu_list;
110
111 int pending_r2t;
112 struct spdk_iscsi_task *outstanding_r2t_tasks[DEFAULT_MAXR2T];
113
114 uint16_t cid;
115
116 /* IP address */
117 char initiator_addr[MAX_INITIATOR_ADDR];
118 char target_addr[MAX_TARGET_ADDR];
119
120 /* Initiator/Target port binds */
121 char initiator_name[MAX_INITIATOR_NAME];
122 struct spdk_scsi_port *initiator_port;
123 char target_short_name[MAX_TARGET_NAME];
124 struct spdk_scsi_port *target_port;
125 struct spdk_iscsi_tgt_node *target;
126 struct spdk_scsi_dev *dev;
127
128 /* for fast access */
129 int header_digest;
130 int data_digest;
131 int full_feature;
132
133 struct iscsi_param *params;
134 bool sess_param_state_negotiated[MAX_SESSION_PARAMS];
135 bool conn_param_state_negotiated[MAX_CONNECTION_PARAMS];
136 struct iscsi_chap_auth auth;
137 int authenticated;
138 int req_auth;
139 int req_mutual;
140 uint32_t pending_task_cnt;
141 uint32_t data_out_cnt;
142 uint32_t data_in_cnt;
143 bool pending_activate_event;
144
145 int timeout;
146 uint64_t nopininterval;
147 bool nop_outstanding;
148
149 /*
150 * This is the maximum data segment length that iscsi target can send
151 * to the initiator on this connection. Not to be confused with the
152 * maximum data segment length that initiators can send to iscsi target, which
153 * is statically defined as SPDK_ISCSI_MAX_RECV_DATA_SEGMENT_LENGTH.
154 */
155 int MaxRecvDataSegmentLength;
156
157 uint32_t StatSN;
158 uint32_t exp_statsn;
159 uint32_t ttt; /* target transfer tag */
160 char *partial_text_parameter;
161
162 STAILQ_ENTRY(spdk_iscsi_conn) link;
163 struct spdk_poller *flush_poller;
164 bool is_stopped; /* Set true when connection is stopped for migration */
165 TAILQ_HEAD(queued_r2t_tasks, spdk_iscsi_task) queued_r2t_tasks;
166 TAILQ_HEAD(active_r2t_tasks, spdk_iscsi_task) active_r2t_tasks;
167 TAILQ_HEAD(queued_datain_tasks, spdk_iscsi_task) queued_datain_tasks;
168
169 struct spdk_scsi_desc *open_lun_descs[SPDK_SCSI_DEV_MAX_LUN];
170 };
171
172 extern struct spdk_iscsi_conn *g_conns_array;
173
174 int spdk_initialize_iscsi_conns(void);
175 void spdk_shutdown_iscsi_conns(void);
176
177 int spdk_iscsi_conn_construct(struct spdk_iscsi_portal *portal, struct spdk_sock *sock);
178 void spdk_iscsi_conn_destruct(struct spdk_iscsi_conn *conn);
179 void spdk_iscsi_conn_handle_nop(struct spdk_iscsi_conn *conn);
180 void spdk_iscsi_conn_migration(struct spdk_iscsi_conn *conn);
181 void spdk_iscsi_conn_logout(struct spdk_iscsi_conn *conn);
182 int spdk_iscsi_drop_conns(struct spdk_iscsi_conn *conn,
183 const char *conn_match, int drop_all);
184 void spdk_iscsi_conn_set_min_per_core(int count);
185 int spdk_iscsi_conn_get_min_per_core(void);
186
187 int spdk_iscsi_conn_read_data(struct spdk_iscsi_conn *conn, int len,
188 void *buf);
189 void spdk_iscsi_conn_write_pdu(struct spdk_iscsi_conn *conn, struct spdk_iscsi_pdu *pdu);
190
191 void spdk_iscsi_conn_free_pdu(struct spdk_iscsi_conn *conn, struct spdk_iscsi_pdu *pdu);
192
193 #endif /* SPDK_ISCSI_CONN_H */