Commit 3e6053d7 authored by Hugh Dickins's avatar Hugh Dickins Committed by Jens Axboe

block: adjust blkdev_issue_discard for swap

Two mods to blkdev_issue_discard(), thinking ahead to its use on swap:

1. Add gfp_mask argument, so swap allocation can use it where GFP_KERNEL
   might deadlock but GFP_NOIO is safe.

2. Enlarge nr_sects argument from unsigned to sector_t: unsigned long is
   enough to cover a whole swap area, but sector_t suits any partition.

Change sb_issue_discard()'s nr_blocks to sector_t too; but no need seen
for a gfp_mask there, just pass GFP_KERNEL down to blkdev_issue_discard().
Signed-off-by: default avatarHugh Dickins <hugh@veritas.com>
Signed-off-by: default avatarJens Axboe <jens.axboe@oracle.com>
parent 4677735f
...@@ -332,12 +332,13 @@ static void blkdev_discard_end_io(struct bio *bio, int err) ...@@ -332,12 +332,13 @@ static void blkdev_discard_end_io(struct bio *bio, int err)
* @bdev: blockdev to issue discard for * @bdev: blockdev to issue discard for
* @sector: start sector * @sector: start sector
* @nr_sects: number of sectors to discard * @nr_sects: number of sectors to discard
* @gfp_mask: memory allocation flags (for bio_alloc)
* *
* Description: * Description:
* Issue a discard request for the sectors in question. Does not wait. * Issue a discard request for the sectors in question. Does not wait.
*/ */
int blkdev_issue_discard(struct block_device *bdev, sector_t sector, int blkdev_issue_discard(struct block_device *bdev,
unsigned nr_sects) sector_t sector, sector_t nr_sects, gfp_t gfp_mask)
{ {
struct request_queue *q; struct request_queue *q;
struct bio *bio; struct bio *bio;
...@@ -354,7 +355,7 @@ int blkdev_issue_discard(struct block_device *bdev, sector_t sector, ...@@ -354,7 +355,7 @@ int blkdev_issue_discard(struct block_device *bdev, sector_t sector,
return -EOPNOTSUPP; return -EOPNOTSUPP;
while (nr_sects && !ret) { while (nr_sects && !ret) {
bio = bio_alloc(GFP_KERNEL, 0); bio = bio_alloc(gfp_mask, 0);
if (!bio) if (!bio)
return -ENOMEM; return -ENOMEM;
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include <linux/bio.h> #include <linux/bio.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/stringify.h> #include <linux/stringify.h>
#include <linux/gfp.h>
#include <linux/bsg.h> #include <linux/bsg.h>
#include <linux/smp.h> #include <linux/smp.h>
...@@ -873,15 +874,15 @@ static inline struct request *blk_map_queue_find_tag(struct blk_queue_tag *bqt, ...@@ -873,15 +874,15 @@ static inline struct request *blk_map_queue_find_tag(struct blk_queue_tag *bqt,
} }
extern int blkdev_issue_flush(struct block_device *, sector_t *); extern int blkdev_issue_flush(struct block_device *, sector_t *);
extern int blkdev_issue_discard(struct block_device *, sector_t sector, extern int blkdev_issue_discard(struct block_device *,
unsigned nr_sects); sector_t sector, sector_t nr_sects, gfp_t);
static inline int sb_issue_discard(struct super_block *sb, static inline int sb_issue_discard(struct super_block *sb,
sector_t block, unsigned nr_blocks) sector_t block, sector_t nr_blocks)
{ {
block <<= (sb->s_blocksize_bits - 9); block <<= (sb->s_blocksize_bits - 9);
nr_blocks <<= (sb->s_blocksize_bits - 9); nr_blocks <<= (sb->s_blocksize_bits - 9);
return blkdev_issue_discard(sb->s_bdev, block, nr_blocks); return blkdev_issue_discard(sb->s_bdev, block, nr_blocks, GFP_KERNEL);
} }
/* /*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment