From 8322b16cd13979f7c872d5ce50517688fc7220bd Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Thu, 1 May 2025 10:30:41 +0100 Subject: [PATCH] file: zero: Document implicit order that we will try zeroing methods There's no substantive change here. I just pulled out the test (flags & NBDKIT_FLAG_MAY_TRIM) into a boolean variable, and documented that we (will) try zero-with-trim methods first. (cherry picked from commit 61fc023f235b17f8a19302885d1613dd0a7a3793) (cherry picked from commit c1984ddcc6497c4446d1bf0e8828d1259852eb74) --- plugins/file/file.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/plugins/file/file.c b/plugins/file/file.c index 55941bb8..e5fd864f 100644 --- a/plugins/file/file.c +++ b/plugins/file/file.c @@ -893,9 +893,14 @@ static int file_zero (void *handle, uint32_t count, uint64_t offset, uint32_t flags) { struct handle *h __attribute__ ((unused)) = handle; + const bool may_trim __attribute__ ((unused)) = flags & NBDKIT_FLAG_MAY_TRIM; + /* These alternate zeroing methods are ordered. Methods which can + * trim (if may_trim is set) are tried first. Methods which can + * only zero are tried last. + */ #ifdef FALLOC_FL_PUNCH_HOLE - if (h->can_punch_hole && (flags & NBDKIT_FLAG_MAY_TRIM)) { + if (may_trim && h->can_punch_hole) { int r; r = do_fallocate (h->fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, -- 2.47.1