[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Libguestfs] [PATCH] xfs: add a new api xfs_repair



Add a new api xfs_repair for repairing an XFS filesystem.

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

diff --git a/daemon/xfs.c b/daemon/xfs.c
index 12ed600..8a86f93 100644
--- a/daemon/xfs.c
+++ b/daemon/xfs.c
@@ -536,3 +536,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 562f785..98a894c 100644
--- a/generator/generator_actions.ml
+++ b/generator/generator_actions.ml
@@ -9453,6 +9453,29 @@ Devices that are mounted cannot be modified.  Administrators must unmount
 filesystems before C<xfs_admin> can convert parameters.  A number of parameters
 of a mounted filesystem can be examined and modified using the C<xfs_growfs>." };
 
+  { 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"; ""; ""; ""; "true"; ""; ""; ""; ""; ""; ""; ""; ""; "/dev/sda1"]
+      ])
+    ];
+    shortdesc = "repair an XFS filesystem";
+    longdesc = "\
+C<xfs_repair> repairs corrupt or damaged XFS filesystems.  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/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


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]