Skip to content
This repository has been archived by the owner on Aug 27, 2022. It is now read-only.

Commit

Permalink
Btrfs: check file pointer in btrfs_sync_file
Browse files Browse the repository at this point in the history
fsync can be called by NFS with a null file pointer, and btrfs was
oopsing in this case.

Signed-off-by: Chris Mason <chris.mason@oracle.com>
  • Loading branch information
chrismason-xx committed Feb 20, 2009
1 parent 2456242 commit 2cfbd50
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions fs/btrfs/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -1222,7 +1222,7 @@ int btrfs_sync_file(struct file *file, struct dentry *dentry, int datasync)
/*
* ok we haven't committed the transaction yet, lets do a commit
*/
if (file->private_data)
if (file && file->private_data)
btrfs_ioctl_trans_end(file);

trans = btrfs_start_transaction(root, 1);
Expand All @@ -1231,7 +1231,7 @@ int btrfs_sync_file(struct file *file, struct dentry *dentry, int datasync)
goto out;
}

ret = btrfs_log_dentry_safe(trans, root, file->f_dentry);
ret = btrfs_log_dentry_safe(trans, root, dentry);
if (ret < 0)
goto out;

Expand All @@ -1245,15 +1245,15 @@ int btrfs_sync_file(struct file *file, struct dentry *dentry, int datasync)
* file again, but that will end up using the synchronization
* inside btrfs_sync_log to keep things safe.
*/
mutex_unlock(&file->f_dentry->d_inode->i_mutex);
mutex_unlock(&dentry->d_inode->i_mutex);

if (ret > 0) {
ret = btrfs_commit_transaction(trans, root);
} else {
btrfs_sync_log(trans, root);
ret = btrfs_end_transaction(trans, root);
}
mutex_lock(&file->f_dentry->d_inode->i_mutex);
mutex_lock(&dentry->d_inode->i_mutex);
out:
return ret > 0 ? EIO : ret;
}
Expand Down

0 comments on commit 2cfbd50

Please sign in to comment.