From patchwork Fri Jun 10 02:04:08 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: 9168757 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 48F4C604DB for ; Fri, 10 Jun 2016 02:04:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3ADE8281F9 for ; Fri, 10 Jun 2016 02:04:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2FB1C28364; Fri, 10 Jun 2016 02:04:45 +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=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 C5598281F9 for ; Fri, 10 Jun 2016 02:04:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750772AbcFJCEn (ORCPT ); Thu, 9 Jun 2016 22:04:43 -0400 Received: from aserp1040.oracle.com ([141.146.126.69]:39805 "EHLO aserp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750756AbcFJCEn (ORCPT ); Thu, 9 Jun 2016 22:04:43 -0400 Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by aserp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id u5A24Dms024750 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 10 Jun 2016 02:04:14 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userv0021.oracle.com (8.13.8/8.13.8) with ESMTP id u5A24DWT021327 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 10 Jun 2016 02:04:13 GMT Received: from abhmp0017.oracle.com (abhmp0017.oracle.com [141.146.116.23]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id u5A24BaU032309; Fri, 10 Jun 2016 02:04:11 GMT Received: from ca-mkp.ca.oracle.com (/10.159.214.123) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 09 Jun 2016 19:04:11 -0700 To: Shaohua Li Cc: , , , , , , , Subject: Re: [PATCH V2] block: correctly fallback for zeroout From: "Martin K. Petersen" Organization: Oracle Corporation References: <20160606223357.GA52883@shli-mbp.local> Date: Thu, 09 Jun 2016 22:04:08 -0400 In-Reply-To: <20160606223357.GA52883@shli-mbp.local> (Shaohua Li's message of "Mon, 6 Jun 2016 15:33:58 -0700") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux) MIME-Version: 1.0 X-Source-IP: userv0021.oracle.com [156.151.31.71] 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, special case it there. /** * blkdev_issue_discard - queue a discard * @bdev: blockdev to issue discard for @@ -98,23 +120,12 @@ EXPORT_SYMBOL(__blkdev_issue_discard); int blkdev_issue_discard(struct block_device *bdev, sector_t sector, sector_t nr_sects, gfp_t gfp_mask, unsigned long flags) { - int type = REQ_WRITE | REQ_DISCARD; - struct bio *bio = NULL; - struct blk_plug plug; - int ret; + int ret, io_err; - if (flags & BLKDEV_DISCARD_SECURE) - type |= REQ_SECURE; - - blk_start_plug(&plug); - ret = __blkdev_issue_discard(bdev, sector, nr_sects, gfp_mask, type, - &bio); - if (!ret && bio) { - ret = submit_bio_wait(type, bio); - if (ret == -EOPNOTSUPP) - ret = 0; - } - blk_finish_plug(&plug); + ret = do_blkdev_issue_discard(bdev, sector, nr_sects, gfp_mask, + flags, &io_err); + if (!ret && io_err != -EOPNOTSUPP) + ret = io_err; return ret; } @@ -167,7 +178,7 @@ 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; } EXPORT_SYMBOL(blkdev_issue_write_same); @@ -236,9 +247,11 @@ int blkdev_issue_zeroout(struct block_device *bdev, sector_t sector, sector_t nr_sects, gfp_t gfp_mask, bool discard) { struct request_queue *q = bdev_get_queue(bdev); + int io_err = 0; 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, + &io_err) == 0 && io_err == 0)) return 0; if (bdev_write_same(bdev) && diff --git a/block/blk-lib.c b/block/blk-lib.c index 23d7f30..a3a26c8 100644 --- a/block/blk-lib.c +++ b/block/blk-lib.c @@ -84,6 +84,28 @@ int __blkdev_issue_discard(struct block_device *bdev, sector_t sector, } EXPORT_SYMBOL(__blkdev_issue_discard); +static int do_blkdev_issue_discard(struct block_device *bdev, sector_t sector, + sector_t nr_sects, gfp_t gfp_mask, unsigned long flags, + int *io_err) +{ + int type = REQ_WRITE | REQ_DISCARD; + struct bio *bio = NULL; + struct blk_plug plug; + int ret; + + if (flags & BLKDEV_DISCARD_SECURE) + type |= REQ_SECURE; + + blk_start_plug(&plug); + ret = __blkdev_issue_discard(bdev, sector, nr_sects, gfp_mask, type, + &bio); + if (!ret && bio) + *io_err = submit_bio_wait(type, bio); + blk_finish_plug(&plug); + + return ret; +} + What does the extra io_err buy us? Just have this function return an error. And then in blkdev_issue_discard if you get -EOPNOTSUPP you