提交 e03a72e1 编写于 作者: M Martin K. Petersen 提交者: Jens Axboe

block: Stop using byte offsets

All callers of the stacking functions use 512-byte sector units rather
than byte offsets.  Simplify the code so the stacking functions take
sectors when specifying data offsets.
Signed-off-by: NMartin K. Petersen <martin.petersen@oracle.com>
Signed-off-by: NJens Axboe <jens.axboe@oracle.com>
上级 ce289321
...@@ -507,7 +507,7 @@ static unsigned int lcm(unsigned int a, unsigned int b) ...@@ -507,7 +507,7 @@ static unsigned int lcm(unsigned int a, unsigned int b)
* blk_stack_limits - adjust queue_limits for stacked devices * blk_stack_limits - adjust queue_limits for stacked devices
* @t: the stacking driver limits (top device) * @t: the stacking driver limits (top device)
* @b: the underlying queue limits (bottom, component device) * @b: the underlying queue limits (bottom, component device)
* @offset: offset to beginning of data within component device * @start: first data sector within component device
* *
* Description: * Description:
* This function is used by stacking drivers like MD and DM to ensure * This function is used by stacking drivers like MD and DM to ensure
...@@ -525,10 +525,9 @@ static unsigned int lcm(unsigned int a, unsigned int b) ...@@ -525,10 +525,9 @@ static unsigned int lcm(unsigned int a, unsigned int b)
* the alignment_offset is undefined. * the alignment_offset is undefined.
*/ */
int blk_stack_limits(struct queue_limits *t, struct queue_limits *b, int blk_stack_limits(struct queue_limits *t, struct queue_limits *b,
sector_t offset) sector_t start)
{ {
sector_t alignment; unsigned int top, bottom, alignment, ret = 0;
unsigned int top, bottom, ret = 0;
t->max_sectors = min_not_zero(t->max_sectors, b->max_sectors); t->max_sectors = min_not_zero(t->max_sectors, b->max_sectors);
t->max_hw_sectors = min_not_zero(t->max_hw_sectors, b->max_hw_sectors); t->max_hw_sectors = min_not_zero(t->max_hw_sectors, b->max_hw_sectors);
...@@ -548,7 +547,7 @@ int blk_stack_limits(struct queue_limits *t, struct queue_limits *b, ...@@ -548,7 +547,7 @@ int blk_stack_limits(struct queue_limits *t, struct queue_limits *b,
t->misaligned |= b->misaligned; t->misaligned |= b->misaligned;
alignment = queue_limit_alignment_offset(b, offset); alignment = queue_limit_alignment_offset(b, start);
/* Bottom device has different alignment. Check that it is /* Bottom device has different alignment. Check that it is
* compatible with the current top alignment. * compatible with the current top alignment.
...@@ -611,11 +610,7 @@ int blk_stack_limits(struct queue_limits *t, struct queue_limits *b, ...@@ -611,11 +610,7 @@ int blk_stack_limits(struct queue_limits *t, struct queue_limits *b,
/* Discard alignment and granularity */ /* Discard alignment and granularity */
if (b->discard_granularity) { if (b->discard_granularity) {
unsigned int granularity = b->discard_granularity; alignment = queue_limit_discard_alignment(b, start);
offset &= granularity - 1;
alignment = (granularity + b->discard_alignment - offset)
& (granularity - 1);
if (t->discard_granularity != 0 && if (t->discard_granularity != 0 &&
t->discard_alignment != alignment) { t->discard_alignment != alignment) {
...@@ -657,7 +652,7 @@ int bdev_stack_limits(struct queue_limits *t, struct block_device *bdev, ...@@ -657,7 +652,7 @@ int bdev_stack_limits(struct queue_limits *t, struct block_device *bdev,
start += get_start_sect(bdev); start += get_start_sect(bdev);
return blk_stack_limits(t, &bq->limits, start << 9); return blk_stack_limits(t, &bq->limits, start);
} }
EXPORT_SYMBOL(bdev_stack_limits); EXPORT_SYMBOL(bdev_stack_limits);
...@@ -668,9 +663,8 @@ EXPORT_SYMBOL(bdev_stack_limits); ...@@ -668,9 +663,8 @@ EXPORT_SYMBOL(bdev_stack_limits);
* @offset: offset to beginning of data within component device * @offset: offset to beginning of data within component device
* *
* Description: * Description:
* Merges the limits for two queues. Returns 0 if alignment * Merges the limits for a top level gendisk and a bottom level
* didn't change. Returns -1 if adding the bottom device caused * block_device.
* misalignment.
*/ */
void disk_stack_limits(struct gendisk *disk, struct block_device *bdev, void disk_stack_limits(struct gendisk *disk, struct block_device *bdev,
sector_t offset) sector_t offset)
...@@ -678,9 +672,7 @@ void disk_stack_limits(struct gendisk *disk, struct block_device *bdev, ...@@ -678,9 +672,7 @@ void disk_stack_limits(struct gendisk *disk, struct block_device *bdev,
struct request_queue *t = disk->queue; struct request_queue *t = disk->queue;
struct request_queue *b = bdev_get_queue(bdev); struct request_queue *b = bdev_get_queue(bdev);
offset += get_start_sect(bdev) << 9; if (bdev_stack_limits(&t->limits, bdev, offset >> 9) < 0) {
if (blk_stack_limits(&t->limits, &b->limits, offset) < 0) {
char top[BDEVNAME_SIZE], bottom[BDEVNAME_SIZE]; char top[BDEVNAME_SIZE], bottom[BDEVNAME_SIZE];
disk_name(disk, 0, top); disk_name(disk, 0, top);
......
...@@ -412,9 +412,10 @@ struct hd_struct *add_partition(struct gendisk *disk, int partno, ...@@ -412,9 +412,10 @@ struct hd_struct *add_partition(struct gendisk *disk, int partno,
pdev = part_to_dev(p); pdev = part_to_dev(p);
p->start_sect = start; p->start_sect = start;
p->alignment_offset = queue_sector_alignment_offset(disk->queue, start); p->alignment_offset =
p->discard_alignment = queue_sector_discard_alignment(disk->queue, queue_limit_alignment_offset(&disk->queue->limits, start);
start); p->discard_alignment =
queue_limit_discard_alignment(&disk->queue->limits, start);
p->nr_sects = len; p->nr_sects = len;
p->partno = partno; p->partno = partno;
p->policy = get_disk_ro(disk); p->policy = get_disk_ro(disk);
......
...@@ -1112,18 +1112,13 @@ static inline int queue_alignment_offset(struct request_queue *q) ...@@ -1112,18 +1112,13 @@ static inline int queue_alignment_offset(struct request_queue *q)
return q->limits.alignment_offset; return q->limits.alignment_offset;
} }
static inline int queue_limit_alignment_offset(struct queue_limits *lim, sector_t offset) static inline int queue_limit_alignment_offset(struct queue_limits *lim, sector_t sector)
{ {
unsigned int granularity = max(lim->physical_block_size, lim->io_min); unsigned int granularity = max(lim->physical_block_size, lim->io_min);
unsigned int alignment = (sector << 9) & (granularity - 1);
offset &= granularity - 1; return (granularity + lim->alignment_offset - alignment)
return (granularity + lim->alignment_offset - offset) & (granularity - 1); & (granularity - 1);
}
static inline int queue_sector_alignment_offset(struct request_queue *q,
sector_t sector)
{
return queue_limit_alignment_offset(&q->limits, sector << 9);
} }
static inline int bdev_alignment_offset(struct block_device *bdev) static inline int bdev_alignment_offset(struct block_device *bdev)
...@@ -1147,10 +1142,8 @@ static inline int queue_discard_alignment(struct request_queue *q) ...@@ -1147,10 +1142,8 @@ static inline int queue_discard_alignment(struct request_queue *q)
return q->limits.discard_alignment; return q->limits.discard_alignment;
} }
static inline int queue_sector_discard_alignment(struct request_queue *q, static inline int queue_limit_discard_alignment(struct queue_limits *lim, sector_t sector)
sector_t sector)
{ {
struct queue_limits *lim = &q->limits;
unsigned int alignment = (sector << 9) & (lim->discard_granularity - 1); unsigned int alignment = (sector << 9) & (lim->discard_granularity - 1);
return (lim->discard_granularity + lim->discard_alignment - alignment) return (lim->discard_granularity + lim->discard_alignment - alignment)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册