From patchwork Mon Feb 13 15:39:47 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 9570081 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 2936560572 for ; Mon, 13 Feb 2017 15:40:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 202B3281D2 for ; Mon, 13 Feb 2017 15:40:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 14D1F28355; Mon, 13 Feb 2017 15:40:19 +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 D15E7281D2 for ; Mon, 13 Feb 2017 15:40:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753727AbdBMPkL (ORCPT ); Mon, 13 Feb 2017 10:40:11 -0500 Received: from mx0a-00082601.pphosted.com ([67.231.145.42]:36484 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753651AbdBMPkI (ORCPT ); Mon, 13 Feb 2017 10:40:08 -0500 Received: from pps.filterd (m0044012.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v1DFdIgK010653; Mon, 13 Feb 2017 07:39:55 -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=CH9B7fcjdhvj7NPXyqCD+JTNjpXGATsd9rr3WQ1tKJs=; b=GGtxDdcSZEwMxKKTFWvO8XbORC1/HhnhVxZxj+R14G2HYBh6H58pElKpzDb1e40cjHm8 AgyAYIppTUPXSZwSoxFDsIwkAce0+66bQnyEFMehAb2xWT1yeNve4UHfV7bIZrhgYMc2 q8hWMVStP7ZRJ3Ktx1JMXlVrgONsvsLCe0w= Received: from maileast.thefacebook.com ([199.201.65.23]) by mx0a-00082601.pphosted.com with ESMTP id 28keyr066u-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Mon, 13 Feb 2017 07:39:55 -0800 Received: from NAM01-BY2-obe.outbound.protection.outlook.com (192.168.183.28) by o365-in.thefacebook.com (192.168.177.32) with Microsoft SMTP Server (TLS) id 14.3.294.0; Mon, 13 Feb 2017 10:39: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=CH9B7fcjdhvj7NPXyqCD+JTNjpXGATsd9rr3WQ1tKJs=; b=INQYKX4IP8AocUl9XbBfhaC9moDnVrjMMhHbtSRYQERnzBqG+nv/tDlpvBZ2WbQ1eZ47OhCQDftlB7lW8fpjYk1vjCyaXL+aEUaXfxOLd+a/34mIeS+iM63/zemNIpoMlN7vP/607HcOSJDiZCbKxfLP/VMK2HjhmLHOgDn2r9k= Received: from localhost (2606:a000:4381:1201:225:22ff:feb3:e51a) by BN6PR15MB1908.namprd15.prod.outlook.com (10.174.239.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 15:39:51 +0000 From: Josef Bacik To: , , , Subject: [PATCH V2] nbd: set the logical and physical blocksize properly Date: Mon, 13 Feb 2017 10:39:47 -0500 Message-ID: <1487000387-1372-1-git-send-email-jbacik@fb.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1486750004-2988-1-git-send-email-jbacik@fb.com> References: <1486750004-2988-1-git-send-email-jbacik@fb.com> MIME-Version: 1.0 X-Originating-IP: [2606:a000:4381:1201:225:22ff:feb3:e51a] X-ClientProxiedBy: BN6PR09CA0021.namprd09.prod.outlook.com (10.172.16.31) To BN6PR15MB1908.namprd15.prod.outlook.com (10.174.239.144) X-MS-Office365-Filtering-Correlation-Id: 109a844e-b282-4214-f617-08d454268cdd X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001); SRVR:BN6PR15MB1908; X-Microsoft-Exchange-Diagnostics: 1; BN6PR15MB1908; 3:yy9DfLcUX921JlBiF8XZq/4EGpbGzA4Idifu7ecdyHxz6f9D5wvCv4Z+Wg/ZqSQsI2PjO+U41qHxZkcYzXJt8H6qw0PSN1S/InDZmTvDFvJ9X15oFXcsAiTjc/JtzZ7K43qXGFU/D5vnDf5Bx9I37hzHLf5nAhm3K3vwyjdVrp3jEXCCRyBCksUsnRHQNpyRhc4DMdF7ClE6tti46zlbZkNIlRo/UK+QgP2AYc6M8tYUXAfQIHCKdIPSjbWHIH/9uJZMDhTkDqLfvaJd4tkFSw==; 25:jpdTp4p2VHYO4mjp3GTD0e8kEdO85cyB5aT7nvNuB2ieD9tOqN9x1VlxiQtmAwcwzCz2AJMoSS+7yWPnpqULaKMWiX7O0wJHISPO0DfuNpnezjmdVrltiXx/JtOcVseAaxoYD6/DfD4qbutPf3ZJ+0Qgc1yilPns/Ph918lbB+Clpja90ezlIBPIKi0tqZQcU1tuSKhiwLE8Kj2m+WMax+0TZMicwcqgBhZBHpLdOpNBS9po98T7x2KJq1rRUhHSrrDmwLAwuGg6X7ZlUlMw0kxuXDYlCvbC2XvrD0E4io4xZmTeisfHg56V8kb/NNpqzgJGRAWBe7bL6knTruqsszocEPMQlZyur5IpqX+c4X7WhqGl5iH0uspl9YcO97dmB9NqMDDuJNnb/riBOMkdMlW0CLuwzkC1AL1iH3DlyHz+h4O8pwGbcaU4nDAh14KCQ0DGlrBxzdxivkWWIJjkcw== X-Microsoft-Exchange-Diagnostics: 1; BN6PR15MB1908; 31:xPdfZTRKIPYy7i6nGDXZblwUTr4ozfgCxMtez4ey7BWMQYSatUW0dHSuXDHzJnegVT8BM6dYj7BDq4nFdFdWncjEt4PfvJ7ZdXN2Dsp/F/4OZ7PrDpYADmxKN7C5u2fyEhbURHYag6cjVpa02AMCaSlswX4esIgAvdXusHA8vtbiZpz9t513D5cTdt97HuK9Vsg1FvgECgg5wMSHsFB2WYj6GVeyq8aLJYIVvLXZp20zKnqAsnQVQc+8KgfJIyV6sh0U5an7FVbriJ2VYvF3xw==; 20:sCoAh1hqvgir9I4ELSFt6EifLusXNaxmobtKAjqnJXuXGGwWXyigpEW6UaytsXW6Wh3t2Kk23TqJUF+jvuaiF89gWvulaHU1/zptoHA87YLV/1/0ApiI52h6cNhqlARfmQM4lRd7iwzH/2QXxpLbUtyNDNy4mPs2VHMLXxzFnW7qtHm/NYMcs7agx/oNwQk11Pb+IyLVetrrVWmBLaNgph5bHQ05PYeer2kDRtkfgRuMIspKkNF9IOKgdDiWGOT9cKZAD0heH6bk+po8ZXZwIyW+vjD6RuZGKfHK3eJMvcW7a6vJGCiXxFXNCUY/cY2eARBifeuVgJiEX3MxNjeP1z4XUGrnjFk7hErX9QcLbqTIW+B8hdCdS+elPwpf2ql2UMssxD68efcww2bgvKQC58jh+RUQaDaluL1HfKlgXc7VTNDJAERgGzpHBz91CqB/iJztF/UP1ImJTKVgMIZaxOGdUwrv0Yk/gZgA51eLpiDEudsrzj0gO7n31X9PpMAX 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)(20161123564025)(20161123555025)(20161123558025)(20161123560025)(20161123562025)(6072148); SRVR:BN6PR15MB1908; BCL:0; PCL:0; RULEID:; SRVR:BN6PR15MB1908; X-Microsoft-Exchange-Diagnostics: 1; BN6PR15MB1908; 4:4JA+G2EVeN7wzQAuZcpuNEiDxHj0ecNvfBHIZ6WRW6zgqgPmrGUYgyT8EnDwGkPHMOuGxM9ZKTgftVU67gs8EM8xMIwvxr9xFC/hpG7Q0Vx0wqW/WGmh25c8MY3nJG2Mm8YaZwYgAzmDF90aQL5WdfDIRHLjkkjksUG5mtVZ18odiNBet3oMtSS7qMTPspt1/aubdHJu018vuXBESwsjOXYiz18YIx00kNkU70BjaXjZ+ea94ae3SoqboceV99NmaGVxebscIMv+lcSXQXTtkFjlLnAWeaFUaPS/By0KYOwH6gSNG5LQrsbIL/S9Uj4Xg9T65fSC2Ld+kkelujdzT+3H4qafir73CTqc4GHyRFajn0TCtpXrB1aVS6oq9eh0pDSlySlfmvaHi92j4ufbH89xpeTn5BCMudBQ7Yow45zXUskASSbZ5kYdkwOTKNkDenzHLwYl/s9nbbc7aIaxjuw0Gt93ChktqjFiJ54kz/5LBe0ht8SXkRuOFP5t6rwFGG0KYA2Qczfl2VTdSNmw/8TTo+M7tFW2LZq+kEiB0pqpzHZxzrZ2PfuCStLOUT4xIMCwC5Owz1ft696aKF6Cd6z1sCcwTcTtbG19PMyjU1EVLSFmfrde9fsP0Y3RYVM42k5eIMKvw56u1eJPGdnFkBKyLUkGT6DabnCpVCl8N472b2CLyyzFfJY3qXuPb4+b X-Forefront-PRVS: 02176E2458 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(4630300001)(6069001)(6009001)(7916002)(39830400002)(39410400002)(39450400003)(199003)(189002)(68736007)(25786008)(305945005)(6486002)(50986999)(76176999)(50466002)(106356001)(8676002)(42186005)(76506005)(5660300001)(81166006)(81156014)(5003940100001)(101416001)(33646002)(2201001)(38730400002)(47776003)(6496005)(6116002)(86362001)(7736002)(2906002)(189998001)(36756003)(50226002)(6666003)(2950100002)(105586002)(53936002)(97736004)(92566002)(48376002); DIR:OUT; SFP:1102; SCL:1; SRVR:BN6PR15MB1908; 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; BN6PR15MB1908; 23:l18iEQtKq3xIAzqLxtwwZwJ3ShTGDSmNDgBSmVLCW?= =?us-ascii?Q?ghYY6DB9zGVeUpRnh4Flz5Wwvc1A54W49S7UQvqpodB8JJLk6owI00PPLFqg?= =?us-ascii?Q?WQpUKd0T/GbYUpPo4/jtDl1F/6PLGnBG1Qk+Rr+LL5MUhRWQotfkEX2nUWo1?= =?us-ascii?Q?THBdn/jnHcpAp7JCQP2pitVZLK8Rly2fF6KK3vUqRJ+qcXWVJ5DwocMLu46Q?= =?us-ascii?Q?5VsKoXzQrWhV4CGvNyWIKZVpX58Yaa2dzXjvzOzaSlE1YN4gamj51Ka2sISw?= =?us-ascii?Q?T/p2OucLBF2jQcgPrg5dfxKHK3Lg5vaO198jJty1qhqP3hTdSXq5zteOX78d?= =?us-ascii?Q?yXchSb1RbSOt1e5hF+aOC2IPskjnaUP5S2ZsnG9AjHSNLJMYW8+pvTidA50K?= =?us-ascii?Q?ow69cA651Wg0Jg65FN8I9Kbx22jeqJtehy1/D/d2d1s0mYkoPoLEfAaArxR8?= =?us-ascii?Q?VCzpyxRVgcCAdveOpPBQhxvxZKSW+upppPIoyGif7jh8ws56G+Hw8WkMkWyi?= =?us-ascii?Q?YrO14gbqWM3pF6s8c9qCIfpR1ZtF6Rfh8PJlTImhwcGde5XDYJnYfLItThJe?= =?us-ascii?Q?ec0HoTHLi6BJIlrRUHey2msr9TI5bHth8bcwv96Tefd4Zv73r1WYrNXTQVap?= =?us-ascii?Q?o2vX+zBZm5KuHsGooBJr2FL9LxFAGJtDREpAEsdfyIQCCLrZ7raSqf0a+BiW?= =?us-ascii?Q?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zBSrwKPtGU2BQnqhrUMWrDnXHc8bVQ==; 24:JzHzHnR7UYzgqBn3D9UgxNT5dtJNcNN0M0VpZ9tC97Xlw1Y6IOFWbUXI564TdbWfB9f2Ap8E/j9zDUrAzOski2S3gedXSJDoNl+frSue9C0= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; BN6PR15MB1908; 7:hvfALBxkQukZJ7h7bLi5wktIWt47IaIspoWoz7eECmA+GA8a/BkyqmdsDGu+FlASZvxd01LmDZ0Zjfp2EuTJJFEG0GiyhRaGf7MUjXcPQ/XBij4IKXhl7+Xlof4enY731Tug0WiT/DWOd8fN6B5V/3IRU0pQqEJyZdSqQQ8nhUxCSx+xUAPFZelJWN5HKnkLJBOpKPWd8eNS06M82P6dAwNhNi6bP8rNn3vwafi5lYZC/vcLsBGsyUF4cGtYaCyHScDmis3x6nZauPPKRj5R9GxCA9oKVCEsQ6PUjRNVs6BrrTBxyf7pf1vZqDlS/wVbycl3tpupeCuTYlamgyu8zQs1jgsiwhtB692NidyKi0Tv9EWany8/D83zSoaOsAs2G6luBofMq3aqTofHlOT6QE8iKoUc4qVHKXrpYDDgYYzJnkg1QBgtbjpUJes9ShV88gq2yJunu2jK86cYp+2fiuG1Wl3mcxS0wipufLILDcKlk9ik7hk1ZTuz8yULF9/cG1EQrE4JsMG+WKr5nmnMHw==; 20:UpJf4dZaqrCbxa5pVIpL109HdbEqm0Nq5vvnrgodGIJRtUwxCXdoi+T2gYosYz+YpuBueqnf/oR0rqG7N+/g84Z8Knu1ZEwsRRE3xMmIyHdMb6MmWNXltXGGS5wJ2l5i9CDMqj4LarCX5mEcWYY+KjTBVtkQPoXbT0py+hqwX/U= X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Feb 2017 15:39:51.4399 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR15MB1908 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_08:, , 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 --- V1->V2: -remove an debug printk that I forgot to delete. drivers/block/nbd.c | 38 +++++++++++++++----------------------- 1 file changed, 15 insertions(+), 23 deletions(-) diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c index afb1353..25891a1 100644 --- a/drivers/block/nbd.c +++ b/drivers/block/nbd.c @@ -152,7 +152,7 @@ static void nbd_socks_put(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); @@ -161,29 +161,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) @@ -926,15 +917,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;