mirror of
https://github.com/torvalds/linux.git
synced 2026-11-07 06:17:02 +01:00
f2fs: parameterize sector conversion macros
Sector-to-block and block-to-sector conversion helpers previously assumed a fixed sector count per block derived from 4KB pages. Parameterize F2FS_LOG_SECTORS_PER_BLOCK, SECTOR_FROM_BLOCK, and SECTOR_TO_BLOCK with struct f2fs_sb_info *sbi, using sbi->log_sectors_per_block. Update all call sites across metadata I/O, data mapping, discard operations, and zoned block device reporting. Signed-off-by: Kelvin Zhang <zhangxp1998@gmail.com> Reviewed-by: Chao Yu <chao@kernel.org> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
This commit is contained in:
parent
48747bfe30
commit
b32d4bdbae
|
|
@ -439,7 +439,7 @@ struct block_device *f2fs_target_device(struct f2fs_sb_info *sbi,
|
|||
}
|
||||
|
||||
if (sector)
|
||||
*sector = SECTOR_FROM_BLOCK(blk_addr);
|
||||
*sector = SECTOR_FROM_BLOCK(sbi, blk_addr);
|
||||
return bdev;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2610,7 +2610,8 @@ static inline int F2FS_HAS_BLOCKS(struct inode *inode)
|
|||
{
|
||||
block_t xattr_block = F2FS_I(inode)->i_xattr_nid ? 1 : 0;
|
||||
|
||||
return (inode->i_blocks >> F2FS_LOG_SECTORS_PER_BLOCK) > xattr_block;
|
||||
return (inode->i_blocks >>
|
||||
F2FS_LOG_SECTORS_PER_BLOCK(F2FS_I_SB(inode))) > xattr_block;
|
||||
}
|
||||
|
||||
static inline bool f2fs_has_xattr_block(unsigned int ofs)
|
||||
|
|
@ -2816,7 +2817,7 @@ static inline void dec_valid_block_count(struct f2fs_sb_info *sbi,
|
|||
struct inode *inode,
|
||||
block_t count)
|
||||
{
|
||||
blkcnt_t sectors = count << F2FS_LOG_SECTORS_PER_BLOCK;
|
||||
blkcnt_t sectors = count << F2FS_LOG_SECTORS_PER_BLOCK(sbi);
|
||||
|
||||
spin_lock(&sbi->stat_lock);
|
||||
if (unlikely(sbi->total_valid_block_count < count)) {
|
||||
|
|
|
|||
|
|
@ -4507,8 +4507,8 @@ static int f2fs_reserve_compress_blocks(struct file *filp, unsigned long arg)
|
|||
static int f2fs_secure_erase(struct block_device *bdev, struct inode *inode,
|
||||
pgoff_t off, block_t block, block_t len, u32 flags)
|
||||
{
|
||||
sector_t sector = SECTOR_FROM_BLOCK(block);
|
||||
sector_t nr_sects = SECTOR_FROM_BLOCK(len);
|
||||
sector_t sector = SECTOR_FROM_BLOCK(F2FS_I_SB(inode), block);
|
||||
sector_t nr_sects = SECTOR_FROM_BLOCK(F2FS_I_SB(inode), len);
|
||||
int ret = 0;
|
||||
|
||||
if (flags & F2FS_TRIM_FILE_DISCARD) {
|
||||
|
|
|
|||
|
|
@ -221,11 +221,11 @@ static bool sanity_check_compress_inode(struct inode *inode,
|
|||
return false;
|
||||
}
|
||||
if (le64_to_cpu(ri->i_compr_blocks) >
|
||||
SECTOR_TO_BLOCK(inode->i_blocks)) {
|
||||
SECTOR_TO_BLOCK(sbi, inode->i_blocks)) {
|
||||
f2fs_warn(sbi,
|
||||
"%s: inode (ino=%llx) has inconsistent i_compr_blocks:%llu, i_blocks:%llu, run fsck to fix",
|
||||
__func__, inode->i_ino, le64_to_cpu(ri->i_compr_blocks),
|
||||
SECTOR_TO_BLOCK(inode->i_blocks));
|
||||
SECTOR_TO_BLOCK(sbi, inode->i_blocks));
|
||||
return false;
|
||||
}
|
||||
if (ri->i_log_cluster_size < MIN_COMPRESS_LOG_SIZE ||
|
||||
|
|
@ -447,7 +447,8 @@ static int do_read_inode(struct inode *inode)
|
|||
i_gid_write(inode, le32_to_cpu(ri->i_gid));
|
||||
set_nlink(inode, le32_to_cpu(ri->i_links));
|
||||
inode->i_size = le64_to_cpu(ri->i_size);
|
||||
inode->i_blocks = SECTOR_FROM_BLOCK(le64_to_cpu(ri->i_blocks) - 1);
|
||||
inode->i_blocks = SECTOR_FROM_BLOCK(sbi,
|
||||
le64_to_cpu(ri->i_blocks) - 1);
|
||||
|
||||
inode_set_atime(inode, le64_to_cpu(ri->i_atime),
|
||||
le32_to_cpu(ri->i_atime_nsec));
|
||||
|
|
@ -696,6 +697,7 @@ struct inode *f2fs_iget_retry(struct super_block *sb, unsigned long ino)
|
|||
|
||||
void f2fs_update_inode(struct inode *inode, struct folio *node_folio)
|
||||
{
|
||||
struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
|
||||
struct f2fs_inode_info *fi = F2FS_I(inode);
|
||||
struct f2fs_inode *ri;
|
||||
struct extent_tree *et = fi->extent_tree[EX_READ];
|
||||
|
|
@ -712,7 +714,8 @@ void f2fs_update_inode(struct inode *inode, struct folio *node_folio)
|
|||
ri->i_uid = cpu_to_le32(i_uid_read(inode));
|
||||
ri->i_gid = cpu_to_le32(i_gid_read(inode));
|
||||
ri->i_links = cpu_to_le32(inode->i_nlink);
|
||||
ri->i_blocks = cpu_to_le64(SECTOR_TO_BLOCK(READ_ONCE(inode->i_blocks)) + 1);
|
||||
ri->i_blocks = cpu_to_le64(SECTOR_TO_BLOCK(sbi,
|
||||
READ_ONCE(inode->i_blocks)) + 1);
|
||||
|
||||
if (!f2fs_is_atomic_file(inode) ||
|
||||
is_inode_flag_set(inode, FI_ATOMIC_COMMITTED))
|
||||
|
|
|
|||
|
|
@ -1310,7 +1310,7 @@ static void __submit_zone_reset_cmd(struct f2fs_sb_info *sbi,
|
|||
/* sanity check on discard range */
|
||||
__check_sit_bitmap(sbi, dc->di.lstart, dc->di.lstart + dc->di.len);
|
||||
|
||||
bio->bi_iter.bi_sector = SECTOR_FROM_BLOCK(dc->di.start);
|
||||
bio->bi_iter.bi_sector = SECTOR_FROM_BLOCK(sbi, dc->di.start);
|
||||
bio->bi_private = dc;
|
||||
bio->bi_end_io = f2fs_submit_discard_endio;
|
||||
submit_bio(bio);
|
||||
|
|
@ -1327,7 +1327,7 @@ static int __submit_discard_cmd(struct f2fs_sb_info *sbi,
|
|||
{
|
||||
struct block_device *bdev = dc->bdev;
|
||||
unsigned int max_discard_blocks =
|
||||
SECTOR_TO_BLOCK(bdev_max_discard_sectors(bdev));
|
||||
SECTOR_TO_BLOCK(sbi, bdev_max_discard_sectors(bdev));
|
||||
struct discard_cmd_control *dcc = SM_I(sbi)->dcc_info;
|
||||
struct list_head *wait_list = (dpolicy->type == DPOLICY_FSTRIM) ?
|
||||
&(dcc->fstrim_list) : &(dcc->wait_list);
|
||||
|
|
@ -1389,8 +1389,8 @@ static int __submit_discard_cmd(struct f2fs_sb_info *sbi,
|
|||
|
||||
dc->di.len += len;
|
||||
|
||||
__blkdev_issue_discard(bdev, SECTOR_FROM_BLOCK(start),
|
||||
SECTOR_FROM_BLOCK(len), GFP_NOFS, &bio);
|
||||
__blkdev_issue_discard(bdev, SECTOR_FROM_BLOCK(sbi, start),
|
||||
SECTOR_FROM_BLOCK(sbi, len), GFP_NOFS, &bio);
|
||||
f2fs_bug_on(sbi, !bio);
|
||||
|
||||
/*
|
||||
|
|
@ -1518,7 +1518,7 @@ static void __update_discard_tree_range(struct f2fs_sb_info *sbi,
|
|||
struct discard_info di = {0};
|
||||
struct rb_node **insert_p = NULL, *insert_parent = NULL;
|
||||
unsigned int max_discard_blocks =
|
||||
SECTOR_TO_BLOCK(bdev_max_discard_sectors(bdev));
|
||||
SECTOR_TO_BLOCK(sbi, bdev_max_discard_sectors(bdev));
|
||||
block_t end = lstart + len;
|
||||
|
||||
dc = __lookup_discard_cmd_ret(&dcc->root, lstart,
|
||||
|
|
@ -2095,8 +2095,8 @@ static int __f2fs_issue_discard_zone(struct f2fs_sb_info *sbi,
|
|||
|
||||
/* For sequential zones, reset the zone write pointer */
|
||||
if (f2fs_blkz_is_seq(sbi, devi, blkstart)) {
|
||||
sector = SECTOR_FROM_BLOCK(blkstart);
|
||||
nr_sects = SECTOR_FROM_BLOCK(blklen);
|
||||
sector = SECTOR_FROM_BLOCK(sbi, blkstart);
|
||||
nr_sects = SECTOR_FROM_BLOCK(sbi, blklen);
|
||||
div64_u64_rem(sector, bdev_zone_sectors(bdev), &remainder);
|
||||
|
||||
if (remainder || nr_sects != bdev_zone_sectors(bdev)) {
|
||||
|
|
|
|||
|
|
@ -114,10 +114,10 @@ f2fs_start_segno(struct f2fs_sb_info *sbi, unsigned int segno)
|
|||
#define f2fs_bitmap_size(nr) \
|
||||
(BITS_TO_LONGS(nr) * sizeof(unsigned long))
|
||||
|
||||
#define SECTOR_FROM_BLOCK(blk_addr) \
|
||||
(((sector_t)blk_addr) << F2FS_LOG_SECTORS_PER_BLOCK)
|
||||
#define SECTOR_TO_BLOCK(sectors) \
|
||||
((sectors) >> F2FS_LOG_SECTORS_PER_BLOCK)
|
||||
#define SECTOR_FROM_BLOCK(sbi, blk_addr) \
|
||||
(((sector_t)blk_addr) << F2FS_LOG_SECTORS_PER_BLOCK(sbi))
|
||||
#define SECTOR_TO_BLOCK(sbi, sectors) \
|
||||
((sectors) >> F2FS_LOG_SECTORS_PER_BLOCK(sbi))
|
||||
|
||||
/*
|
||||
* In the victim_sel_policy->alloc_mode, there are three block allocation modes.
|
||||
|
|
|
|||
|
|
@ -3944,7 +3944,7 @@ static int __f2fs_commit_super(struct f2fs_sb_info *sbi, struct folio *folio,
|
|||
bio = bio_alloc(sbi->sb->s_bdev, 1, opf, GFP_NOFS);
|
||||
|
||||
/* it doesn't need to set crypto context for superblock update */
|
||||
bio->bi_iter.bi_sector = SECTOR_FROM_BLOCK(folio->index);
|
||||
bio->bi_iter.bi_sector = SECTOR_FROM_BLOCK(sbi, folio->index);
|
||||
|
||||
if (!bio_add_folio(bio, folio, folio_size(folio), 0))
|
||||
f2fs_bug_on(sbi, 1);
|
||||
|
|
@ -4519,7 +4519,7 @@ static int f2fs_report_zone_cb(struct blk_zone *zone, unsigned int idx,
|
|||
{
|
||||
struct f2fs_report_zones_args *rz_args = data;
|
||||
block_t unusable_blocks = (zone->len - zone->capacity) >>
|
||||
F2FS_LOG_SECTORS_PER_BLOCK;
|
||||
F2FS_LOG_SECTORS_PER_BLOCK(rz_args->sbi);
|
||||
|
||||
if (zone->type == BLK_ZONE_TYPE_CONVENTIONAL)
|
||||
return 0;
|
||||
|
|
@ -4562,10 +4562,10 @@ static int init_blkz_info(struct f2fs_sb_info *sbi, int devi)
|
|||
|
||||
zone_sectors = bdev_zone_sectors(bdev);
|
||||
if (sbi->blocks_per_blkz && sbi->blocks_per_blkz !=
|
||||
SECTOR_TO_BLOCK(zone_sectors))
|
||||
SECTOR_TO_BLOCK(sbi, zone_sectors))
|
||||
return -EINVAL;
|
||||
sbi->blocks_per_blkz = SECTOR_TO_BLOCK(zone_sectors);
|
||||
FDEV(devi).nr_blkz = div_u64(SECTOR_TO_BLOCK(nr_sectors),
|
||||
sbi->blocks_per_blkz = SECTOR_TO_BLOCK(sbi, zone_sectors);
|
||||
FDEV(devi).nr_blkz = div_u64(SECTOR_TO_BLOCK(sbi, nr_sectors),
|
||||
sbi->blocks_per_blkz);
|
||||
if (nr_sectors & (zone_sectors - 1))
|
||||
FDEV(devi).nr_blkz++;
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@
|
|||
#define F2FS_SUPER_OFFSET 1024 /* byte-size offset */
|
||||
#define F2FS_MIN_LOG_SECTOR_SIZE 9 /* 9 bits for 512 bytes */
|
||||
#define F2FS_MAX_LOG_SECTOR_SIZE PAGE_SHIFT /* Max is Block Size */
|
||||
#define F2FS_LOG_SECTORS_PER_BLOCK (PAGE_SHIFT - 9) /* log number for sector/blk */
|
||||
#define F2FS_LOG_SECTORS_PER_BLOCK(sbi) ((sbi)->log_blocksize - 9) /* log number for sector/blk */
|
||||
#define F2FS_MIN_LOG_BLOCKSIZE 12
|
||||
#define F2FS_MIN_BLKSIZE 4096UL
|
||||
#define F2FS_BLKSIZE PAGE_SIZE /* support only block == page */
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user