diff options
Diffstat (limited to 'block')
-rw-r--r-- | block/blk-map.c | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/block/blk-map.c b/block/blk-map.c index 3c942bd6422a..0b1af5a3537c 100644 --- a/block/blk-map.c +++ b/block/blk-map.c | |||
@@ -255,10 +255,18 @@ EXPORT_SYMBOL(blk_rq_unmap_user); | |||
255 | * @kbuf: the kernel buffer | 255 | * @kbuf: the kernel buffer |
256 | * @len: length of user data | 256 | * @len: length of user data |
257 | * @gfp_mask: memory allocation flags | 257 | * @gfp_mask: memory allocation flags |
258 | * | ||
259 | * Description: | ||
260 | * Data will be mapped directly if possible. Otherwise a bounce | ||
261 | * buffer is used. | ||
258 | */ | 262 | */ |
259 | int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf, | 263 | int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf, |
260 | unsigned int len, gfp_t gfp_mask) | 264 | unsigned int len, gfp_t gfp_mask) |
261 | { | 265 | { |
266 | unsigned long kaddr; | ||
267 | unsigned int alignment; | ||
268 | int reading = rq_data_dir(rq) == READ; | ||
269 | int do_copy = 0; | ||
262 | struct bio *bio; | 270 | struct bio *bio; |
263 | 271 | ||
264 | if (len > (q->max_hw_sectors << 9)) | 272 | if (len > (q->max_hw_sectors << 9)) |
@@ -266,13 +274,24 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf, | |||
266 | if (!len || !kbuf) | 274 | if (!len || !kbuf) |
267 | return -EINVAL; | 275 | return -EINVAL; |
268 | 276 | ||
269 | bio = bio_map_kern(q, kbuf, len, gfp_mask); | 277 | kaddr = (unsigned long)kbuf; |
278 | alignment = queue_dma_alignment(q) | q->dma_pad_mask; | ||
279 | do_copy = ((kaddr & alignment) || (len & alignment)); | ||
280 | |||
281 | if (do_copy) | ||
282 | bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading); | ||
283 | else | ||
284 | bio = bio_map_kern(q, kbuf, len, gfp_mask); | ||
285 | |||
270 | if (IS_ERR(bio)) | 286 | if (IS_ERR(bio)) |
271 | return PTR_ERR(bio); | 287 | return PTR_ERR(bio); |
272 | 288 | ||
273 | if (rq_data_dir(rq) == WRITE) | 289 | if (rq_data_dir(rq) == WRITE) |
274 | bio->bi_rw |= (1 << BIO_RW); | 290 | bio->bi_rw |= (1 << BIO_RW); |
275 | 291 | ||
292 | if (do_copy) | ||
293 | rq->cmd_flags |= REQ_COPY_USER; | ||
294 | |||
276 | blk_rq_bio_prep(q, rq, bio); | 295 | blk_rq_bio_prep(q, rq, bio); |
277 | blk_queue_bounce(q, &rq->bio); | 296 | blk_queue_bounce(q, &rq->bio); |
278 | rq->buffer = rq->data = NULL; | 297 | rq->buffer = rq->data = NULL; |