From: Vyacheslav Dubeyko <slava@dubeyko.com>
To: linux-nilfs@vger.kernel.org
Cc: Ryusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>,
linux-fsdevel@vger.kernel.org,
Andrew Morton <akpm@linux-foundation.org>
Subject: [PATCH] nilfs2: add logic for the case of file growing (old size <= new size) in nilfs_truncate()
Date: Wed, 24 Apr 2013 15:44:26 +0400 [thread overview]
Message-ID: <1366803866.2146.2.camel@slavad-ubuntu> (raw)
From: Vyacheslav Dubeyko <slava@dubeyko.com>
Subject: [PATCH] nilfs2: add logic for the case of file growing (old size <= new size) in nilfs_truncate()
There are situations when nilfs_truncate() is called with new value of i_size that is greater than old one. This patch adds logic for such case.
Signed-off-by: Vyacheslav Dubeyko <slava@dubeyko.com>
CC: Ryusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>
---
fs/nilfs2/inode.c | 30 ++++++++++++++++++++++++++++++
1 file changed, 30 insertions(+)
diff --git a/fs/nilfs2/inode.c b/fs/nilfs2/inode.c
index 6b49f14..5ccaace 100644
--- a/fs/nilfs2/inode.c
+++ b/fs/nilfs2/inode.c
@@ -698,6 +698,36 @@ void nilfs_truncate(struct inode *inode)
blocksize = sb->s_blocksize;
blkoff = (inode->i_size + blocksize - 1) >> sb->s_blocksize_bits;
+
+ if (blkoff > inode->i_blocks) {
+ int err;
+ struct address_space *mapping = inode->i_mapping;
+ struct page *page;
+ void *fsdata;
+ loff_t size = inode->i_size;
+
+ err = pagecache_write_begin(NULL, mapping, size, 0,
+ AOP_FLAG_UNINTERRUPTIBLE,
+ &page, &fsdata);
+ if (err) {
+ printk(KERN_ERR
+ "NILFS: pagecache_write_begin() failed: err %d",
+ err);
+ return;
+ }
+ err = pagecache_write_end(NULL, mapping, size,
+ 0, 0, page, fsdata);
+ if (err < 0) {
+ printk(KERN_ERR
+ "NILFS: pagecache_write_end() failed: err %d",
+ err);
+ return;
+ }
+ mark_inode_dirty(inode);
+ return;
+ } else if (blkoff == inode->i_blocks)
+ return;
+
nilfs_transaction_begin(sb, &ti, 0); /* never fails */
block_truncate_page(inode->i_mapping, inode->i_size, nilfs_get_block);
--
1.7.9.5
next reply other threads:[~2013-04-24 11:44 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-04-24 11:44 Vyacheslav Dubeyko [this message]
2013-04-24 15:48 ` [PATCH] nilfs2: add logic for the case of file growing (old size <= new size) in nilfs_truncate() Ryusuke Konishi
2013-04-25 9:58 ` Vyacheslav Dubeyko
2013-04-26 17:19 ` Ryusuke Konishi
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=1366803866.2146.2.camel@slavad-ubuntu \
--to=slava@dubeyko.com \
--cc=akpm@linux-foundation.org \
--cc=konishi.ryusuke@lab.ntt.co.jp \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-nilfs@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).