From: Jan Kara <jack@suse.cz>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: reiserfs-devel@vger.kernel.org, jeffm@suse.com,
LKML <linux-kernel@vger.kernel.org>
Subject: [PATCH] reiserfs: Truncate blocks not used by a write
Date: Tue, 1 Sep 2009 17:55:54 +0200 [thread overview]
Message-ID: <20090901155554.GD8242@duck.novell.com> (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.
Signed-off-by: Jan Kara <jack@suse.cz>
---
Andrew, would you merge the patch please? Thanks.
diff -rupX /home/jack/.kerndiffexclude linux-2.6.27-SLE11_BRANCH/fs/reiserfs/inode.c linux-2.6.27-SLE11_BRANCH-1-reiserfs_corruption//fs/reiserfs/inode.c
--- linux-2.6.27-SLE11_BRANCH/fs/reiserfs/inode.c 2009-06-02 17:14:29.000000000 +0200
+++ linux-2.6.27-SLE11_BRANCH-1-reiserfs_corruption//fs/reiserfs/inode.c 2009-06-24 14:39:44.000000000 +0200
@@ -2606,6 +2610,8 @@ static int reiserfs_write_begin(struct f
if (ret) {
unlock_page(page);
page_cache_release(page);
+ /* Truncate allocated blocks */
+ vmtruncate(inode, inode->i_size);
}
return ret;
}
@@ -2698,8 +2705,7 @@ static int reiserfs_write_end(struct fil
** 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
@@ -2717,7 +2723,7 @@ static int reiserfs_write_end(struct fil
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
@@ -2744,6 +2750,10 @@ static int reiserfs_write_end(struct fil
out:
unlock_page(page);
page_cache_release(page);
+
+ if (pos + len > inode->i_size)
+ vmtruncate(inode, inode->i_size);
+
return ret == 0 ? copied : ret;
journal_error:
next reply other threads:[~2009-09-01 15:55 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-09-01 15:55 Jan Kara [this message]
2009-09-01 17:42 ` [PATCH] reiserfs: Truncate blocks not used by a write Christoph Hellwig
2009-09-01 18:10 ` Jan Kara
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=20090901155554.GD8242@duck.novell.com \
--to=jack@suse.cz \
--cc=akpm@linux-foundation.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;
as well as URLs for NNTP newsgroup(s).