From patchwork Fri Jun 3 03:26:22 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Martin K. Petersen" X-Patchwork-Id: 9151589 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 78EFC6074E for ; Fri, 3 Jun 2016 03:28:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6B05227BFA for ; Fri, 3 Jun 2016 03:28:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5FB5A2832B; Fri, 3 Jun 2016 03:28:11 +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, UNPARSEABLE_RELAY autolearn=unavailable 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 09C5A27BFA for ; Fri, 3 Jun 2016 03:28:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751035AbcFCD1y (ORCPT ); Thu, 2 Jun 2016 23:27:54 -0400 Received: from aserp1040.oracle.com ([141.146.126.69]:17436 "EHLO aserp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751238AbcFCD0f (ORCPT ); Thu, 2 Jun 2016 23:26:35 -0400 Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by aserp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id u533QTjb030101 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 3 Jun 2016 03:26:29 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by aserv0022.oracle.com (8.13.8/8.13.8) with ESMTP id u533QSxh017604 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 3 Jun 2016 03:26:29 GMT Received: from abhmp0005.oracle.com (abhmp0005.oracle.com [141.146.116.11]) by userv0121.oracle.com (8.13.8/8.13.8) with ESMTP id u533QRFS020326; Fri, 3 Jun 2016 03:26:27 GMT Received: from ca-mkp.ca.oracle.com (/10.159.214.123) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 02 Jun 2016 20:26:27 -0700 To: Shaohua Li Cc: , , , , , , Subject: Re: [PATCH] block: correctly fallback for zeroout From: "Martin K. Petersen" Organization: Oracle Corporation References: <20160526180813.GA49039@shli-mbp.local> Date: Thu, 02 Jun 2016 23:26:22 -0400 In-Reply-To: <20160526180813.GA49039@shli-mbp.local> (Shaohua Li's message of "Thu, 26 May 2016 11:08:14 -0700") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux) MIME-Version: 1.0 X-Source-IP: aserv0022.oracle.com [141.146.126.234] 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 >>>>> "Shaohua" == Shaohua Li writes: Shaohua> blkdev_issue_zeroout try discard/writesame first, if they fail, Shaohua> zeroout fallback to regular write. The problem is Shaohua> discard/writesame doesn't return error for -EOPNOTSUPP, then Shaohua> zeroout can't do fallback and leave disk data not Shaohua> changed. zeroout should have guaranteed zero-fill behavior. As discussed at LSF/MM, let's explicitly separate the exported/ioctl() functions from the __/do_foo_bar iterators. That's essentially what you have done. And then put all error handling and policy in the ioctl() wrappers instead of the worker functions. ignore_nosupport flag. EXPORT_SYMBOL(blkdev_issue_discard); /** @@ -131,9 +139,9 @@ EXPORT_SYMBOL(blkdev_issue_discard); * Description: * Issue a write same request for the sectors in question. */ -int blkdev_issue_write_same(struct block_device *bdev, sector_t sector, +static int do_blkdev_issue_write_same(struct block_device *bdev, sector_t sector, sector_t nr_sects, gfp_t gfp_mask, - struct page *page) + struct page *page, bool ignore_nosupport) { struct request_queue *q = bdev_get_queue(bdev); unsigned int max_write_same_sectors; @@ -167,7 +175,15 @@ int blkdev_issue_write_same(struct block_device *bdev, sector_t sector, if (bio) ret = submit_bio_wait(REQ_WRITE | REQ_WRITE_SAME, bio); - return ret != -EOPNOTSUPP ? ret : 0; + return (ret != -EOPNOTSUPP || !ignore_nosupport) ? ret : 0; +} + +int blkdev_issue_write_same(struct block_device *bdev, sector_t sector, + sector_t nr_sects, gfp_t gfp_mask, + struct page *page) +{ + return do_blkdev_issue_write_same(bdev, sector, nr_sects, gfp_mask, + page, true); } EXPORT_SYMBOL(blkdev_issue_write_same); There should not be a "soft" fail for WRITE SAME, it's not a hint. @@ -238,12 +254,13 @@ int blkdev_issue_zeroout(struct block_device *bdev, sector_t sector, struct request_queue *q = bdev_get_queue(bdev); if (discard && blk_queue_discard(q) && q->limits.discard_zeroes_data && - blkdev_issue_discard(bdev, sector, nr_sects, gfp_mask, 0) == 0) + do_blkdev_issue_discard(bdev, sector, nr_sects, gfp_mask, 0, + false) == 0) return 0; if (bdev_write_same(bdev) && - blkdev_issue_write_same(bdev, sector, nr_sects, gfp_mask, - ZERO_PAGE(0)) == 0) + do_blkdev_issue_write_same(bdev, sector, nr_sects, gfp_mask, + ZERO_PAGE(0), false) == 0) return 0; return __blkdev_issue_zeroout(bdev, sector, nr_sects, gfp_mask); diff --git a/block/blk-lib.c b/block/blk-lib.c index 23d7f30..232f9ea 100644 --- a/block/blk-lib.c +++ b/block/blk-lib.c @@ -95,8 +95,9 @@ EXPORT_SYMBOL(__blkdev_issue_discard); * Description: * Issue a discard request for the sectors in question. */ -int blkdev_issue_discard(struct block_device *bdev, sector_t sector, - sector_t nr_sects, gfp_t gfp_mask, unsigned long flags) +static int do_blkdev_issue_discard(struct block_device *bdev, sector_t sector, + sector_t nr_sects, gfp_t gfp_mask, unsigned long flags, + bool ignore_nosupport) { int type = REQ_WRITE | REQ_DISCARD; struct bio *bio = NULL; @@ -111,13 +112,20 @@ int blkdev_issue_discard(struct block_device *bdev, sector_t sector, &bio); if (!ret && bio) { ret = submit_bio_wait(type, bio); - if (ret == -EOPNOTSUPP) + if (ignore_nosupport && ret == -EOPNOTSUPP) ret = 0; } blk_finish_plug(&plug); return ret; } + +int blkdev_issue_discard(struct block_device *bdev, sector_t sector, + sector_t nr_sects, gfp_t gfp_mask, unsigned long flags) +{ + return do_blkdev_issue_discard(bdev, sector, nr_sects, gfp_mask, + flags, true); +} I'd prefer to do the EOPNOTSUPP mapping for the ioctl here instead of in the do_blkdev_issue_discard() function. Then you don't need the