From patchwork Fri Feb 10 18:06:44 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 9567231 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 5ED6160572 for ; Fri, 10 Feb 2017 18:09:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4F48B2859F for ; Fri, 10 Feb 2017 18:09:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 43DDE285A5; Fri, 10 Feb 2017 18:09:04 +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 8BD642859F for ; Fri, 10 Feb 2017 18:09:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752779AbdBJSIk (ORCPT ); Fri, 10 Feb 2017 13:08:40 -0500 Received: from mx0b-00082601.pphosted.com ([67.231.153.30]:52928 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751990AbdBJSIW (ORCPT ); Fri, 10 Feb 2017 13:08:22 -0500 Received: from pps.filterd (m0089730.ppops.net [127.0.0.1]) by m0089730.ppops.net (8.16.0.20/8.16.0.20) with SMTP id v1AI3aDP028028; Fri, 10 Feb 2017 10:06:54 -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=V08lDGymW9W8CAoJXwqmxPQBPOPL8L7zoSg5gW71KRY=; b=Cq3TfIjxGHNkWxsXzS36mNAbwEuaxSGzmi+XpDbzGDnvHcl2VkSa5tc9uvHw9Lz2YuUb NzSh3/7UWJ0BueDrCAstMB3/wuSsKYeiHewvztggklg+qhBFl6Mb7SuALpG9N4ImG2bz Lduv2MzjKu+wTcUEiQW9gaL8SnZYX5SGy/0= Received: from maileast.thefacebook.com ([199.201.65.23]) by m0089730.ppops.net with ESMTP id 28hhwtr402-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Fri, 10 Feb 2017 10:06:54 -0800 Received: from NAM01-BY2-obe.outbound.protection.outlook.com (192.168.183.28) by o365-in.thefacebook.com (192.168.177.26) with Microsoft SMTP Server (TLS) id 14.3.294.0; Fri, 10 Feb 2017 13:06:53 -0500 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=V08lDGymW9W8CAoJXwqmxPQBPOPL8L7zoSg5gW71KRY=; b=AjShU+I0w2Fd9aIYYHoDC8bMDr8PTYqGYowH1hDXIBRsOGyK0CMtZJ/pbhGIMR9PYY5agqF4y3K9uhaGtvhZYW7Pq9bDMkx3jCVObj13aQwEuQGEQHjcZSLTkq+zozLi9roAIT54iVIQzO9S0Gzx28eL1XDf9MG8gV3LWVY929s= Received: from localhost (2606:a000:4381:1201:225:22ff:feb3:e51a) by DM5PR15MB1914.namprd15.prod.outlook.com (10.174.247.142) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.888.16; Fri, 10 Feb 2017 18:06:47 +0000 From: Josef Bacik To: , , , Subject: [PATCH] nbd: set the logical and physical blocksize properly Date: Fri, 10 Feb 2017 13:06:44 -0500 Message-ID: <1486750004-2988-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: BN6PR01CA0051.prod.exchangelabs.com (10.172.194.141) To DM5PR15MB1914.namprd15.prod.outlook.com (10.174.247.142) X-MS-Office365-Filtering-Correlation-Id: a9dca28a-d9a6-4df1-18e0-08d451df943b X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001); SRVR:DM5PR15MB1914; X-Microsoft-Exchange-Diagnostics: 1; DM5PR15MB1914; 3:PX0A5MZPgDn2GCFYbrCCEempbYfORTJkdTSrRE8v/CqY9tvfDTgmV0AAFg+nYbXkdc/QfrRvDvqtllIq0JEhO+ZqU+5JtMxFV0mYkm/WEaUJWndEbDu82Ju7GRlcVkXTFsEYCPTl2/oVMr6RIHa3AjyFOVg16i43kTNv9pX1E+r6YhwJE1Cfb2WWXOmik3hDlcn8MZbSnCaV9VulLs8JIVb1rg2CdFRLMkk4NhFCQ3jUgK7YJ1kcSUhRcQYo0YXUxxmzDQ1cxtFu8ke43miwRQ==; 25:xRwvZXlKx0hlzHaJIgQI4OhNEfD2VCjlna3sCF4lOl3X9Lm5yJ7urt5CgsYBJTtFPHjJFmFa6ujnyY2z1bOqCuT+ppmFOrwRLF2UQg4dktFubwBzdTR/2x2BPE4MfJ8IwDMxsilCqI57Ww3OwQo67g6wHSHLoKACE0TiF6dnyYDtm3HCMT/xvIh5z4fqmfs8BaoVn5E34DU/IYIYdYMBZKV+JusU+kBI9iXFY4eNWNg5uOWL3W01o2sv3DmmicD6A5EcwZEdHPohWki5R3pkHymQ3Zg4Pck7rckG9mzhxixsDF5y44oP7WUbJqqlAv8+UOjQRS6A7p54NTMN3JYw4bj0TXI0eXU7/AxUNMFfwuz8PldDGKyZJv8ivJThsfydCPY3TYq0ck4/I7/gjrmxqRJG3UhdsH6Y1I14QVpSuep2vKeqSMHvhKAk+eRESU6ZU0/mFZwSnfiFaDFlzS+1Rw== X-Microsoft-Exchange-Diagnostics: 1; DM5PR15MB1914; 31:TIO9ELHNQgL0EQ6ixF44yuB6m1VUhfMMlLCLINWZ46/EXBxopbI6umknsTMdqGXagXX2aCmO2JyGHjNJSxihY7GKI+I27PwaVqS8H2WkkdEV5Al3D1LScYewsL75IdMPNvO4CMGekLsMoBeFraq1ZZwOfkyntAji2LHDBhCF5DQJ3L3KRk+MFRdB4fkTQWbV+xcK39n7IqGu/CcCSoEonBD0pBoMp1GFriTWMXJkKms=; 20:hfKR+4A74uloDVuz1KRK32oje6k4sLuG2EXR/9t0YHdd291gdWrl/tae9DXpODrhudpEqrFCmOkdqF+nwrWwo8c1sNYQZbeZB8SBsX8q/1LfqmmZnFYMLq4gCmwMeDTP9R/bwYecYnuMlZP/YToVXCKaC7MTcMQWpzM1mo/9FkAleChIZtmfTOUibCWe87tLSLW6KBWSmy5jcUHMV+7qRed2Ga2dUn7GPgtyyG+KEYwB1TSLJ+iwV36PaLV35EoU6ZOgz9ZjTgObLaKXgDzc7iw4gi7Tddt/NetrhE6i/x21Av0Xy0RT50LqNAX2jJ0KZQq+HrC9ekilMdJcS1GEGeGNV9iKim4ddOG01z8cf/49DbXhpquUO7sQjLdMU2XemXIBLd2PGURpDI3VMRAIOvUpERY+M3DROfFOf5blMrhstkhaVZ+i6FWMITX1ASAW6g7U/zRHWXZl758slR9js3rZg8MEaNbcjzhQ1Fd+s/08Ct7MsxTszf3xb2skjF9r 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)(5005006)(8121501046)(10201501046)(3002001)(6041248)(20161123555025)(20161123560025)(20161123562025)(20161123564025)(20161123558025)(6072148); SRVR:DM5PR15MB1914; BCL:0; PCL:0; RULEID:; SRVR:DM5PR15MB1914; X-Microsoft-Exchange-Diagnostics: 1; DM5PR15MB1914; 4:ACS4wB505oXcU0VVpnNYGnwsZ/o2ffSpb0168FZ+ZDcO3YxtW+jGWGvYBlz8QowNnkxks23EQA+9g75G9pSmUQR+CHXQCv6/lISm5MmSi+dRSdWTf9LiQLZOHwnHTMMY6d91/PJ8EGqJ5nKgTh1xT8IpFOHiq0FPYMbCkP5pyDxQG4J4fDGQzLPRXmMCMNZepDuQ6j4Iag5OGgdDlrf9MvQi4NksMuj9cy0XmhqjDh5lqdcrxy6zSSzaT+V3YK//XGaqOXCUaieZRbszN0KqUDBCisQYBGN5wZhxytWLc6VyC6FLVlq5t07BmzIAOeeokw4n5C21MNWZoKKTsEhefyp0hgvw0ZhyEEAiYWYf7AHuHFgXQZQrz8wnyuO5WMZHK3Rf24dIdTC3l/aCG3KqtQ+nVmiBNrGFrK//MaDKR4+SLSLmp2yn8q1njIQCyBju68axzevCGN9reiQb2r/0WoNAYJ0hGw9Xlu+MNnTFJxlhgU265PKeOH0r4miR4uEvyqf4sqEPlp4NXLDag1uiKkU3rmah0/WE17zczyMCW+mU/ZlSGAja6UTYHQ80DRMB+u3zvxn7502blAHATCxeqvNBXBLRPmw3o/Iis4UUpXWD/upczQ/V7TotSoBpEvOfEuC4xs+sjwllf7P3A7YdAzd7wKlbtDXXQVyruAVBDKqZxtGSLOtKMgW3AWpgsrPn X-Forefront-PRVS: 0214EB3F68 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(4630300001)(6069001)(6009001)(7916002)(39450400003)(39410400002)(39830400002)(189002)(199003)(68736007)(76506005)(106356001)(189998001)(5003940100001)(575784001)(81156014)(25786008)(7736002)(97736004)(8676002)(33646002)(47776003)(86362001)(81166006)(2906002)(2201001)(38730400002)(105586002)(92566002)(5660300001)(6116002)(42186005)(305945005)(50986999)(101416001)(6666003)(50226002)(6496005)(48376002)(50466002)(53936002)(6486002)(36756003); DIR:OUT; SFP:1102; SCL:1; SRVR:DM5PR15MB1914; 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; DM5PR15MB1914; 23:AmL5UKNfzYkTPtVCcRa4AWxUtgnV7/w4r3/DfFpu5?= =?us-ascii?Q?zXxM8S3+CLHkywJC9wiX7DWIILF+Wz5oAstliPXSG6XP3vcPNySmvYVQxlHl?= =?us-ascii?Q?MMhKmsG39gujJn8zzpNgo5g9h2mVvmar5E9xytelUw3avlp2Ht3ybvGggb4P?= =?us-ascii?Q?kt5aVSqmMBRXDdCq05VHL3rOs/04SVUYjXXb4WNTb0XouqpBr9raap7ffJyL?= =?us-ascii?Q?CZi+9aNN/vtWME2IJgpYSD+jAK3JDRbWtrX34RLfZuB6fxTc/s+mp0Pr+yro?= =?us-ascii?Q?rpj7uS2xWZYQo0GsQB0/1E8omyWTZRvoC8j9f0n7fRXD/buLnwGoTHfZ6VHh?= =?us-ascii?Q?19cVn5RGMRlyqzQK4jtG2mV2XDrrSzphp9Pb7eiSJJ9OoimfB1Gr0G5RudSe?= =?us-ascii?Q?vNFilhvNcbx4ww4IcW+wqkFITf19RwJkJjx0wN+ofTvE4xcGotHdx1FkfECU?= =?us-ascii?Q?8O/6PXlFo+D6QuSu98ejB5JH4dgGpoy97ilmtQx/HLH1HAvScNPlQSifjef6?= =?us-ascii?Q?LjkV9dXYhj6svAlukFJ4wXESH+e7aratTGwR6AuVyA81Q3n/oAxJVpTN7/pM?= =?us-ascii?Q?p/dSSVUDDsvrKYeEZvglE7AkNfzqnytzz0hZBGh7XMrWRCT/GWmNkA1fXKvq?= =?us-ascii?Q?iohQTMN2Xz79LgwGyQ3mRbHyam03kgV0OsrhdNiB5HsAIMPvHzp3Xthv5jKQ?= =?us-ascii?Q?oK2nPTBlrcSUMbiroQVU/LlpvTGz1pqLN8MwZKpKfcRxkX3X3uDVjOCn26m1?= =?us-ascii?Q?9SOzdxj9OwT0EZQUAjJGpHxHFL4BgrvkacdSk1laJ79QmRPeK/6bYUNc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99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; DM5PR15MB1914; 7:FKpqktRdOPjaZw0tL+lcdcDUwcq2XvMvVb85X1WkzmtmrGIUZn/+HnwqJTLgA3tOA2pRqVPVQMS7erSMrxmHQA47amHUlsPjuPBeZ8dVI2Y2nDSqyzR4m8Lj7l0A3lBAk/6+lzf4iVvLUNdAz1f6GkiLpRqavdg7r2dmJUxuZbcP8mkoH8IUkfwS8/KMbXSjOz6+gwCOqSLs2HADtdmtXDVHKDCYpBqrM98Vpsf+lwL5MenoM/oBWAzd2bOtVRLJRAoNuzDe5bZbxZMpipwgbbgi3pWjtI69glpuH/qoRGIIyLQpF3CeZtthsx9K+krlBbTdyQlCrwyzIY45jtMZwisBYQUQrBiFDyzAZ9F8Uq2OYI6gvz0LoMyZ+BjLb6PUo0oT/PzQEzd46p+ZKdXeSCWqvUTwkGj/Ztc4UT490yJINtYgzG2sI72wDLVA9DqGTkW35OF8b6Mfp3/PTSptG4xtVLjtEymF3cepb1QONwE7GtlUbz06azgsBPclv6EeOmtq+1uxWpC1ZcOcqBymWw==; 20:3pQB/vxbgTwYMNLq+DB59irUmNJa99etd8G0jscKWsa/upJGeDfXdtvRUo6JOIGEM2g17wkBAxg/SECnT/mXHrzdOVfCT8atfu6vzizgtM964ynQPbIj385UIHdLfF89F8mSu2YvhKkJpuHzfWjkMJmVVteR/a/sEiNkEtch2PY= X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Feb 2017 18:06:47.0798 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR15MB1914 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-10_07:, , 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 We noticed when trying to do O_DIRECT to an export on the server side that we were getting requests smaller than the 4k sectorsize of the device. This is because the client isn't setting the logical and physical blocksizes properly for the underlying device. Fix this up by setting the queue blocksizes and then calling bd_set_size. Signed-off-by: Josef Bacik --- drivers/block/nbd.c | 39 ++++++++++++++++----------------------- 1 file changed, 16 insertions(+), 23 deletions(-) diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c index 34a280a..e0d770c 100644 --- a/drivers/block/nbd.c +++ b/drivers/block/nbd.c @@ -183,7 +183,7 @@ static int nbd_clear_reconnect(struct nbd_device *nbd) static int nbd_size_clear(struct nbd_device *nbd, struct block_device *bdev) { - bdev->bd_inode->i_size = 0; + bd_set_size(bdev, 0); set_capacity(nbd->disk, 0); kobject_uevent(&nbd_to_dev(nbd)->kobj, KOBJ_CHANGE); @@ -192,29 +192,20 @@ static int nbd_size_clear(struct nbd_device *nbd, struct block_device *bdev) static void nbd_size_update(struct nbd_device *nbd, struct block_device *bdev) { - if (!nbd_is_connected(nbd)) - return; - - bdev->bd_inode->i_size = nbd->bytesize; + 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 int nbd_size_set(struct nbd_device *nbd, struct block_device *bdev, +static void nbd_size_set(struct nbd_device *nbd, struct block_device *bdev, loff_t blocksize, loff_t nr_blocks) { - int ret; - - ret = set_blocksize(bdev, blocksize); - if (ret) - return ret; - nbd->blksize = blocksize; nbd->bytesize = blocksize * nr_blocks; - - nbd_size_update(nbd, bdev); - - return 0; + if (nbd_is_connected(nbd)) + nbd_size_update(nbd, bdev); } static void nbd_end_request(struct nbd_cmd *cmd) @@ -875,6 +866,7 @@ static void send_disconnects(struct nbd_device *nbd) static int nbd_disconnect(struct nbd_device *nbd, struct block_device *bdev) { + printk(KERN_ERR "%u is the blocksize at disconnect\n", bdev_logical_block_size(bdev)); dev_info(disk_to_dev(nbd->disk), "NBD_DISCONNECT\n"); if (!nbd_socks_get_unless_zero(nbd)) return -EINVAL; @@ -997,15 +989,16 @@ static int __nbd_ioctl(struct block_device *bdev, struct nbd_device *nbd, case NBD_SET_SOCK: return nbd_add_socket(nbd, bdev, arg); case NBD_SET_BLKSIZE: - return nbd_size_set(nbd, bdev, arg, - div_s64(nbd->bytesize, arg)); + nbd_size_set(nbd, bdev, arg, + div_s64(nbd->bytesize, arg)); + return 0; case NBD_SET_SIZE: - return nbd_size_set(nbd, bdev, nbd->blksize, - div_s64(arg, nbd->blksize)); - + nbd_size_set(nbd, bdev, nbd->blksize, + div_s64(arg, nbd->blksize)); + return 0; case NBD_SET_SIZE_BLOCKS: - return nbd_size_set(nbd, bdev, nbd->blksize, arg); - + nbd_size_set(nbd, bdev, nbd->blksize, arg); + return 0; case NBD_SET_TIMEOUT: nbd->tag_set.timeout = arg * HZ; return 0;