]> xenbits.xensource.com Git - libvirt.git/commitdiff
fs: Add proper switch to create filesystem with overwrite
authorJohn Ferlan <jferlan@redhat.com>
Tue, 15 Nov 2016 20:29:47 +0000 (15:29 -0500)
committerJohn Ferlan <jferlan@redhat.com>
Wed, 16 Nov 2016 11:52:35 +0000 (06:52 -0500)
https://bugzilla.redhat.com/show_bug.cgi?id=1366460

When using the --overwrite switch on a pool-build or pool-create, the
The mkfs.ext{2|3|4} commands use mke2fs which requires using the '-F' switch
in order to force overwriting the current filesystem on the whole disk.

Likewise, the mkfs.vfat command uses mkfs.fat which requires using the '-I'
switch in order to force overwriting the current filesystem on the whole disk.

src/storage/storage_backend_fs.c

index 6c8bae22cef79f0d01111b1a644d3a7807ed751b..de0e8d57df548fcec53372ff925fa005ac4df75e 100644 (file)
@@ -712,9 +712,17 @@ virStorageBackendExecuteMKFS(const char *device,
 
     cmd = virCommandNewArgList(MKFS, "-t", format, NULL);
 
-    /* use the force, otherwise mkfs.xfs won't overwrite existing fs */
+    /* use the force, otherwise mkfs.xfs won't overwrite existing fs.
+     * Similarly mkfs.ext2, mkfs.ext3, and mkfs.ext4 require supplying -F
+     * and mkfs.vfat uses -I */
     if (STREQ(format, "xfs"))
         virCommandAddArg(cmd, "-f");
+    else if (STREQ(format, "ext2") ||
+             STREQ(format, "ext3") ||
+             STREQ(format, "ext4"))
+        virCommandAddArg(cmd, "-F");
+    else if (STREQ(format, "vfat"))
+        virCommandAddArg(cmd, "-I");
 
     virCommandAddArg(cmd, device);