diff mbox

nbd: allow device creation at a specific index

Message ID 1502735133-15841-1-git-send-email-josef@toxicpanda.com (mailing list archive)
State New, archived
Headers show

Commit Message

Josef Bacik Aug. 14, 2017, 6:25 p.m. UTC
From: Josef Bacik <jbacik@fb.com>

If users really want to use a particular index for their nbd device and it
doesn't already exist there's no reason we can't just create it for them.  Do
this instead of erroring out.

Signed-off-by: Josef Bacik <jbacik@fb.com>
---
 drivers/block/nbd.c | 9 +++++++++
 1 file changed, 9 insertions(+)

Comments

Jens Axboe Aug. 17, 2017, 5:03 p.m. UTC | #1
On 08/14/2017 12:25 PM, Josef Bacik wrote:
> From: Josef Bacik <jbacik@fb.com>
> 
> If users really want to use a particular index for their nbd device and it
> doesn't already exist there's no reason we can't just create it for them.  Do
> this instead of erroring out.

Added for 4.14, thanks.
diff mbox

Patch

diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
index 5bdf923..d816ae7 100644
--- a/drivers/block/nbd.c
+++ b/drivers/block/nbd.c
@@ -1584,6 +1584,15 @@  static int nbd_genl_connect(struct sk_buff *skb, struct genl_info *info)
 		}
 	} else {
 		nbd = idr_find(&nbd_index_idr, index);
+		if (!nbd) {
+			ret = nbd_dev_add(index);
+			if (ret < 0) {
+				mutex_unlock(&nbd_index_mutex);
+				printk(KERN_ERR "nbd: failed to add new device\n");
+				return ret;
+			}
+			nbd = idr_find(&nbd_index_idr, index);
+		}
 	}
 	if (!nbd) {
 		printk(KERN_ERR "nbd: couldn't find device at index %d\n",