btrfs: handle recording of zoned writes in the storage layer
[linux-block.git] / fs / btrfs / zoned.c
index 1f503e8e42d483a765b71b9b5910fce0ede0ea6f..5bf67c3c9f846f859472c1625cd451df4289c40c 100644 (file)
@@ -17,6 +17,7 @@
 #include "space-info.h"
 #include "fs.h"
 #include "accessors.h"
+#include "bio.h"
 
 /* Maximum number of zones to report per blkdev_report_zones() call */
 #define BTRFS_REPORT_NR_ZONES   4096
@@ -160,7 +161,7 @@ static int sb_write_pointer(struct block_device *bdev, struct blk_zone *zones,
  */
 static inline u32 sb_zone_number(int shift, int mirror)
 {
-       u64 zone;
+       u64 zone = U64_MAX;
 
        ASSERT(mirror < BTRFS_SUPER_MIRROR_MAX);
        switch (mirror) {
@@ -220,7 +221,6 @@ static int btrfs_get_dev_zones(struct btrfs_device *device, u64 pos,
                               struct blk_zone *zones, unsigned int *nr_zones)
 {
        struct btrfs_zoned_device_info *zinfo = device->zone_info;
-       u32 zno;
        int ret;
 
        if (!*nr_zones)
@@ -235,6 +235,7 @@ static int btrfs_get_dev_zones(struct btrfs_device *device, u64 pos,
        /* Check cache */
        if (zinfo->zone_cache) {
                unsigned int i;
+               u32 zno;
 
                ASSERT(IS_ALIGNED(pos, zinfo->zone_size));
                zno = pos >> zinfo->zone_size_shift;
@@ -274,9 +275,12 @@ static int btrfs_get_dev_zones(struct btrfs_device *device, u64 pos,
                return -EIO;
 
        /* Populate cache */
-       if (zinfo->zone_cache)
+       if (zinfo->zone_cache) {
+               u32 zno = pos >> zinfo->zone_size_shift;
+
                memcpy(zinfo->zone_cache + zno, zones,
                       sizeof(*zinfo->zone_cache) * *nr_zones);
+       }
 
        return 0;
 }
@@ -1657,21 +1661,17 @@ bool btrfs_use_zone_append(struct btrfs_inode *inode, u64 start)
        return ret;
 }
 
-void btrfs_record_physical_zoned(struct inode *inode, u64 file_offset,
-                                struct bio *bio)
+void btrfs_record_physical_zoned(struct btrfs_bio *bbio)
 {
+       const u64 physical = bbio->bio.bi_iter.bi_sector << SECTOR_SHIFT;
        struct btrfs_ordered_extent *ordered;
-       const u64 physical = bio->bi_iter.bi_sector << SECTOR_SHIFT;
-
-       if (bio_op(bio) != REQ_OP_ZONE_APPEND)
-               return;
 
-       ordered = btrfs_lookup_ordered_extent(BTRFS_I(inode), file_offset);
+       ordered = btrfs_lookup_ordered_extent(bbio->inode, bbio->file_offset);
        if (WARN_ON(!ordered))
                return;
 
        ordered->physical = physical;
-       ordered->bdev = bio->bi_bdev;
+       ordered->bdev = bbio->bio.bi_bdev;
 
        btrfs_put_ordered_extent(ordered);
 }