linux-ext4.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Forrest Liu <forrestl@synology.com>
To: Theodore Ts'o <tytso@mit.edu>
Cc: linux-ext4  <linux-ext4@vger.kernel.org>,
	"Forrest Liu" <forrestl@synology.com>
Subject: [PATCH] ext4: fix extent tree corruption that incurred by hole punch
Date: Tue,  4 Dec 2012 19:32:32 +0800	[thread overview]
Message-ID: <1354620752-7231-1-git-send-email-forrestl@synology.com> (raw)

When depth of extent tree is greater than 1, extent indexes didn't update
correctly in ext4_ext_rm_idx

Signed-off-by: Forrest Liu <forrestl@synology.com>
---
 fs/ext4/extents.c |   24 ++++++++++++++++++++----
 1 files changed, 20 insertions(+), 4 deletions(-)

diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c
index d3dd618..b10b8c0 100644
--- a/fs/ext4/extents.c
+++ b/fs/ext4/extents.c
@@ -2190,13 +2190,15 @@ errout:
  * removes index from the index block.
  */
 static int ext4_ext_rm_idx(handle_t *handle, struct inode *inode,
-			struct ext4_ext_path *path)
+			struct ext4_ext_path *path, int depth)
 {
 	int err;
 	ext4_fsblk_t leaf;
+	__le32 border;
 
 	/* free index block */
-	path--;
+	depth--;
+	path = path + depth;
 	leaf = ext4_idx_pblock(path->p_idx);
 	if (unlikely(path->p_hdr->eh_entries == 0)) {
 		EXT4_ERROR_INODE(inode, "path->p_hdr->eh_entries == 0");
@@ -2221,6 +2223,20 @@ static int ext4_ext_rm_idx(handle_t *handle, struct inode *inode,
 
 	ext4_free_blocks(handle, inode, NULL, leaf, 1,
 			 EXT4_FREE_BLOCKS_METADATA | EXT4_FREE_BLOCKS_FORGET);
+
+	border = path->p_idx->ei_block;
+	while (--depth >= 0) {
+		if (path->p_idx != EXT_FIRST_INDEX(path->p_hdr))
+			break;
+		path--;
+		err = ext4_ext_get_access(handle, inode, path);
+		if (err)
+			break;
+		path->p_idx->ei_block = border;
+		err = ext4_ext_dirty(handle, inode, path);
+		if (err)
+			break;
+	}
 	return err;
 }
 
@@ -2557,7 +2573,7 @@ ext4_ext_rm_leaf(handle_t *handle, struct inode *inode,
 	/* if this leaf is free, then we should
 	 * remove it from index block above */
 	if (err == 0 && eh->eh_entries == 0 && path[depth].p_bh != NULL)
-		err = ext4_ext_rm_idx(handle, inode, path + depth);
+		err = ext4_ext_rm_idx(handle, inode, path, depth);
 
 out:
 	return err;
@@ -2760,7 +2776,7 @@ again:
 				/* index is empty, remove it;
 				 * handle must be already prepared by the
 				 * truncatei_leaf() */
-				err = ext4_ext_rm_idx(handle, inode, path + i);
+				err = ext4_ext_rm_idx(handle, inode, path, i);
 			}
 			/* root level has p_bh == NULL, brelse() eats this */
 			brelse(path[i].p_bh);
-- 
1.7.5.4


             reply	other threads:[~2012-12-04 11:32 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-12-04 11:32 Forrest Liu [this message]
  -- strict thread matches above, loose matches on Subject: below --
2012-12-04 12:11 [PATCH] ext4: fix extent tree corruption that incurred by hole punch Forrest Liu
2012-12-04 12:29 ` forrest
2012-12-05  6:13   ` Forrest Liu
2012-12-05  7:53     ` Ashish Sangwan
2012-12-05  8:09       ` Ashish Sangwan
2012-12-06 11:35         ` Forrest Liu
2012-12-06 13:16           ` Ashish Sangwan
2012-12-06 14:36             ` Forrest Liu
2012-12-07  5:11               ` Ashish Sangwan
2012-12-07 12:13                 ` Forrest Liu
2012-12-10  6:22                   ` Ashish Sangwan
2012-12-08 17:31   ` Eric Sandeen
2012-12-08 18:56     ` Forrest Liu
2012-12-06 15:45 ` Eric Sandeen
2012-12-06 15:48   ` Eric Sandeen
2012-12-07  5:53     ` Ashish Sangwan
2012-12-07 12:26       ` Forrest Liu
2012-12-07 22:17         ` Eric Sandeen
2012-12-08 19:01           ` Forrest Liu
2012-12-07 22:29         ` Theodore Ts'o
2012-12-08 19:29           ` Forrest Liu

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=1354620752-7231-1-git-send-email-forrestl@synology.com \
    --to=forrestl@synology.com \
    --cc=linux-ext4@vger.kernel.org \
    --cc=tytso@mit.edu \
    /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 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).