diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2008-04-29 11:18:03 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2008-04-29 11:18:03 -0400 |
commit | bd5d435a96837c3495e62eef37cbe4cb728b79ae (patch) | |
tree | 82aacaf5a1d220910c4b0a1088d7d2482c0d9ee0 /fs | |
parent | fee4b19fb3f28d17c0b9f9ea0668db5275697178 (diff) | |
parent | ac9fafa1243640349aa481adf473db283a695766 (diff) |
Merge branch 'for-linus' of git://git.kernel.dk/linux-2.6-block
* 'for-linus' of git://git.kernel.dk/linux-2.6-block:
block: Skip I/O merges when disabled
block: add large command support
block: replace sizeof(rq->cmd) with BLK_MAX_CDB
ide: use blk_rq_init() to initialize the request
block: use blk_rq_init() to initialize the request
block: rename and export rq_init()
block: no need to initialize rq->cmd with blk_get_request
block: no need to initialize rq->cmd in prepare_flush_fn hook
block/blk-barrier.c:blk_ordered_cur_seq() mustn't be inline
block/elevator.c:elv_rq_merge_ok() mustn't be inline
block: make queue flags non-atomic
block: add dma alignment and padding support to blk_rq_map_kern
unexport blk_max_pfn
ps3disk: Remove superfluous cast
block: make rq_init() do a full memset()
relay: fix splice problem
Diffstat (limited to 'fs')
-rw-r--r-- | fs/bio.c | 90 | ||||
-rw-r--r-- | fs/splice.c | 2 |
2 files changed, 91 insertions, 1 deletions
@@ -937,6 +937,95 @@ struct bio *bio_map_kern(struct request_queue *q, void *data, unsigned int len, | |||
937 | return ERR_PTR(-EINVAL); | 937 | return ERR_PTR(-EINVAL); |
938 | } | 938 | } |
939 | 939 | ||
940 | static void bio_copy_kern_endio(struct bio *bio, int err) | ||
941 | { | ||
942 | struct bio_vec *bvec; | ||
943 | const int read = bio_data_dir(bio) == READ; | ||
944 | char *p = bio->bi_private; | ||
945 | int i; | ||
946 | |||
947 | __bio_for_each_segment(bvec, bio, i, 0) { | ||
948 | char *addr = page_address(bvec->bv_page); | ||
949 | |||
950 | if (read && !err) | ||
951 | memcpy(p, addr, bvec->bv_len); | ||
952 | |||
953 | __free_page(bvec->bv_page); | ||
954 | p += bvec->bv_len; | ||
955 | } | ||
956 | |||
957 | bio_put(bio); | ||
958 | } | ||
959 | |||
960 | /** | ||
961 | * bio_copy_kern - copy kernel address into bio | ||
962 | * @q: the struct request_queue for the bio | ||
963 | * @data: pointer to buffer to copy | ||
964 | * @len: length in bytes | ||
965 | * @gfp_mask: allocation flags for bio and page allocation | ||
966 | * | ||
967 | * copy the kernel address into a bio suitable for io to a block | ||
968 | * device. Returns an error pointer in case of error. | ||
969 | */ | ||
970 | struct bio *bio_copy_kern(struct request_queue *q, void *data, unsigned int len, | ||
971 | gfp_t gfp_mask, int reading) | ||
972 | { | ||
973 | unsigned long kaddr = (unsigned long)data; | ||
974 | unsigned long end = (kaddr + len + PAGE_SIZE - 1) >> PAGE_SHIFT; | ||
975 | unsigned long start = kaddr >> PAGE_SHIFT; | ||
976 | const int nr_pages = end - start; | ||
977 | struct bio *bio; | ||
978 | struct bio_vec *bvec; | ||
979 | int i, ret; | ||
980 | |||
981 | bio = bio_alloc(gfp_mask, nr_pages); | ||
982 | if (!bio) | ||
983 | return ERR_PTR(-ENOMEM); | ||
984 | |||
985 | while (len) { | ||
986 | struct page *page; | ||
987 | unsigned int bytes = PAGE_SIZE; | ||
988 | |||
989 | if (bytes > len) | ||
990 | bytes = len; | ||
991 | |||
992 | page = alloc_page(q->bounce_gfp | gfp_mask); | ||
993 | if (!page) { | ||
994 | ret = -ENOMEM; | ||
995 | goto cleanup; | ||
996 | } | ||
997 | |||
998 | if (bio_add_pc_page(q, bio, page, bytes, 0) < bytes) { | ||
999 | ret = -EINVAL; | ||
1000 | goto cleanup; | ||
1001 | } | ||
1002 | |||
1003 | len -= bytes; | ||
1004 | } | ||
1005 | |||
1006 | if (!reading) { | ||
1007 | void *p = data; | ||
1008 | |||
1009 | bio_for_each_segment(bvec, bio, i) { | ||
1010 | char *addr = page_address(bvec->bv_page); | ||
1011 | |||
1012 | memcpy(addr, p, bvec->bv_len); | ||
1013 | p += bvec->bv_len; | ||
1014 | } | ||
1015 | } | ||
1016 | |||
1017 | bio->bi_private = data; | ||
1018 | bio->bi_end_io = bio_copy_kern_endio; | ||
1019 | return bio; | ||
1020 | cleanup: | ||
1021 | bio_for_each_segment(bvec, bio, i) | ||
1022 | __free_page(bvec->bv_page); | ||
1023 | |||
1024 | bio_put(bio); | ||
1025 | |||
1026 | return ERR_PTR(ret); | ||
1027 | } | ||
1028 | |||
940 | /* | 1029 | /* |
941 | * bio_set_pages_dirty() and bio_check_pages_dirty() are support functions | 1030 | * bio_set_pages_dirty() and bio_check_pages_dirty() are support functions |
942 | * for performing direct-IO in BIOs. | 1031 | * for performing direct-IO in BIOs. |
@@ -1273,6 +1362,7 @@ EXPORT_SYMBOL(bio_get_nr_vecs); | |||
1273 | EXPORT_SYMBOL(bio_map_user); | 1362 | EXPORT_SYMBOL(bio_map_user); |
1274 | EXPORT_SYMBOL(bio_unmap_user); | 1363 | EXPORT_SYMBOL(bio_unmap_user); |
1275 | EXPORT_SYMBOL(bio_map_kern); | 1364 | EXPORT_SYMBOL(bio_map_kern); |
1365 | EXPORT_SYMBOL(bio_copy_kern); | ||
1276 | EXPORT_SYMBOL(bio_pair_release); | 1366 | EXPORT_SYMBOL(bio_pair_release); |
1277 | EXPORT_SYMBOL(bio_split); | 1367 | EXPORT_SYMBOL(bio_split); |
1278 | EXPORT_SYMBOL(bio_split_pool); | 1368 | EXPORT_SYMBOL(bio_split_pool); |
diff --git a/fs/splice.c b/fs/splice.c index eeb1a86a7014..633f58ebfb72 100644 --- a/fs/splice.c +++ b/fs/splice.c | |||
@@ -1075,7 +1075,7 @@ long do_splice_direct(struct file *in, loff_t *ppos, struct file *out, | |||
1075 | 1075 | ||
1076 | ret = splice_direct_to_actor(in, &sd, direct_splice_actor); | 1076 | ret = splice_direct_to_actor(in, &sd, direct_splice_actor); |
1077 | if (ret > 0) | 1077 | if (ret > 0) |
1078 | *ppos += ret; | 1078 | *ppos = sd.pos; |
1079 | 1079 | ||
1080 | return ret; | 1080 | return ret; |
1081 | } | 1081 | } |