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/
31 * lustre/utils/mount_lustre.c
33 * Author: Robert Read <rread@clusterfs.com>
34 * Author: Nathan Rutman <nathan@clusterfs.com>
49 #include <sys/mount.h>
50 #include <sys/param.h>
51 #include <linux/lustre/lustre_ver.h>
54 #if defined(HAVE_LUSTRE_CRYPTO) && defined(HAVE_LIBKEYUTILS)
57 #include <linux/lnet/nidstr.h>
58 #include <libcfs/util/string.h>
61 #include "mount_utils.h"
63 #define MAX_RETRIES 99
72 "\nThis mount helper should only be invoked via the mount (8) command,\ne.g. mount -t lustre dev dir\n\n");
73 fprintf(out, "usage: %s [-fhnvV] [-o <srvopt>] <device> <mountpt>\n",
75 fprintf(out, "usage: %s [-fhnvV] [-o <cliopt>] <mgstarget> <mountpt>\n",
78 "\t<device>: the local disk device when mounting a server\n"
79 "\t<mgstarget>: the server MGS and filesystem for a client:\n"
80 "\t\t<mgsnid>[:<altmgsnid>...]:/<filesystem>[/<subdir>]\n"
81 "\t\t\t<mgsnid>: MGS LNet Node Identifier (e.g. mgs01@o2ib)\n"
82 "\t\t\t<filesystem>: Lustre filesystem name (e.g. lustre1)\n"
83 "\t\t\t<subdir>: subdirectory of the filesystem to mount\n"
84 "\t<mountpt>: filesystem mountpoint (e.g. /mnt/lustre)\n"
85 "\t-f|--fake: fake mount (only update /etc/mtab)\n"
86 "\t-o force|--force: force mount even if already in /etc/mtab\n"
87 "\t-h|--help: print this usage message\n"
88 "\t-n|--nomtab: do not update /etc/mtab after mount\n"
89 "\t-v|--verbose: print verbose config settings\n"
90 "\t-V|--version: output build version of the utility and exit\n"
91 "\tdefault options are marked below with '*'\n"
92 "\t\t(no)flock: disable* or enable POSIX flock support\n"
93 "\t\t(no)user_xattr: disable or enable* user xattr namespace\n"
94 "\t<srvopt>: one or more comma separated server options:\n"
95 "\t\t(no)acl: disable or enable* POSIX ACL support completely\n"
96 "\t\tabort_recov: abort server recovery handling\n"
97 "\t\tnosvc: only start MGC/MGS without starting MDS/OSS\n"
98 "\t\tnomgs: only start target MDS/OSS, using existing MGS\n"
99 "\t\tnoscrub: do NOT auto start OI scrub unless requested\n"
100 "\t\tskip_lfsck: do NOT auto resume paused/crashed LFSCK\n"
101 "\t\tmax_sectors_kb=<size>: set device max_sectors_kb to size or leaves it untouched if size=0\n"
102 "\t\t\tIf not specified, device max_sectors_kb will be set to max_hw_sectors_kb\n"
103 "\t\tmd_stripe_cache_size=<num>: set MD RAID device stripe cache size\n"
104 "\t<cliopt>: one or more comma separated client options:\n"
105 "\t\texclude=<ostname>[:<ostname>]: list of inactive OSTs (e.g. lustre-OST0001)\n"
106 "\t\tlocalflock: enable POSIX flock only on local client\n"
107 "\t\tretry=<num>: number of times mount is retried by client\n"
109 "\t\tskpath=<file|directory>: path of keys to load into kernel keyring\n"
111 "\t\t(no)user_fid2path: disable* or enable user $MOUNT/.lustre/fid access\n"
112 "\t\t(no)checksum: disable or enable* data checksums\n"
113 "\t\t(no)lruresize: disable or enable* LDLM dynamic LRU size\n"
114 "\t\t(no)lazystatfs: disable or enable* statfs to work if OST is unavailable\n"
115 "\t\t32bitapi: return only 32-bit inode numbers to userspace\n"
116 "\t\t(no)verbose: disable or enable* messages at filesystem (un,re)mount\n"
117 #ifdef HAVE_LUSTRE_CRYPTO
118 #ifdef HAVE_LIBKEYUTILS
119 "\t\ttest_dummy_encryption: enable test dummy encryption mode\n"
121 "\t\tnoencrypt: disable client side encryption\n"
124 exit((out != stdout) ? EINVAL : 0);
127 /* Get rid of symbolic hostnames for tcp, since kernel can't do lookups */
128 #define MAXNIDSTR 1024
129 static char *convert_hostnames(char *s1)
131 char *converted, *s2 = 0, *c;
133 int left = MAXNIDSTR;
136 converted = malloc(left);
138 fprintf(stderr, "out of memory: needed %d bytes\n",
143 while ((left > 0) && (*s1 != '/')) {
144 s2 = strpbrk(s1, ",:");
149 nid = libcfs_str2nid(s1);
150 *s2 = sep; /* back to original string */
151 if (nid == LNET_NID_ANY)
153 c += scnprintf(c, left, "%s%c", libcfs_nid2str(nid), sep);
154 left = converted + MAXNIDSTR - c;
157 snprintf(c, left, "%s", s1);
160 fprintf(stderr, "%s: Can't parse NID '%s'\n", progname, s1);
165 /*****************************************************************************
167 * This part was cribbed from util-linux/mount/mount.c. There was no clear
168 * license information, but many other files in the package are identified as
169 * GNU GPL, so it's a pretty safe bet that was their intent.
171 ****************************************************************************/
173 const char *opt; /* option name */
174 int inv; /* true if flag value should be inverted */
175 int mask; /* flag mask value */
178 static const struct opt_map opt_map[] = {
179 /* these flags are parsed by mount, not Lustre */
180 { .opt = "async", .mask = MS_SYNCHRONOUS, .inv = 1 }, /* asynchronous I/O */
181 { .opt = "atime", .mask = MS_NOATIME, .inv = 1 }, /* set access time */
182 { .opt = "auto" }, /* allow auto mount */
183 { .opt = "defaults" }, /* default options */
184 { .opt = "dev", .mask = MS_NODEV, .inv = 1 }, /* interpret devs */
185 { .opt = "exec", .mask = MS_NOEXEC, .inv = 1 }, /* allow execution */
187 { .opt = "noatime", .mask = MS_NOATIME }, /* do not set atime */
188 { .opt = "noauto" }, /* mount explicitly */
189 { .opt = "nodev", .mask = MS_NODEV }, /* no interpret devs */
190 { .opt = "noowner", .inv = 1 }, /* no special privs */
191 { .opt = "nosuid", .mask = MS_NOSUID }, /* do not honor suid */
192 { .opt = "nouser", .inv = 1 }, /* users cannot mount */
193 { .opt = "nousers", .inv = 1 }, /* users cannot mount */
194 { .opt = "_netdev" }, /* network only */
195 { .opt = "noexec", .mask = MS_NOEXEC }, /* no execute */
196 { .opt = "remount", .mask = MS_REMOUNT }, /* remount */
197 { .opt = "ro", .mask = MS_RDONLY }, /* read-only */
198 { .opt = "rw", .mask = MS_RDONLY, .inv = 1 }, /* read-write */
199 { .opt = "suid", .mask = MS_NOSUID, .inv = 1 }, /* honor suid */
200 { .opt = "sync", .mask = MS_SYNCHRONOUS }, /* synchronous I/O */
202 { .opt = "diratime", /* set access time */
203 .mask = MS_NODIRATIME, .inv = 1 }, /* on read */
204 { .opt = "nodiratime", /* do not set access */
205 .mask = MS_NODIRATIME }, /* time on read */
208 { .opt = "norelatime", /* do not set rel */
209 .mask = MS_RELATIME, .inv = 1 }, /* access time */
210 { .opt = "relatime", /* set relative */
211 .mask = MS_RELATIME }, /* access time */
213 #ifdef MS_STRICTATIME
214 { .opt = "strictatime",
215 .mask = MS_STRICTATIME }, /* strict access time */
218 /****************************************************************************/
221 * 1 = don't pass on to lustre
222 * 0 = pass on to lustre
224 static int parse_one_option(const char *check, int *flagp)
226 const struct opt_map *opt;
228 for (opt = &opt_map[0]; opt->opt != NULL; opt++) {
229 if (strncmp(check, opt->opt, strlen(opt->opt)) == 0) {
232 *flagp &= ~(opt->mask);
240 * Assume any unknown options are valid and pass them on. The mount
241 * will fail if lmd_parse, ll_options or ldiskfs doesn't recognize it.
246 static size_t merge_strings(char *dst, const char *src, size_t size)
248 size_t dsize = strlen(dst);
249 size_t len = strlen(src);
250 size_t ret = dsize + len;
256 memcpy(dst, src, len);
261 static int append_option(char *options, size_t options_len,
262 const char *param, const char *value)
266 if (options[0] != '\0') {
267 rc = merge_strings(options, ",", options_len);
268 if (rc >= options_len)
272 rc = merge_strings(options, param, options_len);
273 if (rc >= options_len)
277 rc = merge_strings(options, value, options_len);
278 if (rc >= options_len)
283 fprintf(stderr, "error: mount options %s%s too long\n", param, value);
288 * Replace options with subset of Lustre-specific options, and
289 * fill in mount flags
291 int parse_options(struct mount_opts *mop, char *orig_options,
292 int *flagp, size_t options_len)
294 char *options, *opt, *nextopt, *arg, *val;
297 options = calloc(strlen(orig_options) + 1, 1);
302 nextopt = orig_options;
303 while ((opt = strsep(&nextopt, ","))) {
308 /* Handle retries in a slightly different manner */
310 val = strchr(opt, '=');
312 * please note that some ldiskfs mount options are also in
313 * the form of param=value. We should pay attention not to
314 * remove those mount options, see bug 22097.
316 if (val && strncmp(arg, "max_sectors_kb", 14) == 0) {
317 mop->mo_max_sectors_kb = atoi(val + 1);
319 strncmp(arg, "md_stripe_cache_size", 20) == 0) {
320 mop->mo_md_stripe_cache_size = atoi(val + 1);
321 } else if (val && strncmp(arg, "retry", 5) == 0) {
322 mop->mo_retry = atoi(val + 1);
323 if (mop->mo_retry > MAX_RETRIES)
324 mop->mo_retry = MAX_RETRIES;
325 else if (mop->mo_retry < 0)
327 } else if (val && strncmp(arg, "mgssec", 6) == 0) {
328 rc = append_option(options, options_len, opt, NULL);
331 } else if (strncmp(arg, "nosvc", 5) == 0) {
333 rc = append_option(options, options_len, opt, NULL);
336 } else if (strcmp(opt, "force") == 0) {
337 /* XXX special check for 'force' option */
339 printf("force: %d\n", mop->mo_force);
341 } else if (val && strncmp(opt, "skpath=", 7) == 0) {
342 if (strlen(val) + 1 >= sizeof(mop->mo_skpath)) {
344 "%s: shared key path too long\n",
349 strncpy(mop->mo_skpath, val + 1,
350 sizeof(mop->mo_skpath) - 1);
352 #ifdef HAVE_LUSTRE_CRYPTO
353 } else if (strncmp(arg, "test_dummy_encryption", 21) == 0) {
354 #ifdef HAVE_LIBKEYUTILS
355 #ifdef HAVE_FSCRYPT_DUMMY_CONTEXT_ENABLED
356 /* Using dummy encryption mode requires inserting a
357 * special dummy key into the session keyring.
358 * Key type is "logon", key description is
359 * "fscrypt:4242424242424242", and key payload has to be
360 * in the form <mode><raw><size>, where:
361 * <mode> is "\x00\x00\x00\x00"
362 * <raw> is "$(printf ""\\\\x%02x"" {0..63})"
363 * <size> is "\x40\x00\x00\x00" for little endian,
364 * "\x00\x00\x00\x40" for big endian.
367 int *p = (int *)payload;
368 char *q = (char *)(p + 1);
378 key = add_key("logon", "fscrypt:4242424242424242",
379 (const void *)payload, sizeof(payload),
380 KEY_SPEC_SESSION_KEYRING);
384 "%s: test dummy encryption option ignored: could not insert dummy encryption key into session keyring\n",
387 /* pass this on as an option */
388 rc = append_option(options, options_len, opt,
393 #else /* !HAVE_FSCRYPT_DUMMY_CONTEXT_ENABLED */
394 /* pass this on as an option */
395 rc = append_option(options, options_len, opt,
400 #else /* HAVE_LIBKEYUTILS */
402 "%s: test dummy encryption option ignored: Lustre not built with libkeyutils support\n",
406 } else if (parse_one_option(opt, flagp) == 0) {
407 /* pass this on as an option */
408 rc = append_option(options, options_len, opt, NULL);
413 #ifdef MS_STRICTATIME
414 #if LUSTRE_VERSION_CODE > OBD_OCD_VERSION(3, 2, 53, 0)
417 * In the future when upstream fixes land in all supported kernels
418 * we should stop forcing MS_STRICTATIME in lustre mounts.
419 * We override the kernel level default of MS_RELATIME for now
420 * due to a kernel vfs level bug in atime updates that fails
421 * to reset timestamps from the future.
423 #warn "remove MS_STRICTATIME override if kernel updates atime from the future"
426 * set strictatime to default if NOATIME or RELATIME
429 if (!(*flagp & (MS_NOATIME | MS_RELATIME)))
430 *flagp |= MS_STRICTATIME;
432 strcpy(orig_options, options);
439 #ifdef HAVE_SERVER_SUPPORT
440 /* Add mgsnids from ldd params */
441 static int add_mgsnids(struct mount_opts *mop, char *options,
442 const char *params, size_t options_len)
444 char *ptr = (char *)params;
448 while ((ptr = strstr(ptr, PARAM_MGSNODE)) != NULL) {
449 sep = strchr(ptr, ' ');
454 rc = append_option(options, options_len, ptr, NULL);
457 mop->mo_have_mgsnid++;
470 static int clear_update_ondisk(char *source, struct lustre_disk_data *ldd)
472 char wanted_mountopts[512] = "";
473 struct mkfs_opts mkop;
477 memset(&mkop, 0, sizeof(mkop));
479 mkop.mo_ldd.ldd_flags &= ~LDD_F_UPDATE;
480 mkop.mo_flags = MO_NOHOSTID_CHECK; /* Ignore missing hostid */
481 if (strlen(source) > sizeof(mkop.mo_device) - 1) {
483 fprintf(stderr, "Device name too long: %s\n", source);
486 strncpy(mkop.mo_device, source, sizeof(mkop.mo_device));
488 ret = osd_prepare_lustre(&mkop,
489 wanted_mountopts, sizeof(wanted_mountopts));
492 fprintf(stderr, "Can't prepare device %s: %s\n",
493 source, strerror(ret));
497 /* Create the loopback file */
498 if (mkop.mo_flags & MO_IS_LOOP) {
499 ret = access(mkop.mo_device, F_OK);
503 fprintf(stderr, "Can't access device %s: %s\n",
504 source, strerror(ret));
508 ret = loop_setup(&mkop);
511 fprintf(stderr, "Loop device setup for %s failed: %s\n",
512 mkop.mo_device, strerror(ret));
516 ret = osd_write_ldd(&mkop);
519 fprintf(stderr, "failed to write local files: %s\n",
523 ret2 = loop_cleanup(&mkop);
530 static int parse_ldd(char *source, struct mount_opts *mop,
531 char *options, size_t options_len)
533 struct lustre_disk_data *ldd = &mop->mo_ldd;
538 rc = osd_is_lustre(source, &ldd->ldd_mount_type);
541 "%s: %s has not been formatted with mkfs.lustre or the backend filesystem type is not supported by this tool\n",
546 rc = osd_read_ldd(source, ldd);
549 "%s: %s failed to read permanent mount data: %s\n",
550 progname, source, rc >= 0 ? strerror(rc) : "");
554 if ((IS_MDT(ldd) || IS_OST(ldd)) &&
555 (ldd->ldd_flags & LDD_F_NEED_INDEX)) {
557 "%s: %s has no index assigned (probably formatted with old mkfs)\n",
562 if (ldd->ldd_flags & LDD_F_UPDATE)
563 clear_update_ondisk(source, ldd);
565 /* Since we never rewrite ldd, ignore temp flags */
566 ldd->ldd_flags &= ~(LDD_F_VIRGIN | LDD_F_WRITECONF |
567 LDD_F_NO_LOCAL_LOGS);
569 /* This is to make sure default options go first */
570 temp_options = strdup(options);
572 fprintf(stderr, "%s: can't allocate memory for temp_options\n",
576 strncpy(options, ldd->ldd_mount_opts, options_len);
577 rc = append_option(options, options_len, temp_options, NULL);
582 /* svname of the form lustre:OST1234 means never registered */
583 rc = strlen(ldd->ldd_svname);
584 if (strcmp(ldd->ldd_svname, "MGS") != 0) {
586 fprintf(stderr, "%s: invalid name '%s'\n",
587 progname, ldd->ldd_svname);
589 } else if (ldd->ldd_svname[rc - 8] == ':') {
590 ldd->ldd_svname[rc - 8] = '-';
591 ldd->ldd_flags |= LDD_F_VIRGIN;
592 } else if (ldd->ldd_svname[rc - 8] == '=') {
593 ldd->ldd_svname[rc - 8] = '-';
594 ldd->ldd_flags |= LDD_F_WRITECONF;
595 } else if (ldd->ldd_svname[rc - 8] == '+') {
596 ldd->ldd_svname[rc - 8] = '-';
597 ldd->ldd_flags |= LDD_F_NO_LOCAL_LOGS;
600 /* backend osd type */
601 rc = append_option(options, options_len, "osd=",
602 mt_type(ldd->ldd_mount_type));
606 if (!mop->mo_have_mgsnid) {
608 * Only use disk data if mount -o mgsnode=nid wasn't
611 if (ldd->ldd_flags & LDD_F_SV_TYPE_MGS) {
612 rc = append_option(options, options_len, "mgs", NULL);
615 mop->mo_have_mgsnid++;
617 if (add_mgsnids(mop, options, ldd->ldd_params,
622 /* Better have an mgsnid by now */
623 if (!mop->mo_have_mgsnid) {
624 fprintf(stderr, "%s: missing option mgsnode=<nid>\n",
629 if (ldd->ldd_flags & LDD_F_VIRGIN) {
630 rc = append_option(options, options_len, "virgin", NULL);
634 if (ldd->ldd_flags & LDD_F_UPDATE) {
635 rc = append_option(options, options_len, "update", NULL);
639 if (ldd->ldd_flags & LDD_F_WRITECONF) {
640 rc = append_option(options, options_len, "writeconf", NULL);
644 if (ldd->ldd_flags & LDD_F_NO_LOCAL_LOGS) {
645 rc = append_option(options, options_len, "nolocallogs", NULL);
649 if (ldd->ldd_flags & LDD_F_NO_PRIMNODE) {
650 rc = append_option(options, options_len, "noprimnode", NULL);
656 * prefix every lustre parameter with param= so that in-kernel
657 * mount can recognize them properly and send to MGS at registration
659 start = ldd->ldd_params;
660 while (start && *start != '\0') {
661 while (*start == ' ')
666 start = strchr(cur, ' ');
671 rc = append_option(options, options_len, "param=", cur);
676 /* svname must be last option */
677 rc = append_option(options, options_len, "svname=", ldd->ldd_svname);
681 #endif /* HAVE_SERVER_SUPPORT */
683 static void set_defaults(struct mount_opts *mop)
685 memset(mop, 0, sizeof(*mop));
686 mop->mo_usource = NULL;
687 mop->mo_source = NULL;
692 mop->mo_have_mgsnid = 0;
693 mop->mo_md_stripe_cache_size = 16384;
694 mop->mo_orig_options = "";
696 mop->mo_max_sectors_kb = -1;
699 static int parse_opts(int argc, char *const argv[], struct mount_opts *mop)
701 static struct option long_opts[] = {
702 { .val = 1, .name = "force", .has_arg = no_argument },
703 { .val = 'f', .name = "fake", .has_arg = no_argument },
704 { .val = 'h', .name = "help", .has_arg = no_argument },
705 { .val = 'n', .name = "nomtab", .has_arg = no_argument },
706 { .val = 'o', .name = "options", .has_arg = required_argument },
707 { .val = 'v', .name = "verbose", .has_arg = no_argument },
708 { .val = 'V', .name = "version", .has_arg = no_argument },
710 char real_path[PATH_MAX] = {'\0'};
712 char path[256], name[256];
717 while ((opt = getopt_long(argc, argv, "fhno:vV",
718 long_opts, NULL)) != EOF){
722 printf("force: %d\n", mop->mo_force);
726 printf("fake: %d\n", mop->mo_fake);
733 printf("nomtab: %d\n", mop->mo_nomtab);
736 mop->mo_orig_options = optarg;
743 fprintf(stdout, "%s %s (libmount)\n", progname,
744 LUSTRE_VERSION_STRING);
747 fprintf(stderr, "%s: unknown option '%c'\n",
754 if (optind + 2 > argc) {
755 fprintf(stderr, "%s: too few arguments\n", progname);
759 mop->mo_usource = argv[optind];
760 if (!mop->mo_usource)
764 * Try to get the real path to the device, in case it is a
765 * symbolic link for instance
767 if (realpath(mop->mo_usource, real_path) != NULL) {
768 ptr = strrchr(real_path, '/');
769 if (ptr && strncmp(ptr, "/dm-", 4) == 0 &&
770 isdigit(*(ptr + 4))) {
771 snprintf(path, sizeof(path), "/sys/block/%s/dm/name",
773 if ((f = fopen(path, "r"))) {
774 /* read "<name>\n" from sysfs */
775 if (fgets(name, sizeof(name), f) &&
776 (sz = strlen(name)) > 1) {
778 snprintf(real_path, sizeof(real_path),
779 "/dev/mapper/%s", name);
784 mop->mo_usource = strdup(real_path);
787 ptr = strstr(mop->mo_usource, ":/");
789 mop->mo_source = convert_hostnames(mop->mo_usource);
793 mop->mo_source = strdup(mop->mo_usource);
796 if (realpath(argv[optind + 1], mop->mo_target) == NULL) {
798 fprintf(stderr, "warning: %s: cannot resolve: %s\n",
799 argv[optind + 1], strerror(errno));
806 #ifdef HAVE_SERVER_SUPPORT
808 * change label from <fsname>:<index> to
809 * <fsname>-<index> to indicate the device has
810 * been registered. only if the label is
811 * supposed to be changed and target service
812 * is supposed to start
814 static void label_lustre(struct mount_opts *mop)
819 if (mop->mo_ldd.ldd_flags & (LDD_F_VIRGIN | LDD_F_WRITECONF |
820 LDD_F_NO_LOCAL_LOGS)) {
821 (void)osd_label_lustre(mop);
823 struct lustre_disk_data ldd;
827 * device label could be changed after journal recovery,
828 * it should also be relabeled for mount has succeeded.
830 memset(&ldd, 0, sizeof(ldd));
831 ldd.ldd_mount_type = mop->mo_ldd.ldd_mount_type;
832 rc = osd_read_ldd(mop->mo_source, &ldd);
834 rc = strlen(ldd.ldd_svname);
835 if (rc >= 8 && ldd.ldd_svname[rc - 8] != '-')
836 (void)osd_label_lustre(mop);
840 #endif /* HAVE_SERVER_SUPPORT */
842 int main(int argc, char *const argv[])
844 struct mount_opts mop;
852 progname = strrchr(argv[0], '/');
853 progname = progname ? progname + 1 : argv[0];
857 g_pagesize = sysconf(_SC_PAGESIZE);
858 if (g_pagesize == -1) {
860 printf("error: %d failed to get page size.\n", rc);
863 maxopt_len = MIN(g_pagesize, 64 * 1024);
865 rc = parse_opts(argc, argv, &mop);
870 for (i = 0; i < argc; i++)
871 printf("arg[%d] = %s\n", i, argv[i]);
872 printf("source = %s (%s), target = %s\n", mop.mo_usource,
873 mop.mo_source, mop.mo_target);
874 printf("options = %s\n", mop.mo_orig_options);
877 options = malloc(maxopt_len);
879 fprintf(stderr, "can't allocate memory for options\n");
884 if (strlen(mop.mo_orig_options) >= maxopt_len) {
885 fprintf(stderr, "error: mount options too long\n");
890 strcpy(options, mop.mo_orig_options);
891 rc = parse_options(&mop, options, &flags, maxopt_len);
893 fprintf(stderr, "%s: can't parse options: %s\n",
899 rc = check_mtab_entry(mop.mo_usource, mop.mo_source,
900 mop.mo_target, "lustre");
901 if (rc && !(flags & MS_REMOUNT)) {
903 "%s: according to %s %s is already mounted on %s\n",
904 progname, MOUNTED, mop.mo_usource,
909 if (!rc && (flags & MS_REMOUNT)) {
911 "%s: according to %s %s is not already mounted on %s\n",
912 progname, MOUNTED, mop.mo_usource,
918 if (flags & MS_REMOUNT)
921 rc = access(mop.mo_target, F_OK);
924 fprintf(stderr, "%s: %s inaccessible: %s\n", progname,
925 mop.mo_target, strerror(errno));
929 client = (strstr(mop.mo_usource, ":/") != NULL);
931 #ifdef HAVE_SERVER_SUPPORT
936 rc = parse_ldd(mop.mo_source, &mop, options, maxopt_len);
941 fprintf(stderr, "%s: cannot mount %s: no server support\n",
942 progname, mop.mo_usource);
948 * In Linux 2.4, the target device doesn't get passed to any of our
949 * functions. So we'll stick it on the end of the options.
951 rc = append_option(options, maxopt_len, "device=", mop.mo_source);
956 printf("mounting device %s at %s, flags=%#x options=%s\n",
957 mop.mo_source, mop.mo_target, flags, options);
959 #ifdef HAVE_SERVER_SUPPORT
960 if (!client && osd_tune_lustre(mop.mo_source, &mop)) {
963 "%s: unable to set tunables for %s (may cause reduced IO performance)\n",
964 argv[0], mop.mo_source);
968 if (mop.mo_skpath[0] != '\0') {
969 /* Treat shared key failures as fatal */
970 rc = load_shared_keys(&mop);
972 fprintf(stderr, "%s: Error loading shared keys: %s\n",
973 progname, strerror(rc));
977 #endif /* HAVE_GSS */
982 /* Prefer filesystem type given on mount command line
983 * so it appears correctly in the /proc/mounts output.
985 if (strstr(argv[0], "mount.lustre_tgt"))
986 fstype = "lustre_tgt";
990 * flags and target get to lustre_get_sb(), but not
991 * lustre_fill_super(). Lustre ignores the flags, but mount
994 for (i = 0, rc = -EAGAIN; i <= mop.mo_retry && rc != 0; i++) {
995 rc = mount(mop.mo_source, mop.mo_target, fstype,
996 flags, (void *)options);
1000 "%s: mount -t %s %s at %s failed: %s retries left: %d\n",
1001 basename(progname), fstype,
1002 mop.mo_usource, mop.mo_target,
1007 /* Pre-2.13 Lustre without 'lustre_tgt' type?
1008 * Try with 'lustre' instead. Eventually this
1009 * can be removed (e.g. 2.18 or whenever).
1011 if (errno == ENODEV &&
1012 strcmp(fstype, "lustre_tgt") == 0) {
1019 int limit = i / 2 > 5 ? i / 2 : 5;
1025 #ifdef HAVE_SERVER_SUPPORT
1039 cli = strrchr(mop.mo_usource, ':');
1040 if (cli && (strlen(cli) > 2))
1045 fprintf(stderr, "%s: mount %s at %s failed: %s\n", progname,
1046 mop.mo_usource, mop.mo_target, strerror(errno));
1049 "Is the backend filesystem mounted?\n Check /etc/mtab and /proc/mounts\n");
1050 if (errno == ENODEV)
1052 "Are the lustre modules loaded?\n Check /etc/modprobe.conf and /proc/filesystems\n");
1053 if (errno == ENOTBLK)
1054 fprintf(stderr, "Do you need -o loop?\n");
1055 if (errno == ENOMEDIUM)
1057 "This filesystem needs at least 1 OST\n");
1058 if (errno == ENOENT) {
1059 fprintf(stderr, "Is the MGS specification correct?\n");
1060 fprintf(stderr, "Is the filesystem name correct?\n");
1062 "If upgrading, is the copied client log valid? (see upgrade docs)\n");
1064 if (errno == EALREADY)
1066 "The target service is already running. (%s)\n",
1070 "The target service failed to start (bad config log?) (%s). See /var/log/messages.\n",
1073 fprintf(stderr, "Is the MGS running?\n");
1074 if (errno == EADDRINUSE)
1076 "The target service's index is already in use. (%s)\n",
1078 if (errno == EINVAL) {
1079 fprintf(stderr, "This may have multiple causes.\n");
1082 "Is '%s' the correct filesystem name?\n",
1084 fprintf(stderr, "Are the mount options correct?\n");
1085 fprintf(stderr, "Check the syslog for more info.\n");
1088 /* May as well try to clean up loop devs */
1089 if (strncmp(mop.mo_usource, "/dev/loop", 9) == 0) {
1093 sprintf(cmd, "/sbin/losetup -d %s", mop.mo_usource);
1094 if ((ret = system(cmd)) < 0)
1097 rc = WEXITSTATUS(ret);
1102 * Deal with utab just for client. Note that we ignore
1103 * the return value here since it is not worth to fail
1104 * mount by prevent some rare cases
1106 if (strstr(mop.mo_usource, ":/") != NULL)
1107 update_utab_entry(&mop);
1108 if (!mop.mo_nomtab) {
1109 rc = update_mtab_entry(mop.mo_usource, mop.mo_target,
1110 "lustre", mop.mo_orig_options,
1116 #ifdef HAVE_SERVER_SUPPORT
1124 /* mo_usource should be freed, but we can rely on the kernel */
1125 free(mop.mo_source);