From patchwork Tue Jun 5 15:41:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 10448527 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 43352600CA for ; Tue, 5 Jun 2018 15:41:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3867829802 for ; Tue, 5 Jun 2018 15:41:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2B3FD298A1; Tue, 5 Jun 2018 15:41:29 +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.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, MAILING_LIST_MULTI, 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 028CC29890 for ; Tue, 5 Jun 2018 15:41:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751879AbeFEPl0 (ORCPT ); Tue, 5 Jun 2018 11:41:26 -0400 Received: from mail-qt0-f193.google.com ([209.85.216.193]:33304 "EHLO mail-qt0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751662AbeFEPl0 (ORCPT ); Tue, 5 Jun 2018 11:41:26 -0400 Received: by mail-qt0-f193.google.com with SMTP id e8-v6so2901049qth.0 for ; Tue, 05 Jun 2018 08:41:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id; bh=nocbqrjcFcfzFbAamkv3w509/MvmCBNwsqt1qPCKdno=; b=dv+tn/hFhd+PlGISWHmCZ+sHqLOYB7vxJGreQYGERkItcuu7chwE7RSQDhMDTbQZGT K8aVo4qe/YTzNj4lmBWs1Nb97ToRxJExHWwaD8IPo/ztK54GO6wgx0DSYNe7S8ZWvTu4 PQ7qgz/SINGPmg/n9TP/aS6Sbci50RAUK8mqxgU9rVNRAoB2WgwcmWTwY+WayHQLafJL loRP6x096+/n1eIELxc+bNVqf/QKWvq4W+wqBZktvytPUlla07y3lPqWQJB4DEVWNeSw fncrjGxUO2nvoebx5YmawLG3iOCh9r09ZXelUqzuVLO7e5aHh3mqn2VZUE+6EXpzpUgY N7bg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id; bh=nocbqrjcFcfzFbAamkv3w509/MvmCBNwsqt1qPCKdno=; b=WkU+ABI7o8OSkrOuBbzNtpQsSKXm+IWmleIO6pOg0ZaEm8FxrYBdaXVGqracSJL3/U z36ZcgEpyaohEMzTQv5FMOBGI1VXqFOwYh8Gkhshn/EstsM9jCsCvumKhXWtyVDN4Va0 O8XCqKwIK6f0FloQwkqRluWEAwpDVwZKEU5Ryt/kr165uhpY+Vi67PPjyBOKMVaNY8VC yHx6/lBwWQ/qMJ5saAVvd7Mixn6xBAKVNZ7ZsiWgMXQL2xBSaJvZFMwXOaZXWwwRcJt/ V9IbrOtEmdnCcZ7c7powoBiN6NdL6GTUCVcO+mHXjpG4+o9HOWbDx82DXlmjUC9TcUBs D3iQ== X-Gm-Message-State: APt69E1N39o0QBfOxwYHPq/p4GOm2+glJ3q1d03hDn2cIlOh7tLQI5Vc wZpQWOGzfmEBKZiJEUDU5I18/XCQ X-Google-Smtp-Source: ADUXVKI3weHmG3NOVb7iLGc3yFPnK6d5m8ITxgSTXfpY5lVmLmR1bRVND7MkkOAuh8NuQMVm3liGsQ== X-Received: by 2002:aed:3ac3:: with SMTP id o61-v6mr26113515qte.335.1528213285570; Tue, 05 Jun 2018 08:41:25 -0700 (PDT) Received: from localhost ([107.15.81.208]) by smtp.gmail.com with ESMTPSA id l66-v6sm11714740qke.69.2018.06.05.08.41.24 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 05 Jun 2018 08:41:24 -0700 (PDT) From: Josef Bacik To: axboe@kernel.dk, nbd@other.debian.org, linux-block@vger.kernel.org, kernel-team@fb.com Subject: [PATCH] nbd: set discard_alignment to the granularity Date: Tue, 5 Jun 2018 11:41:23 -0400 Message-Id: <20180605154123.3226-1-josef@toxicpanda.com> X-Mailer: git-send-email 2.14.3 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 Technically we should be able to get away with 0 as the discard_alignment, but there's no way currently for the protocol to indicate different alignments, and in real life most disks have discard_alignment == discard_granularity. Just set our alignment to our blocksize to make sure discards will actually work properly with 4k drives. Signed-off-by: Josef Bacik --- drivers/block/nbd.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c index bdfbb2a7018c..ec9b43c9f7e3 100644 --- a/drivers/block/nbd.c +++ b/drivers/block/nbd.c @@ -238,6 +238,7 @@ static void nbd_size_update(struct nbd_device *nbd) if (config->flags & NBD_FLAG_SEND_TRIM) { nbd->disk->queue->limits.discard_granularity = config->blksize; + nbd->disk->queue->limits.discard_alignment = config->blksize; blk_queue_max_discard_sectors(nbd->disk->queue, UINT_MAX); } blk_queue_logical_block_size(nbd->disk->queue, config->blksize); @@ -1055,6 +1056,7 @@ static void nbd_config_put(struct nbd_device *nbd) nbd->tag_set.timeout = 0; nbd->disk->queue->limits.discard_granularity = 0; + nbd->disk->queue->limits.discard_alignment = 0; blk_queue_max_discard_sectors(nbd->disk->queue, UINT_MAX); blk_queue_flag_clear(QUEUE_FLAG_DISCARD, nbd->disk->queue); @@ -1509,6 +1511,7 @@ static int nbd_dev_add(int index) blk_queue_flag_set(QUEUE_FLAG_NONROT, disk->queue); blk_queue_flag_clear(QUEUE_FLAG_ADD_RANDOM, disk->queue); disk->queue->limits.discard_granularity = 0; + disk->queue->limits.discard_alignment = 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);