From: Liu Bo <bo.li.liu@oracle.com>
To: linux-btrfs@vger.kernel.org
Subject: [PATCH 1/5] Btrfs: fix deadlock with freeze and sync
Date: Fri, 14 Sep 2012 16:58:03 +0800 [thread overview]
Message-ID: <1347613087-3489-1-git-send-email-bo.li.liu@oracle.com> (raw)
While testing xfstests 068, I realized that
commit bd7de2c9a449e26a5493d918618eb20ae60d56bd
(Btrfs: fix deadlock with freeze and sync V2)
did not fix the bug yet, since someone might jump in between checking
running transaction and joining transaction, and we may still run into
deadlock between freeze and sync.
So IMO the safest and most efficient way is to check running transaction
in joining a transaction directly.
With this patch, I tested xfstests 068 for 120 times and it did not get
into deadlock at least here.
Signed-off-by: Liu Bo <bo.li.liu@oracle.com>
---
fs/btrfs/super.c | 9 +--------
fs/btrfs/transaction.c | 11 ++++++++++-
fs/btrfs/transaction.h | 1 +
3 files changed, 12 insertions(+), 9 deletions(-)
diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
index abb9081..02a3961 100644
--- a/fs/btrfs/super.c
+++ b/fs/btrfs/super.c
@@ -852,14 +852,7 @@ int btrfs_sync_fs(struct super_block *sb, int wait)
btrfs_wait_ordered_extents(root, 0, 0);
- spin_lock(&fs_info->trans_lock);
- if (!fs_info->running_transaction) {
- spin_unlock(&fs_info->trans_lock);
- return 0;
- }
- spin_unlock(&fs_info->trans_lock);
-
- trans = btrfs_join_transaction(root);
+ trans = btrfs_join_transaction_only(root);
if (IS_ERR(trans))
return PTR_ERR(trans);
return btrfs_commit_transaction(trans, root);
diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c
index 27c2600..0c17d9e 100644
--- a/fs/btrfs/transaction.c
+++ b/fs/btrfs/transaction.c
@@ -272,6 +272,7 @@ enum btrfs_trans_type {
TRANS_JOIN,
TRANS_USERSPACE,
TRANS_JOIN_NOLOCK,
+ TRANS_JOIN_ONLY,
};
static int may_wait_transaction(struct btrfs_root *root, int type)
@@ -302,12 +303,15 @@ static struct btrfs_trans_handle *start_transaction(struct btrfs_root *root,
return ERR_PTR(-EROFS);
if (current->journal_info) {
- WARN_ON(type != TRANS_JOIN && type != TRANS_JOIN_NOLOCK);
+ WARN_ON(type != TRANS_JOIN && type != TRANS_JOIN_NOLOCK &&
+ type != TRANS_JOIN_ONLY);
h = current->journal_info;
h->use_count++;
h->orig_rsv = h->block_rsv;
h->block_rsv = NULL;
goto got_it;
+ } else if (type == TRANS_JOIN_ONLY) {
+ return ERR_PTR(-ENOENT);
}
/*
@@ -405,6 +409,11 @@ struct btrfs_trans_handle *btrfs_join_transaction_nolock(struct btrfs_root *root
return start_transaction(root, 0, TRANS_JOIN_NOLOCK);
}
+struct btrfs_trans_handle *btrfs_join_transaction_only(struct btrfs_root *root)
+{
+ return start_transaction(root, 0, TRANS_JOIN_ONLY);
+}
+
struct btrfs_trans_handle *btrfs_start_ioctl_transaction(struct btrfs_root *root)
{
return start_transaction(root, 0, TRANS_USERSPACE);
diff --git a/fs/btrfs/transaction.h b/fs/btrfs/transaction.h
index e8b8416..59adf55 100644
--- a/fs/btrfs/transaction.h
+++ b/fs/btrfs/transaction.h
@@ -98,6 +98,7 @@ struct btrfs_trans_handle *btrfs_start_transaction(struct btrfs_root *root,
int num_items);
struct btrfs_trans_handle *btrfs_join_transaction(struct btrfs_root *root);
struct btrfs_trans_handle *btrfs_join_transaction_nolock(struct btrfs_root *root);
+struct btrfs_trans_handle *btrfs_join_transaction_only(struct btrfs_root *root);
struct btrfs_trans_handle *btrfs_start_ioctl_transaction(struct btrfs_root *root);
int btrfs_wait_for_commit(struct btrfs_root *root, u64 transid);
int btrfs_write_and_wait_transaction(struct btrfs_trans_handle *trans,
--
1.7.7.6
next reply other threads:[~2012-09-14 9:00 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-09-14 8:58 Liu Bo [this message]
2012-09-14 8:58 ` [PATCH 2/5] Btrfs: fix trans block rsv regression Liu Bo
2012-09-14 11:15 ` David Sterba
2012-09-14 11:25 ` Liu Bo
2012-09-14 12:07 ` David Sterba
2012-09-14 12:16 ` Liu Bo
2012-09-14 12:41 ` Josef Bacik
2012-09-14 13:01 ` Liu Bo
2012-09-14 13:05 ` Liu Bo
2012-09-23 10:08 ` Miao Xie
2012-09-14 13:26 ` David Sterba
2012-09-14 8:58 ` [PATCH 3/5] Btrfs: cleanup for duplicated code in find_free_extent Liu Bo
2012-09-14 11:36 ` David Sterba
2012-09-14 8:58 ` [PATCH 4/5] Btrfs: cleanup fs_info->hashers Liu Bo
2012-09-14 11:21 ` David Sterba
2012-09-14 8:58 ` [PATCH 5/5] Btrfs: kill obsolete arguments in btrfs_wait_ordered_extents Liu Bo
2012-09-14 12:45 ` Josef Bacik
2012-09-14 12:55 ` Liu Bo
2012-09-14 13:01 ` Josef Bacik
2012-09-14 13:09 ` David Sterba
2012-09-14 10:07 ` [PATCH 1/5] Btrfs: fix deadlock with freeze and sync Miao Xie
2012-09-14 11:30 ` Liu Bo
2012-09-14 12:42 ` Josef Bacik
2012-09-14 13:03 ` Liu Bo
2012-09-14 14:41 ` Josef Bacik
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=1347613087-3489-1-git-send-email-bo.li.liu@oracle.com \
--to=bo.li.liu@oracle.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;
as well as URLs for NNTP newsgroup(s).