提交 a3bce90e 编写于 作者: F FUJITA Tomonori 提交者: Jens Axboe

block: add gfp_mask argument to blk_rq_map_user and blk_rq_map_user_iov

Currently, blk_rq_map_user and blk_rq_map_user_iov always do
GFP_KERNEL allocation.

This adds gfp_mask argument to blk_rq_map_user and blk_rq_map_user_iov
so sg can use it (sg always does GFP_ATOMIC allocation).
Signed-off-by: NFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Signed-off-by: NDouglas Gilbert <dougg@torque.net>
Cc: Mike Christie <michaelc@cs.wisc.edu>
Cc: James Bottomley <James.Bottomley@HansenPartnership.com>
Signed-off-by: NJens Axboe <jens.axboe@oracle.com>
上级 45333d5a
...@@ -41,7 +41,8 @@ static int __blk_rq_unmap_user(struct bio *bio) ...@@ -41,7 +41,8 @@ static int __blk_rq_unmap_user(struct bio *bio)
} }
static int __blk_rq_map_user(struct request_queue *q, struct request *rq, static int __blk_rq_map_user(struct request_queue *q, struct request *rq,
void __user *ubuf, unsigned int len) void __user *ubuf, unsigned int len,
gfp_t gfp_mask)
{ {
unsigned long uaddr; unsigned long uaddr;
unsigned int alignment; unsigned int alignment;
...@@ -57,9 +58,9 @@ static int __blk_rq_map_user(struct request_queue *q, struct request *rq, ...@@ -57,9 +58,9 @@ static int __blk_rq_map_user(struct request_queue *q, struct request *rq,
uaddr = (unsigned long) ubuf; uaddr = (unsigned long) ubuf;
alignment = queue_dma_alignment(q) | q->dma_pad_mask; alignment = queue_dma_alignment(q) | q->dma_pad_mask;
if (!(uaddr & alignment) && !(len & alignment)) if (!(uaddr & alignment) && !(len & alignment))
bio = bio_map_user(q, NULL, uaddr, len, reading); bio = bio_map_user(q, NULL, uaddr, len, reading, gfp_mask);
else else
bio = bio_copy_user(q, uaddr, len, reading); bio = bio_copy_user(q, uaddr, len, reading, gfp_mask);
if (IS_ERR(bio)) if (IS_ERR(bio))
return PTR_ERR(bio); return PTR_ERR(bio);
...@@ -90,6 +91,7 @@ static int __blk_rq_map_user(struct request_queue *q, struct request *rq, ...@@ -90,6 +91,7 @@ static int __blk_rq_map_user(struct request_queue *q, struct request *rq,
* @rq: request structure to fill * @rq: request structure to fill
* @ubuf: the user buffer * @ubuf: the user buffer
* @len: length of user data * @len: length of user data
* @gfp_mask: memory allocation flags
* *
* Description: * Description:
* Data will be mapped directly for zero copy I/O, if possible. Otherwise * Data will be mapped directly for zero copy I/O, if possible. Otherwise
...@@ -105,7 +107,7 @@ static int __blk_rq_map_user(struct request_queue *q, struct request *rq, ...@@ -105,7 +107,7 @@ static int __blk_rq_map_user(struct request_queue *q, struct request *rq,
* unmapping. * unmapping.
*/ */
int blk_rq_map_user(struct request_queue *q, struct request *rq, int blk_rq_map_user(struct request_queue *q, struct request *rq,
void __user *ubuf, unsigned long len) void __user *ubuf, unsigned long len, gfp_t gfp_mask)
{ {
unsigned long bytes_read = 0; unsigned long bytes_read = 0;
struct bio *bio = NULL; struct bio *bio = NULL;
...@@ -132,7 +134,7 @@ int blk_rq_map_user(struct request_queue *q, struct request *rq, ...@@ -132,7 +134,7 @@ int blk_rq_map_user(struct request_queue *q, struct request *rq,
if (end - start > BIO_MAX_PAGES) if (end - start > BIO_MAX_PAGES)
map_len -= PAGE_SIZE; map_len -= PAGE_SIZE;
ret = __blk_rq_map_user(q, rq, ubuf, map_len); ret = __blk_rq_map_user(q, rq, ubuf, map_len, gfp_mask);
if (ret < 0) if (ret < 0)
goto unmap_rq; goto unmap_rq;
if (!bio) if (!bio)
...@@ -160,6 +162,7 @@ EXPORT_SYMBOL(blk_rq_map_user); ...@@ -160,6 +162,7 @@ EXPORT_SYMBOL(blk_rq_map_user);
* @iov: pointer to the iovec * @iov: pointer to the iovec
* @iov_count: number of elements in the iovec * @iov_count: number of elements in the iovec
* @len: I/O byte count * @len: I/O byte count
* @gfp_mask: memory allocation flags
* *
* Description: * Description:
* Data will be mapped directly for zero copy I/O, if possible. Otherwise * Data will be mapped directly for zero copy I/O, if possible. Otherwise
...@@ -175,7 +178,8 @@ EXPORT_SYMBOL(blk_rq_map_user); ...@@ -175,7 +178,8 @@ EXPORT_SYMBOL(blk_rq_map_user);
* unmapping. * unmapping.
*/ */
int blk_rq_map_user_iov(struct request_queue *q, struct request *rq, int blk_rq_map_user_iov(struct request_queue *q, struct request *rq,
struct sg_iovec *iov, int iov_count, unsigned int len) struct sg_iovec *iov, int iov_count, unsigned int len,
gfp_t gfp_mask)
{ {
struct bio *bio; struct bio *bio;
int i, read = rq_data_dir(rq) == READ; int i, read = rq_data_dir(rq) == READ;
...@@ -194,9 +198,9 @@ int blk_rq_map_user_iov(struct request_queue *q, struct request *rq, ...@@ -194,9 +198,9 @@ int blk_rq_map_user_iov(struct request_queue *q, struct request *rq,
} }
if (unaligned || (q->dma_pad_mask & len)) if (unaligned || (q->dma_pad_mask & len))
bio = bio_copy_user_iov(q, iov, iov_count, read); bio = bio_copy_user_iov(q, iov, iov_count, read, gfp_mask);
else else
bio = bio_map_user_iov(q, NULL, iov, iov_count, read); bio = bio_map_user_iov(q, NULL, iov, iov_count, read, gfp_mask);
if (IS_ERR(bio)) if (IS_ERR(bio))
return PTR_ERR(bio); return PTR_ERR(bio);
......
...@@ -283,7 +283,8 @@ bsg_map_hdr(struct bsg_device *bd, struct sg_io_v4 *hdr, int has_write_perm) ...@@ -283,7 +283,8 @@ bsg_map_hdr(struct bsg_device *bd, struct sg_io_v4 *hdr, int has_write_perm)
next_rq->cmd_type = rq->cmd_type; next_rq->cmd_type = rq->cmd_type;
dxferp = (void*)(unsigned long)hdr->din_xferp; dxferp = (void*)(unsigned long)hdr->din_xferp;
ret = blk_rq_map_user(q, next_rq, dxferp, hdr->din_xfer_len); ret = blk_rq_map_user(q, next_rq, dxferp, hdr->din_xfer_len,
GFP_KERNEL);
if (ret) if (ret)
goto out; goto out;
} }
...@@ -298,7 +299,7 @@ bsg_map_hdr(struct bsg_device *bd, struct sg_io_v4 *hdr, int has_write_perm) ...@@ -298,7 +299,7 @@ bsg_map_hdr(struct bsg_device *bd, struct sg_io_v4 *hdr, int has_write_perm)
dxfer_len = 0; dxfer_len = 0;
if (dxfer_len) { if (dxfer_len) {
ret = blk_rq_map_user(q, rq, dxferp, dxfer_len); ret = blk_rq_map_user(q, rq, dxferp, dxfer_len, GFP_KERNEL);
if (ret) if (ret)
goto out; goto out;
} }
......
...@@ -315,10 +315,11 @@ static int sg_io(struct file *file, struct request_queue *q, ...@@ -315,10 +315,11 @@ static int sg_io(struct file *file, struct request_queue *q,
} }
ret = blk_rq_map_user_iov(q, rq, iov, hdr->iovec_count, ret = blk_rq_map_user_iov(q, rq, iov, hdr->iovec_count,
hdr->dxfer_len); hdr->dxfer_len, GFP_KERNEL);
kfree(iov); kfree(iov);
} else if (hdr->dxfer_len) } else if (hdr->dxfer_len)
ret = blk_rq_map_user(q, rq, hdr->dxferp, hdr->dxfer_len); ret = blk_rq_map_user(q, rq, hdr->dxferp, hdr->dxfer_len,
GFP_KERNEL);
if (ret) if (ret)
goto out; goto out;
......
...@@ -2097,7 +2097,7 @@ static int cdrom_read_cdda_bpc(struct cdrom_device_info *cdi, __u8 __user *ubuf, ...@@ -2097,7 +2097,7 @@ static int cdrom_read_cdda_bpc(struct cdrom_device_info *cdi, __u8 __user *ubuf,
len = nr * CD_FRAMESIZE_RAW; len = nr * CD_FRAMESIZE_RAW;
ret = blk_rq_map_user(q, rq, ubuf, len); ret = blk_rq_map_user(q, rq, ubuf, len, GFP_KERNEL);
if (ret) if (ret)
break; break;
......
...@@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd, ...@@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
int err; int err;
dprintk("%lx %u\n", uaddr, len); dprintk("%lx %u\n", uaddr, len);
err = blk_rq_map_user(q, rq, (void *)uaddr, len); err = blk_rq_map_user(q, rq, (void *)uaddr, len, GFP_KERNEL);
if (err) { if (err) {
/* /*
* TODO: need to fixup sg_tablesize, max_segment_size, * TODO: need to fixup sg_tablesize, max_segment_size,
......
...@@ -558,13 +558,14 @@ int bio_uncopy_user(struct bio *bio) ...@@ -558,13 +558,14 @@ int bio_uncopy_user(struct bio *bio)
* @iov: the iovec. * @iov: the iovec.
* @iov_count: number of elements in the iovec * @iov_count: number of elements in the iovec
* @write_to_vm: bool indicating writing to pages or not * @write_to_vm: bool indicating writing to pages or not
* @gfp_mask: memory allocation flags
* *
* Prepares and returns a bio for indirect user io, bouncing data * Prepares and returns a bio for indirect user io, bouncing data
* to/from kernel pages as necessary. Must be paired with * to/from kernel pages as necessary. Must be paired with
* call bio_uncopy_user() on io completion. * call bio_uncopy_user() on io completion.
*/ */
struct bio *bio_copy_user_iov(struct request_queue *q, struct sg_iovec *iov, struct bio *bio_copy_user_iov(struct request_queue *q, struct sg_iovec *iov,
int iov_count, int write_to_vm) int iov_count, int write_to_vm, gfp_t gfp_mask)
{ {
struct bio_map_data *bmd; struct bio_map_data *bmd;
struct bio_vec *bvec; struct bio_vec *bvec;
...@@ -587,12 +588,12 @@ struct bio *bio_copy_user_iov(struct request_queue *q, struct sg_iovec *iov, ...@@ -587,12 +588,12 @@ struct bio *bio_copy_user_iov(struct request_queue *q, struct sg_iovec *iov,
len += iov[i].iov_len; len += iov[i].iov_len;
} }
bmd = bio_alloc_map_data(nr_pages, iov_count, GFP_KERNEL); bmd = bio_alloc_map_data(nr_pages, iov_count, gfp_mask);
if (!bmd) if (!bmd)
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
ret = -ENOMEM; ret = -ENOMEM;
bio = bio_alloc(GFP_KERNEL, nr_pages); bio = bio_alloc(gfp_mask, nr_pages);
if (!bio) if (!bio)
goto out_bmd; goto out_bmd;
...@@ -605,7 +606,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q, struct sg_iovec *iov, ...@@ -605,7 +606,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q, struct sg_iovec *iov,
if (bytes > len) if (bytes > len)
bytes = len; bytes = len;
page = alloc_page(q->bounce_gfp | GFP_KERNEL); page = alloc_page(q->bounce_gfp | gfp_mask);
if (!page) { if (!page) {
ret = -ENOMEM; ret = -ENOMEM;
break; break;
...@@ -647,26 +648,27 @@ struct bio *bio_copy_user_iov(struct request_queue *q, struct sg_iovec *iov, ...@@ -647,26 +648,27 @@ struct bio *bio_copy_user_iov(struct request_queue *q, struct sg_iovec *iov,
* @uaddr: start of user address * @uaddr: start of user address
* @len: length in bytes * @len: length in bytes
* @write_to_vm: bool indicating writing to pages or not * @write_to_vm: bool indicating writing to pages or not
* @gfp_mask: memory allocation flags
* *
* Prepares and returns a bio for indirect user io, bouncing data * Prepares and returns a bio for indirect user io, bouncing data
* to/from kernel pages as necessary. Must be paired with * to/from kernel pages as necessary. Must be paired with
* call bio_uncopy_user() on io completion. * call bio_uncopy_user() on io completion.
*/ */
struct bio *bio_copy_user(struct request_queue *q, unsigned long uaddr, struct bio *bio_copy_user(struct request_queue *q, unsigned long uaddr,
unsigned int len, int write_to_vm) unsigned int len, int write_to_vm, gfp_t gfp_mask)
{ {
struct sg_iovec iov; struct sg_iovec iov;
iov.iov_base = (void __user *)uaddr; iov.iov_base = (void __user *)uaddr;
iov.iov_len = len; iov.iov_len = len;
return bio_copy_user_iov(q, &iov, 1, write_to_vm); return bio_copy_user_iov(q, &iov, 1, write_to_vm, gfp_mask);
} }
static struct bio *__bio_map_user_iov(struct request_queue *q, static struct bio *__bio_map_user_iov(struct request_queue *q,
struct block_device *bdev, struct block_device *bdev,
struct sg_iovec *iov, int iov_count, struct sg_iovec *iov, int iov_count,
int write_to_vm) int write_to_vm, gfp_t gfp_mask)
{ {
int i, j; int i, j;
int nr_pages = 0; int nr_pages = 0;
...@@ -692,12 +694,12 @@ static struct bio *__bio_map_user_iov(struct request_queue *q, ...@@ -692,12 +694,12 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
if (!nr_pages) if (!nr_pages)
return ERR_PTR(-EINVAL); return ERR_PTR(-EINVAL);
bio = bio_alloc(GFP_KERNEL, nr_pages); bio = bio_alloc(gfp_mask, nr_pages);
if (!bio) if (!bio)
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
ret = -ENOMEM; ret = -ENOMEM;
pages = kcalloc(nr_pages, sizeof(struct page *), GFP_KERNEL); pages = kcalloc(nr_pages, sizeof(struct page *), gfp_mask);
if (!pages) if (!pages)
goto out; goto out;
...@@ -776,19 +778,21 @@ static struct bio *__bio_map_user_iov(struct request_queue *q, ...@@ -776,19 +778,21 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
* @uaddr: start of user address * @uaddr: start of user address
* @len: length in bytes * @len: length in bytes
* @write_to_vm: bool indicating writing to pages or not * @write_to_vm: bool indicating writing to pages or not
* @gfp_mask: memory allocation flags
* *
* Map the user space address into a bio suitable for io to a block * Map the user space address into a bio suitable for io to a block
* device. Returns an error pointer in case of error. * device. Returns an error pointer in case of error.
*/ */
struct bio *bio_map_user(struct request_queue *q, struct block_device *bdev, struct bio *bio_map_user(struct request_queue *q, struct block_device *bdev,
unsigned long uaddr, unsigned int len, int write_to_vm) unsigned long uaddr, unsigned int len, int write_to_vm,
gfp_t gfp_mask)
{ {
struct sg_iovec iov; struct sg_iovec iov;
iov.iov_base = (void __user *)uaddr; iov.iov_base = (void __user *)uaddr;
iov.iov_len = len; iov.iov_len = len;
return bio_map_user_iov(q, bdev, &iov, 1, write_to_vm); return bio_map_user_iov(q, bdev, &iov, 1, write_to_vm, gfp_mask);
} }
/** /**
...@@ -798,18 +802,19 @@ struct bio *bio_map_user(struct request_queue *q, struct block_device *bdev, ...@@ -798,18 +802,19 @@ struct bio *bio_map_user(struct request_queue *q, struct block_device *bdev,
* @iov: the iovec. * @iov: the iovec.
* @iov_count: number of elements in the iovec * @iov_count: number of elements in the iovec
* @write_to_vm: bool indicating writing to pages or not * @write_to_vm: bool indicating writing to pages or not
* @gfp_mask: memory allocation flags
* *
* Map the user space address into a bio suitable for io to a block * Map the user space address into a bio suitable for io to a block
* device. Returns an error pointer in case of error. * device. Returns an error pointer in case of error.
*/ */
struct bio *bio_map_user_iov(struct request_queue *q, struct block_device *bdev, struct bio *bio_map_user_iov(struct request_queue *q, struct block_device *bdev,
struct sg_iovec *iov, int iov_count, struct sg_iovec *iov, int iov_count,
int write_to_vm) int write_to_vm, gfp_t gfp_mask)
{ {
struct bio *bio; struct bio *bio;
bio = __bio_map_user_iov(q, bdev, iov, iov_count, write_to_vm); bio = __bio_map_user_iov(q, bdev, iov, iov_count, write_to_vm,
gfp_mask);
if (IS_ERR(bio)) if (IS_ERR(bio))
return bio; return bio;
......
...@@ -325,11 +325,11 @@ extern int bio_add_pc_page(struct request_queue *, struct bio *, struct page *, ...@@ -325,11 +325,11 @@ extern int bio_add_pc_page(struct request_queue *, struct bio *, struct page *,
unsigned int, unsigned int); unsigned int, unsigned int);
extern int bio_get_nr_vecs(struct block_device *); extern int bio_get_nr_vecs(struct block_device *);
extern struct bio *bio_map_user(struct request_queue *, struct block_device *, extern struct bio *bio_map_user(struct request_queue *, struct block_device *,
unsigned long, unsigned int, int); unsigned long, unsigned int, int, gfp_t);
struct sg_iovec; struct sg_iovec;
extern struct bio *bio_map_user_iov(struct request_queue *, extern struct bio *bio_map_user_iov(struct request_queue *,
struct block_device *, struct block_device *,
struct sg_iovec *, int, int); struct sg_iovec *, int, int, gfp_t);
extern void bio_unmap_user(struct bio *); extern void bio_unmap_user(struct bio *);
extern struct bio *bio_map_kern(struct request_queue *, void *, unsigned int, extern struct bio *bio_map_kern(struct request_queue *, void *, unsigned int,
gfp_t); gfp_t);
...@@ -337,9 +337,10 @@ extern struct bio *bio_copy_kern(struct request_queue *, void *, unsigned int, ...@@ -337,9 +337,10 @@ extern struct bio *bio_copy_kern(struct request_queue *, void *, unsigned int,
gfp_t, int); gfp_t, int);
extern void bio_set_pages_dirty(struct bio *bio); extern void bio_set_pages_dirty(struct bio *bio);
extern void bio_check_pages_dirty(struct bio *bio); extern void bio_check_pages_dirty(struct bio *bio);
extern struct bio *bio_copy_user(struct request_queue *, unsigned long, unsigned int, int); extern struct bio *bio_copy_user(struct request_queue *, unsigned long,
unsigned int, int, gfp_t);
extern struct bio *bio_copy_user_iov(struct request_queue *, struct sg_iovec *, extern struct bio *bio_copy_user_iov(struct request_queue *, struct sg_iovec *,
int, int); int, int, gfp_t);
extern int bio_uncopy_user(struct bio *); extern int bio_uncopy_user(struct bio *);
void zero_fill_bio(struct bio *bio); void zero_fill_bio(struct bio *bio);
extern struct bio_vec *bvec_alloc_bs(gfp_t, int, unsigned long *, struct bio_set *); extern struct bio_vec *bvec_alloc_bs(gfp_t, int, unsigned long *, struct bio_set *);
......
...@@ -710,11 +710,12 @@ extern void __blk_stop_queue(struct request_queue *q); ...@@ -710,11 +710,12 @@ extern void __blk_stop_queue(struct request_queue *q);
extern void __blk_run_queue(struct request_queue *); extern void __blk_run_queue(struct request_queue *);
extern void blk_run_queue(struct request_queue *); extern void blk_run_queue(struct request_queue *);
extern void blk_start_queueing(struct request_queue *); extern void blk_start_queueing(struct request_queue *);
extern int blk_rq_map_user(struct request_queue *, struct request *, void __user *, unsigned long); extern int blk_rq_map_user(struct request_queue *, struct request *,
void __user *, unsigned long, gfp_t);
extern int blk_rq_unmap_user(struct bio *); extern int blk_rq_unmap_user(struct bio *);
extern int blk_rq_map_kern(struct request_queue *, struct request *, void *, unsigned int, gfp_t); extern int blk_rq_map_kern(struct request_queue *, struct request *, void *, unsigned int, gfp_t);
extern int blk_rq_map_user_iov(struct request_queue *, struct request *, extern int blk_rq_map_user_iov(struct request_queue *, struct request *,
struct sg_iovec *, int, unsigned int); struct sg_iovec *, int, unsigned int, gfp_t);
extern int blk_execute_rq(struct request_queue *, struct gendisk *, extern int blk_execute_rq(struct request_queue *, struct gendisk *,
struct request *, int); struct request *, int);
extern void blk_execute_rq_nowait(struct request_queue *, struct gendisk *, extern void blk_execute_rq_nowait(struct request_queue *, struct gendisk *,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册