From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Cyril Hrubis <chrubis@suse.cz>, Jan Kara <jack@suse.cz>,
Christoph Hellwig <hch@lst.de>, Jens Axboe <axboe@kernel.dk>,
Sasha Levin <sashal@kernel.org>,
linux-block@vger.kernel.org
Subject: [PATCH AUTOSEL 6.9 21/21] loop: Disable fallocate() zero and discard if not supported
Date: Sun, 23 Jun 2024 09:43:54 -0400 [thread overview]
Message-ID: <20240623134405.809025-21-sashal@kernel.org> (raw)
In-Reply-To: <20240623134405.809025-1-sashal@kernel.org>
From: Cyril Hrubis <chrubis@suse.cz>
[ Upstream commit 5f75e081ab5cbfbe7aca2112a802e69576ee9778 ]
If fallcate is implemented but zero and discard operations are not
supported by the filesystem the backing file is on we continue to fill
dmesg with errors from the blk_mq_end_request() since each time we call
fallocate() on the loop device the EOPNOTSUPP error from lo_fallocate()
ends up propagated into the block layer. In the end syscall succeeds
since the blkdev_issue_zeroout() falls back to writing zeroes which
makes the errors even more misleading and confusing.
How to reproduce:
1. make sure /tmp is mounted as tmpfs
2. dd if=/dev/zero of=/tmp/disk.img bs=1M count=100
3. losetup /dev/loop0 /tmp/disk.img
4. mkfs.ext2 /dev/loop0
5. dmesg |tail
[710690.898214] operation not supported error, dev loop0, sector 204672 op 0x9:(WRITE_ZEROES) flags 0x8000800 phys_seg 0 prio class 0
[710690.898279] operation not supported error, dev loop0, sector 522 op 0x9:(WRITE_ZEROES) flags 0x8000800 phys_seg 0 prio class 0
[710690.898603] operation not supported error, dev loop0, sector 16906 op 0x9:(WRITE_ZEROES) flags 0x8000800 phys_seg 0 prio class 0
[710690.898917] operation not supported error, dev loop0, sector 32774 op 0x9:(WRITE_ZEROES) flags 0x8000800 phys_seg 0 prio class 0
[710690.899218] operation not supported error, dev loop0, sector 49674 op 0x9:(WRITE_ZEROES) flags 0x8000800 phys_seg 0 prio class 0
[710690.899484] operation not supported error, dev loop0, sector 65542 op 0x9:(WRITE_ZEROES) flags 0x8000800 phys_seg 0 prio class 0
[710690.899743] operation not supported error, dev loop0, sector 82442 op 0x9:(WRITE_ZEROES) flags 0x8000800 phys_seg 0 prio class 0
[710690.900015] operation not supported error, dev loop0, sector 98310 op 0x9:(WRITE_ZEROES) flags 0x8000800 phys_seg 0 prio class 0
[710690.900276] operation not supported error, dev loop0, sector 115210 op 0x9:(WRITE_ZEROES) flags 0x8000800 phys_seg 0 prio class 0
[710690.900546] operation not supported error, dev loop0, sector 131078 op 0x9:(WRITE_ZEROES) flags 0x8000800 phys_seg 0 prio class 0
This patch changes the lo_fallocate() to clear the flags for zero and
discard operations if we get EOPNOTSUPP from the backing file fallocate
callback, that way we at least stop spewing errors after the first
unsuccessful try.
CC: Jan Kara <jack@suse.cz>
Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Jan Kara <jack@suse.cz>
Link: https://lore.kernel.org/r/20240613163817.22640-1-chrubis@suse.cz
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
drivers/block/loop.c | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+)
diff --git a/drivers/block/loop.c b/drivers/block/loop.c
index 28a95fd366fea..95a468eaa7013 100644
--- a/drivers/block/loop.c
+++ b/drivers/block/loop.c
@@ -302,6 +302,21 @@ static int lo_read_simple(struct loop_device *lo, struct request *rq,
return 0;
}
+static void loop_clear_limits(struct loop_device *lo, int mode)
+{
+ struct queue_limits lim = queue_limits_start_update(lo->lo_queue);
+
+ if (mode & FALLOC_FL_ZERO_RANGE)
+ lim.max_write_zeroes_sectors = 0;
+
+ if (mode & FALLOC_FL_PUNCH_HOLE) {
+ lim.max_hw_discard_sectors = 0;
+ lim.discard_granularity = 0;
+ }
+
+ queue_limits_commit_update(lo->lo_queue, &lim);
+}
+
static int lo_fallocate(struct loop_device *lo, struct request *rq, loff_t pos,
int mode)
{
@@ -320,6 +335,14 @@ 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 (unlikely(ret && ret != -EINVAL && ret != -EOPNOTSUPP))
return -EIO;
+
+ /*
+ * We initially configure the limits in a hope that fallocate is
+ * supported and clear them here if that turns out not to be true.
+ */
+ if (unlikely(ret == -EOPNOTSUPP))
+ loop_clear_limits(lo, mode);
+
return ret;
}
--
2.43.0
prev parent reply other threads:[~2024-06-23 13:44 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-23 13:43 [PATCH AUTOSEL 6.9 01/21] NFSv4: Fix memory leak in nfs4_set_security_label Sasha Levin
2024-06-23 13:43 ` [PATCH AUTOSEL 6.9 02/21] nfs: propagate readlink errors in nfs_symlink_filler Sasha Levin
2024-06-23 13:43 ` [PATCH AUTOSEL 6.9 03/21] nfs: Avoid flushing many pages with NFS_FILE_SYNC Sasha Levin
2024-06-23 13:43 ` [PATCH AUTOSEL 6.9 04/21] nfs: don't invalidate dentries on transient errors Sasha Levin
2024-06-23 13:43 ` [PATCH AUTOSEL 6.9 05/21] cachefiles: add consistency check for copen/cread Sasha Levin
2024-06-23 13:43 ` [PATCH AUTOSEL 6.9 06/21] cachefiles: Set object to close if ondemand_id < 0 in copen Sasha Levin
2024-06-23 13:43 ` [PATCH AUTOSEL 6.9 07/21] cachefiles: make on-demand read killable Sasha Levin
2024-06-23 13:43 ` [PATCH AUTOSEL 6.9 08/21] fs/file: fix the check in find_next_fd() Sasha Levin
2024-06-23 13:43 ` [PATCH AUTOSEL 6.9 09/21] vfio: Create vfio_fs_type with inode per device Sasha Levin
2024-06-23 13:43 ` [PATCH AUTOSEL 6.9 10/21] vfio/pci: Use unmap_mapping_range() Sasha Levin
2024-06-23 13:43 ` [PATCH AUTOSEL 6.9 11/21] mei: demote client disconnect warning on suspend to debug Sasha Levin
2024-06-23 13:43 ` [PATCH AUTOSEL 6.9 12/21] parport: amiga: Mark driver struct with __refdata to prevent section mismatch Sasha Levin
2024-06-23 13:43 ` [PATCH AUTOSEL 6.9 13/21] iomap: Fix iomap_adjust_read_range for plen calculation Sasha Levin
2024-06-23 13:43 ` [PATCH AUTOSEL 6.9 14/21] drm/exynos: dp: drop driver owner initialization Sasha Levin
2024-06-23 13:43 ` [PATCH AUTOSEL 6.9 15/21] drm: panel-orientation-quirks: Add quirk for Aya Neo KUN Sasha Levin
2024-06-23 13:43 ` [PATCH AUTOSEL 6.9 16/21] drm: renesas: shmobile: Call drm_atomic_helper_shutdown() at shutdown time Sasha Levin
2024-06-23 13:43 ` [PATCH AUTOSEL 6.9 17/21] drm/mediatek: " Sasha Levin
2024-06-23 13:43 ` Sasha Levin
2024-06-23 13:43 ` [PATCH AUTOSEL 6.9 18/21] nvme: avoid double free special payload Sasha Levin
2024-06-23 13:43 ` [PATCH AUTOSEL 6.9 19/21] nvmet: always initialize cqe.result Sasha Levin
2024-06-23 13:43 ` [PATCH AUTOSEL 6.9 20/21] vfio/pci: Insert full vma on mmap'd MMIO fault Sasha Levin
2024-06-23 13:43 ` Sasha Levin [this message]
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=20240623134405.809025-21-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=axboe@kernel.dk \
--cc=chrubis@suse.cz \
--cc=hch@lst.de \
--cc=jack@suse.cz \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=stable@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.