From: Josef Bacik <josef@redhat.com>
To: linux-btrfs@vger.kernel.org
Subject: [PATCH 2/4] Btrfs: track transaction aborted across the fs_info
Date: Thu, 31 May 2012 16:04:14 -0400 [thread overview]
Message-ID: <1338494656-12232-2-git-send-email-josef@redhat.com> (raw)
In-Reply-To: <1338494656-12232-1-git-send-email-josef@redhat.com>
If we abort a transaction during the commit phase we can have people who
start new transactions because we nave no way of signaling to them that
something went wrong. So add a trans_aborted flag to the fs_info so the
start transaction code can be notified that the last transaction was aborted
and it needs to return an error. Thanks,
Signed-off-by: Josef Bacik <josef@redhat.com>
---
fs/btrfs/ctree.h | 1 +
fs/btrfs/super.c | 1 +
fs/btrfs/transaction.c | 14 ++++++++++++++
3 files changed, 16 insertions(+), 0 deletions(-)
diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index 5f2c6d1..34549ca 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -1213,6 +1213,7 @@ struct btrfs_fs_info {
int log_root_recovering;
int enospc_unlink;
int trans_no_join;
+ int trans_aborted;
u64 total_pinned;
diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
index 85cef50..e0abe7f 100644
--- a/fs/btrfs/super.c
+++ b/fs/btrfs/super.c
@@ -226,6 +226,7 @@ void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
return;
}
trans->transaction->aborted = errno;
+ root->fs_info->trans_aborted = errno;
__btrfs_std_error(root->fs_info, function, line, errno, NULL);
}
/*
diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c
index 4e6f63e..e292b83 100644
--- a/fs/btrfs/transaction.c
+++ b/fs/btrfs/transaction.c
@@ -77,13 +77,21 @@ loop:
if (cur_trans->aborted) {
spin_unlock(&root->fs_info->trans_lock);
return cur_trans->aborted;
+ } else if (root->fs_info->trans_aborted) {
+ WARN_ON(1);
+ spin_unlock(&root->fs_info->trans_lock);
+ return root->fs_info->trans_aborted;
}
atomic_inc(&cur_trans->use_count);
atomic_inc(&cur_trans->num_writers);
cur_trans->num_joined++;
spin_unlock(&root->fs_info->trans_lock);
return 0;
+ } else if (root->fs_info->trans_aborted) {
+ spin_unlock(&root->fs_info->trans_lock);
+ return root->fs_info->trans_aborted;
}
+
spin_unlock(&root->fs_info->trans_lock);
cur_trans = kmem_cache_alloc(btrfs_transaction_cachep, GFP_NOFS);
@@ -99,6 +107,10 @@ loop:
kmem_cache_free(btrfs_transaction_cachep, cur_trans);
cur_trans = root->fs_info->running_transaction;
goto loop;
+ } else if (root->fs_info->trans_aborted) {
+ spin_unlock(&root->fs_info->trans_lock);
+ kmem_cache_free(btrfs_transaction_cachep, cur_trans);
+ return root->fs_info->trans_aborted;
}
atomic_set(&cur_trans->num_writers, 1);
@@ -1209,6 +1221,8 @@ static void cleanup_transaction(struct btrfs_trans_handle *trans,
root->fs_info->running_transaction = NULL;
root->fs_info->trans_no_join = 0;
}
+ if (!root->fs_info->trans_aborted)
+ root->fs_info->trans_aborted = -EROFS;
spin_unlock(&root->fs_info->trans_lock);
btrfs_cleanup_one_transaction(trans->transaction, root);
--
1.7.7.6
next prev parent reply other threads:[~2012-05-31 20:04 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-05-31 20:04 [PATCH 1/4] Btrfs: wake up transaction waiters when aborting a transaction Josef Bacik
2012-05-31 20:04 ` Josef Bacik [this message]
2012-06-01 1:22 ` [PATCH 2/4] Btrfs: track transaction aborted across the fs_info Liu Bo
2012-06-01 12:46 ` Josef Bacik
2012-05-31 20:04 ` [PATCH 3/4] Btrfs: do not reset the eb ref count to 1 when aborting the transaction Josef Bacik
2012-05-31 20:04 ` [PATCH 4/4] Btrfs: unlock everything properly in the error case for nocow 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=1338494656-12232-2-git-send-email-josef@redhat.com \
--to=josef@redhat.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).