All of lore.kernel.org
 help / color / mirror / Atom feed
From: Chao Yu <yuchao0@huawei.com>
To: linux-f2fs-devel@lists.sourceforge.net
Cc: jaegeuk@kernel.org
Subject: [PATCH] f2fs-tools: calculate inode checksum and writeback
Date: Fri, 24 May 2019 15:28:11 +0800	[thread overview]
Message-ID: <20190524072811.104813-1-yuchao0@huawei.com> (raw)

From: Xue Liu <liuxueliu.liu@huawei.com>

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>
---
v2:
- move write_inode() to libf2fs.c for more callers.
- cover missing case in f2fs_add_link.
- clean up update_data_blkaddr() with write_inode().
- don't assert in write_inode().
 fsck/dir.c         |  2 +-
 fsck/mount.c       | 10 +++++-----
 fsck/segment.c     | 14 +++-----------
 fsck/xattr.c       |  3 +--
 include/f2fs_fs.h  |  1 +
 lib/libf2fs.c      |  8 ++++++++
 mkfs/f2fs_format.c | 18 +++---------------
 7 files changed, 22 insertions(+), 34 deletions(-)

diff --git a/fsck/dir.c b/fsck/dir.c
index 592d9db..1e21294 100644
--- a/fsck/dir.c
+++ b/fsck/dir.c
@@ -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);
 	}
 
diff --git a/fsck/mount.c b/fsck/mount.c
index aecd0cd..1c5cd93 100644
--- a/fsck/mount.c
+++ b/fsck/mount.c
@@ -1812,14 +1812,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);
@@ -1835,8 +1836,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);
 }
diff --git a/fsck/segment.c b/fsck/segment.c
index f26e623..1b58b70 100644
--- a/fsck/segment.c
+++ b/fsck/segment.c
@@ -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) {
diff --git a/fsck/xattr.c b/fsck/xattr.c
index b13e5ee..98cbb0c 100644
--- a/fsck/xattr.c
+++ b/fsck/xattr.c
@@ -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);
diff --git a/include/f2fs_fs.h b/include/f2fs_fs.h
index 1890975..120f861 100644
--- a/include/f2fs_fs.h
+++ b/include/f2fs_fs.h
@@ -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 *);
diff --git a/lib/libf2fs.c b/lib/libf2fs.c
index 986bf29..88ab70f 100644
--- a/lib/libf2fs.c
+++ b/lib/libf2fs.c
@@ -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
  */
diff --git a/mkfs/f2fs_format.c b/mkfs/f2fs_format.c
index f2265bb..8f41052 100644
--- a/mkfs/f2fs_format.c
+++ b/mkfs/f2fs_format.c
@@ -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;
-- 
2.18.0.rc1

             reply	other threads:[~2019-05-24  7:28 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-24  7:28 Chao Yu [this message]
  -- strict thread matches above, loose matches on Subject: below --
2018-06-14  3:10 [PATCH] f2fs-tools: calculate inode checksum and writeback Liu Xue
2018-06-19 12:59 ` Chao Yu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190524072811.104813-1-yuchao0@huawei.com \
    --to=yuchao0@huawei.com \
    --cc=jaegeuk@kernel.org \
    --cc=linux-f2fs-devel@lists.sourceforge.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.