aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/scsi/libiscsi.c
diff options
context:
space:
mode:
authorStefani Seibold <stefani@seibold.net>2009-12-21 17:37:26 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2009-12-22 17:17:55 -0500
commit45465487897a1c6d508b14b904dc5777f7ec7e04 (patch)
tree935c8dae68dc793ff2f795d57cf027531475cd53 /drivers/scsi/libiscsi.c
parent2ec91eec47f713e3d158ba5b28a24a85a2cf3650 (diff)
kfifo: move struct kfifo in place
This is a new generic kernel FIFO implementation. The current kernel fifo API is not very widely used, because it has to many constrains. Only 17 files in the current 2.6.31-rc5 used it. FIFO's are like list's a very basic thing and a kfifo API which handles the most use case would save a lot of development time and memory resources. I think this are the reasons why kfifo is not in use: - The API is to simple, important functions are missing - A fifo can be only allocated dynamically - There is a requirement of a spinlock whether you need it or not - There is no support for data records inside a fifo So I decided to extend the kfifo in a more generic way without blowing up the API to much. The new API has the following benefits: - Generic usage: For kernel internal use and/or device driver. - Provide an API for the most use case. - Slim API: The whole API provides 25 functions. - Linux style habit. - DECLARE_KFIFO, DEFINE_KFIFO and INIT_KFIFO Macros - Direct copy_to_user from the fifo and copy_from_user into the fifo. - The kfifo itself is an in place member of the using data structure, this save an indirection access and does not waste the kernel allocator. - Lockless access: if only one reader and one writer is active on the fifo, which is the common use case, no additional locking is necessary. - Remove spinlock - give the user the freedom of choice what kind of locking to use if one is required. - Ability to handle records. Three type of records are supported: - Variable length records between 0-255 bytes, with a record size field of 1 bytes. - Variable length records between 0-65535 bytes, with a record size field of 2 bytes. - Fixed size records, which no record size field. - Preserve memory resource. - Performance! - Easy to use! This patch: Since most users want to have the kfifo as part of another object, reorganize the code to allow including struct kfifo in another data structure. This requires changing the kfifo_alloc and kfifo_init prototypes so that we pass an existing kfifo pointer into them. This patch changes the implementation and all existing users. [akpm@linux-foundation.org: fix warning] Signed-off-by: Stefani Seibold <stefani@seibold.net> Acked-by: Greg Kroah-Hartman <gregkh@suse.de> Acked-by: Mauro Carvalho Chehab <mchehab@redhat.com> Acked-by: Andi Kleen <ak@linux.intel.com> Acked-by: Arnd Bergmann <arnd@arndb.de> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/scsi/libiscsi.c')
-rw-r--r--drivers/scsi/libiscsi.c22
1 files changed, 8 insertions, 14 deletions
diff --git a/drivers/scsi/libiscsi.c b/drivers/scsi/libiscsi.c
index b7689f3d05f..cf0aa7e90be 100644
--- a/drivers/scsi/libiscsi.c
+++ b/drivers/scsi/libiscsi.c
@@ -517,7 +517,7 @@ static void iscsi_free_task(struct iscsi_task *task)
517 if (conn->login_task == task) 517 if (conn->login_task == task)
518 return; 518 return;
519 519
520 __kfifo_put(session->cmdpool.queue, (void*)&task, sizeof(void*)); 520 __kfifo_put(&session->cmdpool.queue, (void*)&task, sizeof(void*));
521 521
522 if (sc) { 522 if (sc) {
523 task->sc = NULL; 523 task->sc = NULL;
@@ -737,7 +737,7 @@ __iscsi_conn_send_pdu(struct iscsi_conn *conn, struct iscsi_hdr *hdr,
737 BUG_ON(conn->c_stage == ISCSI_CONN_INITIAL_STAGE); 737 BUG_ON(conn->c_stage == ISCSI_CONN_INITIAL_STAGE);
738 BUG_ON(conn->c_stage == ISCSI_CONN_STOPPED); 738 BUG_ON(conn->c_stage == ISCSI_CONN_STOPPED);
739 739
740 if (!__kfifo_get(session->cmdpool.queue, 740 if (!__kfifo_get(&session->cmdpool.queue,
741 (void*)&task, sizeof(void*))) 741 (void*)&task, sizeof(void*)))
742 return NULL; 742 return NULL;
743 } 743 }
@@ -1567,7 +1567,7 @@ static inline struct iscsi_task *iscsi_alloc_task(struct iscsi_conn *conn,
1567{ 1567{
1568 struct iscsi_task *task; 1568 struct iscsi_task *task;
1569 1569
1570 if (!__kfifo_get(conn->session->cmdpool.queue, 1570 if (!__kfifo_get(&conn->session->cmdpool.queue,
1571 (void *) &task, sizeof(void *))) 1571 (void *) &task, sizeof(void *)))
1572 return NULL; 1572 return NULL;
1573 1573
@@ -2461,12 +2461,7 @@ iscsi_pool_init(struct iscsi_pool *q, int max, void ***items, int item_size)
2461 if (q->pool == NULL) 2461 if (q->pool == NULL)
2462 return -ENOMEM; 2462 return -ENOMEM;
2463 2463
2464 q->queue = kfifo_init((void*)q->pool, max * sizeof(void*), 2464 kfifo_init(&q->queue, (void*)q->pool, max * sizeof(void*), NULL);
2465 GFP_KERNEL, NULL);
2466 if (IS_ERR(q->queue)) {
2467 q->queue = NULL;
2468 goto enomem;
2469 }
2470 2465
2471 for (i = 0; i < max; i++) { 2466 for (i = 0; i < max; i++) {
2472 q->pool[i] = kzalloc(item_size, GFP_KERNEL); 2467 q->pool[i] = kzalloc(item_size, GFP_KERNEL);
@@ -2474,7 +2469,7 @@ iscsi_pool_init(struct iscsi_pool *q, int max, void ***items, int item_size)
2474 q->max = i; 2469 q->max = i;
2475 goto enomem; 2470 goto enomem;
2476 } 2471 }
2477 __kfifo_put(q->queue, (void*)&q->pool[i], sizeof(void*)); 2472 __kfifo_put(&q->queue, (void*)&q->pool[i], sizeof(void*));
2478 } 2473 }
2479 2474
2480 if (items) { 2475 if (items) {
@@ -2497,7 +2492,6 @@ void iscsi_pool_free(struct iscsi_pool *q)
2497 for (i = 0; i < q->max; i++) 2492 for (i = 0; i < q->max; i++)
2498 kfree(q->pool[i]); 2493 kfree(q->pool[i]);
2499 kfree(q->pool); 2494 kfree(q->pool);
2500 kfree(q->queue);
2501} 2495}
2502EXPORT_SYMBOL_GPL(iscsi_pool_free); 2496EXPORT_SYMBOL_GPL(iscsi_pool_free);
2503 2497
@@ -2825,7 +2819,7 @@ iscsi_conn_setup(struct iscsi_cls_session *cls_session, int dd_size,
2825 2819
2826 /* allocate login_task used for the login/text sequences */ 2820 /* allocate login_task used for the login/text sequences */
2827 spin_lock_bh(&session->lock); 2821 spin_lock_bh(&session->lock);
2828 if (!__kfifo_get(session->cmdpool.queue, 2822 if (!__kfifo_get(&session->cmdpool.queue,
2829 (void*)&conn->login_task, 2823 (void*)&conn->login_task,
2830 sizeof(void*))) { 2824 sizeof(void*))) {
2831 spin_unlock_bh(&session->lock); 2825 spin_unlock_bh(&session->lock);
@@ -2845,7 +2839,7 @@ iscsi_conn_setup(struct iscsi_cls_session *cls_session, int dd_size,
2845 return cls_conn; 2839 return cls_conn;
2846 2840
2847login_task_data_alloc_fail: 2841login_task_data_alloc_fail:
2848 __kfifo_put(session->cmdpool.queue, (void*)&conn->login_task, 2842 __kfifo_put(&session->cmdpool.queue, (void*)&conn->login_task,
2849 sizeof(void*)); 2843 sizeof(void*));
2850login_task_alloc_fail: 2844login_task_alloc_fail:
2851 iscsi_destroy_conn(cls_conn); 2845 iscsi_destroy_conn(cls_conn);
@@ -2908,7 +2902,7 @@ void iscsi_conn_teardown(struct iscsi_cls_conn *cls_conn)
2908 free_pages((unsigned long) conn->data, 2902 free_pages((unsigned long) conn->data,
2909 get_order(ISCSI_DEF_MAX_RECV_SEG_LEN)); 2903 get_order(ISCSI_DEF_MAX_RECV_SEG_LEN));
2910 kfree(conn->persistent_address); 2904 kfree(conn->persistent_address);
2911 __kfifo_put(session->cmdpool.queue, (void*)&conn->login_task, 2905 __kfifo_put(&session->cmdpool.queue, (void*)&conn->login_task,
2912 sizeof(void*)); 2906 sizeof(void*));
2913 if (session->leadconn == conn) 2907 if (session->leadconn == conn)
2914 session->leadconn = NULL; 2908 session->leadconn = NULL;