1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright 2008 Sun Microsystems, Inc. All rights reserved
30 * Use is subject to license terms.
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 which
69 * requires BITS_PER_LONG to be defined */
70 #include <libcfs/libcfs.h>
71 #include <linux/fs.h> /* for BLKGETSIZE64 */
72 #include <linux/version.h>
74 #include <lustre_disk.h>
75 #include <lustre_param.h>
76 #include <lnet/lnetctl.h>
77 #include <lustre_ver.h>
78 #include "mount_utils.h"
84 #define MAX_LOOP_DEVICES 16
85 #define L_BLOCK_SIZE 4096
86 #define INDEX_UNASSIGNED 0xFFFF
87 #define MO_IS_LOOP 0x01
88 #define MO_FORCEFORMAT 0x02
90 /* used to describe the options to format the lustre disk, not persistent */
92 struct lustre_disk_data mo_ldd; /* to be written in MOUNT_DATA_FILE */
93 char mo_device[128]; /* disk device name */
94 char mo_mkfsopts[128]; /* options to the backing-store mkfs */
95 char mo_loopdev[128]; /* in case a loop dev is needed */
96 __u64 mo_device_sz; /* in KB */
104 static int print_only = 0;
105 static int failover = 0;
106 static int upgrade_to_18 = 0;
108 void usage(FILE *out)
110 fprintf(out, "%s v"LUSTRE_VERSION_STRING"\n", progname);
111 fprintf(out, "usage: %s <target types> [options] <device>\n", progname);
113 "\t<device>:block device or file (e.g /dev/sda or /tmp/ost1)\n"
115 "\t\t--ost: object storage, mutually exclusive with mdt,mgs\n"
116 "\t\t--mdt: metadata storage, mutually exclusive with ost\n"
117 "\t\t--mgs: configuration management service - one per site\n"
118 "\toptions (in order of popularity):\n"
119 "\t\t--mgsnode=<nid>[,<...>] : NID(s) of a remote mgs node\n"
120 "\t\t\trequired for all targets other than the mgs node\n"
121 "\t\t--fsname=<filesystem_name> : default is 'lustre'\n"
122 "\t\t--failnode=<nid>[,<...>] : NID(s) of a failover partner\n"
123 "\t\t--param <key>=<value> : set a permanent parameter\n"
124 "\t\t\te.g. --param sys.timeout=40\n"
125 "\t\t\t --param lov.stripesize=2M\n"
126 "\t\t--index=#N : target index (i.e. ost index within the lov)\n"
127 /* FIXME implement 1.6.x
128 "\t\t--configdev=<altdevice|file>: store configuration info\n"
129 "\t\t\tfor this device on an alternate device\n"
131 "\t\t--comment=<user comment>: arbitrary user string (%d bytes)\n"
132 "\t\t--mountfsoptions=<opts> : permanent mount options\n"
134 "\t\t--backfstype=<fstype> : backing fs type (ext3, ldiskfs)\n"
135 "\t\t--device-size=#N(KB) : device size for loop devices\n"
136 "\t\t--mkfsoptions=<opts> : format options\n"
137 "\t\t--reformat: overwrite an existing disk\n"
138 "\t\t--stripe-count-hint=#N : used for optimizing MDT inode size\n"
139 "\t\t--iam-dir: make use of IAM directory format on backfs, incompatible with ext3.\n"
141 "\t\t--erase-params : erase all old parameter settings\n"
142 "\t\t--nomgs: turn off MGS service on this MDT\n"
143 "\t\t--writeconf: erase all config logs for this fs.\n"
145 "\t\t--dryrun: just report what we would do; "
146 "don't write to disk\n"
147 "\t\t--verbose : e.g. show mkfs progress\n"
149 (int)sizeof(((struct lustre_disk_data *)0)->ldd_userdata));
153 #define vprint if (verbose > 0) printf
154 #define verrprint if (verbose >= 0) printf
156 /*================ utility functions =====================*/
158 char *strscat(char *dst, char *src, int buflen) {
160 if (strlen(dst) + strlen(src) >= buflen) {
161 fprintf(stderr, "string buffer overflow (max %d): '%s' + '%s'"
162 "\n", buflen, dst, src);
165 return strcat(dst, src);
169 char *strscpy(char *dst, char *src, int buflen) {
171 return strscat(dst, src, buflen);
175 dev_major (unsigned long long int __dev)
177 return ((__dev >> 8) & 0xfff) | ((unsigned int) (__dev >> 32) & ~0xfff);
181 dev_minor (unsigned long long int __dev)
183 return (__dev & 0xff) | ((unsigned int) (__dev >> 12) & ~0xff);
188 static int version = 0;
192 char release[4] = "";
194 fd = open("/proc/sys/kernel/osrelease", O_RDONLY);
196 fprintf(stderr, "%s: Warning: Can't resolve kernel "
197 "version, assuming 2.6\n", progname);
199 if (read(fd, release, 4) < 0) {
200 fprintf(stderr, "reading from /proc/sys/kernel"
201 "/osrelease: %s\n", strerror(errno));
207 if (strncmp(release, "2.4.", 4) == 0)
215 static int check_mtab_entry(char *spec)
220 fp = setmntent(MOUNTED, "r");
224 while ((mnt = getmntent(fp)) != NULL) {
225 if (strcmp(mnt->mnt_fsname, spec) == 0) {
227 fprintf(stderr, "%s: according to %s %s is "
228 "already mounted on %s\n",
229 progname, MOUNTED, spec, mnt->mnt_dir);
238 /*============ disk dev functions ===================*/
240 /* Setup a file in the first unused loop_device */
241 int loop_setup(struct mkfs_opts *mop)
247 /* Figure out the loop device names */
248 if (!access("/dev/loop0", F_OK | R_OK)) {
249 strcpy(loop_base, "/dev/loop\0");
250 } else if (!access("/dev/loop/0", F_OK | R_OK)) {
251 strcpy(loop_base, "/dev/loop/\0");
253 fprintf(stderr, "%s: can't access loop devices\n", progname);
257 /* Find unused loop device */
258 for (i = 0; i < MAX_LOOP_DEVICES; i++) {
260 int cmdsz = sizeof(cmd);
262 sprintf(l_device, "%s%d", loop_base, i);
263 if (access(l_device, F_OK | R_OK))
265 snprintf(cmd, cmdsz, "losetup %s > /dev/null 2>&1", l_device);
268 /* losetup gets 1 (ret=256) for non-set-up device */
270 /* Set up a loopback device to our file */
271 snprintf(cmd, cmdsz, "losetup %s %s", l_device,
273 ret = run_command(cmd, cmdsz);
275 /* someone else picked up this loop device
279 fprintf(stderr, "%s: error %d on losetup: %s\n",
280 progname, ret, strerror(ret));
283 strscpy(mop->mo_loopdev, l_device,
284 sizeof(mop->mo_loopdev));
289 fprintf(stderr, "%s: out of loop devices!\n", progname);
293 int loop_cleanup(struct mkfs_opts *mop)
297 if ((mop->mo_flags & MO_IS_LOOP) && *mop->mo_loopdev) {
298 sprintf(cmd, "losetup -d %s", mop->mo_loopdev);
299 ret = run_command(cmd, sizeof(cmd));
304 /* Determine if a device is a block device (as opposed to a file) */
305 int is_block(char* devname)
310 ret = access(devname, F_OK);
313 ret = stat(devname, &st);
315 fprintf(stderr, "%s: cannot stat %s\n", progname, devname);
318 return S_ISBLK(st.st_mode);
321 __u64 get_device_size(char* device)
326 fd = open(device, O_RDONLY);
328 fprintf(stderr, "%s: cannot open %s: %s\n",
329 progname, device, strerror(errno));
334 /* size in bytes. bz5831 */
335 ret = ioctl(fd, BLKGETSIZE64, (void*)&size);
340 ret = ioctl(fd, BLKGETSIZE, (void*)&lsize);
341 size = (__u64)lsize * 512;
346 fprintf(stderr, "%s: size ioctl failed: %s\n",
347 progname, strerror(errno));
351 vprint("device size = "LPU64"MB\n", size >> 20);
352 /* return value in KB */
356 int loop_format(struct mkfs_opts *mop)
360 if (mop->mo_device_sz == 0) {
362 fprintf(stderr, "loop device requires a --device-size= "
367 ret = creat(mop->mo_device, S_IRUSR|S_IWUSR);
370 fprintf(stderr, "%s: Unable to create backing store: %d\n",
376 ret = truncate(mop->mo_device, mop->mo_device_sz * 1024);
379 fprintf(stderr, "%s: Unable to truncate backing store: %d\n",
386 /* Display the need for the latest e2fsprogs to be installed. make_backfs
387 * indicates if the caller is make_lustre_backfs() or not. */
388 static void disp_old_e2fsprogs_msg(const char *feature, int make_backfs)
390 static int msg_displayed;
393 fprintf(stderr, "WARNING: %s does not support %s "
394 "feature.\n\n", E2FSPROGS, feature);
400 fprintf(stderr, "WARNING: The %s package currently installed on "
401 "your system does not support \"%s\" feature.\n",
403 #if !(HAVE_LDISKFSPROGS)
404 fprintf(stderr, "Please install the latest version of e2fsprogs from\n"
405 "http://downloads.lustre.org/public/tools/e2fsprogs/\n"
406 "to enable this feature.\n");
409 fprintf(stderr, "Feature will not be enabled until %s"
410 "is updated and '%s -O %s %%{device}' "
411 "is run.\n\n", E2FSPROGS, TUNE2FS, feature);
414 /* Check whether the file exists in the device */
415 static int file_in_dev(char *file_name, char *dev_name)
418 char debugfs_cmd[256];
419 unsigned int inode_num;
422 /* Construct debugfs command line. */
423 snprintf(debugfs_cmd, sizeof(debugfs_cmd),
424 "%s -c -R 'stat %s' '%s' 2>&1 | egrep '(Inode|unsupported)'",
425 DEBUGFS, file_name, dev_name);
427 fp = popen(debugfs_cmd, "r");
429 fprintf(stderr, "%s: %s\n", progname, strerror(errno));
433 if (fscanf(fp, "Inode: %u", &inode_num) == 1) { /* exist */
437 i = fread(debugfs_cmd, 1, sizeof(debugfs_cmd), fp);
440 fprintf(stderr, "%s", debugfs_cmd);
441 if (strstr(debugfs_cmd, "unsupported feature")) {
442 disp_old_e2fsprogs_msg("an unknown", 0);
451 /* Check whether the device has already been used with lustre */
452 static int is_lustre_target(struct mkfs_opts *mop)
456 vprint("checking for existing Lustre data: ");
458 if ((rc = file_in_dev(MOUNT_DATA_FILE, mop->mo_device))) {
460 (rc == 1) ? MOUNT_DATA_FILE : "extents");
461 /* in the -1 case, 'extents' means this really IS a lustre
466 if ((rc = file_in_dev(LAST_RCVD, mop->mo_device))) {
467 vprint("found %s\n", LAST_RCVD);
471 vprint("not found\n");
472 return 0; /* The device is not a lustre target. */
475 /* Check if a certain feature is supported by e2fsprogs.
476 * Firstly we try to use "debugfs supported_features" command to check if
477 * the feature is supported. If this fails we try to set this feature with
478 * mke2fs to check for its support. */
479 static int is_e2fsprogs_feature_supp(const char *feature)
483 char imgname[] = "/tmp/test-img-XXXXXX";
487 snprintf(cmd, sizeof(cmd), "%s -c -R \"supported_features %s\" 2>&1",
490 /* Using popen() instead of run_command() since debugfs does not return
491 * proper error code if command is not supported */
492 fp = popen(cmd, "r");
494 fprintf(stderr, "%s: %s\n", progname, strerror(errno));
497 ret = fread(cmd, 1, sizeof(cmd), fp);
499 if (strstr(cmd, feature) && !(strstr(cmd, "Unknown")))
503 if ((fd = mkstemp(imgname)) < 0)
506 snprintf(cmd, sizeof(cmd), "%s -F -O %s %s 100 >/dev/null 2>&1",
507 MKE2FS, feature, imgname);
508 /* run_command() displays the output of mke2fs when it fails for
509 * some feature, so use system() directly */
517 static void disp_old_kernel_msg(char *feature)
519 fprintf(stderr, "WARNING: ldiskfs filesystem does not support \"%s\" "
520 "feature.\n\n", feature);
523 static void enable_default_backfs_features(struct mkfs_opts *mop)
526 int maj_high, maj_low, min;
529 if (IS_MDT(&mop->mo_ldd))
530 strscat(mop->mo_mkfsopts, " -O dir_index,extents,dirdata",
531 sizeof(mop->mo_mkfsopts));
533 strscat(mop->mo_mkfsopts, " -O dir_index,extents",
534 sizeof(mop->mo_mkfsopts));
537 /* Upstream e2fsprogs called our uninit_groups feature uninit_bg,
538 * check for both of them when testing e2fsprogs features. */
539 if (is_e2fsprogs_feature_supp("uninit_groups") == 0)
540 strscat(mop->mo_mkfsopts, ",uninit_groups",
541 sizeof(mop->mo_mkfsopts));
542 else if (is_e2fsprogs_feature_supp("uninit_bg") == 0)
543 strscat(mop->mo_mkfsopts, ",uninit_bg",
544 sizeof(mop->mo_mkfsopts));
546 disp_old_e2fsprogs_msg("uninit_bg", 1);
552 sscanf(uts.release, "%d.%d.%d", &maj_high, &maj_low, &min);
553 printf("%d %d %d\n", maj_high, maj_low, min);
555 /* Multiple mount protection is enabled only if failover node is
556 * specified and if kernel version is higher than 2.6.9 */
558 if (KERNEL_VERSION(maj_high, maj_low, min) >=
559 KERNEL_VERSION(2,6,9)) {
560 if (is_e2fsprogs_feature_supp("mmp") == 0)
561 strscat(mop->mo_mkfsopts, ",mmp",
562 sizeof(mop->mo_mkfsopts));
564 disp_old_e2fsprogs_msg("mmp", 1);
566 disp_old_kernel_msg("mmp");
570 /* Build fs according to type */
571 int make_lustre_backfs(struct mkfs_opts *mop)
573 __u64 device_sz = mop->mo_device_sz, block_count = 0;
574 char mkfs_cmd[PATH_MAX];
579 if (!(mop->mo_flags & MO_IS_LOOP)) {
580 mop->mo_device_sz = get_device_size(mop->mo_device);
582 if (mop->mo_device_sz == 0)
585 /* Compare to real size */
586 if (device_sz == 0 || device_sz > mop->mo_device_sz)
587 device_sz = mop->mo_device_sz;
589 mop->mo_device_sz = device_sz;
592 if (mop->mo_device_sz != 0) {
593 if (mop->mo_device_sz < 8096){
594 fprintf(stderr, "%s: size of filesystem must be larger "
595 "than 8MB, but is set to %lldKB\n",
596 progname, (long long)mop->mo_device_sz);
599 block_count = mop->mo_device_sz / (L_BLOCK_SIZE >> 10);
602 if ((mop->mo_ldd.ldd_mount_type == LDD_MT_EXT3) ||
603 (mop->mo_ldd.ldd_mount_type == LDD_MT_LDISKFS) ||
604 (mop->mo_ldd.ldd_mount_type == LDD_MT_LDISKFS2)) {
605 /* Journal size in MB */
606 if (strstr(mop->mo_mkfsopts, "-J") == NULL) {
607 /* Choose our own default journal size */
608 long journal_sz = 0, max_sz;
609 if (device_sz > 1024 * 1024) /* 1GB */
610 journal_sz = (device_sz / 102400) * 4;
611 /* cap journal size at 1GB */
612 if (journal_sz > 1024L)
615 max_sz = (102400 * L_BLOCK_SIZE) >> 20; /* 400MB */
616 if (journal_sz > max_sz)
619 sprintf(buf, " -J size=%ld", journal_sz);
620 strscat(mop->mo_mkfsopts, buf,
621 sizeof(mop->mo_mkfsopts));
625 /* Bytes_per_inode: disk size / num inodes */
626 if (strstr(mop->mo_mkfsopts, "-i") == NULL) {
627 long bytes_per_inode = 0;
629 if (IS_MDT(&mop->mo_ldd))
630 bytes_per_inode = 4096;
632 /* Allocate fewer inodes on large OST devices. Most
633 filesystems can be much more aggressive than even
635 if ((IS_OST(&mop->mo_ldd) && (device_sz > 100000000)))
636 bytes_per_inode = 16384; /* > 100 Gb device */
639 if (bytes_per_inode > 0) {
640 sprintf(buf, " -i %ld", bytes_per_inode);
641 strscat(mop->mo_mkfsopts, buf,
642 sizeof(mop->mo_mkfsopts));
646 /* Inode size (for extended attributes). The LOV EA size is
647 * 32 (EA hdr) + 32 (lov_mds_md) + stripes * 24 (lov_ost_data),
648 * and we want some margin above that for ACLs, other EAs... */
649 if (strstr(mop->mo_mkfsopts, "-I") == NULL) {
651 if (IS_MDT(&mop->mo_ldd)) {
652 if (mop->mo_stripe_count > 72)
653 inode_size = 512; /* bz 7241 */
654 /* cray stripes across all osts (>60) */
655 else if (mop->mo_stripe_count > 32)
657 else if (mop->mo_stripe_count > 10)
661 } else if (IS_OST(&mop->mo_ldd)) {
662 /* now as we store fids in EA on OST we need
663 to make inode bigger */
667 if (inode_size > 0) {
668 sprintf(buf, " -I %ld", inode_size);
669 strscat(mop->mo_mkfsopts, buf,
670 sizeof(mop->mo_mkfsopts));
675 strscat(mop->mo_mkfsopts, " -q",
676 sizeof(mop->mo_mkfsopts));
679 if (strstr(mop->mo_mkfsopts, "-O") == NULL)
680 enable_default_backfs_features(mop);
682 /* Allow reformat of full devices (as opposed to
683 partitions.) We already checked for mounted dev. */
684 strscat(mop->mo_mkfsopts, " -F", sizeof(mop->mo_mkfsopts));
686 snprintf(mkfs_cmd, sizeof(mkfs_cmd),
687 "%s -j -b %d -L %s ", MKE2FS, L_BLOCK_SIZE,
688 mop->mo_ldd.ldd_svname);
689 } else if (mop->mo_ldd.ldd_mount_type == LDD_MT_REISERFS) {
690 long journal_sz = 0; /* FIXME default journal size */
691 if (journal_sz > 0) {
692 sprintf(buf, " --journal_size %ld", journal_sz);
693 strscat(mop->mo_mkfsopts, buf,
694 sizeof(mop->mo_mkfsopts));
696 snprintf(mkfs_cmd, sizeof(mkfs_cmd), "mkreiserfs -ff ");
698 fprintf(stderr,"%s: unsupported fs type: %d (%s)\n",
699 progname, mop->mo_ldd.ldd_mount_type,
700 MT_STR(&mop->mo_ldd));
704 /* For loop device format the dev, not the filename */
705 dev = mop->mo_device;
706 if (mop->mo_flags & MO_IS_LOOP)
707 dev = mop->mo_loopdev;
709 vprint("formatting backing filesystem %s on %s\n",
710 MT_STR(&mop->mo_ldd), dev);
711 vprint("\ttarget name %s\n", mop->mo_ldd.ldd_svname);
712 vprint("\t4k blocks "LPU64"\n", block_count);
713 vprint("\toptions %s\n", mop->mo_mkfsopts);
715 /* mkfs_cmd's trailing space is important! */
716 strscat(mkfs_cmd, mop->mo_mkfsopts, sizeof(mkfs_cmd));
717 strscat(mkfs_cmd, " ", sizeof(mkfs_cmd));
718 strscat(mkfs_cmd, dev, sizeof(mkfs_cmd));
719 if (block_count != 0) {
720 sprintf(buf, " "LPU64, block_count);
721 strscat(mkfs_cmd, buf, sizeof(mkfs_cmd));
724 vprint("mkfs_cmd = %s\n", mkfs_cmd);
725 ret = run_command(mkfs_cmd, sizeof(mkfs_cmd));
728 fprintf(stderr, "Unable to build fs %s (%d)\n", dev, ret);
733 /* ==================== Lustre config functions =============*/
735 void print_ldd(char *str, struct lustre_disk_data *ldd)
737 printf("\n %s:\n", str);
738 printf("Target: %s\n", ldd->ldd_svname);
739 if (ldd->ldd_svindex == INDEX_UNASSIGNED)
740 printf("Index: unassigned\n");
742 printf("Index: %d\n", ldd->ldd_svindex);
743 if (ldd->ldd_uuid[0])
744 printf("UUID: %s\n", (char *)ldd->ldd_uuid);
745 printf("Lustre FS: %s\n", ldd->ldd_fsname);
746 printf("Mount type: %s\n", MT_STR(ldd));
747 printf("Flags: %#x\n", ldd->ldd_flags);
748 printf(" (%s%s%s%s%s%s%s%s%s)\n",
749 IS_MDT(ldd) ? "MDT ":"",
750 IS_OST(ldd) ? "OST ":"",
751 IS_MGS(ldd) ? "MGS ":"",
752 ldd->ldd_flags & LDD_F_NEED_INDEX ? "needs_index ":"",
753 ldd->ldd_flags & LDD_F_VIRGIN ? "first_time ":"",
754 ldd->ldd_flags & LDD_F_UPDATE ? "update ":"",
755 ldd->ldd_flags & LDD_F_WRITECONF ? "writeconf ":"",
756 ldd->ldd_flags & LDD_F_IAM_DIR ? "IAM_dir_format ":"",
757 ldd->ldd_flags & LDD_F_UPGRADE14 ? "upgrade1.4 ":"");
758 printf("Persistent mount opts: %s\n", ldd->ldd_mount_opts);
759 printf("Parameters:%s\n", ldd->ldd_params);
760 if (ldd->ldd_userdata[0])
761 printf("Comment: %s\n", ldd->ldd_userdata);
765 static int touch_file(char *filename)
769 if (filename == NULL) {
773 fd = open(filename, O_CREAT | O_TRUNC, 0600);
782 /* keep it less than LL_FID_NAMELEN */
783 #define DUMMY_FILE_NAME_LEN 25
784 #define EXT3_DIRENT_SIZE DUMMY_FILE_NAME_LEN
786 /* Need to add these many entries to this directory to make HTREE dir. */
787 #define MIN_ENTRIES_REQ_FOR_HTREE ((L_BLOCK_SIZE / EXT3_DIRENT_SIZE))
789 static int add_dummy_files(char *dir)
791 char fpname[PATH_MAX];
795 for (i = 0; i < MIN_ENTRIES_REQ_FOR_HTREE; i++) {
796 snprintf(fpname, PATH_MAX, "%s/%0*d", dir,
797 DUMMY_FILE_NAME_LEN, i);
799 rc = touch_file(fpname);
800 if (rc && rc != -EEXIST) {
802 "%s: Can't create dummy file %s: %s\n",
803 progname, fpname , strerror(errno));
810 static int __l_mkdir(char * filepnm, int mode , struct mkfs_opts *mop)
814 ret = mkdir(filepnm, mode);
815 if (ret && ret != -EEXIST)
818 /* IAM mode supports ext3 directories of HTREE type only. So add dummy
819 * entries to new directory to create htree type of container for
821 if (mop->mo_ldd.ldd_flags & LDD_F_IAM_DIR)
822 return add_dummy_files(filepnm);
826 /* Write the server config files */
827 int write_local_files(struct mkfs_opts *mop)
829 char mntpt[] = "/tmp/mntXXXXXX";
836 /* Mount this device temporarily in order to write these files */
837 if (!mkdtemp(mntpt)) {
838 fprintf(stderr, "%s: Can't create temp mount point %s: %s\n",
839 progname, mntpt, strerror(errno));
843 dev = mop->mo_device;
844 if (mop->mo_flags & MO_IS_LOOP)
845 dev = mop->mo_loopdev;
847 ret = mount(dev, mntpt, MT_STR(&mop->mo_ldd), 0,
848 mop->mo_ldd.ldd_mount_opts);
850 fprintf(stderr, "%s: Unable to mount %s: %s\n",
851 progname, dev, strerror(errno));
853 if (errno == ENODEV) {
854 fprintf(stderr, "Is the %s module available?\n",
855 MT_STR(&mop->mo_ldd));
860 /* Set up initial directories */
861 sprintf(filepnm, "%s/%s", mntpt, MOUNT_CONFIGS_DIR);
862 ret = __l_mkdir(filepnm, 0777, mop);
863 if ((ret != 0) && (errno != EEXIST)) {
864 fprintf(stderr, "%s: Can't make configs dir %s (%s)\n",
865 progname, filepnm, strerror(errno));
867 } else if (errno == EEXIST) {
871 /* Save the persistent mount data into a file. Lustre must pre-read
872 this file to get the real mount options. */
873 vprint("Writing %s\n", MOUNT_DATA_FILE);
874 sprintf(filepnm, "%s/%s", mntpt, MOUNT_DATA_FILE);
875 filep = fopen(filepnm, "w");
877 fprintf(stderr, "%s: Unable to create %s file: %s\n",
878 progname, filepnm, strerror(errno));
881 num = fwrite(&mop->mo_ldd, sizeof(mop->mo_ldd), 1, filep);
882 if (num < 1 && ferror(filep)) {
883 fprintf(stderr, "%s: Unable to write to file (%s): %s\n",
884 progname, filepnm, strerror(errno));
890 /* Check for upgrade */
891 if ((mop->mo_ldd.ldd_flags & (LDD_F_UPGRADE14 | LDD_F_SV_TYPE_MGS))
892 == (LDD_F_UPGRADE14 | LDD_F_SV_TYPE_MGS)) {
895 int cmdsz = sizeof(cmd);
896 vprint("Copying old logs\n");
898 /* Copy the old client log to fsname-client */
899 sprintf(filepnm, "%s/%s/%s-client",
900 mntpt, MOUNT_CONFIGS_DIR, mop->mo_ldd.ldd_fsname);
901 snprintf(cmd, cmdsz, "cp %s/%s/client %s", mntpt, MDT_LOGS_DIR,
903 ret = run_command(cmd, cmdsz);
905 fprintf(stderr, "%s: Can't copy 1.4 config %s/client "
906 "(%d)\n", progname, MDT_LOGS_DIR, ret);
907 fprintf(stderr, "mount -t ldiskfs %s somewhere, "
908 "find the client log for fs %s and "
909 "copy it manually into %s/%s-client, "
912 mop->mo_ldd.ldd_fsname, MOUNT_CONFIGS_DIR,
913 mop->mo_ldd.ldd_fsname);
917 /* We need to use the old mdt log because otherwise mdt won't
918 have complete lov if old clients connect before all
920 /* Copy the old mdt log to fsname-MDT0000 (get old
921 name from mdt_UUID) */
923 strscpy(filepnm, (char *)mop->mo_ldd.ldd_uuid, sizeof(filepnm));
924 term = strstr(filepnm, "_UUID");
927 snprintf(cmd, cmdsz, "cp %s/%s/%s %s/%s/%s",
928 mntpt, MDT_LOGS_DIR, filepnm,
929 mntpt, MOUNT_CONFIGS_DIR,
930 mop->mo_ldd.ldd_svname);
931 ret = run_command(cmd, cmdsz);
934 fprintf(stderr, "%s: Can't copy 1.4 config %s/%s "
935 "(%d)\n", progname, MDT_LOGS_DIR, filepnm, ret);
936 fprintf(stderr, "mount -t ext3 %s somewhere, "
937 "find the MDT log for fs %s and "
938 "copy it manually into %s/%s, "
941 mop->mo_ldd.ldd_fsname, MOUNT_CONFIGS_DIR,
942 mop->mo_ldd.ldd_svname);
956 int read_local_files(struct mkfs_opts *mop)
958 char tmpdir[] = "/tmp/dirXXXXXX";
964 int cmdsz = sizeof(cmd);
966 /* Make a temporary directory to hold Lustre data files. */
967 if (!mkdtemp(tmpdir)) {
968 fprintf(stderr, "%s: Can't create temporary directory %s: %s\n",
969 progname, tmpdir, strerror(errno));
973 dev = mop->mo_device;
975 /* TODO: it's worth observing the get_mountdata() function that is
976 in mount_utils.c for getting the mountdata out of the
979 /* Construct debugfs command line. */
980 snprintf(cmd, cmdsz, "%s -c -R 'dump /%s %s/mountdata' '%s'",
981 DEBUGFS, MOUNT_DATA_FILE, tmpdir, dev);
983 ret = run_command(cmd, cmdsz);
985 verrprint("%s: Unable to dump %s dir (%d)\n",
986 progname, MOUNT_CONFIGS_DIR, ret);
988 sprintf(filepnm, "%s/mountdata", tmpdir);
989 filep = fopen(filepnm, "r");
992 vprint("Reading %s\n", MOUNT_DATA_FILE);
993 num_read = fread(&mop->mo_ldd, sizeof(mop->mo_ldd), 1, filep);
994 if (num_read < 1 && ferror(filep)) {
995 fprintf(stderr, "%s: Unable to read from file (%s): %s\n",
996 progname, filepnm, strerror(errno));
1001 /* Try to read pre-1.6 config from last_rcvd */
1002 struct lr_server_data lsd;
1003 verrprint("%s: Unable to read %d.%d config %s.\n",
1004 progname, LUSTRE_MAJOR, LUSTRE_MINOR, filepnm);
1006 verrprint("Trying 1.4 config from last_rcvd\n");
1007 sprintf(filepnm, "%s/%s", tmpdir, LAST_RCVD);
1009 /* Construct debugfs command line. */
1010 snprintf(cmd, cmdsz, "%s -c -R 'dump /%s %s' %s",
1011 DEBUGFS, LAST_RCVD, filepnm, dev);
1013 ret = run_command(cmd, cmdsz);
1015 fprintf(stderr, "%s: Unable to dump %s file (%d)\n",
1016 progname, LAST_RCVD, ret);
1020 filep = fopen(filepnm, "r");
1022 fprintf(stderr, "%s: Unable to open %s: %s\n",
1023 progname, filepnm, strerror(errno));
1025 verrprint("Contents of %s:\n", tmpdir);
1027 snprintf(cmd, cmdsz, "ls -l %s/", tmpdir);
1028 run_command(cmd, cmdsz);
1029 verrprint("Contents of disk:\n");
1030 snprintf(cmd, cmdsz, "%s -c -R 'ls -l /' %s",
1032 run_command(cmd, cmdsz);
1036 vprint("Reading %s\n", LAST_RCVD);
1037 ret = fread(&lsd, 1, sizeof(lsd), filep);
1038 if (ret < sizeof(lsd)) {
1039 fprintf(stderr, "%s: Short read (%d of %d)\n",
1040 progname, ret, (int)sizeof(lsd));
1041 ret = ferror(filep);
1045 vprint("Feature compat=%x, incompat=%x\n",
1046 lsd.lsd_feature_compat, lsd.lsd_feature_incompat);
1048 if ((lsd.lsd_feature_compat & OBD_COMPAT_OST) ||
1049 (lsd.lsd_feature_incompat & OBD_INCOMPAT_OST)) {
1050 mop->mo_ldd.ldd_flags = LDD_F_SV_TYPE_OST;
1051 mop->mo_ldd.ldd_svindex = lsd.lsd_ost_index;
1052 } else if ((lsd.lsd_feature_compat & OBD_COMPAT_MDT) ||
1053 (lsd.lsd_feature_incompat & OBD_INCOMPAT_MDT)) {
1054 /* We must co-locate so mgs can see old logs.
1055 If user doesn't want this, they can copy the old
1056 logs manually and re-tunefs. */
1057 mop->mo_ldd.ldd_flags =
1058 LDD_F_SV_TYPE_MDT | LDD_F_SV_TYPE_MGS;
1059 mop->mo_ldd.ldd_svindex = lsd.lsd_mdt_index;
1061 /* If neither is set, we're pre-1.4.6, make a guess. */
1062 /* Construct debugfs command line. */
1063 snprintf(cmd, cmdsz, "%s -c -R 'rdump /%s %s' %s",
1064 DEBUGFS, MDT_LOGS_DIR, tmpdir, dev);
1065 run_command(cmd, cmdsz);
1067 sprintf(filepnm, "%s/%s", tmpdir, MDT_LOGS_DIR);
1068 if (lsd.lsd_ost_index > 0) {
1069 mop->mo_ldd.ldd_flags = LDD_F_SV_TYPE_OST;
1070 mop->mo_ldd.ldd_svindex = lsd.lsd_ost_index;
1072 /* If there's a LOGS dir, it's an MDT */
1073 if ((ret = access(filepnm, F_OK)) == 0) {
1074 mop->mo_ldd.ldd_flags =
1077 /* Old MDT's are always index 0
1079 mop->mo_ldd.ldd_svindex = 0;
1081 /* The index may not be correct */
1082 mop->mo_ldd.ldd_flags =
1083 LDD_F_SV_TYPE_OST | LDD_F_NEED_INDEX;
1084 verrprint("OST with unknown index\n");
1090 memcpy(mop->mo_ldd.ldd_uuid, lsd.lsd_uuid,
1091 sizeof(mop->mo_ldd.ldd_uuid));
1092 mop->mo_ldd.ldd_flags |= LDD_F_UPGRADE14;
1094 /* end COMPAT_146 */
1099 snprintf(cmd, cmdsz, "rm -rf %s", tmpdir);
1100 run_command(cmd, cmdsz);
1102 verrprint("Failed to read old data (%d)\n", ret);
1107 void set_defaults(struct mkfs_opts *mop)
1109 mop->mo_ldd.ldd_magic = LDD_MAGIC;
1110 mop->mo_ldd.ldd_config_ver = 1;
1111 mop->mo_ldd.ldd_flags = LDD_F_NEED_INDEX | LDD_F_UPDATE | LDD_F_VIRGIN;
1112 mop->mo_mgs_failnodes = 0;
1113 strcpy(mop->mo_ldd.ldd_fsname, "lustre");
1114 if (get_os_version() == 24)
1115 mop->mo_ldd.ldd_mount_type = LDD_MT_EXT3;
1117 mop->mo_ldd.ldd_mount_type = LDD_MT_LDISKFS;
1119 mop->mo_ldd.ldd_svindex = INDEX_UNASSIGNED;
1120 mop->mo_stripe_count = 1;
1123 static inline void badopt(const char *opt, char *type)
1125 fprintf(stderr, "%s: '--%s' only valid for %s\n",
1126 progname, opt, type);
1130 static int add_param(char *buf, char *key, char *val)
1132 int end = sizeof(((struct lustre_disk_data *)0)->ldd_params);
1133 int start = strlen(buf);
1137 keylen = strlen(key);
1138 if (start + 1 + keylen + strlen(val) >= end) {
1139 fprintf(stderr, "%s: params are too long-\n%s %s%s\n",
1140 progname, buf, key ? key : "", val);
1144 sprintf(buf + start, " %s%s", key ? key : "", val);
1148 /* from mount_lustre */
1149 /* Get rid of symbolic hostnames for tcp, since kernel can't do lookups */
1150 #define MAXNIDSTR 1024
1151 static char *convert_hostnames(char *s1)
1153 char *converted, *s2 = 0, *c, *end, sep;
1154 int left = MAXNIDSTR;
1157 converted = malloc(left);
1158 if (converted == NULL) {
1162 end = s1 + strlen(s1);
1164 while ((left > 0) && (s1 < end)) {
1165 s2 = strpbrk(s1, ",:");
1170 nid = libcfs_str2nid(s1);
1172 if (nid == LNET_NID_ANY) {
1173 fprintf(stderr, "%s: Can't parse NID '%s'\n", progname, s1);
1177 if (strncmp(libcfs_nid2str(nid), "127.0.0.1",
1178 strlen("127.0.0.1")) == 0) {
1179 fprintf(stderr, "%s: The NID '%s' resolves to the "
1180 "loopback address '%s'. Lustre requires a "
1181 "non-loopback address.\n",
1182 progname, s1, libcfs_nid2str(nid));
1187 c += snprintf(c, left, "%s%c", libcfs_nid2str(nid), sep);
1188 left = converted + MAXNIDSTR - c;
1194 int parse_opts(int argc, char *const argv[], struct mkfs_opts *mop,
1197 static struct option long_opt[] = {
1198 {"iam-dir", 0, 0, 'a'},
1199 {"backfstype", 1, 0, 'b'},
1200 {"stripe-count-hint", 1, 0, 'c'},
1201 {"comment", 1, 0, 'u'},
1202 {"configdev", 1, 0, 'C'},
1203 {"device-size", 1, 0, 'd'},
1204 {"dryrun", 0, 0, 'n'},
1205 {"erase-params", 0, 0, 'e'},
1206 {"failnode", 1, 0, 'f'},
1207 {"failover", 1, 0, 'f'},
1209 {"help", 0, 0, 'h'},
1210 {"index", 1, 0, 'i'},
1211 {"mkfsoptions", 1, 0, 'k'},
1212 {"mgsnode", 1, 0, 'm'},
1213 {"mgsnid", 1, 0, 'm'},
1215 {"fsname",1, 0, 'L'},
1216 {"noformat", 0, 0, 'n'},
1217 {"nomgs", 0, 0, 'N'},
1218 {"mountfsoptions", 1, 0, 'o'},
1220 {"param", 1, 0, 'p'},
1221 {"print", 0, 0, 'n'},
1222 {"quiet", 0, 0, 'q'},
1223 {"reformat", 0, 0, 'r'},
1224 {"verbose", 0, 0, 'v'},
1225 {"writeconf", 0, 0, 'w'},
1226 {"upgrade_to_18", 0, 0, 'U'},
1229 char *optstring = "b:c:C:d:ef:Ghi:k:L:m:MnNo:Op:Pqru:vw";
1233 while ((opt = getopt_long(argc, argv, optstring, long_opt, &longidx)) !=
1237 if (IS_MDT(&mop->mo_ldd))
1238 mop->mo_ldd.ldd_flags |= LDD_F_IAM_DIR;
1243 while (i < LDD_MT_LAST) {
1244 if (strcmp(optarg, mt_str(i)) == 0) {
1245 mop->mo_ldd.ldd_mount_type = i;
1253 if (IS_MDT(&mop->mo_ldd)) {
1254 int stripe_count = atol(optarg);
1255 if (stripe_count <= 0) {
1256 fprintf(stderr, "%s: bad stripe count "
1257 "%d\n", progname, stripe_count);
1260 mop->mo_stripe_count = stripe_count;
1262 badopt(long_opt[longidx].name, "MDT");
1266 case 'C': /* Configdev */
1268 printf("Configdev not implemented\n");
1271 mop->mo_device_sz = atol(optarg);
1274 mop->mo_ldd.ldd_params[0] = '\0';
1275 /* Must update the mgs logs */
1276 mop->mo_ldd.ldd_flags |= LDD_F_UPDATE;
1279 char *nids = convert_hostnames(optarg);
1282 rc = add_param(mop->mo_ldd.ldd_params, PARAM_FAILNODE,
1287 /* Must update the mgs logs */
1288 mop->mo_ldd.ldd_flags |= LDD_F_UPDATE;
1293 mop->mo_ldd.ldd_flags |= LDD_F_SV_TYPE_MGS;
1299 if (!(mop->mo_ldd.ldd_flags &
1300 (LDD_F_UPGRADE14 | LDD_F_VIRGIN |
1301 LDD_F_WRITECONF))) {
1302 fprintf(stderr, "%s: cannot change the index of"
1303 " a registered target\n", progname);
1306 if (IS_MDT(&mop->mo_ldd) || IS_OST(&mop->mo_ldd)) {
1307 mop->mo_ldd.ldd_svindex = atol(optarg);
1308 mop->mo_ldd.ldd_flags &= ~LDD_F_NEED_INDEX;
1310 badopt(long_opt[longidx].name, "MDT,OST");
1315 strscpy(mop->mo_mkfsopts, optarg,
1316 sizeof(mop->mo_mkfsopts));
1320 if (!(mop->mo_flags & MO_FORCEFORMAT) &&
1321 (!(mop->mo_ldd.ldd_flags &
1322 (LDD_F_UPGRADE14 | LDD_F_VIRGIN |
1323 LDD_F_WRITECONF)))) {
1324 fprintf(stderr, "%s: cannot change the name of"
1325 " a registered target\n", progname);
1328 if ((strlen(optarg) < 1) || (strlen(optarg) > 8)) {
1329 fprintf(stderr, "%s: filesystem name must be "
1330 "1-8 chars\n", progname);
1333 if ((tmp = strpbrk(optarg, "/:"))) {
1334 fprintf(stderr, "%s: char '%c' not allowed in "
1335 "filesystem name\n", progname, *tmp);
1338 strscpy(mop->mo_ldd.ldd_fsname, optarg,
1339 sizeof(mop->mo_ldd.ldd_fsname));
1343 char *nids = convert_hostnames(optarg);
1346 rc = add_param(mop->mo_ldd.ldd_params, PARAM_MGSNODE,
1351 mop->mo_mgs_failnodes++;
1355 mop->mo_ldd.ldd_flags |= LDD_F_SV_TYPE_MDT;
1361 mop->mo_ldd.ldd_flags &= ~LDD_F_SV_TYPE_MGS;
1364 *mountopts = optarg;
1367 mop->mo_ldd.ldd_flags |= LDD_F_SV_TYPE_OST;
1370 rc = add_param(mop->mo_ldd.ldd_params, NULL, optarg);
1373 /* Must update the mgs logs */
1374 mop->mo_ldd.ldd_flags |= LDD_F_UPDATE;
1380 mop->mo_flags |= MO_FORCEFORMAT;
1383 strscpy(mop->mo_ldd.ldd_userdata, optarg,
1384 sizeof(mop->mo_ldd.ldd_userdata));
1390 mop->mo_ldd.ldd_flags |= LDD_F_WRITECONF;
1398 fprintf(stderr, "Unknown option '%c'\n", opt);
1404 /* Last arg is device */
1405 if (optind != argc - 1) {
1407 fprintf(stderr, "Bad argument: %s\n", argv[optind]);
1411 /* single argument: <device> */
1418 /* Search for opt in mntlist, returning true if found.
1420 static int in_mntlist(char *opt, char *mntlist)
1422 char *ml, *mlp, *item, *ctx = NULL;
1424 if (!(ml = strdup(mntlist))) {
1425 fprintf(stderr, "%s: out of memory\n", progname);
1429 while ((item = strtok_r(mlp, ",", &ctx))) {
1430 if (!strcmp(opt, item))
1435 return (item != NULL);
1438 /* Issue a message on stderr for every item in wanted_mountopts that is not
1439 * present in mountopts. The justwarn boolean toggles between error and
1440 * warning message. Return an error count.
1442 static int check_mountfsoptions(char *mountopts, char *wanted_mountopts,
1445 char *ml, *mlp, *item, *ctx = NULL;
1448 if (!(ml = strdup(wanted_mountopts))) {
1449 fprintf(stderr, "%s: out of memory\n", progname);
1453 while ((item = strtok_r(mlp, ",", &ctx))) {
1454 if (!in_mntlist(item, mountopts)) {
1455 fprintf(stderr, "%s: %s mount option `%s' is missing\n",
1456 progname, justwarn ? "Warning: default"
1457 : "Error: mandatory", item);
1466 /* Trim embedded white space, leading and trailing commas from string s.
1468 static void trim_mountfsoptions(char *s)
1474 memmove(p, p + 1, strlen(p + 1) + 1);
1481 memmove(&s[0], &s[1], strlen(&s[1]) + 1);
1483 p = s + strlen(s) - 1;
1484 while (p >= s && *p == ',')
1488 int main(int argc, char *const argv[])
1490 struct mkfs_opts mop;
1491 struct lustre_disk_data *ldd;
1492 char *mountopts = NULL;
1493 char always_mountopts[512] = "";
1494 char default_mountopts[512] = "";
1497 if ((progname = strrchr(argv[0], '/')) != NULL)
1502 if ((argc < 2) || (argv[argc - 1][0] == '-')) {
1507 memset(&mop, 0, sizeof(mop));
1510 /* device is last arg */
1511 strscpy(mop.mo_device, argv[argc - 1], sizeof(mop.mo_device));
1513 /* Are we using a loop device? */
1514 ret = is_block(mop.mo_device);
1518 mop.mo_flags |= MO_IS_LOOP;
1521 /* For tunefs, we must read in the old values before parsing any
1524 /* Check whether the disk has already been formatted by mkfs.lustre */
1525 ret = is_lustre_target(&mop);
1528 fprintf(stderr, "Device %s has not been formatted with "
1529 "mkfs.lustre\n", mop.mo_device);
1534 ret = read_local_files(&mop);
1537 fprintf(stderr, "Failed to read previous Lustre data from %s "
1538 "(%d)\n", mop.mo_device, ret);
1541 if (strstr(mop.mo_ldd.ldd_params, PARAM_MGSNODE))
1542 mop.mo_mgs_failnodes++;
1545 print_ldd("Read previous values", &(mop.mo_ldd));
1548 ret = parse_opts(argc, argv, &mop, &mountopts);
1554 if (!(IS_MDT(ldd) || IS_OST(ldd) || IS_MGS(ldd))) {
1556 fprintf(stderr, "must set target type: MDT,OST,MGS\n");
1561 if (((IS_MDT(ldd) || IS_MGS(ldd))) && IS_OST(ldd)) {
1563 fprintf(stderr, "OST type is exclusive with MDT,MGS\n");
1568 if ((mop.mo_ldd.ldd_flags & (LDD_F_NEED_INDEX | LDD_F_UPGRADE14)) ==
1569 (LDD_F_NEED_INDEX | LDD_F_UPGRADE14)) {
1571 fprintf(stderr, "Can't find the target index, "
1572 "specify with --index\n");
1578 * Comment out these 2 checks temporarily, since for multi-MDSes
1579 * in single node only 1 mds node could have mgs service
1581 if (IS_MDT(ldd) && !IS_MGS(ldd) && (mop.mo_mgs_failnodes == 0)) {
1582 verrprint("No management node specified, adding MGS to this "
1584 ldd->ldd_flags |= LDD_F_SV_TYPE_MGS;
1586 if (!IS_MGS(ldd) && (mop.mo_mgs_failnodes == 0)) {
1589 fprintf(stderr, "Must specify --mgs or --mgsnode=\n");
1591 fprintf(stderr, "Must specify --mgsnode=\n");
1597 /* These are the permanent mount options (always included) */
1598 switch (ldd->ldd_mount_type) {
1600 case LDD_MT_LDISKFS:
1601 case LDD_MT_LDISKFS2: {
1602 strscat(default_mountopts, ",errors=remount-ro",
1603 sizeof(default_mountopts));
1604 if (IS_MDT(ldd) || IS_MGS(ldd))
1605 strscat(always_mountopts, ",iopen_nopriv,user_xattr",
1606 sizeof(always_mountopts));
1607 if ((get_os_version() == 24) && IS_OST(ldd))
1608 strscat(always_mountopts, ",asyncdel",
1609 sizeof(always_mountopts));
1610 /* NB: Files created while extents are enabled cannot be read
1611 if mounted with a kernel that doesn't include the Lustre ldiskfs
1614 (ldd->ldd_mount_type == LDD_MT_LDISKFS ||
1615 ldd->ldd_mount_type == LDD_MT_LDISKFS2)) {
1616 strscat(default_mountopts, ",extents,mballoc",
1617 sizeof(default_mountopts));
1622 mop.mo_flags |= MO_IS_LOOP;
1623 sprintf(always_mountopts, ",type=ext3,dev=%s",
1629 fprintf(stderr, "unknown fs type %d '%s'\n",
1630 ldd->ldd_mount_type,
1638 trim_mountfsoptions(mountopts);
1639 (void)check_mountfsoptions(mountopts, default_mountopts, 1);
1640 if (check_mountfsoptions(mountopts, always_mountopts, 0)) {
1644 sprintf(ldd->ldd_mount_opts, "%s", mountopts);
1647 if (ldd->ldd_mount_opts[0] == 0)
1648 /* use the defaults unless old opts exist */
1651 sprintf(ldd->ldd_mount_opts, "%s%s",
1652 always_mountopts, default_mountopts);
1653 trim_mountfsoptions(ldd->ldd_mount_opts);
1657 server_make_name(ldd->ldd_flags, ldd->ldd_svindex,
1658 ldd->ldd_fsname, ldd->ldd_svname);
1661 print_ldd("Permanent disk data", ldd);
1664 printf("exiting before disk write.\n");
1668 if (check_mtab_entry(mop.mo_device))
1671 /* Create the loopback file */
1672 if (mop.mo_flags & MO_IS_LOOP) {
1673 ret = access(mop.mo_device, F_OK);
1676 #ifndef TUNEFS /* mkfs.lustre */
1677 /* Reformat the loopback file */
1678 if (ret || (mop.mo_flags & MO_FORCEFORMAT))
1679 ret = loop_format(&mop);
1682 ret = loop_setup(&mop);
1685 fprintf(stderr, "Loop device setup for %s failed: %s\n",
1686 mop.mo_device, strerror(ret));
1691 #ifndef TUNEFS /* mkfs.lustre */
1692 /* Check whether the disk has already been formatted by mkfs.lustre */
1693 if (!(mop.mo_flags & MO_FORCEFORMAT)) {
1694 ret = is_lustre_target(&mop);
1697 fprintf(stderr, "Device %s was previously formatted "
1698 "for lustre. Use --reformat to reformat it, "
1699 "or tunefs.lustre to modify.\n",
1705 /* Format the backing filesystem */
1706 ret = make_lustre_backfs(&mop);
1709 fprintf(stderr, "mkfs failed %d\n", ret);
1714 /* Write our config files */
1715 ret = write_local_files(&mop);
1718 fprintf(stderr, "failed to write local files\n");
1725 /* Fix any crazy return values from system() */
1726 if (ret && ((ret & 255) == 0))
1729 verrprint("%s: exiting with %d (%s)\n",
1730 progname, ret, strerror(ret));