null_blk: return fixed zoned reads > write pointer
authorAjay Joshi <ajay.joshi@wdc.com>
Thu, 17 Oct 2019 21:19:43 +0000 (14:19 -0700)
committerJens Axboe <axboe@kernel.dk>
Fri, 18 Oct 2019 01:01:22 +0000 (19:01 -0600)
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>
drivers/block/null_blk.h
drivers/block/null_blk_main.c
drivers/block/null_blk_zoned.c

index a235c45e22a70c7bb046bb1d897b74adba595727..93c2a3d403da94d534df8b5c5e186d804ac0fec5 100644 (file)
@@ -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 */
index f5e0dffb4624a06065e6ede6ef93c64f37060ac2..ea7a4d6b78487f4f4471e774d016e94d2faea0ae 100644 (file)
@@ -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);
index eabc116832a7ea47f22d4634926b521ce7206002..e020f17dac9f67414978fa1f6b91811fc3715cfd 100644 (file)
@@ -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)) {