From patchwork Tue Feb 28 16:57:08 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 9596403 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 CC7D960574 for ; Tue, 28 Feb 2017 17:36:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C202827FA6 for ; Tue, 28 Feb 2017 17:36:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B6ACD28547; Tue, 28 Feb 2017 17:36:15 +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 DA49127FA6 for ; Tue, 28 Feb 2017 17:36:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751600AbdB1Rf6 (ORCPT ); Tue, 28 Feb 2017 12:35:58 -0500 Received: from mx0b-00082601.pphosted.com ([67.231.153.30]:40496 "EHLO mx0b-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751248AbdB1Rfu (ORCPT ); Tue, 28 Feb 2017 12:35:50 -0500 Received: from pps.filterd (m0109331.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v1SGvYR2025369; Tue, 28 Feb 2017 08:57:50 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=facebook; bh=+jvDVQ6sEGJHVqS87rNK6rvTmQMjME3fij3DWGfBr1k=; b=Lbt/GhFecT26JVsPbNxZoHhTCSTa/+R+BgnIVCdU7Z9dA/LgOdHAb0uLB9ejj1AdFcsj 1tGh0B0697GlNa6AxUWNFxhLS5OLlogsbhEWLpx1TtHsay5WWT535leKu6a5MgjAJMt3 KE/Kaku6pLeoeDoamNNc+1Wa46EoDs+xZqE= Received: from mail.thefacebook.com ([199.201.64.23]) by mx0a-00082601.pphosted.com with ESMTP id 28w838h4ks-3 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Tue, 28 Feb 2017 08:57:50 -0800 Received: from NAM03-CO1-obe.outbound.protection.outlook.com (192.168.54.28) by o365-in.thefacebook.com (192.168.16.14) with Microsoft SMTP Server (TLS) id 14.3.319.2; Tue, 28 Feb 2017 08:57:49 -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=+jvDVQ6sEGJHVqS87rNK6rvTmQMjME3fij3DWGfBr1k=; b=HjH8kRbfRlbttPP945mKu9OVIW6vD0DbSh7mHmbnZqnQew8CDeHZRz6usEUKYRYT5BogtVn/P14mJ83yxEZfaXoEzAdWMxQgTtLMoSsQ9rocucdZfJf86t08ky2ue+gBF+lZYgvcoIyfSmJbLH7nklj/NqqmuRZ95EGJ0bdL0mM= Received: from localhost (2606:a000:4381:1201:225:22ff:feb3:e51a) by CY4PR15MB1909.namprd15.prod.outlook.com (10.174.54.142) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.933.12; Tue, 28 Feb 2017 16:57:46 +0000 From: Josef Bacik To: , , , Subject: [PATCH 3/6] nbd: stop using the bdev everywhere Date: Tue, 28 Feb 2017 11:57:08 -0500 Message-ID: <1488301031-3199-4-git-send-email-jbacik@fb.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1488301031-3199-1-git-send-email-jbacik@fb.com> References: <1488301031-3199-1-git-send-email-jbacik@fb.com> MIME-Version: 1.0 X-Originating-IP: [2606:a000:4381:1201:225:22ff:feb3:e51a] X-ClientProxiedBy: BN6PR11CA0046.namprd11.prod.outlook.com (10.173.25.32) To CY4PR15MB1909.namprd15.prod.outlook.com (10.174.54.142) X-MS-Office365-Filtering-Correlation-Id: 810e50ec-bdab-4028-fd94-08d45ffaebf3 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001); SRVR:CY4PR15MB1909; X-Microsoft-Exchange-Diagnostics: 1; CY4PR15MB1909; 3:by4gg8SYdxBlpG0LfLPa9MjUpw3RG37yOxRI7tz21ycc4IEHirs72eWJuDFFMMT33e4PHwTDuC3T4ypMQi4OKkYOjnwB8l12egRdQNkzE+QjfjOu8OPhs2GKjB0uLnACXGO4uzz6cqgyNgrlM5VQwVUnSmoysR+/pOLT/kfzlzdUyRmU+eUqSC9qQrd1Ne+joRf1OH975kbVBwSPAPP4Rut1kbe4PrZVna+TdDaVlW6cqPuiNg34pcbcD2HTDbAy6FkRmoSyQ8vVz/oGVm6lYA==; 25:8cUAIWTqn448WgZnk4shr2hCJ47raktWBaSm5DGl1DktJC8yivTO9Jr7UBhM7DGvoxvSUbMLhYt/iOnoQIac5+I8qFAY1LW9L8Q9SBkwMaeZlvesqEi9PLKMOxJ13DIiZtSkv9X8qfwbKy2Grx3usrgIbwgEJZHfP52sK3ofSQ1d+ifELUAea8OQUgljNINrsqBUnDGjI1bkRLavbKvrGuNHc9ZeEKnoimOklpaTDm0axYHcc9MEGaq+NbUUySMnx/IZeyZ17nT63SpHK2wr69dRHB8gKoIjZUyzU+Uo9EVzp2RVGuyvm7kQSTJrWXOvkOSMi5+cmDwulkTaC4aEx797TonmKgePCEVJbVtlAn9x0ky2Y94wS0sYagm3e+B3DHKOLRyQA5QlNTCDipAkZiVHmY8KNI7u+vnKwaZ5tc2mmvQAszIf6MWlHbFJFUFT76oPD0jptSsvRQFNuHLSZA== X-Microsoft-Exchange-Diagnostics: 1; CY4PR15MB1909; 31:4lWy+w9iNh/3esbk2e2mCXUWXdfklN3yqChCetXcbaOnHHhrCpbaJmrDUdIqnXdTIplt/RlimKmxcN4eq0NR2wVSltCXL1cHHCZ7bEUVXWfqftF9HORlsBlDQDHIfcdEHdrAJQVecOzsqkzeKnXcAL/+3i3iwAFIHG8Jb/T8vE0f/L19W1jMqS1hZiVIVasXTOY4JBYjrwUMOOC2jjqZTMsTsWrsYbHwKYVt2CZ4BhE=; 20:m+EC4xcRcK/0aQnu7y74tg4wkxEI1QBCJ9JlmVaEumX0YVDrgSWwpTl4crk8RHXZnuEGndvJ+yeaZyVEYSRM+GLjPu8XMKTqnTvrlQc+CZRWWrTbvib8Ho7dAn45Qq4NTrjhsNX1xSFHdhGUU7hFXFFMSBU2N3og7whh+HJl/C6sfQdYTOcNUMratL4122YIqSXaQum7H5nZsl6mrZ48gHBTpaDlPuEQLtYhGhZdQcg0jlFI6bX5IIcO6eSmSIgs5fXqYUFQ6+gdjvCWFKKqhtsq67A1xlNHzWikkgh1Oo487khXpEPE1IzE6b23xe6I8R0DonBzRXGxqqruRuvgvRopBxO0j6Pm246shtCrl+Hqe7ltMEbcX0Y1KHLT/rWhCItosVtTWHE2BEMFlhz5iD3Sgcht8edhziNoNSBot6SPJRIxN9vdHejycpz2iT0fmrjRUCQ5DND60BVv/W5yDZmun1mb12dK2ZQoIh1x7qsAsO+mFRpJCq61cA6Eq5Bq 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)(3002001)(10201501046)(6041248)(20161123558025)(20161123564025)(20161123562025)(20161123555025)(20161123560025)(6072148); SRVR:CY4PR15MB1909; BCL:0; PCL:0; RULEID:; SRVR:CY4PR15MB1909; X-Microsoft-Exchange-Diagnostics: 1; CY4PR15MB1909; 4:IY/AqjRRiZ7BLSoHbUUpt9J/Oe00YTma89YRXewOoEGP1At5zUgVdFlfX6tc20ZN3XNx3DYwHRruKP6u+Dx0fHKPvoUqR1I8R5A94MmRh4o5KsQl3lkQ9MLRxqtiD7OLkXUp7iLXrcDWldAEKg8Eq3egMusgnfcohdIVB7ueU5Hgi9ve5K1eSAqFXEkM9Pk9Ce0W1+3p/6k9X3wTlV63al9tGg5qkYu/6ULzjO0MFGVwDl6agopkbibUvImJ9/6mLlhyLdC88lpJarGvXuxyyTmmw5U16ZFl77S8VFAnNol9RZgeTSZzeoCHIt5R4u9QpFKrk+8B6mS0FkdC4eYapMDmSTp7Q/ff2XG/6LM3buC67hOgo6ogS+3l80DsHbIDI1IftLNeV0134tG0ivX+LiOCVchsSY+/BhToFPXBk8aI8rWU1zkoJ75KpuXvawNgzLsqckbipH9TzFbrESvNTIlrheIVebOvdLW+WsvBZOt0m1A4zHth6QhN1OQzpRCVkldnm3vaIDvZRU4hKYyXwF7EoXDCxbSX3GSOF28rUSuYh2D78aA5wbXXwBb0duL7T+2STknWsdmO5B6wpgbSyAbA2wIIJYuTZjQ7kdiz3tReTu5ZXe+mtgcfWXJpvQYEVNl/Sw8835JTVwHqhYCTpCqlSrDcEdwVemv5mdTMKah1lug6F27WGS/eJATnVywg X-Forefront-PRVS: 0232B30BBC X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(4630300001)(6069001)(6009001)(7916002)(39410400002)(39830400002)(39450400003)(189002)(199003)(76176999)(5660300001)(106356001)(105586002)(25786008)(97736004)(5003940100001)(2906002)(50986999)(189998001)(6666003)(101416001)(2950100002)(50226002)(6486002)(81156014)(8676002)(81166006)(36756003)(6636002)(305945005)(7736002)(68736007)(53936002)(42186005)(48376002)(50466002)(86362001)(92566002)(47776003)(76506005)(6116002)(6496005)(2201001)(38730400002)(33646002)(309714004); DIR:OUT; SFP:1102; SCL:1; SRVR:CY4PR15MB1909; H:localhost; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A: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; CY4PR15MB1909; 23:mBW3N9ONwEdjm5R8cKP1rYVy8jFBUUDKpBQuBCmu9?= =?us-ascii?Q?oDomt/9PsC3thd6CVjgg29AE6vAjUUNJQh2AK8ykQ4+Z0bSXJQN8gjHCoNPQ?= =?us-ascii?Q?vicyL5hugBn+Pk8kCOOwRupkEkoYXTTDiCpj+xS7CgobS8x8lcNMfno1NGov?= =?us-ascii?Q?OfSApEFU0mhGJ8CZBNQYPw7Gdl7cQFsbzYat1Yo55+dBrTuCyFOrLSrDawVA?= =?us-ascii?Q?zfRTbjm0YN3W+cPhD1Rb7CSqWprGyCXsH4vrft9Fh+22IfPj8BBjmX0GFCDz?= =?us-ascii?Q?uwFDgCcGXgiND+QSBhFjBTQDimefJYeMJe6P3tLEXQ+cZRo1IQrd5pS/IYXB?= =?us-ascii?Q?NY2iBBIzWBHq6Rr1QMPEJmMhsv/kM9/5+KWvqFl3jPwoiMg4JJleMITGA/Kq?= =?us-ascii?Q?tVk2YN202itFKRwFyZEV27Ym1GaDkAGwiZTDBo2o+ygEkRPrSweZYHE2rcTf?= =?us-ascii?Q?YKJX4p7qYc6Q41QfcCtmuOA2u+OZPZ/gU1PrFBZjOAH3yBsLEWnXODSLXLh2?= =?us-ascii?Q?IR20y7VcfIAMkHdV+oLeFT7ZlBiEBUBfmNEi67wAFLbXktG3/MDGFo5UBNSo?= =?us-ascii?Q?geWDANenGzbqyDPCzwOfm/lD1VdwmzUWOu2rK41DBslrHPUDZML5Ffdhs8/J?= =?us-ascii?Q?2kg/BNAyuuD6MZ/CjGW1xERRMUFsAxnwtWwwe+exMwGoRsqtjuy3jm3LL6Ty?= =?us-ascii?Q?/ElilkLgqjbkniBoNUw1S+REzb9j9kBnrvXDTzRLZL2sAq0ohCad+5bUia5P?= =?us-ascii?Q?iCr9u3M8YLVfbkFXHfi3ybV1J197FSsAHZyF2TrAB2iLJfhwJkPsI1QsVYBZ?= =?us-ascii?Q?9XPeQmtRBK0pusPEviiwnLp/5UUQ15CaK+P59rMBqOw8dijDwRavIk0gxFLB?= =?us-ascii?Q?8P6rRPFLxGdtzXKYDfYt7mpa9oBo50gPqbZEkbRCJy0zcj48DubjSNQ2riDz?= =?us-ascii?Q?kWwzvKBPhSmPh0ge5nGsD3TiOTNt1SZV3TMms4NeCqPqDyA+23qQ7kV1X2v5?= =?us-ascii?Q?KkrCUi9XRgJcqn1h0loYuU+RZ0GvmZ29Nsi1ckJ+Pql7M6lPgrZGlvFrHxcE?= =?us-ascii?Q?Oa9L9Kc7MaFHUthr2sAEdHbcBqKUYIP5c0fNU2BThOkc141Fz6etUx41++G8?= =?us-ascii?Q?NOzEz+AmH5knxLCRfETTccXv+V510rv?= X-Microsoft-Exchange-Diagnostics: 1; CY4PR15MB1909; 6:BlNgAv047SmYzPqnZPDqI+9iPIxMs2eFCJTXS4s/ox40qSe21J3dVMPRTdC3thBpl59DlkLGMJp4Yr+vnK7hJ8Dts5Ebo2leOKYR216fNaNBly2SKq4e9/sqdFoCHY+Uc1VqTyQrHdzlXokEUe7iBV+W1XuheHC29ELQLLVBdrHS+z5rt6i//repyv3tsHcwi/A+wzPhxKDMrnYLKcFeuRj5oYUD2RTEY338K5qdDdlucmkN+Vmb9SdY/iQldXrlZ1/KFDhyoX6s4uZfKTQR7clT1nYtV0OZ7JbX+qtODVET0xnGKdTyDU1wdY9R/nuW5yjvdNd0Lqhw2Mw54f+R3l9a1GjZVe37+ZwgqOMvm2iA2rP/0ic1Hxkd2J1SNjHBPRG9ftsed6Rh2OyPYYZTSg==; 5:jnXbHnqpSk04YTIVmXnENjU9S1MzNBOTw3z5cOjP/KhFJ/58ZLJModbrBBDjwjc4q1V1sUzIFZW+jJyk9svkChBJvdf6xzAqlJTKChY2uc2InZPEFUuuBKCfDsY9b3fCc7WNNQyQA89nvxKboT5Ts/HnQDkGHjT2MjKFAVB8RyM=; 24:yTF34ja6AfJ3eXopuAslRxbj+HAqtYC3a62ng+jinqUwaTnJn1yayEA/8eQuZEOuGmrwB7FzPOJhPmQhy7WUc/YEYW7kOX/Ff0g55HZ3Iuk= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; CY4PR15MB1909; 7:BF+XGL7OV0umvCNxDqjRzXoqK/wkuHncBPEqPvq8dNsEkNffLjWjfL6fjD2zgNlBTSCeurm9IXZDiKfR8gibENooZiR3ePnivqtJ3znttDMtlY5S2ZQqZHmELhgLsv4VVt7crNDVN1IX0cHcnJ1TxgLcueZviXju8triSiyMUyYSqcxzbUWrpkNdVnjsdwhdPUXc0ujYmBPqwIre17BjPDJ4pVW0nYZ93rRJ/4+L+U7ajXCHXoHBMQdKgymVwofFgSNH2WiSjcoBBY9dtMOnpEOP34RhiZCWjGSe5ooXrnRV4nIO74iqranXFUpOmaW1X+gYdjnwapo/ETe66oIUtA==; 20:DtiCQi7ONGe8OA5l3Hwhg2KUlxmQPpzXmMSjjucChWioqlnkH7DMPojcMXmmFEjemOheo/r5a1F9Ht37YjGc/MRZtdDIRvwzNAs5xWankNDZPhR86+AD8awxtRx4IuPQApvQAEj9EhtYSjer7zL5UbQ4kqLHmMTDcGjcVaLBqPY= X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Feb 2017 16:57:46.9462 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR15MB1909 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-28_15:, , 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 around, just use it in places where we know we already have the bdev. Signed-off-by: Josef Bacik --- drivers/block/nbd.c | 93 ++++++++++++++++++++++------------------------------- 1 file changed, 39 insertions(+), 54 deletions(-) diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c index 6760ee5..059c80a 100644 --- a/drivers/block/nbd.c +++ b/drivers/block/nbd.c @@ -119,11 +119,6 @@ static inline struct device *nbd_to_dev(struct nbd_device *nbd) return disk_to_dev(nbd->disk); } -static bool nbd_is_connected(struct nbd_device *nbd) -{ - return !!nbd->task_recv; -} - static const char *nbdcmd_to_ascii(int cmd) { switch (cmd) { @@ -155,31 +150,26 @@ static int nbd_get_unless_zero(struct nbd_device *nbd) return atomic_add_unless(&nbd->refs, 1, 0); } -static int nbd_size_clear(struct nbd_device *nbd, struct block_device *bdev) +static void nbd_size_clear(struct nbd_device *nbd) { - bd_set_size(bdev, 0); set_capacity(nbd->disk, 0); kobject_uevent(&nbd_to_dev(nbd)->kobj, KOBJ_CHANGE); - - return 0; } -static void nbd_size_update(struct nbd_device *nbd, struct block_device *bdev) +static void nbd_size_update(struct nbd_device *nbd) { blk_queue_logical_block_size(nbd->disk->queue, nbd->blksize); blk_queue_physical_block_size(nbd->disk->queue, nbd->blksize); - bd_set_size(bdev, nbd->bytesize); set_capacity(nbd->disk, nbd->bytesize >> 9); 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 void nbd_size_set(struct nbd_device *nbd, loff_t blocksize, + loff_t nr_blocks) { nbd->blksize = blocksize; nbd->bytesize = blocksize * nr_blocks; - if (nbd_is_connected(nbd)) - nbd_size_update(nbd, bdev); + nbd_size_update(nbd); } static void nbd_end_request(struct nbd_cmd *cmd) @@ -670,8 +660,7 @@ static int nbd_queue_rq(struct blk_mq_hw_ctx *hctx, return BLK_MQ_RQ_QUEUE_OK; } -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; @@ -712,8 +701,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: return err; @@ -734,18 +721,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) @@ -770,16 +758,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_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); @@ -787,33 +770,22 @@ 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 void nbd_clear_sock(struct nbd_device *nbd) { sock_shutdown(nbd); nbd_clear_que(nbd); - kill_bdev(bdev); - nbd_bdev_reset(bdev); nbd->task_setup = NULL; - if (test_and_clear_bit(NBD_HAS_SOCKS_REF, &nbd->runtime_flags)) - nbd_put(nbd); - return 0; } static void nbd_put(struct nbd_device *nbd) { if (atomic_dec_and_test(&nbd->refs)) { - struct block_device *bdev; - - bdev = bdget_disk(nbd->disk, 0); - if (!bdev) - return; - mutex_lock(&nbd->config_lock); nbd_dev_dbg_close(nbd); - nbd_size_clear(nbd, bdev); + nbd_size_clear(nbd); device_remove_file(disk_to_dev(nbd->disk), &pid_attr); nbd->task_recv = NULL; - nbd_clear_sock(nbd, bdev); + nbd_clear_sock(nbd); if (nbd->num_connections) { int i; for (i = 0; i < nbd->num_connections; i++) @@ -825,7 +797,6 @@ static void nbd_put(struct nbd_device *nbd) kfree(nbd->args); nbd_reset(nbd); mutex_unlock(&nbd->config_lock); - bdput(bdev); module_put(THIS_MODULE); } } @@ -846,7 +817,6 @@ static int nbd_start_device(struct nbd_device *nbd, struct block_device *bdev) error = -EINVAL; goto out; } - 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"); @@ -854,6 +824,9 @@ static int nbd_start_device(struct nbd_device *nbd, struct block_device *bdev) goto out; } + 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) { @@ -864,15 +837,16 @@ 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) { dev_err(disk_to_dev(nbd->disk), "device_create_file failed!\n"); goto out; } - - nbd_size_update(nbd, bdev); + if (max_part) + bdev->bd_invalidated = 1; + bd_set_size(bdev, nbd->bytesize); nbd_dev_dbg_init(nbd); for (i = 0; i < num_connections; i++) { @@ -901,27 +875,38 @@ static int nbd_start_device(struct nbd_device *nbd, struct block_device *bdev) return error; } +static void nbd_clear_sock_ioctl(struct nbd_device *nbd, + struct block_device *bdev) +{ + nbd_clear_sock(nbd); + kill_bdev(bdev); + nbd_bdev_reset(bdev); + if (test_and_clear_bit(NBD_HAS_SOCKS_REF, &nbd->runtime_flags)) + nbd_put(nbd); +} + /* 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) { switch (cmd) { case NBD_DISCONNECT: - return nbd_disconnect(nbd, bdev); + return nbd_disconnect(nbd); case NBD_CLEAR_SOCK: - return nbd_clear_sock(nbd, bdev); + nbd_clear_sock_ioctl(nbd, bdev); + return 0; 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, + nbd_size_set(nbd, arg, div_s64(nbd->bytesize, arg)); return 0; case NBD_SET_SIZE: - nbd_size_set(nbd, bdev, nbd->blksize, + nbd_size_set(nbd, nbd->blksize, div_s64(arg, nbd->blksize)); return 0; case NBD_SET_SIZE_BLOCKS: - nbd_size_set(nbd, bdev, nbd->blksize, arg); + nbd_size_set(nbd, nbd->blksize, arg); return 0; case NBD_SET_TIMEOUT: nbd->tag_set.timeout = arg * HZ;