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.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2011, Whamcloud, Inc.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lustre/utils/mkfs_lustre.c
38 * Author: Nathan Rutman <nathan@clusterfs.com>
41 /* This source file is compiled into both mkfs.lustre and tunefs.lustre */
45 #endif /* HAVE_CONFIG_H */
57 #include <sys/types.h>
59 #include <sys/mount.h>
60 #include <sys/utsname.h>
68 /* libcfs.h is not really needed here, but on SLES10/PPC, fs.h includes idr.h
69 * which requires BITS_PER_LONG to be defined */
70 #include <libcfs/libcfs.h>
72 #include <linux/fs.h> /* for BLKGETSIZE64 */
74 #include <linux/version.h>
76 #include <lustre_disk.h>
77 #include <lustre_param.h>
78 #include <lnet/lnetctl.h>
79 #include <lustre_ver.h>
80 #include "mount_utils.h"
88 static int print_only = 0;
89 static int upgrade_to_18 = 0;
93 fprintf(out, "%s v"LUSTRE_VERSION_STRING"\n", progname);
94 fprintf(out, "usage: %s <target types> [options] <device>\n", progname);
96 "\t<device>:block device or file (e.g /dev/sda or /tmp/ost1)\n"
98 "\t\t--ost: object storage, mutually exclusive with mdt,mgs\n"
99 "\t\t--mdt: metadata storage, mutually exclusive with ost\n"
100 "\t\t--mgs: configuration management service - one per site\n"
101 "\toptions (in order of popularity):\n"
102 "\t\t--mgsnode=<nid>[,<...>] : NID(s) of a remote mgs node\n"
103 "\t\t\trequired for all targets other than the mgs node\n"
104 "\t\t--fsname=<filesystem_name> : default is 'lustre'\n"
105 "\t\t--failnode=<nid>[,<...>] : NID(s) of a failover partner\n"
106 "\t\t\tcannot be used with --servicenode\n"
107 "\t\t--servicenode=<nid>[,<...>] : NID(s) of all service partners\n"
108 "\t\t\ttreat all nodes as equal service node, cannot be used with --failnode\n"
109 "\t\t--param <key>=<value> : set a permanent parameter\n"
110 "\t\t\te.g. --param sys.timeout=40\n"
111 "\t\t\t --param lov.stripesize=2M\n"
112 "\t\t--index=#N : target index (i.e. ost index within lov)\n"
113 "\t\t--comment=<user comment>: arbitrary string (%d bytes)\n"
114 "\t\t--mountfsoptions=<opts> : permanent mount options\n"
115 "\t\t--network=<net>[,<...>] : restrict OST/MDT to network(s)\n"
117 "\t\t--backfstype=<fstype> : backing fs type (ext3, ldiskfs)\n"
118 "\t\t--device-size=#N(KB) : device size for loop devices\n"
119 "\t\t--mkfsoptions=<opts> : format options\n"
120 "\t\t--reformat: overwrite an existing disk\n"
121 "\t\t--stripe-count-hint=#N : for optimizing MDT inode size\n"
122 "\t\t--iam-dir: use IAM directory format, not ext3 compatible\n"
124 "\t\t--erase-params : erase all old parameter settings\n"
125 "\t\t--nomgs: turn off MGS service on this MDT\n"
126 "\t\t--writeconf: erase all config logs for this fs.\n"
128 "\t\t--dryrun: just report what we would do; "
129 "don't write to disk\n"
130 "\t\t--verbose : e.g. show mkfs progress\n"
132 (int)sizeof(((struct lustre_disk_data *)0)->ldd_userdata));
136 /*================ utility functions =====================*/
138 char *strscat(char *dst, char *src, int buflen) {
140 if (strlen(dst) + strlen(src) >= buflen) {
141 fprintf(stderr, "string buffer overflow (max %d): '%s' + '%s'"
142 "\n", buflen, dst, src);
145 return strcat(dst, src);
149 char *strscpy(char *dst, char *src, int buflen) {
151 return strscat(dst, src, buflen);
155 dev_major (unsigned long long int __dev)
157 return ((__dev >> 8) & 0xfff) | ((unsigned int) (__dev >> 32) & ~0xfff);
161 dev_minor (unsigned long long int __dev)
163 return (__dev & 0xff) | ((unsigned int) (__dev >> 12) & ~0xff);
168 static int version = 0;
172 char release[4] = "";
174 fd = open("/proc/sys/kernel/osrelease", O_RDONLY);
176 fprintf(stderr, "%s: Warning: Can't resolve kernel "
177 "version, assuming 2.6\n", progname);
179 if (read(fd, release, 4) < 0) {
180 fprintf(stderr, "reading from /proc/sys/kernel"
181 "/osrelease: %s\n", strerror(errno));
187 if (strncmp(release, "2.4.", 4) == 0)
195 static int check_mtab_entry(char *spec)
200 fp = setmntent(MOUNTED, "r");
204 while ((mnt = getmntent(fp)) != NULL) {
205 if (strcmp(mnt->mnt_fsname, spec) == 0) {
207 fprintf(stderr, "%s: according to %s %s is "
208 "already mounted on %s\n",
209 progname, MOUNTED, spec, mnt->mnt_dir);
218 /*============ disk dev functions ===================*/
220 /* Setup a file in the first unused loop_device */
221 int loop_setup(struct mkfs_opts *mop)
227 /* Figure out the loop device names */
228 if (!access("/dev/loop0", F_OK | R_OK)) {
229 strcpy(loop_base, "/dev/loop\0");
230 } else if (!access("/dev/loop/0", F_OK | R_OK)) {
231 strcpy(loop_base, "/dev/loop/\0");
233 fprintf(stderr, "%s: can't access loop devices\n", progname);
237 /* Find unused loop device */
238 for (i = 0; i < MAX_LOOP_DEVICES; i++) {
240 int cmdsz = sizeof(cmd);
242 sprintf(l_device, "%s%d", loop_base, i);
243 if (access(l_device, F_OK | R_OK))
245 snprintf(cmd, cmdsz, "losetup %s > /dev/null 2>&1", l_device);
248 /* losetup gets 1 (ret=256) for non-set-up device */
250 /* Set up a loopback device to our file */
251 snprintf(cmd, cmdsz, "losetup %s %s", l_device,
253 ret = run_command(cmd, cmdsz);
255 /* someone else picked up this loop device
259 fprintf(stderr, "%s: error %d on losetup: %s\n",
260 progname, ret, strerror(ret));
263 strscpy(mop->mo_loopdev, l_device,
264 sizeof(mop->mo_loopdev));
269 fprintf(stderr, "%s: out of loop devices!\n", progname);
273 int loop_cleanup(struct mkfs_opts *mop)
277 if ((mop->mo_flags & MO_IS_LOOP) && *mop->mo_loopdev) {
278 sprintf(cmd, "losetup -d %s", mop->mo_loopdev);
279 ret = run_command(cmd, sizeof(cmd));
284 __u64 get_device_size(char* device)
289 fd = open(device, O_RDONLY);
291 fprintf(stderr, "%s: cannot open %s: %s\n",
292 progname, device, strerror(errno));
297 /* size in bytes. bz5831 */
298 ret = ioctl(fd, BLKGETSIZE64, (void*)&size);
303 ret = ioctl(fd, BLKGETSIZE, (void*)&lsize);
304 size = (__u64)lsize * 512;
309 fprintf(stderr, "%s: size ioctl failed: %s\n",
310 progname, strerror(errno));
314 vprint("device size = "LPU64"MB\n", size >> 20);
315 /* return value in KB */
319 int loop_format(struct mkfs_opts *mop)
323 if (mop->mo_device_sz == 0) {
325 fprintf(stderr, "loop device requires a --device-size= "
330 fd = creat(mop->mo_device, S_IRUSR|S_IWUSR);
333 fprintf(stderr, "%s: Unable to create backing store: %s\n",
334 progname, strerror(errno));
338 if (ftruncate(fd, mop->mo_device_sz * 1024) != 0) {
341 fprintf(stderr, "%s: Unable to truncate backing store: %s\n",
342 progname, strerror(errno));
350 /* ==================== Lustre config functions =============*/
352 void print_ldd(char *str, struct lustre_disk_data *ldd)
354 printf("\n %s:\n", str);
355 printf("Target: %s\n", ldd->ldd_svname);
356 if (ldd->ldd_svindex == INDEX_UNASSIGNED)
357 printf("Index: unassigned\n");
359 printf("Index: %d\n", ldd->ldd_svindex);
360 if (ldd->ldd_uuid[0])
361 printf("UUID: %s\n", (char *)ldd->ldd_uuid);
362 printf("Lustre FS: %s\n", ldd->ldd_fsname);
363 printf("Mount type: %s\n", MT_STR(ldd));
364 printf("Flags: %#x\n", ldd->ldd_flags);
365 printf(" (%s%s%s%s%s%s%s%s%s%s)\n",
366 IS_MDT(ldd) ? "MDT ":"",
367 IS_OST(ldd) ? "OST ":"",
368 IS_MGS(ldd) ? "MGS ":"",
369 ldd->ldd_flags & LDD_F_NEED_INDEX ? "needs_index ":"",
370 ldd->ldd_flags & LDD_F_VIRGIN ? "first_time ":"",
371 ldd->ldd_flags & LDD_F_UPDATE ? "update ":"",
372 ldd->ldd_flags & LDD_F_WRITECONF ? "writeconf ":"",
373 ldd->ldd_flags & LDD_F_IAM_DIR ? "IAM_dir_format ":"",
374 ldd->ldd_flags & LDD_F_NO_PRIMNODE? "no_primnode ":"",
375 ldd->ldd_flags & LDD_F_UPGRADE14 ? "upgrade1.4 ":"");
376 printf("Persistent mount opts: %s\n", ldd->ldd_mount_opts);
377 printf("Parameters:%s\n", ldd->ldd_params);
378 if (ldd->ldd_userdata[0])
379 printf("Comment: %s\n", ldd->ldd_userdata);
383 void set_defaults(struct mkfs_opts *mop)
385 mop->mo_ldd.ldd_magic = LDD_MAGIC;
386 mop->mo_ldd.ldd_config_ver = 1;
387 mop->mo_ldd.ldd_flags = LDD_F_NEED_INDEX | LDD_F_UPDATE | LDD_F_VIRGIN;
388 mop->mo_mgs_failnodes = 0;
389 strcpy(mop->mo_ldd.ldd_fsname, "lustre");
390 mop->mo_ldd.ldd_mount_type = LDD_MT_LDISKFS;
392 mop->mo_ldd.ldd_svindex = INDEX_UNASSIGNED;
393 mop->mo_stripe_count = 1;
396 static inline void badopt(const char *opt, char *type)
398 fprintf(stderr, "%s: '--%s' only valid for %s\n",
399 progname, opt, type);
403 int add_param(char *buf, char *key, char *val)
405 int end = sizeof(((struct lustre_disk_data *)0)->ldd_params);
406 int start = strlen(buf);
410 keylen = strlen(key);
411 if (start + 1 + keylen + strlen(val) >= end) {
412 fprintf(stderr, "%s: params are too long-\n%s %s%s\n",
413 progname, buf, key ? key : "", val);
417 sprintf(buf + start, " %s%s", key ? key : "", val);
421 /* from mount_lustre */
422 /* Get rid of symbolic hostnames for tcp, since kernel can't do lookups */
423 #define MAXNIDSTR 1024
424 static char *convert_hostnames(char *s1)
426 char *converted, *s2 = 0, *c, *end, sep;
427 int left = MAXNIDSTR;
430 converted = malloc(left);
431 if (converted == NULL) {
435 end = s1 + strlen(s1);
437 while ((left > 0) && (s1 < end)) {
438 s2 = strpbrk(s1, ",:");
443 nid = libcfs_str2nid(s1);
445 if (nid == LNET_NID_ANY) {
446 fprintf(stderr, "%s: Can't parse NID '%s'\n",
451 if (strncmp(libcfs_nid2str(nid), "127.0.0.1",
452 strlen("127.0.0.1")) == 0) {
453 fprintf(stderr, "%s: The NID '%s' resolves to the "
454 "loopback address '%s'. Lustre requires a "
455 "non-loopback address.\n",
456 progname, s1, libcfs_nid2str(nid));
461 c += snprintf(c, left, "%s%c", libcfs_nid2str(nid), sep);
462 left = converted + MAXNIDSTR - c;
468 int parse_opts(int argc, char *const argv[], struct mkfs_opts *mop,
471 static struct option long_opt[] = {
472 {"iam-dir", 0, 0, 'a'},
473 {"backfstype", 1, 0, 'b'},
474 {"stripe-count-hint", 1, 0, 'c'},
475 {"comment", 1, 0, 'u'},
476 {"configdev", 1, 0, 'C'},
477 {"device-size", 1, 0, 'd'},
478 {"dryrun", 0, 0, 'n'},
479 {"erase-params", 0, 0, 'e'},
480 {"failnode", 1, 0, 'f'},
481 {"failover", 1, 0, 'f'},
484 {"index", 1, 0, 'i'},
485 {"mkfsoptions", 1, 0, 'k'},
486 {"mgsnode", 1, 0, 'm'},
487 {"mgsnid", 1, 0, 'm'},
489 {"fsname",1, 0, 'L'},
490 {"noformat", 0, 0, 'n'},
491 {"nomgs", 0, 0, 'N'},
492 {"mountfsoptions", 1, 0, 'o'},
494 {"param", 1, 0, 'p'},
495 {"print", 0, 0, 'n'},
496 {"quiet", 0, 0, 'q'},
497 {"reformat", 0, 0, 'r'},
498 {"servicenode", 1, 0, 's'},
499 {"verbose", 0, 0, 'v'},
500 {"writeconf", 0, 0, 'w'},
501 {"upgrade_to_18", 0, 0, 'U'},
502 {"network", 1, 0, 't'},
505 char *optstring = "b:c:C:d:ef:Ghi:k:L:m:MnNo:Op:Pqrs:t:Uu:vw";
508 int failnode_set = 0, servicenode_set = 0;
510 while ((opt = getopt_long(argc, argv, optstring, long_opt, &longidx)) !=
514 if (IS_MDT(&mop->mo_ldd))
515 mop->mo_ldd.ldd_flags |= LDD_F_IAM_DIR;
520 while (i < LDD_MT_LAST) {
521 if (strcmp(optarg, mt_str(i)) == 0) {
522 mop->mo_ldd.ldd_mount_type = i;
530 if (IS_MDT(&mop->mo_ldd)) {
531 int stripe_count = atol(optarg);
532 if (stripe_count <= 0) {
533 fprintf(stderr, "%s: bad stripe count "
534 "%d\n", progname, stripe_count);
537 mop->mo_stripe_count = stripe_count;
539 badopt(long_opt[longidx].name, "MDT");
543 case 'C': /* Configdev */
545 printf("Configdev not implemented\n");
548 mop->mo_device_sz = atol(optarg);
551 mop->mo_ldd.ldd_params[0] = '\0';
552 /* Must update the mgs logs */
553 mop->mo_ldd.ldd_flags |= LDD_F_UPDATE;
559 if ((opt == 'f' && servicenode_set)
560 || (opt == 's' && failnode_set)) {
561 fprintf(stderr, "%s: %s cannot use with --%s\n",
562 progname, long_opt[longidx].name,
563 opt == 'f' ? "servicenode" : "failnode");
567 nids = convert_hostnames(optarg);
570 rc = add_param(mop->mo_ldd.ldd_params, PARAM_FAILNODE,
575 /* Must update the mgs logs */
576 mop->mo_ldd.ldd_flags |= LDD_F_UPDATE;
580 mop->mo_ldd.ldd_flags |= LDD_F_NO_PRIMNODE;
583 mop->mo_flags |= MO_FAILOVER;
587 mop->mo_ldd.ldd_flags |= LDD_F_SV_TYPE_MGS;
593 if (!(mop->mo_ldd.ldd_flags &
594 (LDD_F_UPGRADE14 | LDD_F_VIRGIN |
596 fprintf(stderr, "%s: cannot change the index of"
597 " a registered target\n", progname);
600 if (IS_MDT(&mop->mo_ldd) || IS_OST(&mop->mo_ldd)) {
601 mop->mo_ldd.ldd_svindex = atol(optarg);
602 mop->mo_ldd.ldd_flags &= ~LDD_F_NEED_INDEX;
604 badopt(long_opt[longidx].name, "MDT,OST");
609 strscpy(mop->mo_mkfsopts, optarg,
610 sizeof(mop->mo_mkfsopts));
614 if (!(mop->mo_flags & MO_FORCEFORMAT) &&
615 (!(mop->mo_ldd.ldd_flags &
616 (LDD_F_UPGRADE14 | LDD_F_VIRGIN |
617 LDD_F_WRITECONF)))) {
618 fprintf(stderr, "%s: cannot change the name of"
619 " a registered target\n", progname);
622 if ((strlen(optarg) < 1) || (strlen(optarg) > 8)) {
623 fprintf(stderr, "%s: filesystem name must be "
624 "1-8 chars\n", progname);
627 if ((tmp = strpbrk(optarg, "/:"))) {
628 fprintf(stderr, "%s: char '%c' not allowed in "
629 "filesystem name\n", progname, *tmp);
632 strscpy(mop->mo_ldd.ldd_fsname, optarg,
633 sizeof(mop->mo_ldd.ldd_fsname));
637 char *nids = convert_hostnames(optarg);
640 rc = add_param(mop->mo_ldd.ldd_params, PARAM_MGSNODE,
645 mop->mo_mgs_failnodes++;
649 mop->mo_ldd.ldd_flags |= LDD_F_SV_TYPE_MDT;
655 mop->mo_ldd.ldd_flags &= ~LDD_F_SV_TYPE_MGS;
661 mop->mo_ldd.ldd_flags |= LDD_F_SV_TYPE_OST;
664 rc = add_param(mop->mo_ldd.ldd_params, NULL, optarg);
667 /* Must update the mgs logs */
668 mop->mo_ldd.ldd_flags |= LDD_F_UPDATE;
674 mop->mo_flags |= MO_FORCEFORMAT;
677 if (!IS_MDT(&mop->mo_ldd) && !IS_OST(&mop->mo_ldd)) {
678 badopt(long_opt[longidx].name, "MDT,OST");
685 rc = add_param(mop->mo_ldd.ldd_params,
686 PARAM_NETWORK, optarg);
689 /* Must update the mgs logs */
690 mop->mo_ldd.ldd_flags |= LDD_F_UPDATE;
693 strscpy(mop->mo_ldd.ldd_userdata, optarg,
694 sizeof(mop->mo_ldd.ldd_userdata));
700 mop->mo_ldd.ldd_flags |= LDD_F_WRITECONF;
708 fprintf(stderr, "Unknown option '%c'\n", opt);
714 /* Last arg is device */
715 if (optind != argc - 1) {
717 fprintf(stderr, "Bad argument: %s\n", argv[optind]);
721 /* single argument: <device> */
728 /* Search for opt in mntlist, returning true if found.
730 static int in_mntlist(char *opt, char *mntlist)
732 char *ml, *mlp, *item, *ctx = NULL;
734 if (!(ml = strdup(mntlist))) {
735 fprintf(stderr, "%s: out of memory\n", progname);
739 while ((item = strtok_r(mlp, ",", &ctx))) {
740 if (!strcmp(opt, item))
745 return (item != NULL);
748 /* Issue a message on stderr for every item in wanted_mountopts that is not
749 * present in mountopts. The justwarn boolean toggles between error and
750 * warning message. Return an error count.
752 static int check_mountfsoptions(char *mountopts, char *wanted_mountopts,
755 char *ml, *mlp, *item, *ctx = NULL;
758 if (!(ml = strdup(wanted_mountopts))) {
759 fprintf(stderr, "%s: out of memory\n", progname);
763 while ((item = strtok_r(mlp, ",", &ctx))) {
764 if (!in_mntlist(item, mountopts)) {
765 fprintf(stderr, "%s: %s mount option `%s' is missing\n",
766 progname, justwarn ? "Warning: default"
767 : "Error: mandatory", item);
776 /* Trim embedded white space, leading and trailing commas from string s.
778 static void trim_mountfsoptions(char *s)
784 memmove(p, p + 1, strlen(p + 1) + 1);
791 memmove(&s[0], &s[1], strlen(&s[1]) + 1);
793 p = s + strlen(s) - 1;
794 while (p >= s && *p == ',')
798 int main(int argc, char *const argv[])
800 struct mkfs_opts mop;
801 struct lustre_disk_data *ldd;
802 char *mountopts = NULL;
803 char always_mountopts[512] = "";
804 char default_mountopts[512] = "";
807 if ((progname = strrchr(argv[0], '/')) != NULL)
812 if ((argc < 2) || (argv[argc - 1][0] == '-')) {
817 memset(&mop, 0, sizeof(mop));
820 /* device is last arg */
821 strscpy(mop.mo_device, argv[argc - 1], sizeof(mop.mo_device));
823 /* Are we using a loop device? */
824 ret = is_block(mop.mo_device);
830 mop.mo_flags |= MO_IS_LOOP;
833 /* For tunefs, we must read in the old values before parsing any
836 /* Check whether the disk has already been formatted by mkfs.lustre */
837 ret = is_lustre_target(&mop);
840 fprintf(stderr, "Device %s has not been formatted with "
841 "mkfs.lustre\n", mop.mo_device);
846 ret = read_local_files(&mop);
849 fprintf(stderr, "Failed to read previous Lustre data from %s "
850 "(%d)\n", mop.mo_device, ret);
853 if (strstr(mop.mo_ldd.ldd_params, PARAM_MGSNODE))
854 mop.mo_mgs_failnodes++;
857 print_ldd("Read previous values", &(mop.mo_ldd));
860 ret = parse_opts(argc, argv, &mop, &mountopts);
866 if (!(IS_MDT(ldd) || IS_OST(ldd) || IS_MGS(ldd))) {
868 fprintf(stderr, "must set target type: MDT,OST,MGS\n");
873 if (((IS_MDT(ldd) || IS_MGS(ldd))) && IS_OST(ldd)) {
875 fprintf(stderr, "OST type is exclusive with MDT,MGS\n");
880 if ((mop.mo_ldd.ldd_flags & (LDD_F_NEED_INDEX | LDD_F_UPGRADE14)) ==
881 (LDD_F_NEED_INDEX | LDD_F_UPGRADE14)) {
883 fprintf(stderr, "Can't find the target index, "
884 "specify with --index\n");
890 * Comment out these 2 checks temporarily, since for multi-MDSes
891 * in single node only 1 mds node could have mgs service
893 if (IS_MDT(ldd) && !IS_MGS(ldd) && (mop.mo_mgs_failnodes == 0)) {
894 verrprint("No management node specified, adding MGS to this "
896 ldd->ldd_flags |= LDD_F_SV_TYPE_MGS;
898 if (!IS_MGS(ldd) && (mop.mo_mgs_failnodes == 0)) {
901 fprintf(stderr, "Must specify --mgs or --mgsnode=\n");
903 fprintf(stderr, "Must specify --mgsnode=\n");
909 /* These are the permanent mount options (always included) */
910 switch (ldd->ldd_mount_type) {
913 case LDD_MT_LDISKFS2:
914 strscat(default_mountopts, ",errors=remount-ro",
915 sizeof(default_mountopts));
916 if (IS_MDT(ldd) || IS_MGS(ldd))
917 strscat(always_mountopts, ",user_xattr",
918 sizeof(always_mountopts));
919 /* NB: Files created while extents are enabled can only be read
920 * if mounted using the ext4 or ldiskfs filesystem type. */
922 (ldd->ldd_mount_type == LDD_MT_LDISKFS ||
923 ldd->ldd_mount_type == LDD_MT_LDISKFS2)) {
924 strscat(default_mountopts, ",extents,mballoc",
925 sizeof(default_mountopts));
930 fprintf(stderr, "unknown fs type %d '%s'\n",
938 trim_mountfsoptions(mountopts);
939 (void)check_mountfsoptions(mountopts, default_mountopts, 1);
940 if (check_mountfsoptions(mountopts, always_mountopts, 0)) {
944 sprintf(ldd->ldd_mount_opts, "%s", mountopts);
947 if (ldd->ldd_mount_opts[0] == 0)
948 /* use the defaults unless old opts exist */
951 sprintf(ldd->ldd_mount_opts, "%s%s",
952 always_mountopts, default_mountopts);
953 trim_mountfsoptions(ldd->ldd_mount_opts);
957 server_make_name(ldd->ldd_flags, ldd->ldd_svindex,
958 ldd->ldd_fsname, ldd->ldd_svname);
961 print_ldd("Permanent disk data", ldd);
964 printf("exiting before disk write.\n");
968 if (check_mtab_entry(mop.mo_device))
971 /* Create the loopback file */
972 if (mop.mo_flags & MO_IS_LOOP) {
973 ret = access(mop.mo_device, F_OK);
976 #ifndef TUNEFS /* mkfs.lustre */
977 /* Reformat the loopback file */
978 if (ret || (mop.mo_flags & MO_FORCEFORMAT)) {
979 ret = loop_format(&mop);
985 ret = loop_setup(&mop);
988 fprintf(stderr, "Loop device setup for %s failed: %s\n",
989 mop.mo_device, strerror(ret));
994 #ifndef TUNEFS /* mkfs.lustre */
995 /* Check whether the disk has already been formatted by mkfs.lustre */
996 if (!(mop.mo_flags & MO_FORCEFORMAT)) {
997 ret = is_lustre_target(&mop);
1000 fprintf(stderr, "Device %s was previously formatted "
1001 "for lustre. Use --reformat to reformat it, "
1002 "or tunefs.lustre to modify.\n",
1008 /* Format the backing filesystem */
1009 ret = make_lustre_backfs(&mop);
1012 fprintf(stderr, "mkfs failed %d\n", ret);
1017 /* Write our config files */
1018 ret = write_local_files(&mop);
1021 fprintf(stderr, "failed to write local files\n");
1028 /* Fix any crazy return values from system() */
1029 if (ret && ((ret & 255) == 0))
1032 verrprint("%s: exiting with %d (%s)\n",
1033 progname, ret, strerror(ret));