> @@ -57,7 +59,7 @@ static struct folio *brd_lookup_folio(struct brd_device *brd, sector_t sector) > { > pgoff_t idx; > struct folio *folio; > - unsigned int rd_sector_shift = brd->brd_sector_shift - SECTOR_SHIFT; > + unsigned int rd_sector_shift = brd->brd_sector_shift - brd->brd_logical_sector_shift; Could we create a simple macro instead of repeating this everywhere? #define RD_SECTOR_SHIFT(brd) (brd->brd_sector_shift - brd->brd_logical_sector_shift) > > /* > * The folio lifetime is protected by the fact that we have opened the > bio_io_error(bio); > return; > } > - sector += len >> SECTOR_SHIFT; > + sector += len >> brd->brd_logical_sector_shift; > } > > bio_endio(bio); > @@ -353,6 +355,10 @@ static unsigned int rd_blksize = PAGE_SIZE; > module_param(rd_blksize, uint, 0444); > MODULE_PARM_DESC(rd_blksize, "Blocksize of each RAM disk in bytes."); > > +static unsigned int rd_logical_blksize = SECTOR_SIZE; > +module_param(rd_logical_blksize, uint, 0444); > +MODULE_PARM_DESC(rd_logical_blksize, "Logical blocksize of each RAM disk in bytes."); > + > MODULE_LICENSE("GPL"); > MODULE_ALIAS_BLOCKDEV_MAJOR(RAMDISK_MAJOR); > MODULE_ALIAS("rd"); > @@ -391,6 +397,8 @@ static int brd_alloc(int i) > list_add_tail(&brd->brd_list, &brd_devices); > brd->brd_sector_shift = ilog2(rd_blksize); > brd->brd_sector_size = rd_blksize; > + brd->brd_logical_sector_shift = ilog2(rd_logical_blksize); > + brd->brd_logical_sector_size = rd_logical_blksize; We should a check here to see if logical block > rd_blksize similar to what is done in blk_queue_logical_block_size()? // physical block size should not be less than the logical block size if (rd_blksize < rd_logical_blksize) { brd->brd_logical_sector_shift = ilog2(rd_blksize); brd->brd_logical_sector_size = rd_blksize; } > > spin_lock_init(&brd->brd_lock); > INIT_RADIX_TREE(&brd->brd_folios, GFP_ATOMIC); > @@ -418,6 +426,7 @@ static int brd_alloc(int i) > goto out_cleanup_disk; > } > blk_queue_physical_block_size(disk->queue, rd_blksize); > + blk_queue_logical_block_size(disk->queue, rd_logical_blksize); > blk_queue_max_hw_sectors(disk->queue, RD_MAX_SECTOR_SIZE); > > /* Tell the block layer that this is not a rotational device */ > -- > 2.35.3 >