[PATCH] xfsprogs: add fpunch command for hole punching via fallocate V2

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
---
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@xxxxxxxxxxx
http://oss.sgi.com/mailman/listinfo/xfs


[Index of Archives]     [Linux XFS Devel]     [Linux Filesystem Development]     [Filesystem Testing]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux