diff options
author | Sage Weil <sage@redhat.com> | 2014-09-26 11:30:06 -0400 |
---|---|---|
committer | Chris Mason <clm@fb.com> | 2014-10-03 19:14:59 -0400 |
commit | 42383020beb1cfb05f5d330cc311931bc4917a97 (patch) | |
tree | 08e2411cd332c3c56323ac9ffc27164079e29daf /fs/btrfs/transaction.c | |
parent | 656f30dba7ab8179c9a2e04293b0c7b383fa9ce9 (diff) |
Btrfs: fix race in WAIT_SYNC ioctl
We check whether transid is already committed via last_trans_committed and
then search through trans_list for pending transactions. If
last_trans_committed is updated by btrfs_commit_transaction after we check
it (there is no locking), we will fail to find the committed transaction
and return EINVAL to the caller. This has been observed occasionally by
ceph-osd (which uses this ioctl heavily).
Fix by rechecking whether the provided transid <= last_trans_committed
after the search fails, and if so return 0.
Signed-off-by: Sage Weil <sage@redhat.com>
Signed-off-by: Chris Mason <clm@fb.com>
Diffstat (limited to 'fs/btrfs/transaction.c')
-rw-r--r-- | fs/btrfs/transaction.c | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c index a47b1000a6e5..86ef8d79c19f 100644 --- a/fs/btrfs/transaction.c +++ b/fs/btrfs/transaction.c | |||
@@ -609,7 +609,6 @@ int btrfs_wait_for_commit(struct btrfs_root *root, u64 transid) | |||
609 | if (transid <= root->fs_info->last_trans_committed) | 609 | if (transid <= root->fs_info->last_trans_committed) |
610 | goto out; | 610 | goto out; |
611 | 611 | ||
612 | ret = -EINVAL; | ||
613 | /* find specified transaction */ | 612 | /* find specified transaction */ |
614 | spin_lock(&root->fs_info->trans_lock); | 613 | spin_lock(&root->fs_info->trans_lock); |
615 | list_for_each_entry(t, &root->fs_info->trans_list, list) { | 614 | list_for_each_entry(t, &root->fs_info->trans_list, list) { |
@@ -625,9 +624,16 @@ int btrfs_wait_for_commit(struct btrfs_root *root, u64 transid) | |||
625 | } | 624 | } |
626 | } | 625 | } |
627 | spin_unlock(&root->fs_info->trans_lock); | 626 | spin_unlock(&root->fs_info->trans_lock); |
628 | /* The specified transaction doesn't exist */ | 627 | |
629 | if (!cur_trans) | 628 | /* |
629 | * The specified transaction doesn't exist, or we | ||
630 | * raced with btrfs_commit_transaction | ||
631 | */ | ||
632 | if (!cur_trans) { | ||
633 | if (transid > root->fs_info->last_trans_committed) | ||
634 | ret = -EINVAL; | ||
630 | goto out; | 635 | goto out; |
636 | } | ||
631 | } else { | 637 | } else { |
632 | /* find newest transaction that is committing | committed */ | 638 | /* find newest transaction that is committing | committed */ |
633 | spin_lock(&root->fs_info->trans_lock); | 639 | spin_lock(&root->fs_info->trans_lock); |