linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] btrfs-progs: fsck:Add repair function for I_ERR_FILE_WRONG_NBYTES.
@ 2015-07-02  6:52 Qu Wenruo
  2015-07-02  6:52 ` [PATCH 0/2] btrfsck repair for I_ERR_FILE_WRONG_NBYTES and test case Qu Wenruo
  0 siblings, 1 reply; 3+ messages in thread
From: Qu Wenruo @ 2015-07-02  6:52 UTC (permalink / raw)
  To: linux-btrfs

Some unknown kernel bug makes inode nbytes modification out of sync with
file extent update.

But it's quite easy to fix in btrfs-progs anyway.

So just fix it by adding a new function repair_inode_nbytes by using the
found_size in inode_record.

Reported-by: Christian <cdysthe@gmail.com>
Reported-by: Chris Murphy <lists@colorremedies.com>
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
---
 cmds-check.c | 38 +++++++++++++++++++++++++++++++++++++-
 1 file changed, 37 insertions(+), 1 deletion(-)

diff --git a/cmds-check.c b/cmds-check.c
index 778f141..dd2fce3 100644
--- a/cmds-check.c
+++ b/cmds-check.c
@@ -1918,6 +1918,39 @@ static int repair_inode_orphan_item(struct btrfs_trans_handle *trans,
 	return ret;
 }
 
+static int repair_inode_nbytes(struct btrfs_trans_handle *trans,
+			       struct btrfs_root *root,
+			       struct btrfs_path *path,
+			       struct inode_record *rec)
+{
+	struct btrfs_inode_item *ei;
+	struct btrfs_key key;
+	int ret = 0;
+
+	key.objectid = rec->ino;
+	key.type = BTRFS_INODE_ITEM_KEY;
+	key.offset = 0;
+
+	ret = btrfs_search_slot(trans, root, &key, path, 0, 1);
+	if (ret) {
+		if (ret > 0)
+			ret = -ENOENT;
+		goto out;
+	}
+
+	/* Since ret == 0, no need to check anything */
+	ei = btrfs_item_ptr(path->nodes[0], path->slots[0],
+			    struct btrfs_inode_item);
+	btrfs_set_inode_nbytes(path->nodes[0], ei, rec->found_size);
+	btrfs_mark_buffer_dirty(path->nodes[0]);
+	rec->errors &= ~I_ERR_FILE_NBYTES_WRONG;
+	printf("reset nbytes for ino %llu root %llu\n",
+	       rec->ino, root->root_key.objectid);
+out:
+	btrfs_release_path(path);
+	return ret;
+}
+
 static int add_missing_dir_index(struct btrfs_root *root,
 				 struct cache_tree *inode_cache,
 				 struct inode_record *rec,
@@ -2661,7 +2694,8 @@ static int try_repair_inode(struct btrfs_root *root, struct inode_record *rec)
 			     I_ERR_LINK_COUNT_WRONG |
 			     I_ERR_NO_INODE_ITEM |
 			     I_ERR_FILE_EXTENT_ORPHAN |
-			     I_ERR_FILE_EXTENT_DISCOUNT)))
+			     I_ERR_FILE_EXTENT_DISCOUNT|
+			     I_ERR_FILE_NBYTES_WRONG)))
 		return rec->errors;
 
 	path = btrfs_alloc_path();
@@ -2693,6 +2727,8 @@ static int try_repair_inode(struct btrfs_root *root, struct inode_record *rec)
 		ret = repair_inode_orphan_item(trans, root, path, rec);
 	if (!ret && rec->errors & I_ERR_LINK_COUNT_WRONG)
 		ret = repair_inode_nlinks(trans, root, path, rec);
+	if (!ret && rec->errors & I_ERR_FILE_NBYTES_WRONG)
+		ret = repair_inode_nbytes(trans, root, path, rec);
 	btrfs_commit_transaction(trans, root);
 	btrfs_free_path(path);
 	return ret;
-- 
2.4.4


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH 0/2] btrfsck repair for I_ERR_FILE_WRONG_NBYTES and test case
  2015-07-02  6:52 [PATCH 1/2] btrfs-progs: fsck:Add repair function for I_ERR_FILE_WRONG_NBYTES Qu Wenruo
@ 2015-07-02  6:52 ` Qu Wenruo
  2015-07-03 16:06   ` David Sterba
  0 siblings, 1 reply; 3+ messages in thread
From: Qu Wenruo @ 2015-07-02  6:52 UTC (permalink / raw)
  To: linux-btrfs

Add repair function for I_ERR_FILE_WRONG_NBYTES and a test case for it.
Rebased to devel branch.

The second patch contains binary data, so created a pull request for it.
https://github.com/kdave/btrfs-progs/pull/7

Qu Wenruo (2):
  btrfs-progs: fsck:Add repair function for I_ERR_FILE_WRONG_NBYTES.
  btrfs-progs: tests: Add test case for I_ERR_FILE_WRONG_NBYTES repair.

 cmds-check.c                                       |  38 ++++++++++++++++++++-
 .../016-wrong-inode-nbytes/default_case.img.xz     | Bin 0 -> 1996 bytes
 2 files changed, 37 insertions(+), 1 deletion(-)
 create mode 100644 tests/fsck-tests/016-wrong-inode-nbytes/default_case.img.xz

-- 
2.4.4


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH 0/2] btrfsck repair for I_ERR_FILE_WRONG_NBYTES and test case
  2015-07-02  6:52 ` [PATCH 0/2] btrfsck repair for I_ERR_FILE_WRONG_NBYTES and test case Qu Wenruo
@ 2015-07-03 16:06   ` David Sterba
  0 siblings, 0 replies; 3+ messages in thread
From: David Sterba @ 2015-07-03 16:06 UTC (permalink / raw)
  To: Qu Wenruo; +Cc: linux-btrfs

On Thu, Jul 02, 2015 at 02:52:31PM +0800, Qu Wenruo wrote:
> Add repair function for I_ERR_FILE_WRONG_NBYTES and a test case for it.
> Rebased to devel branch.
> 
> The second patch contains binary data, so created a pull request for it.
> https://github.com/kdave/btrfs-progs/pull/7
> 
> Qu Wenruo (2):
>   btrfs-progs: fsck:Add repair function for I_ERR_FILE_WRONG_NBYTES.
>   btrfs-progs: tests: Add test case for I_ERR_FILE_WRONG_NBYTES repair.

Applied, thanks.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-07-03 16:06 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-07-02  6:52 [PATCH 1/2] btrfs-progs: fsck:Add repair function for I_ERR_FILE_WRONG_NBYTES Qu Wenruo
2015-07-02  6:52 ` [PATCH 0/2] btrfsck repair for I_ERR_FILE_WRONG_NBYTES and test case Qu Wenruo
2015-07-03 16:06   ` David Sterba

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).