[Libguestfs] [PATCH V2] NEW API:xfs:xfs_repair

Wanlong Gao gaowanlong at cn.fujitsu.com
Wed Aug 22 06:41:55 UTC 2012


Add a new api xfs_repair for repairing an XFS filesystem.

Signed-off-by: Wanlong Gao <gaowanlong at cn.fujitsu.com>
---
 daemon/xfs.c                   | 116 +++++++++++++++++++++++++++++++++++++++++
 generator/generator_actions.ml |  25 +++++++++
 gobject/Makefile.inc           |   6 ++-
 guestfs-release-notes.txt      |   5 ++
 po/POTFILES                    |   1 +
 src/MAX_PROC_NR                |   2 +-
 6 files changed, 152 insertions(+), 3 deletions(-)

diff --git a/daemon/xfs.c b/daemon/xfs.c
index f3058d3..dc3d81c 100644
--- a/daemon/xfs.c
+++ b/daemon/xfs.c
@@ -528,3 +528,119 @@ error:
   free (err);
   return -1;
 }
+
+int
+do_xfs_repair (const char *device,
+              int imgfile, int forcelogzero, int dangerous,
+              int nomodify, int noprefetch, int forcegeometry,
+              int64_t maxmem, int64_t ihashsize,
+              int64_t bhashsize, int64_t agstride,
+              const char *logdev, const char *rtdev)
+{
+  int r;
+  char *err = NULL;
+  const char *argv[MAX_ARGS];
+  char maxmem_s[64];
+  char ihashsize_s[70];
+  char bhashsize_s[70];
+  char agstride_s[74];
+  size_t i = 0;
+
+  ADD_ARG (argv, i, "xfs_repair");
+
+  /* Optional arguments */
+  if (!(optargs_bitmask & GUESTFS_XFS_REPAIR_IMGFILE_BITMASK))
+    imgfile = 0;
+  if (!(optargs_bitmask & GUESTFS_XFS_REPAIR_FORCELOGZERO_BITMASK))
+    forcelogzero = 0;
+  if (!(optargs_bitmask & GUESTFS_XFS_REPAIR_DANGEROUS_BITMASK))
+    dangerous = 0;
+  if (!(optargs_bitmask & GUESTFS_XFS_REPAIR_NOMODIFY_BITMASK))
+    nomodify = 0;
+  if (!(optargs_bitmask & GUESTFS_XFS_REPAIR_NOPREFETCH_BITMASK))
+    noprefetch = 0;
+  if (!(optargs_bitmask & GUESTFS_XFS_REPAIR_FORCEGEOMETRY_BITMASK))
+    forcegeometry = 0;
+
+  if (imgfile)
+    ADD_ARG (argv, i, "-f");
+  if (forcelogzero)
+    ADD_ARG (argv, i, "-L");
+  if (dangerous)
+    ADD_ARG (argv, i, "-d");
+  if (nomodify)
+    ADD_ARG (argv, i, "-n");
+  if (noprefetch)
+    ADD_ARG (argv, i, "-P");
+  if (forcegeometry) {
+    ADD_ARG (argv, i, "-o");
+    ADD_ARG (argv, i, "force_geometry");
+  }
+
+  if (optargs_bitmask & GUESTFS_XFS_REPAIR_MAXMEM_BITMASK) {
+    if (maxmem < 0) {
+      reply_with_error ("maxmem must be >= 0");
+      goto error;
+    }
+    snprintf(maxmem_s, sizeof maxmem_s, "%" PRIi64, maxmem);
+    ADD_ARG (argv, i, "-m");
+    ADD_ARG (argv, i, maxmem_s);
+  }
+
+  if (optargs_bitmask & GUESTFS_XFS_REPAIR_IHASHSIZE_BITMASK) {
+    if (ihashsize < 0) {
+      reply_with_error ("ihashsize must be >= 0");
+      goto error;
+    }
+    snprintf(ihashsize_s, sizeof ihashsize_s, "ihash=" "%" PRIi64, ihashsize);
+    ADD_ARG (argv, i, "-o");
+    ADD_ARG (argv, i, ihashsize_s);
+  }
+
+  if (optargs_bitmask & GUESTFS_XFS_REPAIR_BHASHSIZE_BITMASK) {
+    if (bhashsize < 0) {
+      reply_with_error ("bhashsize must be >= 0");
+      goto error;
+    }
+    snprintf(bhashsize_s, sizeof bhashsize_s, "bhash=" "%" PRIi64, bhashsize);
+    ADD_ARG (argv, i, "-o");
+    ADD_ARG (argv, i, bhashsize_s);
+  }
+
+  if (optargs_bitmask & GUESTFS_XFS_REPAIR_AGSTRIDE_BITMASK) {
+    if (agstride < 0) {
+      reply_with_error ("agstride must be >= 0");
+      goto error;
+    }
+    snprintf(agstride_s, sizeof agstride_s, "ag_stride=" "%" PRIi64, agstride);
+    ADD_ARG (argv, i, "-o");
+    ADD_ARG (argv, i, agstride_s);
+  }
+
+
+  if (optargs_bitmask & GUESTFS_XFS_REPAIR_LOGDEV_BITMASK) {
+    ADD_ARG (argv, i, "-l");
+    ADD_ARG (argv, i, logdev);
+  }
+
+  if (optargs_bitmask & GUESTFS_XFS_REPAIR_RTDEV_BITMASK) {
+    ADD_ARG (argv, i, "-r");
+    ADD_ARG (argv, i, rtdev);
+  }
+
+  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);
+    goto error;
+  }
+
+  free (err);
+  return 0;
+
+error:
+  if (err) free (err);
+  return -1;
+}
diff --git a/generator/generator_actions.ml b/generator/generator_actions.ml
index 8cc9bb3..70e7b33 100644
--- a/generator/generator_actions.ml
+++ b/generator/generator_actions.ml
@@ -9462,6 +9462,31 @@ Some of the parameters of a mounted filesystem can be examined
 and modified using the C<guestfs_xfs_info> and
 C<guestfs_xfs_growfs> calls." };
 
