提交 a8cdc308 编写于 作者: A Al Viro

[PATCH] switch nbd

NB: nbd_ioctl() appears to be racy; BKL is held, but doesn't really
help, AFAICS.  Left as-is for now, but it'll need fixing.
Signed-off-by: NAl Viro <viro@zeniv.linux.org.uk>
上级 bb214884
...@@ -557,10 +557,11 @@ static void do_nbd_request(struct request_queue * q) ...@@ -557,10 +557,11 @@ static void do_nbd_request(struct request_queue * q)
} }
} }
static int nbd_ioctl(struct inode *inode, struct file *file, static int nbd_ioctl(struct block_device *bdev, fmode_t mode,
unsigned int cmd, unsigned long arg) unsigned int cmd, unsigned long arg)
{ {
struct nbd_device *lo = inode->i_bdev->bd_disk->private_data; struct nbd_device *lo = bdev->bd_disk->private_data;
struct file *file;
int error; int error;
struct request sreq ; struct request sreq ;
struct task_struct *thread; struct task_struct *thread;
...@@ -612,8 +613,7 @@ static int nbd_ioctl(struct inode *inode, struct file *file, ...@@ -612,8 +613,7 @@ static int nbd_ioctl(struct inode *inode, struct file *file,
error = -EINVAL; error = -EINVAL;
file = fget(arg); file = fget(arg);
if (file) { if (file) {
struct block_device *bdev = inode->i_bdev; struct inode *inode = file->f_path.dentry->d_inode;
inode = file->f_path.dentry->d_inode;
if (S_ISSOCK(inode->i_mode)) { if (S_ISSOCK(inode->i_mode)) {
lo->file = file; lo->file = file;
lo->sock = SOCKET_I(inode); lo->sock = SOCKET_I(inode);
...@@ -628,14 +628,14 @@ static int nbd_ioctl(struct inode *inode, struct file *file, ...@@ -628,14 +628,14 @@ static int nbd_ioctl(struct inode *inode, struct file *file,
case NBD_SET_BLKSIZE: case NBD_SET_BLKSIZE:
lo->blksize = arg; lo->blksize = arg;
lo->bytesize &= ~(lo->blksize-1); lo->bytesize &= ~(lo->blksize-1);
inode->i_bdev->bd_inode->i_size = lo->bytesize; bdev->bd_inode->i_size = lo->bytesize;
set_blocksize(inode->i_bdev, lo->blksize); set_blocksize(bdev, lo->blksize);
set_capacity(lo->disk, lo->bytesize >> 9); set_capacity(lo->disk, lo->bytesize >> 9);
return 0; return 0;
case NBD_SET_SIZE: case NBD_SET_SIZE:
lo->bytesize = arg & ~(lo->blksize-1); lo->bytesize = arg & ~(lo->blksize-1);
inode->i_bdev->bd_inode->i_size = lo->bytesize; bdev->bd_inode->i_size = lo->bytesize;
set_blocksize(inode->i_bdev, lo->blksize); set_blocksize(bdev, lo->blksize);
set_capacity(lo->disk, lo->bytesize >> 9); set_capacity(lo->disk, lo->bytesize >> 9);
return 0; return 0;
case NBD_SET_TIMEOUT: case NBD_SET_TIMEOUT:
...@@ -643,8 +643,8 @@ static int nbd_ioctl(struct inode *inode, struct file *file, ...@@ -643,8 +643,8 @@ static int nbd_ioctl(struct inode *inode, struct file *file,
return 0; return 0;
case NBD_SET_SIZE_BLOCKS: case NBD_SET_SIZE_BLOCKS:
lo->bytesize = ((u64) arg) * lo->blksize; lo->bytesize = ((u64) arg) * lo->blksize;
inode->i_bdev->bd_inode->i_size = lo->bytesize; bdev->bd_inode->i_size = lo->bytesize;
set_blocksize(inode->i_bdev, lo->blksize); set_blocksize(bdev, lo->blksize);
set_capacity(lo->disk, lo->bytesize >> 9); set_capacity(lo->disk, lo->bytesize >> 9);
return 0; return 0;
case NBD_DO_IT: case NBD_DO_IT:
...@@ -666,10 +666,10 @@ static int nbd_ioctl(struct inode *inode, struct file *file, ...@@ -666,10 +666,10 @@ static int nbd_ioctl(struct inode *inode, struct file *file,
if (file) if (file)
fput(file); fput(file);
lo->bytesize = 0; lo->bytesize = 0;
inode->i_bdev->bd_inode->i_size = 0; bdev->bd_inode->i_size = 0;
set_capacity(lo->disk, 0); set_capacity(lo->disk, 0);
if (max_part > 0) if (max_part > 0)
ioctl_by_bdev(inode->i_bdev, BLKRRPART, 0); ioctl_by_bdev(bdev, BLKRRPART, 0);
return lo->harderror; return lo->harderror;
case NBD_CLEAR_QUE: case NBD_CLEAR_QUE:
/* /*
...@@ -680,7 +680,7 @@ static int nbd_ioctl(struct inode *inode, struct file *file, ...@@ -680,7 +680,7 @@ static int nbd_ioctl(struct inode *inode, struct file *file,
return 0; return 0;
case NBD_PRINT_DEBUG: case NBD_PRINT_DEBUG:
printk(KERN_INFO "%s: next = %p, prev = %p, head = %p\n", printk(KERN_INFO "%s: next = %p, prev = %p, head = %p\n",
inode->i_bdev->bd_disk->disk_name, bdev->bd_disk->disk_name,
lo->queue_head.next, lo->queue_head.prev, lo->queue_head.next, lo->queue_head.prev,
&lo->queue_head); &lo->queue_head);
return 0; return 0;
...@@ -691,7 +691,7 @@ static int nbd_ioctl(struct inode *inode, struct file *file, ...@@ -691,7 +691,7 @@ static int nbd_ioctl(struct inode *inode, struct file *file,
static struct block_device_operations nbd_fops = static struct block_device_operations nbd_fops =
{ {
.owner = THIS_MODULE, .owner = THIS_MODULE,
.__ioctl = nbd_ioctl, .locked_ioctl = nbd_ioctl,
}; };
/* /*
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册