aboutsummaryrefslogtreecommitdiffstats
path: root/meta-networking/recipes-extended/iscsitarget/files/fix-errors-observed-with-linux-3.19-and-greater.patch
blob: 1e6a1d6d3f6c5aeddcc769f5b885b0ea2bd9a762 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
Description: Fix source to compile on 3.19 kernels
Author: Stefan Bader <stefan.bader@canonical.com>
Forward: no

Fixes below inconsistent crash when trying to login to iSCSI target
server, observed with linux kernel v4.1.

-- snip --
CPU: 1 PID: 29883 Comm: istd1 Tainted: G           O    4.1.35-rt40-yocto-standard #1
Hardware name: To be filled by O.E.M. To be filled by O.E.M./Larne CRB, BIOS 4.6.5.4 09/18/2014
task: ffff88020f1f30c0 ti: ffff8800d7f3c000 task.ti: ffff8800d7f3c000
RIP: 0010:[<ffffffff8140d1ae>]  [<ffffffff8140d1ae>] copy_to_iter+0x3e/0x280
RSP: 0018:ffff8800d7f3f728  EFLAGS: 00010246
RAX: 00000000d7f3f928 RBX: 0000000000000030 RCX: 0000000000000030
RDX: ffff8800d7f3f900 RSI: 0000000000000030 RDI: ffff8800d1501e82
RBP: ffff8800d7f3f768 R08: 00000000c127d467 R09: 0000000000000000
R10: ffff88020f29e118 R11: 0000000000000004 R12: ffff8800d7f3f900
R13: 0000000000000030 R14: 0000000000000001 R15: 0000000000000246
FS:  00007f86f9c4c700(0000) GS:ffff88021ec80000(0000) knlGS:00000000f7733700
CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 000000000000024e CR3: 00000000d38b0000 CR4: 00000000000406e0
Stack:
ffff880214f14ec0 ffff8800d1501e82 ffff8800d7f3f748 0000000000000030
ffff88020f122500 0000000000000030 0000000000000000 0000000000000030
ffff8800d7f3f7c8 ffffffff81806981 ffff8800d7f3f798 ffffffff8105d72a
Call Trace:
[<ffffffff81806981>] skb_copy_datagram_iter+0x71/0x2b0
[<ffffffff8105d72a>] ? __local_bh_enable_ip+0x4a/0xb0
[<ffffffff8186c9c0>] tcp_recvmsg+0x5e0/0xbb0
[<ffffffff81898ded>] inet_recvmsg+0x8d/0xb0
[<ffffffff817f49f3>] sock_recvmsg+0x13/0x20
[<ffffffffa01655c3>] do_recv+0xe3/0x1f0 [iscsi_trgt]
[<ffffffff81153097>] ? __mod_zone_page_state+0x77/0xb0
[<ffffffff81417613>] ? __this_cpu_preempt_check+0x13/0x20
[<ffffffff81153097>] ? __mod_zone_page_state+0x77/0xb0
[<ffffffff8140fed5>] ? find_next_bit+0x15/0x30
[<ffffffff813fa8e0>] ? cpumask_next_and+0x30/0x50
[<ffffffff8113f785>] ? __alloc_pages_nodemask+0x165/0x980
[<ffffffff8107e370>] ? preempt_count_add+0xd0/0xf0
[<ffffffff8195da8b>] ? _raw_spin_lock+0x1b/0x60
[<ffffffff8109cfa8>] ? cpuacct_charge+0x58/0x70
[<ffffffff81089039>] ? update_curr+0xb9/0x190
[<ffffffff81417613>] ? __this_cpu_preempt_check+0x13/0x20
[<ffffffff8112b43f>] ? __perf_event_task_sched_in+0x4f/0x90
[<ffffffff8195dbbd>] ? _raw_spin_unlock_irq+0x1d/0x40
[<ffffffff8107e223>] ? finish_task_switch+0x63/0xe0
[<ffffffff81959e3b>] ? __schedule+0x38b/0x980
[<ffffffff8107e370>] ? preempt_count_add+0xd0/0xf0
[<ffffffffa0165c65>] istd+0x4d5/0x1390 [iscsi_trgt]
[<ffffffff81959e3b>] ? __schedule+0x38b/0x980
[<ffffffffa0165790>] ? nthread_wakeup+0x40/0x40 [iscsi_trgt]
[<ffffffffa0165790>] ? nthread_wakeup+0x40/0x40 [iscsi_trgt]
[<ffffffff8107748b>] kthread+0xbb/0xe0
[<ffffffff81950000>] ? wireless_dev_seq_show+0x100/0x180
[<ffffffff810773d0>] ? kthread_worker_fn+0x170/0x170
[<ffffffff8195e7a2>] ret_from_fork+0x42/0x70
[<ffffffff810773d0>] ? kthread_worker_fn+0x170/0x170
Code: 5a 10 48 89 7d c8 48 39 f3 48 0f 47 de 48 85 db 0f 84 6f 01 00 00 8b 02 49 89
d4 4c 8b 72 08 4c 8b 7a 18 a8 04 0f 85 a2 00 00 00 <4d> 8b 6f 08 4d 29 f5 49 39 dd 4c 0f 47 eb a8 02 0f 85 5c 01 00 
RSP <ffff8800d7f3f728>
CR2: 000000000000024e
------------[ cut here ]------------
-- snip --

