From nobody Sun Nov 24 05:26:42 2024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6884DDDA9 for ; Thu, 7 Nov 2024 01:46:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730943970; cv=none; b=XEAYHJsQeR6itOKxxlrTDgW/pSxlnBJQj2GGh5IP6aIGxD23w80b02wkGKp1tiXBbVVmcDA29sCR9fVs5M2n6kLdLLPmtWaeGRTXMx7ak/nhzgA3piYYQ2K3Oxhj0dBOxIuvUykxsfplgVnDxpcMa+xv9O8ExtbEpfIGgtCZl+k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730943970; c=relaxed/simple; bh=D0KhrNrHO6v+scc86PXOTZqKNDZ5GEGYNMenvyi8Iw0=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=aLTqHzL7RPPtGN/oC6XwBFGA3jImBtUM7F9QPvp2kOJPLZBcgHkO2AQWhZkeuipYnZFwQypJfX2ffMf7jrWWMBrIKuTa+5CwVaUVHV5HRXhWfrxtV36RWVWHrdXbRRtcGnJsr3Z3re54aQydttTeRyjrBWX48jq1fv03hHX5cx8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ejYC5MmE; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ejYC5MmE" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 941AAC4CEC6; Thu, 7 Nov 2024 01:46:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1730943970; bh=D0KhrNrHO6v+scc86PXOTZqKNDZ5GEGYNMenvyi8Iw0=; h=From:To:Cc:Subject:Date:From; b=ejYC5MmE7P97wL0XO3YDnvF8MNrFoVyr6uVJMfv0XqU2Fgyx9SfVmnLtepzAjDQid yrmoKgnDxU7NJ02CGZoaxeJQ5TOvag8g6BLdkrscRq7Ibb7WheDC2WSnSmIk7wGRdw bM7cFlrr1yv6xA3VzOcHgczDVUZjBlY84uZfEhiH3Y35whMV8v0L8emt9RDpmdVaGZ UQAahcdchHdbEsVDQkmE/hADP2hcd+qZ2cgiA4s4gwETqy7Ci4IGWFecS9FTyfBJ56 1CVRxUnGpH6hK+ZjHXYX1kMmpQ5oir0D69Cq76xjYyurXySrduKnALQH87uTfZ6yBa 71b3deJF8jg9w== From: Chao Yu To: jaegeuk@kernel.org Cc: linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, Chao Yu , Zhiguo Niu Subject: [PATCH] f2fs: clean up w/ F2FS_{BLK_TO_BYTES,BTYES_TO_BLK} Date: Thu, 7 Nov 2024 09:46:02 +0800 Message-Id: <20241107014602.3638020-1-chao@kernel.org> X-Mailer: git-send-email 2.40.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" f2fs doesn't support different blksize in one instance, so bytes_to_blks() and blks_to_bytes() are equal to F2FS_BYTES_TO_BLK and F2FS_BLK_TO_BYTES, let's use F2FS_BYTES_TO_BLK/F2FS_BLK_TO_BYTES instead for cleanup. Reported-by: Zhiguo Niu Signed-off-by: Chao Yu Reviewed-by: Zhiguo Niu --- fs/f2fs/data.c | 68 +++++++++++++++++++++----------------------------- 1 file changed, 29 insertions(+), 39 deletions(-) diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c index b33aca24b9ef..0e8390cbdb5b 100644 --- a/fs/f2fs/data.c +++ b/fs/f2fs/data.c @@ -1819,16 +1819,6 @@ bool f2fs_overwrite_io(struct inode *inode, loff_t p= os, size_t len) return true; } =20 -static inline u64 bytes_to_blks(struct inode *inode, u64 bytes) -{ - return (bytes >> inode->i_blkbits); -} - -static inline u64 blks_to_bytes(struct inode *inode, u64 blks) -{ - return (blks << inode->i_blkbits); -} - static int f2fs_xattr_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo) { @@ -1854,7 +1844,7 @@ static int f2fs_xattr_fiemap(struct inode *inode, return err; } =20 - phys =3D blks_to_bytes(inode, ni.blk_addr); + phys =3D F2FS_BLK_TO_BYTES(ni.blk_addr); offset =3D offsetof(struct f2fs_inode, i_addr) + sizeof(__le32) * (DEF_ADDRS_PER_INODE - get_inline_xattr_addrs(inode)); @@ -1886,7 +1876,7 @@ static int f2fs_xattr_fiemap(struct inode *inode, return err; } =20 - phys =3D blks_to_bytes(inode, ni.blk_addr); + phys =3D F2FS_BLK_TO_BYTES(ni.blk_addr); len =3D inode->i_sb->s_blocksize; =20 f2fs_put_page(page, 1); @@ -1948,16 +1938,16 @@ int f2fs_fiemap(struct inode *inode, struct fiemap_= extent_info *fieinfo, goto out; } =20 - if (bytes_to_blks(inode, len) =3D=3D 0) - len =3D blks_to_bytes(inode, 1); + if (F2FS_BYTES_TO_BLK(len) =3D=3D 0) + len =3D F2FS_BLKSIZE; =20 - start_blk =3D bytes_to_blks(inode, start); - last_blk =3D bytes_to_blks(inode, start + len - 1); + start_blk =3D F2FS_BYTES_TO_BLK(start); + last_blk =3D F2FS_BYTES_TO_BLK(start + len - 1); =20 next: memset(&map, 0, sizeof(map)); map.m_lblk =3D start_blk; - map.m_len =3D bytes_to_blks(inode, len); + map.m_len =3D F2FS_BYTES_TO_BLK(len); map.m_next_pgofs =3D &next_pgofs; map.m_seg_type =3D NO_CHECK_TYPE; =20 @@ -1974,7 +1964,7 @@ int f2fs_fiemap(struct inode *inode, struct fiemap_ex= tent_info *fieinfo, if (!compr_cluster && !(map.m_flags & F2FS_MAP_FLAGS)) { start_blk =3D next_pgofs; =20 - if (blks_to_bytes(inode, start_blk) < maxbytes) + if (F2FS_BLK_TO_BYTES(start_blk) < maxbytes) goto prep_next; =20 flags |=3D FIEMAP_EXTENT_LAST; @@ -2011,14 +2001,14 @@ int f2fs_fiemap(struct inode *inode, struct fiemap_= extent_info *fieinfo, } else if (compr_appended) { unsigned int appended_blks =3D cluster_size - count_in_cluster + 1; - size +=3D blks_to_bytes(inode, appended_blks); + size +=3D F2FS_BLK_TO_BYTES(appended_blks); start_blk +=3D appended_blks; compr_cluster =3D false; } else { - logical =3D blks_to_bytes(inode, start_blk); + logical =3D F2FS_BLK_TO_BYTES(start_blk); phys =3D __is_valid_data_blkaddr(map.m_pblk) ? - blks_to_bytes(inode, map.m_pblk) : 0; - size =3D blks_to_bytes(inode, map.m_len); + F2FS_BLK_TO_BYTES(map.m_pblk) : 0; + size =3D F2FS_BLK_TO_BYTES(map.m_len); flags =3D 0; =20 if (compr_cluster) { @@ -2026,13 +2016,13 @@ int f2fs_fiemap(struct inode *inode, struct fiemap_= extent_info *fieinfo, count_in_cluster +=3D map.m_len; if (count_in_cluster =3D=3D cluster_size) { compr_cluster =3D false; - size +=3D blks_to_bytes(inode, 1); + size +=3D F2FS_BLKSIZE; } } else if (map.m_flags & F2FS_MAP_DELALLOC) { flags =3D FIEMAP_EXTENT_UNWRITTEN; } =20 - start_blk +=3D bytes_to_blks(inode, size); + start_blk +=3D F2FS_BYTES_TO_BLK(size); } =20 prep_next: @@ -2070,7 +2060,7 @@ static int f2fs_read_single_page(struct inode *inode,= struct folio *folio, struct readahead_control *rac) { struct bio *bio =3D *bio_ret; - const unsigned blocksize =3D blks_to_bytes(inode, 1); + const unsigned int blocksize =3D F2FS_BLKSIZE; sector_t block_in_file; sector_t last_block; sector_t last_block_in_file; @@ -2080,8 +2070,8 @@ static int f2fs_read_single_page(struct inode *inode,= struct folio *folio, =20 block_in_file =3D (sector_t)index; last_block =3D block_in_file + nr_pages; - last_block_in_file =3D bytes_to_blks(inode, - f2fs_readpage_limit(inode) + blocksize - 1); + last_block_in_file =3D F2FS_BYTES_TO_BLK(f2fs_readpage_limit(inode) + + blocksize - 1); if (last_block > last_block_in_file) last_block =3D last_block_in_file; =20 @@ -2181,7 +2171,7 @@ int f2fs_read_multi_pages(struct compress_ctx *cc, st= ruct bio **bio_ret, struct bio *bio =3D *bio_ret; unsigned int start_idx =3D cc->cluster_idx << cc->log_cluster_size; sector_t last_block_in_file; - const unsigned blocksize =3D blks_to_bytes(inode, 1); + const unsigned int blocksize =3D F2FS_BLKSIZE; struct decompress_io_ctx *dic =3D NULL; struct extent_info ei =3D {}; bool from_dnode =3D true; @@ -2190,8 +2180,8 @@ int f2fs_read_multi_pages(struct compress_ctx *cc, st= ruct bio **bio_ret, =20 f2fs_bug_on(sbi, f2fs_cluster_is_empty(cc)); =20 - last_block_in_file =3D bytes_to_blks(inode, - f2fs_readpage_limit(inode) + blocksize - 1); + last_block_in_file =3D F2FS_BYTES_TO_BLK(f2fs_readpage_limit(inode) + + blocksize - 1); =20 /* get rid of pages beyond EOF */ for (i =3D 0; i < cc->cluster_size; i++) { @@ -3957,7 +3947,7 @@ static int check_swap_activate(struct swap_info_struc= t *sis, * to be very smart. */ cur_lblock =3D 0; - last_lblock =3D bytes_to_blks(inode, i_size_read(inode)); + last_lblock =3D F2FS_BYTES_TO_BLK(i_size_read(inode)); =20 while (cur_lblock < last_lblock && cur_lblock < sis->max) { struct f2fs_map_blocks map; @@ -4200,8 +4190,8 @@ static int f2fs_iomap_begin(struct inode *inode, loff= _t offset, loff_t length, pgoff_t next_pgofs =3D 0; int err; =20 - map.m_lblk =3D bytes_to_blks(inode, offset); - map.m_len =3D bytes_to_blks(inode, offset + length - 1) - map.m_lblk + 1; + map.m_lblk =3D F2FS_BYTES_TO_BLK(offset); + map.m_len =3D F2FS_BYTES_TO_BLK(offset + length - 1) - map.m_lblk + 1; map.m_next_pgofs =3D &next_pgofs; map.m_seg_type =3D f2fs_rw_hint_to_seg_type(F2FS_I_SB(inode), inode->i_write_hint); @@ -4212,7 +4202,7 @@ static int f2fs_iomap_begin(struct inode *inode, loff= _t offset, loff_t length, if (err) return err; =20 - iomap->offset =3D blks_to_bytes(inode, map.m_lblk); + iomap->offset =3D F2FS_BLK_TO_BYTES(map.m_lblk); =20 /* * When inline encryption is enabled, sometimes I/O to an encrypted file @@ -4232,21 +4222,21 @@ static int f2fs_iomap_begin(struct inode *inode, lo= ff_t offset, loff_t length, if (WARN_ON_ONCE(map.m_pblk =3D=3D NEW_ADDR)) return -EINVAL; =20 - iomap->length =3D blks_to_bytes(inode, map.m_len); + iomap->length =3D F2FS_BLK_TO_BYTES(map.m_len); iomap->type =3D IOMAP_MAPPED; iomap->flags |=3D IOMAP_F_MERGED; iomap->bdev =3D map.m_bdev; - iomap->addr =3D blks_to_bytes(inode, map.m_pblk); + iomap->addr =3D F2FS_BLK_TO_BYTES(map.m_pblk); } else { if (flags & IOMAP_WRITE) return -ENOTBLK; =20 if (map.m_pblk =3D=3D NULL_ADDR) { - iomap->length =3D blks_to_bytes(inode, next_pgofs) - - iomap->offset; + iomap->length =3D F2FS_BLK_TO_BYTES(next_pgofs) - + iomap->offset; iomap->type =3D IOMAP_HOLE; } else if (map.m_pblk =3D=3D NEW_ADDR) { - iomap->length =3D blks_to_bytes(inode, map.m_len); + iomap->length =3D F2FS_BLK_TO_BYTES(map.m_len); iomap->type =3D IOMAP_UNWRITTEN; } else { f2fs_bug_on(F2FS_I_SB(inode), 1); --=20 2.40.1