4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2011, 2017, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
30 * Lustre is a trademark of Sun Microsystems, Inc.
32 * lustre/utils/mkfs_lustre.c
34 * Author: Nathan Rutman <nathan@clusterfs.com>
37 /* This source file is compiled into both mkfs.lustre and tunefs.lustre */
41 #endif /* HAVE_CONFIG_H */
54 #include <sys/types.h>
56 #include <sys/mount.h>
57 #include <sys/utsname.h>
63 #include <linux/lnet/nidstr.h>
64 #include <linux/lnet/lnetctl.h>
65 #include <linux/lustre/lustre_user.h>
66 #include <linux/lustre/lustre_ver.h>
68 #include "mount_utils.h"
73 static int print_only;
75 #ifdef HAVE_LDISKFS_OSD
76 #define FSLIST_LDISKFS "ldiskfs"
79 #define FSLIST_LDISKFS ""
80 #endif /* HAVE_LDISKFS_OSD */
83 #define FSLIST_ZFS "|zfs"
85 #define FSLIST_ZFS "zfs"
90 #endif /* HAVE_ZFS_OSD */
93 #error "no backing OSD types (ldiskfs or ZFS) are configured"
96 #define FSLIST FSLIST_LDISKFS FSLIST_ZFS
100 fprintf(out, "usage: %s <target type> [--backfstype="FSLIST"] "
101 "--fsname=<filesystem name>\n"
102 "\t--index=<target index> [options] <device>\n", progname);
104 fprintf(out, "usage: %s <target type> --backfstype=zfs "
105 "--fsname=<filesystem name> [options]\n"
106 "\t<pool name>/<dataset name>\n"
107 "\t[[<vdev type>] <device> [<device> ...] [vdev type>] ...]\n",
111 "\t<device>:block device or file (e.g /dev/sda or /tmp/ost1)\n"
113 "\t<pool name>: name of ZFS pool where target is created "
115 "\t<dataset name>: name of new dataset, must be unique within "
117 "\t<vdev type>: type of vdev (mirror, raidz, raidz2, spare, "
122 "\t\t--mgs: configuration management service\n"
123 "\t\t--nomgs: turn off MGS service on this MDT\n"
125 "\t\t--mdt: metadata storage, mutually exclusive with ost\n"
126 "\t\t--ost: object storage, mutually exclusive with mdt, mgs\n"
128 "\toptions (in order of popularity):\n"
129 "\t\t--index=#N: numerical target index (0..N)\n"
130 "\t\t\trequired for all targets other than the MGS,\n"
131 "\t\t\ttarget index may either be a decimal number or\n"
132 "\t\t\thexadecimal number starting with '0x'\n"
133 "\t\t--fsname=<8_char_filesystem_name>: fs targets belong to\n"
134 "\t\t\trequired for all targets other than MGS\n"
135 "\t\t--mgsnode=<nid>[,<...>]: NID(s) of remote MGS\n"
136 "\t\t\trequired for all targets other than MGS\n"
137 "\t\t--mountfsoptions=<opts>: permanent Lustre mount options\n"
138 "\t\t--backfs-mount-opts=<opts>: backing fs mount options\n"
139 "\t\t--failnode=<nid>[,<...>]: NID(s) of backup failover node\n"
140 "\t\t\tmutually exclusive with --servicenode\n"
141 "\t\t--servicenode=<nid>[,<...>]: NID(s) of service partners\n"
142 "\t\t\ttreat nodes as equal service node, mutually exclusive "
144 "\t\t--param <key>=<value>: set a permanent parameter\n"
145 "\t\t\te.g. --param sys.timeout=40\n"
146 "\t\t\t --param lov.stripesize=2M\n"
147 "\t\t--network=<net>[,<...>]: restrict OST/MDT to network(s)\n"
149 "\t\t--backfstype=<fstype>: backing fs type (ldiskfs, zfs)\n"
150 "\t\t--device-size=#N(KB): device size for loop devices\n"
151 "\t\t--mkfsoptions=<opts>: format options\n"
152 "\t\t--reformat: overwrite an existing disk\n"
153 "\t\t--replace: replace an old target with the same index\n"
154 "\t\t--stripe-count-hint=#N: for optimizing MDT inode size\n"
156 "\t\t--erase-param <key>: erase all instances of a parameter\n"
157 "\t\t--erase-params: erase all old parameter settings\n"
158 "\t\t--writeconf: erase all config logs for this fs.\n"
159 "\t\t--quota: enable space accounting on old 2.x device.\n"
160 "\t\t--rename: rename the filesystem name\n"
162 "\t\t--comment=<user comment>: arbitrary string (%d bytes)\n"
163 "\t\t--dryrun: report what we would do; don't write to disk\n"
164 "\t\t--verbose: e.g. show mkfs progress\n"
165 "\t\t--force-nohostid: Ignore hostid requirement for ZFS "
167 "\t\t-V|--version: output build version of the utility and\n"
170 (int)sizeof(((struct lustre_disk_data *)0)->ldd_userdata));
173 /* ==================== Lustre config functions =============*/
175 void print_ldd(char *str, struct mkfs_opts *mop)
177 struct lustre_disk_data *ldd = &mop->mo_ldd;
179 printf("\n %s:\n", str);
180 printf("Target: %s\n", ldd->ldd_svname);
181 if (ldd->ldd_svindex == INDEX_UNASSIGNED)
182 printf("Index: unassigned\n");
184 printf("Index: %d\n", ldd->ldd_svindex);
185 if (ldd->ldd_uuid[0])
186 printf("UUID: %s\n", (char *)ldd->ldd_uuid);
187 printf("Lustre FS: %s\n", ldd->ldd_fsname);
188 printf("Mount type: %s\n", MT_STR(ldd));
189 printf("Flags: %#x\n", ldd->ldd_flags);
190 printf(" (%s%s%s%s%s%s%s%s)\n",
191 IS_MDT(ldd) ? "MDT " : "",
192 IS_OST(ldd) ? "OST " : "",
193 IS_MGS(ldd) ? "MGS " : "",
194 ldd->ldd_flags & LDD_F_NEED_INDEX ? "needs_index " : "",
195 ldd->ldd_flags & LDD_F_VIRGIN ? "first_time " : "",
196 ldd->ldd_flags & LDD_F_UPDATE ? "update " : "",
197 ldd->ldd_flags & LDD_F_WRITECONF ? "writeconf " : "",
198 ldd->ldd_flags & LDD_F_NO_PRIMNODE ? "no_primnode " : "");
199 printf("Persistent mount opts: %s\n", ldd->ldd_mount_opts);
200 osd_print_ldd_params(mop);
201 if (ldd->ldd_userdata[0])
202 printf("Comment: %s\n", ldd->ldd_userdata);
206 void set_defaults(struct mkfs_opts *mop)
208 mop->mo_ldd.ldd_magic = LDD_MAGIC;
209 mop->mo_ldd.ldd_config_ver = 1;
210 mop->mo_ldd.ldd_flags = LDD_F_NEED_INDEX | LDD_F_UPDATE | LDD_F_VIRGIN;
211 #ifdef HAVE_LDISKFS_OSD
212 mop->mo_ldd.ldd_mount_type = LDD_MT_LDISKFS;
214 mop->mo_ldd.ldd_mount_type = LDD_MT_ZFS;
216 mop->mo_ldd.ldd_svindex = INDEX_UNASSIGNED;
217 mop->mo_mgs_failnodes = 0;
218 mop->mo_stripe_count = 1;
219 mop->mo_pool_vdevs = NULL;
222 /* Make the mdt/ost server obd name based on the filesystem name */
223 static bool server_make_name(__u32 flags, __u16 index, const char *fs,
224 char *name_buf, size_t name_buf_size)
226 bool invalid_flag = false;
228 if (flags & (LDD_F_SV_TYPE_MDT | LDD_F_SV_TYPE_OST)) {
229 if (!(flags & LDD_F_SV_ALL))
230 snprintf(name_buf, name_buf_size, "%.8s%c%s%04x", fs,
231 (flags & LDD_F_VIRGIN) ? ':' :
232 ((flags & LDD_F_WRITECONF) ? '=' : '-'),
233 (flags & LDD_F_SV_TYPE_MDT) ? "MDT" : "OST",
235 } else if (flags & LDD_F_SV_TYPE_MGS) {
236 snprintf(name_buf, name_buf_size, "MGS");
238 fprintf(stderr, "unknown server type %#x\n", flags);
244 static inline void badopt(const char *opt, char *type)
246 fprintf(stderr, "%s: '--%s' only valid for %s\n",
247 progname, opt, type);
253 * Removes all existing instances of the parameter passed in \a param,
254 * which are in the form of "key=<value>", from the buffer at \a buf.
256 * The parameter can be either in the form of "key" when passed by option
257 * "--erase-param", or in the form of "key=<value>" when passed by option
260 * \param buf the buffer holding on-disk server parameters.
261 * \param param the parameter whose instances are to be removed from \a buf.
262 * \param withval true means the parameter is in the form of "key=<value>"
263 * false means the parameter is in the form of "key"
265 * \retval 0 success, parameter was erased,
266 * \retval 1 success, parameter was not found, don't need to do erase_ldd,
267 * \retval EINVAL failure, invalid input parameter.
269 static int erase_param(const char *const buf, const char *const param,
272 char search[PARAM_MAX + 1] = "";
273 char *buffer = (char *)buf;
276 if (strlen(param) > PARAM_MAX) {
277 fprintf(stderr, "%s: param to erase is too long-\n%s\n",
282 /* add_param() writes a space as the first character in ldd_params */
285 /* "key" or "key=<value>" */
289 keyend = strchr(param, '=');
292 strncpy(&search[1], param, keyend - param + 1);
294 snprintf(search + 1, sizeof(search) - 1, "%s=", param);
300 buffer = strstr(buffer, search);
302 return found == true ? 0 : 1;
304 space = strchr(buffer + 1, ' ');
306 memmove(buffer, space, strlen(space) + 1);
315 /* from mount_lustre */
316 /* Get rid of symbolic hostnames for tcp, since kernel can't do lookups */
317 #define MAXNIDSTR 1024
318 static char *convert_hostnames(char *s1)
320 char *converted, *s2 = 0, *c, *end, sep;
321 int left = MAXNIDSTR;
324 converted = malloc(left);
328 end = s1 + strlen(s1);
330 while ((left > 0) && (s1 < end)) {
331 s2 = strpbrk(s1, ",:");
336 nid = libcfs_str2nid(s1);
339 if (nid == LNET_NID_ANY) {
340 fprintf(stderr, "%s: Cannot resolve hostname '%s'.\n",
345 if (strncmp(libcfs_nid2str(nid), "127.0.0.1",
346 strlen("127.0.0.1")) == 0) {
348 "%s: The NID '%s' resolves to the loopback address '%s'. Lustre requires a non-loopback address.\n",
349 progname, s1, libcfs_nid2str(nid));
354 c += snprintf(c, left, "%s%c", libcfs_nid2str(nid), sep);
355 left = converted + MAXNIDSTR - c;
361 int parse_opts(int argc, char *const argv[], struct mkfs_opts *mop,
362 char **mountopts, char *old_fsname)
364 static struct option long_opts[] = {
365 { .val = 'B', .name = "backfs-mount-opts",
366 .has_arg = required_argument},
367 { .val = 'f', .name = "failnode", .has_arg = required_argument},
368 { .val = 'f', .name = "failover", .has_arg = required_argument},
369 { .val = 'G', .name = "mgs", .has_arg = no_argument},
370 { .val = 'h', .name = "help", .has_arg = no_argument},
371 { .val = 'i', .name = "index", .has_arg = required_argument},
372 { .val = 'L', .name = "fsname", .has_arg = required_argument},
373 { .val = 'm', .name = "mgsnode", .has_arg = required_argument},
374 { .val = 'm', .name = "mgsnid", .has_arg = required_argument},
375 { .val = 'n', .name = "dryrun", .has_arg = no_argument},
376 { .val = 'N', .name = "nomgs", .has_arg = no_argument},
377 { .val = 'o', .name = "mountfsoptions",
378 .has_arg = required_argument},
379 { .val = 'p', .name = "param", .has_arg = required_argument},
380 { .val = 'q', .name = "quiet", .has_arg = no_argument},
381 { .val = 's', .name = "servicenode", .has_arg = required_argument},
382 { .val = 't', .name = "network", .has_arg = required_argument},
383 { .val = 'u', .name = "comment", .has_arg = required_argument},
384 { .val = 'U', .name = "force-nohostid",
385 .has_arg = no_argument},
386 { .val = 'v', .name = "verbose", .has_arg = no_argument},
387 { .val = 'V', .name = "version", .has_arg = no_argument},
389 { .val = 'b', .name = "backfstype", .has_arg = required_argument},
390 { .val = 'c', .name = "stripe-count-hint",
391 .has_arg = required_argument},
392 { .val = 'd', .name = "device-size", .has_arg = required_argument},
393 { .val = 'k', .name = "mkfsoptions", .has_arg = required_argument},
394 { .val = 'M', .name = "mdt", .has_arg = no_argument},
395 { .val = 'O', .name = "ost", .has_arg = no_argument},
396 { .val = 'r', .name = "reformat", .has_arg = no_argument},
397 { .val = 'R', .name = "replace", .has_arg = no_argument},
399 { .val = 'E', .name = "erase-param", .has_arg = required_argument},
400 { .val = 'e', .name = "erase-params",
401 .has_arg = no_argument},
402 { .val = 'Q', .name = "quota", .has_arg = no_argument},
403 { .val = 'R', .name = "rename", .has_arg = optional_argument},
404 { .val = 'w', .name = "writeconf", .has_arg = no_argument},
407 char *short_opts = "B:f:Ghi:L:m:nNo:p:qs:t:u:vV"
413 struct lustre_disk_data *ldd = &mop->mo_ldd;
414 char new_fsname[16] = { 0 };
417 int failnode_set = 0, servicenode_set = 0;
419 bool index_option = false;
423 * For the right semantics, if '-e'/'--erase-params' is specified,
424 * it must be picked out and all old parameters should be erased
425 * before any other changes are done.
427 while ((opt = getopt_long(argc, argv, short_opts, long_opts,
431 ldd->ldd_params[0] = '\0';
432 mop->mo_flags |= MO_ERASE_ALL;
433 ldd->ldd_flags |= LDD_F_UPDATE;
438 if (mop->mo_flags & MO_ERASE_ALL)
443 while ((opt = getopt_long(argc, argv, short_opts, long_opts,
447 mop->mo_mountopts = optarg;
453 if ((opt == 'f' && servicenode_set) ||
454 (opt == 's' && failnode_set)) {
455 fprintf(stderr, "%s: %s cannot use with --%s\n",
456 progname, long_opts[longidx].name,
457 opt == 'f' ? "servicenode" :
462 nids = convert_hostnames(optarg);
466 rc = append_param(ldd->ldd_params, PARAM_FAILNODE,
472 /* Must update the mgs logs */
473 ldd->ldd_flags |= LDD_F_UPDATE;
475 ldd->ldd_flags &= ~LDD_F_NO_PRIMNODE;
478 ldd->ldd_flags |= LDD_F_NO_PRIMNODE;
481 mop->mo_flags |= MO_FAILOVER;
485 ldd->ldd_flags |= LDD_F_SV_TYPE_MGS;
495 /* LU-2374: check whether it is OST/MDT later */
496 base = (strlen(optarg) > 1 &&
497 !strncmp(optarg, "0x", 2)) ? 16 : 10;
498 /* Allowed input are base 16 and base 10 numbers only */
499 mop->mo_ldd.ldd_svindex = strtoul(optarg,
501 if (*endptr != '\0') {
503 "%s: wrong index %s. Target index must be decimal or hexadecimal.\n",
507 if (ldd->ldd_svindex >= INDEX_UNASSIGNED) {
509 "%s: wrong index %u. Target index must be less than %u.\n",
510 progname, ldd->ldd_svindex,
515 ldd->ldd_flags &= ~LDD_F_NEED_INDEX;
522 len = strlen(optarg);
523 if (len < 1 || len > LUSTRE_MAXFSNAME) {
525 "%s: filesystem name must be 1-%d chars\n",
526 progname, LUSTRE_MAXFSNAME);
530 for (tmp = optarg; *tmp != '\0'; ++tmp) {
531 if (isalnum(*tmp) || *tmp == '_' || *tmp == '-')
538 "%s: char '%c' not allowed in filesystem name\n",
542 strscpy(new_fsname, optarg, sizeof(new_fsname));
546 char *nids = convert_hostnames(optarg);
551 rc = append_param(ldd->ldd_params, PARAM_MGSNODE,
557 mop->mo_mgs_failnodes++;
564 ldd->ldd_flags &= ~LDD_F_SV_TYPE_MGS;
572 * Removes all existing instances of the parameter
573 * before adding new values.
575 rc = erase_param(ldd->ldd_params, optarg, true);
579 rc = add_param(ldd->ldd_params, NULL, optarg);
582 /* Must update the mgs logs */
583 ldd->ldd_flags |= LDD_F_UPDATE;
589 if (!IS_MDT(ldd) && !IS_OST(ldd)) {
590 badopt(long_opts[longidx].name, "MDT,OST");
597 rc = add_param(ldd->ldd_params, PARAM_NETWORK, optarg);
601 /* Must update the mgs logs */
602 ldd->ldd_flags |= LDD_F_UPDATE;
605 strscpy(ldd->ldd_userdata, optarg,
606 sizeof(ldd->ldd_userdata));
609 mop->mo_flags |= MO_NOHOSTID_CHECK;
616 fprintf(stdout, "%s %s\n", progname,
617 LUSTRE_VERSION_STRING);
624 if (strcmp(optarg, mt_str(i)) == 0) {
625 ldd->ldd_mount_type = i;
628 } while (++i < LDD_MT_LAST);
630 if (i == LDD_MT_LAST) {
632 "%s: invalid backend filesystem type %s\n",
640 int stripe_count = atol(optarg);
642 if (stripe_count <= 0) {
644 "%s: bad stripe count %s\n",
648 mop->mo_stripe_count = stripe_count;
650 badopt(long_opts[longidx].name, "MDT");
655 mop->mo_device_kb = atol(optarg);
658 strscpy(mop->mo_mkfsopts, optarg,
659 sizeof(mop->mo_mkfsopts));
662 ldd->ldd_flags |= LDD_F_SV_TYPE_MDT;
665 ldd->ldd_flags |= LDD_F_SV_TYPE_OST;
668 mop->mo_flags |= MO_FORCEFORMAT;
675 rc = erase_param(ldd->ldd_params, optarg, false);
677 * (rc == 1) means not found, so don't need to
678 * call osd_erase_ldd().
683 rc = osd_erase_ldd(mop, optarg);
687 /* Must update the mgs logs */
688 ldd->ldd_flags |= LDD_F_UPDATE;
691 /* Already done in the beginning */
694 mop->mo_flags |= MO_QUOTA;
699 mop->mo_flags |= MO_RENAME;
701 if (IS_SEPARATED_MGS(ldd)) {
703 "%s: must specify the old fsname to be renamed for separated MGS\n",
710 if ((strlen(optarg) < 1) || (strlen(optarg) > 8)) {
712 "%s: filesystem name must be 1-8 chars\n",
717 tmp = strpbrk(optarg, "/:");
720 "%s: char '%c' not allowed in filesystem name\n",
725 if (IS_SEPARATED_MGS(ldd)) {
726 strscpy(old_fsname, optarg,
727 sizeof(ldd->ldd_fsname));
728 } else if (strlen(old_fsname) != strlen(optarg) ||
729 strcmp(old_fsname, optarg) != 0) {
731 "%s: the given fsname '%s' to be renamed does not exist\n",
738 ldd->ldd_flags |= LDD_F_WRITECONF;
744 fprintf(stderr, "Unknown option '%c'\n", opt);
750 if (strlen(new_fsname) > 0) {
751 if (!(mop->mo_flags & (MO_FORCEFORMAT | MO_RENAME)) &&
752 (!(ldd->ldd_flags & (LDD_F_VIRGIN | LDD_F_WRITECONF)))) {
754 "%s: cannot change the name of a registered target\n",
759 strscpy(ldd->ldd_fsname, new_fsname, sizeof(ldd->ldd_fsname));
762 if (index_option && !(mop->mo_ldd.ldd_flags &
763 (LDD_F_VIRGIN | LDD_F_WRITECONF))) {
765 "%s: cannot change the index of a registered target\n",
771 if (mop->mo_flags & MO_RENAME) {
772 if (new_fsname[0] == '\0') {
774 "%s: need to specify new fsname for renaming case\n",
779 if (strcmp(old_fsname, new_fsname) == 0) {
781 "%s: cannot rename fsname '%s' to the same name\n",
782 progname, old_fsname);
788 /* Need to clear this flag after parsing 'L' and 'i' options. */
790 ldd->ldd_flags &= ~LDD_F_VIRGIN;
792 if (optind == argc) {
793 /* The user didn't specify device name */
796 "Not enough arguments - device name or pool/dataset name not specified.\n");
800 /* The device or pool/filesystem name */
801 strscpy(mop->mo_device, argv[optind], sizeof(mop->mo_device));
803 /* Followed by optional vdevs */
804 if (optind < argc - 1)
805 mop->mo_pool_vdevs = (char **)&argv[optind + 1];
810 int main(int argc, char *const argv[])
812 struct mkfs_opts mop;
813 struct lustre_disk_data *ldd = &mop.mo_ldd;
814 char *mountopts = NULL;
815 char wanted_mountopts[512] = "";
816 char old_fsname[16] = "";
817 unsigned int mount_type;
821 progname = strrchr(argv[0], '/');
827 if ((argc < 2) || (argv[argc - 1][0] == '-')) {
832 memset(&mop, 0, sizeof(mop));
835 /* device is last arg */
836 strscpy(mop.mo_device, argv[argc - 1], sizeof(mop.mo_device));
844 * For tunefs, we must read in the old values before parsing any
848 /* Check whether the disk has already been formatted by mkfs.lustre */
849 ret = osd_is_lustre(mop.mo_device, &mount_type);
853 "Device %s has not been formatted with mkfs.lustre\n",
858 ldd->ldd_mount_type = mount_type;
860 ret = osd_read_ldd(mop.mo_device, ldd);
864 "Failed to read previous Lustre data from %s (%d)\n",
869 strscpy(old_fsname, ldd->ldd_fsname, sizeof(ldd->ldd_fsname));
870 ldd->ldd_flags &= ~(LDD_F_WRITECONF | LDD_F_VIRGIN);
872 /* svname of the form lustre:OST1234 means never registered */
873 ret = strlen(ldd->ldd_svname);
874 if (ldd->ldd_svname[ret - 8] == ':') {
875 ldd->ldd_svname[ret - 8] = '-';
876 ldd->ldd_flags |= LDD_F_VIRGIN;
877 } else if (ldd->ldd_svname[ret - 8] == '=') {
878 ldd->ldd_svname[ret - 8] = '-';
879 ldd->ldd_flags |= LDD_F_WRITECONF;
882 if (strstr(ldd->ldd_params, PARAM_MGSNODE))
883 mop.mo_mgs_failnodes++;
886 print_ldd("Read previous values", &mop);
889 ret = parse_opts(argc, argv, &mop, &mountopts, old_fsname);
890 if (ret != 0 || version)
893 if (!IS_MDT(ldd) && !IS_OST(ldd) && !IS_MGS(ldd)) {
895 fprintf(stderr, "must set target type: MDT,OST,MGS\n");
900 if (((IS_MDT(ldd) || IS_MGS(ldd))) && IS_OST(ldd)) {
902 fprintf(stderr, "OST type is exclusive with MDT,MGS\n");
907 /* Stand alone MGS doesn't need an index */
908 if (!IS_MDT(ldd) && IS_MGS(ldd)) {
910 /* But if --index was specified flag an error */
911 if (!(ldd->ldd_flags & LDD_F_NEED_INDEX)) {
912 badopt("index", "MDT,OST");
916 ldd->ldd_flags &= ~LDD_F_NEED_INDEX;
919 if (ldd->ldd_flags & LDD_F_NEED_INDEX)
921 "warning: %s: for Lustre 2.4 and later, the target index must be specified with --index\n",
924 /* If no index is supplied for MDT by default set index to zero */
925 if (IS_MDT(ldd) && (ldd->ldd_svindex == INDEX_UNASSIGNED)) {
926 ldd->ldd_flags &= ~LDD_F_NEED_INDEX;
927 ldd->ldd_svindex = 0;
930 if (!IS_MGS(ldd) && (mop.mo_mgs_failnodes == 0)) {
933 * Don't check --mgs or --mgsnode if print_only is set or
934 * --erase-params is set.
936 if (!IS_MGS(ldd) && (mop.mo_mgs_failnodes == 0) && !print_only &&
937 !(mop.mo_flags & MO_ERASE_ALL)) {
941 fprintf(stderr, "Must specify --mgs or --mgsnode\n");
943 fprintf(stderr, "Must specify --mgsnode\n");
947 if ((IS_MDT(ldd) || IS_OST(ldd)) && ldd->ldd_fsname[0] == '\0') {
949 fprintf(stderr, "Must specify --fsname for MDT/OST device\n");
954 /* These are the permanent mount options (always included) */
955 ret = osd_prepare_lustre(&mop,
956 wanted_mountopts, sizeof(wanted_mountopts));
959 fprintf(stderr, "unable to prepare backend (%d)\n", ret);
964 trim_mountfsoptions(mountopts);
965 if (check_mountfsoptions(mountopts, wanted_mountopts)) {
969 snprintf(ldd->ldd_mount_opts, sizeof(ldd->ldd_mount_opts),
973 if (ldd->ldd_mount_opts[0] == 0)
974 /* use the defaults unless old opts exist */
977 snprintf(ldd->ldd_mount_opts,
978 sizeof(ldd->ldd_mount_opts),
979 "%s", wanted_mountopts);
980 trim_mountfsoptions(ldd->ldd_mount_opts);
984 ret = osd_fix_mountopts(&mop, ldd->ldd_mount_opts,
985 sizeof(ldd->ldd_mount_opts));
988 fprintf(stderr, "unable to fix mountfsoptions (%d)\n", ret);
992 if (server_make_name(ldd->ldd_flags, ldd->ldd_svindex,
993 ldd->ldd_fsname, ldd->ldd_svname,
994 sizeof(ldd->ldd_svname))) {
995 printf("unknown server type %#x\n", ldd->ldd_flags);
1000 print_ldd("Permanent disk data", &mop);
1003 printf("exiting before disk write.\n");
1007 if (check_mtab_entry(mop.mo_device, mop.mo_device, NULL, NULL))
1010 /* Create the loopback file */
1011 if (mop.mo_flags & MO_IS_LOOP) {
1012 ret = access(mop.mo_device, F_OK);
1017 /* Reformat the loopback file */
1018 if (ret != 0 || (mop.mo_flags & MO_FORCEFORMAT)) {
1019 ret = loop_format(&mop);
1025 ret = loop_setup(&mop);
1028 fprintf(stderr, "Loop device setup for %s failed: %s\n",
1029 mop.mo_device, strerror(ret));
1035 /* Check whether the disk has already been formatted by mkfs.lustre */
1036 if (!(mop.mo_flags & MO_FORCEFORMAT)) {
1037 ret = osd_is_lustre(mop.mo_device, &mount_type);
1041 "Device %s was previously formatted for lustre. Use --reformat to reformat it, or tunefs.lustre to modify.\n",
1047 /* Format the backing filesystem */
1048 ret = osd_make_lustre(&mop);
1051 fprintf(stderr, "mkfs failed %d\n", ret);
1055 /* update svname with '=' to refresh config */
1056 if (ldd->ldd_flags & LDD_F_WRITECONF) {
1057 struct mount_opts opts;
1060 opts.mo_source = mop.mo_device;
1061 (void)osd_label_lustre(&opts);
1064 /* Rename filesystem fsname */
1065 if (mop.mo_flags & MO_RENAME) {
1066 ret = osd_rename_fsname(&mop, old_fsname);
1071 /* Enable quota accounting */
1072 if (mop.mo_flags & MO_QUOTA) {
1073 ret = osd_enable_quota(&mop);
1076 #endif /* !TUNEFS */
1078 /* Write our config files */
1079 ret = osd_write_ldd(&mop);
1082 fprintf(stderr, "failed to write local files\n");
1087 ret2 = loop_cleanup(&mop);
1091 /* Fix any crazy return values from system() */
1092 if (ret != 0 && ((ret & 255) == 0))
1096 verrprint("%s: exiting with %d (%s)\n",
1097 progname, ret, strerror(ret));