From patchwork Mon Jun 6 22:33:58 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shaohua Li X-Patchwork-Id: 9159289 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 88DA960573 for ; Mon, 6 Jun 2016 22:34:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7801928210 for ; Mon, 6 Jun 2016 22:34:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6C36D2833E; Mon, 6 Jun 2016 22:34:53 +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.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID 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 2E53628210 for ; Mon, 6 Jun 2016 22:34:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751060AbcFFWev (ORCPT ); Mon, 6 Jun 2016 18:34:51 -0400 Received: from mx0b-00082601.pphosted.com ([67.231.153.30]:40277 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750886AbcFFWet (ORCPT ); Mon, 6 Jun 2016 18:34:49 -0400 Received: from pps.filterd (m0089730.ppops.net [127.0.0.1]) by m0089730.ppops.net (8.16.0.11/8.16.0.11) with SMTP id u56MUMdg027102; Mon, 6 Jun 2016 15:34:18 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=fb.com; h=date : from : to : cc : subject : message-id : mime-version : content-type; s=facebook; bh=h5e+ch10K/s4hv82JzFrEStf97+LCFfQFPtbOZBv12g=; b=a3HoGI+427v1Ey7xQAP8EFH4WrTJWgRZqntog8T0I9JCJv3abYDMtsqTzrzgvC+6TIfp 1QjvyTK7m+HnMptkOAhYkpcsIhf3wM2ksNtg2RmMyITY4cDcgf4NH7xhHk/51pwUMUss KdKkIrc6ybKCp6Buuv4eCjspR+nG4XsNb/E= Received: from maileast.thefacebook.com ([199.201.65.23]) by m0089730.ppops.net with ESMTP id 23btfm1hx1-2 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Mon, 06 Jun 2016 15:34:18 -0700 Received: from na01-bn1-obe.outbound.protection.outlook.com (192.168.183.28) by o365-in.thefacebook.com (192.168.177.21) with Microsoft SMTP Server (TLS) id 14.3.294.0; Mon, 6 Jun 2016 18:34:15 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.onmicrosoft.com; s=selector1-fb-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=pHgWooRQ06MdrrWoCM2WPz1floV/Utl0Hpw5jBLtWz0=; b=T2nEAsH9ElO69sZrWjZzrQuSI23QlNfq7sNg7mRHmyWyluGN8KdIEwI2TRZdYUDx+4Unmv8ailXdHDZDv+RhjBe8DEyN+g5dfLJrj4nUT/KTzCJjf4lA0tmcYYArnTaMnPtL+bxNj/Xr3D/kDREfirnZ9td0TDGVKP4SSVj/Jo0= Received: from shli-mbp.local (2620:10d:c090:200::5:cc1) by CO2PR15MB0057.namprd15.prod.outlook.com (10.161.86.148) with Microsoft SMTP Server (TLS) id 15.1.511.8; Mon, 6 Jun 2016 22:34:12 +0000 Date: Mon, 6 Jun 2016 15:33:58 -0700 From: Shaohua Li To: , CC: , , , , , Subject: [PATCH V2] block: correctly fallback for zeroout Message-ID: <20160606223357.GA52883@shli-mbp.local> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.6.1 (2016-04-27) X-Originating-IP: [2620:10d:c090:200::5:cc1] X-ClientProxiedBy: SN1PR17CA0058.namprd17.prod.outlook.com (10.163.3.154) To CO2PR15MB0057.namprd15.prod.outlook.com (10.161.86.148) X-MS-Office365-Filtering-Correlation-Id: 56f6d60f-6afb-464d-1206-08d38e5aafc0 X-Microsoft-Exchange-Diagnostics: 1; CO2PR15MB0057; 2:lo9yzEmIeuAGQeDPqwvu/cL5qtg8wzfHxwkesiqyC3xvh/yGikdvLtwGv6l6OegoNEX7FaGcxa3kHQcrOoGa2Mvn3mXPVTg6+/PtqlMC5gSqLvNJy4AowLrl1FdjQ8iWKPb8cnGWa5nMo7WT7fomcJml3JnmqG8ELBM6oi7wG1d4KaeVQohelC0OjAJEdlW4; 3:RMocVClKhIOU08KyKLwBVi3wzv7R8eJ4uDNi3sNuR1k10ZtL+uMrqcuBh9CG9Zjr+2wLqPcWjXwXOOdDqqVJVVVT3qlKdgjS3Gwr3Hz22sI0LGkbQZKNVm+/Fe1EVrTd; 25:dzKZsa1YNEf/AagE+ujLiGFJjrjOunxdcU8s37KAPHs/WqYESAnlwnyKGYi+RktXQ1yCceAyGUJpLyAvfS9dXtvge0jxgde3IexB9CYTADgyDkEdEYMMO+NTnkVTQ8HyYq2x2cQPMygJl8JixofJZEayBKSCR5TNAfojJHkf69uzNsWlN4NOwRarkn3ICamwvpkPq6VBMeNitG6PViy9VtvAfeFUYtLVbxgz8jqdl1KBY9RT/fzlseDrW5+15u1vJa4n/AnyMo06OYutFevssDb1WX1XJn5W2cayr4ZfPt7MxqGF479Q747dWYHXtrMZxancUn86KPBxS3MgwOs4d8UtpGojIbKRSVhJ7cTQO4DepChRLY1CcvN7o9Eiz2NgDXRL1T7CmVr7POQhOBKEdWQ864aemhMyOgk+8j4p6lk=; 20:d/ccNHIDiYrzjJgwg1OCo1RUWeFd2KoyUCWNOq5a14HWcHQ6/8NxKdjq3oUnwTUXI5TpLT8CziX6lFW/LCt1Up9prC5yeyA4k1i73Qyg6lBQQ9SlLKl5XiEFligUsxzaYXPb5ziGLoY5jXiIMA4RLXkJyd82HALKaNeDmMm/m+0= X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:CO2PR15MB0057; X-LD-Processed: 8ae927fe-1255-47a7-a2af-5f3a069daaa2,ExtAddr X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(67672495146484)(146099531331640)(201166117486090); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(8121501046)(5005006)(3002001)(10201501046); SRVR:CO2PR15MB0057; BCL:0; PCL:0; RULEID:; SRVR:CO2PR15MB0057; X-Microsoft-Exchange-Diagnostics: 1; CO2PR15MB0057; 4:JSKCTkg0ARPRWJhEia0UOWKLc02cOuvjSjH5cYfPMCLCCLNLeeJe5uQRH1gmWVFBRa7mUkheUPLAV3eBByCb/5D9nUSlvHWBJ+8N2g+F7pP0MjgShzern0vEiwgU0RTPffnHwvpB0PWunLW4ivBZM1hX4gxFIgRa7mLXXEbXAjEQutqGSfj85UhTvfZbJ3JxY/c7t1MZL+Xa09H2l4iH3+F6AeKEZOW+rwEFxRX1Gfu7CyLzyIrtUPnumL9hf95FiugHm+61ReIfq4hd3AdytipTaHqARXlQROusSqZdDSmJA8vZiP5CYxz40+kdJw9qoVXqbCcqKMkJj6/mdPg5kK8xCYXFLcZwqlF7dhq2CRf6Sov6ED12ngIgdy2X6asjMcYsGymuhS2L+B5mRh/0YlTnqEV11OXZDU9+2S1zCmr1MO1TJdiz+nB/c1v4+0djACerJpYpfdt4xiGXlG4kauafyGmxSeCRKm4eJmc6uYU= X-Forefront-PRVS: 096507C068 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(4630300001)(6009001)(199003)(189002)(46406003)(83506001)(86362001)(81166006)(81156014)(5008740100001)(189998001)(106356001)(97736004)(4001350100001)(5001770100001)(105586002)(229853001)(8676002)(42186005)(50466002)(47776003)(50986999)(9686002)(54356999)(101416001)(77096005)(15975445007)(33656002)(5004730100002)(2906002)(4326007)(68736007)(1076002)(586003)(23726003)(6116002)(19580395003)(98436002)(19580405001)(92566002)(97756001)(3826002); DIR:OUT; SFP:1102; SCL:1; SRVR:CO2PR15MB0057; H:shli-mbp.local; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; Received-SPF: None (protection.outlook.com: fb.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; CO2PR15MB0057; 23:I30qGK7FKiIDZ83AZApcX3tHvrj2pNRxUwSoT/rwy?= =?us-ascii?Q?kwT/tSG5wQpwuoA81gOWaabBCX27yaKKqy4YRqW3k1FI0fn8XcAkU+6O/4ry?= =?us-ascii?Q?y000WzADtH67QFPGWG9ulyLskCiBvV7EAjdd9tzD+jx9l4glGjSgzilyJtHZ?= =?us-ascii?Q?wFW7sAzug2x3CTw+Rqhfs14rWA1lp9PwxQv4yzKooaNhHRewItEeleCcnHIm?= =?us-ascii?Q?Vd+8kPpu/ofvRzIiskCh8StxNMU3J+8xAksXkGrHXw25jhDEhTYz4BSgVVfx?= =?us-ascii?Q?IvHA4F/F9cpTqxa4MRnNjpAzkmk4JBoOLx5F/iJ9Vs706SAvwOa/cUDLE20y?= =?us-ascii?Q?Z8CIQR59fE2gBg8kw9VifApIlfBJeyq4JWAAL8PwEM4ocNSqPXmzkhu5mOSG?= =?us-ascii?Q?jPmySlE3WUNooHoAzz/j/QBOHmmMxL+4OYWiT8j/aaPjmuuXw5vK7OcW8Lks?= =?us-ascii?Q?+1XLedrCabjiWl9sjfUqrAlPrXv5EHB+lJBlQw1QmtG40w746FpWjD9sS0ob?= =?us-ascii?Q?2dqv0Ie2xYTL/DZMmOnws/wEaounalr4eNCtJRIOP18X+h5CTRKlOpxRLdny?= =?us-ascii?Q?ClXW4XF4xJMBmFQVKHWX1CJK7BDHnw8Z4VeiOkQkV6PS4vYI3opV7QBzSxdK?= =?us-ascii?Q?thaMAZ8vK4qKb2fSIiSd1hbG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TJA==; 20:CFmQpDm6HkOFuzrshRO+1prixX8+y9rqZPjAQFyBeQJTsRF5mzwtxWIEfS5ip3xwYjvGEGYIj9C8BDZpqeb7i+qYlaeEuME6E8ppR+bh7qXFv47jKj8t/FZ6R0NWF6Z9JU+cx4Mjpw14T3JqOXjCpi0RtjQWFomaup/nf92bSeo= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Jun 2016 22:34:12.3204 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO2PR15MB0057 X-OriginatorOrg: fb.com X-Proofpoint-Spam-Reason: safe X-FB-Internal: Safe X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2016-06-06_09:, , signatures=0 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 blkdev_issue_zeroout try discard/writesame first, if they fail, zeroout fallback to regular write. The problem is discard/writesame doesn't return error for -EOPNOTSUPP, then zeroout can't do fallback and leave disk data not changed. zeroout should have guaranteed zero-fill behavior. https://bugzilla.kernel.org/show_bug.cgi?id=118581 V2: move the return value policy to blkdev_issue_discard and delete the policy for blkdev_issue_write_same (Martin) Cc: Sitsofe Wheeler Cc: Mike Snitzer Cc: Jens Axboe Cc: Martin K. Petersen Signed-off-by: Shaohua Li --- block/blk-lib.c | 49 +++++++++++++++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 18 deletions(-) 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; +} + /** * 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) &&