]> www.infradead.org Git - users/hch/block.git/commitdiff
f2fs: return a f2fs_dev_info from f2fs_target_device
authorChristoph Hellwig <hch@lst.de>
Fri, 14 Jan 2022 08:32:40 +0000 (09:32 +0100)
committerChristoph Hellwig <hch@lst.de>
Wed, 9 Feb 2022 08:33:03 +0000 (09:33 +0100)
Change the calling conventions of f2fs_target_device to return the more
useful struture and prepare for refactoring the bio allocation.

Signed-off-by: Christoph Hellwig <hch@lst.de>
fs/f2fs/data.c
fs/f2fs/f2fs.h
fs/f2fs/file.c
fs/f2fs/segment.c

index e71dde8de0db097fd7fe480ab85803928080d677..dd8793adb61ffe97cbeb7ea4aa10e62a25af1fa0 100644 (file)
@@ -353,27 +353,20 @@ static void f2fs_write_end_io(struct bio *bio)
        bio_put(bio);
 }
 
-struct block_device *f2fs_target_device(struct f2fs_sb_info *sbi,
-                               block_t blk_addr, struct bio *bio)
+struct f2fs_dev_info *f2fs_target_device(struct f2fs_sb_info *sbi,
+               block_t blkaddr)
 {
-       struct block_device *bdev = sbi->sb->s_bdev;
        int i;
 
        if (f2fs_is_multi_device(sbi)) {
                for (i = 0; i < sbi->s_ndevs; i++) {
-                       if (FDEV(i).start_blk <= blk_addr &&
-                           FDEV(i).end_blk >= blk_addr) {
-                               blk_addr -= FDEV(i).start_blk;
-                               bdev = FDEV(i).bdev;
-                               break;
-                       }
+                       if (sbi->devs[i].start_blk <= blkaddr &&
+                           sbi->devs[i].end_blk >= blkaddr)
+                               return &sbi->devs[i];
                }
        }
-       if (bio) {
-               bio_set_dev(bio, bdev);
-               bio->bi_iter.bi_sector = SECTOR_FROM_BLOCK(blk_addr);
-       }
-       return bdev;
+
+       return &sbi->devs[0];
 }
 
 int f2fs_target_device_index(struct f2fs_sb_info *sbi, block_t blkaddr)