The original patch is at
http://launchpadlibrarian.net/218100509/iscsitarget_1.4.20.3+svn499-0ubuntu2_1.4.20.3+svn499-0ubuntu2.1.diff.gz,
those changes were taken using #ifs, inorder to allow compilation of 
iscsitarget package with linux kernels < 3.19.

Upstream-Status: Submitted [http://launchpadlibrarian.net/218100509/iscsitarget_1.4.20.3+svn499-0ubuntu2_1.4.20.3+svn499-0ubuntu2.1.diff.gz]

Signed-off-by: Jagadeesh Krishnanjanappa <jkrishnanjanappa@mvista.com>

diff -Naurp iscsitarget-1.4.20.3+svn502_org/kernel/conn.c iscsitarget-1.4.20.3+svn502/kernel/conn.c
--- iscsitarget-1.4.20.3+svn502_org/kernel/conn.c	2017-01-18 22:27:02.713167436 -0800
+++ iscsitarget-1.4.20.3+svn502/kernel/conn.c	2017-01-18 23:13:11.909214379 -0800
@@ -129,7 +129,11 @@ static void iet_socket_bind(struct iscsi
 
 	dprintk(D_GENERIC, "%llu\n", (unsigned long long) session->sid);
 
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0)
+	conn->sock = SOCKET_I(file_inode(conn->file));
+#else
 	conn->sock = SOCKET_I(conn->file->f_dentry->d_inode);
+#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0) */
 	conn->sock->sk->sk_user_data = conn;
 
 	write_lock_bh(&conn->sock->sk->sk_callback_lock);
diff -Naurp iscsitarget-1.4.20.3+svn502_org/kernel/file-io.c iscsitarget-1.4.20.3+svn502/kernel/file-io.c
--- iscsitarget-1.4.20.3+svn502_org/kernel/file-io.c	2014-05-06 13:59:55.000000000 -0700
+++ iscsitarget-1.4.20.3+svn502/kernel/file-io.c	2017-01-18 23:54:38.505717079 -0800
@@ -69,7 +69,11 @@ static int fileio_make_request(struct ie
 static int fileio_sync(struct iet_volume *lu, struct tio *tio)
 {
 	struct fileio_data *p = lu->private;
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0)
+	struct inode *inode = file_inode(p->filp);
+#else
 	struct inode *inode = p->filp->f_dentry->d_inode;
+#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0) */
 	struct address_space *mapping = inode->i_mapping;
 	loff_t ppos, count;
 	int res;
@@ -213,7 +217,11 @@ static int fileio_attach(struct iet_volu
 		eprintk("%d\n", err);
 		goto out;
 	}
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0)
+	inode = file_inode(p->filp);
+#else
 	inode = p->filp->f_dentry->d_inode;
+#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0) */
 
 	if (S_ISREG(inode->i_mode))
 		;
diff -Naurp iscsitarget-1.4.20.3+svn502_org/kernel/iscsi.c iscsitarget-1.4.20.3+svn502/kernel/iscsi.c
--- iscsitarget-1.4.20.3+svn502_org/kernel/iscsi.c	2014-05-06 13:59:55.000000000 -0700
+++ iscsitarget-1.4.20.3+svn502/kernel/iscsi.c	2017-01-18 23:37:36.462970326 -0800
@@ -489,8 +489,12 @@ static void cmnd_skip_pdu(struct iscsi_c
 	}
 	conn->read_iov[i].iov_base = addr;
 	conn->read_iov[i].iov_len = size;
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0)
+	iov_iter_init(&conn->read_msg.msg_iter, READ, conn->read_iov, ++i, conn->read_size);
+#else
 	conn->read_msg.msg_iov = conn->read_iov;
 	conn->read_msg.msg_iovlen = ++i;
