From: Miao Xie <miaox@cn.fujitsu.com>
To: linux-btrfs@vger.kernel.org
Subject: [PATCH 2/9] Btrfs: fix the skipped transaction commit during the file sync
Date: Thu, 20 Feb 2014 18:08:52 +0800 [thread overview]
Message-ID: <1392890939-19044-2-git-send-email-miaox@cn.fujitsu.com> (raw)
In-Reply-To: <1392890939-19044-1-git-send-email-miaox@cn.fujitsu.com>
We may abort the wait earlier if ->last_trans_log_full_commit was set to
the current transaction id, at this case, we need commit the current
transaction instead of the log sub-transaction. But the current code
didn't tell the caller to do it (return 0, not -EAGAIN). Fix it.
Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
---
fs/btrfs/tree-log.c | 26 ++++++++++++++++----------
1 file changed, 16 insertions(+), 10 deletions(-)
diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c
index 5a4e10b..8a03b39 100644
--- a/fs/btrfs/tree-log.c
+++ b/fs/btrfs/tree-log.c
@@ -2364,6 +2364,7 @@ static int wait_log_commit(struct btrfs_trans_handle *trans,
{
DEFINE_WAIT(wait);
int index = transid % 2;
+ int ret = 0;
/*
* we only allow two pending log transactions at a time,
@@ -2371,21 +2372,26 @@ static int wait_log_commit(struct btrfs_trans_handle *trans,
* current transaction, we're done
*/
do {
+ if (ACCESS_ONCE(root->fs_info->last_trans_log_full_commit) ==
+ trans->transid) {
+ ret = -EAGAIN;
+ break;
+ }
+
prepare_to_wait(&root->log_commit_wait[index],
&wait, TASK_UNINTERRUPTIBLE);
mutex_unlock(&root->log_mutex);
- if (ACCESS_ONCE(root->fs_info->last_trans_log_full_commit) !=
- trans->transid && root->log_transid < transid + 2 &&
+ if (root->log_transid < transid + 2 &&
atomic_read(&root->log_commit[index]))
schedule();
finish_wait(&root->log_commit_wait[index], &wait);
mutex_lock(&root->log_mutex);
- } while (ACCESS_ONCE(root->fs_info->last_trans_log_full_commit) !=
- trans->transid && root->log_transid < transid + 2 &&
+ } while (root->log_transid < transid + 2 &&
atomic_read(&root->log_commit[index]));
- return 0;
+
+ return ret;
}
static void wait_for_writer(struct btrfs_trans_handle *trans,
@@ -2433,15 +2439,16 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans,
log_transid = root->log_transid;
index1 = root->log_transid % 2;
if (atomic_read(&root->log_commit[index1])) {
- wait_log_commit(trans, root, root->log_transid);
+ ret = wait_log_commit(trans, root, root->log_transid);
mutex_unlock(&root->log_mutex);
- return 0;
+ return ret;
}
atomic_set(&root->log_commit[index1], 1);
/* wait for previous tree log sync to complete */
if (atomic_read(&root->log_commit[(index1 + 1) % 2]))
wait_log_commit(trans, root, root->log_transid - 1);
+
while (1) {
int batch = atomic_read(&root->log_batch);
/* when we're on an ssd, just kick the log commit out */
@@ -2529,11 +2536,10 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans,
if (atomic_read(&log_root_tree->log_commit[index2])) {
blk_finish_plug(&plug);
btrfs_wait_marked_extents(log, &log->dirty_log_pages, mark);
- wait_log_commit(trans, log_root_tree,
- log_root_tree->log_transid);
+ ret = wait_log_commit(trans, log_root_tree,
+ log_root_tree->log_transid);
btrfs_free_logged_extents(log, log_transid);
mutex_unlock(&log_root_tree->log_mutex);
- ret = 0;
goto out;
}
atomic_set(&log_root_tree->log_commit[index2], 1);
--
1.8.1.4
next prev parent reply other threads:[~2014-02-20 10:07 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-02-20 10:08 [PATCH 1/9] Btrfs: use ACCESS_ONCE to prevent the optimize accesses to ->last_trans_log_full_commit Miao Xie
2014-02-20 10:08 ` Miao Xie [this message]
2014-02-20 10:08 ` [PATCH 3/9] Btrfs: don't start the log transaction if the log tree init fails Miao Xie
2014-02-20 10:08 ` [PATCH 4/9] Btrfs: use bitfield instead of integer data type for the some variants in btrfs_root Miao Xie
2014-02-22 0:23 ` David Sterba
2014-02-26 9:10 ` Miao Xie
2014-02-27 17:02 ` David Sterba
2014-03-07 23:54 ` Josef Bacik
2014-03-08 0:00 ` Josef Bacik
2014-03-10 1:16 ` Miao Xie
2014-02-20 10:08 ` [PATCH 5/9] Btrfs: remove unnecessary memory barrier in btrfs_sync_log() Miao Xie
2014-02-20 10:08 ` [PATCH 6/9] Btrfs: use signed integer instead of unsigned long integer for log transid Miao Xie
2014-02-20 10:08 ` [PATCH 7/9] Btrfs: stop joining the log transaction if sync log fails Miao Xie
2014-02-22 0:27 ` David Sterba
2014-02-26 8:51 ` Miao Xie
2014-02-20 10:08 ` [PATCH 8/9] Btrfs: fix skipped error handle when log sync failed Miao Xie
2014-02-20 10:08 ` [PATCH 9/9] Btrfs: just wait or commit our own log sub-transaction Miao Xie
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=1392890939-19044-2-git-send-email-miaox@cn.fujitsu.com \
--to=miaox@cn.fujitsu.com \
--cc=linux-btrfs@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