Commit f7ef9b83 authored by Jaegeuk Kim's avatar Jaegeuk Kim

f2fs: introduce macros to convert bytes and blocks in f2fs

This patch adds two macros for transition between byte and block offsets.
Currently, f2fs only supports 4KB blocks, so use the default size for now.
Signed-off-by: default avatarJaegeuk Kim <jaegeuk@kernel.org>
parent da17eece
...@@ -981,15 +981,14 @@ static void do_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc) ...@@ -981,15 +981,14 @@ static void do_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc)
/* write out checkpoint buffer at block 0 */ /* write out checkpoint buffer at block 0 */
cp_page = grab_meta_page(sbi, start_blk++); cp_page = grab_meta_page(sbi, start_blk++);
kaddr = page_address(cp_page); kaddr = page_address(cp_page);
memcpy(kaddr, ckpt, (1 << sbi->log_blocksize)); memcpy(kaddr, ckpt, F2FS_BLKSIZE);
set_page_dirty(cp_page); set_page_dirty(cp_page);
f2fs_put_page(cp_page, 1); f2fs_put_page(cp_page, 1);
for (i = 1; i < 1 + cp_payload_blks; i++) { for (i = 1; i < 1 + cp_payload_blks; i++) {
cp_page = grab_meta_page(sbi, start_blk++); cp_page = grab_meta_page(sbi, start_blk++);
kaddr = page_address(cp_page); kaddr = page_address(cp_page);
memcpy(kaddr, (char *)ckpt + i * F2FS_BLKSIZE, memcpy(kaddr, (char *)ckpt + i * F2FS_BLKSIZE, F2FS_BLKSIZE);
(1 << sbi->log_blocksize));
set_page_dirty(cp_page); set_page_dirty(cp_page);
f2fs_put_page(cp_page, 1); f2fs_put_page(cp_page, 1);
} }
...@@ -1009,7 +1008,7 @@ static void do_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc) ...@@ -1009,7 +1008,7 @@ static void do_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc)
/* writeout checkpoint block */ /* writeout checkpoint block */
cp_page = grab_meta_page(sbi, start_blk); cp_page = grab_meta_page(sbi, start_blk);
kaddr = page_address(cp_page); kaddr = page_address(cp_page);
memcpy(kaddr, ckpt, (1 << sbi->log_blocksize)); memcpy(kaddr, ckpt, F2FS_BLKSIZE);
set_page_dirty(cp_page); set_page_dirty(cp_page);
f2fs_put_page(cp_page, 1); f2fs_put_page(cp_page, 1);
......
...@@ -491,8 +491,7 @@ int truncate_blocks(struct inode *inode, u64 from, bool lock) ...@@ -491,8 +491,7 @@ int truncate_blocks(struct inode *inode, u64 from, bool lock)
trace_f2fs_truncate_blocks_enter(inode, from); trace_f2fs_truncate_blocks_enter(inode, from);
free_from = (pgoff_t) free_from = (pgoff_t)F2FS_BYTES_TO_BLK(from + blocksize - 1);
((from + blocksize - 1) >> (sbi->log_blocksize));
if (lock) if (lock)
f2fs_lock_op(sbi); f2fs_lock_op(sbi);
......
...@@ -1048,8 +1048,8 @@ static const struct segment_allocation default_salloc_ops = { ...@@ -1048,8 +1048,8 @@ static const struct segment_allocation default_salloc_ops = {
int f2fs_trim_fs(struct f2fs_sb_info *sbi, struct fstrim_range *range) int f2fs_trim_fs(struct f2fs_sb_info *sbi, struct fstrim_range *range)
{ {
__u64 start = range->start >> sbi->log_blocksize; __u64 start = F2FS_BYTES_TO_BLK(range->start);
__u64 end = start + (range->len >> sbi->log_blocksize) - 1; __u64 end = start + F2FS_BYTES_TO_BLK(range->len) - 1;
unsigned int start_segno, end_segno; unsigned int start_segno, end_segno;
struct cp_control cpc; struct cp_control cpc;
...@@ -1066,7 +1066,7 @@ int f2fs_trim_fs(struct f2fs_sb_info *sbi, struct fstrim_range *range) ...@@ -1066,7 +1066,7 @@ int f2fs_trim_fs(struct f2fs_sb_info *sbi, struct fstrim_range *range)
end_segno = (end >= MAX_BLKADDR(sbi)) ? MAIN_SEGS(sbi) - 1 : end_segno = (end >= MAX_BLKADDR(sbi)) ? MAIN_SEGS(sbi) - 1 :
GET_SEGNO(sbi, end); GET_SEGNO(sbi, end);
cpc.reason = CP_DISCARD; cpc.reason = CP_DISCARD;
cpc.trim_minlen = range->minlen >> sbi->log_blocksize; cpc.trim_minlen = F2FS_BYTES_TO_BLK(range->minlen);
/* do checkpoint to issue discard commands safely */ /* do checkpoint to issue discard commands safely */
for (; start_segno <= end_segno; start_segno = cpc.trim_end + 1) { for (; start_segno <= end_segno; start_segno = cpc.trim_end + 1) {
...@@ -1080,7 +1080,7 @@ int f2fs_trim_fs(struct f2fs_sb_info *sbi, struct fstrim_range *range) ...@@ -1080,7 +1080,7 @@ int f2fs_trim_fs(struct f2fs_sb_info *sbi, struct fstrim_range *range)
mutex_unlock(&sbi->gc_mutex); mutex_unlock(&sbi->gc_mutex);
} }
out: out:
range->len = cpc.trimmed << sbi->log_blocksize; range->len = F2FS_BLK_TO_BYTES(cpc.trimmed);
return 0; return 0;
} }
......
...@@ -19,12 +19,16 @@ ...@@ -19,12 +19,16 @@
#define F2FS_MAX_LOG_SECTOR_SIZE 12 /* 12 bits for 4096 bytes */ #define F2FS_MAX_LOG_SECTOR_SIZE 12 /* 12 bits for 4096 bytes */
#define F2FS_LOG_SECTORS_PER_BLOCK 3 /* log number for sector/blk */ #define F2FS_LOG_SECTORS_PER_BLOCK 3 /* log number for sector/blk */
#define F2FS_BLKSIZE 4096 /* support only 4KB block */ #define F2FS_BLKSIZE 4096 /* support only 4KB block */
#define F2FS_BLKSIZE_BITS 12 /* bits for F2FS_BLKSIZE */
#define F2FS_MAX_EXTENSION 64 /* # of extension entries */ #define F2FS_MAX_EXTENSION 64 /* # of extension entries */
#define F2FS_BLK_ALIGN(x) (((x) + F2FS_BLKSIZE - 1) / F2FS_BLKSIZE) #define F2FS_BLK_ALIGN(x) (((x) + F2FS_BLKSIZE - 1) / F2FS_BLKSIZE)
#define NULL_ADDR ((block_t)0) /* used as block_t addresses */ #define NULL_ADDR ((block_t)0) /* used as block_t addresses */
#define NEW_ADDR ((block_t)-1) /* used as block_t addresses */ #define NEW_ADDR ((block_t)-1) /* used as block_t addresses */
#define F2FS_BYTES_TO_BLK(bytes) ((bytes) >> F2FS_BLKSIZE_BITS)
#define F2FS_BLK_TO_BYTES(blk) ((blk) << F2FS_BLKSIZE_BITS)
/* 0, 1(node nid), 2(meta nid) are reserved node id */ /* 0, 1(node nid), 2(meta nid) are reserved node id */
#define F2FS_RESERVED_NODE_NUM 3 #define F2FS_RESERVED_NODE_NUM 3
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment