* [PATCH] xfsprogs: add fpunch command for hole punching via fallocate V2
@ 2010-11-19 19:33 Josef Bacik
0 siblings, 0 replies; only message in thread
From: Josef Bacik @ 2010-11-19 19:33 UTC (permalink / raw)
To: xfs, david
This adds a fpunch command that Dave Chinner recommended. It simply uses
fallocate to punch a hole for the given offset and length. It is necessary to
run the xfstest I have for hole punching. Thanks,
Signed-off-by: Josef Bacik <josef@redhat.com>
---
V1->V2
-instead of a -p option for falloc, make fpunch
io/prealloc.c | 45 +++++++++++++++++++++++++++++++++++++++++----
1 files changed, 41 insertions(+), 4 deletions(-)
diff --git a/io/prealloc.c b/io/prealloc.c
index c8b7df6..9dcfc1c 100644
--- a/io/prealloc.c
+++ b/io/prealloc.c
@@ -32,6 +32,9 @@ static cmdinfo_t unresvsp_cmd;
static cmdinfo_t zero_cmd;
#if defined(HAVE_FALLOCATE)
static cmdinfo_t falloc_cmd;
+#if defined (FALLOC_FL_PUNCH_HOLE)
+static cmdinfo_t fpunch_cmd;
+#endif
#endif
static int
@@ -153,8 +156,10 @@ fallocate_f(
xfs_flock64_t segment;
int mode = 0;
int c;
+ const char *opts;
- while ((c = getopt(argc, argv, "k")) != EOF) {
+ opts = "k";
+ while ((c = getopt(argc, argv, opts)) != EOF) {
switch (c) {
case 'k':
mode = FALLOC_FL_KEEP_SIZE;
@@ -176,7 +181,28 @@ fallocate_f(
}
return 0;
}
-#endif
+
+#if defined (FALLOC_FL_PUNCH_HOLE)
+static int
+fpunch_f(
+ int argc,
+ char **argv)
+{
+ xfs_flock64_t segment;
+ int mode = FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE;
+
+ if (!offset_length(argv[1], argv[2], &segment))
+ return 0;
+
+ if (fallocate(file->fd, mode,
+ segment.l_start, segment.l_len)) {
+ perror("fallocate");
+ return 0;
+ }
+ return 0;
+}
+#endif /* FALLOC_FL_PUNCH_HOLE */
+#endif /* HAVE_FALLOCATE */
void
prealloc_init(void)
@@ -239,7 +265,18 @@ prealloc_init(void)
falloc_cmd.args = _("[-k] off len");
falloc_cmd.oneline =
_("allocates space associated with part of a file via fallocate");
-
add_command(&falloc_cmd);
-#endif
+
+#if defined (FALLOC_FL_PUNCH_HOLE)
+ fpunch_cmd.name = _("fpunch");
+ fpunch_cmd.cfunc = fpunch_f;
+ fpunch_cmd.argmin = 2;
+ fpunch_cmd.argmax = -1;
+ fpunch_cmd.flags = CMD_NOMAP_OK | CMD_FOREIGN_OK;
+ fpunch_cmd.args = _("off len");
+ fpunch_cmd.oneline =
+ _("de-allocates space assocated with part of a file via fallocate");
+ add_command(&fpunch_cmd);
+#endif /* FALLOC_FL_PUNCH_HOLE */
+#endif /* HAVE_FALLOCATE */
}
--
1.6.6.1
_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2010-11-19 19:41 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-11-19 19:33 [PATCH] xfsprogs: add fpunch command for hole punching via fallocate V2 Josef Bacik
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox