Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 172899
b: refs/heads/master
c: ca80650
h: refs/heads/master
i:
  172897: 090487e
  172895: a793348
v: v3
  • Loading branch information
Christoph Hellwig authored and Jens Axboe committed Oct 1, 2009
1 parent f8b6872 commit 57964d6
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 6 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 1122a26f2abe4245ccdaed95ec23f63fe086b332
refs/heads/master: ca80650cfbde5b17a5fa957a261c7973f84599a7
10 changes: 6 additions & 4 deletions trunk/block/blk-barrier.c
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,8 @@ int blkdev_issue_discard(struct block_device *bdev, sector_t sector,

while (nr_sects && !ret) {
unsigned int sector_size = q->limits.logical_block_size;
unsigned int max_discard_sectors =
min(q->limits.max_discard_sectors, UINT_MAX >> 9);

bio = bio_alloc(gfp_mask, 1);
if (!bio)
Expand All @@ -411,10 +413,10 @@ int blkdev_issue_discard(struct block_device *bdev, sector_t sector,
* touch many more blocks on disk than the actual payload
* length.
*/
if (nr_sects > queue_max_hw_sectors(q)) {
bio->bi_size = queue_max_hw_sectors(q) << 9;
nr_sects -= queue_max_hw_sectors(q);
sector += queue_max_hw_sectors(q);
if (nr_sects > max_discard_sectors) {
bio->bi_size = max_discard_sectors << 9;
nr_sects -= max_discard_sectors;
sector += max_discard_sectors;
} else {
bio->bi_size = nr_sects << 9;
nr_sects = 0;
Expand Down
3 changes: 2 additions & 1 deletion trunk/block/blk-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -1436,7 +1436,8 @@ static inline void __generic_make_request(struct bio *bio)
goto end_io;
}

if (unlikely(nr_sectors > queue_max_hw_sectors(q))) {
if (unlikely(!bio_rw_flagged(bio, BIO_RW_DISCARD) &&
nr_sectors > queue_max_hw_sectors(q))) {
printk(KERN_ERR "bio too big device %s (%u > %u)\n",
bdevname(bio->bi_bdev, b),
bio_sectors(bio),
Expand Down
13 changes: 13 additions & 0 deletions trunk/block/blk-settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ void blk_set_default_limits(struct queue_limits *lim)
lim->max_segment_size = MAX_SEGMENT_SIZE;
lim->max_sectors = BLK_DEF_MAX_SECTORS;
lim->max_hw_sectors = INT_MAX;
lim->max_discard_sectors = SAFE_MAX_SECTORS;
lim->logical_block_size = lim->physical_block_size = lim->io_min = 512;
lim->bounce_pfn = (unsigned long)(BLK_BOUNCE_ANY >> PAGE_SHIFT);
lim->alignment_offset = 0;
Expand Down Expand Up @@ -238,6 +239,18 @@ void blk_queue_max_hw_sectors(struct request_queue *q, unsigned int max_sectors)
}
EXPORT_SYMBOL(blk_queue_max_hw_sectors);

/**
* blk_queue_max_discard_sectors - set max sectors for a single discard
* @q: the request queue for the device
* @max_discard: maximum number of sectors to discard
**/
void blk_queue_max_discard_sectors(struct request_queue *q,
unsigned int max_discard_sectors)
{
q->limits.max_discard_sectors = max_discard_sectors;
}
EXPORT_SYMBOL(blk_queue_max_discard_sectors);

/**
* blk_queue_max_phys_segments - set max phys segments for a request for this queue
* @q: the request queue for the device
Expand Down
3 changes: 3 additions & 0 deletions trunk/include/linux/blkdev.h
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ struct queue_limits {
unsigned int alignment_offset;
unsigned int io_min;
unsigned int io_opt;
unsigned int max_discard_sectors;

unsigned short logical_block_size;
unsigned short max_hw_segments;
Expand Down Expand Up @@ -928,6 +929,8 @@ extern void blk_queue_max_hw_sectors(struct request_queue *, unsigned int);
extern void blk_queue_max_phys_segments(struct request_queue *, unsigned short);
extern void blk_queue_max_hw_segments(struct request_queue *, unsigned short);
extern void blk_queue_max_segment_size(struct request_queue *, unsigned int);
extern void blk_queue_max_discard_sectors(struct request_queue *q,
unsigned int max_discard_sectors);
extern void blk_queue_logical_block_size(struct request_queue *, unsigned short);
extern void blk_queue_physical_block_size(struct request_queue *, unsigned short);
extern void blk_queue_alignment_offset(struct request_queue *q,
Expand Down

0 comments on commit 57964d6

Please sign in to comment.