From patchwork Wed Oct 26 20:26:15 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mikulas Patocka X-Patchwork-Id: 9398235 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 5F41660231 for ; Wed, 26 Oct 2016 20:26:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4550D29DE3 for ; Wed, 26 Oct 2016 20:26:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3857829DE5; Wed, 26 Oct 2016 20:26:18 +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,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 CA7FC29DE3 for ; Wed, 26 Oct 2016 20:26:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933361AbcJZU0R (ORCPT ); Wed, 26 Oct 2016 16:26:17 -0400 Received: from mx1.redhat.com ([209.132.183.28]:48070 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932320AbcJZU0Q (ORCPT ); Wed, 26 Oct 2016 16:26:16 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2E9E34DB15; Wed, 26 Oct 2016 20:26:16 +0000 (UTC) Received: from file01.intranet.prod.int.rdu2.redhat.com (file01.intranet.prod.int.rdu2.redhat.com [10.11.5.7]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u9QKQFAZ002619 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Wed, 26 Oct 2016 16:26:15 -0400 Received: from file01.intranet.prod.int.rdu2.redhat.com (localhost [127.0.0.1]) by file01.intranet.prod.int.rdu2.redhat.com (8.14.4/8.14.4) with ESMTP id u9QKQFFu012528; Wed, 26 Oct 2016 16:26:15 -0400 Received: from localhost (mpatocka@localhost) by file01.intranet.prod.int.rdu2.redhat.com (8.14.4/8.14.4/Submit) with ESMTP id u9QKQFCm012525; Wed, 26 Oct 2016 16:26:15 -0400 X-Authentication-Warning: file01.intranet.prod.int.rdu2.redhat.com: mpatocka owned process doing -bs Date: Wed, 26 Oct 2016 16:26:15 -0400 (EDT) From: Mikulas Patocka X-X-Sender: mpatocka@file01.intranet.prod.int.rdu2.redhat.com To: Jens Axboe cc: Mike Snitzer , Christoph Hellwig , dm-devel@redhat.com, "Alasdair G. Kergon" , linux-block@vger.kernel.org Subject: [PATCH 1/4] brd: handle misaligned discard In-Reply-To: Message-ID: References: <20161021200022.GA12580@redhat.com> <20161024155756.GA48306@redhat.com> <20161025130712.GA12717@infradead.org> <20161025143719.GA51266@redhat.com> <710b07a3-9091-6935-37c4-ea1dcedcab4f@kernel.dk> User-Agent: Alpine 2.02 (LRH 1266 2009-07-14) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Wed, 26 Oct 2016 20:26:16 +0000 (UTC) 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 The brd driver refuses misaligned discard requests with an error. However, this is suboptimal, misaligned requests could be handled by discarding a part of the request that is aligned on a page boundary. This patch changes the code so that it handles misaligned requests. Signed-off-by: Mikulas Patocka --- drivers/block/brd.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe linux-block" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Index: linux-2.6/drivers/block/brd.c =================================================================== --- linux-2.6.orig/drivers/block/brd.c +++ linux-2.6/drivers/block/brd.c @@ -213,9 +213,14 @@ static int copy_to_brd_setup(struct brd_ } static void discard_from_brd(struct brd_device *brd, - sector_t sector, size_t n) + sector_t sector, unsigned n_sectors) { - while (n >= PAGE_SIZE) { + unsigned boundary = -sector & ((PAGE_SIZE >> SECTOR_SHIFT) - 1); + if (unlikely(boundary >= n_sectors)) + return; + sector += boundary; + n_sectors -= boundary; + while (n_sectors >= PAGE_SIZE >> SECTOR_SHIFT) { /* * Don't want to actually discard pages here because * re-allocating the pages can result in writeback @@ -226,7 +231,7 @@ static void discard_from_brd(struct brd_ else brd_zero_page(brd, sector); sector += PAGE_SIZE >> SECTOR_SHIFT; - n -= PAGE_SIZE; + n_sectors -= PAGE_SIZE >> SECTOR_SHIFT; } } @@ -339,10 +344,7 @@ static blk_qc_t brd_make_request(struct goto io_error; if (unlikely(bio_op(bio) == REQ_OP_DISCARD)) { - if (sector & ((PAGE_SIZE >> SECTOR_SHIFT) - 1) || - bio->bi_iter.bi_size & ~PAGE_MASK) - goto io_error; - discard_from_brd(brd, sector, bio->bi_iter.bi_size); + discard_from_brd(brd, sector, bio->bi_iter.bi_size >> SECTOR_SHIFT); goto out; }