[Pkg-libvirt-commits] [libguestfs] 187/384: New API: add btrfs_filesystem_defragment
Hilko Bengen
bengen at moszumanska.debian.org
Sun Mar 29 16:56:51 UTC 2015
This is an automated email from the git hooks/post-receive script.
bengen pushed a commit to branch experimental
in repository libguestfs.
commit e32b59c926eb480913140a57e1ec501cf44726b5
Author: Hu Tao <hutao at cn.fujitsu.com>
Date: Fri Jan 16 10:23:45 2015 +0800
New API: add btrfs_filesystem_defragment
Signed-off-by: Hu Tao <hutao at cn.fujitsu.com>
---
daemon/btrfs.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
generator/actions.ml | 21 +++++++++++++++++++++
gobject/Makefile.inc | 2 ++
po/POTFILES | 1 +
src/MAX_PROC_NR | 2 +-
5 files changed, 74 insertions(+), 1 deletion(-)
diff --git a/daemon/btrfs.c b/daemon/btrfs.c
index 18d2a79..9fa6511 100644
--- a/daemon/btrfs.c
+++ b/daemon/btrfs.c
@@ -1558,3 +1558,52 @@ do_btrfs_balance_resume (const char *path)
return 0;
}
+
+/* Takes optional arguments, consult optargs_bitmask. */
+int
+do_btrfs_filesystem_defragment (const char *path, int flush, const char *compress)
+{
+ const size_t MAX_ARGS = 64;
+ const char *argv[MAX_ARGS];
+ size_t i = 0;
+ CLEANUP_FREE char *path_buf = NULL;
+ CLEANUP_FREE char *err = NULL;
+ CLEANUP_FREE char *out = NULL;
+ int r;
+
+ path_buf = sysroot_path (path);
+ if (path_buf == NULL) {
+ reply_with_perror ("malloc");
+ return -1;
+ }
+
+ ADD_ARG (argv, i, str_btrfs);
+ ADD_ARG (argv, i, "filesystem");
+ ADD_ARG (argv, i, "defragment");
+ ADD_ARG (argv, i, "-r");
+
+ /* Optional arguments. */
+ if ((optargs_bitmask & GUESTFS_BTRFS_FILESYSTEM_DEFRAGMENT_FLUSH_BITMASK) && flush)
+ ADD_ARG (argv, i, "-f");
+ if (optargs_bitmask & GUESTFS_BTRFS_FILESYSTEM_DEFRAGMENT_COMPRESS_BITMASK) {
+ if (STREQ(compress, "zlib"))
+ ADD_ARG (argv, i, "-czlib");
+ else if (STREQ(compress, "lzo"))
+ ADD_ARG (argv, i, "-clzo");
+ else {
+ reply_with_error ("unknown compress method: %s", compress);
+ return -1;
+ }
+ }
+
+ ADD_ARG (argv, i, path_buf);
+ ADD_ARG (argv, i, NULL);
+
+ r = commandv (&out, &err, argv);
+ if (r == -1) {
+ reply_with_error ("%s: %s", path, err);
+ return -1;
+ }
+
+ return 0;
+}
diff --git a/generator/actions.ml b/generator/actions.ml
index 7c035e1..0dc8520 100644
--- a/generator/actions.ml
+++ b/generator/actions.ml
@@ -12336,6 +12336,27 @@ Cancel a running balance on a btrfs filesystem." };
shortdesc = "resume a paused balance";
longdesc = "\
Resume a paused balance on a btrfs filesystem." };
+
+ { defaults with
+ name = "btrfs_filesystem_defragment";
+ style = RErr, [Pathname "path"], [OBool "flush"; OString "compress"];
+ proc_nr = Some 443;
+ optional = Some "btrfs"; camel_name = "BTRFSFilesystemDefragment";
+ tests = [
+ InitPartition, Always, TestRun (
+ [["mkfs_btrfs"; "/dev/sda1"; ""; ""; "NOARG"; ""; "NOARG"; "NOARG"; ""; ""];
+ ["mount"; "/dev/sda1"; "/"];
+ ["btrfs_filesystem_defragment"; "/"; "true"; "lzo"]]), [];
+ InitPartition, Always, TestRun (
+ [["mkfs_btrfs"; "/dev/sda1"; ""; ""; "NOARG"; ""; "NOARG"; "NOARG"; ""; ""];
+ ["mount"; "/dev/sda1"; "/"];
+ ["touch"; "/hello"];
+ ["btrfs_filesystem_defragment"; "/hello"; ""; "zlib"]]), [];
+ ];
+ shortdesc = "defragment a file or directory";
+ longdesc = "\
+Defragment a file or directory on a btrfs filesystem. compress is one of zlib or lzo." };
+
]
(* Non-API meta-commands available only in guestfish.
diff --git a/gobject/Makefile.inc b/gobject/Makefile.inc
index 15bbd21..e0c0a5f 100644
--- a/gobject/Makefile.inc
+++ b/gobject/Makefile.inc
@@ -49,6 +49,7 @@ guestfs_gobject_headers= \
include/guestfs-gobject/optargs-add_drive.h \
include/guestfs-gobject/optargs-add_drive_scratch.h \
include/guestfs-gobject/optargs-add_libvirt_dom.h \
+ include/guestfs-gobject/optargs-btrfs_filesystem_defragment.h \
include/guestfs-gobject/optargs-btrfs_filesystem_resize.h \
include/guestfs-gobject/optargs-btrfs_fsck.h \
include/guestfs-gobject/optargs-btrfs_subvolume_create.h \
@@ -131,6 +132,7 @@ guestfs_gobject_sources= \
src/optargs-add_drive.c \
src/optargs-add_drive_scratch.c \
src/optargs-add_libvirt_dom.c \
+ src/optargs-btrfs_filesystem_defragment.c \
src/optargs-btrfs_filesystem_resize.c \
src/optargs-btrfs_fsck.c \
src/optargs-btrfs_subvolume_create.c \
diff --git a/po/POTFILES b/po/POTFILES
index b18895b..4194e5f 100644
--- a/po/POTFILES
+++ b/po/POTFILES
@@ -174,6 +174,7 @@ gobject/src/optargs-add_domain.c
gobject/src/optargs-add_drive.c
gobject/src/optargs-add_drive_scratch.c
gobject/src/optargs-add_libvirt_dom.c
+gobject/src/optargs-btrfs_filesystem_defragment.c
gobject/src/optargs-btrfs_filesystem_resize.c
gobject/src/optargs-btrfs_fsck.c
gobject/src/optargs-btrfs_subvolume_create.c
diff --git a/src/MAX_PROC_NR b/src/MAX_PROC_NR
index 534a21e..6a13cf6 100644
--- a/src/MAX_PROC_NR
+++ b/src/MAX_PROC_NR
@@ -1 +1 @@
-440
+443
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-libvirt/libguestfs.git
More information about the Pkg-libvirt-commits
mailing list