From: Josef Bacik <josef@redhat.com>
To: xfs@oss.sgi.com, david@fromorbit.com
Subject: [PATCH] xfsprogs: add fpunch command for hole punching via fallocate V2
Date: Fri, 19 Nov 2010 14:33:06 -0500 [thread overview]
Message-ID: <1290195186-19249-1-git-send-email-josef@redhat.com> (raw)
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
reply other threads:[~2010-11-19 19:41 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=1290195186-19249-1-git-send-email-josef@redhat.com \
--to=josef@redhat.com \
--cc=david@fromorbit.com \
--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