From: Yongqiang Yang <xiaoqiangnk@gmail.com>
To: tytso@mit.edu
Cc: linux-ext4@vger.kernel.org, Yongqiang Yang <xiaoqiangnk@gmail.com>
Subject: [PATCH 5/5] jbd2: clear revoked flag on buffers before a new transaction started
Date: Tue, 15 Nov 2011 16:07:54 +0800 [thread overview]
Message-ID: <1321344474-14707-5-git-send-email-xiaoqiangnk@gmail.com> (raw)
In-Reply-To: <1321344474-14707-1-git-send-email-xiaoqiangnk@gmail.com>
A revoked block in a transaction means the block is deleted by filesystem
in the transaction. If the block is reused in the same transaction, we
need to cancel revoke status of the block. We also should prohibit a block
from being revoked more than once in a transaction. So we need to look up
the revoke table to check if a given block is revoked, to acceletate the
looking up, jbd/jbd2 use revoked flag to cache status of a block.
Ok, we should clear revoked flag once the transaction is not running. Because
the revoking and cancelling revoke operate on a running transaction. Once
a transaction is non-running, revoked flag is useless.
Without this patch, the following case triggers a false journal error.
Given that a block is used as a meta block and is deleted(revoked) in ordered
mode, then the block is allocated as a data block to a file. Up to now,
user changes the file's journal mode from ordered to journaled, then truncates
the file. The block will be considered re-revoked by journal because it
has revoked flag in last transaction.
Signed-off-by: Yongqiang Yang <xiaoqiangnk@gmail.com>
---
fs/ext4/ext4_jbd2.c | 5 +++++
fs/jbd2/commit.c | 5 +++++
fs/jbd2/revoke.c | 28 ++++++++++++++++++++++++++++
include/linux/jbd2.h | 1 +
4 files changed, 39 insertions(+), 0 deletions(-)
diff --git a/fs/ext4/ext4_jbd2.c b/fs/ext4/ext4_jbd2.c
index aca1790..c69baa0 100644
--- a/fs/ext4/ext4_jbd2.c
+++ b/fs/ext4/ext4_jbd2.c
@@ -47,6 +47,11 @@ int __ext4_forget(const char *where, unsigned int line, handle_t *handle,
"data mode %x\n",
bh, is_metadata, inode->i_mode,
test_opt(inode->i_sb, DATA_FLAGS));
+ if (bh)
+ printk("forgetting bh %p: is_metadata = %d, mode %o, "
+ "data mode %x\n",
+ bh, is_metadata, inode->i_mode,
+ test_opt(inode->i_sb, DATA_FLAGS));
/* In the no journal case, we can just do a bforget and return */
if (!ext4_handle_valid(handle)) {
diff --git a/fs/jbd2/commit.c b/fs/jbd2/commit.c
index 264f0bb..ec63df5 100644
--- a/fs/jbd2/commit.c
+++ b/fs/jbd2/commit.c
@@ -430,6 +430,11 @@ void jbd2_journal_commit_transaction(journal_t *journal)
jbd_debug (3, "JBD: commit phase 1\n");
/*
+ * Clear revoked flag.
+ */
+ journal_clear_revoked_flag(journal);
+
+ /*
* Switch to a new revoke table.
*/
jbd2_journal_switch_revoke_table(journal);
diff --git a/fs/jbd2/revoke.c b/fs/jbd2/revoke.c
index 1b67105..dca50c6 100644
--- a/fs/jbd2/revoke.c
+++ b/fs/jbd2/revoke.c
@@ -474,6 +474,34 @@ int jbd2_journal_cancel_revoke(handle_t *handle, struct journal_head *jh)
return did_revoke;
}
+/* journal_clear_revoked_flag clears revoked flag of buffers in
+ * revoke table.
+ */
+void journal_clear_revoked_flag(journal_t *journal)
+{
+ struct jbd2_revoke_table_s *revoke = journal->j_revoke;
+ int i = 0;
+
+ for (i = 0; i < revoke->hash_size; i++) {
+ struct list_head *hash_list;
+ struct list_head *list_entry;
+ hash_list = &revoke->hash_table[i];
+
+ list_for_each(list_entry, hash_list) {
+ struct jbd2_revoke_record_s *record;
+ struct buffer_head *bh;
+ record = (struct jbd2_revoke_record_s *)list_entry;
+ bh = __find_get_block(journal->j_fs_dev,
+ record->blocknr,
+ journal->j_blocksize);
+ if (bh) {
+ clear_buffer_revoked(bh);
+ __brelse(bh);
+ }
+ }
+ }
+}
+
/* journal_switch_revoke table select j_revoke for next transaction
* we do not want to suspend any processing until all revokes are
* written -bzzz
diff --git a/include/linux/jbd2.h b/include/linux/jbd2.h
index e44d114..4891a4d 100644
--- a/include/linux/jbd2.h
+++ b/include/linux/jbd2.h
@@ -1156,6 +1156,7 @@ extern int jbd2_journal_set_revoke(journal_t *, unsigned long long, tid_t);
extern int jbd2_journal_test_revoke(journal_t *, unsigned long long, tid_t);
extern void jbd2_journal_clear_revoke(journal_t *);
extern void jbd2_journal_switch_revoke_table(journal_t *journal);
+extern void journal_clear_revoked_flag(journal_t *journal);
/*
* The log thread user interface:
--
1.7.5.1
next prev parent reply other threads:[~2011-11-15 10:32 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-11-15 8:07 [PATCH 1/5] ext4: allocate delalloc blocks before changing journal mode Yongqiang Yang
2011-11-15 8:07 ` [PATCH 2/5] ext4: let ext4 journal deletion of data blocks Yongqiang Yang
2011-12-28 17:23 ` Ted Ts'o
2011-12-30 14:59 ` Yongqiang Yang
2011-12-30 15:05 ` Ted Ts'o
2011-11-15 8:07 ` [PATCH 3/5] ext4: let ext4_free_blocks handle multiblock correctly Yongqiang Yang
2011-12-28 17:23 ` Ted Ts'o
2011-11-15 8:07 ` [PATCH 4/5] ext4: flush journal when switching from journal data mode Yongqiang Yang
2011-12-28 18:56 ` Ted Ts'o
2011-12-29 21:01 ` Darrick J. Wong
2011-12-30 14:43 ` Yongqiang Yang
2011-12-30 14:57 ` Ted Ts'o
2011-11-15 8:07 ` Yongqiang Yang [this message]
2011-12-28 23:25 ` [PATCH 5/5] jbd2: clear revoked flag on buffers before a new transaction started Ted Ts'o
2011-12-09 3:31 ` [PATCH 1/5] ext4: allocate delalloc blocks before changing journal mode Toshiyuki Okajima
2011-12-28 17:14 ` Ted Ts'o
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=1321344474-14707-5-git-send-email-xiaoqiangnk@gmail.com \
--to=xiaoqiangnk@gmail.com \
--cc=linux-ext4@vger.kernel.org \
--cc=tytso@mit.edu \
/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).