+#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0) */
 }
 
 static void iscsi_cmnd_reject(struct iscsi_cmnd *req, int reason)
@@ -718,7 +722,9 @@ static int cmnd_recv_pdu(struct iscsi_co
 	idx = offset >> PAGE_CACHE_SHIFT;
 	offset &= ~PAGE_CACHE_MASK;
 
+#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 19, 0)
 	conn->read_msg.msg_iov = conn->read_iov;
+#endif	/* LINUX_VERSION_CODE < KERNEL_VERSION(3, 19, 0) */
 	conn->read_size = size = (size + 3) & -4;
 	conn->read_overflow = 0;
 
@@ -730,16 +736,25 @@ static int cmnd_recv_pdu(struct iscsi_co
 		conn->read_iov[i].iov_base =  addr + offset;
 		if (offset + size <= PAGE_CACHE_SIZE) {
 			conn->read_iov[i].iov_len = size;
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0)
+			iov_iter_init(&conn->read_msg.msg_iter, READ, conn->read_iov, ++i, conn->read_size);
+#else
 			conn->read_msg.msg_iovlen = ++i;
+#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0) */
 			break;
 		}
 		conn->read_iov[i].iov_len = PAGE_CACHE_SIZE - offset;
 		size -= conn->read_iov[i].iov_len;
 		offset = 0;
 		if (++i >= ISCSI_CONN_IOV_MAX) {
+#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 19, 0)
 			conn->read_msg.msg_iovlen = i;
+#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(3, 19, 0) */
 			conn->read_overflow = size;
 			conn->read_size -= size;
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0)
+			iov_iter_init(&conn->read_msg.msg_iter, READ, conn->read_iov, i, conn->read_size);
+#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0) */
 			break;
 		}
 
@@ -918,7 +933,9 @@ static int nop_out_start(struct iscsi_co
 
 	if ((size = cmnd->pdu.datasize)) {
 		size = (size + 3) & -4;
+#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 19, 0)
 		conn->read_msg.msg_iov = conn->read_iov;
+#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(3, 19, 0) */
 		if (cmnd->pdu.bhs.itt != cpu_to_be32(ISCSI_RESERVED_TAG)) {
 			struct tio *tio;
 			int pg_cnt = get_pgcnt(size);
@@ -946,7 +963,11 @@ static int nop_out_start(struct iscsi_co
 		}
 		assert(!size);
 		conn->read_overflow = size;
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0)
+		iov_iter_init(&conn->read_msg.msg_iter, READ, conn->read_iov, i, conn->read_size);
+#else
 		conn->read_msg.msg_iovlen = i;
+#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0) */
 	}
 
 out:
@@ -986,7 +1007,11 @@ static void scsi_cmnd_start(struct iscsi
 		set_cmnd_lunit(req);
 
 	switch (req_hdr->scb[0]) {
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0)
+	case SERVICE_ACTION_IN_16:
+#else
 	case SERVICE_ACTION_IN:
+#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0) */
 		if ((req_hdr->scb[1] & 0x1f) != 0x10)
 			goto error;
 	case INQUIRY:
diff -Naurp iscsitarget-1.4.20.3+svn502_org/kernel/nthread.c iscsitarget-1.4.20.3+svn502/kernel/nthread.c
--- iscsitarget-1.4.20.3+svn502_org/kernel/nthread.c	2014-05-06 13:59:55.000000000 -0700
+++ iscsitarget-1.4.20.3+svn502/kernel/nthread.c	2017-01-18 23:45:03.291033881 -0800
@@ -42,9 +42,14 @@ static inline void iscsi_conn_init_read(
 	len = (len + 3) & -4; // XXX ???
 	conn->read_iov[0].iov_base = data;
 	conn->read_iov[0].iov_len = len;
+#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 19, 0)
 	conn->read_msg.msg_iov = conn->read_iov;
 	conn->read_msg.msg_iovlen = 1;
+#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(3, 19, 0) */
 	conn->read_size = (len + 3) & -4;
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0)
+	iov_iter_init(&conn->read_msg.msg_iter, READ, conn->read_iov, 1, conn->read_size);
+#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0) */
 }
 
 static void iscsi_conn_read_ahs(struct iscsi_conn *conn, struct iscsi_cmnd *cmnd)
@@ -83,14 +88,31 @@ static int is_data_available(struct iscs
 
 static void forward_iov(struct msghdr *msg, int len)
 {
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0)
+	struct iovec *iov;
+
+	while (msg->msg_iter.iov->iov_len <= len) {
+		len -= msg->msg_iter.iov->iov_len;
+		msg->msg_iter.iov++;
+		msg->msg_iter.nr_segs--;
+	}
+#else
 	while (msg->msg_iov->iov_len <= len) {
 		len -= msg->msg_iov->iov_len;
 		msg->msg_iov++;
 		msg->msg_iovlen--;
 	}
+#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0) */
 
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0)
+	/* XXX: discards const ... */
+	iov = msg->msg_iter.iov;
+	iov->iov_base = (char *) msg->msg_iter.iov->iov_base + len;
+	iov->iov_len -= len;
+#else
 	msg->msg_iov->iov_base = (char *) msg->msg_iov->iov_base + len;
 	msg->msg_iov->iov_len -= len;
+#endif	/* LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0) */
 }
 
 static int do_recv(struct iscsi_conn *conn, int state)
