]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - fs/bio.c
block: add support for IO CPU affinity
[linux-2.6-omap-h63xx.git] / fs / bio.c
index 8000e2fa16cb21a12f8288b3f0b7eeb8d88ab042..6a637b5c24b5b8f859f8368e7b91e71706711f5c 100644 (file)
--- a/fs/bio.c
+++ b/fs/bio.c
@@ -111,6 +111,7 @@ void bio_init(struct bio *bio)
 {
        memset(bio, 0, sizeof(*bio));
        bio->bi_flags = 1 << BIO_UPTODATE;
+       bio->bi_comp_cpu = -1;
        atomic_set(&bio->bi_cnt, 1);
 }
 
@@ -208,14 +209,6 @@ inline int bio_phys_segments(struct request_queue *q, struct bio *bio)
        return bio->bi_phys_segments;
 }
 
-inline int bio_hw_segments(struct request_queue *q, struct bio *bio)
-{
-       if (unlikely(!bio_flagged(bio, BIO_SEG_VALID)))
-               blk_recount_segments(q, bio);
-
-       return bio->bi_hw_segments;
-}
-
 /**
  *     __bio_clone     -       clone a bio
  *     @bio: destination bio
@@ -350,8 +343,7 @@ static int __bio_add_page(struct request_queue *q, struct bio *bio, struct page
         */
 
        while (bio->bi_phys_segments >= q->max_phys_segments
-              || bio->bi_hw_segments >= q->max_hw_segments
-              || BIOVEC_VIRT_OVERSIZE(bio->bi_size)) {
+              || bio->bi_phys_segments >= q->max_hw_segments) {
 
                if (retried_segments)
                        return 0;
@@ -395,13 +387,11 @@ static int __bio_add_page(struct request_queue *q, struct bio *bio, struct page
        }
 
        /* If we may be able to merge these biovecs, force a recount */
-       if (bio->bi_vcnt && (BIOVEC_PHYS_MERGEABLE(bvec-1, bvec) ||
-           BIOVEC_VIRT_MERGEABLE(bvec-1, bvec)))
+       if (bio->bi_vcnt && (BIOVEC_PHYS_MERGEABLE(bvec-1, bvec)))
                bio->bi_flags &= ~(1 << BIO_SEG_VALID);
 
        bio->bi_vcnt++;
        bio->bi_phys_segments++;
-       bio->bi_hw_segments++;
  done:
        bio->bi_size += len;
        return len;
@@ -469,20 +459,21 @@ static void bio_free_map_data(struct bio_map_data *bmd)
        kfree(bmd);
 }
 
-static struct bio_map_data *bio_alloc_map_data(int nr_segs, int iov_count)
+static struct bio_map_data *bio_alloc_map_data(int nr_segs, int iov_count,
+                                              gfp_t gfp_mask)
 {
-       struct bio_map_data *bmd = kmalloc(sizeof(*bmd), GFP_KERNEL);
+       struct bio_map_data *bmd = kmalloc(sizeof(*bmd), gfp_mask);
 
        if (!bmd)
                return NULL;
 
-       bmd->iovecs = kmalloc(sizeof(struct bio_vec) * nr_segs, GFP_KERNEL);
+       bmd->iovecs = kmalloc(sizeof(struct bio_vec) * nr_segs, gfp_mask);
        if (!bmd->iovecs) {
                kfree(bmd);
                return NULL;
        }
 
-       bmd->sgvecs = kmalloc(sizeof(struct sg_iovec) * iov_count, GFP_KERNEL);
+       bmd->sgvecs = kmalloc(sizeof(struct sg_iovec) * iov_count, gfp_mask);
        if (bmd->sgvecs)
                return bmd;
 
@@ -491,8 +482,8 @@ static struct bio_map_data *bio_alloc_map_data(int nr_segs, int iov_count)
        return NULL;
 }
 
