From patchwork Thu Jul 2 01:54:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shijie Luo X-Patchwork-Id: 11637693 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F001B912 for ; Thu, 2 Jul 2020 01:54:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D71AF2083E for ; Thu, 2 Jul 2020 01:54:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726792AbgGBBy7 (ORCPT ); Wed, 1 Jul 2020 21:54:59 -0400 Received: from szxga07-in.huawei.com ([45.249.212.35]:59474 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726735AbgGBBy7 (ORCPT ); Wed, 1 Jul 2020 21:54:59 -0400 Received: from DGGEMS414-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id ACE7739AAA95A4870431; Thu, 2 Jul 2020 09:54:57 +0800 (CST) Received: from huawei.com (10.175.104.175) by DGGEMS414-HUB.china.huawei.com (10.3.19.214) with Microsoft SMTP Server id 14.3.487.0; Thu, 2 Jul 2020 09:54:56 +0800 From: Shijie Luo To: CC: , Subject: [PATCH] loop: change to punch hole if zero range is not supported Date: Wed, 1 Jul 2020 21:54:01 -0400 Message-ID: <20200702015401.51199-1-luoshijie1@huawei.com> X-Mailer: git-send-email 2.19.1 MIME-Version: 1.0 X-Originating-IP: [10.175.104.175] X-CFilter-Loop: Reflected Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org We found a problem when excuting these operations. $ cd /tmp $ qemu-img create -f raw test.img 10G $ mknod -m 0660 /dev/loop0 b 7 0 $ losetup /dev/loop0 test.img $ mkfs /dev/loop0 Here is the error message. [ 142.364823] blk_update_request: operation not supported error, dev loop0, sector 20971392 op 0x9:(WRITE_ZEROES) flags 0x1000800 phys_seg 0 prio class 0 [ 142.371823] blk_update_request: operation not supported error, dev loop0, sector 5144 op 0x9:(WRITE_ZEROES) flags 0x1000800 phys_seg 0 prio class 0 The problem is that not all filesystem support zero range (eg, tmpfs), if filesystem doesn 't support zero range, change to punch hole to fix it. Fixes: efcfec579f613 ("loop: fix no-unmap write-zeroes request behavior") Signed-off-by: Shijie Luo --- drivers/block/loop.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/block/loop.c b/drivers/block/loop.c index c33bbbfd1bd9..504e658adcaf 100644 --- a/drivers/block/loop.c +++ b/drivers/block/loop.c @@ -450,6 +450,13 @@ static int lo_fallocate(struct loop_device *lo, struct request *rq, loff_t pos, } ret = file->f_op->fallocate(file, mode, pos, blk_rq_bytes(rq)); + + if ((ret == -EOPNOTSUPP) && (mode & FALLOC_FL_ZERO_RANGE)) { + mode &= ~FALLOC_FL_ZERO_RANGE; + mode |= FALLOC_FL_PUNCH_HOLE; + ret = file->f_op->fallocate(file, mode, pos, blk_rq_bytes(rq)); + } + if (unlikely(ret && ret != -EINVAL && ret != -EOPNOTSUPP)) ret = -EIO; out: