1
diff --git a/iscsi_tcp.c b/iscsi_tcp.c
2
index 2a401b9..197d314 100644
7
#include "scsi_transport_iscsi.h"
9
+#include "open_iscsi_compat.h"
10
#include "iscsi_tcp.h"
12
MODULE_AUTHOR("Mike Christie <michaelc@cs.wisc.edu>, "
13
diff --git a/libiscsi.c b/libiscsi.c
14
index 59e3a5f..b79453a 100644
17
@@ -518,7 +518,7 @@ static void iscsi_free_task(struct iscsi_task *task)
18
if (conn->login_task == task)
21
- kfifo_in(&session->cmdpool.queue, (void*)&task, sizeof(void*));
22
+ __kfifo_put(session->cmdpool.queue, (void*)&task, sizeof(void*));
26
@@ -738,7 +738,7 @@ __iscsi_conn_send_pdu(struct iscsi_conn *conn, struct iscsi_hdr *hdr,
27
BUG_ON(conn->c_stage == ISCSI_CONN_INITIAL_STAGE);
28
BUG_ON(conn->c_stage == ISCSI_CONN_STOPPED);
30
- if (!kfifo_out(&session->cmdpool.queue,
31
+ if (!__kfifo_get(session->cmdpool.queue,
32
(void*)&task, sizeof(void*)))
35
@@ -1568,7 +1568,7 @@ static inline struct iscsi_task *iscsi_alloc_task(struct iscsi_conn *conn,
37
struct iscsi_task *task;
39
- if (!kfifo_out(&conn->session->cmdpool.queue,
40
+ if (!__kfifo_get(conn->session->cmdpool.queue,
41
(void *) &task, sizeof(void *)))
44
@@ -1738,21 +1738,9 @@ fault:
46
EXPORT_SYMBOL_GPL(iscsi_queuecommand);
48
-int iscsi_change_queue_depth(struct scsi_device *sdev, int depth, int reason)
49
+int iscsi_change_queue_depth(struct scsi_device *sdev, int depth)
52
- case SCSI_QDEPTH_DEFAULT:
53
- scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), depth);
55
- case SCSI_QDEPTH_QFULL:
56
- scsi_track_queue_full(sdev, depth);
58
- case SCSI_QDEPTH_RAMP_UP:
59
- scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), depth);
64
+ scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), depth);
65
return sdev->queue_depth;
67
EXPORT_SYMBOL_GPL(iscsi_change_queue_depth);
68
@@ -2524,7 +2512,12 @@ iscsi_pool_init(struct iscsi_pool *q, int max, void ***items, int item_size)
72
- kfifo_init(&q->queue, (void*)q->pool, max * sizeof(void*));
73
+ q->queue = kfifo_init((void*)q->pool, max * sizeof(void*),
75
+ if (IS_ERR(q->queue)) {
80
for (i = 0; i < max; i++) {
81
q->pool[i] = kzalloc(item_size, GFP_KERNEL);
82
@@ -2532,7 +2525,7 @@ iscsi_pool_init(struct iscsi_pool *q, int max, void ***items, int item_size)
86
- kfifo_in(&q->queue, (void*)&q->pool[i], sizeof(void*));
87
+ __kfifo_put(q->queue, (void*)&q->pool[i], sizeof(void*));
91
@@ -2555,6 +2548,7 @@ void iscsi_pool_free(struct iscsi_pool *q)
92
for (i = 0; i < q->max; i++)
97
EXPORT_SYMBOL_GPL(iscsi_pool_free);
99
@@ -2882,7 +2876,7 @@ iscsi_conn_setup(struct iscsi_cls_session *cls_session, int dd_size,
101
/* allocate login_task used for the login/text sequences */
102
spin_lock_bh(&session->lock);
103
- if (!kfifo_out(&session->cmdpool.queue,
104
+ if (!__kfifo_get(session->cmdpool.queue,
105
(void*)&conn->login_task,
107
spin_unlock_bh(&session->lock);
108
@@ -2902,7 +2896,7 @@ iscsi_conn_setup(struct iscsi_cls_session *cls_session, int dd_size,
111
login_task_data_alloc_fail:
112
- kfifo_in(&session->cmdpool.queue, (void*)&conn->login_task,
113
+ __kfifo_put(session->cmdpool.queue, (void*)&conn->login_task,
115
login_task_alloc_fail:
116
iscsi_destroy_conn(cls_conn);
117
@@ -2965,7 +2959,7 @@ void iscsi_conn_teardown(struct iscsi_cls_conn *cls_conn)
118
free_pages((unsigned long) conn->data,
119
get_order(ISCSI_DEF_MAX_RECV_SEG_LEN));
120
kfree(conn->persistent_address);
121
- kfifo_in(&session->cmdpool.queue, (void*)&conn->login_task,
122
+ __kfifo_put(session->cmdpool.queue, (void*)&conn->login_task,
124
if (session->leadconn == conn)
125
session->leadconn = NULL;
126
diff --git a/libiscsi.h b/libiscsi.h
127
index 0563539..4be9333 100644
130
@@ -231,7 +231,7 @@ struct iscsi_conn {
134
- struct kfifo queue; /* FIFO Queue */
135
+ struct kfifo *queue; /* FIFO Queue */
136
void **pool; /* Pool of elements */
137
int max; /* Max number of elements */
139
@@ -334,8 +334,7 @@ struct iscsi_host {
143
-extern int iscsi_change_queue_depth(struct scsi_device *sdev, int depth,
145
+extern int iscsi_change_queue_depth(struct scsi_device *sdev, int depth);
146
extern int iscsi_eh_abort(struct scsi_cmnd *sc);
147
extern int iscsi_eh_recover_target(struct scsi_cmnd *sc);
148
extern int iscsi_eh_session_reset(struct scsi_cmnd *sc);
149
diff --git a/libiscsi_tcp.c b/libiscsi_tcp.c
150
index 1122de4..c3ff728 100644
153
@@ -446,15 +446,15 @@ void iscsi_tcp_cleanup_task(struct iscsi_task *task)
156
/* flush task's r2t queues */
157
- while (kfifo_out(&tcp_task->r2tqueue, (void*)&r2t, sizeof(void*))) {
158
- kfifo_in(&tcp_task->r2tpool.queue, (void*)&r2t,
159
+ while (__kfifo_get(tcp_task->r2tqueue, (void*)&r2t, sizeof(void*))) {
160
+ __kfifo_put(tcp_task->r2tpool.queue, (void*)&r2t,
162
ISCSI_DBG_TCP(task->conn, "pending r2t dropped\n");
167
- kfifo_in(&tcp_task->r2tpool.queue, (void*)&r2t,
168
+ __kfifo_put(tcp_task->r2tpool.queue, (void*)&r2t,
170
tcp_task->r2t = NULL;
172
@@ -542,7 +542,7 @@ static int iscsi_tcp_r2t_rsp(struct iscsi_conn *conn, struct iscsi_task *task)
176
- rc = kfifo_out(&tcp_task->r2tpool.queue, (void*)&r2t, sizeof(void*));
177
+ rc = __kfifo_get(tcp_task->r2tpool.queue, (void*)&r2t, sizeof(void*));
179
iscsi_conn_printk(KERN_ERR, conn, "Could not allocate R2T. "
180
"Target has sent more R2Ts than it "
181
@@ -555,7 +555,7 @@ static int iscsi_tcp_r2t_rsp(struct iscsi_conn *conn, struct iscsi_task *task)
182
if (r2t->data_length == 0) {
183
iscsi_conn_printk(KERN_ERR, conn,
184
"invalid R2T with zero data len\n");
185
- kfifo_in(&tcp_task->r2tpool.queue, (void*)&r2t,
186
+ __kfifo_put(tcp_task->r2tpool.queue, (void*)&r2t,
188
return ISCSI_ERR_DATALEN;
190
@@ -571,7 +571,7 @@ static int iscsi_tcp_r2t_rsp(struct iscsi_conn *conn, struct iscsi_task *task)
191
"invalid R2T with data len %u at offset %u "
192
"and total length %d\n", r2t->data_length,
193
r2t->data_offset, scsi_out(task->sc)->length);
194
- kfifo_in(&tcp_task->r2tpool.queue, (void*)&r2t,
195
+ __kfifo_put(tcp_task->r2tpool.queue, (void*)&r2t,
197
return ISCSI_ERR_DATALEN;
199
@@ -581,7 +581,7 @@ static int iscsi_tcp_r2t_rsp(struct iscsi_conn *conn, struct iscsi_task *task)
202
tcp_task->exp_datasn = r2tsn + 1;
203
- kfifo_in(&tcp_task->r2tqueue, (void*)&r2t, sizeof(void*));
204
+ __kfifo_put(tcp_task->r2tqueue, (void*)&r2t, sizeof(void*));
205
conn->r2t_pdus_cnt++;
207
iscsi_requeue_task(task);
208
@@ -952,7 +952,7 @@ int iscsi_tcp_task_init(struct iscsi_task *task)
209
return conn->session->tt->init_pdu(task, 0, task->data_count);
212
- BUG_ON(kfifo_len(&tcp_task->r2tqueue));
213
+ BUG_ON(__kfifo_len(tcp_task->r2tqueue));
214
tcp_task->exp_datasn = 0;
216
/* Prepare PDU, optionally w/ immediate data */
217
@@ -983,7 +983,7 @@ static struct iscsi_r2t_info *iscsi_tcp_get_curr_r2t(struct iscsi_task *task)
218
if (r2t->data_length <= r2t->sent) {
219
ISCSI_DBG_TCP(task->conn,
220
" done with r2t %p\n", r2t);
221
- kfifo_in(&tcp_task->r2tpool.queue,
222
+ __kfifo_put(tcp_task->r2tpool.queue,
223
(void *)&tcp_task->r2t,
225
tcp_task->r2t = r2t = NULL;
226
@@ -991,12 +991,9 @@ static struct iscsi_r2t_info *iscsi_tcp_get_curr_r2t(struct iscsi_task *task)
230
- if (kfifo_out(&tcp_task->r2tqueue,
231
- (void *)&tcp_task->r2t, sizeof(void *)) !=
235
- r2t = tcp_task->r2t;
236
+ __kfifo_get(tcp_task->r2tqueue,
237
+ (void *)&tcp_task->r2t, sizeof(void *));
238
+ r2t = tcp_task->r2t;
240
spin_unlock_bh(&session->lock);
242
@@ -1131,8 +1128,9 @@ int iscsi_tcp_r2tpool_alloc(struct iscsi_session *session)
246
- if (kfifo_alloc(&tcp_task->r2tqueue,
247
- session->max_r2t * 4 * sizeof(void*), GFP_KERNEL)) {
248
+ tcp_task->r2tqueue = kfifo_alloc(
249
+ session->max_r2t * 4 * sizeof(void*), GFP_KERNEL, NULL);
250
+ if (tcp_task->r2tqueue == ERR_PTR(-ENOMEM)) {
251
iscsi_pool_free(&tcp_task->r2tpool);
254
@@ -1145,7 +1143,7 @@ r2t_alloc_fail:
255
struct iscsi_task *task = session->cmds[i];
256
struct iscsi_tcp_task *tcp_task = task->dd_data;
258
- kfifo_free(&tcp_task->r2tqueue);
259
+ kfifo_free(tcp_task->r2tqueue);
260
iscsi_pool_free(&tcp_task->r2tpool);
263
@@ -1160,7 +1158,7 @@ void iscsi_tcp_r2tpool_free(struct iscsi_session *session)
264
struct iscsi_task *task = session->cmds[i];
265
struct iscsi_tcp_task *tcp_task = task->dd_data;
267
- kfifo_free(&tcp_task->r2tqueue);
268
+ kfifo_free(tcp_task->r2tqueue);
269
iscsi_pool_free(&tcp_task->r2tpool);
272
diff --git a/libiscsi_tcp.h b/libiscsi_tcp.h
273
index c020eee..3bacef5 100644
276
@@ -80,7 +80,7 @@ struct iscsi_tcp_task {
278
struct iscsi_r2t_info *r2t; /* in progress solict R2T */
279
struct iscsi_pool r2tpool;
280
- struct kfifo r2tqueue;
281
+ struct kfifo *r2tqueue;
285
diff --git a/open_iscsi_compat.h b/open_iscsi_compat.h
287
index 0000000..50ab84d
289
+++ b/open_iscsi_compat.h
291
+#include <linux/version.h>
292
+#include <linux/kernel.h>
293
+#include <scsi/scsi.h>
294
+#include <scsi/scsi_cmnd.h>
296
+#ifndef OPEN_ISCSI_COMPAT
297
+#define OPEN_ISCSI_COMPAT
299
+#ifndef SCAN_WILD_CARD
300
+#define SCAN_WILD_CARD ~0
304
+#define NIPQUAD_FMT "%u.%u.%u.%u"
308
+#define NIP6_FMT "%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x"
311
+#ifndef DEFINE_MUTEX
313
+/* mutex changes from 2.6.16-rc1 and up */
314
+#define DEFINE_MUTEX DECLARE_MUTEX
315
+#define mutex_lock down
316
+#define mutex_unlock up
317
+#define mutex semaphore
318
+#define mutex_init init_MUTEX
321
+#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,12)
323
+void int_to_scsilun(unsigned int lun, struct scsi_lun *scsilun)
327
+ memset(scsilun->scsi_lun, 0, sizeof(scsilun->scsi_lun));
329
+ for (i = 0; i < sizeof(lun); i += 2) {
330
+ scsilun->scsi_lun[i] = (lun >> 8) & 0xFF;
331
+ scsilun->scsi_lun[i+1] = lun & 0xFF;
336
+#define __nlmsg_put(skb, daemon_pid, seq, type, len, flags) \
337
+ __nlmsg_put(skb, daemon_pid, 0, 0, len)
341
+#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,13)
343
+#define gfp_t unsigned
345
+void *kzalloc(size_t size, gfp_t flags)
347
+ void *ret = kmalloc(size, flags);
349
+ memset(ret, 0, size);
354
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
356
+#include "linux/crypto.h"
358
+#define CRYPTO_ALG_ASYNC 0x00000080
361
+ struct crypto_tfm *tfm;
365
+static inline int crypto_hash_init(struct hash_desc *desc)
367
+ crypto_digest_init(desc->tfm);
371
+static inline int crypto_hash_digest(struct hash_desc *desc,
372
+ struct scatterlist *sg,
373
+ unsigned int nbytes, u8 *out)
375
+ crypto_digest_digest(desc->tfm, sg, 1, out);
379
+static inline int crypto_hash_update(struct hash_desc *desc,
380
+ struct scatterlist *sg,
381
+ unsigned int nbytes)
383
+ crypto_digest_update(desc->tfm, sg, 1);
387
+static inline int crypto_hash_final(struct hash_desc *desc, u8 *out)
389
+ crypto_digest_final(desc->tfm, out);
393
+static inline struct crypto_tfm *crypto_alloc_hash(const char *alg_name,
394
+ u32 type, u32 mask)
396
+ struct crypto_tfm *ret = crypto_alloc_tfm(alg_name ,type);
397
+ return ret ? ret : ERR_PTR(-ENOMEM);
400
+static inline void crypto_free_hash(struct crypto_tfm *tfm)
402
+ crypto_free_tfm(tfm);
405
+int kernel_getsockname(struct socket *sock, struct sockaddr *addr,
408
+ return sock->ops->getname(sock, addr, addrlen, 0);
411
+int kernel_getpeername(struct socket *sock, struct sockaddr *addr,
414
+ return sock->ops->getname(sock, addr, addrlen, 1);
419
+#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,20)
421
+static inline int is_power_of_2(unsigned long n)
423
+ return (n != 0 && ((n & (n - 1)) == 0));
427
+#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,21)
429
+static inline struct nlmsghdr *nlmsg_hdr(const struct sk_buff *skb)
431
+ return (struct nlmsghdr *)skb->data;
436
+#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,22)
438
+static inline void *shost_priv(struct Scsi_Host *shost)
440
+ return (void *)shost->hostdata;
444
+ * Note: We do not support bidi for the compat modules if the kernel
445
+ * does not have support.
447
+#define scsi_sg_count(cmd) ((cmd)->use_sg)
448
+#define scsi_sglist(cmd) ((struct scatterlist *)(cmd)->request_buffer)
449
+#define scsi_bufflen(cmd) ((cmd)->request_bufflen)
451
+static inline void scsi_set_resid(struct scsi_cmnd *cmd, int resid)
453
+ cmd->resid = resid;
456
+static inline int scsi_get_resid(struct scsi_cmnd *cmd)
463
+#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,23)
465
+static inline unsigned long rounddown_pow_of_two(unsigned long n)
467
+ return 1UL << (fls_long(n) - 1);
471
+static inline struct scatterlist *sg_next(struct scatterlist *sg)
480
+#define for_each_sg(sglist, sg, nr, __i) \
481
+ for (__i = 0, sg = (sglist); __i < (nr); __i++, sg = sg_next(sg))
483
+#define sg_page(_sg) _sg->page
485
+static inline void sg_set_page(struct scatterlist *sg, struct page *page,
486
+ unsigned int len, unsigned int offset)
489
+ sg->offset = offset;
493
+static inline void sg_init_table(struct scatterlist *sgl, unsigned int nents)
495
+ memset(sgl, 0, sizeof(*sgl) * nents);
499
+#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,24)
501
+static inline int scsi_bidi_cmnd(struct scsi_cmnd *cmd)
506
+#define netlink_kernel_release(_nls) \
507
+ sock_release(_nls->sk_socket)
513
+#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,13)
515
+#define netlink_kernel_create(net, uint, groups, input, cb_mutex, mod) \
516
+ netlink_kernel_create(uint, input)
518
+#elif LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,21)
520
+#define netlink_kernel_create(net, uint, groups, input, cb_mutex, mod) \
521
+ netlink_kernel_create(uint, groups, input, mod)
523
+#elif LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,22)
525
+#define netlink_kernel_create(net, uint, groups, input, cb_mutex, mod) \
526
+ netlink_kernel_create(uint, groups, input, cb_mutex, mod)
528
+#elif LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,23)
530
+#define netlink_kernel_create(net, uint, groups, input, cb_mutex, mod) \
531
+ netlink_kernel_create(uint, groups, input, cb_mutex, mod)
535
+#ifndef DID_TRANSPORT_DISRUPTED
536
+#define DID_TRANSPORT_DISRUPTED DID_BUS_BUSY
539
+#ifndef DID_TRANSPORT_FAILFAST
540
+#define DID_TRANSPORT_FAILFAST DID_NO_CONNECT
543
+#ifndef SCSI_MLQUEUE_TARGET_BUSY
544
+#define SCSI_MLQUEUE_TARGET_BUSY SCSI_MLQUEUE_HOST_BUSY
547
+#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,27)
549
+#define BLK_EH_NOT_HANDLED EH_NOT_HANDLED
550
+#define BLK_EH_RESET_TIMER EH_RESET_TIMER
552
+#define blk_eh_timer_return scsi_eh_timer_return
557
+#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,34)
559
+static inline wait_queue_head_t *sk_sleep(struct sock *sk)
561
+ return sk->sk_sleep;