diff options
author | Stefani Seibold <stefani@seibold.net> | 2009-12-21 17:37:26 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2009-12-22 17:17:55 -0500 |
commit | 45465487897a1c6d508b14b904dc5777f7ec7e04 (patch) | |
tree | 935c8dae68dc793ff2f795d57cf027531475cd53 /drivers/scsi/libsrp.c | |
parent | 2ec91eec47f713e3d158ba5b28a24a85a2cf3650 (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/libsrp.c')
-rw-r--r-- | drivers/scsi/libsrp.c | 13 |
1 files changed, 5 insertions, 8 deletions
diff --git a/drivers/scsi/libsrp.c b/drivers/scsi/libsrp.c index 9ad38e81e343..b1b5e51ca8e3 100644 --- a/drivers/scsi/libsrp.c +++ b/drivers/scsi/libsrp.c | |||
@@ -58,19 +58,16 @@ static int srp_iu_pool_alloc(struct srp_queue *q, size_t max, | |||
58 | goto free_pool; | 58 | goto free_pool; |
59 | 59 | ||
60 | spin_lock_init(&q->lock); | 60 | spin_lock_init(&q->lock); |
61 | q->queue = kfifo_init((void *) q->pool, max * sizeof(void *), | 61 | kfifo_init(&q->queue, (void *) q->pool, max * sizeof(void *), |
62 | GFP_KERNEL, &q->lock); | 62 | &q->lock); |
63 | if (IS_ERR(q->queue)) | ||
64 | goto free_item; | ||
65 | 63 | ||
66 | for (i = 0, iue = q->items; i < max; i++) { | 64 | for (i = 0, iue = q->items; i < max; i++) { |
67 | __kfifo_put(q->queue, (void *) &iue, sizeof(void *)); | 65 | __kfifo_put(&q->queue, (void *) &iue, sizeof(void *)); |
68 | iue->sbuf = ring[i]; | 66 | iue->sbuf = ring[i]; |
69 | iue++; | 67 | iue++; |
70 | } | 68 | } |
71 | return 0; | 69 | return 0; |
72 | 70 | ||
73 | free_item: | ||
74 | kfree(q->items); | 71 | kfree(q->items); |
75 | free_pool: | 72 | free_pool: |
76 | kfree(q->pool); | 73 | kfree(q->pool); |
@@ -167,7 +164,7 @@ struct iu_entry *srp_iu_get(struct srp_target *target) | |||
167 | { | 164 | { |
168 | struct iu_entry *iue = NULL; | 165 | struct iu_entry *iue = NULL; |
169 | 166 | ||
170 | kfifo_get(target->iu_queue.queue, (void *) &iue, sizeof(void *)); | 167 | kfifo_get(&target->iu_queue.queue, (void *) &iue, sizeof(void *)); |
171 | if (!iue) | 168 | if (!iue) |
172 | return iue; | 169 | return iue; |
173 | iue->target = target; | 170 | iue->target = target; |
@@ -179,7 +176,7 @@ EXPORT_SYMBOL_GPL(srp_iu_get); | |||
179 | 176 | ||
180 | void srp_iu_put(struct iu_entry *iue) | 177 | void srp_iu_put(struct iu_entry *iue) |
181 | { | 178 | { |
182 | kfifo_put(iue->target->iu_queue.queue, (void *) &iue, sizeof(void *)); | 179 | kfifo_put(&iue->target->iu_queue.queue, (void *) &iue, sizeof(void *)); |
183 | } | 180 | } |
184 | EXPORT_SYMBOL_GPL(srp_iu_put); | 181 | EXPORT_SYMBOL_GPL(srp_iu_put); |
185 | 182 | ||