Skip to contentSkip to conversation

xfsprogs: xfsio: add support FALLOC_FL_COLLAPSE_RANGE for fallocate

PATCH RESEND Superseded Namjae Jeon 3 participants 6 messages Oct 6, 2013 – Oct 22, 2013 VFS

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH RESEND 4/7 xfsprogs: xfsio: add support FALLOC_FL_COLLAPSE_RANGE for fallocate

From: Namjae Jeon <[email protected]>

Add support FALLOC_FL_COLLAPSE_RANGE for fallocate.

---
 io/prealloc.c     |   39 ++++++++++++++++++++++++++++++++++++++-
 man/man8/xfs_io.8 |    6 ++++++
 2 files changed, 44 insertions(+), 1 deletion(-)
io/prealloc.c +38 -1
index 8380646..e7ff940 100644
@@ -29,6 +29,10 @@
 #define FALLOC_FL_PUNCH_HOLE	0x02
 #endif
 
+#ifndef FALLOC_FL_COLLAPSE_RANGE
+#define FALLOC_FL_COLLAPSE_RANGE 0x08
+#endif
+
 static cmdinfo_t allocsp_cmd;
 static cmdinfo_t freesp_cmd;
 static cmdinfo_t resvsp_cmd;
@@ -37,6 +41,7 @@ static cmdinfo_t zero_cmd;
 #if defined(HAVE_FALLOCATE)
 static cmdinfo_t falloc_cmd;
 static cmdinfo_t fpunch_cmd;
+static cmdinfo_t fcollapse_cmd;
 #endif
 
 static int
@@ -159,8 +164,11 @@ fallocate_f(
 	int		mode = 0;
 	int		c;
 
-	while ((c = getopt(argc, argv, "kp")) != EOF) {
+	while ((c = getopt(argc, argv, "ckp")) != EOF) {
 		switch (c) {
+		case 'c':
+			mode = FALLOC_FL_COLLAPSE_RANGE;
+			break;
 		case 'k':
 			mode = FALLOC_FL_KEEP_SIZE;
 			break;
@@ -203,6 +211,25 @@ fpunch_f(
 	}
 	return 0;
 }
+
+static int
+fcollapse_f(
+	int		argc,
+	char		**argv)
+{
+	xfs_flock64_t	segment;
+	int		mode = FALLOC_FL_COLLAPSE_RANGE;
+
+	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	/* HAVE_FALLOCATE */
 
 void
@@ -277,5 +304,15 @@ prealloc_init(void)
 	fpunch_cmd.oneline =
 		_("de-allocates space assocated with part of a file via fallocate");
 	add_command(&fpunch_cmd);
+
+	fcollapse_cmd.name = "fcollapse";
+	fcollapse_cmd.cfunc = fcollapse_f;
+	fcollapse_cmd.argmin = 2;
+	fcollapse_cmd.argmax = 2;
+	fcollapse_cmd.flags = CMD_NOMAP_OK | CMD_FOREIGN_OK;
+	fcollapse_cmd.args = _("off len");
+	fcollapse_cmd.oneline =
+	_("de-allocates space and eliminates the hole by shifting extents");
+	add_command(&fcollapse_cmd);
 #endif	/* HAVE_FALLOCATE */
 }
man/man8/xfs_io.8 +6 -0
index 767b50e..9543b20 100644
@@ -380,6 +380,12 @@ will set the FALLOC_FL_KEEP_SIZE flag as described in
 .PD
 .RE
 .TP
+.BI fcollapse " offset length"
+Call fallocate with FALLOC_FL_COLLAPSE_RANGE flag as described in the
+.BR fallocate (2)
+manual page to de-allocates blocks and eliminates the hole created in this process
+by shifting data blocks into the hole.
+.TP
 .BI fpunch " offset length"
 Punches (de-allocates) blocks in the file by calling fallocate with 
 the FALLOC_FL_PUNCH_HOLE flag as described in the
Signature · 6 lines
1.7.9.5

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
Reviewed-by on v1 4/7
#1 lore raw
Quoted 6 lines · Namjae Jeon

From: Namjae Jeon <[email protected]>

Add support FALLOC_FL_COLLAPSE_RANGE for fallocate.

Looks good.

Signature · 7 lines
Dave Chinner
[email protected]

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
#3 lore raw
Quoted 11 lines · Rich Johnston

This has been committed.

Thanks
--Rich

commit e64190f8440286a815060524777b435e06a7b364

Author: Namjae Jeon <[email protected]>
Date:   Sun Oct 6 20:13:38 2013 +0000

[RESEND, 4/7] xfsprogs: xfsio: add support
FALLOC_FL_COLLAPSE_RANGE for fallocate

Hi Rich,

This isn't ready for being committed into xfsprogs. The kernel code is still under review, and until we actually have it in a tree to be merged int eh kernel, we shoul d't be making any userspace changes at all. Indeed, there's a chance (unlikely, but still there) that this code may still not end up in the kernel at all...

So, it's probably best right now to revert this patch until we have the fallocate API support merged into the kernel...

Cheers,

Dave.

Signature · 2 lines
Dave Chinner
[email protected]
#4 lore raw

Sorry if there are others please let me know.

Quoted 21 lines · Dave Chinner
Quoted 11 lines · Rich Johnston

This has been committed.

Thanks
--Rich

commit e64190f8440286a815060524777b435e06a7b364

Author: Namjae Jeon <[email protected]>
Date:   Sun Oct 6 20:13:38 2013 +0000

[RESEND, 4/7] xfsprogs: xfsio: add support
FALLOC_FL_COLLAPSE_RANGE for fallocate

Hi Rich,

This isn't ready for being committed into xfsprogs. The kernel code is still under review, and until we actually have it in a tree to be merged int eh kernel, we shoul d't be making any userspace changes at all. Indeed, there's a chance (unlikely, but still there) that this code may still not end up in the kernel at all...

Quoted 7 lines

So, it's probably best right now to revert this patch until we have the fallocate API support merged into the kernel...

Cheers,

Dave.

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

#5 lore raw
In reply to Dave Chinner

This commit was reverted

commit 19e73c9d220728617816c47a1671cc931c40e45b

Author: Rich Johnston <[email protected]>
Date:   Tue Oct 22 10:15:20 2013 -0500

Revert "[RESEND, 4/7] xfsprogs: xfsio: add support
FALLOC_FL_COLLAPSE_RANGE for fallocate"

This reverts commit e64190f8440286a815060524777b435e06a7b364 until we have the fallocate API support merged into the kernel. The kernel code is still under review.

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs