From patchwork Mon Feb 13 17:31:40 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 9570451 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 D116F6045D for ; Mon, 13 Feb 2017 17:31:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BF8A623B24 for ; Mon, 13 Feb 2017 17:31:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B20E326CFC; Mon, 13 Feb 2017 17:31:59 +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=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI 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 0469423B24 for ; Mon, 13 Feb 2017 17:31:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752512AbdBMRb6 (ORCPT ); Mon, 13 Feb 2017 12:31:58 -0500 Received: from mx0b-00082601.pphosted.com ([67.231.153.30]:42401 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750943AbdBMRb5 (ORCPT ); Mon, 13 Feb 2017 12:31:57 -0500 Received: from pps.filterd (m0001303.ppops.net [127.0.0.1]) by m0001303.ppops.net (8.16.0.20/8.16.0.20) with SMTP id v1DHR4PO009646; Mon, 13 Feb 2017 09:31:49 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : subject : date : message-id : mime-version : content-type; s=facebook; bh=JRsZWMDXgnFWRhbYin0bhSKJXdv7L3O4HiPa3UFuGUE=; b=HgvpXeyOry5/ZyxhCvEHzry6zH89AOTgKwm1PqqZGSWiJrQQm08AAR07Yaa6WgXjWkvr GojuDTiXLokoIA+KfMmASf9gty6RT66WT+1Vtve3fG9r7SPxwjIRDp0vuKEbk5IPLCab GD2eNj+Apa9Uq9oqV88jmUpywa7m/orkUpY= Received: from mail.thefacebook.com ([199.201.64.23]) by m0001303.ppops.net with ESMTP id 28hy5hw1ah-2 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Mon, 13 Feb 2017 09:31:49 -0800 Received: from NAM02-BL2-obe.outbound.protection.outlook.com (192.168.54.28) by o365-in.thefacebook.com (192.168.16.12) with Microsoft SMTP Server (TLS) id 14.3.294.0; Mon, 13 Feb 2017 09:31:46 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.onmicrosoft.com; s=selector1-fb-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=JRsZWMDXgnFWRhbYin0bhSKJXdv7L3O4HiPa3UFuGUE=; b=W5i8pFiBvIm4aXsiBFXGY+Yfks2uSwiS7oijfQV1Wc/mVqtcYSXwxrlIa3BF5c47H6fQq+NTM/L/0WCSHGGV4bJuvQ54QDEGyjXNt3aN78q6fJUdOrIXYaw577mVetvFwfr8betSCHxuR0u5C1L1QYiZ6kypW+n/PZeKEELtb+Q= Received: from localhost (2606:a000:4381:1201:225:22ff:feb3:e51a) by DM5PR15MB1916.namprd15.prod.outlook.com (10.174.247.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.888.16; Mon, 13 Feb 2017 17:31:43 +0000 From: Josef Bacik To: , , , Subject: [PATCH] nbd: use bdget_disk to get bdev Date: Mon, 13 Feb 2017 12:31:40 -0500 Message-ID: <1487007100-6847-1-git-send-email-jbacik@fb.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 X-Originating-IP: [2606:a000:4381:1201:225:22ff:feb3:e51a] X-ClientProxiedBy: MWHPR15CA0031.namprd15.prod.outlook.com (10.173.226.145) To DM5PR15MB1916.namprd15.prod.outlook.com (10.174.247.144) X-MS-Office365-Filtering-Correlation-Id: 50080866-b8e0-4a95-cbdd-08d454362dae X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001); SRVR:DM5PR15MB1916; X-Microsoft-Exchange-Diagnostics: 1; DM5PR15MB1916; 3:42YTGeqx2TmHNoZx94cMTegvTZR/nM2g0f0TyOyj0wmdt8Nfz4OV8BbOk78JiTrtChXKygxSSwvDOVYAl409PcD9xb4bObnlwKwXb30U7vaPjEnGSafmw0LRZP7Q+m80xA90fVPhNyQT5qLonYWKtmYuJyb+qA51E4+t8W9oSJl474OYWqGS5KNRoC5+4Z4PthWEc1l5zKf5be40Jlr09LnSWB46HB8Vx8zRyRp6DIPHYjyfksr7T3pRAy+D2VdWDFMkhRbr2jnfVINjPSz+KA==; 25:TEoqZ2/W4uIpEXTMe5k8/3Nj++l3BhK1TjyhcDaxn2eoHQGQSLSt8Qy/FezVoJpsjqmXf1jOQb/df+iZilhX8ObDzLGIS0Vd+mIFFF8PAf1maoshdyRb+6X30GOyApOn9AxtyXr/npbivvbC5baSfGZ24l05d5J+7P0y29Fo2YZZWpzs81gPJ8iOcGWg8HXdaAL5EscFjLNVU242Oa8MJG0+B5HvxMWFDB1xRtgR6o9jSiZ9yxh5HZ3MIW8yPQ7oMrrb1ak1lONGaX593SsJ7o6r/7VKxisCsyoKoRw2bSg6gaBtWUMLXtITDcc2L0ajfFvqNV4SaZa8viRDqE+rdW7Jl4u/1Ig8Ln54F6oeCLCpWqjI2rfFM6AYZXKCjtgRVl7oyCsuIP+AnCtdMpUQ3vW6Z2sbNrhLxqFdtAz069QeSfYcIkk0Rz8FPWL5O93S3GTU6ZbQIYAZZFNhtT4EYA== X-Microsoft-Exchange-Diagnostics: 1; DM5PR15MB1916; 31:OLFIokX65DFcvrgL5OM6yvfi0zq4B6jSU8WxEGd4/SCWTrpr6w8RcP1y06mR9D0A1Xs8/wtgLJ8TNxGIL0Is+8z8uOVA4B0xQ+qfFzrESjDI6caftXNycxwyoqluPu0iV6Z3oUdA1M70TP9QkihTWCLTtMzZvk8Tl9wFuudfrNhoRgI0IezCCKA4s3MJtkxQtIpSO/cSscZ5hM7fyw69leq1di1bvT8hSE93UTWhHRFTYAfWADUqpGL2qQJbSHaL; 20:Zc6O0Pvd0oA0afpT5X+BRwSuQRAtrsbm1q3ZQgvSysiwZVCxu3u3T91v0703JyQm1Lpk++iA20L2CRlV7kDCUwH/os8x9wt+sdSaq9JsnsY4GUGWR3fLowvVw5JbzYzQMEcurzCheg5oD0SwVieJyXhWWp2x0VG7VQQ34QygYlywiC2g3Pqt9W6vsKbHB8pTn9afHyPOkF75cM6LcK++UesLtjQxQZmn4OHJGqJ0pR8RcZwOjd0F6KSiZlPOJikZaJgJMnU6C3jv6w0RTkUS3WW+45QeEBuKbhwJirMKfY85hsNEeOcM4NuuwzoSGH2Bj26yY8JHXQ3uE4kM4dYSgITpzd5WWwfDjt1GM2YnXZviMVanwRwwt1jB86Qkj89rGcwMpio4JL/lH9sKqa5BMCUFetTWQC63E8YNT2MBefmDJpKozvg6T90NXvohdvUPjqgHZXGWW1auodA+Fm6iW2fgr2ggmGan1VlbLgKg5A77UIHRMPf/E18lZBydCL1D X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(158342451672863)(67672495146484); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040375)(601004)(2401047)(8121501046)(5005006)(10201501046)(3002001)(6041248)(20161123564025)(20161123562025)(20161123555025)(20161123558025)(20161123560025)(6072148); SRVR:DM5PR15MB1916; BCL:0; PCL:0; RULEID:; SRVR:DM5PR15MB1916; X-Microsoft-Exchange-Diagnostics: 1; DM5PR15MB1916; 4:TMzwGoKXSuV5IDZIG2vdZbndbZsCRJkNcRSZefPO5idkZOuMMuTs2tE6cdUSDzWgcUoaiVCJUQnt25WNXigzCdjC7isgZjWkBhoBGK2df/xXO/EEBcg/SJ1Zi2G6MA+BCexk+5D+1ncpuX8yrbvvHPrpcu7ADZyX3Q3DvOEOenKVWV3QrTmsVFwW/MPA+/pDpCp97qVU6wfsOiYI2Hg3rtMSG+gNLJCRU2dCreC4Rs4wVT9JukcMSzqLaeHAhE5DkW9Lyqyx5oLSWCdsrCmD3Ehqq4oTzG9C9WOL/UH0V8qvPeTdPLbmciw1RMlM3EfKFbAaZHF+kuAwQjmox1mFLpPzHKXyOifuDs+lEjG5yT/HQLuh7yQ09gNQIRjc459d086rdEw9f4uyG/IlRcu/OD7FMeMsg/JQF6ZXr1nSTzph9YljrSK04x8rhEAODfv3TlQ+d0lgHtEoTHy63jUVTocl8vq75yJV/fQkazrFOyrr7ULSms9IITcdrBdnLJ2AfI2myzDv/A8unmzoT6lIdtRXGwVaaERagIbx6R4F01F82dbQniBV9ol74FpSnIMAAblXYgk9H4rKQ+ubFvfPogoV38WPxdKfcAS2OAhONgY8xe+NiBRpOLhjFTNWO7ywJ70gqziinRdHC89r61cvm2kAC7aYIyKORMe9VRyZl3Ys+ACfWDAa5zszLuZnIqXN X-Forefront-PRVS: 02176E2458 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(4630300001)(6009001)(6069001)(7916002)(39450400003)(199003)(189002)(81156014)(105586002)(106356001)(50226002)(97736004)(8676002)(101416001)(81166006)(76506005)(92566002)(189998001)(5660300001)(47776003)(50986999)(42186005)(5003940100001)(48376002)(50466002)(2906002)(7736002)(6116002)(305945005)(25786008)(6496005)(33646002)(68736007)(38730400002)(86362001)(2201001)(36756003)(6636002)(53936002)(6486002); DIR:OUT; SFP:1102; SCL:1; SRVR:DM5PR15MB1916; H:localhost; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; Received-SPF: None (protection.outlook.com: fb.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; DM5PR15MB1916; 23:U40H/SeAfErsYrvEkXBIuxqpFqyweHZrnajLxnJa9?= =?us-ascii?Q?cAiaoZ1LqWvU884MtObwYFIwY65kKfWuUbkVHGaLAjmWsdtdfEbbxoaRrMhY?= =?us-ascii?Q?dySGP5Sl237bcSPXFyk5jY4u/QMNdfhK4eYmz06o9n5ahZ/6N0yoFNsxnzgg?= =?us-ascii?Q?AHegEKcaz1SzDh0Pw3qHvvKkS7eypEGN/13EX3crDfYf2KDsOK4kg6AsMcn5?= =?us-ascii?Q?DZer12LfSbc87QBWUpM+a/5jAkFYjFzIhIwnfYoJYOQ6SSR1dzokFCbjhM3X?= =?us-ascii?Q?j+321sUt1oQUfl5V3+UHum6CZJOCX+twUjwUcYdeScJulzy754A5pJbbo4nt?= =?us-ascii?Q?LogYjrYsWbEOhuNPvlY4Ndp7xS35Qa3VzEmfFD6kW2V86UOo6LpUddQI2xnF?= =?us-ascii?Q?wXkpzxKVAoomSna3aW4aC42m3K7bwBp2MBKLw4eF8pCl3OyCdaQ44A9a4IFC?= =?us-ascii?Q?sP7vc7BJ2I/k+MNIOUbjZelYuLR/L1zR4d5EQbvF4eymXrA6/s5uBqma5mgV?= =?us-ascii?Q?4ww/hw1jmnxWG3v8J9k/JmBSkzNBOwPzkOCnB7UmC52JoAfQXN5K9jz5klVy?= =?us-ascii?Q?AmuLJh99iCbrjX53H6htudWAhltLWtTooybvQ2CCGgfbGSh6Ztnlcw/yoCq1?= =?us-ascii?Q?ZEV016bJBlA69qHkc08VxfkE8/501tx9SbbWF/pBf2q7X8Y9SB/NPGP0Rd4Q?= =?us-ascii?Q?EGWDFJGCibk6aVDx6uNcA8C2FmOicj/An78X5CoIh67ou0MUwGfRMwTH+/31?= =?us-ascii?Q?lGbs689VYLgqbKYM7mtjgFnMgS85v1YDQy+LHeGJOL+cNEFEVSZjAkoliafo?= =?us-ascii?Q?j861AK96Q3+DBYLPaHEFiOAMC2MgvstPny5UWnxpJqtQW0U46biF/J8UAXPr?= =?us-ascii?Q?QD+NZzINHOy/WUE+AO+RSkNi/F8ajFW5HTPGTL4BdvZlG+OGNDJGiGcm9EZv?= =?us-ascii?Q?fWnE73IW3sLbY5TOQYcvoJEjADR98JiMXWSU0so/FsUWA/jHi0JH4teNLnWg?= =?us-ascii?Q?2w=3D?= X-Microsoft-Exchange-Diagnostics: 1; DM5PR15MB1916; 6:VdaxxT6+t1zwL/4cmsFnWemn1nsZeQU0rTcPYK/4auA+BX//ns255slN6H9nes056cXC+MhcorHYboQbCxi4JAGAHaeEU3oFU0CJgsPxomOZny/fCAw+02bC3uJTDlAFfcGf3+u6qgnmph96yKk9h7CVphy/cFwrtx9mXlRdphZnK0j8IfdlzokhbYv1+cdvni0WL2FzpWJBoRaekcV9a+6P+xe+Cc8B6I+EYbv7VZwPjNYjpRuDjhXUfiO2kTO29kbmZ/ldiCKtRzDpJitEP01hUyyHdGc0+ajbRQ2K7NjCFVgZ6cmgMLsGpuRtQp8FBmHS8h8k6KF0feK0REUcDOf+0rfvBdctCXrAGcATQraQIwjpqng4Z41h1PXkYT4B8McZPTklixw+ONiCXLZQYA==; 5:dHynrLjHTxiDqFi5sIlw4XG7iyJnejA3zVXgQo1mZpFD/OF/XJ/9Vy88/wg6/Vv3REZzjWIA79uPm3MqlAflXczZ0OTtm6gWqg6qgsp85ZvfD23xMBhSZY3YN+N29fqEXm0QoQOTb2zxJIcln2rivA==; 24:S6Mik3RtBa93H+ajQZFZv3YW8tssInAHi+Ee4vkf3Qk4mCwtjGR8SS8zgB2bUebpI+0qkJnWnX7PPU2ESrIVvaObkpAdIXknjTDrBO3KfmY= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; DM5PR15MB1916; 7:RFT6yhjhL8AN/tDSgvmMO+2X9y4ln502Bd8NMTCqYWOvg/0kQCyWSmwcxi3AZ/Ko2duFtKXlPl+k/iex8J4Yd8RWpue6xYzFdSNrFewFkb4h1Q2zxWssQabK0qY1PFql3vLfMWfIVTuPQ5JLORreU74Dcum/22LQ7PfS0DicmYlUbUOiQ2G6zhStg9wnImJFnsJdaXF/BooDs/znl88E03+JddCqmarLcDts5uhRduqhjMJf67Ys7YzR/uWzOm/TZnEM7iGIt6ZpW5NR0R2GkM4Q5lzmFsPNQhcUGoQABRhBGcq47u7qQfRKkI+Z4ZBLf7vJfEnv9yv6dl+Mq7IeLuawGyz6w8X7ycu5g2iHsaVFh1hN8SzPwiNKPoKjhIid1QOHeEFwPcJdLJ7rdOcKYW4Myeihtm00Ldd75DZS28/HpubmM3JI2KaArsrrmvyY4fpoMWsqefCNmEks8gSjEDrVT9fA3oakw60/yAYbaUjlfI3oTelwcJ2/fYMfkf9WMZRmBMBH6DGcoKyCoWF5CA==; 20:unqDXacQMQZVWmm3bdK6XKqMMz5Ot/FHBSjPUIGwA/WfoYupr7WxpyY0PqceG3B+mM3b85Cpd/lRharm1LfC+nBelxNIw9UsTKuaz6bN3kZIYldQlJZdaPJ5NvggwSAe2IyctZc8m4SBQcfvAY3POY+TrI3g4kOOGwkarU2ZZlc= X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Feb 2017 17:31:43.3736 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR15MB1916 X-OriginatorOrg: fb.com X-Proofpoint-Spam-Reason: safe X-FB-Internal: Safe X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-02-13_09:, , signatures=0 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 In preparation for the upcoming netlink interface we need to not rely on already having the bdev for the NBD device we are doing operations on. Instead of passing the bdev from the bdev ioctl around, use bdget_disk() wherever we need the bdev and pass that down to the helpers as necessary. Signed-off-by: Josef Bacik --- drivers/block/nbd.c | 88 ++++++++++++++++++++++++++++++----------------------- 1 file changed, 50 insertions(+), 38 deletions(-) diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c index 25891a1..0623f8f 100644 --- a/drivers/block/nbd.c +++ b/drivers/block/nbd.c @@ -168,13 +168,18 @@ static void nbd_size_update(struct nbd_device *nbd, struct block_device *bdev) kobject_uevent(&nbd_to_dev(nbd)->kobj, KOBJ_CHANGE); } -static void nbd_size_set(struct nbd_device *nbd, struct block_device *bdev, - loff_t blocksize, loff_t nr_blocks) +static int nbd_size_set(struct nbd_device *nbd, loff_t blocksize, + loff_t nr_blocks) { + struct block_device *bdev = bdget_disk(nbd->disk, 0); + if (!bdev) + return -EINVAL; nbd->blksize = blocksize; nbd->bytesize = blocksize * nr_blocks; if (nbd_is_connected(nbd)) nbd_size_update(nbd, bdev); + bdput(bdev); + return 0; } static void nbd_end_request(struct nbd_cmd *cmd) @@ -704,8 +709,7 @@ static int nbd_wait_for_socks(struct nbd_device *nbd) return ret; } -static int nbd_add_socket(struct nbd_device *nbd, struct block_device *bdev, - unsigned long arg) +static int nbd_add_socket(struct nbd_device *nbd, unsigned long arg) { struct socket *sock; struct nbd_sock **socks; @@ -749,8 +753,6 @@ static int nbd_add_socket(struct nbd_device *nbd, struct block_device *bdev, nsock->sock = sock; socks[nbd->num_connections++] = nsock; - if (max_part) - bdev->bd_invalidated = 1; err = 0; out: mutex_unlock(&nbd->socks_lock); @@ -771,18 +773,19 @@ static void nbd_reset(struct nbd_device *nbd) static void nbd_bdev_reset(struct block_device *bdev) { - set_device_ro(bdev, false); - bdev->bd_inode->i_size = 0; + bd_set_size(bdev, 0); if (max_part > 0) { blkdev_reread_part(bdev); bdev->bd_invalidated = 1; } } -static void nbd_parse_flags(struct nbd_device *nbd, struct block_device *bdev) +static void nbd_parse_flags(struct nbd_device *nbd) { if (nbd->flags & NBD_FLAG_READ_ONLY) - set_device_ro(bdev, true); + set_disk_ro(nbd->disk, true); + else + set_disk_ro(nbd->disk, false); if (nbd->flags & NBD_FLAG_SEND_TRIM) queue_flag_set_unlocked(QUEUE_FLAG_DISCARD, nbd->disk->queue); if (nbd->flags & NBD_FLAG_SEND_FLUSH) @@ -807,16 +810,11 @@ static void send_disconnects(struct nbd_device *nbd) } } -static int nbd_disconnect(struct nbd_device *nbd, struct block_device *bdev) +static int nbd_disconnect(struct nbd_device *nbd) { dev_info(disk_to_dev(nbd->disk), "NBD_DISCONNECT\n"); if (!nbd_socks_get_unless_zero(nbd)) return -EINVAL; - - mutex_unlock(&nbd->config_lock); - fsync_bdev(bdev); - mutex_lock(&nbd->config_lock); - if (!test_and_set_bit(NBD_DISCONNECT_REQUESTED, &nbd->runtime_flags)) send_disconnects(nbd); @@ -824,28 +822,40 @@ static int nbd_disconnect(struct nbd_device *nbd, struct block_device *bdev) return 0; } -static int nbd_clear_sock(struct nbd_device *nbd, struct block_device *bdev) +static int nbd_clear_sock(struct nbd_device *nbd) { + struct block_device *bdev = bdget_disk(nbd->disk, 0); + sock_shutdown(nbd); nbd_clear_que(nbd); - kill_bdev(bdev); - nbd_bdev_reset(bdev); + if (bdev) { + kill_bdev(bdev); + nbd_bdev_reset(bdev); + bdput(bdev); + } nbd->task_setup = NULL; if (test_and_clear_bit(NBD_HAS_SOCKS_REF, &nbd->runtime_flags)) nbd_socks_put(nbd); return 0; } -static int nbd_start_device(struct nbd_device *nbd, struct block_device *bdev) +static int nbd_start_device(struct nbd_device *nbd) { struct recv_thread_args *args; + struct block_device *bdev = bdget_disk(nbd->disk, 0); int num_connections = nbd->num_connections; int error = 0, i; - if (nbd->task_recv) + if (!bdev) + return -EINVAL; + if (nbd->task_recv) { + bdput(bdev); return -EBUSY; - if (!nbd->socks) + } + if (!nbd->socks) { + bdput(bdev); return -EINVAL; + } if (num_connections > 1 && !(nbd->flags & NBD_FLAG_CAN_MULTI_CONN)) { dev_err(disk_to_dev(nbd->disk), "server does not support multiple connections per device.\n"); @@ -853,6 +863,9 @@ static int nbd_start_device(struct nbd_device *nbd, struct block_device *bdev) goto out_err; } + if (max_part) + bdev->bd_invalidated = 1; + blk_mq_update_nr_hw_queues(&nbd->tag_set, nbd->num_connections); args = kcalloc(num_connections, sizeof(*args), GFP_KERNEL); if (!args) { @@ -862,7 +875,7 @@ static int nbd_start_device(struct nbd_device *nbd, struct block_device *bdev) nbd->task_recv = current; mutex_unlock(&nbd->config_lock); - nbd_parse_flags(nbd, bdev); + nbd_parse_flags(nbd); error = device_create_file(disk_to_dev(nbd->disk), &pid_attr); if (error) { @@ -893,7 +906,7 @@ static int nbd_start_device(struct nbd_device *nbd, struct block_device *bdev) mutex_lock(&nbd->config_lock); nbd->task_recv = NULL; out_err: - nbd_clear_sock(nbd, bdev); + nbd_clear_sock(nbd); /* user requested, ignore socket errors */ if (test_bit(NBD_DISCONNECT_REQUESTED, &nbd->runtime_flags)) @@ -902,31 +915,30 @@ static int nbd_start_device(struct nbd_device *nbd, struct block_device *bdev) error = -ETIMEDOUT; nbd_reset(nbd); + bdput(bdev); return error; } /* Must be called with config_lock held */ -static int __nbd_ioctl(struct block_device *bdev, struct nbd_device *nbd, - unsigned int cmd, unsigned long arg) +static int __nbd_ioctl(struct nbd_device *nbd, unsigned int cmd, + unsigned long arg) { switch (cmd) { case NBD_DISCONNECT: - return nbd_disconnect(nbd, bdev); + return nbd_disconnect(nbd); case NBD_CLEAR_SOCK: - return nbd_clear_sock(nbd, bdev); + return nbd_clear_sock(nbd); case NBD_SET_SOCK: - return nbd_add_socket(nbd, bdev, arg); + return nbd_add_socket(nbd, arg); case NBD_SET_BLKSIZE: - nbd_size_set(nbd, bdev, arg, - div_s64(nbd->bytesize, arg)); + return nbd_size_set(nbd, arg, + div_s64(nbd->bytesize, arg)); return 0; case NBD_SET_SIZE: - nbd_size_set(nbd, bdev, nbd->blksize, - div_s64(arg, nbd->blksize)); - return 0; + return nbd_size_set(nbd, nbd->blksize, + div_s64(arg, nbd->blksize)); case NBD_SET_SIZE_BLOCKS: - nbd_size_set(nbd, bdev, nbd->blksize, arg); - return 0; + return nbd_size_set(nbd, nbd->blksize, arg); case NBD_SET_TIMEOUT: nbd->tag_set.timeout = arg * HZ; return 0; @@ -935,7 +947,7 @@ static int __nbd_ioctl(struct block_device *bdev, struct nbd_device *nbd, nbd->flags = arg; return 0; case NBD_DO_IT: - return nbd_start_device(nbd, bdev); + return nbd_start_device(nbd); case NBD_CLEAR_QUE: /* * This is for compatibility only. The queue is always cleared @@ -964,7 +976,7 @@ static int nbd_ioctl(struct block_device *bdev, fmode_t mode, BUG_ON(nbd->magic != NBD_MAGIC); mutex_lock(&nbd->config_lock); - error = __nbd_ioctl(bdev, nbd, cmd, arg); + error = __nbd_ioctl(nbd, cmd, arg); mutex_unlock(&nbd->config_lock); return error;