diff options
author | Richard W.M. Jones <rjones@redhat.com> | 2012-06-22 08:49:40 +0100 |
---|---|---|
committer | Richard W.M. Jones <rjones@redhat.com> | 2012-06-28 09:09:03 +0100 |
commit | 7e37bcfa2670cda780fc76b1456f26b0c2a1408c (patch) | |
tree | 74da90ef935ca86159689ea7bcd48fa4684c4e4b | |
parent | 2fa9779b81bc6dff11eb10644755ca9063e8865f (diff) | |
download | libguestfs-7e37bcfa2670cda780fc76b1456f26b0c2a1408c.tar.gz libguestfs-7e37bcfa2670cda780fc76b1456f26b0c2a1408c.tar.xz libguestfs-7e37bcfa2670cda780fc76b1456f26b0c2a1408c.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.
(cherry picked from commit 6cb74d46ba5b1c3f1edd3bfb12df9d4da2ec8a8f)
-rw-r--r-- | format/format.c | 26 |
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; +} |