@@ -98,6 +120,9 @@ static int do_recv(struct iscsi_conn *co
 	mm_segment_t oldfs;
 	struct msghdr msg;
 	struct iovec iov[ISCSI_CONN_IOV_MAX];
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0)
+	size_t iovlen = ISCSI_CONN_IOV_MAX;
+#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0) */
 	int i, len, res;
 
 	if (!test_bit(CONN_ACTIVE, &conn->state)) {
@@ -110,12 +135,23 @@ static int do_recv(struct iscsi_conn *co
 		goto out;
 	}
 
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0)
+	if (conn->read_msg.msg_iter.nr_segs < iovlen)
+		iovlen = conn->read_msg.msg_iter.nr_segs;
+
+	for (i = 0, len = 0; i < iovlen; i++) {
+		iov[i] = conn->read_msg.msg_iter.iov[i];
+		len += iov[i].iov_len;
+	}
+	iov_iter_init(&msg.msg_iter, READ, iov, iovlen, len);
+#else
 	msg.msg_iov = iov;
 	msg.msg_iovlen = min_t(size_t, conn->read_msg.msg_iovlen, ISCSI_CONN_IOV_MAX);
 	for (i = 0, len = 0; i < msg.msg_iovlen; i++) {
 		iov[i] = conn->read_msg.msg_iov[i];
 		len += iov[i].iov_len;
 	}
+#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0) */
 
 	oldfs = get_fs();
 	set_fs(get_ds());
diff -Naurp iscsitarget-1.4.20.3+svn502_org/kernel/target_disk.c iscsitarget-1.4.20.3+svn502/kernel/target_disk.c
--- iscsitarget-1.4.20.3+svn502_org/kernel/target_disk.c	2014-05-06 13:59:55.000000000 -0700
+++ iscsitarget-1.4.20.3+svn502/kernel/target_disk.c	2017-01-18 23:45:51.451010417 -0800
@@ -606,7 +606,11 @@ static int disk_execute_cmnd(struct iscs
 	case REQUEST_SENSE:
 		send_data_rsp(cmnd, build_request_sense_response);
 		break;
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0)
+	case SERVICE_ACTION_IN_16:
+#else
 	case SERVICE_ACTION_IN:
+#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0) */
 		send_data_rsp(cmnd, build_service_action_in_response);
 		break;
 	case READ_6:
diff -Naurp iscsitarget-1.4.20.3+svn502_org/kernel/volume.c iscsitarget-1.4.20.3+svn502/kernel/volume.c
--- iscsitarget-1.4.20.3+svn502_org/kernel/volume.c	2014-05-06 13:59:55.000000000 -0700
+++ iscsitarget-1.4.20.3+svn502/kernel/volume.c	2017-01-18 23:47:07.957561600 -0800
@@ -398,7 +398,11 @@ int is_volume_reserved(struct iet_volume
 		case READ_CAPACITY:
 			/* allowed commands when reserved */
 			break;
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0)
+		case SERVICE_ACTION_IN_16:
+#else
 		case SERVICE_ACTION_IN:
+#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0) */
 			if ((scb[1] & 0x1F) == 0x10)
 				break;
 			/* fall through */
@@ -465,7 +469,11 @@ int is_volume_reserved(struct iet_volume
 		if (excl_access_ro && !registered)
 			err = -EBUSY;
 		break;
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0)
+	case SERVICE_ACTION_IN_16:
+#else
 	case SERVICE_ACTION_IN:
+#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0) */
 		if ((scb[1] & 0x1F) == 0x10)
 			break;
 		/* fall through */