diff options
-rw-r--r-- | drivers/block/nbd.c | 10 | ||||
-rw-r--r-- | fs/block_dev.c | 3 | ||||
-rw-r--r-- | include/linux/fs.h | 2 |
3 files changed, 14 insertions, 1 deletions
diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c index 86848c6303f..40a0fcbdd74 100644 --- a/drivers/block/nbd.c +++ b/drivers/block/nbd.c @@ -584,12 +584,20 @@ static int __nbd_ioctl(struct block_device *bdev, struct nbd_device *lo, struct request sreq; dev_info(disk_to_dev(lo->disk), "NBD_DISCONNECT\n"); + if (!lo->sock) + return -EINVAL; + mutex_unlock(&lo->tx_lock); + fsync_bdev(bdev); + mutex_lock(&lo->tx_lock); blk_rq_init(NULL, &sreq); sreq.cmd_type = REQ_TYPE_SPECIAL; nbd_cmd(&sreq) = NBD_CMD_DISC; + + /* Check again after getting mutex back. */ if (!lo->sock) return -EINVAL; + nbd_send_req(lo, &sreq); return 0; } @@ -603,6 +611,7 @@ static int __nbd_ioctl(struct block_device *bdev, struct nbd_device *lo, nbd_clear_que(lo); BUG_ON(!list_empty(&lo->queue_head)); BUG_ON(!list_empty(&lo->waiting_queue)); + kill_bdev(bdev); if (file) fput(file); return 0; @@ -683,6 +692,7 @@ static int __nbd_ioctl(struct block_device *bdev, struct nbd_device *lo, lo->file = NULL; nbd_clear_que(lo); dev_warn(disk_to_dev(lo->disk), "queue cleared\n"); + kill_bdev(bdev); if (file) fput(file); lo->bytesize = 0; diff --git a/fs/block_dev.c b/fs/block_dev.c index 5db58fc60c0..613edd8822d 100644 --- a/fs/block_dev.c +++ b/fs/block_dev.c @@ -82,13 +82,14 @@ sector_t blkdev_max_block(struct block_device *bdev) } /* Kill _all_ buffers and pagecache , dirty or not.. */ -static void kill_bdev(struct block_device *bdev) +void kill_bdev(struct block_device *bdev) { if (bdev->bd_inode->i_mapping->nrpages == 0) return; invalidate_bh_lrus(); truncate_inode_pages(bdev->bd_inode->i_mapping, 0); } +EXPORT_SYMBOL(kill_bdev); int set_blocksize(struct block_device *bdev, int size) { diff --git a/include/linux/fs.h b/include/linux/fs.h index 29b63538d24..a2768177ad2 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -2103,6 +2103,7 @@ extern void bd_forget(struct inode *inode); extern void bdput(struct block_device *); extern void invalidate_bdev(struct block_device *); extern int sync_blockdev(struct block_device *bdev); +extern void kill_bdev(struct block_device *); extern struct super_block *freeze_bdev(struct block_device *); extern void emergency_thaw_all(void); extern int thaw_bdev(struct block_device *bdev, struct super_block *sb); @@ -2110,6 +2111,7 @@ extern int fsync_bdev(struct block_device *); #else static inline void bd_forget(struct inode *inode) {} static inline int sync_blockdev(struct block_device *bdev) { return 0; } +static inline void kill_bdev(struct block_device *bdev) {} static inline void invalidate_bdev(struct block_device *bdev) {} static inline struct super_block *freeze_bdev(struct block_device *sb) |