jffs2: constify xattr_handler
[safe/jmp/linux-2.6] / fs / bio.c
index bcab9e9..e7bf6ca 100644 (file)
--- a/fs/bio.c
+++ b/fs/bio.c
@@ -78,7 +78,7 @@ static struct kmem_cache *bio_find_or_create_slab(unsigned int extra_size)
 
        i = 0;
        while (i < bio_slab_nr) {
-               struct bio_slab *bslab = &bio_slabs[i];
+               bslab = &bio_slabs[i];
 
                if (!bslab->slab && entry == -1)
                        entry = i;
@@ -264,15 +264,14 @@ EXPORT_SYMBOL(bio_init);
  * bio_alloc_bioset - allocate a bio for I/O
  * @gfp_mask:   the GFP_ mask given to the slab allocator
  * @nr_iovecs: number of iovecs to pre-allocate
- * @bs:                the bio_set to allocate from. If %NULL, just use kmalloc
+ * @bs:                the bio_set to allocate from.
  *
  * Description:
- *   bio_alloc_bioset will first try its own mempool to satisfy the allocation.
+ *   bio_alloc_bioset will try its own mempool to satisfy the allocation.
  *   If %__GFP_WAIT is set then we will block on the internal pool waiting
- *   for a &struct bio to become free. If a %NULL @bs is passed in, we will
- *   fall back to just using @kmalloc to allocate the required memory.
+ *   for a &struct bio to become free.
  *
- *   Note that the caller must set ->bi_destructor on succesful return
+ *   Note that the caller must set ->bi_destructor on successful return
  *   of a bio, to do the appropriate freeing of the bio once the reference
  *   count drops to zero.
  **/
@@ -325,8 +324,16 @@ static void bio_fs_destructor(struct bio *bio)
  *     @gfp_mask: allocation mask to use
  *     @nr_iovecs: number of iovecs
  *
- *     Allocate a new bio with @nr_iovecs bvecs.  If @gfp_mask
- *     contains __GFP_WAIT, the allocation is guaranteed to succeed.
+ *     bio_alloc will allocate a bio and associated bio_vec array that can hold
+ *     at least @nr_iovecs entries. Allocations will be done from the
+ *     fs_bio_set. Also see @bio_alloc_bioset and @bio_kmalloc.
+ *
+ *     If %__GFP_WAIT is set, then bio_alloc will always be able to allocate
+ *     a bio. This is due to the mempool guarantees. To make this work, callers
+ *     must never allocate more than 1 bio at a time from this pool. Callers
+ *     that need to allocate more than 1 bio must always submit the previously
+ *     allocated bio for IO before attempting to allocate a new one. Failure to
+ *     do so can cause livelocks under memory pressure.
  *
  *     RETURNS:
  *     Pointer to new bio on success, NULL on failure.
@@ -350,21 +357,13 @@ static void bio_kmalloc_destructor(struct bio *bio)
 }
 
 /**
- * bio_alloc - allocate a bio for I/O
+ * bio_kmalloc - allocate a bio for I/O using kmalloc()
  * @gfp_mask:   the GFP_ mask given to the slab allocator
  * @nr_iovecs: number of iovecs to pre-allocate
  *
  * Description:
- *   bio_alloc will allocate a bio and associated bio_vec array that can hold
- *   at least @nr_iovecs entries. Allocations will be done from the
- *   fs_bio_set. Also see @bio_alloc_bioset.
- *
- *   If %__GFP_WAIT is set, then bio_alloc will always be able to allocate
- *   a bio. This is due to the mempool guarantees. To make this work, callers
- *   must never allocate more than 1 bio at a time from this pool. Callers
- *   that need to allocate more than 1 bio must always submit the previously
- *   allocated bio for IO before attempting to allocate a new one. Failure to
- *   do so can cause livelocks under memory pressure.
+ *   Allocate a new bio with @nr_iovecs bvecs.  If @gfp_mask contains
+ *   %__GFP_WAIT, the allocation is guaranteed to succeed.
  *
  **/
 struct bio *bio_kmalloc(gfp_t gfp_mask, int nr_iovecs)
@@ -507,10 +506,8 @@ int bio_get_nr_vecs(struct block_device *bdev)
        int nr_pages;
 
        nr_pages = ((queue_max_sectors(q) << 9) + PAGE_SIZE - 1) >> PAGE_SHIFT;
-       if (nr_pages > queue_max_phys_segments(q))
-               nr_pages = queue_max_phys_segments(q);
-       if (nr_pages > queue_max_hw_segments(q))
-               nr_pages = queue_max_hw_segments(q);
+       if (nr_pages > queue_max_segments(q))
+               nr_pages = queue_max_segments(q);
 
        return nr_pages;
 }
@@ -542,17 +539,22 @@ static int __bio_add_page(struct request_queue *q, struct bio *bio, struct page
 
                if (page == prev->bv_page &&
                    offset == prev->bv_offset + prev->bv_len) {
+                       unsigned int prev_bv_len = prev->bv_len;
                        prev->bv_len += len;
 
                        if (q->merge_bvec_fn) {
                                struct bvec_merge_data bvm = {
+                                       /* prev_bvec is already charged in
+                                          bi_size, discharge it in order to
+                                          simulate merging updated prev_bvec
+                                          as new bvec. */
                                        .bi_bdev = bio->bi_bdev,
                                        .bi_sector = bio->bi_sector,
-                                       .bi_size = bio->bi_size,
+                                       .bi_size = bio->bi_size - prev_bv_len,
                                        .bi_rw = bio->bi_rw,
                                };
 
-                               if (q->merge_bvec_fn(q, &bvm, prev) < len) {
+                               if (q->merge_bvec_fn(q, &bvm, prev) < prev->bv_len) {
                                        prev->bv_len -= len;
                                        return 0;
                                }
@@ -570,8 +572,7 @@ static int __bio_add_page(struct request_queue *q, struct bio *bio, struct page
         * make this too complex.
         */
 
-       while (bio->bi_phys_segments >= queue_max_phys_segments(q)
-              || bio->bi_phys_segments >= queue_max_hw_segments(q)) {
+       while (bio->bi_phys_segments >= queue_max_segments(q)) {
 
                if (retried_segments)
                        return 0;
@@ -606,7 +607,7 @@ static int __bio_add_page(struct request_queue *q, struct bio *bio, struct page
                 * merge_bvec_fn() returns number of bytes it can accept
                 * at this offset
                 */
-               if (q->merge_bvec_fn(q, &bvm, bvec) < len) {
+               if (q->merge_bvec_fn(q, &bvm, bvec) < bvec->bv_len) {
                        bvec->bv_page = NULL;
                        bvec->bv_len = 0;
                        bvec->bv_offset = 0;
@@ -1393,6 +1394,18 @@ void bio_check_pages_dirty(struct bio *bio)
        }
 }
 
+#if ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE
+void bio_flush_dcache_pages(struct bio *bi)
+{
+       int i;
+       struct bio_vec *bvec;
+
+       bio_for_each_segment(bvec, bi, i)
+               flush_dcache_page(bvec->bv_page);
+}
+EXPORT_SYMBOL(bio_flush_dcache_pages);
+#endif
+
 /**
  * bio_endio - end I/O on a bio
  * @bio:       bio