From patchwork Wed Sep 6 17:38:10 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Dryomov X-Patchwork-Id: 9941141 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 7A7FC602CC for ; Wed, 6 Sep 2017 17:38:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6645722B39 for ; Wed, 6 Sep 2017 17:38:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5AE4928BFF; Wed, 6 Sep 2017 17:38: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.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM 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 CA70A22B39 for ; Wed, 6 Sep 2017 17:38:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752404AbdIFRiw (ORCPT ); Wed, 6 Sep 2017 13:38:52 -0400 Received: from mail-wr0-f196.google.com ([209.85.128.196]:37755 "EHLO mail-wr0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751236AbdIFRiv (ORCPT ); Wed, 6 Sep 2017 13:38:51 -0400 Received: by mail-wr0-f196.google.com with SMTP id y15so3381216wrc.4 for ; Wed, 06 Sep 2017 10:38:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=rh2YZYzCu+4vRnKqpACOVt7obGPqgiy51xidQXtcHjw=; b=G45jpqOlP5vkONAz9mKyD3B75KkR50uu6IOKWhuRDzpYXn29zFhtB04HVxpyqfERLT fhj5qsSxS6hOA6mPTU5suhzxvonhkO9nKcmcJzAwUnPYizgZ5c2ggbeNV83nazHlF2RK RnjZvgqUgGqff8a6uWy16YxQ3Y2DPB/Wcu1i7RcS7IieQ0IfSyYwI1wOTQ/Xu0PiZXwK +xEr8dfNop15CAdqjXTVB847DfdJBjGlb72N0t5H7rSgarN1EhlLA6DSJER/BNY91pA5 Q0jNZgWBidrkqPfE8QsMMXWYTQkYR1sWJ3dkjov6z+QrCVoLXCesUuxiSKoK+nulUy8Q 9Teg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=rh2YZYzCu+4vRnKqpACOVt7obGPqgiy51xidQXtcHjw=; b=QtFgigp5KFJCxbiKYynT4YDC/+cYHgKXkYAMLxwHzvTgvSZ/ArgByYeMoCKmVAaZ3p GkrmSvzITgJnBKLvIRxSg8qIvgQaxSYa44KS+Pq0YZ7lxUcWDBGhwneKeRqlMj5fscdF K6uXcjuH6hc2FCgCstr5z2vULpTN6H2nWgKPYkhyYMU7oIrzvdsSLWEyJSse2r/EdKmj 4MJE+ofO0DpHobCRuNhcmPa+vL/mgkvNrGMbcH2I6BmD0/8JuFWel3nbzrgKChwmqT9z 9ejI0bMsUeph53IWSPBtO2lW3lpSbssir+0dD+p79rXty2AJjTP4vxtFrt1R0W9kFwlD citg== X-Gm-Message-State: AHPjjUjbYmhmSOmLRUj5v7oWFTWGB9SKjiBH3/xZ5wDaSGJsm9sT3UPQ +zO3gtm49KjLPA== X-Google-Smtp-Source: ADKCNb7o5qVDtzoqdCNe+IRYpYVsUxCBJsgzbjzJWIxyuK3qnl0O3S2sx5E94vXa2oTki/Y0tiGm1Q== X-Received: by 10.223.176.46 with SMTP id f43mr2177702wra.206.1504719529857; Wed, 06 Sep 2017 10:38:49 -0700 (PDT) Received: from orange.brq.redhat.com. (nat-pool-brq-t.redhat.com. [213.175.37.10]) by smtp.gmail.com with ESMTPSA id 53sm363793wrt.59.2017.09.06.10.38.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 06 Sep 2017 10:38:49 -0700 (PDT) From: Ilya Dryomov To: Christoph Hellwig Cc: "Martin K. Petersen" , Hannes Reinecke , Jens Axboe , linux-block@vger.kernel.org Subject: [PATCH] block: cope with WRITE SAME failing in blkdev_issue_zeroout() Date: Wed, 6 Sep 2017 19:38:10 +0200 Message-Id: <1504719490-7523-1-git-send-email-idryomov@gmail.com> X-Mailer: git-send-email 2.4.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 sd_config_write_same() ignores ->max_ws_blocks == 0 and resets it to permit trying WRITE SAME on older SCSI devices, unless ->no_write_same is set. This means blkdev_issue_zeroout() must cope with WRITE SAME failing with BLK_STS_TARGET/-EREMOTEIO and explicitly write zeroes, unless BLKDEV_ZERO_NOFALLBACK is specified. Commit 71027e97d796 ("block: stop using discards for zeroing") added the following to __blkdev_issue_zeroout() comment: "Note that this function may fail with -EOPNOTSUPP if the driver signals zeroing offload support, but the device fails to process the command (for some devices there is no non-destructive way to verify whether this operation is actually supported). In this case the caller should call retry the call to blkdev_issue_zeroout() and the fallback path will be used." But __blkdev_issue_zeroout() doesn't fail in this case: if WRITE SAME support is indicated, a REQ_OP_WRITE_ZEROES bio is built and returned to blkdev_issue_zeroout(). -EREMOTEIO is then propagated up: $ fallocate -zn -l 1k /dev/sdg fallocate: fallocate failed: Remote I/O error $ fallocate -zn -l 1k /dev/sdg # OK (The second fallocate(1) succeeds because sd_done() sets ->no_write_same in response to a sense that would become BLK_STS_TARGET.) Retry __blkdev_issue_zeroout() if the I/O fails with -EREMOTEIO. This is roughly what we did until 4.12, sans BLKDEV_ZERO_NOFALLBACK knob. Fixes: c20cfc27a473 ("block: stop using blkdev_issue_write_same for zeroing") Cc: Christoph Hellwig Cc: "Martin K. Petersen" Cc: Hannes Reinecke Cc: stable@vger.kernel.org # 4.12+ Signed-off-by: Ilya Dryomov --- block/blk-lib.c | 49 +++++++++++++++++++++++++++++++++---------------- 1 file changed, 33 insertions(+), 16 deletions(-) diff --git a/block/blk-lib.c b/block/blk-lib.c index 3fe0aec90597..876b5478c1a2 100644 --- a/block/blk-lib.c +++ b/block/blk-lib.c @@ -287,12 +287,6 @@ static unsigned int __blkdev_sectors_to_bio_pages(sector_t nr_sects) * Zero-fill a block range, either using hardware offload or by explicitly * writing zeroes to the device. * - * Note that this function may fail with -EOPNOTSUPP if the driver signals - * zeroing offload support, but the device fails to process the command (for - * some devices there is no non-destructive way to verify whether this - * operation is actually supported). In this case the caller should call - * retry the call to blkdev_issue_zeroout() and the fallback path will be used. - * * If a device is using logical block provisioning, the underlying space will * not be released if %flags contains BLKDEV_ZERO_NOUNMAP. * @@ -343,6 +337,34 @@ int __blkdev_issue_zeroout(struct block_device *bdev, sector_t sector, } EXPORT_SYMBOL(__blkdev_issue_zeroout); +/* + * This function may fail with -EREMOTEIO if the driver signals zeroing + * offload support, but the device fails to process the command (for + * some devices there is no non-destructive way to verify whether this + * operation is actually supported). In this case the caller should + * retry and the fallback path in __blkdev_issue_zeroout() will be used + * unless %flags contains BLKDEV_ZERO_NOFALLBACK. + */ +static int __blkdev_issue_zeroout_wait(struct block_device *bdev, + sector_t sector, sector_t nr_sects, + gfp_t gfp_mask, unsigned flags) +{ + int ret; + struct bio *bio = NULL; + struct blk_plug plug; + + blk_start_plug(&plug); + ret = __blkdev_issue_zeroout(bdev, sector, nr_sects, gfp_mask, + &bio, flags); + if (ret == 0 && bio) { + ret = submit_bio_wait(bio); + bio_put(bio); + } + blk_finish_plug(&plug); + + return ret; +} + /** * blkdev_issue_zeroout - zero-fill a block range * @bdev: blockdev to write @@ -360,17 +382,12 @@ int blkdev_issue_zeroout(struct block_device *bdev, sector_t sector, sector_t nr_sects, gfp_t gfp_mask, unsigned flags) { int ret; - struct bio *bio = NULL; - struct blk_plug plug; - blk_start_plug(&plug); - ret = __blkdev_issue_zeroout(bdev, sector, nr_sects, gfp_mask, - &bio, flags); - if (ret == 0 && bio) { - ret = submit_bio_wait(bio); - bio_put(bio); - } - blk_finish_plug(&plug); + ret = __blkdev_issue_zeroout_wait(bdev, sector, nr_sects, + gfp_mask, flags); + if (ret == -EREMOTEIO) + ret = __blkdev_issue_zeroout_wait(bdev, sector, nr_sects, + gfp_mask, flags); return ret; }