+  { defaults with
+    name = "xfs_repair";
+    style = RErr, [Device "device"], [OBool "imgfile"; OBool "forcelogzero"; OBool "dangerous"; OBool "nomodify"; OBool "noprefetch"; OBool "forcegeometry"; OInt64 "maxmem"; OInt64 "ihashsize"; OInt64 "bhashsize"; OInt64 "agstride"; OString "logdev"; OString "rtdev"];
+    proc_nr = Some 350;
+    optional = Some "xfs";
+    tests = [
+      InitEmpty, IfAvailable "xfs", TestRun (
+        [["part_disk"; "/dev/sda"; "mbr"];
+         ["mkfs"; "xfs"; "/dev/sda1"; ""; "NOARG"; ""; ""];
+         ["xfs_repair"; "/dev/sda1"; ""; ""; ""; "true"; ""; ""; ""; ""; ""; ""; "NOARG"; "NOARG"]
+      ])
+    ];
+    shortdesc = "repair an XFS filesystem";
+    longdesc = "\
+Repair corrupt or damaged XFS filesystem on C<device>.
+
+The filesystem is specified using the C<device> argument which should be
+the device name of the disk partition or volume containing the filesystem.
+If given the name of a block device, C<xfs_repair> will attempt to find
+the raw device associated with the specified block device and will use
+the raw device instead.
+
+Regardless, the filesystem to be repaired must be unmounted, otherwise,
+the resulting filesystem may be inconsistent or corrupt." };
+
 ]
 
 (* Non-API meta-commands available only in guestfish.
diff --git a/gobject/Makefile.inc b/gobject/Makefile.inc
index 9f81cd2..4dfa0bf 100644
--- a/gobject/Makefile.inc
+++ b/gobject/Makefile.inc
@@ -73,7 +73,8 @@ guestfs_gobject_headers= \
   include/guestfs-gobject/optargs-rsync.h \
   include/guestfs-gobject/optargs-rsync_in.h \
   include/guestfs-gobject/optargs-rsync_out.h \
-  include/guestfs-gobject/optargs-xfs_admin.h
+  include/guestfs-gobject/optargs-xfs_admin.h \
+  include/guestfs-gobject/optargs-xfs_repair.h
 
 guestfs_gobject_sources= \
   src/session.c \
@@ -128,4 +129,5 @@ guestfs_gobject_sources= \
   src/optargs-rsync.c \
   src/optargs-rsync_in.c \
   src/optargs-rsync_out.c \
-  src/optargs-xfs_admin.c
+  src/optargs-xfs_admin.c \
+  src/optargs-xfs_repair.c
diff --git a/guestfs-release-notes.txt b/guestfs-release-notes.txt
index ed9de41..19b8a59 100644
--- a/guestfs-release-notes.txt
+++ b/guestfs-release-notes.txt
@@ -114,6 +114,7 @@ RELEASE NOTES FOR LIBGUESTFS 1.20
 
     For further information, see
     https://bugzilla.redhat.com/show_bug.cgi?id=788642
+    <https://bugzilla.redhat.com/show_bug.cgi?id=788642>
 
  New APIs
 
@@ -1633,10 +1634,14 @@ BUGS
     To get a list of bugs against libguestfs, use this link:
     https://bugzilla.redhat.com/buglist.cgi?component=libguestfs&product=Vi
     rtualization+Tools
+    <https://bugzilla.redhat.com/buglist.cgi?component=libguestfs&product=V
+    irtualization+Tools>
 
     To report a new bug against libguestfs, use this link:
     https://bugzilla.redhat.com/enter_bug.cgi?component=libguestfs&product=
     Virtualization+Tools
+    <https://bugzilla.redhat.com/enter_bug.cgi?component=libguestfs&product
+    =Virtualization+Tools>
 
     When reporting a bug, please supply:
 
diff --git a/po/POTFILES b/po/POTFILES
index d961ac1..727438b 100644
--- a/po/POTFILES
+++ b/po/POTFILES
@@ -169,6 +169,7 @@ gobject/src/optargs-umount.c
 gobject/src/optargs-umount_local.c
 gobject/src/optargs-xfs_admin.c
 gobject/src/optargs-xfs_growfs.c
+gobject/src/optargs-xfs_repair.c
 gobject/src/session.c
 gobject/src/struct-application.c
 gobject/src/struct-btrfssubvolume.c
diff --git a/src/MAX_PROC_NR b/src/MAX_PROC_NR
index aef2e27..0fecf65 100644
--- a/src/MAX_PROC_NR
+++ b/src/MAX_PROC_NR
@@ -1 +1 @@
-349
+350
-- 
1.7.12




More information about the Libguestfs mailing list