hc
2024-05-10 9999e48639b3cecb08ffb37358bcba3b48161b29
kernel/drivers/target/iscsi/iscsi_target_util.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*******************************************************************************
23 * This file contains the iSCSI Target specific utility functions.
34 *
....@@ -5,15 +6,6 @@
56 *
67 * Author: Nicholas A. Bellinger <nab@linux-iscsi.org>
78 *
8
- * This program is free software; you can redistribute it and/or modify
9
- * it under the terms of the GNU General Public License as published by
10
- * the Free Software Foundation; either version 2 of the License, or
11
- * (at your option) any later version.
12
- *
13
- * This program is distributed in the hope that it will be useful,
14
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
- * GNU General Public License for more details.
179 ******************************************************************************/
1810
1911 #include <linux/list.h>
....@@ -56,9 +48,6 @@
5648 extern struct list_head g_tiqn_list;
5749 extern spinlock_t tiqn_lock;
5850
59
-/*
60
- * Called with cmd->r2t_lock held.
61
- */
6251 int iscsit_add_r2t_to_list(
6352 struct iscsi_cmd *cmd,
6453 u32 offset,
....@@ -67,6 +56,10 @@
6756 u32 r2t_sn)
6857 {
6958 struct iscsi_r2t *r2t;
59
+
60
+ lockdep_assert_held(&cmd->r2t_lock);
61
+
62
+ WARN_ON_ONCE((s32)xfer_len < 0);
7063
7164 r2t = kmem_cache_zalloc(lio_r2t_cache, GFP_ATOMIC);
7265 if (!r2t) {
....@@ -128,11 +121,10 @@
128121 return NULL;
129122 }
130123
131
-/*
132
- * Called with cmd->r2t_lock held.
133
- */
134124 void iscsit_free_r2t(struct iscsi_r2t *r2t, struct iscsi_cmd *cmd)
135125 {
126
+ lockdep_assert_held(&cmd->r2t_lock);
127
+
136128 list_del(&r2t->r2t_list);
137129 kmem_cache_free(lio_r2t_cache, r2t);
138130 }
....@@ -150,24 +142,26 @@
150142 static int iscsit_wait_for_tag(struct se_session *se_sess, int state, int *cpup)
151143 {
152144 int tag = -1;
153
- DEFINE_WAIT(wait);
145
+ DEFINE_SBQ_WAIT(wait);
154146 struct sbq_wait_state *ws;
147
+ struct sbitmap_queue *sbq;
155148
156149 if (state == TASK_RUNNING)
157150 return tag;
158151
159
- ws = &se_sess->sess_tag_pool.ws[0];
152
+ sbq = &se_sess->sess_tag_pool;
153
+ ws = &sbq->ws[0];
160154 for (;;) {
161
- prepare_to_wait_exclusive(&ws->wait, &wait, state);
155
+ sbitmap_prepare_to_wait(sbq, ws, &wait, state);
162156 if (signal_pending_state(state, current))
163157 break;
164
- tag = sbitmap_queue_get(&se_sess->sess_tag_pool, cpup);
158
+ tag = sbitmap_queue_get(sbq, cpup);
165159 if (tag >= 0)
166160 break;
167161 schedule();
168162 }
169163
170
- finish_wait(&ws->wait, &wait);
164
+ sbitmap_finish_wait(sbq, ws, &wait);
171165 return tag;
172166 }
173167
....@@ -735,6 +729,7 @@
735729 kfree(cmd->pdu_list);
736730 kfree(cmd->seq_list);
737731 kfree(cmd->tmr_req);
732
+ kfree(cmd->overflow_buf);
738733 kfree(cmd->iov_data);
739734 kfree(cmd->text_in_ptr);
740735
....@@ -760,14 +755,16 @@
760755 iscsit_remove_cmd_from_response_queue(cmd, conn);
761756 }
762757
763
- if (conn && conn->conn_transport->iscsit_release_cmd)
764
- conn->conn_transport->iscsit_release_cmd(conn, cmd);
758
+ if (conn && conn->conn_transport->iscsit_unmap_cmd)
759
+ conn->conn_transport->iscsit_unmap_cmd(conn, cmd);
765760 }
766761
767762 void iscsit_free_cmd(struct iscsi_cmd *cmd, bool shutdown)
768763 {
769764 struct se_cmd *se_cmd = cmd->se_cmd.se_tfo ? &cmd->se_cmd : NULL;
770765 int rc;
766
+
767
+ WARN_ON(!list_empty(&cmd->i_conn_node));
771768
772769 __iscsit_free_cmd(cmd, shutdown);
773770 if (se_cmd) {
....@@ -915,6 +912,7 @@
915912 void iscsit_handle_nopin_response_timeout(struct timer_list *t)
916913 {
917914 struct iscsi_conn *conn = from_timer(conn, t, nopin_response_timer);
915
+ struct iscsi_session *sess = conn->sess;
918916
919917 iscsit_inc_conn_usage_count(conn);
920918
....@@ -925,28 +923,14 @@
925923 return;
926924 }
927925
928
- pr_debug("Did not receive response to NOPIN on CID: %hu on"
929
- " SID: %u, failing connection.\n", conn->cid,
930
- conn->sess->sid);
926
+ pr_err("Did not receive response to NOPIN on CID: %hu, failing"
927
+ " connection for I_T Nexus %s,i,0x%6phN,%s,t,0x%02x\n",
928
+ conn->cid, sess->sess_ops->InitiatorName, sess->isid,
929
+ sess->tpg->tpg_tiqn->tiqn, (u32)sess->tpg->tpgt);
931930 conn->nopin_response_timer_flags &= ~ISCSI_TF_RUNNING;
932931 spin_unlock_bh(&conn->nopin_timer_lock);
933932
934
- {
935
- struct iscsi_portal_group *tpg = conn->sess->tpg;
936
- struct iscsi_tiqn *tiqn = tpg->tpg_tiqn;
937
-
938
- if (tiqn) {
939
- spin_lock_bh(&tiqn->sess_err_stats.lock);
940
- strcpy(tiqn->sess_err_stats.last_sess_fail_rem_name,
941
- conn->sess->sess_ops->InitiatorName);
942
- tiqn->sess_err_stats.last_sess_failure_type =
943
- ISCSI_SESS_ERR_CXN_TIMEOUT;
944
- tiqn->sess_err_stats.cxn_timeout_errors++;
945
- atomic_long_inc(&conn->sess->conn_timeout_errors);
946
- spin_unlock_bh(&tiqn->sess_err_stats.lock);
947
- }
948
- }
949
-
933
+ iscsit_fill_cxn_timeout_err_stats(sess);
950934 iscsit_cause_connection_reinstatement(conn, 0);
951935 iscsit_dec_conn_usage_count(conn);
952936 }
....@@ -967,9 +951,6 @@
967951 spin_unlock_bh(&conn->nopin_timer_lock);
968952 }
969953
970
-/*
971
- * Called with conn->nopin_timer_lock held.
972
- */
973954 void iscsit_start_nopin_response_timer(struct iscsi_conn *conn)
974955 {
975956 struct iscsi_session *sess = conn->sess;
....@@ -1027,13 +1008,13 @@
10271008 iscsit_dec_conn_usage_count(conn);
10281009 }
10291010
1030
-/*
1031
- * Called with conn->nopin_timer_lock held.
1032
- */
10331011 void __iscsit_start_nopin_timer(struct iscsi_conn *conn)
10341012 {
10351013 struct iscsi_session *sess = conn->sess;
10361014 struct iscsi_node_attrib *na = iscsit_tpg_get_node_attrib(sess);
1015
+
1016
+ lockdep_assert_held(&conn->nopin_timer_lock);
1017
+
10371018 /*
10381019 * NOPIN timeout is disabled.
10391020 */
....@@ -1247,19 +1228,20 @@
12471228 iscsi_dump_sess_ops(sess->sess_ops);
12481229 }
12491230
1250
-static int iscsit_do_rx_data(
1231
+int rx_data(
12511232 struct iscsi_conn *conn,
1252
- struct iscsi_data_count *count)
1233
+ struct kvec *iov,
1234
+ int iov_count,
1235
+ int data)
12531236 {
1254
- int data = count->data_length, rx_loop = 0, total_rx = 0;
1237
+ int rx_loop = 0, total_rx = 0;
12551238 struct msghdr msg;
12561239
12571240 if (!conn || !conn->sock || !conn->conn_ops)
12581241 return -1;
12591242
12601243 memset(&msg, 0, sizeof(struct msghdr));
1261
- iov_iter_kvec(&msg.msg_iter, READ | ITER_KVEC,
1262
- count->iov, count->iov_count, data);
1244
+ iov_iter_kvec(&msg.msg_iter, READ, iov, iov_count, data);
12631245
12641246 while (msg_data_left(&msg)) {
12651247 rx_loop = sock_recvmsg(conn->sock, &msg, MSG_WAITALL);
....@@ -1274,26 +1256,6 @@
12741256 }
12751257
12761258 return total_rx;
1277
-}
1278
-
1279
-int rx_data(
1280
- struct iscsi_conn *conn,
1281
- struct kvec *iov,
1282
- int iov_count,
1283
- int data)
1284
-{
1285
- struct iscsi_data_count c;
1286
-
1287
- if (!conn || !conn->sock || !conn->conn_ops)
1288
- return -1;
1289
-
1290
- memset(&c, 0, sizeof(struct iscsi_data_count));
1291
- c.iov = iov;
1292
- c.iov_count = iov_count;
1293
- c.data_length = data;
1294
- c.type = ISCSI_RX_DATA;
1295
-
1296
- return iscsit_do_rx_data(conn, &c);
12971259 }
12981260
12991261 int tx_data(
....@@ -1315,8 +1277,7 @@
13151277
13161278 memset(&msg, 0, sizeof(struct msghdr));
13171279
1318
- iov_iter_kvec(&msg.msg_iter, WRITE | ITER_KVEC,
1319
- iov, iov_count, data);
1280
+ iov_iter_kvec(&msg.msg_iter, WRITE, iov, iov_count, data);
13201281
13211282 while (msg_data_left(&msg)) {
13221283 int tx_loop = sock_sendmsg(conn->sock, &msg);
....@@ -1405,3 +1366,22 @@
14051366
14061367 return tpg->tpg_tiqn;
14071368 }
1369
+
1370
+void iscsit_fill_cxn_timeout_err_stats(struct iscsi_session *sess)
1371
+{
1372
+ struct iscsi_portal_group *tpg = sess->tpg;
1373
+ struct iscsi_tiqn *tiqn = tpg->tpg_tiqn;
1374
+
1375
+ if (!tiqn)
1376
+ return;
1377
+
1378
+ spin_lock_bh(&tiqn->sess_err_stats.lock);
1379
+ strlcpy(tiqn->sess_err_stats.last_sess_fail_rem_name,
1380
+ sess->sess_ops->InitiatorName,
1381
+ sizeof(tiqn->sess_err_stats.last_sess_fail_rem_name));
1382
+ tiqn->sess_err_stats.last_sess_failure_type =
1383
+ ISCSI_SESS_ERR_CXN_TIMEOUT;
1384
+ tiqn->sess_err_stats.cxn_timeout_errors++;
1385
+ atomic_long_inc(&sess->conn_timeout_errors);
1386
+ spin_unlock_bh(&tiqn->sess_err_stats.lock);
1387
+}