Commit 2a852a69 authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Jens Axboe

nbd: use the correct block_device in nbd_bdev_reset

The bdev parameter to ->ioctl contains the block device that the ioctl
is called on, which can be the partition.  But the openers check in
nbd_bdev_reset really needs to check use the whole device, so switch to
using that.
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarJan Kara <jack@suse.cz>
Link: https://lore.kernel.org/r/20220330052917.2566582-2-hch@lst.deSigned-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent 8fd6533e
...@@ -1217,11 +1217,11 @@ static int nbd_reconnect_socket(struct nbd_device *nbd, unsigned long arg) ...@@ -1217,11 +1217,11 @@ static int nbd_reconnect_socket(struct nbd_device *nbd, unsigned long arg)
return -ENOSPC; return -ENOSPC;
} }
static void nbd_bdev_reset(struct block_device *bdev) static void nbd_bdev_reset(struct nbd_device *nbd)
{ {
if (bdev->bd_openers > 1) if (nbd->disk->part0->bd_openers > 1)
return; return;
set_capacity(bdev->bd_disk, 0); set_capacity(nbd->disk, 0);
} }
static void nbd_parse_flags(struct nbd_device *nbd) static void nbd_parse_flags(struct nbd_device *nbd)
...@@ -1386,7 +1386,7 @@ static int nbd_start_device(struct nbd_device *nbd) ...@@ -1386,7 +1386,7 @@ static int nbd_start_device(struct nbd_device *nbd)
return nbd_set_size(nbd, config->bytesize, nbd_blksize(config)); return nbd_set_size(nbd, config->bytesize, nbd_blksize(config));
} }
static int nbd_start_device_ioctl(struct nbd_device *nbd, struct block_device *bdev) static int nbd_start_device_ioctl(struct nbd_device *nbd)
{ {
struct nbd_config *config = nbd->config; struct nbd_config *config = nbd->config;
int ret; int ret;
...@@ -1405,7 +1405,7 @@ static int nbd_start_device_ioctl(struct nbd_device *nbd, struct block_device *b ...@@ -1405,7 +1405,7 @@ static int nbd_start_device_ioctl(struct nbd_device *nbd, struct block_device *b
flush_workqueue(nbd->recv_workq); flush_workqueue(nbd->recv_workq);
mutex_lock(&nbd->config_lock); mutex_lock(&nbd->config_lock);
nbd_bdev_reset(bdev); nbd_bdev_reset(nbd);
/* user requested, ignore socket errors */ /* user requested, ignore socket errors */
if (test_bit(NBD_RT_DISCONNECT_REQUESTED, &config->runtime_flags)) if (test_bit(NBD_RT_DISCONNECT_REQUESTED, &config->runtime_flags))
ret = 0; ret = 0;
...@@ -1419,7 +1419,7 @@ static void nbd_clear_sock_ioctl(struct nbd_device *nbd, ...@@ -1419,7 +1419,7 @@ static void nbd_clear_sock_ioctl(struct nbd_device *nbd,
{ {
sock_shutdown(nbd); sock_shutdown(nbd);
__invalidate_device(bdev, true); __invalidate_device(bdev, true);
nbd_bdev_reset(bdev); nbd_bdev_reset(nbd);
if (test_and_clear_bit(NBD_RT_HAS_CONFIG_REF, if (test_and_clear_bit(NBD_RT_HAS_CONFIG_REF,
&nbd->config->runtime_flags)) &nbd->config->runtime_flags))
nbd_config_put(nbd); nbd_config_put(nbd);
...@@ -1465,7 +1465,7 @@ static int __nbd_ioctl(struct block_device *bdev, struct nbd_device *nbd, ...@@ -1465,7 +1465,7 @@ static int __nbd_ioctl(struct block_device *bdev, struct nbd_device *nbd,
config->flags = arg; config->flags = arg;
return 0; return 0;
case NBD_DO_IT: case NBD_DO_IT:
return nbd_start_device_ioctl(nbd, bdev); return nbd_start_device_ioctl(nbd);
case NBD_CLEAR_QUE: case NBD_CLEAR_QUE:
/* /*
* This is for compatibility only. The queue is always cleared * This is for compatibility only. The queue is always cleared
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment