Whamcloud - gitweb
Need to include mount_utils.h in the _SOURCES for the tools that use it.
[fs/lustre-release.git] / lustre / utils / mkfs_lustre.c
index f64a86f..b6a7f26 100644 (file)
@@ -40,6 +40,9 @@
 #include <limits.h>
 
 #ifdef __linux__
+/* libcfs.h is not really needed here, but on SLES10/PPC, fs.h includes idr.h which
+ * requires BITS_PER_LONG to be defined */
+#include <libcfs/libcfs.h>
 #include <linux/fs.h> /* for BLKGETSIZE64 */
 #include <linux/version.h>
 #endif
@@ -47,6 +50,7 @@
 #include <lustre_param.h>
 #include <lnet/lnetctl.h>
 #include <lustre_ver.h>
+#include "mount_utils.h"
 
 #ifndef PATH_MAX
 #define PATH_MAX 4096
@@ -70,8 +74,8 @@ struct mkfs_opts {
         int   mo_mgs_failnodes;
 };
 
-static char *progname;
-static int verbose = 1;
+char *progname;
+int verbose = 1;
 static int print_only = 0;
 static int failover = 0;
 
@@ -122,12 +126,6 @@ void usage(FILE *out)
 #define vprint if (verbose > 0) printf
 #define verrprint if (verbose >= 0) printf
 
-static void fatal(void)
-{
-        verbose = 0;
-        fprintf(stderr, "\n%s FATAL: ", progname);
-}
-
 /*================ utility functions =====================*/
 
 char *strscat(char *dst, char *src, int buflen) {
@@ -182,47 +180,6 @@ int get_os_version()
         return version;
 }
 
-int run_command(char *cmd, int cmdsz)
-{
-        char log[] = "/tmp/mkfs_logXXXXXX";
-        int fd = -1, rc;
-
-        if ((cmdsz - strlen(cmd)) < 6) {
-                fatal();
-                fprintf(stderr, "Command buffer overflow: %.*s...\n",
-                        cmdsz, cmd);
-                return ENOMEM;
-        }
-
-        if (verbose > 1) {
-                printf("cmd: %s\n", cmd);
-        } 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 && (fd >= 0)) {
-                char buf[128];
-                FILE *fp;
-                fp = fopen(log, "r");
-                if (fp) {
-                        while (fgets(buf, sizeof(buf), fp) != NULL) {
-                                printf("   %s", buf);
-                        }
-                        fclose(fp);
-                }
-        }
-        if (fd >= 0)
-                remove(log);
-        return rc;
-}
-
 static int check_mtab_entry(char *spec)
 {
         FILE *fp;
@@ -269,6 +226,7 @@ int loop_setup(struct mkfs_opts *mop)
         for (i = 0; i < MAX_LOOP_DEVICES; i++) {
                 char cmd[PATH_MAX];
                 int cmdsz = sizeof(cmd);
+
                 sprintf(l_device, "%s%d", loop_base, i);
                 if (access(l_device, F_OK | R_OK))
                         break;
@@ -445,6 +403,7 @@ static int file_in_dev(char *file_name, char *dev_name)
                 if (strstr(debugfs_cmd, "unsupported feature")) {
                           disp_old_e2fsprogs_msg("an unknown", 0);
                 }
+                pclose(fp);
                 return -1;
         }
         pclose(fp);
@@ -531,11 +490,16 @@ static void enable_default_backfs_features(struct mkfs_opts *mop)
 
         strscat(mop->mo_mkfsopts, " -O dir_index", sizeof(mop->mo_mkfsopts));
 
+        /* Upstream e2fsprogs called our uninit_groups feature uninit_bg,
+         * check for both of them when testing e2fsprogs features. */
         if (is_e2fsprogs_feature_supp("uninit_groups") == 0)
                 strscat(mop->mo_mkfsopts, ",uninit_groups",
                         sizeof(mop->mo_mkfsopts));
+        else if (is_e2fsprogs_feature_supp("uninit_bg") == 0)
+                strscat(mop->mo_mkfsopts, ",uninit_bg",
+                        sizeof(mop->mo_mkfsopts));
         else
-                disp_old_e2fsprogs_msg("uninit_groups", 1);
+                disp_old_e2fsprogs_msg("uninit_bg", 1);
 
         ret = uname(&uts);
         if (ret)
@@ -903,6 +867,10 @@ int read_local_files(struct mkfs_opts *mop)
 
         dev = mop->mo_device;
 
+        /* TODO: it's worth observing the get_mountdata() function that is
+                 in mount_utils.c for getting the mountdata out of the
+                 filesystem */
+
         /* Construct debugfs command line. */
         snprintf(cmd, cmdsz, "debugfs -c -R 'dump /%s %s/mountdata' %s",
                  MOUNT_DATA_FILE, tmpdir, dev);
@@ -921,10 +889,10 @@ int read_local_files(struct mkfs_opts *mop)
                 /* COMPAT_146 */
                 /* Try to read pre-1.6 config from last_rcvd */
                 struct lr_server_data lsd;
-                verrprint("%s: Unable to read %s (%s).\n",
-                          progname, filepnm, strerror(errno));
+                verrprint("%s: Unable to read %d.%d config %s.\n",
+                          progname, LUSTRE_MAJOR, LUSTRE_MINOR, filepnm);
 
-                verrprint("Trying last_rcvd\n");
+                verrprint("Trying 1.4 config from last_rcvd\n");
                 sprintf(filepnm, "%s/%s", tmpdir, LAST_RCVD);
 
                 /* Construct debugfs command line. */
@@ -1192,12 +1160,6 @@ int parse_opts(int argc, char *const argv[], struct mkfs_opts *mop,
                                 return 1;
                         rc = add_param(mop->mo_ldd.ldd_params, PARAM_FAILNODE,
                                        nids);
-                        /* Combo needs to add MDT failnodes as MGS failnodes
-                           as well */
-                        if (!rc && IS_MGS(&mop->mo_ldd)) {
-                                rc = add_param(mop->mo_ldd.ldd_params,
-                                               PARAM_MGSNODE, nids);
-                        }
                         free(nids);
                         if (rc)
                                 return rc;
@@ -1321,7 +1283,7 @@ int parse_opts(int argc, char *const argv[], struct mkfs_opts *mop,
                 fprintf(stderr, "Bad argument: %s\n", argv[optind]);
                 return EINVAL;
         }
-        
+
         return 0;
 }