From: Namjae Jeon <linkinjeon@gmail.com>
To: viro@zeniv.linux.org.uk, mtk.manpages@gmail.com, tytso@mit.edu,
adilger.kernel@dilger.ca, bpm@sgi.com, elder@kernel.org,
hch@infradead.org, david@fromorbit.com
Cc: Namjae Jeon <linkinjeon@gmail.com>,
Namjae Jeon <namjae.jeon@samsung.com>,
linux-kernel@vger.kernel.org, xfs@oss.sgi.com,
a.sangwan@samsung.com, linux-fsdevel@vger.kernel.org,
linux-ext4@vger.kernel.org
Subject: [PATCH v3 4/7] xfsprogs: xfsio: add support FALLOC_FL_COLLAPSE_RANGE for fallocate
Date: Sun, 8 Sep 2013 22:42:19 +0900 [thread overview]
Message-ID: <1378647739-2700-1-git-send-email-linkinjeon@gmail.com> (raw)
From: Namjae Jeon <namjae.jeon@samsung.com>
Add support FALLOC_FL_COLLAPSE_RANGE for fallocate.
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: Ashish Sangwan <a.sangwan@samsung.com>
---
io/prealloc.c | 39 ++++++++++++++++++++++++++++++++++++++-
man/man8/xfs_io.8 | 6 ++++++
2 files changed, 44 insertions(+), 1 deletion(-)
diff --git a/io/prealloc.c b/io/prealloc.c
index 8380646..e7ff940 100644
--- a/io/prealloc.c
+++ b/io/prealloc.c
@@ -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 */
}
diff --git a/man/man8/xfs_io.8 b/man/man8/xfs_io.8
index 767b50e..9543b20 100644
--- a/man/man8/xfs_io.8
+++ b/man/man8/xfs_io.8
@@ -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
--
1.7.9.5
_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs
reply other threads:[~2013-09-08 13:42 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1378647739-2700-1-git-send-email-linkinjeon@gmail.com \
--to=linkinjeon@gmail.com \
--cc=a.sangwan@samsung.com \
--cc=adilger.kernel@dilger.ca \
--cc=bpm@sgi.com \
--cc=david@fromorbit.com \
--cc=elder@kernel.org \
--cc=hch@infradead.org \
--cc=linux-ext4@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mtk.manpages@gmail.com \
--cc=namjae.jeon@samsung.com \
--cc=tytso@mit.edu \
--cc=viro@zeniv.linux.org.uk \
--cc=xfs@oss.sgi.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).