mirror of
https://github.com/torvalds/linux.git
synced 2024-11-28 07:01:32 +00:00
null_blk: return fixed zoned reads > write pointer
A zoned block device maintains a write pointer within a zone, and reads beyond the write pointer are undefined. Fill data buffer returned above the write pointer with 0xFF. Signed-off-by: Ajay Joshi <ajay.joshi@wdc.com> Reviewed-by: Damien Le Moal <damien.lemoal@wdc.com> Reviewed-by: Matias Bjørling <matias.bjorling@wdc.com> Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
This commit is contained in:
parent
45919fbfe1
commit
dd85b4922d
@ -96,6 +96,8 @@ int null_zone_report(struct gendisk *disk, sector_t sector,
|
||||
blk_status_t null_handle_zoned(struct nullb_cmd *cmd,
|
||||
enum req_opf op, sector_t sector,
|
||||
sector_t nr_sectors);
|
||||
size_t null_zone_valid_read_len(struct nullb *nullb,
|
||||
sector_t sector, unsigned int len);
|
||||
#else
|
||||
static inline int null_zone_init(struct nullb_device *dev)
|
||||
{
|
||||
@ -115,5 +117,11 @@ static inline blk_status_t null_handle_zoned(struct nullb_cmd *cmd,
|
||||
{
|
||||
return BLK_STS_NOTSUPP;
|
||||
}
|
||||
static inline size_t null_zone_valid_read_len(struct nullb *nullb,
|
||||
sector_t sector,
|
||||
unsigned int len)
|
||||
{
|
||||
return len;
|
||||
}
|
||||
#endif /* CONFIG_BLK_DEV_ZONED */
|
||||
#endif /* __NULL_BLK_H */
|
||||
|
@ -1022,6 +1022,16 @@ next:
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void nullb_fill_pattern(struct nullb *nullb, struct page *page,
|
||||
unsigned int len, unsigned int off)
|
||||
{
|
||||
void *dst;
|
||||
|
||||
dst = kmap_atomic(page);
|
||||
memset(dst + off, 0xFF, len);
|
||||
kunmap_atomic(dst);
|
||||
}
|
||||
|
||||
static void null_handle_discard(struct nullb *nullb, sector_t sector, size_t n)
|
||||
{
|
||||
size_t temp;
|
||||
@ -1062,10 +1072,24 @@ static int null_transfer(struct nullb *nullb, struct page *page,
|
||||
unsigned int len, unsigned int off, bool is_write, sector_t sector,
|
||||
bool is_fua)
|
||||
{
|
||||
struct nullb_device *dev = nullb->dev;
|
||||
unsigned int valid_len = len;
|
||||
int err = 0;
|
||||
|
||||
if (!is_write) {
|
||||
err = copy_from_nullb(nullb, page, off, sector, len);
|
||||
if (dev->zoned)
|
||||
valid_len = null_zone_valid_read_len(nullb,
|
||||
sector, len);
|
||||
|
||||
if (valid_len) {
|
||||
err = copy_from_nullb(nullb, page, off,
|
||||
sector, valid_len);
|
||||
off += valid_len;
|
||||
len -= valid_len;
|
||||
}
|
||||
|
||||
if (len)
|
||||
nullb_fill_pattern(nullb, page, len, off);
|
||||
flush_dcache_page(page);
|
||||
} else {
|
||||
flush_dcache_page(page);
|
||||
|
@ -84,6 +84,24 @@ int null_zone_report(struct gendisk *disk, sector_t sector,
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t null_zone_valid_read_len(struct nullb *nullb,
|
||||
sector_t sector, unsigned int len)
|
||||
{
|
||||
struct nullb_device *dev = nullb->dev;
|
||||
struct blk_zone *zone = &dev->zones[null_zone_no(dev, sector)];
|
||||
unsigned int nr_sectors = len >> SECTOR_SHIFT;
|
||||
|
||||
/* Read must be below the write pointer position */
|
||||
if (zone->type == BLK_ZONE_TYPE_CONVENTIONAL ||
|
||||
sector + nr_sectors <= zone->wp)
|
||||
return len;
|
||||
|
||||
if (sector > zone->wp)
|
||||
return 0;
|
||||
|
||||
return (zone->wp - sector) << SECTOR_SHIFT;
|
||||
}
|
||||
|
||||
static blk_status_t null_zone_write(struct nullb_cmd *cmd, sector_t sector,
|
||||
unsigned int nr_sectors)
|
||||
{
|
||||
@ -121,8 +139,7 @@ static blk_status_t null_zone_write(struct nullb_cmd *cmd, sector_t sector,
|
||||
static blk_status_t null_zone_reset(struct nullb_cmd *cmd, sector_t sector)
|
||||
{
|
||||
struct nullb_device *dev = cmd->nq->dev;
|
||||
unsigned int zno = null_zone_no(dev, sector);
|
||||
struct blk_zone *zone = &dev->zones[zno];
|
||||
struct blk_zone *zone = &dev->zones[null_zone_no(dev, sector)];
|
||||
size_t i;
|
||||
|
||||
switch (req_op(cmd->rq)) {
|
||||
|
Loading…
Reference in New Issue
Block a user