From: Yongqiang Yang <xiaoqiangnk@gmail.com>
To: linux-ext4@vger.kernel.org
Cc: achender@linux.vnet.ibm.com, cmm@us.ibm.com,
Yongqiang Yang <xiaoqiangnk@gmail.com>
Subject: [PATCH RFC v1 4/5] ext4: Add a function ext4_ext_zeroout_mem().
Date: Sat, 23 Apr 2011 01:44:18 -0700 [thread overview]
Message-ID: <1303548259-28311-5-git-send-email-xiaoqiangnk@gmail.com> (raw)
In-Reply-To: <1303548259-28311-1-git-send-email-xiaoqiangnk@gmail.com>
ext4_ext_zeroout_mem() zero out blocks in mem.
Signed-off-by: Yongqiang Yang <xiaoqiangnk@gmail.com>
---
fs/ext4/extents.c | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 70 insertions(+), 0 deletions(-)
diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c
index 9e7c7b3..30663b6 100644
--- a/fs/ext4/extents.c
+++ b/fs/ext4/extents.c
@@ -2555,6 +2555,76 @@ static int ext4_ext_zeroout(struct inode *inode, struct ext4_extent *ex)
}
/*
+ * ext4_ext_zeroout_mem() zero specified pages in page cache.
+ * this function is used by ext4_ext_convert_to_initialized() to
+ * zeroout small extents.
+ *
+ * @inode: the file inode
+ * @ex: the extent to be zeroout
+ *
+ * return 0 on success
+ */
+static int ext4_ext_zeroout_mem(struct inode *inode,
+ struct ext4_extent *ex)
+{
+ ext4_fsblk_t pblk;
+ ext4_lblk_t lblk;
+ ext4_lblk_t end;
+ struct page *page;
+ struct buffer_head *bh;
+ struct block_device *bdev;
+ pgoff_t index;
+ unsigned blocksize, blks_per_page_bits;
+
+ bdev = inode->i_sb->s_bdev;
+
+ blocksize = 1 << inode->i_blkbits;
+ blks_per_page_bits = PAGE_CACHE_SHIFT - inode->i_blkbits;
+
+ pblk = ext4_ext_pblock(ex);
+ lblk = le32_to_cpu(ex->ee_block);
+ end = lblk + ext4_ext_get_actual_len(ex);
+
+ while (lblk < end) {
+ struct ext4_extent ext;
+ char *kaddr;
+
+ /* grab page */
+ index = lblk >> blks_per_page_bits;
+ page = grab_cache_page_write_begin(inode->i_mapping,
+ index, AOP_FLAG_NOFS);
+ if (!page) {
+ ext.ee_block = cpu_to_le32(lblk);
+ ext.ee_len = cpu_to_le16(end - lblk);
+ ext4_ext_store_pblock(&ext, pblk);
+ return ext4_ext_zeroout(inode, &ext);
+ }
+
+ /* map buffers, mark dirty */
+ if (!page_has_buffers(page))
+ create_empty_buffers(page, blocksize, 0);
+
+ kaddr = kmap_atomic(page, KM_USER0);
+ bh = page_buffers(page);
+ do {
+ unmap_underlying_metadata(bdev, pblk);
+ memset(kaddr, 0, blocksize);
+ map_bh(bh, inode->i_sb, pblk++);
+ set_buffer_uptodate(bh);
+ mark_buffer_dirty(bh);
+ bh = bh->b_this_page;
+ lblk++;
+ } while (bh != page_buffers(page) && lblk < end);
+ kunmap_atomic(kaddr, KM_USER0);
+
+ unlock_page(page);
+ page_cache_release(page);
+ }
+
+ return 0;
+}
+
+/*
* used by extent splitting.
*/
#define EXT4_EXT_MAY_ZEROOUT 0x1 /* safe to zeroout if split fails \
--
1.7.4.4
next prev parent reply other threads:[~2011-04-23 8:47 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-04-23 8:44 [PATCH RFC v1 0/5]Factor common code from convert and split unwritten Yongqiang Yang
2011-04-23 8:44 ` [PATCH RFC v1 1/5] ext4:Add a function merging extent right and left Yongqiang Yang
2011-04-23 8:44 ` [PATCH RFC v1 2/5] ext4:Add two functions splitting an extent Yongqiang Yang
2011-04-23 8:44 ` [PATCH RFC v1 3/5] ext4:Reimplement convert and split_unwritten Yongqiang Yang
2011-04-23 8:44 ` Yongqiang Yang [this message]
2011-04-23 8:44 ` [PATCH RFC v1 5/5] ext4: optimize ext4_ext_convert_to_initialized() Yongqiang Yang
2011-04-26 19:08 ` [PATCH RFC v1 0/5]Factor common code from convert and split unwritten Allison Henderson
2011-04-27 1:14 ` Yongqiang Yang
2011-04-27 4:48 ` Yongqiang Yang
2011-04-27 6:34 ` Allison Henderson
2011-04-27 7:19 ` Yongqiang Yang
2011-04-28 6:05 ` Yongqiang Yang
2011-04-28 19:51 ` Allison Henderson
2011-04-29 19:16 ` Allison Henderson
2011-04-29 19:42 ` Yongqiang Yang
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=1303548259-28311-5-git-send-email-xiaoqiangnk@gmail.com \
--to=xiaoqiangnk@gmail.com \
--cc=achender@linux.vnet.ibm.com \
--cc=cmm@us.ibm.com \
--cc=linux-ext4@vger.kernel.org \
/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).