From: Shijie Luo <luoshijie1@huawei.com>
To: <linux-block@vger.kernel.org>
Cc: <darrick.wong@oracle.com>, <axboe@kernel.dk>
Subject: [PATCH] loop: change to punch hole if zero range is not supported
Date: Wed, 1 Jul 2020 21:54:01 -0400 [thread overview]
Message-ID: <20200702015401.51199-1-luoshijie1@huawei.com> (raw)
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 <luoshijie1@huawei.com>
---
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:
--
2.19.1
next reply other threads:[~2020-07-02 1:55 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-02 1:54 Shijie Luo [this message]
2020-07-02 16:57 ` [PATCH] loop: change to punch hole if zero range is not supported Darrick J. Wong
2020-07-03 2:04 ` Shijie Luo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200702015401.51199-1-luoshijie1@huawei.com \
--to=luoshijie1@huawei.com \
--cc=axboe@kernel.dk \
--cc=darrick.wong@oracle.com \
--cc=linux-block@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox