[Libguestfs] mke2fs fails due to wipefs --force
Richard W.M. Jones
rjones at redhat.com
Sun Jan 19 20:30:08 UTC 2014
On Sun, Jan 19, 2014 at 07:42:58PM +0100, Olaf Hering wrote:
> My wipefs has no --force option, as a result mke2fs command in guestfish fails.
>
> Looks like 72dd398679cd0bb803daf306d12558369615ba70 needs an adjustment
> to make use of do_wipefs?
> Also str_wipefs is not used in that file.
Also daemon/zero.c has a wipefs_has_force_option function. It seems
like it would be better if this function was also used in
wipe_device_before_mkfs (in the same file).
But yes, it's definitely a bug if wipefs is causing mke2fs to fail.
How about the attached patch (only compile-tested)?
Rich.
--
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Fedora Windows cross-compiler. Compile Windows programs, test, and
build Windows installers. Over 100 libraries supported.
http://fedoraproject.org/wiki/MinGW
-------------- next part --------------
>From c9b4e65b376b1c6c3f45e66f34c97bebe8412a02 Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones at redhat.com>
Date: Sun, 19 Jan 2014 20:28:35 +0000
Subject: [PATCH] daemon: Use wipefs_has_force_option to decide whether to add
wipefs --force option.
---
daemon/zero.c | 24 +++++++++++++++++-------
1 file changed, 17 insertions(+), 7 deletions(-)
diff --git a/daemon/zero.c b/daemon/zero.c
index a07989e..ff0ea97 100644
--- a/daemon/zero.c
+++ b/daemon/zero.c
@@ -26,6 +26,8 @@
#include <unistd.h>
#include <sys/statvfs.h>
+#include "ignore-value.h"
+
#include "daemon.h"
#include "actions.h"
#include "optgroups.h"
@@ -91,7 +93,7 @@ wipefs_has_force_option (void)
CLEANUP_FREE char *out = NULL, *err = NULL;
if (flag == -1) {
- r = command (&out, &err, "wipefs", "--help", NULL);
+ r = command (&out, &err, str_wipefs, "--help", NULL);
if (r == -1) {
reply_with_error ("%s", err);
return -1;
@@ -354,15 +356,23 @@ do_zero_free_space (const char *dir)
void
wipe_device_before_mkfs (const char *device)
{
- int r;
+ int force;
+ const size_t MAX_ARGS = 16;
+ const char *argv[MAX_ARGS];
+ size_t i = 0;
- r = command (NULL, NULL, "wipefs", "-a", "--force", device, NULL);
- if (r == 0)
+ force = wipefs_has_force_option ();
+ if (force == -1)
return;
- r = command (NULL, NULL, "wipefs", "-a", device, NULL);
- if (r == 0)
- return;
+ ADD_ARG (argv, i, str_wipefs);
+ ADD_ARG (argv, i, "-a");
+ if (force)
+ ADD_ARG (argv, i, "--force");
+ ADD_ARG (argv, i, device);
+ ADD_ARG (argv, i, NULL);
+
+ ignore_value (commandv (NULL, NULL, argv));
/* XXX We could fall back to overwriting bits of disk here, but if
* they don't have working wipefs, it seems unlikely they are using
--
1.8.4.2
More information about the Libguestfs
mailing list