diff options
author | Martin K. Petersen <martin.petersen@oracle.com> | 2012-09-18 12:19:28 -0400 |
---|---|---|
committer | Jens Axboe <axboe@kernel.dk> | 2012-09-20 08:31:49 -0400 |
commit | 579e8f3c7b2ecf7db91398d942d76457a3ddba21 (patch) | |
tree | f41d7d469cb427550656f1d1d2c3b5215a9ea0aa /block | |
parent | 4363ac7c13a9a4b763c6e8d9fdbfc2468f3b8ca4 (diff) |
block: Make blkdev_issue_zeroout use WRITE SAME
If the device supports WRITE SAME, use that to optimize zeroing of
blocks. If the device does not support WRITE SAME or if the operation
fails, fall back to writing zeroes the old-fashioned way.
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
Acked-by: Mike Snitzer <snitzer@redhat.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'block')
-rw-r--r-- | block/blk-lib.c | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/block/blk-lib.c b/block/blk-lib.c index a062543c58ac..9373b58dfab1 100644 --- a/block/blk-lib.c +++ b/block/blk-lib.c | |||
@@ -214,7 +214,7 @@ EXPORT_SYMBOL(blkdev_issue_write_same); | |||
214 | * Generate and issue number of bios with zerofiled pages. | 214 | * Generate and issue number of bios with zerofiled pages. |
215 | */ | 215 | */ |
216 | 216 | ||
217 | int blkdev_issue_zeroout(struct block_device *bdev, sector_t sector, | 217 | int __blkdev_issue_zeroout(struct block_device *bdev, sector_t sector, |
218 | sector_t nr_sects, gfp_t gfp_mask) | 218 | sector_t nr_sects, gfp_t gfp_mask) |
219 | { | 219 | { |
220 | int ret; | 220 | int ret; |
@@ -264,4 +264,32 @@ int blkdev_issue_zeroout(struct block_device *bdev, sector_t sector, | |||
264 | 264 | ||
265 | return ret; | 265 | return ret; |
266 | } | 266 | } |
267 | |||
268 | /** | ||
269 | * blkdev_issue_zeroout - zero-fill a block range | ||
270 | * @bdev: blockdev to write | ||
271 | * @sector: start sector | ||
272 | * @nr_sects: number of sectors to write | ||
273 | * @gfp_mask: memory allocation flags (for bio_alloc) | ||
274 | * | ||
275 | * Description: | ||
276 | * Generate and issue number of bios with zerofiled pages. | ||
277 | */ | ||
278 | |||
279 | int blkdev_issue_zeroout(struct block_device *bdev, sector_t sector, | ||
280 | sector_t nr_sects, gfp_t gfp_mask) | ||
281 | { | ||
282 | if (bdev_write_same(bdev)) { | ||
283 | unsigned char bdn[BDEVNAME_SIZE]; | ||
284 | |||
285 | if (!blkdev_issue_write_same(bdev, sector, nr_sects, gfp_mask, | ||
286 | ZERO_PAGE(0))) | ||
287 | return 0; | ||
288 | |||
289 | bdevname(bdev, bdn); | ||
290 | pr_err("%s: WRITE SAME failed. Manually zeroing.\n", bdn); | ||
291 | } | ||
292 | |||
293 | return __blkdev_issue_zeroout(bdev, sector, nr_sects, gfp_mask); | ||
294 | } | ||
267 | EXPORT_SYMBOL(blkdev_issue_zeroout); | 295 | EXPORT_SYMBOL(blkdev_issue_zeroout); |