Whamcloud - gitweb
catch extra args without dashes
[fs/lustre-release.git] / lustre / utils / mkfs_lustre.c
index fdb2043..9c9f381 100644 (file)
@@ -110,9 +110,9 @@ void usage(FILE *out)
                 "\t\t--nomgs: turn off MGS service on this MDT\n"
                 "\t\t--writeconf: erase all config logs for this fs.\n"
 #endif
-                "\t\t--noformat: just report what we would do; "
+                "\t\t--dryrun: just report what we would do; "
                 "don't write to disk\n"
-                "\t\t--verbose\n"
+                "\t\t--verbose : e.g. show mkfs progress\n"
                 "\t\t--quiet\n",
                 (int)sizeof(((struct lustre_disk_data *)0)->ldd_userdata));
         return;
@@ -168,7 +168,7 @@ int get_os_version()
 int run_command(char *cmd, int cmdsz)
 {
         char log[] = "/tmp/mkfs_logXXXXXX";
-        int fd, rc;
+        int fd = -1, rc;
         
         if ((cmdsz - strlen(cmd)) < 6) {
                 fatal();
@@ -177,19 +177,20 @@ int run_command(char *cmd, int cmdsz)
                 return ENOMEM;
         }
 
-        if (verbose > 1)
+        if (verbose > 1) {
                 printf("cmd: %s\n", cmd);
-        
-        if ((fd = mkstemp(log)) >= 0) {
-                close(fd);
-                strcat(cmd, " >");
-                strcat(cmd, log);
+        } else {
+                if ((fd = mkstemp(log)) >= 0) {
+                        close(fd);
+                        strcat(cmd, " >");
+                        strcat(cmd, log);
+                }
         }
         strcat(cmd, " 2>&1");
 
         /* Can't use popen because we need the rv of the command */
         rc = system(cmd);
-        if ((rc || (verbose > 2)) && (fd >= 0)) {
+        if (rc && (fd >= 0)) {
                 char buf[128];
                 FILE *fp;
                 fp = fopen(log, "r");
@@ -473,7 +474,7 @@ int make_lustre_backfs(struct mkfs_opts *mop)
                         }
                 }
 
-                /* Default bytes_per_inode is block size */
+                /* bytes_per_inode: disk size / num inodes */
                 if (strstr(mop->mo_mkfsopts, "-i") == NULL) {
                         long bytes_per_inode = 0;
                                         
@@ -492,7 +493,7 @@ int make_lustre_backfs(struct mkfs_opts *mop)
                         }
                 }
                 
-                /* This is an undocumented mke2fs option. Default is 128. */
+                /* Inode size (for extended attributes) */
                 if (strstr(mop->mo_mkfsopts, "-I") == NULL) {
                         long inode_size = 0;
                         if (IS_MDT(&mop->mo_ldd)) {
@@ -969,6 +970,7 @@ int parse_opts(int argc, char *const argv[], struct mkfs_opts *mop,
                 {"comment", 1, 0, 'u'},
                 {"configdev", 1, 0, 'C'},
                 {"device-size", 1, 0, 'd'},
+                {"dryrun", 0, 0, 'n'},
                 {"erase-params", 0, 0, 'e'},
                 {"failnode", 1, 0, 'f'},
                 {"failover", 1, 0, 'f'},
@@ -1162,15 +1164,15 @@ int parse_opts(int argc, char *const argv[], struct mkfs_opts *mop,
                                 fatal();
                                 fprintf(stderr, "Unknown option '%c'\n", opt);
                         }
-                        usage(stderr);
-                        return 1;
+                        return EINVAL;
                 }
         }//while
-        if (optind >= argc) {
+
+        /* Last arg is device */
+        if (optind != argc - 1) {
                 fatal();
-                fprintf(stderr, "Bad arguments\n");
-                usage(stderr);
-                return 1;
+                fprintf(stderr, "Bad argument: %s\n", argv[optind]);
+                return EINVAL;
         }
 
         return 0;