diff options
author | Josef Bacik <jbacik@fusionio.com> | 2013-02-13 20:09:14 +0400 |
---|---|---|
committer | Josef Bacik <jbacik@fusionio.com> | 2013-02-20 21:59:57 +0400 |
commit | 569e0f358c0c37f6733702d4a5d2c412860f7169 (patch) | |
tree | 8ab0ece9bd2716da66a43406628f6f5176604817 /fs/btrfs/file.c | |
parent | dde5740fdd6175fc95aecf4ccc7856fbbad9b44e (diff) | |
download | linux-569e0f358c0c37f6733702d4a5d2c412860f7169.tar.xz |
Btrfs: place ordered operations on a per transaction list
Miao made the ordered operations stuff run async, which introduced a
deadlock where we could get somebody (sync) racing in and committing the
transaction while a commit was already happening. The new committer would
try and flush ordered operations which would hang waiting for the commit to
finish because it is done asynchronously and no longer inherits the callers
trans handle. To fix this we need to make the ordered operations list a per
transaction list. We can get new inodes added to the ordered operation list
by truncating them and then having another process writing to them, so this
makes it so that anybody trying to add an ordered operation _must_ start a
transaction in order to add itself to the list, which will keep new inodes
from getting added to the ordered operations list after we start committing.
This should fix the deadlock and also keeps us from doing a lot more work
than we need to during commit. Thanks,
Signed-off-by: Josef Bacik <jbacik@fusionio.com>
Diffstat (limited to 'fs/btrfs/file.c')
-rw-r--r-- | fs/btrfs/file.c | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c index 75d0fe134be3..b12ba52c4505 100644 --- a/fs/btrfs/file.c +++ b/fs/btrfs/file.c @@ -1628,7 +1628,20 @@ int btrfs_release_file(struct inode *inode, struct file *filp) */ if (test_and_clear_bit(BTRFS_INODE_ORDERED_DATA_CLOSE, &BTRFS_I(inode)->runtime_flags)) { - btrfs_add_ordered_operation(NULL, BTRFS_I(inode)->root, inode); + struct btrfs_trans_handle *trans; + struct btrfs_root *root = BTRFS_I(inode)->root; + + /* + * We need to block on a committing transaction to keep us from + * throwing a ordered operation on to the list and causing + * something like sync to deadlock trying to flush out this + * inode. + */ + trans = btrfs_start_transaction(root, 0); + if (IS_ERR(trans)) + return PTR_ERR(trans); + btrfs_add_ordered_operation(trans, BTRFS_I(inode)->root, inode); + btrfs_end_transaction(trans, root); if (inode->i_size > BTRFS_ORDERED_OPERATIONS_FLUSH_LIMIT) filemap_flush(inode->i_mapping); } |