summaryrefslogtreecommitdiffstats
path: root/format
diff options
context:
space:
mode:
authorRichard W.M. Jones <rjones@redhat.com>2012-06-22 08:49:40 +0100
committerRichard W.M. Jones <rjones@redhat.com>2012-06-22 10:57:55 +0100
commit6cb74d46ba5b1c3f1edd3bfb12df9d4da2ec8a8f (patch)
tree4c17a85376cffc51eb83b4acba74ec45d26470a9 /format
parent145f35badfd9ca4a6d9f54f7732566a5e5114876 (diff)
downloadlibguestfs-6cb74d46ba5b1c3f1edd3bfb12df9d4da2ec8a8f.tar.gz
libguestfs-6cb74d46ba5b1c3f1edd3bfb12df9d4da2ec8a8f.tar.xz
libguestfs-6cb74d46ba5b1c3f1edd3bfb12df9d4da2ec8a8f.zip
virt-format: Don't call wipefs unless API is available.
This API is optional. Don't call it unless it's available in the appliance.
Diffstat (limited to 'format')
-rw-r--r--format/format.c26
1 files changed, 25 insertions, 1 deletions
diff --git a/format/format.c b/format/format.c
index f9b864b7..b9bab4d2 100644
--- a/format/format.c
+++ b/format/format.c
@@ -50,10 +50,12 @@ static const char *filesystem = NULL;
static const char *vg = NULL, *lv = NULL;
static const char *partition = "DEFAULT";
static int wipe = 0;
+static int have_wipefs;
static void parse_vg_lv (const char *lvm);
static int do_format (void);
static int do_rescan (char **devices);
+static int feature_available (guestfs_h *g, const char *feature);
static inline char *
bad_cast (char const *s)
@@ -242,6 +244,9 @@ main (int argc, char *argv[])
if (guestfs_launch (g) == -1)
exit (EXIT_FAILURE);
+ /* Test if the wipefs API is available. */
+ have_wipefs = feature_available (g, "wipefs");
+
/* Perform the format. */
retry = do_format ();
if (!retry)
@@ -325,7 +330,7 @@ do_format (void)
if (!wipe) {
for (i = 0; devices[i] != NULL; ++i) {
/* erase the filesystem signatures on each device */
- if (guestfs_wipefs (g, devices[i]) == -1)
+ if (have_wipefs && guestfs_wipefs (g, devices[i]) == -1)
exit (EXIT_FAILURE);
/* Then erase the partition table on each device. */
if (guestfs_zero (g, devices[i]) == -1)
@@ -440,3 +445,22 @@ do_rescan (char **devices)
return errors ? 1 : 0;
}
+
+static int
+feature_available (guestfs_h *g, const char *feature)
+{
+ /* If there's an error we should ignore it, so to do that we have to
+ * temporarily replace the error handler with a null one.
+ */
+ guestfs_error_handler_cb old_error_cb;
+ void *old_error_data;
+ old_error_cb = guestfs_get_error_handler (g, &old_error_data);
+ guestfs_set_error_handler (g, NULL, NULL);
+
+ const char *groups[] = { feature, NULL };
+ int r = guestfs_available (g, (char * const *) groups);
+
+ guestfs_set_error_handler (g, old_error_cb, old_error_data);
+
+ return r == 0 ? 1 : 0;
+}