From patchwork Wed Nov 29 21:13: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: 10083591 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 0582460234 for ; Wed, 29 Nov 2017 21:13:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EC51A29C68 for ; Wed, 29 Nov 2017 21:13:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E14DD29C6B; Wed, 29 Nov 2017 21:13:48 +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.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,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 2554129C6C for ; Wed, 29 Nov 2017 21:13:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752862AbdK2VNr (ORCPT ); Wed, 29 Nov 2017 16:13:47 -0500 Received: from mail-qt0-f196.google.com ([209.85.216.196]:40941 "EHLO mail-qt0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752774AbdK2VNq (ORCPT ); Wed, 29 Nov 2017 16:13:46 -0500 Received: by mail-qt0-f196.google.com with SMTP id u42so6199628qte.7 for ; Wed, 29 Nov 2017 13:13:46 -0800 (PST) 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=Ac0Y+Fubz5jw1IfxkSWIYzFjdTZtbTbV2RfYeDgUV/8=; b=QZHWLZ7BBvOS5JoJiIKMdeP7ZkB7ayWs/ebPcttz02XUTGVdRic8wVFHb7eX+5+AsL EYlRTagfL0nqOI/cBvDsG52uTi2H0K4bygJUv1Rnkwn73AZWzWUc9JN6cLp3gkhJMfSY JCetcMd0oJyD+EtQt98xjIT3/4yR7AiyTPrF2TAP9VV71tgu2wmeiKbOc3LMXtrzZYp0 wv865U8UPGm57n5IdYlBRceGvqolQYIQfkko8PsgaJ4h+vNh4AhI49PL/zegWKFBFSJL fKvWv7s5OCHnw+aJeawnlUcoNV43CToGGjoaIhaG5nqtapgLCn2NwzxgYLNyUYtGc8GG V+Fw== 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=Ac0Y+Fubz5jw1IfxkSWIYzFjdTZtbTbV2RfYeDgUV/8=; b=QdPjtA0YatjK0NYVdpPiCjoW5ejpR5U6Pca9EbMzp/7scYkTL0am+R1IDMfcxW1mrm kZeae8D0Y2HV/hwffOtyQRUeSso6AFDXMIiLZRtvidwTHrVZ9xN7ERiwfLVeTZAOUR9s 7QReZ+ghnr7K3OLIhLS/SjFNagvCB1MLS/aErGHTDvDbA32X8Xb4N5qIcdNMNKbbzUrZ VEhh3ynPwqWCaFaCqpfMb+lBDA1D30oqTEYgedbF4z2yJapmqeMSb+SjYKi6GgBe+TvE RTL7NN/1K5PD5Yv+3dB+IFMkbDf84JunHKlyi132mtDZ0MO6CG/Bn2vfJSX3ypLBP+JD 8XjA== X-Gm-Message-State: AKGB3mJqQNgEfviBzeG6dg0+ccwn+dQsrHZZwOTzVojGwzNd6kEzmcoH sf5nRBxrhWB4U4+Vdtscq5z6HA== X-Google-Smtp-Source: AGs4zMbUEdmflxPyjPfafeXZeh7XdWBtgeb6FIqqEYix+YCNSbbiczIJI5jQEWv/6axX9iOEJ3ygZQ== X-Received: by 10.200.36.9 with SMTP id c9mr425974qtc.182.1511990026119; Wed, 29 Nov 2017 13:13:46 -0800 (PST) Received: from localhost (cpe-2606-A000-4381-1201-225-22FF-FEB3-E51A.dyn6.twc.com. [2606:a000:4381:1201:225:22ff:feb3:e51a]) by smtp.gmail.com with ESMTPSA id t28sm1865354qtb.83.2017.11.29.13.13.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 29 Nov 2017 13:13:45 -0800 (PST) From: Josef Bacik To: axboe@kernel.dk, nbd@other.debian.org, linux-block@vger.kernel.org, kernel-team@fb.com Cc: Josef Bacik Subject: [PATCH] nbd: set discard granularity properly Date: Wed, 29 Nov 2017 16:13:44 -0500 Message-Id: <1511990024-2742-1-git-send-email-josef@toxicpanda.com> X-Mailer: git-send-email 2.7.5 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 For some reason we had discard granularity set to 512 always even when discards were disabled. Fix this by having the default be 0, and then if we turn it on set the discard granularity to the blocksize. Signed-off-by: Josef Bacik Reviewed-by: Martin K. Petersen --- drivers/block/nbd.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c index 5f2a4240a204..32b6f66ea5bf 100644 --- a/drivers/block/nbd.c +++ b/drivers/block/nbd.c @@ -231,6 +231,11 @@ static void nbd_size_clear(struct nbd_device *nbd) static void nbd_size_update(struct nbd_device *nbd) { struct nbd_config *config = nbd->config; + + if (config->flags & NBD_FLAG_SEND_TRIM) { + nbd->disk->queue->limits.discard_granularity = config->blksize; + blk_queue_max_discard_sectors(nbd->disk->queue, UINT_MAX); + } blk_queue_logical_block_size(nbd->disk->queue, config->blksize); blk_queue_physical_block_size(nbd->disk->queue, config->blksize); set_capacity(nbd->disk, config->bytesize >> 9); @@ -1040,6 +1045,8 @@ static void nbd_config_put(struct nbd_device *nbd) nbd->config = NULL; nbd->tag_set.timeout = 0; + nbd->disk->queue->limits.discard_granularity = 0; + blk_queue_max_discard_sectors(nbd->disk->queue, 0); queue_flag_clear_unlocked(QUEUE_FLAG_DISCARD, nbd->disk->queue); mutex_unlock(&nbd->config_lock); @@ -1490,8 +1497,8 @@ static int nbd_dev_add(int index) */ queue_flag_set_unlocked(QUEUE_FLAG_NONROT, disk->queue); queue_flag_clear_unlocked(QUEUE_FLAG_ADD_RANDOM, disk->queue); - disk->queue->limits.discard_granularity = 512; - blk_queue_max_discard_sectors(disk->queue, UINT_MAX); + disk->queue->limits.discard_granularity = 0; + blk_queue_max_discard_sectors(disk->queue, 0); blk_queue_max_segment_size(disk->queue, UINT_MAX); blk_queue_max_segments(disk->queue, USHRT_MAX); blk_queue_max_hw_sectors(disk->queue, 65536);