Commit 2020cd48 authored by Chao Yu's avatar Chao Yu Committed by Jaegeuk Kim

f2fs: introduce get_dnode_addr() to clean up codes

Just cleanup, no logic changes.
Signed-off-by: default avatarChao Yu <chao@kernel.org>
Signed-off-by: default avatarJaegeuk Kim <jaegeuk@kernel.org>
parent bb6e1c8f
...@@ -1181,16 +1181,9 @@ static int f2fs_submit_page_read(struct inode *inode, struct page *page, ...@@ -1181,16 +1181,9 @@ static int f2fs_submit_page_read(struct inode *inode, struct page *page,
static void __set_data_blkaddr(struct dnode_of_data *dn) static void __set_data_blkaddr(struct dnode_of_data *dn)
{ {
struct f2fs_node *rn = F2FS_NODE(dn->node_page); __le32 *addr = get_dnode_addr(dn->inode, dn->node_page);
__le32 *addr_array;
int base = 0;
if (IS_INODE(dn->node_page) && f2fs_has_extra_attr(dn->inode)) addr[dn->ofs_in_node] = cpu_to_le32(dn->data_blkaddr);
base = get_extra_isize(dn->inode);
/* Get physical address of data block */
addr_array = blkaddr_in_node(rn);
addr_array[base + dn->ofs_in_node] = cpu_to_le32(dn->data_blkaddr);
} }
/* /*
......
...@@ -3277,12 +3277,13 @@ static inline bool f2fs_is_cow_file(struct inode *inode) ...@@ -3277,12 +3277,13 @@ static inline bool f2fs_is_cow_file(struct inode *inode)
return is_inode_flag_set(inode, FI_COW_FILE); return is_inode_flag_set(inode, FI_COW_FILE);
} }
static inline __le32 *get_dnode_addr(struct inode *inode,
struct page *node_page);
static inline void *inline_data_addr(struct inode *inode, struct page *page) static inline void *inline_data_addr(struct inode *inode, struct page *page)
{ {
struct f2fs_inode *ri = F2FS_INODE(page); __le32 *addr = get_dnode_addr(inode, page);
int extra_size = get_extra_isize(inode);
return (void *)&(ri->i_addr[extra_size + DEF_INLINE_RESERVED_SIZE]); return (void *)(addr + DEF_INLINE_RESERVED_SIZE);
} }
static inline int f2fs_has_inline_dentry(struct inode *inode) static inline int f2fs_has_inline_dentry(struct inode *inode)
...@@ -3427,6 +3428,17 @@ static inline int get_inline_xattr_addrs(struct inode *inode) ...@@ -3427,6 +3428,17 @@ static inline int get_inline_xattr_addrs(struct inode *inode)
return F2FS_I(inode)->i_inline_xattr_size; return F2FS_I(inode)->i_inline_xattr_size;
} }
static inline __le32 *get_dnode_addr(struct inode *inode,
struct page *node_page)
{
int base = 0;
if (IS_INODE(node_page) && f2fs_has_extra_attr(inode))
base = get_extra_isize(inode);
return blkaddr_in_node(F2FS_NODE(node_page)) + base;
}
#define f2fs_get_inode_mode(i) \ #define f2fs_get_inode_mode(i) \
((is_inode_flag_set(i, FI_ACL_MODE)) ? \ ((is_inode_flag_set(i, FI_ACL_MODE)) ? \
(F2FS_I(i)->i_acl_mode) : ((i)->i_mode)) (F2FS_I(i)->i_acl_mode) : ((i)->i_mode))
......
...@@ -557,20 +557,14 @@ static int f2fs_file_open(struct inode *inode, struct file *filp) ...@@ -557,20 +557,14 @@ static int f2fs_file_open(struct inode *inode, struct file *filp)
void f2fs_truncate_data_blocks_range(struct dnode_of_data *dn, int count) void f2fs_truncate_data_blocks_range(struct dnode_of_data *dn, int count)
{ {
struct f2fs_sb_info *sbi = F2FS_I_SB(dn->inode); struct f2fs_sb_info *sbi = F2FS_I_SB(dn->inode);
struct f2fs_node *raw_node;
int nr_free = 0, ofs = dn->ofs_in_node, len = count; int nr_free = 0, ofs = dn->ofs_in_node, len = count;
__le32 *addr; __le32 *addr;
int base = 0;
bool compressed_cluster = false; bool compressed_cluster = false;
int cluster_index = 0, valid_blocks = 0; int cluster_index = 0, valid_blocks = 0;
int cluster_size = F2FS_I(dn->inode)->i_cluster_size; int cluster_size = F2FS_I(dn->inode)->i_cluster_size;
bool released = !atomic_read(&F2FS_I(dn->inode)->i_compr_blocks); bool released = !atomic_read(&F2FS_I(dn->inode)->i_compr_blocks);
if (IS_INODE(dn->node_page) && f2fs_has_extra_attr(dn->inode)) addr = get_dnode_addr(dn->inode, dn->node_page) + ofs;
base = get_extra_isize(dn->inode);
raw_node = F2FS_NODE(dn->node_page);
addr = blkaddr_in_node(raw_node) + base + ofs;
/* Assumption: truncation starts with cluster */ /* Assumption: truncation starts with cluster */
for (; count > 0; count--, addr++, dn->ofs_in_node++, cluster_index++) { for (; count > 0; count--, addr++, dn->ofs_in_node++, cluster_index++) {
......
...@@ -61,35 +61,31 @@ void f2fs_set_inode_flags(struct inode *inode) ...@@ -61,35 +61,31 @@ void f2fs_set_inode_flags(struct inode *inode)
S_ENCRYPTED|S_VERITY|S_CASEFOLD); S_ENCRYPTED|S_VERITY|S_CASEFOLD);
} }
static void __get_inode_rdev(struct inode *inode, struct f2fs_inode *ri) static void __get_inode_rdev(struct inode *inode, struct page *node_page)
{ {
int extra_size = get_extra_isize(inode); __le32 *addr = get_dnode_addr(inode, node_page);
if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode) || if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode) ||
S_ISFIFO(inode->i_mode) || S_ISSOCK(inode->i_mode)) { S_ISFIFO(inode->i_mode) || S_ISSOCK(inode->i_mode)) {
if (ri->i_addr[extra_size]) if (addr[0])
inode->i_rdev = old_decode_dev( inode->i_rdev = old_decode_dev(le32_to_cpu(addr[0]));
le32_to_cpu(ri->i_addr[extra_size]));
else else
inode->i_rdev = new_decode_dev( inode->i_rdev = new_decode_dev(le32_to_cpu(addr[1]));
le32_to_cpu(ri->i_addr[extra_size + 1]));
} }
} }
static void __set_inode_rdev(struct inode *inode, struct f2fs_inode *ri) static void __set_inode_rdev(struct inode *inode, struct page *node_page)
{ {
int extra_size = get_extra_isize(inode); __le32 *addr = get_dnode_addr(inode, node_page);
if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode)) { if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode)) {
if (old_valid_dev(inode->i_rdev)) { if (old_valid_dev(inode->i_rdev)) {
ri->i_addr[extra_size] = addr[0] = cpu_to_le32(old_encode_dev(inode->i_rdev));
cpu_to_le32(old_encode_dev(inode->i_rdev)); addr[1] = 0;
ri->i_addr[extra_size + 1] = 0;
} else { } else {
ri->i_addr[extra_size] = 0; addr[0] = 0;
ri->i_addr[extra_size + 1] = addr[1] = cpu_to_le32(new_encode_dev(inode->i_rdev));
cpu_to_le32(new_encode_dev(inode->i_rdev)); addr[2] = 0;
ri->i_addr[extra_size + 2] = 0;
} }
} }
} }
...@@ -463,7 +459,7 @@ static int do_read_inode(struct inode *inode) ...@@ -463,7 +459,7 @@ static int do_read_inode(struct inode *inode)
} }
/* get rdev by using inline_info */ /* get rdev by using inline_info */
__get_inode_rdev(inode, ri); __get_inode_rdev(inode, node_page);
if (!f2fs_need_inode_block_update(sbi, inode->i_ino)) if (!f2fs_need_inode_block_update(sbi, inode->i_ino))
fi->last_disk_size = inode->i_size; fi->last_disk_size = inode->i_size;
...@@ -736,7 +732,7 @@ void f2fs_update_inode(struct inode *inode, struct page *node_page) ...@@ -736,7 +732,7 @@ void f2fs_update_inode(struct inode *inode, struct page *node_page)
} }
} }
__set_inode_rdev(inode, ri); __set_inode_rdev(inode, node_page);
/* deleted inode */ /* deleted inode */
if (inode->i_nlink == 0) if (inode->i_nlink == 0)
......
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