nbd: return the allocated nbd_device from nbd_dev_add
Return the device we just allocated instead of doing an extra search for it in the caller. Signed-off-by: Christoph Hellwig <hch@lst.de> Link: https://lore.kernel.org/r/20210811124428.2368491-5-hch@lst.de Reviewed-by: Josef Bacik <josef@toxicpanda.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
This commit is contained in:
committed by
Jens Axboe
parent
327b501b1d
commit
7bdc00cf7e
@@ -1683,7 +1683,7 @@ static const struct blk_mq_ops nbd_mq_ops = {
|
|||||||
.timeout = nbd_xmit_timeout,
|
.timeout = nbd_xmit_timeout,
|
||||||
};
|
};
|
||||||
|
|
||||||
static int nbd_dev_add(int index)
|
static struct nbd_device *nbd_dev_add(int index)
|
||||||
{
|
{
|
||||||
struct nbd_device *nbd;
|
struct nbd_device *nbd;
|
||||||
struct gendisk *disk;
|
struct gendisk *disk;
|
||||||
@@ -1755,7 +1755,7 @@ static int nbd_dev_add(int index)
|
|||||||
sprintf(disk->disk_name, "nbd%d", index);
|
sprintf(disk->disk_name, "nbd%d", index);
|
||||||
add_disk(disk);
|
add_disk(disk);
|
||||||
nbd_total_devices++;
|
nbd_total_devices++;
|
||||||
return index;
|
return nbd;
|
||||||
|
|
||||||
out_free_idr:
|
out_free_idr:
|
||||||
idr_remove(&nbd_index_idr, index);
|
idr_remove(&nbd_index_idr, index);
|
||||||
@@ -1764,7 +1764,7 @@ out_free_tags:
|
|||||||
out_free_nbd:
|
out_free_nbd:
|
||||||
kfree(nbd);
|
kfree(nbd);
|
||||||
out:
|
out:
|
||||||
return err;
|
return ERR_PTR(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int find_free_cb(int id, void *ptr, void *data)
|
static int find_free_cb(int id, void *ptr, void *data)
|
||||||
@@ -1850,25 +1850,22 @@ again:
|
|||||||
if (index == -1) {
|
if (index == -1) {
|
||||||
ret = idr_for_each(&nbd_index_idr, &find_free_cb, &nbd);
|
ret = idr_for_each(&nbd_index_idr, &find_free_cb, &nbd);
|
||||||
if (ret == 0) {
|
if (ret == 0) {
|
||||||
int new_index;
|
nbd = nbd_dev_add(-1);
|
||||||
new_index = nbd_dev_add(-1);
|
if (IS_ERR(nbd)) {
|
||||||
if (new_index < 0) {
|
|
||||||
mutex_unlock(&nbd_index_mutex);
|
mutex_unlock(&nbd_index_mutex);
|
||||||
printk(KERN_ERR "nbd: failed to add new device\n");
|
printk(KERN_ERR "nbd: failed to add new device\n");
|
||||||
return new_index;
|
return PTR_ERR(nbd);
|
||||||
}
|
}
|
||||||
nbd = idr_find(&nbd_index_idr, new_index);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
nbd = idr_find(&nbd_index_idr, index);
|
nbd = idr_find(&nbd_index_idr, index);
|
||||||
if (!nbd) {
|
if (!nbd) {
|
||||||
ret = nbd_dev_add(index);
|
nbd = nbd_dev_add(index);
|
||||||
if (ret < 0) {
|
if (IS_ERR(nbd)) {
|
||||||
mutex_unlock(&nbd_index_mutex);
|
mutex_unlock(&nbd_index_mutex);
|
||||||
printk(KERN_ERR "nbd: failed to add new device\n");
|
printk(KERN_ERR "nbd: failed to add new device\n");
|
||||||
return ret;
|
return PTR_ERR(nbd);
|
||||||
}
|
}
|
||||||
nbd = idr_find(&nbd_index_idr, index);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!nbd) {
|
if (!nbd) {
|
||||||
|
Reference in New Issue
Block a user