4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2011, 2017, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
30 * Lustre is a trademark of Sun Microsystems, Inc.
32 * lustre/utils/mount_lustre.c
34 * Author: Robert Read <rread@clusterfs.com>
35 * Author: Nathan Rutman <nathan@clusterfs.com>
50 #include <sys/mount.h>
51 #include <sys/param.h>
52 #include <linux/lustre/lustre_ver.h>
55 #include <linux/lnet/nidstr.h>
56 #include <libcfs/util/string.h>
59 #include "mount_utils.h"
61 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 10, 53, 0)
64 * We only #include a kernel level include file here because
65 * important MS_ flag #defines are missing from the SLES version
67 * In the future if SLES updates sys/mount.h to have a more complete
68 * set of flag #defines we should stop including linux/fs.h
70 #if !defined(MS_RDONLY)
76 # define WITH_LIBMOUNT "(libmount)"
78 # define WITH_LIBMOUNT ""
81 #define MAX_RETRIES 99
89 fprintf(out, "\nThis mount helper should only be invoked via the "
90 "mount (8) command,\ne.g. mount -t lustre dev dir\n\n");
91 fprintf(out, "usage: %s [-fhnvV] [-o <srvopt>] <device> <mountpt>\n",
93 fprintf(out, "usage: %s [-fhnvV] [-o <cliopt>] <mgstarget> <mountpt>\n",
96 "\t<device>: the local disk device when mounting a server\n"
97 "\t<mgstarget>: the server MGS and filesystem for a client:\n"
98 "\t\t<mgsnid>[:<altmgsnid>...]:/<filesystem>[/<subdir>]\n"
99 "\t\t\t<mgsnid>: MGS LNet Node Identifier (e.g. mgs01@o2ib)\n"
100 "\t\t\t<filesystem>: Lustre filesystem name (e.g. lustre1)\n"
101 "\t\t\t<subdir>: subdirectory of the filesystem to mount\n"
102 "\t<mountpt>: filesystem mountpoint (e.g. /mnt/lustre)\n"
103 "\t-f|--fake: fake mount (only update /etc/mtab)\n"
104 "\t-o force|--force: force mount even if already in /etc/mtab\n"
105 "\t-h|--help: print this usage message\n"
106 "\t-n|--nomtab: do not update /etc/mtab after mount\n"
107 "\t-v|--verbose: print verbose config settings\n"
108 "\t-V|--version: output build version of the utility and exit\n"
109 "\tdefault options are marked below with '*'\n"
110 "\t\t(no)flock: disable* or enable POSIX flock support\n"
111 "\t\t(no)user_xattr: disable or enable* user xattr namespace\n"
112 "\t<srvopt>: one or more comma separated server options:\n"
113 "\t\t(no)acl: disable or enable* POSIX ACL support completely\n"
114 "\t\tabort_recov: abort server recovery handling\n"
115 "\t\tnosvc: only start MGC/MGS without starting MDS/OSS\n"
116 "\t\tnomgs: only start target MDS/OSS, using existing MGS\n"
117 "\t\tnoscrub: do NOT auto start OI scrub unless requested\n"
118 "\t\tskip_lfsck: do NOT auto resume paused/crashed LFSCK\n"
119 "\t\tmd_stripe_cache_size=<num>: set MD RAID device stripe cache size\n"
120 "\t<cliopt>: one or more comma separated client options:\n"
121 "\t\texclude=<ostname>[:<ostname>]: list of inactive OSTs (e.g. lustre-OST0001)\n"
122 "\t\tlocalflock: enable POSIX flock only on local client\n"
123 "\t\tretry=<num>: number of times mount is retried by client\n"
125 "\t\tskpath=<file|directory>: path of keys to load into kernel keyring\n"
127 "\t\t(no)user_fid2path: disable* or enable user $MOUNT/.lustre/fid access\n"
128 "\t\t(no)checksum: disable or enable* data checksums\n"
129 "\t\t(no)lruresize: disable or enable* LDLM dynamic LRU size\n"
130 "\t\t(no)lazystatfs: disable or enable* statfs to work if OST is unavailable\n"
131 "\t\t32bitapi: return only 32-bit inode numbers to userspace\n"
132 "\t\t(no)verbose: disable or enable* messages at filesystem (un,re)mount\n"
134 exit((out != stdout) ? EINVAL : 0);
137 /* Get rid of symbolic hostnames for tcp, since kernel can't do lookups */
138 #define MAXNIDSTR 1024
139 static char *convert_hostnames(char *s1)
141 char *converted, *s2 = 0, *c;
143 int left = MAXNIDSTR;
146 converted = malloc(left);
147 if (converted == NULL) {
148 fprintf(stderr, "out of memory: needed %d bytes\n",
153 while ((left > 0) && (*s1 != '/')) {
154 s2 = strpbrk(s1, ",:");
159 nid = libcfs_str2nid(s1);
160 *s2 = sep; /* back to original string */
161 if (nid == LNET_NID_ANY)
163 c += snprintf(c, left, "%s%c", libcfs_nid2str(nid), sep);
164 left = converted + MAXNIDSTR - c;
167 snprintf(c, left, "%s", s1);
170 fprintf(stderr, "%s: Can't parse NID '%s'\n", progname, s1);
175 /*****************************************************************************
177 * This part was cribbed from util-linux/mount/mount.c. There was no clear
178 * license information, but many other files in the package are identified as
179 * GNU GPL, so it's a pretty safe bet that was their intent.
181 ****************************************************************************/
183 const char *opt; /* option name */
184 int inv; /* true if flag value should be inverted */
185 int mask; /* flag mask value */
188 static const struct opt_map opt_map[] = {
189 /* these flags are parsed by mount, not Lustre */
190 { .opt = "async", .mask = MS_SYNCHRONOUS, .inv = 1 }, /* asynchronous I/O */
191 { .opt = "atime", .mask = MS_NOATIME, .inv = 1 }, /* set access time */
192 { .opt = "auto" }, /* allow auto mount */
193 { .opt = "defaults" }, /* default options */
194 { .opt = "dev", .mask = MS_NODEV, .inv = 1 }, /* interpret devs */
195 { .opt = "exec", .mask = MS_NOEXEC, .inv = 1 }, /* allow execution */
197 { .opt = "noatime", .mask = MS_NOATIME }, /* do not set atime */
198 { .opt = "noauto" }, /* mount explicitly */
199 { .opt = "nodev", .mask = MS_NODEV }, /* no interpret devs */
200 { .opt = "noowner", .inv = 1 }, /* no special privs */
201 { .opt = "nosuid", .mask = MS_NOSUID }, /* do not honor suid */
202 { .opt = "nouser", .inv = 1 }, /* users cannot mount */
203 { .opt = "nousers", .inv = 1 }, /* users cannot mount */
204 { .opt = "_netdev" }, /* network only */
205 { .opt = "noexec", .mask = MS_NOEXEC }, /* no execute */
206 { .opt = "remount", .mask = MS_REMOUNT }, /* remount */
207 { .opt = "ro", .mask = MS_RDONLY }, /* read-only */
208 { .opt = "rw", .mask = MS_RDONLY, .inv = 1 }, /* read-write */
209 { .opt = "suid", .mask = MS_NOSUID, .inv = 1 }, /* honor suid */
210 { .opt = "sync", .mask = MS_SYNCHRONOUS }, /* synchronous I/O */
212 { .opt = "diratime", /* set access time */
213 .mask = MS_NODIRATIME, .inv = 1 }, /* on read */
214 { .opt = "nodiratime", /* do not set access */
215 .mask = MS_NODIRATIME }, /* time on read */
218 { .opt = "norelatime", /* do not set rel */
219 .mask = MS_RELATIME, .inv = 1 }, /* access time */
220 { .opt = "relatime", /* set relative */
221 .mask = MS_RELATIME }, /* access time */
223 #ifdef MS_STRICTATIME
224 { .opt = "strictatime",
225 .mask = MS_STRICTATIME }, /* strict access time */
228 /****************************************************************************/
230 /* 1 = don't pass on to lustre
231 0 = pass on to lustre */
232 static int parse_one_option(const char *check, int *flagp)
234 const struct opt_map *opt;
236 for (opt = &opt_map[0]; opt->opt != NULL; opt++) {
237 if (strncmp(check, opt->opt, strlen(opt->opt)) == 0) {
240 *flagp &= ~(opt->mask);
247 /* Assume any unknown options are valid and pass them on. The mount
248 will fail if lmd_parse, ll_options or ldiskfs doesn't recognize it.*/
252 static size_t merge_strings(char *dst, const char *src, size_t size)
254 size_t dsize = strlen(dst);
255 size_t len = strlen(src);
256 size_t ret = dsize + len;
262 memcpy(dst, src, len);
267 static int append_option(char *options, size_t options_len,
268 const char *param, const char *value)
272 if (options[0] != '\0') {
273 rc = merge_strings(options, ",", options_len);
274 if (rc >= options_len)
278 rc = merge_strings(options, param, options_len);
279 if (rc >= options_len)
283 rc = merge_strings(options, value, options_len);
284 if (rc >= options_len)
289 fprintf(stderr, "error: mount options %s%s too long\n", param, value);
293 /* Replace options with subset of Lustre-specific options, and
294 fill in mount flags */
295 int parse_options(struct mount_opts *mop, char *orig_options,
296 int *flagp, size_t options_len)
298 char *options, *opt, *nextopt, *arg, *val;
301 options = calloc(strlen(orig_options) + 1, 1);
306 nextopt = orig_options;
307 while ((opt = strsep(&nextopt, ","))) {
312 /* Handle retries in a slightly different manner */
314 val = strchr(opt, '=');
315 /* please note that some ldiskfs mount options are also in
316 * the form of param=value. We should pay attention not to
317 * remove those mount options, see bug 22097. */
318 if (val && strncmp(arg, "max_sectors_kb", 14) == 0) {
319 mop->mo_max_sectors_kb = atoi(val + 1);
321 strncmp(arg, "md_stripe_cache_size", 20) == 0) {
322 mop->mo_md_stripe_cache_size = atoi(val + 1);
323 } else if (val && strncmp(arg, "retry", 5) == 0) {
324 mop->mo_retry = atoi(val + 1);
325 if (mop->mo_retry > MAX_RETRIES)
326 mop->mo_retry = MAX_RETRIES;
327 else if (mop->mo_retry < 0)
329 } else if (val && strncmp(arg, "mgssec", 6) == 0) {
330 rc = append_option(options, options_len, opt, NULL);
333 } else if (strncmp(arg, "nosvc", 5) == 0) {
335 rc = append_option(options, options_len, opt, NULL);
338 } else if (strcmp(opt, "force") == 0) {
339 /* XXX special check for 'force' option */
341 printf("force: %d\n", mop->mo_force);
343 } else if (val && strncmp(opt, "skpath=", 7) == 0) {
344 if (strlen(val) + 1 >= sizeof(mop->mo_skpath)) {
346 "%s: shared key path too long\n",
351 strncpy(mop->mo_skpath, val + 1, strlen(val + 1));
353 } else if (parse_one_option(opt, flagp) == 0) {
354 /* pass this on as an option */
355 rc = append_option(options, options_len, opt, NULL);
360 #ifdef MS_STRICTATIME
361 #if LUSTRE_VERSION_CODE > OBD_OCD_VERSION(3, 2, 53, 0)
364 * In the future when upstream fixes land in all supported kernels
365 * we should stop forcing MS_STRICTATIME in lustre mounts.
366 * We override the kernel level default of MS_RELATIME for now
367 * due to a kernel vfs level bug in atime updates that fails
368 * to reset timestamps from the future.
370 #warn "remove MS_STRICTATIME override if kernel updates atime from the future"
372 /* set strictatime to default if NOATIME or RELATIME
373 not given explicit */
374 if (!(*flagp & (MS_NOATIME | MS_RELATIME)))
375 *flagp |= MS_STRICTATIME;
377 strcpy(orig_options, options);
384 #ifdef HAVE_SERVER_SUPPORT
385 /* Add mgsnids from ldd params */
386 static int add_mgsnids(struct mount_opts *mop, char *options,
387 const char *params, size_t options_len)
389 char *ptr = (char *)params;
393 while ((ptr = strstr(ptr, PARAM_MGSNODE)) != NULL) {
394 sep = strchr(ptr, ' ');
399 rc = append_option(options, options_len, ptr, NULL);
402 mop->mo_have_mgsnid++;
415 static int clear_update_ondisk(char *source, struct lustre_disk_data *ldd)
417 char wanted_mountopts[512] = "";
418 struct mkfs_opts mkop;
422 memset(&mkop, 0, sizeof(mkop));
424 mkop.mo_ldd.ldd_flags &= ~LDD_F_UPDATE;
425 mkop.mo_flags = MO_NOHOSTID_CHECK; /* Ignore missing hostid */
426 if (strlen(source) > sizeof(mkop.mo_device)-1) {
428 fprintf(stderr, "Device name too long: %s\n", source);
431 strncpy(mkop.mo_device, source, sizeof(mkop.mo_device));
433 ret = osd_prepare_lustre(&mkop,
434 wanted_mountopts, sizeof(wanted_mountopts));
437 fprintf(stderr, "Can't prepare device %s: %s\n",
438 source, strerror(ret));
442 /* Create the loopback file */
443 if (mkop.mo_flags & MO_IS_LOOP) {
444 ret = access(mkop.mo_device, F_OK);
448 fprintf(stderr, "Can't access device %s: %s\n",
449 source, strerror(ret));
453 ret = loop_setup(&mkop);
456 fprintf(stderr, "Loop device setup for %s failed: %s\n",
457 mkop.mo_device, strerror(ret));
461 ret = osd_write_ldd(&mkop);
464 fprintf(stderr, "failed to write local files: %s\n",
468 ret2 = loop_cleanup(&mkop);
475 static int parse_ldd(char *source, struct mount_opts *mop,
476 char *options, size_t options_len)
478 struct lustre_disk_data *ldd = &mop->mo_ldd;
483 rc = osd_is_lustre(source, &ldd->ldd_mount_type);
485 fprintf(stderr, "%s: %s has not been formatted with mkfs.lustre"
486 " or the backend filesystem type is not supported by "
487 "this tool\n", progname, source);
491 rc = osd_read_ldd(source, ldd);
493 fprintf(stderr, "%s: %s failed to read permanent mount"
494 " data: %s\n", progname, source,
495 rc >= 0 ? strerror(rc) : "");
499 if ((IS_MDT(ldd) || IS_OST(ldd)) &&
500 (ldd->ldd_flags & LDD_F_NEED_INDEX)) {
501 fprintf(stderr, "%s: %s has no index assigned "
502 "(probably formatted with old mkfs)\n",
507 if (ldd->ldd_flags & LDD_F_UPDATE)
508 clear_update_ondisk(source, ldd);
510 /* Since we never rewrite ldd, ignore temp flags */
511 ldd->ldd_flags &= ~(LDD_F_VIRGIN | LDD_F_WRITECONF);
513 /* This is to make sure default options go first */
514 temp_options = strdup(options);
515 if (temp_options == NULL) {
516 fprintf(stderr, "%s: can't allocate memory for temp_options\n",
520 strncpy(options, ldd->ldd_mount_opts, options_len);
521 rc = append_option(options, options_len, temp_options, NULL);
526 /* svname of the form lustre:OST1234 means never registered */
527 rc = strlen(ldd->ldd_svname);
528 if (strcmp(ldd->ldd_svname, "MGS") != 0) {
530 fprintf(stderr, "%s: invalid name '%s'\n",
531 progname, ldd->ldd_svname);
533 } else if (ldd->ldd_svname[rc - 8] == ':') {
534 ldd->ldd_svname[rc - 8] = '-';
535 ldd->ldd_flags |= LDD_F_VIRGIN;
536 } else if (ldd->ldd_svname[rc - 8] == '=') {
537 ldd->ldd_svname[rc - 8] = '-';
538 ldd->ldd_flags |= LDD_F_WRITECONF;
541 /* backend osd type */
542 rc = append_option(options, options_len, "osd=",
543 mt_type(ldd->ldd_mount_type));
547 if (!mop->mo_have_mgsnid) {
548 /* Only use disk data if mount -o mgsnode=nid wasn't
550 if (ldd->ldd_flags & LDD_F_SV_TYPE_MGS) {
551 rc = append_option(options, options_len, "mgs", NULL);
554 mop->mo_have_mgsnid++;
556 if (add_mgsnids(mop, options, ldd->ldd_params,
561 /* Better have an mgsnid by now */
562 if (!mop->mo_have_mgsnid) {
563 fprintf(stderr, "%s: missing option mgsnode=<nid>\n",
568 if (ldd->ldd_flags & LDD_F_VIRGIN) {
569 rc = append_option(options, options_len, "virgin", NULL);
573 if (ldd->ldd_flags & LDD_F_UPDATE) {
574 rc = append_option(options, options_len, "update", NULL);
578 if (ldd->ldd_flags & LDD_F_WRITECONF) {
579 rc = append_option(options, options_len, "writeconf", NULL);
583 if (ldd->ldd_flags & LDD_F_NO_PRIMNODE) {
584 rc = append_option(options, options_len, "noprimnode", NULL);
589 /* prefix every lustre parameter with param= so that in-kernel
590 * mount can recognize them properly and send to MGS at registration */
591 start = ldd->ldd_params;
592 while (start && *start != '\0') {
593 while (*start == ' ') start++;
597 start = strchr(cur, ' ');
602 rc = append_option(options, options_len, "param=", cur);
607 /* svname must be last option */
608 rc = append_option(options, options_len, "svname=", ldd->ldd_svname);
612 #endif /* HAVE_SERVER_SUPPORT */
614 static void set_defaults(struct mount_opts *mop)
616 memset(mop, 0, sizeof(*mop));
617 mop->mo_usource = NULL;
618 mop->mo_source = NULL;
623 mop->mo_have_mgsnid = 0;
624 mop->mo_md_stripe_cache_size = 16384;
625 mop->mo_orig_options = "";
627 mop->mo_max_sectors_kb = -1;
630 static int parse_opts(int argc, char *const argv[], struct mount_opts *mop)
632 static struct option long_opts[] = {
633 { .val = 1, .name = "force", .has_arg = no_argument },
634 { .val = 'f', .name = "fake", .has_arg = no_argument },
635 { .val = 'h', .name = "help", .has_arg = no_argument },
636 { .val = 'n', .name = "nomtab", .has_arg = no_argument },
637 { .val = 'o', .name = "options", .has_arg = required_argument },
638 { .val = 'v', .name = "verbose", .has_arg = no_argument },
639 { .val = 'V', .name = "version", .has_arg = no_argument },
641 char real_path[PATH_MAX] = {'\0'};
643 char path[256], name[256];
648 while ((opt = getopt_long(argc, argv, "fhno:vV",
649 long_opts, NULL)) != EOF){
653 printf("force: %d\n", mop->mo_force);
657 printf("fake: %d\n", mop->mo_fake);
664 printf("nomtab: %d\n", mop->mo_nomtab);
667 mop->mo_orig_options = optarg;
674 fprintf(stdout, "%s %s %s\n", progname,
675 LUSTRE_VERSION_STRING, WITH_LIBMOUNT);
678 fprintf(stderr, "%s: unknown option '%c'\n",
685 if (optind + 2 > argc) {
686 fprintf(stderr, "%s: too few arguments\n", progname);
690 mop->mo_usource = argv[optind];
691 if (!mop->mo_usource) {
696 * Try to get the real path to the device, in case it is a
697 * symbolic link for instance
699 if (realpath(mop->mo_usource, real_path) != NULL) {
700 ptr = strrchr(real_path, '/');
701 if (ptr && strncmp(ptr, "/dm-", 4) == 0 && isdigit(*(ptr + 4))) {
702 snprintf(path, sizeof(path), "/sys/block/%s/dm/name", ptr+1);
703 if ((f = fopen(path, "r"))) {
704 /* read "<name>\n" from sysfs */
705 if (fgets(name, sizeof(name), f) && (sz = strlen(name)) > 1) {
707 snprintf(real_path, sizeof(real_path), "/dev/mapper/%s", name);
712 mop->mo_usource = strdup(real_path);
715 ptr = strstr(mop->mo_usource, ":/");
717 mop->mo_source = convert_hostnames(mop->mo_usource);
721 mop->mo_source = strdup(mop->mo_usource);
724 if (realpath(argv[optind + 1], mop->mo_target) == NULL) {
726 fprintf(stderr, "warning: %s: cannot resolve: %s\n",
727 argv[optind + 1], strerror(errno));
734 #ifdef HAVE_SERVER_SUPPORT
735 /* change label from <fsname>:<index> to
736 * <fsname>-<index> to indicate the device has
737 * been registered. only if the label is
738 * supposed to be changed and target service
739 * is supposed to start */
740 static void label_lustre(struct mount_opts *mop)
745 if (mop->mo_ldd.ldd_flags & (LDD_F_VIRGIN | LDD_F_WRITECONF)) {
746 (void)osd_label_lustre(mop);
748 struct lustre_disk_data ldd;
751 /* device label could be changed after journal recovery,
752 * it should also be relabeled for mount has succeeded. */
753 memset(&ldd, 0, sizeof(ldd));
754 ldd.ldd_mount_type = mop->mo_ldd.ldd_mount_type;
755 rc = osd_read_ldd(mop->mo_source, &ldd);
757 rc = strlen(ldd.ldd_svname);
758 if (rc >= 8 && ldd.ldd_svname[rc - 8] != '-')
759 (void)osd_label_lustre(mop);
763 #endif /* HAVE_SERVER_SUPPORT */
765 int main(int argc, char *const argv[])
767 struct mount_opts mop;
775 progname = strrchr(argv[0], '/');
776 progname = progname ? progname + 1 : argv[0];
780 g_pagesize = sysconf(_SC_PAGESIZE);
781 if (g_pagesize == -1) {
783 printf("error: %d failed to get page size.\n", rc);
786 maxopt_len = MIN(g_pagesize, 64 * 1024);
788 rc = parse_opts(argc, argv, &mop);
793 for (i = 0; i < argc; i++)
794 printf("arg[%d] = %s\n", i, argv[i]);
795 printf("source = %s (%s), target = %s\n", mop.mo_usource,
796 mop.mo_source, mop.mo_target);
797 printf("options = %s\n", mop.mo_orig_options);
800 options = malloc(maxopt_len);
801 if (options == NULL) {
802 fprintf(stderr, "can't allocate memory for options\n");
807 if (strlen(mop.mo_orig_options) >= maxopt_len) {
808 fprintf(stderr, "error: mount options too long\n");
813 strcpy(options, mop.mo_orig_options);
814 rc = parse_options(&mop, options, &flags, maxopt_len);
816 fprintf(stderr, "%s: can't parse options: %s\n",
822 rc = check_mtab_entry(mop.mo_usource, mop.mo_source,
823 mop.mo_target, "lustre");
824 if (rc && !(flags & MS_REMOUNT)) {
825 fprintf(stderr, "%s: according to %s %s is "
826 "already mounted on %s\n", progname, MOUNTED,
827 mop.mo_usource, mop.mo_target);
831 if (!rc && (flags & MS_REMOUNT)) {
832 fprintf(stderr, "%s: according to %s %s is "
833 "not already mounted on %s\n", progname, MOUNTED,
834 mop.mo_usource, mop.mo_target);
839 if (flags & MS_REMOUNT)
842 rc = access(mop.mo_target, F_OK);
845 fprintf(stderr, "%s: %s inaccessible: %s\n", progname,
846 mop.mo_target, strerror(errno));
850 client = (strstr(mop.mo_usource, ":/") != NULL);
852 #ifdef HAVE_SERVER_SUPPORT
857 rc = parse_ldd(mop.mo_source, &mop, options, maxopt_len);
866 /* In Linux 2.4, the target device doesn't get passed to any of our
867 functions. So we'll stick it on the end of the options. */
868 rc = append_option(options, maxopt_len, "device=", mop.mo_source);
873 printf("mounting device %s at %s, flags=%#x options=%s\n",
874 mop.mo_source, mop.mo_target, flags, options);
876 #ifdef HAVE_SERVER_SUPPORT
877 if (!client && osd_tune_lustre(mop.mo_source, &mop)) {
879 fprintf(stderr, "%s: unable to set tunables for %s"
880 " (may cause reduced IO performance)\n",
881 argv[0], mop.mo_source);
885 if (mop.mo_skpath[0] != '\0') {
886 /* Treat shared key failures as fatal */
887 rc = load_shared_keys(&mop);
890 "%s: Error loading shared keys: %s\n",
891 progname, strerror(rc));
895 #endif /* HAVE_GSS */
898 /* flags and target get to lustre_get_sb(), but not
899 * lustre_fill_super(). Lustre ignores the flags, but mount
901 for (i = 0, rc = -EAGAIN; i <= mop.mo_retry && rc != 0; i++) {
902 rc = mount(mop.mo_source, mop.mo_target, "lustre",
903 flags, (void *)options);
906 fprintf(stderr, "%s: mount %s at %s "
907 "failed: %s retries left: "
908 "%d\n", basename(progname),
909 mop.mo_usource, mop.mo_target,
915 int limit = i/2 > 5 ? i/2 : 5;
921 #ifdef HAVE_SERVER_SUPPORT
935 cli = strrchr(mop.mo_usource, ':');
936 if (cli && (strlen(cli) > 2))
941 fprintf(stderr, "%s: mount %s at %s failed: %s\n", progname,
942 mop.mo_usource, mop.mo_target, strerror(errno));
944 fprintf(stderr, "Is the backend filesystem mounted?\n"
945 "Check /etc/mtab and /proc/mounts\n");
947 fprintf(stderr, "Are the lustre modules loaded?\n"
948 "Check /etc/modprobe.conf and "
949 "/proc/filesystems\n");
950 if (errno == ENOTBLK)
951 fprintf(stderr, "Do you need -o loop?\n");
952 if (errno == ENOMEDIUM)
954 "This filesystem needs at least 1 OST\n");
955 if (errno == ENOENT) {
956 fprintf(stderr, "Is the MGS specification correct?\n");
957 fprintf(stderr, "Is the filesystem name correct?\n");
958 fprintf(stderr, "If upgrading, is the copied client log"
959 " valid? (see upgrade docs)\n");
961 if (errno == EALREADY)
962 fprintf(stderr, "The target service is already running."
963 " (%s)\n", mop.mo_usource);
965 fprintf(stderr, "The target service failed to start "
966 "(bad config log?) (%s). "
967 "See /var/log/messages.\n", mop.mo_usource);
969 fprintf(stderr, "Is the MGS running?\n");
970 if (errno == EADDRINUSE)
971 fprintf(stderr, "The target service's index is already "
972 "in use. (%s)\n", mop.mo_usource);
973 if (errno == EINVAL) {
974 fprintf(stderr, "This may have multiple causes.\n");
976 fprintf(stderr, "Is '%s' the correct filesystem"
978 fprintf(stderr, "Are the mount options correct?\n");
979 fprintf(stderr, "Check the syslog for more info.\n");
982 /* May as well try to clean up loop devs */
983 if (strncmp(mop.mo_usource, "/dev/loop", 9) == 0) {
986 sprintf(cmd, "/sbin/losetup -d %s", mop.mo_usource);
987 if ((ret = system(cmd)) < 0)
990 rc = WEXITSTATUS(ret);
994 /* Deal with utab just for client. Note that we ignore
995 * the return value here since it is not worth to fail
996 * mount by prevent some rare cases */
997 if (strstr(mop.mo_usource, ":/") != NULL)
998 update_utab_entry(&mop);
999 if (!mop.mo_nomtab) {
1000 rc = update_mtab_entry(mop.mo_usource, mop.mo_target,
1001 "lustre", mop.mo_orig_options,
1007 #ifdef HAVE_SERVER_SUPPORT
1015 /* mo_usource should be freed, but we can rely on the kernel */
1016 free(mop.mo_source);