linux-ext4.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Robin Dong <hao.bigrat@gmail.com>
To: linux-ext4@vger.kernel.org
Cc: Robin Dong <sanbai@taobao.com>
Subject: [PATCH 8/9 bigalloc] ext4: align fallocate size to a whole cluster
Date: Wed,  9 Nov 2011 19:17:07 +0800	[thread overview]
Message-ID: <1320837428-8516-9-git-send-email-hao.bigrat@gmail.com> (raw)
In-Reply-To: <1320837428-8516-1-git-send-email-hao.bigrat@gmail.com>

From: Robin Dong <sanbai@taobao.com>

Signed-off-by: Robin Dong <sanbai@taobao.com>
---
 fs/ext4/extents.c |   34 ++++++++++++++++++++++++++++++++--
 1 files changed, 32 insertions(+), 2 deletions(-)

diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c
index f84c122..7e3d4c8 100644
--- a/fs/ext4/extents.c
+++ b/fs/ext4/extents.c
@@ -3533,8 +3533,11 @@ ext4_ext_handle_uninitialized_extents(handle_t *handle, struct inode *inode,
 			struct ext4_ext_path *path, int flags,
 			unsigned int allocated, ext4_fsblk_t newblock)
 {
+	struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb);
+	struct ext4_map_blocks convert_map;
 	int ret = 0;
 	int err = 0;
+	int offset;
 	ext4_io_end_t *io = EXT4_I(inode)->cur_aio_dio;
 
 	ext_debug("ext4_ext_handle_uninitialized_extents: inode %lu, logical"
@@ -3598,8 +3601,14 @@ ext4_ext_handle_uninitialized_extents(handle_t *handle, struct inode *inode,
 	}
 
 	/* buffered write, writepage time, convert*/
-	ret = ext4_ext_convert_to_initialized(handle, inode, map, path);
+	offset = map->m_lblk & (sbi->s_cluster_ratio - 1);
+	convert_map.m_len =
+		EXT4_C2B(sbi, EXT4_NUM_B2C(sbi, offset + map->m_len));
+	convert_map.m_lblk = map->m_lblk - offset;
+	ret = ext4_ext_convert_to_initialized(handle, inode,
+			&convert_map, path);
 	if (ret >= 0) {
+		ret = map->m_len;
 		ext4_update_inode_fsync_trans(handle, inode, 1);
 		err = check_eofblocks_fl(handle, inode, map->m_lblk, path,
 					 map->m_len);
@@ -4318,8 +4327,9 @@ static void ext4_falloc_update_inode(struct inode *inode,
 long ext4_fallocate(struct file *file, int mode, loff_t offset, loff_t len)
 {
 	struct inode *inode = file->f_path.dentry->d_inode;
+	struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb);
 	handle_t *handle;
-	loff_t new_size;
+	loff_t new_size, old_size;
 	unsigned int max_blocks;
 	int ret = 0;
 	int ret2 = 0;
@@ -4349,6 +4359,8 @@ long ext4_fallocate(struct file *file, int mode, loff_t offset, loff_t len)
 	 */
 	max_blocks = (EXT4_BLOCK_ALIGN(len + offset, blkbits) >> blkbits)
 		- map.m_lblk;
+
+	old_size = i_size_read(inode);
 	/*
 	 * credits to insert 1 extent into extent tree
 	 */
@@ -4403,6 +4415,24 @@ retry:
 		goto retry;
 	}
 	mutex_unlock(&inode->i_mutex);
+
+	/* if the fallocate expand the file size, we need to zeroout
+	 * extra pages in cluster */
+	if (len + offset > old_size) {
+		credits = ext4_chunk_trans_blocks(inode, sbi->s_cluster_ratio);
+		handle = ext4_journal_start(inode, credits);
+		if (IS_ERR(handle)) {
+			ret = PTR_ERR(handle);
+			goto out;
+		}
+		ext4_ext_truncate_zero_pages(handle, inode, old_size);
+		if (IS_SYNC(inode))
+			ext4_handle_sync(handle);
+		ext4_mark_inode_dirty(handle, inode);
+		ext4_journal_stop(handle);
+	}
+
+out:
 	trace_ext4_fallocate_exit(inode, offset, max_blocks,
 				ret > 0 ? ret2 : ret);
 	return ret > 0 ? ret2 : ret;
-- 
1.7.3.2


  parent reply	other threads:[~2011-11-09 11:17 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-11-09 11:16 [PATCH 0/9 bigalloc] ext4: change unit of extent's ee_block and ee_len from block to cluster Robin Dong
2011-11-09 11:17 ` [PATCH 1/9 bigalloc] ext4: get blocks from ext4_ext_get_actual_blocks Robin Dong
2011-11-09 11:17 ` [PATCH 2/9 bigalloc] ext4: change ext4_ext_map_blocks to allocate clusters instead of blocks Robin Dong
2011-11-09 11:17 ` [PATCH 3/9 bigalloc] ext4: change unit of ee_block of extent to cluster Robin Dong
2011-11-09 11:17 ` [PATCH 4/9] ext4: remove unused functions and tags Robin Dong
2011-11-09 11:17 ` [PATCH 5/9 bigalloc] ext4: zero out extra pages when users write one page Robin Dong
2011-11-09 11:17 ` [PATCH 6/9 bigalloc] ext4: zero out extra pages when truncate file Robin Dong
2011-11-09 11:17 ` [PATCH 7/9 bigalloc] ext4: allocate a cluster for a directory when it need spaces Robin Dong
2011-11-09 11:17 ` Robin Dong [this message]
2011-11-09 11:17 ` [PATCH 9/9 bigalloc] ext4: make cluster works for mmap Robin Dong

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=1320837428-8516-9-git-send-email-hao.bigrat@gmail.com \
    --to=hao.bigrat@gmail.com \
    --cc=linux-ext4@vger.kernel.org \
    --cc=sanbai@taobao.com \
    /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).