1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2006 Cluster File Systems, Inc.
5 * Author: Nathan Rutman <nathan@clusterfs.com>
7 * This file is part of Lustre, http://www.lustre.org.
9 * Lustre is free software; you can redistribute it and/or
10 * modify it under the terms of version 2 of the GNU General Public
11 * License as published by the Free Software Foundation.
13 * Lustre is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with Lustre; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 /* This source file is compiled into both mkfs.lustre and tunefs.lustre */
33 #include <sys/types.h>
35 #include <sys/mount.h>
36 #include <sys/utsname.h>
43 /* kp30.h is not really needed here, but on SLES10/PPC, fs.h includes idr.h which
44 * requires BITS_PER_LONG to be defined */
45 #include <libcfs/kp30.h>
46 #include <linux/fs.h> /* for BLKGETSIZE64 */
47 #include <linux/version.h>
49 #include <lustre_disk.h>
50 #include <lustre_param.h>
51 #include <lnet/lnetctl.h>
52 #include <lustre_ver.h>
58 #define MAX_LOOP_DEVICES 16
59 #define L_BLOCK_SIZE 4096
60 #define INDEX_UNASSIGNED 0xFFFF
61 #define MO_IS_LOOP 0x01
62 #define MO_FORCEFORMAT 0x02
64 /* used to describe the options to format the lustre disk, not persistent */
66 struct lustre_disk_data mo_ldd; /* to be written in MOUNT_DATA_FILE */
67 char mo_device[128]; /* disk device name */
68 char mo_mkfsopts[128]; /* options to the backing-store mkfs */
69 char mo_loopdev[128]; /* in case a loop dev is needed */
70 __u64 mo_device_sz; /* in KB */
76 static char *progname;
77 static int verbose = 1;
78 static int print_only = 0;
79 static int failover = 0;
83 fprintf(out, "%s v"LUSTRE_VERSION_STRING"\n", progname);
84 fprintf(out, "usage: %s <target types> [options] <device>\n", progname);
86 "\t<device>:block device or file (e.g /dev/sda or /tmp/ost1)\n"
88 "\t\t--ost: object storage, mutually exclusive with mdt,mgs\n"
89 "\t\t--mdt: metadata storage, mutually exclusive with ost\n"
90 "\t\t--mgs: configuration management service - one per site\n"
91 "\toptions (in order of popularity):\n"
92 "\t\t--mgsnode=<nid>[,<...>] : NID(s) of a remote mgs node\n"
93 "\t\t\trequired for all targets other than the mgs node\n"
94 "\t\t--fsname=<filesystem_name> : default is 'lustre'\n"
95 "\t\t--failnode=<nid>[,<...>] : NID(s) of a failover partner\n"
96 "\t\t--param <key>=<value> : set a permanent parameter\n"
97 "\t\t\te.g. --param sys.timeout=40\n"
98 "\t\t\t --param lov.stripesize=2M\n"
99 "\t\t--index=#N : target index (i.e. ost index within the lov)\n"
100 /* FIXME implement 1.6.x
101 "\t\t--configdev=<altdevice|file>: store configuration info\n"
102 "\t\t\tfor this device on an alternate device\n"
104 "\t\t--comment=<user comment>: arbitrary user string (%d bytes)\n"
105 "\t\t--mountfsoptions=<opts> : permanent mount options\n"
107 "\t\t--backfstype=<fstype> : backing fs type (ext3, ldiskfs)\n"
108 "\t\t--device-size=#N(KB) : device size for loop devices\n"
109 "\t\t--mkfsoptions=<opts> : format options\n"
110 "\t\t--reformat: overwrite an existing disk\n"
111 "\t\t--stripe-count-hint=#N : used for optimizing MDT inode size\n"
113 "\t\t--erase-params : erase all old parameter settings\n"
114 "\t\t--nomgs: turn off MGS service on this MDT\n"
115 "\t\t--writeconf: erase all config logs for this fs.\n"
117 "\t\t--dryrun: just report what we would do; "
118 "don't write to disk\n"
119 "\t\t--verbose : e.g. show mkfs progress\n"
121 (int)sizeof(((struct lustre_disk_data *)0)->ldd_userdata));
125 #define vprint if (verbose > 0) printf
126 #define verrprint if (verbose >= 0) printf
128 static void fatal(void)
131 fprintf(stderr, "\n%s FATAL: ", progname);
134 /*================ utility functions =====================*/
136 char *strscat(char *dst, char *src, int buflen) {
138 if (strlen(dst) + strlen(src) >= buflen) {
139 fprintf(stderr, "string buffer overflow (max %d): '%s' + '%s'"
140 "\n", buflen, dst, src);
143 return strcat(dst, src);
147 char *strscpy(char *dst, char *src, int buflen) {
149 return strscat(dst, src, buflen);
153 dev_major (unsigned long long int __dev)
155 return ((__dev >> 8) & 0xfff) | ((unsigned int) (__dev >> 32) & ~0xfff);
159 dev_minor (unsigned long long int __dev)
161 return (__dev & 0xff) | ((unsigned int) (__dev >> 12) & ~0xff);
166 static int version = 0;
170 char release[4] = "";
172 fd = open("/proc/sys/kernel/osrelease", O_RDONLY);
174 fprintf(stderr, "%s: Warning: Can't resolve kernel "
175 "version, assuming 2.6\n", progname);
177 read(fd, release, 4);
180 if (strncmp(release, "2.4.", 4) == 0)
188 int run_command(char *cmd, int cmdsz)
190 char log[] = "/tmp/mkfs_logXXXXXX";
193 if ((cmdsz - strlen(cmd)) < 6) {
195 fprintf(stderr, "Command buffer overflow: %.*s...\n",
201 printf("cmd: %s\n", cmd);
203 if ((fd = mkstemp(log)) >= 0) {
209 strcat(cmd, " 2>&1");
211 /* Can't use popen because we need the rv of the command */
213 if (rc && (fd >= 0)) {
216 fp = fopen(log, "r");
218 while (fgets(buf, sizeof(buf), fp) != NULL) {
229 static int check_mtab_entry(char *spec)
234 fp = setmntent(MOUNTED, "r");
238 while ((mnt = getmntent(fp)) != NULL) {
239 if (strcmp(mnt->mnt_fsname, spec) == 0) {
241 fprintf(stderr, "%s: according to %s %s is "
242 "already mounted on %s\n",
243 progname, MOUNTED, spec, mnt->mnt_dir);
252 /*============ disk dev functions ===================*/
254 /* Setup a file in the first unused loop_device */
255 int loop_setup(struct mkfs_opts *mop)
261 /* Figure out the loop device names */
262 if (!access("/dev/loop0", F_OK | R_OK)) {
263 strcpy(loop_base, "/dev/loop\0");
264 } else if (!access("/dev/loop/0", F_OK | R_OK)) {
265 strcpy(loop_base, "/dev/loop/\0");
267 fprintf(stderr, "%s: can't access loop devices\n", progname);
271 /* Find unused loop device */
272 for (i = 0; i < MAX_LOOP_DEVICES; i++) {
274 int cmdsz = sizeof(cmd);
276 sprintf(l_device, "%s%d", loop_base, i);
277 if (access(l_device, F_OK | R_OK))
279 snprintf(cmd, cmdsz, "losetup %s > /dev/null 2>&1", l_device);
282 /* losetup gets 1 (ret=256) for non-set-up device */
284 /* Set up a loopback device to our file */
285 snprintf(cmd, cmdsz, "losetup %s %s", l_device,
287 ret = run_command(cmd, cmdsz);
289 fprintf(stderr, "%s: error %d on losetup: %s\n",
290 progname, ret, strerror(ret));
293 strscpy(mop->mo_loopdev, l_device,
294 sizeof(mop->mo_loopdev));
299 fprintf(stderr, "%s: out of loop devices!\n", progname);
303 int loop_cleanup(struct mkfs_opts *mop)
307 if ((mop->mo_flags & MO_IS_LOOP) && *mop->mo_loopdev) {
308 sprintf(cmd, "losetup -d %s", mop->mo_loopdev);
309 ret = run_command(cmd, sizeof(cmd));
314 /* Determine if a device is a block device (as opposed to a file) */
315 int is_block(char* devname)
320 ret = access(devname, F_OK);
323 ret = stat(devname, &st);
325 fprintf(stderr, "%s: cannot stat %s\n", progname, devname);
328 return S_ISBLK(st.st_mode);
331 __u64 get_device_size(char* device)
336 fd = open(device, O_RDONLY);
338 fprintf(stderr, "%s: cannot open %s: %s\n",
339 progname, device, strerror(errno));
344 /* size in bytes. bz5831 */
345 ret = ioctl(fd, BLKGETSIZE64, (void*)&size);
350 ret = ioctl(fd, BLKGETSIZE, (void*)&lsize);
351 size = (__u64)lsize * 512;
356 fprintf(stderr, "%s: size ioctl failed: %s\n",
357 progname, strerror(errno));
361 vprint("device size = "LPU64"MB\n", size >> 20);
362 /* return value in KB */
366 int loop_format(struct mkfs_opts *mop)
370 if (mop->mo_device_sz == 0) {
372 fprintf(stderr, "loop device requires a --device-size= "
377 ret = creat(mop->mo_device, S_IRUSR|S_IWUSR);
380 fprintf(stderr, "%s: Unable to create backing store: %d\n",
386 ret = truncate(mop->mo_device, mop->mo_device_sz * 1024);
389 fprintf(stderr, "%s: Unable to truncate backing store: %d\n",
396 /* Display the need for the latest e2fsprogs to be installed. make_backfs
397 * indicates if the caller is make_lustre_backfs() or not. */
398 static void disp_old_e2fsprogs_msg(const char *feature, int make_backfs)
400 static int msg_displayed;
403 fprintf(stderr, "WARNING: e2fsprogs does not support %s "
404 "feature.\n\n", feature);
410 fprintf(stderr, "WARNING: The e2fsprogs package currently installed on "
411 "your system does not support \"%s\" feature.\nPlease install "
412 "the latest version of e2fsprogs from http://www.clusterfs.com/"
413 "downloads/public/Lustre/Tools/e2fsprogs/\nto enable this "
414 "feature.\n", feature);
417 fprintf(stderr, "Feature will not be enabled until e2fsprogs "
418 "is updated and 'tune2fs -O %s %%{device}' "
419 "is run.\n\n", feature);
422 /* Check whether the file exists in the device */
423 static int file_in_dev(char *file_name, char *dev_name)
426 char debugfs_cmd[256];
427 unsigned int inode_num;
430 /* Construct debugfs command line. */
431 snprintf(debugfs_cmd, sizeof(debugfs_cmd),
432 "debugfs -c -R 'stat %s' %s 2>&1 | egrep '(Inode|unsupported)'",
433 file_name, dev_name);
435 fp = popen(debugfs_cmd, "r");
437 fprintf(stderr, "%s: %s\n", progname, strerror(errno));
441 if (fscanf(fp, "Inode: %u", &inode_num) == 1) { /* exist */
445 i = fread(debugfs_cmd, 1, sizeof(debugfs_cmd), fp);
448 fprintf(stderr, "%s", debugfs_cmd);
449 if (strstr(debugfs_cmd, "unsupported feature")) {
450 disp_old_e2fsprogs_msg("an unknown", 0);
458 /* Check whether the device has already been used with lustre */
459 static int is_lustre_target(struct mkfs_opts *mop)
463 vprint("checking for existing Lustre data: ");
465 if ((rc = file_in_dev(MOUNT_DATA_FILE, mop->mo_device))) {
467 (rc == 1) ? MOUNT_DATA_FILE : "extents");
468 /* in the -1 case, 'extents' means this really IS a lustre
473 if ((rc = file_in_dev(LAST_RCVD, mop->mo_device))) {
474 vprint("found %s\n", LAST_RCVD);
478 vprint("not found\n");
479 return 0; /* The device is not a lustre target. */
482 /* Check if a certain feature is supported by e2fsprogs.
483 * Firstly we try to use "debugfs supported_features" command to check if
484 * the feature is supported. If this fails we try to set this feature with
485 * mke2fs to check for its support. */
486 static int is_e2fsprogs_feature_supp(const char *feature)
490 char imgname[] = "/tmp/test-img-XXXXXX";
494 snprintf(cmd, sizeof(cmd),
495 "debugfs -c -R \"supported_features %s\" 2>&1", feature);
497 /* Using popen() instead of run_command() since debugfs does not return
498 * proper error code if command is not supported */
499 fp = popen(cmd, "r");
501 fprintf(stderr, "%s: %s\n", progname, strerror(errno));
504 ret = fread(cmd, 1, sizeof(cmd), fp);
506 if (strstr(cmd, feature) && !(strstr(cmd, "Unknown")))
510 if ((fd = mkstemp(imgname)) < 0)
513 snprintf(cmd, sizeof(cmd), "mke2fs -F -O %s %s 100 >/dev/null 2>&1",
515 /* run_command() displays the output of mke2fs when it fails for
516 * some feature, so use system() directly */
524 static void disp_old_kernel_msg(char *feature)
526 fprintf(stderr, "WARNING: ldiskfs filesystem does not support \"%s\" "
527 "feature.\n\n", feature);
530 static void enable_default_backfs_features(struct mkfs_opts *mop)
533 int maj_high, maj_low, min;
536 strscat(mop->mo_mkfsopts, " -O dir_index", sizeof(mop->mo_mkfsopts));
538 if (is_e2fsprogs_feature_supp("uninit_groups") == 0)
539 strscat(mop->mo_mkfsopts, ",uninit_groups",
540 sizeof(mop->mo_mkfsopts));
542 disp_old_e2fsprogs_msg("uninit_groups", 1);
548 sscanf(uts.release, "%d.%d.%d", &maj_high, &maj_low, &min);
549 printf("%d %d %d\n", maj_high, maj_low, min);
551 /* Multiple mount protection is enabled only if failover node is
552 * specified and if kernel version is higher than 2.6.9 */
554 if (KERNEL_VERSION(maj_high, maj_low, min) >=
555 KERNEL_VERSION(2,6,9)) {
556 if (is_e2fsprogs_feature_supp("mmp") == 0)
557 strscat(mop->mo_mkfsopts, ",mmp",
558 sizeof(mop->mo_mkfsopts));
560 disp_old_e2fsprogs_msg("mmp", 1);
562 disp_old_kernel_msg("mmp");
566 /* Build fs according to type */
567 int make_lustre_backfs(struct mkfs_opts *mop)
569 char mkfs_cmd[PATH_MAX];
575 if (mop->mo_device_sz != 0) {
576 if (mop->mo_device_sz < 8096){
577 fprintf(stderr, "%s: size of filesystem must be larger "
578 "than 8MB, but is set to %lldKB\n",
579 progname, (long long)mop->mo_device_sz);
582 block_count = mop->mo_device_sz / (L_BLOCK_SIZE >> 10);
585 if ((mop->mo_ldd.ldd_mount_type == LDD_MT_EXT3) ||
586 (mop->mo_ldd.ldd_mount_type == LDD_MT_LDISKFS) ||
587 (mop->mo_ldd.ldd_mount_type == LDD_MT_LDISKFS2)) {
588 __u64 device_sz = mop->mo_device_sz;
590 /* we really need the size */
591 if (device_sz == 0) {
592 device_sz = get_device_size(mop->mo_device);
597 /* Journal size in MB */
598 if (strstr(mop->mo_mkfsopts, "-J") == NULL) {
599 /* Choose our own default journal size */
600 long journal_sz = 0, max_sz;
601 if (device_sz > 1024 * 1024) /* 1GB */
602 journal_sz = (device_sz / 102400) * 4;
603 /* cap journal size at 1GB */
604 if (journal_sz > 1024L)
607 max_sz = (256000 * L_BLOCK_SIZE) >> 20; /* 1GB */
608 if (journal_sz > max_sz)
611 sprintf(buf, " -J size=%ld", journal_sz);
612 strscat(mop->mo_mkfsopts, buf,
613 sizeof(mop->mo_mkfsopts));
617 /* Bytes_per_inode: disk size / num inodes */
618 if (strstr(mop->mo_mkfsopts, "-i") == NULL) {
619 long bytes_per_inode = 0;
621 if (IS_MDT(&mop->mo_ldd))
622 bytes_per_inode = 4096;
624 /* Allocate fewer inodes on large OST devices. Most
625 filesystems can be much more aggressive than even
627 if ((IS_OST(&mop->mo_ldd) && (device_sz > 100000000)))
628 bytes_per_inode = 16384; /* > 100 Gb device */
631 if (bytes_per_inode > 0) {
632 sprintf(buf, " -i %ld", bytes_per_inode);
633 strscat(mop->mo_mkfsopts, buf,
634 sizeof(mop->mo_mkfsopts));
638 /* Inode size (for extended attributes). The LOV EA size is
639 * 32 (EA hdr) + 32 (lov_mds_md) + stripes * 24 (lov_ost_data),
640 * and we want some margin above that for ACLs, other EAs... */
641 if (strstr(mop->mo_mkfsopts, "-I") == NULL) {
643 if (IS_MDT(&mop->mo_ldd)) {
644 if (mop->mo_stripe_count > 72)
645 inode_size = 512; /* bz 7241 */
646 /* cray stripes across all osts (>60) */
647 else if (mop->mo_stripe_count > 32)
649 else if (mop->mo_stripe_count > 10)
653 } else if (IS_OST(&mop->mo_ldd)) {
654 /* now as we store fids in EA on OST we need
655 to make inode bigger */
659 if (inode_size > 0) {
660 sprintf(buf, " -I %ld", inode_size);
661 strscat(mop->mo_mkfsopts, buf,
662 sizeof(mop->mo_mkfsopts));
667 strscat(mop->mo_mkfsopts, " -q",
668 sizeof(mop->mo_mkfsopts));
671 if (strstr(mop->mo_mkfsopts, "-O") == NULL)
672 enable_default_backfs_features(mop);
674 /* Allow reformat of full devices (as opposed to
675 partitions.) We already checked for mounted dev. */
676 strscat(mop->mo_mkfsopts, " -F", sizeof(mop->mo_mkfsopts));
678 snprintf(mkfs_cmd, sizeof(mkfs_cmd),
679 "mkfs.ext2 -j -b %d -L %s ", L_BLOCK_SIZE,
680 mop->mo_ldd.ldd_svname);
681 } else if (mop->mo_ldd.ldd_mount_type == LDD_MT_REISERFS) {
682 long journal_sz = 0; /* FIXME default journal size */
683 if (journal_sz > 0) {
684 sprintf(buf, " --journal_size %ld", journal_sz);
685 strscat(mop->mo_mkfsopts, buf,
686 sizeof(mop->mo_mkfsopts));
688 snprintf(mkfs_cmd, sizeof(mkfs_cmd), "mkreiserfs -ff ");
690 fprintf(stderr,"%s: unsupported fs type: %d (%s)\n",
691 progname, mop->mo_ldd.ldd_mount_type,
692 MT_STR(&mop->mo_ldd));
696 /* For loop device format the dev, not the filename */
697 dev = mop->mo_device;
698 if (mop->mo_flags & MO_IS_LOOP)
699 dev = mop->mo_loopdev;
701 vprint("formatting backing filesystem %s on %s\n",
702 MT_STR(&mop->mo_ldd), dev);
703 vprint("\ttarget name %s\n", mop->mo_ldd.ldd_svname);
704 vprint("\t4k blocks %d\n", block_count);
705 vprint("\toptions %s\n", mop->mo_mkfsopts);
707 /* mkfs_cmd's trailing space is important! */
708 strscat(mkfs_cmd, mop->mo_mkfsopts, sizeof(mkfs_cmd));
709 strscat(mkfs_cmd, " ", sizeof(mkfs_cmd));
710 strscat(mkfs_cmd, dev, sizeof(mkfs_cmd));
711 if (block_count != 0) {
712 sprintf(buf, " %d", block_count);
713 strscat(mkfs_cmd, buf, sizeof(mkfs_cmd));
716 vprint("mkfs_cmd = %s\n", mkfs_cmd);
717 ret = run_command(mkfs_cmd, sizeof(mkfs_cmd));
720 fprintf(stderr, "Unable to build fs %s (%d)\n", dev, ret);
725 /* ==================== Lustre config functions =============*/
727 void print_ldd(char *str, struct lustre_disk_data *ldd)
729 printf("\n %s:\n", str);
730 printf("Target: %s\n", ldd->ldd_svname);
731 if (ldd->ldd_svindex == INDEX_UNASSIGNED)
732 printf("Index: unassigned\n");
734 printf("Index: %d\n", ldd->ldd_svindex);
735 if (ldd->ldd_uuid[0])
736 printf("UUID: %s\n", (char *)ldd->ldd_uuid);
737 printf("Lustre FS: %s\n", ldd->ldd_fsname);
738 printf("Mount type: %s\n", MT_STR(ldd));
739 printf("Flags: %#x\n", ldd->ldd_flags);
740 printf(" (%s%s%s%s%s%s%s%s)\n",
741 IS_MDT(ldd) ? "MDT ":"",
742 IS_OST(ldd) ? "OST ":"",
743 IS_MGS(ldd) ? "MGS ":"",
744 ldd->ldd_flags & LDD_F_NEED_INDEX ? "needs_index ":"",
745 ldd->ldd_flags & LDD_F_VIRGIN ? "first_time ":"",
746 ldd->ldd_flags & LDD_F_UPDATE ? "update ":"",
747 ldd->ldd_flags & LDD_F_WRITECONF ? "writeconf ":"",
748 ldd->ldd_flags & LDD_F_UPGRADE14 ? "upgrade1.4 ":"");
749 printf("Persistent mount opts: %s\n", ldd->ldd_mount_opts);
750 printf("Parameters:%s\n", ldd->ldd_params);
751 if (ldd->ldd_userdata[0])
752 printf("Comment: %s\n", ldd->ldd_userdata);
756 /* Write the server config files */
757 int write_local_files(struct mkfs_opts *mop)
759 char mntpt[] = "/tmp/mntXXXXXX";
765 /* Mount this device temporarily in order to write these files */
766 if (!mkdtemp(mntpt)) {
767 fprintf(stderr, "%s: Can't create temp mount point %s: %s\n",
768 progname, mntpt, strerror(errno));
772 dev = mop->mo_device;
773 if (mop->mo_flags & MO_IS_LOOP)
774 dev = mop->mo_loopdev;
776 ret = mount(dev, mntpt, MT_STR(&mop->mo_ldd), 0, NULL);
778 fprintf(stderr, "%s: Unable to mount %s: %s\n",
779 progname, dev, strerror(errno));
781 if (errno == ENODEV) {
782 fprintf(stderr, "Is the %s module available?\n",
783 MT_STR(&mop->mo_ldd));
788 /* Set up initial directories */
789 sprintf(filepnm, "%s/%s", mntpt, MOUNT_CONFIGS_DIR);
790 ret = mkdir(filepnm, 0777);
791 if ((ret != 0) && (errno != EEXIST)) {
792 fprintf(stderr, "%s: Can't make configs dir %s (%s)\n",
793 progname, filepnm, strerror(errno));
795 } else if (errno == EEXIST) {
799 sprintf(filepnm, "%s/%s", mntpt, "ROOT");
800 ret = mkdir(filepnm, 0777);
801 if ((ret != 0) && (errno != EEXIST)) {
802 fprintf(stderr, "%s: Can't make ROOT dir %s (%s)\n",
803 progname, filepnm, strerror(errno));
805 } else if (errno == EEXIST) {
809 /* Save the persistent mount data into a file. Lustre must pre-read
810 this file to get the real mount options. */
811 vprint("Writing %s\n", MOUNT_DATA_FILE);
812 sprintf(filepnm, "%s/%s", mntpt, MOUNT_DATA_FILE);
813 filep = fopen(filepnm, "w");
815 fprintf(stderr, "%s: Unable to create %s file: %s\n",
816 progname, filepnm, strerror(errno));
819 fwrite(&mop->mo_ldd, sizeof(mop->mo_ldd), 1, filep);
824 /* Check for upgrade */
825 if ((mop->mo_ldd.ldd_flags & (LDD_F_UPGRADE14 | LDD_F_SV_TYPE_MGS))
826 == (LDD_F_UPGRADE14 | LDD_F_SV_TYPE_MGS)) {
829 int cmdsz = sizeof(cmd);
830 vprint("Copying old logs\n");
832 /* Copy the old client log to fsname-client */
833 sprintf(filepnm, "%s/%s/%s-client",
834 mntpt, MOUNT_CONFIGS_DIR, mop->mo_ldd.ldd_fsname);
835 snprintf(cmd, cmdsz, "cp %s/%s/client %s", mntpt, MDT_LOGS_DIR,
837 ret = run_command(cmd, cmdsz);
839 fprintf(stderr, "%s: Can't copy 1.4 config %s/client "
840 "(%d)\n", progname, MDT_LOGS_DIR, ret);
841 fprintf(stderr, "mount -t ldiskfs %s somewhere, "
842 "find the client log for fs %s and "
843 "copy it manually into %s/%s-client, "
846 mop->mo_ldd.ldd_fsname, MOUNT_CONFIGS_DIR,
847 mop->mo_ldd.ldd_fsname);
851 /* We need to use the old mdt log because otherwise mdt won't
852 have complete lov if old clients connect before all
854 /* Copy the old mdt log to fsname-MDT0000 (get old
855 name from mdt_UUID) */
857 strscpy(filepnm, (char *)mop->mo_ldd.ldd_uuid, sizeof(filepnm));
858 term = strstr(filepnm, "_UUID");
861 snprintf(cmd, cmdsz, "cp %s/%s/%s %s/%s/%s",
862 mntpt, MDT_LOGS_DIR, filepnm,
863 mntpt, MOUNT_CONFIGS_DIR,
864 mop->mo_ldd.ldd_svname);
865 ret = run_command(cmd, cmdsz);
868 fprintf(stderr, "%s: Can't copy 1.4 config %s/%s "
869 "(%d)\n", progname, MDT_LOGS_DIR, filepnm, ret);
870 fprintf(stderr, "mount -t ext3 %s somewhere, "
871 "find the MDT log for fs %s and "
872 "copy it manually into %s/%s, "
875 mop->mo_ldd.ldd_fsname, MOUNT_CONFIGS_DIR,
876 mop->mo_ldd.ldd_svname);
891 int read_local_files(struct mkfs_opts *mop)
893 char tmpdir[] = "/tmp/dirXXXXXX";
899 int cmdsz = sizeof(cmd);
901 /* Make a temporary directory to hold Lustre data files. */
902 if (!mkdtemp(tmpdir)) {
903 fprintf(stderr, "%s: Can't create temporary directory %s: %s\n",
904 progname, tmpdir, strerror(errno));
908 dev = mop->mo_device;
910 /* Construct debugfs command line. */
911 snprintf(cmd, cmdsz, "debugfs -c -R 'dump /%s %s/mountdata' %s",
912 MOUNT_DATA_FILE, tmpdir, dev);
914 ret = run_command(cmd, cmdsz);
916 verrprint("%s: Unable to dump %s dir (%d)\n",
917 progname, MOUNT_CONFIGS_DIR, ret);
919 sprintf(filepnm, "%s/mountdata", tmpdir);
920 filep = fopen(filepnm, "r");
922 vprint("Reading %s\n", MOUNT_DATA_FILE);
923 fread(&mop->mo_ldd, sizeof(mop->mo_ldd), 1, filep);
926 /* Try to read pre-1.6 config from last_rcvd */
927 struct lr_server_data lsd;
928 verrprint("%s: Unable to read %d.%d config %s.\n",
929 progname, LUSTRE_MAJOR, LUSTRE_MINOR, filepnm);
931 verrprint("Trying 1.4 config from last_rcvd\n");
932 sprintf(filepnm, "%s/%s", tmpdir, LAST_RCVD);
934 /* Construct debugfs command line. */
935 snprintf(cmd, cmdsz, "debugfs -c -R 'dump /%s %s' %s",
936 LAST_RCVD, filepnm, dev);
938 ret = run_command(cmd, cmdsz);
940 fprintf(stderr, "%s: Unable to dump %s file (%d)\n",
941 progname, LAST_RCVD, ret);
945 filep = fopen(filepnm, "r");
947 fprintf(stderr, "%s: Unable to open %s: %s\n",
948 progname, filepnm, strerror(errno));
950 verrprint("Contents of %s:\n", tmpdir);
952 snprintf(cmd, cmdsz, "ls -l %s/", tmpdir);
953 run_command(cmd, cmdsz);
954 verrprint("Contents of disk:\n");
955 snprintf(cmd, cmdsz, "debugfs -c -R 'ls -l /' %s", dev);
956 run_command(cmd, cmdsz);
960 vprint("Reading %s\n", LAST_RCVD);
961 ret = fread(&lsd, 1, sizeof(lsd), filep);
962 if (ret < sizeof(lsd)) {
963 fprintf(stderr, "%s: Short read (%d of %d)\n",
964 progname, ret, (int)sizeof(lsd));
969 vprint("Feature compat=%x, incompat=%x\n",
970 lsd.lsd_feature_compat, lsd.lsd_feature_incompat);
972 if ((lsd.lsd_feature_compat & OBD_COMPAT_OST) ||
973 (lsd.lsd_feature_incompat & OBD_INCOMPAT_OST)) {
974 mop->mo_ldd.ldd_flags = LDD_F_SV_TYPE_OST;
975 mop->mo_ldd.ldd_svindex = lsd.lsd_ost_index;
976 } else if ((lsd.lsd_feature_compat & OBD_COMPAT_MDT) ||
977 (lsd.lsd_feature_incompat & OBD_INCOMPAT_MDT)) {
978 /* We must co-locate so mgs can see old logs.
979 If user doesn't want this, they can copy the old
980 logs manually and re-tunefs. */
981 mop->mo_ldd.ldd_flags =
982 LDD_F_SV_TYPE_MDT | LDD_F_SV_TYPE_MGS;
983 mop->mo_ldd.ldd_svindex = lsd.lsd_mdt_index;
985 /* If neither is set, we're pre-1.4.6, make a guess. */
986 /* Construct debugfs command line. */
987 snprintf(cmd, cmdsz, "debugfs -c -R 'rdump /%s %s' %s",
988 MDT_LOGS_DIR, tmpdir, dev);
989 run_command(cmd, cmdsz);
991 sprintf(filepnm, "%s/%s", tmpdir, MDT_LOGS_DIR);
992 if (lsd.lsd_ost_index > 0) {
993 mop->mo_ldd.ldd_flags = LDD_F_SV_TYPE_OST;
994 mop->mo_ldd.ldd_svindex = lsd.lsd_ost_index;
996 /* If there's a LOGS dir, it's an MDT */
997 if ((ret = access(filepnm, F_OK)) == 0) {
998 mop->mo_ldd.ldd_flags =
1001 /* Old MDT's are always index 0
1003 mop->mo_ldd.ldd_svindex = 0;
1005 /* The index may not be correct */
1006 mop->mo_ldd.ldd_flags =
1007 LDD_F_SV_TYPE_OST | LDD_F_NEED_INDEX;
1008 verrprint("OST with unknown index\n");
1014 memcpy(mop->mo_ldd.ldd_uuid, lsd.lsd_uuid,
1015 sizeof(mop->mo_ldd.ldd_uuid));
1016 mop->mo_ldd.ldd_flags |= LDD_F_UPGRADE14;
1018 /* end COMPAT_146 */
1023 snprintf(cmd, cmdsz, "rm -rf %s", tmpdir);
1024 run_command(cmd, cmdsz);
1026 verrprint("Failed to read old data (%d)\n", ret);
1031 void set_defaults(struct mkfs_opts *mop)
1033 mop->mo_ldd.ldd_magic = LDD_MAGIC;
1034 mop->mo_ldd.ldd_config_ver = 1;
1035 mop->mo_ldd.ldd_flags = LDD_F_NEED_INDEX | LDD_F_UPDATE | LDD_F_VIRGIN;
1036 mop->mo_mgs_failnodes = 0;
1037 strcpy(mop->mo_ldd.ldd_fsname, "lustre");
1038 if (get_os_version() == 24)
1039 mop->mo_ldd.ldd_mount_type = LDD_MT_EXT3;
1041 mop->mo_ldd.ldd_mount_type = LDD_MT_LDISKFS;
1043 mop->mo_ldd.ldd_svindex = INDEX_UNASSIGNED;
1044 mop->mo_stripe_count = 1;
1047 static inline void badopt(const char *opt, char *type)
1049 fprintf(stderr, "%s: '--%s' only valid for %s\n",
1050 progname, opt, type);
1054 static int add_param(char *buf, char *key, char *val)
1056 int end = sizeof(((struct lustre_disk_data *)0)->ldd_params);
1057 int start = strlen(buf);
1061 keylen = strlen(key);
1062 if (start + 1 + keylen + strlen(val) >= end) {
1063 fprintf(stderr, "%s: params are too long-\n%s %s%s\n",
1064 progname, buf, key ? key : "", val);
1068 sprintf(buf + start, " %s%s", key ? key : "", val);
1072 /* from mount_lustre */
1073 /* Get rid of symbolic hostnames for tcp, since kernel can't do lookups */
1074 #define MAXNIDSTR 1024
1075 static char *convert_hostnames(char *s1)
1077 char *converted, *s2 = 0, *c;
1078 int left = MAXNIDSTR;
1081 converted = malloc(left);
1082 if (converted == NULL) {
1087 while ((left > 0) && ((s2 = strsep(&s1, ",: \0")))) {
1088 nid = libcfs_str2nid(s2);
1089 if (nid == LNET_NID_ANY) {
1093 fprintf(stderr, "%s: Can't parse NID '%s'\n",
1099 if (strncmp(libcfs_nid2str(nid), "127.0.0.1",
1100 strlen("127.0.0.1")) == 0) {
1101 fprintf(stderr, "%s: The NID '%s' resolves to the "
1102 "loopback address '%s'. Lustre requires a "
1103 "non-loopback address.\n",
1104 progname, s2, libcfs_nid2str(nid));
1109 c += snprintf(c, left, "%s,", libcfs_nid2str(nid));
1110 left = converted + MAXNIDSTR - c;
1116 int parse_opts(int argc, char *const argv[], struct mkfs_opts *mop,
1119 static struct option long_opt[] = {
1120 {"backfstype", 1, 0, 'b'},
1121 {"stripe-count-hint", 1, 0, 'c'},
1122 {"comment", 1, 0, 'u'},
1123 {"configdev", 1, 0, 'C'},
1124 {"device-size", 1, 0, 'd'},
1125 {"dryrun", 0, 0, 'n'},
1126 {"erase-params", 0, 0, 'e'},
1127 {"failnode", 1, 0, 'f'},
1128 {"failover", 1, 0, 'f'},
1130 {"help", 0, 0, 'h'},
1131 {"index", 1, 0, 'i'},
1132 {"mkfsoptions", 1, 0, 'k'},
1133 {"mgsnode", 1, 0, 'm'},
1134 {"mgsnid", 1, 0, 'm'},
1136 {"fsname",1, 0, 'L'},
1137 {"noformat", 0, 0, 'n'},
1138 {"nomgs", 0, 0, 'N'},
1139 {"mountfsoptions", 1, 0, 'o'},
1141 {"param", 1, 0, 'p'},
1142 {"print", 0, 0, 'n'},
1143 {"quiet", 0, 0, 'q'},
1144 {"reformat", 0, 0, 'r'},
1145 {"verbose", 0, 0, 'v'},
1146 {"writeconf", 0, 0, 'w'},
1149 char *optstring = "b:c:C:d:ef:Ghi:k:L:m:MnNo:Op:Pqru:vw";
1153 while ((opt = getopt_long(argc, argv, optstring, long_opt, &longidx)) !=
1158 while (i < LDD_MT_LAST) {
1159 if (strcmp(optarg, mt_str(i)) == 0) {
1160 mop->mo_ldd.ldd_mount_type = i;
1168 if (IS_MDT(&mop->mo_ldd)) {
1169 int stripe_count = atol(optarg);
1170 if (stripe_count <= 0) {
1171 fprintf(stderr, "%s: bad stripe count "
1172 "%d\n", progname, stripe_count);
1175 mop->mo_stripe_count = stripe_count;
1177 badopt(long_opt[longidx].name, "MDT");
1181 case 'C': /* Configdev */
1183 printf("Configdev not implemented\n");
1186 mop->mo_device_sz = atol(optarg);
1189 mop->mo_ldd.ldd_params[0] = '\0';
1190 /* Must update the mgs logs */
1191 mop->mo_ldd.ldd_flags |= LDD_F_UPDATE;
1194 char *nids = convert_hostnames(optarg);
1197 rc = add_param(mop->mo_ldd.ldd_params, PARAM_FAILNODE,
1202 /* Must update the mgs logs */
1203 mop->mo_ldd.ldd_flags |= LDD_F_UPDATE;
1208 mop->mo_ldd.ldd_flags |= LDD_F_SV_TYPE_MGS;
1214 if (!(mop->mo_ldd.ldd_flags &
1215 (LDD_F_UPGRADE14 | LDD_F_VIRGIN |
1216 LDD_F_WRITECONF))) {
1217 fprintf(stderr, "%s: cannot change the index of"
1218 " a registered target\n", progname);
1221 if (IS_MDT(&mop->mo_ldd) || IS_OST(&mop->mo_ldd)) {
1222 mop->mo_ldd.ldd_svindex = atol(optarg);
1223 mop->mo_ldd.ldd_flags &= ~LDD_F_NEED_INDEX;
1225 badopt(long_opt[longidx].name, "MDT,OST");
1230 strscpy(mop->mo_mkfsopts, optarg,
1231 sizeof(mop->mo_mkfsopts));
1235 if (!(mop->mo_flags & MO_FORCEFORMAT) &&
1236 (!(mop->mo_ldd.ldd_flags &
1237 (LDD_F_UPGRADE14 | LDD_F_VIRGIN |
1238 LDD_F_WRITECONF)))) {
1239 fprintf(stderr, "%s: cannot change the name of"
1240 " a registered target\n", progname);
1243 if ((strlen(optarg) < 1) || (strlen(optarg) > 8)) {
1244 fprintf(stderr, "%s: filesystem name must be "
1245 "1-8 chars\n", progname);
1248 if ((tmp = strpbrk(optarg, "/:"))) {
1249 fprintf(stderr, "%s: char '%c' not allowed in "
1250 "filesystem name\n", progname, *tmp);
1253 strscpy(mop->mo_ldd.ldd_fsname, optarg,
1254 sizeof(mop->mo_ldd.ldd_fsname));
1258 char *nids = convert_hostnames(optarg);
1261 rc = add_param(mop->mo_ldd.ldd_params, PARAM_MGSNODE,
1266 mop->mo_mgs_failnodes++;
1270 mop->mo_ldd.ldd_flags |= LDD_F_SV_TYPE_MDT;
1276 mop->mo_ldd.ldd_flags &= ~LDD_F_SV_TYPE_MGS;
1279 *mountopts = optarg;
1282 mop->mo_ldd.ldd_flags |= LDD_F_SV_TYPE_OST;
1285 rc = add_param(mop->mo_ldd.ldd_params, NULL, optarg);
1288 /* Must update the mgs logs */
1289 mop->mo_ldd.ldd_flags |= LDD_F_UPDATE;
1295 mop->mo_flags |= MO_FORCEFORMAT;
1298 strscpy(mop->mo_ldd.ldd_userdata, optarg,
1299 sizeof(mop->mo_ldd.ldd_userdata));
1305 mop->mo_ldd.ldd_flags |= LDD_F_WRITECONF;
1310 fprintf(stderr, "Unknown option '%c'\n", opt);
1316 /* Last arg is device */
1317 if (optind != argc - 1) {
1319 fprintf(stderr, "Bad argument: %s\n", argv[optind]);
1326 #include <lustre/libiam.h>
1328 #define LDISKFS_IOC_GETVERSION _IOR('f', 3, long)
1330 #ifndef TUNEFS /* mkfs.lustre */
1331 static int mkfs_iam_insert(int key_need_convert, char *keybuf,
1332 int rec_need_convert, char *recbuf, char *filename)
1336 struct iam_uapi_info ua;
1338 fd = iam_open(filename, &ua);
1340 fprintf(stderr, "failed to iam_open %s\n", filename);
1344 ret = iam_insert(fd, &ua,
1345 key_need_convert, keybuf,
1346 rec_need_convert, recbuf);
1349 fprintf(stderr, "failed to iam_insert %s\n", filename);
1356 static int touch_file(char *filename)
1360 if (filename == NULL) {
1364 fd = open(filename, O_CREAT | O_TRUNC, 0600);
1373 static int get_generation(char *filename, unsigned long *result)
1378 if (filename == NULL) {
1382 fd = open(filename, O_RDONLY);
1384 fprintf(stderr, "%s: failed to open %s\n",
1385 __FUNCTION__, filename);
1389 ret = ioctl(fd, LDISKFS_IOC_GETVERSION, result);
1392 return ((ret < 0) ? ret : 0);
1395 static int mkfs_mdt(struct mkfs_opts *mop)
1397 char mntpt[] = "/tmp/mntXXXXXX";
1398 char fstype[] = "ldiskfs";
1403 unsigned long generation;
1406 source = mop->mo_device;
1407 if (mop->mo_flags & MO_IS_LOOP) {
1408 source = mop->mo_loopdev;
1411 if ((source == NULL) || (*source == 0)) {
1415 if (!mkdtemp(mntpt)) {
1416 fprintf(stderr, "%s: failed to mkdtemp %s\n",
1417 __FUNCTION__, mntpt);
1421 ret = mount(source, mntpt, fstype, 0, NULL);
1426 snprintf(filepnm, sizeof(filepnm) - 1, "%s/%s", mntpt, "seq_ctl");
1427 ret = touch_file(filepnm);
1432 snprintf(filepnm, sizeof(filepnm) - 1, "%s/%s", mntpt, "seq_srv");
1433 ret = touch_file(filepnm);
1438 snprintf(filepnm, sizeof(filepnm) - 1, "%s/%s", mntpt, "last_received");
1439 ret = touch_file(filepnm);
1444 snprintf(filepnm, sizeof(filepnm) - 1, "%s/%s", mntpt, "lov_objid");
1445 ret = touch_file(filepnm);
1450 snprintf(filepnm, sizeof(filepnm) - 1, "%s/%s", mntpt, "root");
1451 ret = iam_creat(filepnm, FMT_LVAR, L_BLOCK_SIZE, 4, 17, 4);
1456 snprintf(filepnm, sizeof(filepnm) - 1, "%s/%s", mntpt, "fld");
1457 ret = iam_creat(filepnm, FMT_LFIX, L_BLOCK_SIZE, 8, 8, 4);
1462 snprintf(filepnm, sizeof(filepnm) - 1, "%s/%s", mntpt, "orphans");
1463 ret = iam_creat(filepnm, FMT_LFIX, L_BLOCK_SIZE, 20, 8, 4);
1468 snprintf(filepnm, sizeof(filepnm) - 1, "%s/%s", mntpt, "oi.16");
1469 ret = iam_creat(filepnm, FMT_LFIX, L_BLOCK_SIZE, 16, 8, 4);
1474 snprintf(filepnm, sizeof(filepnm) - 1, "%s/%s", mntpt, "oi.5");
1475 ret = iam_creat(filepnm, FMT_LFIX, L_BLOCK_SIZE, 5, 8, 4);
1480 snprintf(filepnm, sizeof(filepnm) - 1, "%s/%s", mntpt, CAPA_KEYS);
1481 ret = touch_file(filepnm);
1487 ret = mount(source, mntpt, fstype, 0, NULL);
1492 snprintf(filepnm, sizeof(filepnm) - 1, "%s/%s", mntpt, "root");
1493 ret = iam_polymorph(filepnm, 040755);
1495 perror("IAM_IOC_POLYMORPH");
1500 ret = mount(source, mntpt, fstype, 0, NULL);
1505 snprintf(filepnm, sizeof(filepnm) - 1, "%s/%s", mntpt, "fld");
1506 ret = mkfs_iam_insert(1, "0000000000000002", 1, "0000000000000000", filepnm);
1511 ret = mkfs_iam_insert(1, "0000000000000001", 1, "0000000000000000", filepnm);
1516 snprintf(filepnm, sizeof(filepnm) - 1, "%s/%s", mntpt, "root");
1517 ret = stat(filepnm, &st);
1522 ret = get_generation(filepnm, &generation);
1527 snprintf(recbuf, sizeof(recbuf) - 1, "110000000000000001%8.8x%8.8x",
1528 (unsigned int)st.st_ino, (unsigned int)generation);
1529 ret = mkfs_iam_insert(0, ".", 1, recbuf, filepnm);
1534 ret = mkfs_iam_insert(0, "..", 1, recbuf, filepnm);
1547 int main(int argc, char *const argv[])
1549 struct mkfs_opts mop;
1550 struct lustre_disk_data *ldd;
1551 char *mountopts = NULL;
1552 char always_mountopts[512] = "";
1553 char default_mountopts[512] = "";
1556 if ((progname = strrchr(argv[0], '/')) != NULL)
1561 if ((argc < 2) || (argv[argc - 1][0] == '-')) {
1566 memset(&mop, 0, sizeof(mop));
1569 /* device is last arg */
1570 strscpy(mop.mo_device, argv[argc - 1], sizeof(mop.mo_device));
1572 /* Are we using a loop device? */
1573 ret = is_block(mop.mo_device);
1577 mop.mo_flags |= MO_IS_LOOP;
1580 /* For tunefs, we must read in the old values before parsing any
1583 /* Check whether the disk has already been formatted by mkfs.lustre */
1584 ret = is_lustre_target(&mop);
1587 fprintf(stderr, "Device %s has not been formatted with "
1588 "mkfs.lustre\n", mop.mo_device);
1593 ret = read_local_files(&mop);
1596 fprintf(stderr, "Failed to read previous Lustre data from %s "
1597 "(%d)\n", mop.mo_device, ret);
1600 if (strstr(mop.mo_ldd.ldd_params, PARAM_MGSNODE))
1601 mop.mo_mgs_failnodes++;
1604 print_ldd("Read previous values", &(mop.mo_ldd));
1607 ret = parse_opts(argc, argv, &mop, &mountopts);
1613 if (!(IS_MDT(ldd) || IS_OST(ldd) || IS_MGS(ldd))) {
1615 fprintf(stderr, "must set target type: MDT,OST,MGS\n");
1620 if (((IS_MDT(ldd) || IS_MGS(ldd))) && IS_OST(ldd)) {
1622 fprintf(stderr, "OST type is exclusive with MDT,MGS\n");
1627 if ((mop.mo_ldd.ldd_flags & (LDD_F_NEED_INDEX | LDD_F_UPGRADE14)) ==
1628 (LDD_F_NEED_INDEX | LDD_F_UPGRADE14)) {
1630 fprintf(stderr, "Can't find the target index, "
1631 "specify with --index\n");
1637 * Comment out these 2 checks temporarily, since for multi-MDSes
1638 * in single node only 1 mds node could have mgs service
1640 if (IS_MDT(ldd) && !IS_MGS(ldd) && (mop.mo_mgs_failnodes == 0)) {
1641 verrprint("No management node specified, adding MGS to this "
1643 ldd->ldd_flags |= LDD_F_SV_TYPE_MGS;
1645 if (!IS_MGS(ldd) && (mop.mo_mgs_failnodes == 0)) {
1648 fprintf(stderr, "Must specify --mgs or --mgsnode=\n");
1650 fprintf(stderr, "Must specify --mgsnode=\n");
1656 /* These are the permanent mount options (always included) */
1657 switch (ldd->ldd_mount_type) {
1659 case LDD_MT_LDISKFS:
1660 case LDD_MT_LDISKFS2: {
1661 sprintf(always_mountopts, "errors=remount-ro");
1662 if (IS_MDT(ldd) || IS_MGS(ldd))
1663 strscat(always_mountopts, ",iopen_nopriv,user_xattr",
1664 sizeof(always_mountopts));
1665 if ((get_os_version() == 24) && IS_OST(ldd))
1666 strscat(always_mountopts, ",asyncdel",
1667 sizeof(always_mountopts));
1668 /* NB: Files created while extents are enabled cannot be read
1669 if mounted with a kernel that doesn't include the CFS
1672 (ldd->ldd_mount_type == LDD_MT_LDISKFS ||
1673 ldd->ldd_mount_type == LDD_MT_LDISKFS2)) {
1674 strscat(default_mountopts, ",extents,mballoc",
1675 sizeof(default_mountopts));
1680 mop.mo_flags |= MO_IS_LOOP;
1681 sprintf(always_mountopts, "type=ext3,dev=%s",
1687 fprintf(stderr, "unknown fs type %d '%s'\n",
1688 ldd->ldd_mount_type,
1696 /* If user specifies mount opts, don't use defaults,
1697 but always use always_mountopts */
1698 sprintf(ldd->ldd_mount_opts, "%s,%s",
1699 always_mountopts, mountopts);
1702 if (ldd->ldd_mount_opts[0] == 0)
1703 /* use the defaults unless old opts exist */
1706 sprintf(ldd->ldd_mount_opts, "%s%s",
1707 always_mountopts, default_mountopts);
1711 server_make_name(ldd->ldd_flags, ldd->ldd_svindex,
1712 ldd->ldd_fsname, ldd->ldd_svname);
1715 print_ldd("Permanent disk data", ldd);
1718 printf("exiting before disk write.\n");
1722 if (check_mtab_entry(mop.mo_device))
1725 /* Create the loopback file */
1726 if (mop.mo_flags & MO_IS_LOOP) {
1727 ret = access(mop.mo_device, F_OK);
1730 #ifndef TUNEFS /* mkfs.lustre */
1731 /* Reformat the loopback file */
1732 if (ret || (mop.mo_flags & MO_FORCEFORMAT))
1733 ret = loop_format(&mop);
1736 ret = loop_setup(&mop);
1739 fprintf(stderr, "Loop device setup for %s failed: %s\n",
1740 mop.mo_device, strerror(ret));
1745 #ifndef TUNEFS /* mkfs.lustre */
1746 /* Check whether the disk has already been formatted by mkfs.lustre */
1747 if (!(mop.mo_flags & MO_FORCEFORMAT)) {
1748 ret = is_lustre_target(&mop);
1751 fprintf(stderr, "Device %s was previously formatted "
1752 "for lustre. Use --reformat to reformat it, "
1753 "or tunefs.lustre to modify.\n",
1759 /* Format the backing filesystem */
1760 ret = make_lustre_backfs(&mop);
1763 fprintf(stderr, "mkfs failed %d\n", ret);
1768 /* Write our config files */
1769 ret = write_local_files(&mop);
1772 fprintf(stderr, "failed to write local files\n");
1776 #ifndef TUNEFS /* mkfs.lustre */
1778 ret = mkfs_mdt(&mop);
1780 fprintf(stderr, "failed to mkfs_mdt\n");
1789 /* Fix any crazy return values from system() */
1790 if (ret && ((ret & 255) == 0))
1793 verrprint("%s: exiting with %d (%s)\n",
1794 progname, ret, strerror(ret));