Skip to content

Commit

Permalink
Lock splice_read and splice_write functions
Browse files Browse the repository at this point in the history
Functions generic_file_splice_read and generic_file_splice_write access
the pagecache directly. For block devices these functions must be locked
so that block size is not changed while they are in progress.

This patch is an additional fix for commit b87570f ("Fix a crash
when block device is read and block size is changed at the same time")
that locked aio_read, aio_write and mmap against block size change.

Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
  • Loading branch information
Mikulas Patocka authored and Linus Torvalds committed Oct 28, 2012
1 parent 1bf11c5 commit 1a25b1c
Showing 1 changed file with 35 additions and 2 deletions.
37 changes: 35 additions & 2 deletions fs/block_dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -1661,6 +1661,39 @@ static int blkdev_mmap(struct file *file, struct vm_area_struct *vma)
return ret;
}

static ssize_t blkdev_splice_read(struct file *file, loff_t *ppos,
struct pipe_inode_info *pipe, size_t len,
unsigned int flags)
{
ssize_t ret;
struct block_device *bdev = I_BDEV(file->f_mapping->host);

percpu_down_read(&bdev->bd_block_size_semaphore);

ret = generic_file_splice_read(file, ppos, pipe, len, flags);

percpu_up_read(&bdev->bd_block_size_semaphore);

return ret;
}

static ssize_t blkdev_splice_write(struct pipe_inode_info *pipe,
struct file *file, loff_t *ppos, size_t len,
unsigned int flags)
{
ssize_t ret;
struct block_device *bdev = I_BDEV(file->f_mapping->host);

percpu_down_read(&bdev->bd_block_size_semaphore);

ret = generic_file_splice_write(pipe, file, ppos, len, flags);

percpu_up_read(&bdev->bd_block_size_semaphore);

return ret;
}


/*
* Try to release a page associated with block device when the system
* is under memory pressure.
Expand Down Expand Up @@ -1699,8 +1732,8 @@ const struct file_operations def_blk_fops = {
#ifdef CONFIG_COMPAT
.compat_ioctl = compat_blkdev_ioctl,
#endif
.splice_read = generic_file_splice_read,
.splice_write = generic_file_splice_write,
.splice_read = blkdev_splice_read,
.splice_write = blkdev_splice_write,
};

int ioctl_by_bdev(struct block_device *bdev, unsigned cmd, unsigned long arg)
Expand Down

0 comments on commit 1a25b1c

Please sign in to comment.