Skip to content

Commit

Permalink
block: Stop using byte offsets
Browse files Browse the repository at this point in the history
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: Martin K. Petersen <martin.petersen@oracle.com>
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
  • Loading branch information
Martin K. Petersen authored and Jens Axboe committed Jan 11, 2010
1 parent ce28932 commit e03a72e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 32 deletions.
26 changes: 9 additions & 17 deletions block/blk-settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ static unsigned int lcm(unsigned int a, unsigned int b)
* blk_stack_limits - adjust queue_limits for stacked devices
* @t: the stacking driver limits (top 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:
* This function is used by stacking drivers like MD and DM to ensure
Expand All @@ -525,10 +525,9 @@ static unsigned int lcm(unsigned int a, unsigned int b)
* the alignment_offset is undefined.
*/
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, ret = 0;
unsigned int top, bottom, alignment, ret = 0;

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);
Expand All @@ -548,7 +547,7 @@ int blk_stack_limits(struct queue_limits *t, struct queue_limits *b,

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
* compatible with the current top alignment.
Expand Down Expand Up @@ -611,11 +610,7 @@ int blk_stack_limits(struct queue_limits *t, struct queue_limits *b,

/* Discard alignment and granularity */
if (b->discard_granularity) {
unsigned int granularity = b->discard_granularity;
offset &= granularity - 1;

alignment = (granularity + b->discard_alignment - offset)
& (granularity - 1);
alignment = queue_limit_discard_alignment(b, start);

if (t->discard_granularity != 0 &&
t->discard_alignment != alignment) {
Expand Down Expand Up @@ -657,7 +652,7 @@ int bdev_stack_limits(struct queue_limits *t, struct block_device *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);

Expand All @@ -668,19 +663,16 @@ EXPORT_SYMBOL(bdev_stack_limits);
* @offset: offset to beginning of data within component device
*
* Description:
* Merges the limits for two queues. Returns 0 if alignment
* didn't change. Returns -1 if adding the bottom device caused
* misalignment.
* Merges the limits for a top level gendisk and a bottom level
* block_device.
*/
void disk_stack_limits(struct gendisk *disk, struct block_device *bdev,
sector_t offset)
{
struct request_queue *t = disk->queue;
struct request_queue *b = bdev_get_queue(bdev);

offset += get_start_sect(bdev) << 9;

if (blk_stack_limits(&t->limits, &b->limits, offset) < 0) {
if (bdev_stack_limits(&t->limits, bdev, offset >> 9) < 0) {
char top[BDEVNAME_SIZE], bottom[BDEVNAME_SIZE];

disk_name(disk, 0, top);
Expand Down
7 changes: 4 additions & 3 deletions fs/partitions/check.c
Original file line number Diff line number Diff line change
Expand Up @@ -412,9 +412,10 @@ struct hd_struct *add_partition(struct gendisk *disk, int partno,
pdev = part_to_dev(p);

p->start_sect = start;
p->alignment_offset = queue_sector_alignment_offset(disk->queue, start);
p->discard_alignment = queue_sector_discard_alignment(disk->queue,
start);
p->alignment_offset =
queue_limit_alignment_offset(&disk->queue->limits, start);
p->discard_alignment =
queue_limit_discard_alignment(&disk->queue->limits, start);
p->nr_sects = len;
p->partno = partno;
p->policy = get_disk_ro(disk);
Expand Down
17 changes: 5 additions & 12 deletions include/linux/blkdev.h
Original file line number Diff line number Diff line change
Expand Up @@ -1112,18 +1112,13 @@ static inline int queue_alignment_offset(struct request_queue *q)
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 alignment = (sector << 9) & (granularity - 1);

offset &= granularity - 1;
return (granularity + lim->alignment_offset - offset) & (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);
return (granularity + lim->alignment_offset - alignment)
& (granularity - 1);
}

static inline int bdev_alignment_offset(struct block_device *bdev)
Expand All @@ -1147,10 +1142,8 @@ static inline int queue_discard_alignment(struct request_queue *q)
return q->limits.discard_alignment;
}

static inline int queue_sector_discard_alignment(struct request_queue *q,
sector_t sector)
static inline int queue_limit_discard_alignment(struct queue_limits *lim, sector_t sector)
{
struct queue_limits *lim = &q->limits;
unsigned int alignment = (sector << 9) & (lim->discard_granularity - 1);

return (lim->discard_granularity + lim->discard_alignment - alignment)
Expand Down

0 comments on commit e03a72e

Please sign in to comment.