@@ -392,11 +385,14 @@ int f2fs_target_device_index(struct f2fs_sb_info *sbi, block_t blkaddr)
 static struct bio *__bio_alloc(struct f2fs_io_info *fio, int npages)
 {
        struct f2fs_sb_info *sbi = fio->sbi;
+       struct f2fs_dev_info *di = f2fs_target_device(sbi, fio->new_blkaddr);
        struct bio *bio;
 
-       bio = bio_alloc_bioset(NULL, npages, 0, GFP_NOIO, &f2fs_bioset);
+       bio = bio_alloc_bioset(di->bdev, npages, 0, GFP_NOIO, &f2fs_bioset);
+
+       bio->bi_iter.bi_sector =
+               SECTOR_FROM_BLOCK(fio->new_blkaddr - di->start_blk);
 
-       f2fs_target_device(sbi, fio->new_blkaddr, bio);
        if (is_read_io(fio->op)) {
                bio->bi_end_io = f2fs_read_end_io;
                bio->bi_private = NULL;
@@ -697,7 +693,7 @@ static bool page_is_mergeable(struct f2fs_sb_info *sbi, struct bio *bio,
                return false;
        if (last_blkaddr + 1 != cur_blkaddr)
                return false;
-       return bio->bi_bdev == f2fs_target_device(sbi, cur_blkaddr, NULL);
+       return bio->bi_bdev == f2fs_target_device(sbi, cur_blkaddr)->bdev;
 }
 
 static bool io_type_is_mergeable(struct f2fs_bio_info *io,
@@ -981,18 +977,19 @@ static struct bio *f2fs_grab_read_bio(struct inode *inode, block_t blkaddr,
                                      pgoff_t first_idx, bool for_write)
 {
        struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
+       struct f2fs_dev_info *di = f2fs_target_device(sbi, blkaddr);
        struct bio *bio;
        struct bio_post_read_ctx *ctx = NULL;
        unsigned int post_read_steps = 0;
 
-       bio = bio_alloc_bioset(NULL, bio_max_segs(nr_pages), REQ_OP_READ,
+       bio = bio_alloc_bioset(di->bdev, bio_max_segs(nr_pages), REQ_OP_READ,
                               for_write ? GFP_NOIO : GFP_KERNEL, &f2fs_bioset);
        if (!bio)
                return ERR_PTR(-ENOMEM);
 
        f2fs_set_bio_crypt_ctx(bio, inode, first_idx, NULL, GFP_NOFS);
 
-       f2fs_target_device(sbi, blkaddr, bio);
+       bio->bi_iter.bi_sector = SECTOR_FROM_BLOCK(blkaddr - di->start_blk);
        bio->bi_end_io = f2fs_read_end_io;
 
        if (fscrypt_inode_uses_fs_layer_crypto(inode))
@@ -1412,7 +1409,7 @@ int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map,
        struct extent_info ei = {0, };
        block_t blkaddr;
        unsigned int start_pgofs;
-       int bidx = 0;
+       struct f2fs_dev_info *di = NULL;
 
        if (!maxblocks)
                return 0;
@@ -1447,12 +1444,11 @@ int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map,
                if (map->m_multidev_dio) {
                        block_t blk_addr = map->m_pblk;
 
-                       bidx = f2fs_target_device_index(sbi, map->m_pblk);
-
-                       map->m_bdev = FDEV(bidx).bdev;
-                       map->m_pblk -= FDEV(bidx).start_blk;
-                       map->m_len = min(map->m_len,
-                               FDEV(bidx).end_blk + 1 - map->m_pblk);
+                       di = f2fs_target_device(sbi, blk_addr);
+                       map->m_bdev = di->bdev;
+                       map->m_pblk -= di->start_blk;
+                       map->m_len =
+                               min(map->m_len, di->end_blk + 1 - map->m_pblk);
 
                        if (map->m_may_create)
                                f2fs_update_device_state(sbi, inode->i_ino,
@@ -1580,7 +1576,7 @@ next_block:
                goto skip;
 
        if (map->m_multidev_dio)
-               bidx = f2fs_target_device_index(sbi, blkaddr);
+               di = f2fs_target_device(sbi, blkaddr);
 
        if (map->m_len == 0) {
                /* preallocated unwritten block should be mapped for fiemap. */
@@ -1592,12 +1588,12 @@ next_block:
                map->m_len = 1;
 
                if (map->m_multidev_dio)
-                       map->m_bdev = FDEV(bidx).bdev;
+                       map->m_bdev = di->bdev;
        } else if ((map->m_pblk != NEW_ADDR &&
                        blkaddr == (map->m_pblk + ofs)) ||
                        (map->m_pblk == NEW_ADDR && blkaddr == NEW_ADDR) ||
                        flag == F2FS_GET_BLOCK_PRE_DIO) {
-               if (map->m_multidev_dio && map->m_bdev != FDEV(bidx).bdev)
+               if (map->m_multidev_dio && map->m_bdev != di->bdev)
                        goto sync_out;
                ofs++;
                map->m_len++;
@@ -1664,17 +1660,17 @@ sync_out:
                if (map->m_multidev_dio) {
                        block_t blk_addr = map->m_pblk;
 
-                       bidx = f2fs_target_device_index(sbi, map->m_pblk);
+                       di = f2fs_target_device(sbi, map->m_pblk);
 
-                       map->m_bdev = FDEV(bidx).bdev;
-                       map->m_pblk -= FDEV(bidx).start_blk;
+                       map->m_bdev = di->bdev;
+                       map->m_pblk -= di->start_blk;
 
                        if (map->m_may_create)
                                f2fs_update_device_state(sbi, inode->i_ino,
                                                        blk_addr, map->m_len);
 
                        f2fs_bug_on(sbi, blk_addr + map->m_len >
-                                               FDEV(bidx).end_blk + 1);
+                                               di->end_blk + 1);
                }
        }
 
index eb22fa91c2b26694aab5a602d3e245db04fe2219..785d85dbc96938f2616f09892e390a04508629f6 100644 (file)
@@ -3630,8 +3630,8 @@ void f2fs_flush_merged_writes(struct f2fs_sb_info *sbi);
 int f2fs_submit_page_bio(struct f2fs_io_info *fio);
 int f2fs_merge_page_bio(struct f2fs_io_info *fio);
 void f2fs_submit_page_write(struct f2fs_io_info *fio);
-struct block_device *f2fs_target_device(struct f2fs_sb_info *sbi,
-                       block_t blk_addr, struct bio *bio);
+struct f2fs_dev_info *f2fs_target_device(struct f2fs_sb_info *sbi,
+               block_t blkaddr);
 int f2fs_target_device_index(struct f2fs_sb_info *sbi, block_t blkaddr);
 void f2fs_set_data_blkaddr(struct dnode_of_data *dn);
 void f2fs_update_data_blkaddr(struct dnode_of_data *dn, block_t blkaddr);
@@ -4258,12 +4258,10 @@ static inline bool f2fs_may_extent_tree(struct inode *inode)
 }
 
 #ifdef CONFIG_BLK_DEV_ZONED
-static inline bool f2fs_blkz_is_seq(struct f2fs_sb_info *sbi, int devi,
-                                   block_t blkaddr)
+static inline bool f2fs_blkz_is_seq(struct f2fs_sb_info *sbi,
+               struct f2fs_dev_info *di, block_t blkaddr)
 {
-       unsigned int zno = blkaddr >> sbi->log_blocks_per_blkz;
-
-       return test_bit(zno, FDEV(devi).blkz_seq);
+       return test_bit(blkaddr >> sbi->log_blocks_per_blkz, di->blkz_seq);
 }
 #endif
 
index 3c98ef6af97d139db476e060afb35514d8e18d58..5392b5714f9ebd5ca91ff5f4fb9e83b6a8fe3273 100644 (file)
@@ -3812,11 +3812,12 @@ static int f2fs_sec_trim_file(struct file *filp, unsigned long arg)
                                goto out;
                        }
 
-                       cur_bdev = f2fs_target_device(sbi, blkaddr, NULL);
+                       cur_bdev = f2fs_target_device(sbi, blkaddr)->bdev;
                        if (f2fs_is_multi_device(sbi)) {
-                               int di = f2fs_target_device_index(sbi, blkaddr);
+                               struct f2fs_dev_info *di =
+                                       f2fs_target_device(sbi, blkaddr);
 
-                               blkaddr -= FDEV(di).start_blk;
+                               blkaddr -= di->start_blk;
                        }
 
                        if (len) {
index 1dabc8244083d84d1337f34597bdd918e7805b03..339f618f59eb05894999c2f63e7ff043499af771 100644 (file)
@@ -1469,11 +1469,8 @@ static int __queue_discard_cmd(struct f2fs_sb_info *sbi,
 
        trace_f2fs_queue_discard(bdev, blkstart, blklen);
 
-       if (f2fs_is_multi_device(sbi)) {
-               int devi = f2fs_target_device_index(sbi, blkstart);
-
-               blkstart -= FDEV(devi).start_blk;
-       }
+       if (f2fs_is_multi_device(sbi))
+               blkstart -= f2fs_target_device(sbi, blkstart)->start_blk;
        mutex_lock(&SM_I(sbi)->dcc_info->cmd_lock);
        __update_discard_tree_range(sbi, bdev, lblkstart, blkstart, blklen);
        mutex_unlock(&SM_I(sbi)->dcc_info->cmd_lock);
@@ -1848,27 +1845,21 @@ static int __f2fs_issue_discard_zone(struct f2fs_sb_info *sbi,
 {
        sector_t sector, nr_sects;
        block_t lblkstart = blkstart;
-       int devi = 0;
+       struct f2fs_dev_info *di = f2fs_target_device(sbi, blkstart);
 
-       if (f2fs_is_multi_device(sbi)) {
-               devi = f2fs_target_device_index(sbi, blkstart);
-               if (blkstart < FDEV(devi).start_blk ||
-                   blkstart > FDEV(devi).end_blk) {
-                       f2fs_err(sbi, "Invalid block %x", blkstart);
-                       return -EIO;
-               }
-               blkstart -= FDEV(devi).start_blk;
-       }
+       if (f2fs_is_multi_device(sbi))
+               blkstart -= di->start_blk;
 
        /* For sequential zones, reset the zone write pointer */
-       if (f2fs_blkz_is_seq(sbi, devi, blkstart)) {
+       if (f2fs_blkz_is_seq(sbi, di, blkstart)) {
                sector = SECTOR_FROM_BLOCK(blkstart);
                nr_sects = SECTOR_FROM_BLOCK(blklen);
 
                if (sector & (bdev_zone_sectors(bdev) - 1) ||
                                nr_sects != bdev_zone_sectors(bdev)) {
                        f2fs_err(sbi, "(%d) %s: Unaligned zone reset attempted (block %x + %x)",
-                                devi, sbi->s_ndevs ? FDEV(devi).path : "",
+                                f2fs_target_device_index(sbi, blkstart),
+                                sbi->s_ndevs ? di->path : "",
                                 blkstart, blklen);
                        return -EIO;
                }
@@ -1902,12 +1893,12 @@ static int f2fs_issue_discard(struct f2fs_sb_info *sbi,
        block_t i;
        int err = 0;
 
-       bdev = f2fs_target_device(sbi, blkstart, NULL);
+       bdev = f2fs_target_device(sbi, blkstart)->bdev;
 
        for (i = blkstart; i < blkstart + blklen; i++, len++) {
                if (i != start) {
                        struct block_device *bdev2 =
-                               f2fs_target_device(sbi, i, NULL);
+                               f2fs_target_device(sbi, i)->bdev;
 
                        if (bdev2 != bdev) {
                                err = __issue_discard_async(sbi, bdev,