From: Dmitry Monakhov <dmonakhov@openvz.org>
To: linux-ext4@vger.kernel.org
Cc: achender@linux.vnet.ibm.com, tytso@mit.edu,
Dmitry Monakhov <dmonakhov@openvz.org>
Subject: [PATCH 3/7] ext4: Move punch hole logic to didicated function
Date: Fri, 28 Oct 2011 21:00:06 +0400 [thread overview]
Message-ID: <1319821210-7374-4-git-send-email-dmonakhov@openvz.org> (raw)
In-Reply-To: <1319821210-7374-1-git-send-email-dmonakhov@openvz.org>
punch hole logic is sited directly in ext4_ext_map_blocks() on 3rd controll
level, IMHO one can easily screw-up his eyes while invastigating that code.
We have nothing to hide aren't we? Let's move it to didicate function.
Do it similar to uninitialized extent handlers. Logic moved as is.
Signed-off-by: Dmitry Monakhov <dmonakhov@openvz.org>
---
fs/ext4/extents.c | 145 +++++++++++++++++++++++++----------------------------
1 files changed, 68 insertions(+), 77 deletions(-)
diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c
index 6e3ce38..02dfe38 100644
--- a/fs/ext4/extents.c
+++ b/fs/ext4/extents.c
@@ -3225,6 +3225,70 @@ static void unmap_underlying_metadata_blocks(struct block_device *bdev,
unmap_underlying_metadata(bdev, block + i);
}
+static int
+ext4_ext_handle_punched_extent(handle_t *handle, struct inode *inode,
+ struct ext4_map_blocks *map, struct ext4_ext_path *path)
+{
+ struct ext4_extent *ex = path[path->p_depth].p_ext;
+ ext4_lblk_t ee_block = ext4_ext_get_actual_len(ex);
+ unsigned short ee_len = le32_to_cpu(ex->ee_block);
+ struct ext4_map_blocks punch_map;
+ ext4_fsblk_t partial_cluster = 0;
+ unsigned int punched_out = 0;
+ int err;
+
+ /* Punch out the map length, but only to the end of the extent */
+ punched_out = ee_len - (map->m_lblk - ee_block);
+ if (punched_out > map->m_len)
+ punched_out = map->m_len;
+ /*
+ * Sense extents need to be converted to uninitialized, they must
+ * fit in an uninitialized extent
+ */
+ if (punched_out > EXT_UNINIT_MAX_LEN)
+ punched_out = EXT_UNINIT_MAX_LEN;
+
+ punch_map.m_lblk = map->m_lblk;
+ punch_map.m_pblk = map->m_lblk - ee_block + ext4_ext_pblock(ex);;
+ punch_map.m_len = punched_out;
+ punch_map.m_flags = 0;
+
+ /* Check to see if the extent needs to be split */
+ if (punch_map.m_len != ee_len || punch_map.m_lblk != ee_block) {
+ err = ext4_split_extent(handle, inode, path, &punch_map, 0,
+ EXT4_GET_BLOCKS_PUNCH_OUT_EXT |
+ EXT4_GET_BLOCKS_PRE_IO);
+ if (err < 0)
+ goto out;
+ /*
+ * find extent for the block at the start of the hole
+ */
+ ext4_ext_drop_refs(path);
+ kfree(path);
+
+ path = ext4_ext_find_extent(inode, map->m_lblk, NULL);
+ if (IS_ERR(path)) {
+ err = PTR_ERR(path);
+ path = NULL;
+ goto out;
+ }
+ ex = path[path->p_depth].p_ext;
+ }
+
+ ext4_ext_mark_uninitialized(ex);
+ ext4_ext_invalidate_cache(inode);
+ err = ext4_ext_rm_leaf(handle, inode, path, &partial_cluster,
+ map->m_lblk, map->m_lblk + punched_out);
+ if (!err && ext4_ext_try_shrink(handle, inode))
+ err = ext4_mark_inode_dirty(handle, inode);
+out:
+ if (path) {
+ ext4_ext_drop_refs(path);
+ kfree(path);
+ }
+
+ return err ? err : punched_out;
+}
/*
* Handle EOFBLOCKS_FL flag, clearing it if necessary
*/
@@ -3731,12 +3795,9 @@ int ext4_ext_map_blocks(handle_t *handle, struct inode *inode,
int eof_fl = 0;
unsigned int allocated = 0, offset = 0;
unsigned int allocated_clusters = 0, reserved_clusters = 0;
- unsigned int punched_out = 0;
- unsigned int result = 0;
struct ext4_allocation_request ar;
ext4_io_end_t *io = EXT4_I(inode)->cur_aio_dio;
ext4_lblk_t cluster_offset;
- struct ext4_map_blocks punch_map;
ext_debug("blocks %u/%u requested for inode %lu\n",
map->m_lblk, map->m_len, inode->i_ino);
@@ -3812,8 +3873,6 @@ int ext4_ext_map_blocks(handle_t *handle, struct inode *inode,
/* if found extent covers block, simply return it */
if (in_range(map->m_lblk, ee_block, ee_len)) {
- ext4_fsblk_t partial_cluster = 0;
-
newblock = map->m_lblk - ee_block + ee_start;
/* number of remaining blocks in the extent */
allocated = ee_len - (map->m_lblk - ee_block);
@@ -3835,75 +3894,9 @@ int ext4_ext_map_blocks(handle_t *handle, struct inode *inode,
allocated, newblock);
return ret;
}
-
- /*
- * Punch out the map length, but only to the
- * end of the extent
- */
- punched_out = allocated < map->m_len ?
- allocated : map->m_len;
-
- /*
- * Sense extents need to be converted to
- * uninitialized, they must fit in an
- * uninitialized extent
- */
- if (punched_out > EXT_UNINIT_MAX_LEN)
- punched_out = EXT_UNINIT_MAX_LEN;
-
- punch_map.m_lblk = map->m_lblk;
- punch_map.m_pblk = newblock;
- punch_map.m_len = punched_out;
- punch_map.m_flags = 0;
-
- /* Check to see if the extent needs to be split */
- if (punch_map.m_len != ee_len ||
- punch_map.m_lblk != ee_block) {
-
- ret = ext4_split_extent(handle, inode,
- path, &punch_map, 0,
- EXT4_GET_BLOCKS_PUNCH_OUT_EXT |
- EXT4_GET_BLOCKS_PRE_IO);
-
- if (ret < 0) {
- err = ret;
- goto out2;
- }
- /*
- * find extent for the block at
- * the start of the hole
- */
- ext4_ext_drop_refs(path);
- kfree(path);
-
- path = ext4_ext_find_extent(inode,
- map->m_lblk, NULL);
- if (IS_ERR(path)) {
- err = PTR_ERR(path);
- path = NULL;
- goto out2;
- }
-
- depth = ext_depth(inode);
- ex = path[depth].p_ext;
- ee_len = ext4_ext_get_actual_len(ex);
- ee_block = le32_to_cpu(ex->ee_block);
- ee_start = ext4_ext_pblock(ex);
-
- }
-
- ext4_ext_mark_uninitialized(ex);
-
- ext4_ext_invalidate_cache(inode);
-
- err = ext4_ext_rm_leaf(handle, inode, path,
- &partial_cluster, map->m_lblk,
- map->m_lblk + punched_out);
-
- if (!err && ext4_ext_try_shrink(handle, inode))
- err = ext4_mark_inode_dirty(handle, inode);
next prev parent reply other threads:[~2011-10-28 17:00 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-10-28 17:00 [PATCH 0/7] ext4: cleanups and regression fixes for grow/shrink logic V3 Dmitry Monakhov
2011-10-28 17:00 ` [PATCH 1/7] ext4: Restore old EOFBLOCKS flag state after error Dmitry Monakhov
2011-10-28 17:00 ` [PATCH 2/7] ext4: move inode indepth shrink logic to didicated function Dmitry Monakhov
2011-10-28 17:00 ` Dmitry Monakhov [this message]
2011-10-28 17:00 ` [PATCH 4/7] ext4: punch_hole fix extent conversion Dmitry Monakhov
2011-10-28 17:00 ` [PATCH 5/7] ext4: Update inode's transaction id after punch_hole Dmitry Monakhov
2011-10-28 17:00 ` [PATCH 6/7] ext4: punch hole should be restarted after transaction restart Dmitry Monakhov
2011-10-28 17:00 ` [PATCH 7/7] ext4: update EOFBLOCK flags after punch hole Dmitry Monakhov
2011-11-02 23:12 ` [PATCH 0/7] ext4: cleanups and regression fixes for grow/shrink logic V3 Allison Henderson
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=1319821210-7374-4-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).