Skip to content

Commit

Permalink
Btrfs: hold i_mutex when calling btrfs_log_dentry_safe
Browse files Browse the repository at this point in the history
Since we walk up the path logging all of the parts of the inode's path, we need
to hold i_mutex to make sure that the inode is not renamed while we're logging
everything.  btrfs_log_dentry_safe does dget_parent and all of that jazz, but we
may get unexpected results if the rename changes the inode's location while
we're higher up the path logging those dentries, so do this for safety reasons.
Thanks,

Signed-off-by: Josef Bacik <josef@redhat.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
  • Loading branch information
Josef Bacik authored and Chris Mason committed Nov 22, 2010
1 parent 6a91221 commit 495e867
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions fs/btrfs/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -1047,8 +1047,14 @@ static ssize_t btrfs_file_aio_write(struct kiocb *iocb,

if ((file->f_flags & O_DSYNC) || IS_SYNC(inode)) {
trans = btrfs_start_transaction(root, 0);
if (IS_ERR(trans)) {
num_written = PTR_ERR(trans);
goto done;
}
mutex_lock(&inode->i_mutex);
ret = btrfs_log_dentry_safe(trans, root,
file->f_dentry);
mutex_unlock(&inode->i_mutex);
if (ret == 0) {
ret = btrfs_sync_log(trans, root);
if (ret == 0)
Expand All @@ -1067,6 +1073,7 @@ static ssize_t btrfs_file_aio_write(struct kiocb *iocb,
(start_pos + num_written - 1) >> PAGE_CACHE_SHIFT);
}
}
done:
current->backing_dev_info = NULL;
return num_written ? num_written : err;
}
Expand Down

0 comments on commit 495e867

Please sign in to comment.