Skip to content

Commit c1373f1

Browse files
Christoph Hellwigaxboe
authored andcommitted
block: add a queue_limits_stack_bdev helper
Add a small wrapper around blk_stack_limits that allows passing a bdev for the bottom device and prints an error in case of misaligned device. The name fits into the new queue limits API and the intent is to eventually replace disk_stack_limits. Signed-off-by: Christoph Hellwig <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent 631d4ef commit c1373f1

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

block/blk-settings.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -891,6 +891,31 @@ int blk_stack_limits(struct queue_limits *t, struct queue_limits *b,
891891
}
892892
EXPORT_SYMBOL(blk_stack_limits);
893893

894+
/**
895+
* queue_limits_stack_bdev - adjust queue_limits for stacked devices
896+
* @t: the stacking driver limits (top device)
897+
* @bdev: the underlying block device (bottom)
898+
* @offset: offset to beginning of data within component device
899+
* @pfx: prefix to use for warnings logged
900+
*
901+
* Description:
902+
* This function is used by stacking drivers like MD and DM to ensure
903+
* that all component devices have compatible block sizes and
904+
* alignments. The stacking driver must provide a queue_limits
905+
* struct (top) and then iteratively call the stacking function for
906+
* all component (bottom) devices. The stacking function will
907+
* attempt to combine the values and ensure proper alignment.
908+
*/
909+
void queue_limits_stack_bdev(struct queue_limits *t, struct block_device *bdev,
910+
sector_t offset, const char *pfx)
911+
{
912+
if (blk_stack_limits(t, &bdev_get_queue(bdev)->limits,
913+
get_start_sect(bdev) + offset))
914+
pr_notice("%s: Warning: Device %pg is misaligned\n",
915+
pfx, bdev);
916+
}
917+
EXPORT_SYMBOL_GPL(queue_limits_stack_bdev);
918+
894919
/**
895920
* disk_stack_limits - adjust queue limits for stacked drivers
896921
* @disk: MD/DM gendisk (top)

include/linux/blkdev.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -924,6 +924,8 @@ extern void blk_set_queue_depth(struct request_queue *q, unsigned int depth);
924924
extern void blk_set_stacking_limits(struct queue_limits *lim);
925925
extern int blk_stack_limits(struct queue_limits *t, struct queue_limits *b,
926926
sector_t offset);
927+
void queue_limits_stack_bdev(struct queue_limits *t, struct block_device *bdev,
928+
sector_t offset, const char *pfx);
927929
extern void disk_stack_limits(struct gendisk *disk, struct block_device *bdev,
928930
sector_t offset);
929931
extern void blk_queue_update_dma_pad(struct request_queue *, unsigned int);

0 commit comments

Comments
 (0)