1 diff -urNp linux-1580/drivers/char/raw.c linux-1620/drivers/char/raw.c
2 --- linux-1580/drivers/char/raw.c
3 +++ linux-1620/drivers/char/raw.c
4 @@ -86,12 +86,6 @@ int raw_open(struct inode *inode, struct
5 filp->f_op = &raw_ctl_fops;
9 - if (!filp->f_iobuf) {
10 - err = alloc_kiovec(1, &filp->f_iobuf);
15 down(&raw_devices[minor].mutex);
17 @@ -295,7 +289,6 @@ ssize_t rw_raw_dev(int rw, struct file *
18 size_t size, loff_t *offp)
20 struct kiobuf * iobuf;
23 unsigned long blocknr, blocks;
25 @@ -314,18 +307,10 @@ ssize_t rw_raw_dev(int rw, struct file *
27 minor = MINOR(filp->f_dentry->d_inode->i_rdev);
30 - iobuf = filp->f_iobuf;
31 - if (test_and_set_bit(0, &filp->f_iobuf_lock)) {
33 - * A parallel read/write is using the preallocated iobuf
34 - * so just run slow and allocate a new one.
36 - err = alloc_kiovec(1, &iobuf);
41 + err = alloc_kiovec(1, &iobuf);
46 dev = to_kdev_t(raw_devices[minor].binding->bd_dev);
47 sector_size = raw_devices[minor].sector_size;
48 @@ -398,10 +383,6 @@ ssize_t rw_raw_dev(int rw, struct file *
53 - clear_bit(0, &filp->f_iobuf_lock);
55 - free_kiovec(1, &iobuf);
57 + free_kiovec(1, &iobuf);
60 diff -urNp linux-1580/fs/iobuf.c linux-1620/fs/iobuf.c
61 --- linux-1580/fs/iobuf.c
62 +++ linux-1620/fs/iobuf.c
65 #include <linux/iobuf.h>
66 #include <linux/slab.h>
67 -#include <linux/vmalloc.h>
70 static kmem_cache_t *kiobuf_cachep;
72 @@ -27,6 +25,8 @@ void end_kio_request(struct kiobuf *kiob
74 static int kiobuf_init(struct kiobuf *iobuf)
78 init_waitqueue_head(&iobuf->wait_queue);
81 @@ -35,7 +35,16 @@ static int kiobuf_init(struct kiobuf *io
83 atomic_set(&iobuf->io_count, 0);
85 - return expand_kiobuf(iobuf, KIO_STATIC_PAGES);
86 + iobuf->initialized = 0;
87 + retval = expand_kiobuf(iobuf, KIO_STATIC_PAGES);
88 + if (retval) return retval;
89 + retval = alloc_kiobuf_bhs(iobuf);
91 + kfree(iobuf->maplist);
94 + iobuf->initialized = 1;
98 int alloc_kiobuf_bhs(struct kiobuf * kiobuf)
99 @@ -89,6 +98,21 @@ void free_kiobuf_bhs(struct kiobuf * kio
103 +void kiobuf_ctor(void * objp, kmem_cache_t * cachep, unsigned long flag)
105 + struct kiobuf * iobuf = (struct kiobuf *) objp;
106 + kiobuf_init(iobuf);
109 +void kiobuf_dtor(void * objp, kmem_cache_t * cachep, unsigned long flag)
111 + struct kiobuf * iobuf = (struct kiobuf *) objp;
112 + if (iobuf->initialized) {
113 + kfree(iobuf->maplist);
114 + free_kiobuf_bhs(iobuf);
118 int alloc_kiovec(int nr, struct kiobuf **bufp)
121 @@ -98,10 +122,11 @@ int alloc_kiovec(int nr, struct kiobuf *
122 iobuf = kmem_cache_alloc(kiobuf_cachep, GFP_KERNEL);
123 if (unlikely(!iobuf))
125 - if (unlikely(kiobuf_init(iobuf)))
127 - if (unlikely(alloc_kiobuf_bhs(iobuf)))
129 + if (unlikely(!iobuf->initialized)) {
130 + /* try again to complete previously failed ctor */
131 + if (unlikely(kiobuf_init(iobuf)))
137 @@ -121,11 +146,10 @@ void free_kiovec(int nr, struct kiobuf *
139 for (i = 0; i < nr; i++) {
142 - unlock_kiovec(1, &iobuf);
143 - kfree(iobuf->maplist);
144 - free_kiobuf_bhs(iobuf);
145 - kmem_cache_free(kiobuf_cachep, bufp[i]);
146 + init_waitqueue_head(&iobuf->wait_queue);
147 + iobuf->io_count.counter = 0;
148 + iobuf->end_io = NULL;
149 + kmem_cache_free(kiobuf_cachep, iobuf);
153 @@ -180,7 +204,7 @@ repeat:
154 void __init iobuf_cache_init(void)
156 kiobuf_cachep = kmem_cache_create("kiobuf", sizeof(struct kiobuf),
157 - 0, SLAB_HWCACHE_ALIGN, NULL, NULL);
158 + 0, SLAB_HWCACHE_ALIGN, kiobuf_ctor, kiobuf_dtor);
160 panic("Cannot create kiobuf SLAB cache");
162 diff -urNp linux-1580/include/linux/iobuf.h linux-1620/include/linux/iobuf.h
163 --- linux-1580/include/linux/iobuf.h
164 +++ linux-1620/include/linux/iobuf.h
165 @@ -39,7 +39,8 @@ struct kiobuf
166 int offset; /* Offset to start of valid data */
167 int length; /* Number of valid bytes of data */
169 - unsigned int locked : 1; /* If set, pages has been locked */
170 + unsigned int locked : 1, /* If set, pages has been locked */
171 + initialized:1; /* If set, done initialize */
173 struct page ** maplist;
174 struct buffer_head ** bh;