Whamcloud - gitweb
LU-1581 utils: mkfs's usage to show zfs support
[fs/lustre-release.git] / lustre / utils / mkfs_lustre.c
index 27fdad3..bd90059 100644 (file)
@@ -88,12 +88,47 @@ int verbose = 1;
 static int print_only = 0;
 static int upgrade_to_18 = 0;
 
+#define FSLIST_LDISKFS "ldiskfs"
+#define HAVE_FSLIST
+#ifdef HAVE_ZFS_OSD
+ #ifdef HAVE_FSLIST
+   #define FSLIST_ZFS "|zfs"
+ #else
+  #define FSLIST_ZFS "zfs"
+  #define HAVE_FSLIST
+ #endif
+#else
+ #define FSLIST_ZFS ""
+#endif /* HAVE_ZFS_OSD */
+
+#ifndef HAVE_FSLIST
+ #error "no backing OSD types (ldiskfs or ZFS) are configured"
+#endif
+
+#define FSLIST FSLIST_LDISKFS FSLIST_ZFS
+
 void usage(FILE *out)
 {
         fprintf(out, "%s v"LUSTRE_VERSION_STRING"\n", progname);
-        fprintf(out, "usage: %s <target types> [options] <device>\n", progname);
+#ifdef HAVE_ZFS_OSD
+       fprintf(out, "usage: %s <target types> [--backfstype=zfs] [options] "
+                       "<pool name>/<dataset name> [[<vdev type>] <device> "
+                       "[<device> ...] [[vdev type>] ...]]\n", progname);
+#endif
+
+       fprintf(out, "usage: %s <target types> --backfstype="FSLIST" "
+                       "[options] <device>\n", progname);
         fprintf(out,
                 "\t<device>:block device or file (e.g /dev/sda or /tmp/ost1)\n"
+#ifdef HAVE_ZFS_OSD
+               "\t<pool name>: name of the ZFS pool where to create the "
+               "target (e.g. tank)\n"
+               "\t<dataset name>: name of the new dataset (e.g. ost1). The "
+               "dataset name must be unique within the ZFS pool\n"
+               "\t<vdev type>: type of vdev (mirror, raidz, raidz2, spare, "
+               "cache, log)\n"
+#endif
+               "\n"
                 "\ttarget types:\n"
                 "\t\t--ost: object storage, mutually exclusive with mdt,mgs\n"
                 "\t\t--mdt: metadata storage, mutually exclusive with ost\n"
@@ -177,6 +212,7 @@ void set_defaults(struct mkfs_opts *mop)
 
         mop->mo_ldd.ldd_svindex = INDEX_UNASSIGNED;
         mop->mo_stripe_count = 1;
+       mop->mo_pool_vdevs = NULL;
 }
 
 static inline void badopt(const char *opt, char *type)
@@ -292,6 +328,11 @@ int parse_opts(int argc, char *const argv[], struct mkfs_opts *mop,
                                 }
                                 i++;
                         }
+                       if (i == LDD_MT_LAST) {
+                               fprintf(stderr, "%s: invalid backend filesystem"
+                                       " type %s\n", progname, optarg);
+                               return 1;
+                       }
                         break;
                 }
                 case 'c':
@@ -479,16 +520,20 @@ int parse_opts(int argc, char *const argv[], struct mkfs_opts *mop,
                 }
         }//while
 
-        /* Last arg is device */
-        if (optind != argc - 1) {
-                fatal();
-                fprintf(stderr, "Bad argument: %s\n", argv[optind]);
-                return EINVAL;
-        }
-
-        /* single argument: <device> */
-        if (argc == 2)
-                ++print_only;
+       if (optind == argc) {
+               /* The user didn't specify device name */
+               fatal();
+               fprintf(stderr, "Not enough arguments - device name or "
+                       "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];
+       }
 
         return 0;
 }
@@ -500,6 +545,7 @@ int main(int argc, char *const argv[])
         char *mountopts = NULL;
         char always_mountopts[512] = "";
         char default_mountopts[512] = "";
+       unsigned mount_type;
         int ret = 0;
 
         if ((progname = strrchr(argv[0], '/')) != NULL)
@@ -523,7 +569,7 @@ int main(int argc, char *const argv[])
            new ones. */
 
         /* Check whether the disk has already been formatted by mkfs.lustre */
-        ret = is_lustre_target(&mop);
+       ret = osd_is_lustre(mop.mo_device, &mount_type);
         if (ret == 0) {
                 fatal();
                 fprintf(stderr, "Device %s has not been formatted with "
@@ -532,7 +578,7 @@ int main(int argc, char *const argv[])
                 goto out;
         }
 
-        ret = read_local_files(&mop);
+       ret = osd_read_ldd(mop.mo_device, &mop.mo_ldd);
         if (ret) {
                 fatal();
                 fprintf(stderr, "Failed to read previous Lustre data from %s "
@@ -546,6 +592,10 @@ int main(int argc, char *const argv[])
                 print_ldd("Read previous values", &(mop.mo_ldd));
 #endif
 
+       ret = osd_init();
+       if (ret)
+               return ret;
+
         ret = parse_opts(argc, argv, &mop, &mountopts);
         if (ret)
                 goto out;
@@ -665,7 +715,7 @@ int main(int argc, char *const argv[])
 #ifndef TUNEFS /* mkfs.lustre */
         /* Check whether the disk has already been formatted by mkfs.lustre */
         if (!(mop.mo_flags & MO_FORCEFORMAT)) {
-                ret = is_lustre_target(&mop);
+               ret = osd_is_lustre(mop.mo_device, &mount_type);
                 if (ret) {
                         fatal();
                         fprintf(stderr, "Device %s was previously formatted "
@@ -677,7 +727,7 @@ int main(int argc, char *const argv[])
         }
 
         /* Format the backing filesystem */
-        ret = make_lustre_backfs(&mop);
+       ret = osd_make_lustre(&mop);
         if (ret != 0) {
                 fatal();
                 fprintf(stderr, "mkfs failed %d\n", ret);
@@ -686,7 +736,7 @@ int main(int argc, char *const argv[])
 #endif
 
         /* Write our config files */
-        ret = write_local_files(&mop);
+       ret = osd_write_ldd(&mop);
         if (ret != 0) {
                 fatal();
                 fprintf(stderr, "failed to write local files\n");
@@ -695,6 +745,7 @@ int main(int argc, char *const argv[])
 
 out:
         loop_cleanup(&mop);
+       osd_fini();
 
         /* Fix any crazy return values from system() */
         if (ret && ((ret & 255) == 0))