nbd: reset NBD to NULL when restarting in nbd_genl_connect
When nbd_genl_connect restarts to wait for a disconnecting device, nbd needs to be reset to NULL. Do that by facoring out a helper to find an unused device. Fixes: 6177b56c96ff ("nbd: refactor device search and allocation in nbd_genl_connect") Reported-by: Tetsuo Handa <penguin-kernel@i-love.sakura.ne.jp> Reported-by: Hillf Danton <hdanton@sina.com> Signed-off-by: Christoph Hellwig <hch@lst.de> Link: https://lore.kernel.org/r/20210825163108.50713-3-hch@lst.de Reviewed-by: Josef Bacik <josef@toxicpanda.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
This commit is contained in:
parent
93f63bc41f
commit
409e0ff10e
@ -1781,6 +1781,20 @@ out:
|
|||||||
return ERR_PTR(err);
|
return ERR_PTR(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static struct nbd_device *nbd_find_unused(void)
|
||||||
|
{
|
||||||
|
struct nbd_device *nbd;
|
||||||
|
int id;
|
||||||
|
|
||||||
|
lockdep_assert_held(&nbd_index_mutex);
|
||||||
|
|
||||||
|
idr_for_each_entry(&nbd_index_idr, nbd, id)
|
||||||
|
if (!refcount_read(&nbd->config_refs))
|
||||||
|
return nbd;
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
/* Netlink interface. */
|
/* Netlink interface. */
|
||||||
static const struct nla_policy nbd_attr_policy[NBD_ATTR_MAX + 1] = {
|
static const struct nla_policy nbd_attr_policy[NBD_ATTR_MAX + 1] = {
|
||||||
[NBD_ATTR_INDEX] = { .type = NLA_U32 },
|
[NBD_ATTR_INDEX] = { .type = NLA_U32 },
|
||||||
@ -1828,7 +1842,7 @@ static int nbd_genl_size_set(struct genl_info *info, struct nbd_device *nbd)
|
|||||||
static int nbd_genl_connect(struct sk_buff *skb, struct genl_info *info)
|
static int nbd_genl_connect(struct sk_buff *skb, struct genl_info *info)
|
||||||
{
|
{
|
||||||
DECLARE_COMPLETION_ONSTACK(destroy_complete);
|
DECLARE_COMPLETION_ONSTACK(destroy_complete);
|
||||||
struct nbd_device *nbd = NULL;
|
struct nbd_device *nbd;
|
||||||
struct nbd_config *config;
|
struct nbd_config *config;
|
||||||
int index = -1;
|
int index = -1;
|
||||||
int ret;
|
int ret;
|
||||||
@ -1849,20 +1863,10 @@ static int nbd_genl_connect(struct sk_buff *skb, struct genl_info *info)
|
|||||||
}
|
}
|
||||||
again:
|
again:
|
||||||
mutex_lock(&nbd_index_mutex);
|
mutex_lock(&nbd_index_mutex);
|
||||||
if (index == -1) {
|
if (index == -1)
|
||||||
struct nbd_device *tmp;
|
nbd = nbd_find_unused();
|
||||||
int id;
|
else
|
||||||
|
|
||||||
idr_for_each_entry(&nbd_index_idr, tmp, id) {
|
|
||||||
if (!refcount_read(&tmp->config_refs)) {
|
|
||||||
nbd = tmp;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
nbd = idr_find(&nbd_index_idr, index);
|
nbd = idr_find(&nbd_index_idr, index);
|
||||||
}
|
|
||||||
|
|
||||||
if (nbd) {
|
if (nbd) {
|
||||||
if (test_bit(NBD_DESTROY_ON_DISCONNECT, &nbd->flags) &&
|
if (test_bit(NBD_DESTROY_ON_DISCONNECT, &nbd->flags) &&
|
||||||
test_bit(NBD_DISCONNECT_REQUESTED, &nbd->flags)) {
|
test_bit(NBD_DISCONNECT_REQUESTED, &nbd->flags)) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user