From patchwork Mon Aug 14 18:25:33 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 9899913 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 7C9CF602BA for ; Mon, 14 Aug 2017 18:25:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7039728573 for ; Mon, 14 Aug 2017 18:25:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6555F28676; Mon, 14 Aug 2017 18:25:37 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.4 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B065428618 for ; Mon, 14 Aug 2017 18:25:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751030AbdHNSZg (ORCPT ); Mon, 14 Aug 2017 14:25:36 -0400 Received: from mail-yw0-f194.google.com ([209.85.161.194]:33982 "EHLO mail-yw0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750910AbdHNSZf (ORCPT ); Mon, 14 Aug 2017 14:25:35 -0400 Received: by mail-yw0-f194.google.com with SMTP id t139so6696050ywg.1 for ; Mon, 14 Aug 2017 11:25:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id; bh=yqTH6MnFFY/D9m+SDsZekCrVwdgxfh9rmLEdBWxxTEA=; b=ZVAhYpZ6VMFtgRr6clsjXgFtKMT14t81wlfflT4RSKUnWIS8C3YgzfgFmoafJTP4hK L/TKzoCFauhcPmh0ffZC/kLB1GibBNaLOKLrsLdOHIarG0+3aPYvU0o8BUSEk36fyRpE ov+WrT3FXnLQOhmUnEJ1cd52bsoGzdwt7HMM0QvC8/vznZd1Jj2y/eQjQcow4fDueHez m1MZzf71WzebhO6o4GyIaHTqS7xa7MmzDIxGmP3fuIS4MvV2ksRNgP0Im7qHD3FAkLdT gn+wBsdivDehgMjpuVttJecvEp2eCgdBe/m1wF/DysDYAmYG9sJ5hs48i54+eDhPJ2EE RSEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=yqTH6MnFFY/D9m+SDsZekCrVwdgxfh9rmLEdBWxxTEA=; b=b73I04X073MSeku+6Jg+ggCVYSfaI25/kj2S+7UiwsdhVLob3ibekIDL/kjEkDxKKh d2L5Ml/IuaR3swomqRB1LiA3Nf5B2dv8z6xlU5yM+vwWMQNZVShGeziNM5i/te7NfIeF jOgDqu6RvHQmxCp/5cz2sAQwpeRX5k9kuZaTfZplJcg76Z1xQfdvNQROP6gHzUmJtZqo 1DOmc8AejxMb0q+4WIz3OIxrHFeR9oI2+QNuQ+Q+XDB6y65j2D4eoorRLtzahPdlk1n3 WmbQE7ZWQlBWTKnKoghNc6kZUMZ09zqGt1I7VgFQV4bHW6mpKNkE9Z9l1mwp3AukLzv/ LXmQ== X-Gm-Message-State: AHYfb5iJOCHHbK4oWRx0sENblzYDC0rtinLTk/kWKgGAq97C9nF1szVx jaS4oPq/Tn5P1WbE X-Received: by 10.37.209.196 with SMTP id i187mr20666792ybg.231.1502735134975; Mon, 14 Aug 2017 11:25:34 -0700 (PDT) Received: from localhost (li70-116.members.linode.com. [74.207.228.116]) by smtp.gmail.com with ESMTPSA id c77sm2948582ywb.42.2017.08.14.11.25.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 14 Aug 2017 11:25:34 -0700 (PDT) From: Josef Bacik To: axboe@kernel.dk, linux-block@vger.kernel.org, kernel-team@fb.com Cc: Josef Bacik Subject: [PATCH] nbd: allow device creation at a specific index Date: Mon, 14 Aug 2017 18:25:33 +0000 Message-Id: <1502735133-15841-1-git-send-email-josef@toxicpanda.com> X-Mailer: git-send-email 1.8.3.1 Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Josef Bacik 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 --- drivers/block/nbd.c | 9 +++++++++ 1 file changed, 9 insertions(+) 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",