mirror of
https://gitee.com/openharmony/third_party_f2fs-tools
synced 2024-11-23 10:10:00 +00:00
f2fs-tools: calculate inode checksum and writeback
Calculate inode checksum and writeback when processing sload or resize. Signed-off-by: Xue Liu <liuxueliu.liu@huawei.com> [Chao Yu: change commit message and code] Signed-off-by: Chao Yu <yuchao0@huawei.com> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
This commit is contained in:
parent
0912289c17
commit
ee0025a13f
@ -319,7 +319,7 @@ add_dentry:
|
||||
|
||||
if (dn.idirty) {
|
||||
ASSERT(parent == dn.inode_blk);
|
||||
ret = dev_write_block(dn.inode_blk, p_blkaddr);
|
||||
ret = write_inode(dn.inode_blk, p_blkaddr);
|
||||
ASSERT(ret >= 0);
|
||||
}
|
||||
|
||||
|
10
fsck/mount.c
10
fsck/mount.c
@ -1815,14 +1815,15 @@ void update_data_blkaddr(struct f2fs_sb_info *sbi, nid_t nid,
|
||||
|
||||
oldaddr = le32_to_cpu(node_blk->i.i_addr[ofs + ofs_in_node]);
|
||||
node_blk->i.i_addr[ofs + ofs_in_node] = cpu_to_le32(newaddr);
|
||||
ret = write_inode(node_blk, ni.blk_addr);
|
||||
ASSERT(ret >= 0);
|
||||
} else {
|
||||
oldaddr = le32_to_cpu(node_blk->dn.addr[ofs_in_node]);
|
||||
node_blk->dn.addr[ofs_in_node] = cpu_to_le32(newaddr);
|
||||
ret = dev_write_block(node_blk, ni.blk_addr);
|
||||
ASSERT(ret >= 0);
|
||||
}
|
||||
|
||||
ret = dev_write_block(node_blk, ni.blk_addr);
|
||||
ASSERT(ret >= 0);
|
||||
|
||||
/* check extent cache entry */
|
||||
if (node_blk->footer.nid != node_blk->footer.ino) {
|
||||
get_node_info(sbi, le32_to_cpu(node_blk->footer.ino), &ni);
|
||||
@ -1838,8 +1839,7 @@ void update_data_blkaddr(struct f2fs_sb_info *sbi, nid_t nid,
|
||||
node_blk->i.i_ext.len = 0;
|
||||
|
||||
/* update inode block */
|
||||
ret = dev_write_block(node_blk, ni.blk_addr);
|
||||
ASSERT(ret >= 0);
|
||||
ASSERT(write_inode(node_blk, ni.blk_addr) >= 0);
|
||||
}
|
||||
free(node_blk);
|
||||
}
|
||||
|
@ -16,14 +16,6 @@
|
||||
#include "fsck.h"
|
||||
#include "node.h"
|
||||
|
||||
static void write_inode(u64 blkaddr, struct f2fs_node *inode)
|
||||
{
|
||||
if (c.feature & cpu_to_le32(F2FS_FEATURE_INODE_CHKSUM))
|
||||
inode->i.i_inode_checksum =
|
||||
cpu_to_le32(f2fs_inode_chksum(inode));
|
||||
ASSERT(dev_write_block(inode, blkaddr) >= 0);
|
||||
}
|
||||
|
||||
int reserve_new_block(struct f2fs_sb_info *sbi, block_t *to,
|
||||
struct f2fs_summary *sum, int type)
|
||||
{
|
||||
@ -278,7 +270,7 @@ u64 f2fs_write(struct f2fs_sb_info *sbi, nid_t ino, u8 *buffer,
|
||||
}
|
||||
if (idirty) {
|
||||
ASSERT(inode == dn.inode_blk);
|
||||
write_inode(ni.blk_addr, inode);
|
||||
ASSERT(write_inode(inode, ni.blk_addr) >= 0);
|
||||
}
|
||||
if (index_node)
|
||||
free(index_node);
|
||||
@ -303,7 +295,7 @@ void f2fs_filesize_update(struct f2fs_sb_info *sbi, nid_t ino, u64 filesize)
|
||||
|
||||
inode->i.i_size = cpu_to_le64(filesize);
|
||||
|
||||
write_inode(ni.blk_addr, inode);
|
||||
ASSERT(write_inode(inode, ni.blk_addr) >= 0);
|
||||
free(inode);
|
||||
}
|
||||
|
||||
@ -348,7 +340,7 @@ int f2fs_build_file(struct f2fs_sb_info *sbi, struct dentry *de)
|
||||
ASSERT((unsigned long)n == de->size);
|
||||
memcpy(inline_data_addr(node_blk), buffer, de->size);
|
||||
node_blk->i.i_size = cpu_to_le64(de->size);
|
||||
write_inode(ni.blk_addr, node_blk);
|
||||
ASSERT(write_inode(node_blk, ni.blk_addr) >= 0);
|
||||
free(node_blk);
|
||||
} else {
|
||||
while ((n = read(fd, buffer, BLOCK_SZ)) > 0) {
|
||||
|
@ -223,8 +223,7 @@ int f2fs_setxattr(struct f2fs_sb_info *sbi, nid_t ino, int index, const char *na
|
||||
write_all_xattrs(sbi, inode, new_hsize, base_addr);
|
||||
|
||||
/* inode need update */
|
||||
ret = dev_write_block(inode, ni.blk_addr);
|
||||
ASSERT(ret >= 0);
|
||||
ASSERT(write_inode(inode, ni.blk_addr) >= 0);
|
||||
exit:
|
||||
free(inode);
|
||||
free(base_addr);
|
||||
|
@ -1145,6 +1145,7 @@ extern int log_base_2(u_int32_t);
|
||||
extern unsigned int addrs_per_inode(struct f2fs_inode *);
|
||||
extern __u32 f2fs_inode_chksum(struct f2fs_node *);
|
||||
extern __u32 f2fs_checkpoint_chksum(struct f2fs_checkpoint *);
|
||||
extern int write_inode(struct f2fs_node *, u64);
|
||||
|
||||
extern int get_bits_in_byte(unsigned char n);
|
||||
extern int test_and_set_bit_le(u32, u8 *);
|
||||
|
@ -546,6 +546,14 @@ __u32 f2fs_checkpoint_chksum(struct f2fs_checkpoint *cp)
|
||||
return chksum;
|
||||
}
|
||||
|
||||
int write_inode(struct f2fs_node *inode, u64 blkaddr)
|
||||
{
|
||||
if (c.feature & cpu_to_le32(F2FS_FEATURE_INODE_CHKSUM))
|
||||
inode->i.i_inode_checksum =
|
||||
cpu_to_le32(f2fs_inode_chksum(inode));
|
||||
return dev_write_block(inode, blkaddr);
|
||||
}
|
||||
|
||||
/*
|
||||
* try to identify the root device
|
||||
*/
|
||||
|
@ -1149,10 +1149,6 @@ static int f2fs_write_root_inode(void)
|
||||
raw_node->i.i_ext.blk_addr = 0;
|
||||
raw_node->i.i_ext.len = 0;
|
||||
|
||||
if (c.feature & cpu_to_le32(F2FS_FEATURE_INODE_CHKSUM))
|
||||
raw_node->i.i_inode_checksum =
|
||||
cpu_to_le32(f2fs_inode_chksum(raw_node));
|
||||
|
||||
main_area_node_seg_blk_offset = get_sb(main_blkaddr);
|
||||
main_area_node_seg_blk_offset += c.cur_seg[CURSEG_HOT_NODE] *
|
||||
c.blks_per_seg;
|
||||
@ -1161,7 +1157,7 @@ static int f2fs_write_root_inode(void)
|
||||
get_sb(main_blkaddr),
|
||||
c.cur_seg[CURSEG_HOT_NODE],
|
||||
c.blks_per_seg, main_area_node_seg_blk_offset);
|
||||
if (dev_write_block(raw_node, main_area_node_seg_blk_offset)) {
|
||||
if (write_inode(raw_node, main_area_node_seg_blk_offset) < 0) {
|
||||
MSG(1, "\tError: While writing the raw_node to disk!!!\n");
|
||||
free(raw_node);
|
||||
return -1;
|
||||
@ -1320,10 +1316,6 @@ static int f2fs_write_qf_inode(int qtype)
|
||||
raw_node->i.i_ext.blk_addr = 0;
|
||||
raw_node->i.i_ext.len = 0;
|
||||
|
||||
if (c.feature & cpu_to_le32(F2FS_FEATURE_INODE_CHKSUM))
|
||||
raw_node->i.i_inode_checksum =
|
||||
cpu_to_le32(f2fs_inode_chksum(raw_node));
|
||||
|
||||
main_area_node_seg_blk_offset = get_sb(main_blkaddr);
|
||||
main_area_node_seg_blk_offset += c.cur_seg[CURSEG_HOT_NODE] *
|
||||
c.blks_per_seg + qtype + 1;
|
||||
@ -1332,7 +1324,7 @@ static int f2fs_write_qf_inode(int qtype)
|
||||
get_sb(main_blkaddr),
|
||||
c.cur_seg[CURSEG_HOT_NODE],
|
||||
c.blks_per_seg, main_area_node_seg_blk_offset);
|
||||
if (dev_write_block(raw_node, main_area_node_seg_blk_offset)) {
|
||||
if (write_inode(raw_node, main_area_node_seg_blk_offset) < 0) {
|
||||
MSG(1, "\tError: While writing the raw_node to disk!!!\n");
|
||||
free(raw_node);
|
||||
return -1;
|
||||
@ -1507,10 +1499,6 @@ static int f2fs_write_lpf_inode(void)
|
||||
}
|
||||
raw_node->i.i_addr[get_extra_isize(raw_node)] = cpu_to_le32(data_blk_nor);
|
||||
|
||||
if (c.feature & cpu_to_le32(F2FS_FEATURE_INODE_CHKSUM))
|
||||
raw_node->i.i_inode_checksum =
|
||||
cpu_to_le32(f2fs_inode_chksum(raw_node));
|
||||
|
||||
main_area_node_seg_blk_offset = get_sb(main_blkaddr);
|
||||
main_area_node_seg_blk_offset += c.cur_seg[CURSEG_HOT_NODE] *
|
||||
c.blks_per_seg + c.quota_inum + 1;
|
||||
@ -1519,7 +1507,7 @@ static int f2fs_write_lpf_inode(void)
|
||||
get_sb(main_blkaddr),
|
||||
c.cur_seg[CURSEG_HOT_NODE],
|
||||
c.blks_per_seg, main_area_node_seg_blk_offset);
|
||||
if (dev_write_block(raw_node, main_area_node_seg_blk_offset)) {
|
||||
if (write_inode(raw_node, main_area_node_seg_blk_offset) < 0) {
|
||||
MSG(1, "\tError: While writing the raw_node to disk!!!\n");
|
||||
err = -1;
|
||||
goto exit;
|
||||
|
Loading…
Reference in New Issue
Block a user