summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWanlong Gao <gaowanlong@cn.fujitsu.com>2011-12-14 17:40:56 +0800
committerRichard W.M. Jones <rjones@redhat.com>2012-01-10 15:36:54 +0000
commit5b9b317fdad5f7165da485dd9a6ebdc325941179 (patch)
treeb036644afc132bd8a0634c58ffe5be7b3fbac975
parent1f63454886c66f9672f0b15b0ed1050ec24c5ec5 (diff)
downloadlibguestfs-5b9b317fdad5f7165da485dd9a6ebdc325941179.tar.gz
libguestfs-5b9b317fdad5f7165da485dd9a6ebdc325941179.tar.xz
libguestfs-5b9b317fdad5f7165da485dd9a6ebdc325941179.zip
mkfs: optimization and code cleanup
v1->v2: fix a typo pointed by Matt Optimizations by reducing the STREQ operations and do some code cleanup. Signed-off-by: Wanlong Gao <gaowanlong@cn.fujitsu.com> RWMJ: Whitespace changes. (cherry picked from commit 2ac869bcc86fbf0dd7e878f10a2b60769a58c962)
-rw-r--r--daemon/mkfs.c29
1 files changed, 14 insertions, 15 deletions
diff --git a/daemon/mkfs.c b/daemon/mkfs.c
index a2c23667..b1b725c7 100644
--- a/daemon/mkfs.c
+++ b/daemon/mkfs.c
@@ -44,13 +44,17 @@ do_mkfs_opts (const char *fstype, const char *device, int blocksize,
int r;
char *err;
char mke2fs[] = "mke2fs";
+ int extfs = 0;
+
+ if (STREQ (fstype, "ext2") || STREQ (fstype, "ext3") ||
+ STREQ (fstype, "ext4"))
+ extfs = 1;
/* For ext2/3/4 run the mke2fs program directly. This is because
* the mkfs program "eats" some options, in particular the -F
* option.
*/
- if (STREQ (fstype, "ext2") || STREQ (fstype, "ext3") ||
- STREQ (fstype, "ext4")) {
+ if (extfs) {
if (e2prog (mke2fs) == -1)
return -1;
ADD_ARG (argv, i, mke2fs);
@@ -64,8 +68,7 @@ do_mkfs_opts (const char *fstype, const char *device, int blocksize,
/* Force mke2fs to create a filesystem, even if it thinks it
* shouldn't (RHBZ#690819).
*/
- if (STREQ (fstype, "ext2") || STREQ (fstype, "ext3") ||
- STREQ (fstype, "ext4"))
+ if (extfs)
ADD_ARG (argv, i, "-F");
/* mkfs.ntfs requires the -Q argument otherwise it writes zeroes
@@ -77,16 +80,13 @@ do_mkfs_opts (const char *fstype, const char *device, int blocksize,
/* mkfs.reiserfs produces annoying interactive prompts unless you
* tell it to be quiet.
+ * mkfs.jfs is the same
+ * mkfs.xfs must force to make xfs filesystem when the device already
+ * has a filesystem on it
*/
- if (STREQ (fstype, "reiserfs"))
- ADD_ARG (argv, i, "-f");
-
- /* Same for JFS. */
- if (STREQ (fstype, "jfs"))
- ADD_ARG (argv, i, "-f");
-
- if (STREQ (fstype, "xfs"))
- ADD_ARG (argv, i, "-f");
+ if (STREQ (fstype, "reiserfs") || STREQ (fstype, "jfs") ||
+ STREQ (fstype, "xfs"))
+ ADD_ARG(argv, i, "-f");
/* For GFS, GFS2, assume a single node. */
if (STREQ (fstype, "gfs") || STREQ (fstype, "gfs2")) {
@@ -147,8 +147,7 @@ do_mkfs_opts (const char *fstype, const char *device, int blocksize,
}
if (optargs_bitmask & GUESTFS_MKFS_OPTS_INODE_BITMASK) {
- if (!STREQ (fstype, "ext2") && !STREQ (fstype, "ext3") &&
- !STREQ (fstype, "ext4")) {
+ if (!extfs) {
reply_with_error ("inode size (-I) can only be set on ext2/3/4 filesystems");
return -1;
}