[Devel] [PATCH vz9] ploop: fallback to zero range for backing stores without punch hole support

Alexander Atanasov alexander.atanasov at virtuozzo.com
Fri Apr 7 18:58:56 MSK 2023


Using punch hole is on by default but it might not be supported by
the backing store. Gracefully fall back to use zero range in that case.

Ratelimit errors from punch hole/zero range to reduce log clutter.

https://jira.vzint.dev/browse/PSBM-146678
Signed-off-by: Alexander Atanasov <alexander.atanasov at virtuozzo.com>
---
 drivers/md/dm-ploop-map.c | 11 ++++++++---
 drivers/md/dm-ploop.h     |  1 +
 2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/drivers/md/dm-ploop-map.c b/drivers/md/dm-ploop-map.c
index 0882c714af72..640cf8428d9b 100644
--- a/drivers/md/dm-ploop-map.c
+++ b/drivers/md/dm-ploop-map.c
@@ -1050,12 +1050,17 @@ static int ploop_allocate_cluster(struct ploop *ploop, u32 *dst_clu)
 	if (pos < top->file_preallocated_area_start) {
 		/* Clu at @pos may contain dirty data */
 		off = min_t(loff_t, old_size, end);
-		if (!ploop->falloc_new_clu)
+		if (!ploop->falloc_new_clu) {
 			ret = ploop_punch_hole(file, pos, off - pos);
-		else
+			if (unlikely(ret == -EOPNOTSUPP)) {
+				ploop->falloc_new_clu = 1;
+				PL_WARN("punch hole unsupported - disabling");
+			}
+		} else
 			ret = ploop_zero_range(file, pos, off - pos);
 		if (ret) {
-			PL_ERR("punch/zero area: %d", ret);
+			if (printk_ratelimit())
+				PL_ERR("punch/zero area: %d", ret);
 			return ret;
 		}
 	}
diff --git a/drivers/md/dm-ploop.h b/drivers/md/dm-ploop.h
index 2d1db3fc8c57..646b107c4300 100644
--- a/drivers/md/dm-ploop.h
+++ b/drivers/md/dm-ploop.h
@@ -550,6 +550,7 @@ static inline const char *ploop_device_name(struct ploop *ploop)
 
 #define PL_FMT(fmt) "ploop: %s: " fmt "\n"
 #define PL_ERR(fmt, ...) pr_err(PL_FMT(fmt), ploop_device_name(ploop), ##__VA_ARGS__)
+#define PL_WARN(fmt, ...) pr_warn(PL_FMT(fmt), ploop_device_name(ploop), ##__VA_ARGS__)
 #define PL_INFO(fmt, ...) pr_info(PL_FMT(fmt), ploop_device_name(ploop), ##__VA_ARGS__)
 
 extern void ploop_md_page_insert(struct ploop *ploop, struct md_page *md);
-- 
2.39.1



More information about the Devel mailing list