Skip to contentSkip to conversation

punch-alternating: prevent punching all extents

PATCH In review [email protected] 2 participants 5 messages Dec 21, 2025 – Jan 5

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 punch-alternating: prevent punching all extents

From: Carlos Maiolino <[email protected]>

If by any chance the punch size is >= the interval, we end up punching everything, zeroing out the file.

As this is not a tool to dealloc the whole file, so force the user to pass a configuration that won't cause it to happen.

---
 src/punch-alternating.c | 5 +++++
 1 file changed, 5 insertions(+)
src/punch-alternating.c +5 -0
index d2bb4b6a2276..c555b48d8591 100644
@@ -88,6 +88,11 @@ int main(int argc, char *argv[])
 		usage(argv[0]);
 	}
 
+	if (size >= interval) {
+		printf("Interval must be > size\n");
+		usage(argv[0]);
+	}
+
 	if (optind != argc - 1)
 		usage(argv[0]);
 
Signature · 1 line
2.52.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 19 lines · On Sun, Dec 21, 2025 at 11:24:50AM +0100, [email protected] wrote:

From: Carlos Maiolino <[email protected]>

If by any chance the punch size is >= the interval, we end up punching everything, zeroing out the file.

As this is not a tool to dealloc the whole file, so force the user to pass a configuration that won't cause it to happen.

---
 src/punch-alternating.c | 5 +++++
 1 file changed, 5 insertions(+)
src/punch-alternating.c +0 -0
index d2bb4b6a2276..c555b48d8591 100644

src/punch-alternating.c int main(int argc, char *argv[]) · line 94

Quoted 7 lines
src/punch-alternating.c +4 -0
@@ -88,6 +88,11 @@ int main(int argc, char *argv[])
 		usage(argv[0]);
 	}
 
+	if (size >= interval) {
+		printf("Interval must be > size\n");
+		usage(argv[0]);
+	}

OK, I don't mind adding this checking. May I ask which test case hit this "size >= interval" issue when you ran your test?

Quoted 7 lines
src/punch-alternating.c +1 -0
+
 	if (optind != argc - 1)
 		usage(argv[0]);
 
Signature · 1 line
2.52.0
#2 lore raw
Quoted 23 lines · Zorro Lang
Quoted 22 lines · On Sun, Dec 21, 2025 at 11:24:50AM +0100, [email protected] wrote:

From: Carlos Maiolino <[email protected]>

If by any chance the punch size is >= the interval, we end up punching everything, zeroing out the file.

As this is not a tool to dealloc the whole file, so force the user to pass a configuration that won't cause it to happen.

---
 src/punch-alternating.c | 5 +++++
 1 file changed, 5 insertions(+)
src/punch-alternating.c +0 -0
index d2bb4b6a2276..c555b48d8591 100644
@@ -88,6 +88,11 @@ int main(int argc, char *argv[])
 		usage(argv[0]);
 	}
 
Quoted 7 lines

src/punch-alternating.c int main(int argc, char *argv[]) · line 94

Quoted 4 lines
src/punch-alternating.c +4 -0
+	if (size >= interval) {
+		printf("Interval must be > size\n");
+		usage(argv[0]);
+	}

OK, I don't mind adding this checking. May I ask which test case hit this "size >= interval" issue when you ran your test?

None. I was just using the program to test some other stuff without any specific test.

Quoted 11 lines
Quoted 7 lines
src/punch-alternating.c +1 -0
+
 	if (optind != argc - 1)
 		usage(argv[0]);
 
Signature · 1 line
2.52.0
#3 lore raw
Quoted 32 lines · Carlos Maiolino
Quoted 23 lines · Zorro Lang
Quoted 22 lines · On Sun, Dec 21, 2025 at 11:24:50AM +0100, [email protected] wrote:

From: Carlos Maiolino <[email protected]>

If by any chance the punch size is >= the interval, we end up punching everything, zeroing out the file.

As this is not a tool to dealloc the whole file, so force the user to pass a configuration that won't cause it to happen.

---
 src/punch-alternating.c | 5 +++++
 1 file changed, 5 insertions(+)
src/punch-alternating.c +0 -0
index d2bb4b6a2276..c555b48d8591 100644
@@ -88,6 +88,11 @@ int main(int argc, char *argv[])
 		usage(argv[0]);
 	}
 
Quoted 7 lines

src/punch-alternating.c int main(int argc, char *argv[]) · line 94

Quoted 4 lines
src/punch-alternating.c +4 -0
+	if (size >= interval) {
+		printf("Interval must be > size\n");
+		usage(argv[0]);
+	}

OK, I don't mind adding this checking. May I ask which test case hit this "size >= interval" issue when you ran your test?

Quoted 2 lines

None. I was just using the program to test some other stuff without any specific test.

Sure, good to know there's not other issues :) This program is a good tool to do some other tests, especially creates lots of data extents effectively :) I've pushed this patch to patches-in-queue branch, will merge it in next release after testing, feel free to check it.

Thanks,
Zorro

Quoted 13 lines
Quoted 12 lines
Quoted 7 lines
src/punch-alternating.c +1 -0
+
 	if (optind != argc - 1)
 		usage(argv[0]);
 
Signature · 1 line
2.52.0
#4 lore raw
Quoted 33 lines · Zorro Lang
Quoted 32 lines · Carlos Maiolino
Quoted 30 lines · Zorro Lang
Quoted 19 lines · On Sun, Dec 21, 2025 at 11:24:50AM +0100, [email protected] wrote:

From: Carlos Maiolino <[email protected]>

If by any chance the punch size is >= the interval, we end up punching everything, zeroing out the file.

As this is not a tool to dealloc the whole file, so force the user to pass a configuration that won't cause it to happen.

---
 src/punch-alternating.c | 5 +++++
 1 file changed, 5 insertions(+)
src/punch-alternating.c +0 -0
index d2bb4b6a2276..c555b48d8591 100644

src/punch-alternating.c int main(int argc, char *argv[]) · line 94

Quoted 7 lines
src/punch-alternating.c +4 -0
@@ -88,6 +88,11 @@ int main(int argc, char *argv[])
 		usage(argv[0]);
 	}
 
+	if (size >= interval) {
+		printf("Interval must be > size\n");
+		usage(argv[0]);
+	}

OK, I don't mind adding this checking. May I ask which test case hit this "size >= interval" issue when you ran your test?

Quoted 7 lines
Quoted 2 lines

None. I was just using the program to test some other stuff without any specific test.

Sure, good to know there's not other issues :) This program is a good tool to do some other tests, especially creates lots of data extents effectively :) I've pushed this patch to patches-in-queue branch, will merge it in next release after testing, feel free to check it.

Indeed, and took me a while to understand why I was ending up with an empty file instead of a bunch of extents :)

Quoted 19 lines

Thanks,
Zorro

Quoted 13 lines
Quoted 12 lines
Quoted 7 lines
src/punch-alternating.c +1 -0
+
 	if (optind != argc - 1)
 		usage(argv[0]);
 
Signature · 1 line
2.52.0