-static int __bio_copy_iov(struct bio *bio, struct sg_iovec *iov, int iov_count,
-                         int uncopy)
+static int __bio_copy_iov(struct bio *bio, struct bio_vec *iovecs,
+                         struct sg_iovec *iov, int iov_count, int uncopy)
 {
        int ret = 0, i;
        struct bio_vec *bvec;
@@ -502,7 +493,7 @@ static int __bio_copy_iov(struct bio *bio, struct sg_iovec *iov, int iov_count,
 
        __bio_for_each_segment(bvec, bio, i, 0) {
                char *bv_addr = page_address(bvec->bv_page);
-               unsigned int bv_len = bvec->bv_len;
+               unsigned int bv_len = iovecs[i].bv_len;
 
                while (bv_len && iov_idx < iov_count) {
                        unsigned int bytes;
@@ -554,7 +545,7 @@ int bio_uncopy_user(struct bio *bio)
        struct bio_map_data *bmd = bio->bi_private;
        int ret;
 
-       ret = __bio_copy_iov(bio, bmd->sgvecs, bmd->nr_sgvecs, 1);
+       ret = __bio_copy_iov(bio, bmd->iovecs, bmd->sgvecs, bmd->nr_sgvecs, 1);
 
        bio_free_map_data(bmd);
        bio_put(bio);
@@ -596,7 +587,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q, struct sg_iovec *iov,
                len += iov[i].iov_len;
        }
 
-       bmd = bio_alloc_map_data(nr_pages, iov_count);
+       bmd = bio_alloc_map_data(nr_pages, iov_count, GFP_KERNEL);
        if (!bmd)
                return ERR_PTR(-ENOMEM);
 
@@ -633,7 +624,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q, struct sg_iovec *iov,
         * success
         */
        if (!write_to_vm) {
-               ret = __bio_copy_iov(bio, iov, iov_count, 0);
+               ret = __bio_copy_iov(bio, bio->bi_io_vec, iov, iov_count, 0);
                if (ret)
                        goto cleanup;
        }
@@ -942,19 +933,22 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
 {
        struct bio_vec *bvec;
        const int read = bio_data_dir(bio) == READ;
-       char *p = bio->bi_private;
+       struct bio_map_data *bmd = bio->bi_private;
        int i;
+       char *p = bmd->sgvecs[0].iov_base;
 
        __bio_for_each_segment(bvec, bio, i, 0) {
                char *addr = page_address(bvec->bv_page);
+               int len = bmd->iovecs[i].bv_len;
 
                if (read && !err)
-                       memcpy(p, addr, bvec->bv_len);
+                       memcpy(p, addr, len);
 
                __free_page(bvec->bv_page);
-               p += bvec->bv_len;
+               p += len;
        }
 
+       bio_free_map_data(bmd);
        bio_put(bio);
 }
 
@@ -978,11 +972,21 @@ struct bio *bio_copy_kern(struct request_queue *q, void *data, unsigned int len,
        const int nr_pages = end - start;
        struct bio *bio;
        struct bio_vec *bvec;
+       struct bio_map_data *bmd;
        int i, ret;
+       struct sg_iovec iov;
+
+       iov.iov_base = data;
+       iov.iov_len = len;
+
+       bmd = bio_alloc_map_data(nr_pages, 1, gfp_mask);
+       if (!bmd)
+               return ERR_PTR(-ENOMEM);
 
+       ret = -ENOMEM;
        bio = bio_alloc(gfp_mask, nr_pages);
        if (!bio)
-               return ERR_PTR(-ENOMEM);
+               goto out_bmd;
 
        while (len) {
                struct page *page;
@@ -1016,14 +1020,18 @@ struct bio *bio_copy_kern(struct request_queue *q, void *data, unsigned int len,
                }
        }
 
-       bio->bi_private = data;
+       bio->bi_private = bmd;
        bio->bi_end_io = bio_copy_kern_endio;
+
+       bio_set_map_data(bmd, bio, &iov, 1);
        return bio;
 cleanup:
        bio_for_each_segment(bvec, bio, i)
                __free_page(bvec->bv_page);
 
        bio_put(bio);
+out_bmd:
+       bio_free_map_data(bmd);
 
        return ERR_PTR(ret);
 }
@@ -1365,7 +1373,6 @@ EXPORT_SYMBOL(bio_init);
 EXPORT_SYMBOL(__bio_clone);
 EXPORT_SYMBOL(bio_clone);
 EXPORT_SYMBOL(bio_phys_segments);
-EXPORT_SYMBOL(bio_hw_segments);
 EXPORT_SYMBOL(bio_add_page);
 EXPORT_SYMBOL(bio_add_pc_page);
 EXPORT_SYMBOL(bio_get_nr_vecs);