summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWanlong Gao <gaowanlong@cn.fujitsu.com>2012-05-15 22:29:19 +0800
committerRichard W.M. Jones <rjones@redhat.com>2012-05-15 16:07:45 +0100
commitb9331a2d73f2ce2e424329d35139e68f0fbe8c7a (patch)
treefb2f0afa7d848fac27a3d149d5e1616007c407f0
parenta84d02e8d8fbb7d31cd124cd0eefe56cddeb3045 (diff)
downloadlibguestfs-b9331a2d73f2ce2e424329d35139e68f0fbe8c7a.tar.gz
libguestfs-b9331a2d73f2ce2e424329d35139e68f0fbe8c7a.tar.xz
libguestfs-b9331a2d73f2ce2e424329d35139e68f0fbe8c7a.zip
NEW API: add new api btrfs-fsck
Add the new API btrfs-fsck to check the btrfs filesystem. Btrfs is currently under heavy development, and not suitable for any uses other than benchmarking and review. But it'll be useful in the near future. Signed-off-by: Wanlong Gao <gaowanlong@cn.fujitsu.com>
-rw-r--r--daemon/btrfs.c44
-rw-r--r--generator/generator_actions.ml9
-rw-r--r--gobject/Makefile.inc6
-rw-r--r--po/POTFILES1
-rw-r--r--src/MAX_PROC_NR2
5 files changed, 59 insertions, 3 deletions
diff --git a/daemon/btrfs.c b/daemon/btrfs.c
index 125dd297..b9b88dd1 100644
--- a/daemon/btrfs.c
+++ b/daemon/btrfs.c
@@ -619,3 +619,47 @@ do_btrfs_set_seeding (const char *device, int svalue)
free (err);
return 0;
}
+
+/* Takes optional arguments, consult optargs_bitmask. */
+int
+do_btrfs_fsck (const char *device, int64_t superblock, int repair)
+{
+ char *err;
+ int r;
+ size_t i = 0;
+ const size_t MAX_ARGS = 64;
+ const char *argv[MAX_ARGS];
+ char super_s[64];
+
+ ADD_ARG (argv, i, "btrfsck");
+
+ /* Optional arguments. */
+ if (optargs_bitmask & GUESTFS_BTRFS_FSCK_SUPERBLOCK_BITMASK) {
+ if (superblock < 0) {
+ reply_with_error ("super block offset must be >= 0");
+ return -1;
+ }
+ snprintf (super_s, sizeof super_s, "%" PRIi64, superblock);
+ ADD_ARG (argv, i, "--super");
+ ADD_ARG (argv, i, super_s);
+ }
+
+ if (!(optargs_bitmask & GUESTFS_BTRFS_FSCK_REPAIR_BITMASK))
+ repair = 0;
+
+ if (repair)
+ ADD_ARG (argv, i, "--repair");
+
+ ADD_ARG (argv, i, device);
+ ADD_ARG (argv, i, NULL);
+
+ r = commandv (NULL, &err, argv);
+ if (r == -1) {
+ reply_with_error ("%s: %s", device, err);
+ free (err);
+ return -1;
+ }
+
+ free (err);
+ return 0;
+}
diff --git a/generator/generator_actions.ml b/generator/generator_actions.ml
index fc2df423..4dc46385 100644
--- a/generator/generator_actions.ml
+++ b/generator/generator_actions.ml
@@ -7232,6 +7232,15 @@ If C<devices> is an empty list, this does nothing.");
Enable or disable the seeding feature of a device that contains
a btrfs filesystem.");
+ ("btrfs_fsck", (RErr, [Device "device"], [OInt64 "superblock"; OBool "repair"]), 332, [Optional "btrfs"],
+ [InitPartition, IfAvailable "btrfs", TestRun (
+ [["mkfs_btrfs"; "/dev/sda1"; ""; ""; "NOARG"; ""; "NOARG"; "NOARG"; ""; ""];
+ ["btrfs_fsck"; "/dev/sda1"; ""; ""]])],
+ "check a btrfs filesystem",
+ "\
+Used to check a btrfs filesystem, C<device> is the device file where the
+filesystem is stored.");
+
]
let all_functions = non_daemon_functions @ daemon_functions
diff --git a/gobject/Makefile.inc b/gobject/Makefile.inc
index c912fef6..d4db407c 100644
--- a/gobject/Makefile.inc
+++ b/gobject/Makefile.inc
@@ -60,7 +60,8 @@ guestfs_gobject_headers= \
include/guestfs-gobject/optargs-ntfsfix.h \
include/guestfs-gobject/optargs-ntfsclone_out.h \
include/guestfs-gobject/optargs-mkfs_btrfs.h \
- include/guestfs-gobject/optargs-set_e2attrs.h
+ include/guestfs-gobject/optargs-set_e2attrs.h \
+ include/guestfs-gobject/optargs-btrfs_fsck.h
guestfs_gobject_sources= \
src/session.c \
@@ -102,4 +103,5 @@ guestfs_gobject_sources= \
src/optargs-ntfsfix.c \
src/optargs-ntfsclone_out.c \
src/optargs-mkfs_btrfs.c \
- src/optargs-set_e2attrs.c
+ src/optargs-set_e2attrs.c \
+ src/optargs-btrfs_fsck.c
diff --git a/po/POTFILES b/po/POTFILES
index 2b4b5864..9d3282ef 100644
--- a/po/POTFILES
+++ b/po/POTFILES
@@ -134,6 +134,7 @@ fuse/guestmount.c
gobject/src/optargs-add_domain.c
gobject/src/optargs-add_drive_opts.c
gobject/src/optargs-btrfs_filesystem_resize.c
+gobject/src/optargs-btrfs_fsck.c
gobject/src/optargs-compress_device_out.c
gobject/src/optargs-compress_out.c
gobject/src/optargs-copy_device_to_device.c
diff --git a/src/MAX_PROC_NR b/src/MAX_PROC_NR
index ec6cab01..6f96da66 100644
--- a/src/MAX_PROC_NR
+++ b/src/MAX_PROC_NR
@@ -1 +1 @@
-331
+332