Whamcloud - gitweb
Revert "LU-3682 tunefs: prevent tunefs running on a mounted device"
[fs/lustre-release.git] / lustre / utils / mkfs_lustre.c
index 3d6baee..646a767 100644 (file)
@@ -270,7 +270,7 @@ static char *convert_hostnames(char *s1)
         return converted;
 }
 
-static int parse_opts(int argc, char *const argv[], struct mkfs_opts *mop,
+int parse_opts(int argc, char *const argv[], struct mkfs_opts *mop,
                char **mountopts)
 {
         static struct option long_opt[] = {
@@ -522,6 +522,9 @@ static int parse_opts(int argc, char *const argv[], struct mkfs_opts *mop,
                        "pool/dataset name not specified.\n");
                return EINVAL;
        } else {
+               /*  The device or pool/filesystem name */
+               strscpy(mop->mo_device, argv[optind], sizeof(mop->mo_device));
+
                /* Followed by optional vdevs */
                if (optind < argc - 1)
                        mop->mo_pool_vdevs = (char **) &argv[optind + 1];
@@ -553,14 +556,12 @@ int main(int argc, char *const argv[])
         memset(&mop, 0, sizeof(mop));
         set_defaults(&mop);
 
-       /* Try to get the real path to the device */
-       ret = get_realpath(argv[argc - 1], &mop.mo_device);
-       if (ret != 0)
-               return ret;
+        /* device is last arg */
+        strscpy(mop.mo_device, argv[argc - 1], sizeof(mop.mo_device));
 
        ret = osd_init();
        if (ret)
-               goto out;
+               return ret;
 
 #ifdef TUNEFS
         /* For tunefs, we must read in the old values before parsing any
@@ -723,12 +724,8 @@ int main(int argc, char *const argv[])
                 goto out;
         }
 
-       ret = check_mtab_entry(mop.mo_device, mop.mo_device, NULL, NULL);
-       if (ret != 0) {
-               fprintf(stderr, "%s: %s is already mounted\n",
-                       progname, mop.mo_device);
-               goto out;
-       }
+       if (check_mtab_entry(mop.mo_device, mop.mo_device, NULL, NULL))
+               return(EEXIST);
 
         /* Create the loopback file */
         if (mop.mo_flags & MO_IS_LOOP) {
@@ -801,7 +798,6 @@ int main(int argc, char *const argv[])
 
 out:
         loop_cleanup(&mop);
-       free(mop.mo_device);
        osd_fini();
 
         /* Fix any crazy return values from system() */