diff --git a/iscsi_tcp.c b/iscsi_tcp.c index 2a401b9..197d314 100644 --- a/iscsi_tcp.c +++ b/iscsi_tcp.c @@ -43,6 +43,7 @@ #include #include "scsi_transport_iscsi.h" +#include "open_iscsi_compat.h" #include "iscsi_tcp.h" MODULE_AUTHOR("Mike Christie , " diff --git a/libiscsi.c b/libiscsi.c index 59e3a5f..d0e41d9 100644 --- a/libiscsi.c +++ b/libiscsi.c @@ -39,6 +39,8 @@ #include "scsi_transport_iscsi.h" #include "libiscsi.h" +#include "open_iscsi_compat.h" + static int iscsi_dbg_lib_conn; module_param_named(debug_libiscsi_conn, iscsi_dbg_lib_conn, int, S_IRUGO | S_IWUSR); @@ -518,7 +520,7 @@ static void iscsi_free_task(struct iscsi_task *task) if (conn->login_task == task) return; - kfifo_in(&session->cmdpool.queue, (void*)&task, sizeof(void*)); + __kfifo_put(session->cmdpool.queue, (void*)&task, sizeof(void*)); if (sc) { task->sc = NULL; @@ -738,7 +740,7 @@ __iscsi_conn_send_pdu(struct iscsi_conn *conn, struct iscsi_hdr *hdr, BUG_ON(conn->c_stage == ISCSI_CONN_INITIAL_STAGE); BUG_ON(conn->c_stage == ISCSI_CONN_STOPPED); - if (!kfifo_out(&session->cmdpool.queue, + if (!__kfifo_get(session->cmdpool.queue, (void*)&task, sizeof(void*))) return NULL; } @@ -1568,7 +1570,7 @@ static inline struct iscsi_task *iscsi_alloc_task(struct iscsi_conn *conn, { struct iscsi_task *task; - if (!kfifo_out(&conn->session->cmdpool.queue, + if (!__kfifo_get(conn->session->cmdpool.queue, (void *) &task, sizeof(void *))) return NULL; @@ -1738,21 +1740,9 @@ fault: } EXPORT_SYMBOL_GPL(iscsi_queuecommand); -int iscsi_change_queue_depth(struct scsi_device *sdev, int depth, int reason) +int iscsi_change_queue_depth(struct scsi_device *sdev, int depth) { - switch (reason) { - case SCSI_QDEPTH_DEFAULT: - scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), depth); - break; - case SCSI_QDEPTH_QFULL: - scsi_track_queue_full(sdev, depth); - break; - case SCSI_QDEPTH_RAMP_UP: - scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), depth); - break; - default: - return -EOPNOTSUPP; - } + scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), depth); return sdev->queue_depth; } EXPORT_SYMBOL_GPL(iscsi_change_queue_depth); @@ -2524,7 +2514,12 @@ iscsi_pool_init(struct iscsi_pool *q, int max, void ***items, int item_size) if (q->pool == NULL) return -ENOMEM; - kfifo_init(&q->queue, (void*)q->pool, max * sizeof(void*)); + q->queue = kfifo_init((void*)q->pool, max * sizeof(void*), + GFP_KERNEL, NULL); + if (IS_ERR(q->queue)) { + q->queue = NULL; + goto enomem; + } for (i = 0; i < max; i++) { q->pool[i] = kzalloc(item_size, GFP_KERNEL); @@ -2532,7 +2527,7 @@ iscsi_pool_init(struct iscsi_pool *q, int max, void ***items, int item_size) q->max = i; goto enomem; } - kfifo_in(&q->queue, (void*)&q->pool[i], sizeof(void*)); + __kfifo_put(q->queue, (void*)&q->pool[i], sizeof(void*)); } if (items) { @@ -2555,6 +2550,7 @@ void iscsi_pool_free(struct iscsi_pool *q) for (i = 0; i < q->max; i++) kfree(q->pool[i]); kfree(q->pool); + kfree(q->queue); } EXPORT_SYMBOL_GPL(iscsi_pool_free); @@ -2882,7 +2878,7 @@ iscsi_conn_setup(struct iscsi_cls_session *cls_session, int dd_size, /* allocate login_task used for the login/text sequences */ spin_lock_bh(&session->lock); - if (!kfifo_out(&session->cmdpool.queue, + if (!__kfifo_get(session->cmdpool.queue, (void*)&conn->login_task, sizeof(void*))) { spin_unlock_bh(&session->lock); @@ -2902,7 +2898,7 @@ iscsi_conn_setup(struct iscsi_cls_session *cls_session, int dd_size, return cls_conn; login_task_data_alloc_fail: - kfifo_in(&session->cmdpool.queue, (void*)&conn->login_task, + __kfifo_put(session->cmdpool.queue, (void*)&conn->login_task, sizeof(void*)); login_task_alloc_fail: iscsi_destroy_conn(cls_conn); @@ -2965,7 +2961,7 @@ void iscsi_conn_teardown(struct iscsi_cls_conn *cls_conn) free_pages((unsigned long) conn->data, get_order(ISCSI_DEF_MAX_RECV_SEG_LEN)); kfree(conn->persistent_address); - kfifo_in(&session->cmdpool.queue, (void*)&conn->login_task, + __kfifo_put(session->cmdpool.queue, (void*)&conn->login_task, sizeof(void*)); if (session->leadconn == conn) session->leadconn = NULL; diff --git a/libiscsi.h b/libiscsi.h index 0563539..4be9333 100644 --- a/libiscsi.h +++ b/libiscsi.h @@ -231,7 +231,7 @@ struct iscsi_conn { }; struct iscsi_pool { - struct kfifo queue; /* FIFO Queue */ + struct kfifo *queue; /* FIFO Queue */ void **pool; /* Pool of elements */ int max; /* Max number of elements */ }; @@ -334,8 +334,7 @@ struct iscsi_host { /* * scsi host template */ -extern int iscsi_change_queue_depth(struct scsi_device *sdev, int depth, - int reason); +extern int iscsi_change_queue_depth(struct scsi_device *sdev, int depth); extern int iscsi_eh_abort(struct scsi_cmnd *sc); extern int iscsi_eh_recover_target(struct scsi_cmnd *sc); extern int iscsi_eh_session_reset(struct scsi_cmnd *sc); diff --git a/libiscsi_tcp.c b/libiscsi_tcp.c index 1122de4..c3ff728 100644 --- a/libiscsi_tcp.c +++ b/libiscsi_tcp.c @@ -446,15 +446,15 @@ void iscsi_tcp_cleanup_task(struct iscsi_task *task) return; /* flush task's r2t queues */ - while (kfifo_out(&tcp_task->r2tqueue, (void*)&r2t, sizeof(void*))) { - kfifo_in(&tcp_task->r2tpool.queue, (void*)&r2t, + while (__kfifo_get(tcp_task->r2tqueue, (void*)&r2t, sizeof(void*))) { + __kfifo_put(tcp_task->r2tpool.queue, (void*)&r2t, sizeof(void*)); ISCSI_DBG_TCP(task->conn, "pending r2t dropped\n"); } r2t = tcp_task->r2t; if (r2t != NULL) { - kfifo_in(&tcp_task->r2tpool.queue, (void*)&r2t, + __kfifo_put(tcp_task->r2tpool.queue, (void*)&r2t, sizeof(void*)); tcp_task->r2t = NULL; } @@ -542,7 +542,7 @@ static int iscsi_tcp_r2t_rsp(struct iscsi_conn *conn, struct iscsi_task *task) return 0; } - rc = kfifo_out(&tcp_task->r2tpool.queue, (void*)&r2t, sizeof(void*)); + rc = __kfifo_get(tcp_task->r2tpool.queue, (void*)&r2t, sizeof(void*)); if (!rc) { iscsi_conn_printk(KERN_ERR, conn, "Could not allocate R2T. " "Target has sent more R2Ts than it " @@ -555,7 +555,7 @@ static int iscsi_tcp_r2t_rsp(struct iscsi_conn *conn, struct iscsi_task *task) if (r2t->data_length == 0) { iscsi_conn_printk(KERN_ERR, conn, "invalid R2T with zero data len\n"); - kfifo_in(&tcp_task->r2tpool.queue, (void*)&r2t, + __kfifo_put(tcp_task->r2tpool.queue, (void*)&r2t, sizeof(void*)); return ISCSI_ERR_DATALEN; } @@ -571,7 +571,7 @@ static int iscsi_tcp_r2t_rsp(struct iscsi_conn *conn, struct iscsi_task *task) "invalid R2T with data len %u at offset %u " "and total length %d\n", r2t->data_length, r2t->data_offset, scsi_out(task->sc)->length); - kfifo_in(&tcp_task->r2tpool.queue, (void*)&r2t, + __kfifo_put(tcp_task->r2tpool.queue, (void*)&r2t, sizeof(void*)); return ISCSI_ERR_DATALEN; } @@ -581,7 +581,7 @@ static int iscsi_tcp_r2t_rsp(struct iscsi_conn *conn, struct iscsi_task *task) r2t->sent = 0; tcp_task->exp_datasn = r2tsn + 1; - kfifo_in(&tcp_task->r2tqueue, (void*)&r2t, sizeof(void*)); + __kfifo_put(tcp_task->r2tqueue, (void*)&r2t, sizeof(void*)); conn->r2t_pdus_cnt++; iscsi_requeue_task(task); @@ -952,7 +952,7 @@ int iscsi_tcp_task_init(struct iscsi_task *task) return conn->session->tt->init_pdu(task, 0, task->data_count); } - BUG_ON(kfifo_len(&tcp_task->r2tqueue)); + BUG_ON(__kfifo_len(tcp_task->r2tqueue)); tcp_task->exp_datasn = 0; /* Prepare PDU, optionally w/ immediate data */ @@ -983,7 +983,7 @@ static struct iscsi_r2t_info *iscsi_tcp_get_curr_r2t(struct iscsi_task *task) if (r2t->data_length <= r2t->sent) { ISCSI_DBG_TCP(task->conn, " done with r2t %p\n", r2t); - kfifo_in(&tcp_task->r2tpool.queue, + __kfifo_put(tcp_task->r2tpool.queue, (void *)&tcp_task->r2t, sizeof(void *)); tcp_task->r2t = r2t = NULL; @@ -991,12 +991,9 @@ static struct iscsi_r2t_info *iscsi_tcp_get_curr_r2t(struct iscsi_task *task) } if (r2t == NULL) { - if (kfifo_out(&tcp_task->r2tqueue, - (void *)&tcp_task->r2t, sizeof(void *)) != - sizeof(void *)) - r2t = NULL; - else - r2t = tcp_task->r2t; + __kfifo_get(tcp_task->r2tqueue, + (void *)&tcp_task->r2t, sizeof(void *)); + r2t = tcp_task->r2t; } spin_unlock_bh(&session->lock); } @@ -1131,8 +1128,9 @@ int iscsi_tcp_r2tpool_alloc(struct iscsi_session *session) } /* R2T xmit queue */ - if (kfifo_alloc(&tcp_task->r2tqueue, - session->max_r2t * 4 * sizeof(void*), GFP_KERNEL)) { + tcp_task->r2tqueue = kfifo_alloc( + session->max_r2t * 4 * sizeof(void*), GFP_KERNEL, NULL); + if (tcp_task->r2tqueue == ERR_PTR(-ENOMEM)) { iscsi_pool_free(&tcp_task->r2tpool); goto r2t_alloc_fail; } @@ -1145,7 +1143,7 @@ r2t_alloc_fail: struct iscsi_task *task = session->cmds[i]; struct iscsi_tcp_task *tcp_task = task->dd_data; - kfifo_free(&tcp_task->r2tqueue); + kfifo_free(tcp_task->r2tqueue); iscsi_pool_free(&tcp_task->r2tpool); } return -ENOMEM; @@ -1160,7 +1158,7 @@ void iscsi_tcp_r2tpool_free(struct iscsi_session *session) struct iscsi_task *task = session->cmds[i]; struct iscsi_tcp_task *tcp_task = task->dd_data; - kfifo_free(&tcp_task->r2tqueue); + kfifo_free(tcp_task->r2tqueue); iscsi_pool_free(&tcp_task->r2tpool); } } diff --git a/libiscsi_tcp.h b/libiscsi_tcp.h index c020eee..3bacef5 100644 --- a/libiscsi_tcp.h +++ b/libiscsi_tcp.h @@ -80,7 +80,7 @@ struct iscsi_tcp_task { int data_offset; struct iscsi_r2t_info *r2t; /* in progress solict R2T */ struct iscsi_pool r2tpool; - struct kfifo r2tqueue; + struct kfifo *r2tqueue; void *dd_data; }; diff --git a/open_iscsi_compat.h b/open_iscsi_compat.h new file mode 100644 index 0000000..50ab84d --- /dev/null +++ b/open_iscsi_compat.h @@ -0,0 +1,276 @@ +#include +#include +#include +#include + +#ifndef OPEN_ISCSI_COMPAT +#define OPEN_ISCSI_COMPAT + +#ifndef SCAN_WILD_CARD +#define SCAN_WILD_CARD ~0 +#endif + +#ifndef NIPQUAD_FMT +#define NIPQUAD_FMT "%u.%u.%u.%u" +#endif + +#ifndef NIP6_FMT +#define NIP6_FMT "%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x" +#endif + +#ifndef DEFINE_MUTEX + +/* mutex changes from 2.6.16-rc1 and up */ +#define DEFINE_MUTEX DECLARE_MUTEX +#define mutex_lock down +#define mutex_unlock up +#define mutex semaphore +#define mutex_init init_MUTEX +#endif + +#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,12) + +void int_to_scsilun(unsigned int lun, struct scsi_lun *scsilun) +{ + int i; + + memset(scsilun->scsi_lun, 0, sizeof(scsilun->scsi_lun)); + + for (i = 0; i < sizeof(lun); i += 2) { + scsilun->scsi_lun[i] = (lun >> 8) & 0xFF; + scsilun->scsi_lun[i+1] = lun & 0xFF; + lun = lun >> 16; + } +} + +#define __nlmsg_put(skb, daemon_pid, seq, type, len, flags) \ + __nlmsg_put(skb, daemon_pid, 0, 0, len) + +#endif + +#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,13) + +#define gfp_t unsigned + +void *kzalloc(size_t size, gfp_t flags) +{ + void *ret = kmalloc(size, flags); + if (ret) + memset(ret, 0, size); +} + +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19) + +#include "linux/crypto.h" + +#define CRYPTO_ALG_ASYNC 0x00000080 +struct hash_desc +{ + struct crypto_tfm *tfm; + u32 flags; +}; + +static inline int crypto_hash_init(struct hash_desc *desc) +{ + crypto_digest_init(desc->tfm); + return 0; +} + +static inline int crypto_hash_digest(struct hash_desc *desc, + struct scatterlist *sg, + unsigned int nbytes, u8 *out) +{ + crypto_digest_digest(desc->tfm, sg, 1, out); + return nbytes; +} + +static inline int crypto_hash_update(struct hash_desc *desc, + struct scatterlist *sg, + unsigned int nbytes) +{ + crypto_digest_update(desc->tfm, sg, 1); + return nbytes; +} + +static inline int crypto_hash_final(struct hash_desc *desc, u8 *out) +{ + crypto_digest_final(desc->tfm, out); + return 0; +} + +static inline struct crypto_tfm *crypto_alloc_hash(const char *alg_name, + u32 type, u32 mask) +{ + struct crypto_tfm *ret = crypto_alloc_tfm(alg_name ,type); + return ret ? ret : ERR_PTR(-ENOMEM); +} + +static inline void crypto_free_hash(struct crypto_tfm *tfm) +{ + crypto_free_tfm(tfm); +} + +int kernel_getsockname(struct socket *sock, struct sockaddr *addr, + int *addrlen) +{ + return sock->ops->getname(sock, addr, addrlen, 0); +} + +int kernel_getpeername(struct socket *sock, struct sockaddr *addr, + int *addrlen) +{ + return sock->ops->getname(sock, addr, addrlen, 1); +} + +#endif + +#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,20) + +static inline int is_power_of_2(unsigned long n) +{ + return (n != 0 && ((n & (n - 1)) == 0)); +} +#endif + +#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,21) + +static inline struct nlmsghdr *nlmsg_hdr(const struct sk_buff *skb) +{ + return (struct nlmsghdr *)skb->data; +} + +#endif + +#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,22) + +static inline void *shost_priv(struct Scsi_Host *shost) +{ + return (void *)shost->hostdata; +} + +/* + * Note: We do not support bidi for the compat modules if the kernel + * does not have support. + */ +#define scsi_sg_count(cmd) ((cmd)->use_sg) +#define scsi_sglist(cmd) ((struct scatterlist *)(cmd)->request_buffer) +#define scsi_bufflen(cmd) ((cmd)->request_bufflen) + +static inline void scsi_set_resid(struct scsi_cmnd *cmd, int resid) +{ + cmd->resid = resid; +} + +static inline int scsi_get_resid(struct scsi_cmnd *cmd) +{ + return cmd->resid; +} + +#endif + +#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,23) + +static inline unsigned long rounddown_pow_of_two(unsigned long n) +{ + return 1UL << (fls_long(n) - 1); +} + + +static inline struct scatterlist *sg_next(struct scatterlist *sg) +{ + if (!sg) { + BUG(); + return NULL; + } + return sg + 1; +} + +#define for_each_sg(sglist, sg, nr, __i) \ + for (__i = 0, sg = (sglist); __i < (nr); __i++, sg = sg_next(sg)) + +#define sg_page(_sg) _sg->page + +static inline void sg_set_page(struct scatterlist *sg, struct page *page, + unsigned int len, unsigned int offset) +{ + sg->page = page; + sg->offset = offset; + sg->length = len; +} + +static inline void sg_init_table(struct scatterlist *sgl, unsigned int nents) +{ + memset(sgl, 0, sizeof(*sgl) * nents); +} +#endif + +#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,24) + +static inline int scsi_bidi_cmnd(struct scsi_cmnd *cmd) +{ + return 0; +} + +#define netlink_kernel_release(_nls) \ + sock_release(_nls->sk_socket) + + +#endif + + +#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,13) + +#define netlink_kernel_create(net, uint, groups, input, cb_mutex, mod) \ + netlink_kernel_create(uint, input) + +#elif LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,21) + +#define netlink_kernel_create(net, uint, groups, input, cb_mutex, mod) \ + netlink_kernel_create(uint, groups, input, mod) + +#elif LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,22) + +#define netlink_kernel_create(net, uint, groups, input, cb_mutex, mod) \ + netlink_kernel_create(uint, groups, input, cb_mutex, mod) + +#elif LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,23) + +#define netlink_kernel_create(net, uint, groups, input, cb_mutex, mod) \ + netlink_kernel_create(uint, groups, input, cb_mutex, mod) + +#endif + +#ifndef DID_TRANSPORT_DISRUPTED +#define DID_TRANSPORT_DISRUPTED DID_BUS_BUSY +#endif + +#ifndef DID_TRANSPORT_FAILFAST +#define DID_TRANSPORT_FAILFAST DID_NO_CONNECT +#endif + +#ifndef SCSI_MLQUEUE_TARGET_BUSY +#define SCSI_MLQUEUE_TARGET_BUSY SCSI_MLQUEUE_HOST_BUSY +#endif + +#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,27) + +#define BLK_EH_NOT_HANDLED EH_NOT_HANDLED +#define BLK_EH_RESET_TIMER EH_RESET_TIMER + +#define blk_eh_timer_return scsi_eh_timer_return + +#endif + + +#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,34) + +static inline wait_queue_head_t *sk_sleep(struct sock *sk) +{ + return sk->sk_sleep; +} + +#endif + +#endif diff --git a/scsi_transport_iscsi.c b/scsi_transport_iscsi.c index fed8c9e..3b28918 100644 --- a/scsi_transport_iscsi.c +++ b/scsi_transport_iscsi.c @@ -31,6 +31,8 @@ #include "scsi_transport_iscsi.h" #include "iscsi_if.h" +#include "open_iscsi_compat.h" + #define ISCSI_SESSION_ATTRS 22 #define ISCSI_CONN_ATTRS 13 #define ISCSI_HOST_ATTRS 4 -- 1.6.6.1