linux-ext4.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Dmitry Monakhov <dmonakhov@openvz.org>
To: linux-ext4@vger.kernel.org
Cc: tytso@mit.edu, achender@linux.vnet.ibm.com,
	Dmitry Monakhov <dmonakhov@openvz.org>
Subject: [PATCH 2/4] ext4: move inode indepth shrink logic to didicated function
Date: Tue, 20 Sep 2011 18:49:28 +0400	[thread overview]
Message-ID: <1316530170-3965-3-git-send-email-dmonakhov@openvz.org> (raw)
In-Reply-To: <1316530170-3965-1-git-send-email-dmonakhov@openvz.org>

- Add ext4_ext_try_shrink() helper
- ext4_mark_inode_dirty() called externally in order to allow
  caller to butch several inode updates in to one mark_dirty call.

Signed-off-by: Dmitry Monakhov <dmonakhov@openvz.org>
---
 fs/ext4/extents.c |   62 +++++++++++++++++++++-------------------------------
 1 files changed, 25 insertions(+), 37 deletions(-)

diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c
index b3a08f0..9032214 100644
--- a/fs/ext4/extents.c
+++ b/fs/ext4/extents.c
@@ -2497,13 +2497,29 @@ ext4_ext_more_to_rm(struct ext4_ext_path *path)
 	return 1;
 }
 
+static int ext4_ext_try_shrink(handle_t *handle, struct inode *inode)
+{
+	/* TODO: flexible tree reduction should be here */
+	if (ext_depth(inode) && ext_inode_hdr(inode)->eh_entries == 0) {
+		/*
+		 * truncate to zero freed all the tree,
+		 * so we need to correct eh_depth
+		 */
+		ext_inode_hdr(inode)->eh_depth = 0;
+		ext_inode_hdr(inode)->eh_max =
+			cpu_to_le16(ext4_ext_space_root(inode, 0));
+		return 1;
+	}
+	return 0;
+}
+
 static int ext4_ext_remove_space(struct inode *inode, ext4_lblk_t start)
 {
 	struct super_block *sb = inode->i_sb;
 	int depth = ext_depth(inode);
 	struct ext4_ext_path *path;
 	handle_t *handle;
-	int i, err;
+	int i, err, err2;
 
 	ext_debug("truncate since %u\n", start);
 
@@ -2608,29 +2624,18 @@ again:
 			ext_debug("return to level %d\n", i);
 		}
 	}
-
-	/* TODO: flexible tree reduction should be here */
-	if (path->p_hdr->eh_entries == 0) {
-		/*
-		 * truncate to zero freed all the tree,
-		 * so we need to correct eh_depth
-		 */
-		err = ext4_ext_get_access(handle, inode, path);
-		if (err == 0) {
-			ext_inode_hdr(inode)->eh_depth = 0;
-			ext_inode_hdr(inode)->eh_max =
-				cpu_to_le16(ext4_ext_space_root(inode, 0));
-			err = ext4_ext_dirty(handle, inode, path);
-		}
-	}
+	if(ext4_ext_try_shrink(handle, inode))
+		err2 = ext4_mark_inode_dirty(handle, inode);
+	if (!err)
+		err = err2;
 out:
 	ext4_ext_drop_refs(path);
 	kfree(path);
 	if (err == -EAGAIN)
 		goto again;
-	ext4_journal_stop(handle);
+	err2 = ext4_journal_stop(handle);
 
-	return err;
+	return err ? err : err2;
 }
 
 /*
@@ -3456,28 +3461,11 @@ int ext4_ext_map_blocks(handle_t *handle, struct inode *inode,
 			}
 
 			ext4_ext_mark_uninitialized(ex);
-
 			ext4_ext_invalidate_cache(inode);
-
 			err = ext4_ext_rm_leaf(handle, inode, path,
 				map->m_lblk, map->m_lblk + punched_out);
-
-			if (!err && path->p_hdr->eh_entries == 0) {
-				/*
-				 * Punch hole freed all of this sub tree,
-				 * so we need to correct eh_depth
-				 */
-				err = ext4_ext_get_access(handle, inode, path);
-				if (err == 0) {
-					ext_inode_hdr(inode)->eh_depth = 0;
-					ext_inode_hdr(inode)->eh_max =
-					cpu_to_le16(ext4_ext_space_root(
-						inode, 0));

  parent reply	other threads:[~2011-09-20 14:49 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-09-20 14:49 [PATCH 0/4] ext4: cleanup and bugfixes for grow/shrink logic Dmitry Monakhov
2011-09-20 14:49 ` [PATCH 1/4] ext4: cleanup ext4_ext_grow_indepth code Dmitry Monakhov
2011-09-20 14:49 ` Dmitry Monakhov [this message]
2011-09-20 14:49 ` [PATCH 3/4] ext4: Do not clear EOFBLOCKS_FL too soon Dmitry Monakhov
2011-09-20 14:49 ` [PATCH 4/4] ext4: fix punch_hole extend handler Dmitry Monakhov
2011-09-20 15:02 ` [PATCH 0/4] ext4: cleanup and bugfixes for grow/shrink logic Dmitry Monakhov
2011-10-19 11:47 ` [PATCH 0/4] ext4: Ping Dmitry Monakhov

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=1316530170-3965-3-git-send-email-dmonakhov@openvz.org \
    --to=dmonakhov@openvz.org \
    --cc=achender@linux.vnet.ibm.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).