From: Jan Kara <jack@suse.cz>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: LKML <linux-kernel@vger.kernel.org>,
hch@infradead.org, Jan Kara <jack@suse.cz>,
reiserfs-devel@vger.kernel.org, jeffm@suse.com
Subject: [PATCH] reiserfs: Truncate blocks not used by a write (v2)
Date: Wed, 16 Sep 2009 19:25:12 +0200 [thread overview]
Message-ID: <1253121912-20718-1-git-send-email-jack@suse.cz> (raw)
It can happen that write does not use all the blocks allocated in write_begin
either because of some filesystem error (like ENOSPC) or because page with
data to write has been removed from memory. We truncate these blocks so that
we don't have dangling blocks beyond i_size.
CC: reiserfs-devel@vger.kernel.org
CC: jeffm@suse.com
Signed-off-by: Jan Kara <jack@suse.cz>
---
fs/reiserfs/inode.c | 11 ++++++++---
1 files changed, 8 insertions(+), 3 deletions(-)
Next try, this time without vmtruncate() as Christoph asked.
diff --git a/fs/reiserfs/inode.c b/fs/reiserfs/inode.c
index a14d6cd..a83280f 100644
--- a/fs/reiserfs/inode.c
+++ b/fs/reiserfs/inode.c
@@ -2597,6 +2597,8 @@ static int reiserfs_write_begin(struct file *file,
if (ret) {
unlock_page(page);
page_cache_release(page);
+ /* Truncate allocated blocks */
+ reiserfs_truncate_file(inode, 0);
}
return ret;
}
@@ -2689,8 +2691,7 @@ static int reiserfs_write_end(struct file *file, struct address_space *mapping,
** transaction tracking stuff when the size changes. So, we have
** to do the i_size updates here.
*/
- pos += copied;
- if (pos > inode->i_size) {
+ if (pos + copied > inode->i_size) {
struct reiserfs_transaction_handle myth;
reiserfs_write_lock(inode->i_sb);
/* If the file have grown beyond the border where it
@@ -2708,7 +2709,7 @@ static int reiserfs_write_end(struct file *file, struct address_space *mapping,
goto journal_error;
}
reiserfs_update_inode_transaction(inode);
- inode->i_size = pos;
+ inode->i_size = pos + copied;
/*
* this will just nest into our transaction. It's important
* to use mark_inode_dirty so the inode gets pushed around on the
@@ -2735,6 +2736,10 @@ static int reiserfs_write_end(struct file *file, struct address_space *mapping,
out:
unlock_page(page);
page_cache_release(page);
+
+ if (pos + len > inode->i_size)
+ reiserfs_truncate_file(inode, 0);
+
return ret == 0 ? copied : ret;
journal_error:
--
1.6.0.2
next reply other threads:[~2009-09-16 17:25 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-09-16 17:25 Jan Kara [this message]
2009-09-16 21:48 ` Andrew Morton
2009-09-17 0:56 ` Frederic Weisbecker
2009-09-17 1:56 ` Stephen Rothwell
2009-10-08 12:48 ` Frederic Weisbecker
2009-10-08 23:11 ` Stephen Rothwell
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=1253121912-20718-1-git-send-email-jack@suse.cz \
--to=jack@suse.cz \
--cc=akpm@linux-foundation.org \
--cc=hch@infradead.org \
--cc=jeffm@suse.com \
--cc=linux-kernel@vger.kernel.org \
--cc=reiserfs-devel@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
all inboxes | Powered by JetHome®