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"
64 # define WITH_LIBMOUNT "(libmount)"
66 # define WITH_LIBMOUNT ""
69 #define MAX_RETRIES 99
78 "\nThis mount helper should only be invoked via the mount (8) command,\ne.g. mount -t lustre dev dir\n\n");
79 fprintf(out, "usage: %s [-fhnvV] [-o <srvopt>] <device> <mountpt>\n",
81 fprintf(out, "usage: %s [-fhnvV] [-o <cliopt>] <mgstarget> <mountpt>\n",
84 "\t<device>: the local disk device when mounting a server\n"
85 "\t<mgstarget>: the server MGS and filesystem for a client:\n"
86 "\t\t<mgsnid>[:<altmgsnid>...]:/<filesystem>[/<subdir>]\n"
87 "\t\t\t<mgsnid>: MGS LNet Node Identifier (e.g. mgs01@o2ib)\n"
88 "\t\t\t<filesystem>: Lustre filesystem name (e.g. lustre1)\n"
89 "\t\t\t<subdir>: subdirectory of the filesystem to mount\n"
90 "\t<mountpt>: filesystem mountpoint (e.g. /mnt/lustre)\n"
91 "\t-f|--fake: fake mount (only update /etc/mtab)\n"
92 "\t-o force|--force: force mount even if already in /etc/mtab\n"
93 "\t-h|--help: print this usage message\n"
94 "\t-n|--nomtab: do not update /etc/mtab after mount\n"
95 "\t-v|--verbose: print verbose config settings\n"
96 "\t-V|--version: output build version of the utility and exit\n"
97 "\tdefault options are marked below with '*'\n"
98 "\t\t(no)flock: disable* or enable POSIX flock support\n"
99 "\t\t(no)user_xattr: disable or enable* user xattr namespace\n"
100 "\t<srvopt>: one or more comma separated server options:\n"
101 "\t\t(no)acl: disable or enable* POSIX ACL support completely\n"
102 "\t\tabort_recov: abort server recovery handling\n"
103 "\t\tnosvc: only start MGC/MGS without starting MDS/OSS\n"
104 "\t\tnomgs: only start target MDS/OSS, using existing MGS\n"
105 "\t\tnoscrub: do NOT auto start OI scrub unless requested\n"
106 "\t\tskip_lfsck: do NOT auto resume paused/crashed LFSCK\n"
107 "\t\tmax_sectors_kb=<size>: set device max_sectors_kb to size or leaves it untouched if size=0\n"
108 "\t\t\tIf not specified, device max_sectors_kb will be set to max_hw_sectors_kb\n"
109 "\t\tmd_stripe_cache_size=<num>: set MD RAID device stripe cache size\n"
110 "\t<cliopt>: one or more comma separated client options:\n"
111 "\t\texclude=<ostname>[:<ostname>]: list of inactive OSTs (e.g. lustre-OST0001)\n"
112 "\t\tlocalflock: enable POSIX flock only on local client\n"
113 "\t\tretry=<num>: number of times mount is retried by client\n"
115 "\t\tskpath=<file|directory>: path of keys to load into kernel keyring\n"
117 "\t\t(no)user_fid2path: disable* or enable user $MOUNT/.lustre/fid access\n"
118 "\t\t(no)checksum: disable or enable* data checksums\n"
119 "\t\t(no)lruresize: disable or enable* LDLM dynamic LRU size\n"
120 "\t\t(no)lazystatfs: disable or enable* statfs to work if OST is unavailable\n"
121 "\t\t32bitapi: return only 32-bit inode numbers to userspace\n"
122 "\t\t(no)verbose: disable or enable* messages at filesystem (un,re)mount\n"
123 #ifdef HAVE_LUSTRE_CRYPTO
124 #ifdef HAVE_LIBKEYUTILS
125 "\t\ttest_dummy_encryption: enable test dummy encryption mode\n"
127 "\t\tnoencrypt: disable client side encryption\n"
130 exit((out != stdout) ? EINVAL : 0);
133 /* Get rid of symbolic hostnames for tcp, since kernel can't do lookups */
134 #define MAXNIDSTR 1024
135 static char *convert_hostnames(char *s1)
137 char *converted, *s2 = 0, *c;
139 int left = MAXNIDSTR;
142 converted = malloc(left);
144 fprintf(stderr, "out of memory: needed %d bytes\n",
149 while ((left > 0) && (*s1 != '/')) {
150 s2 = strpbrk(s1, ",:");
155 nid = libcfs_str2nid(s1);
156 *s2 = sep; /* back to original string */
157 if (nid == LNET_NID_ANY)
159 c += scnprintf(c, left, "%s%c", libcfs_nid2str(nid), sep);
160 left = converted + MAXNIDSTR - c;
163 snprintf(c, left, "%s", s1);
166 fprintf(stderr, "%s: Can't parse NID '%s'\n", progname, s1);
171 /*****************************************************************************
173 * This part was cribbed from util-linux/mount/mount.c. There was no clear
174 * license information, but many other files in the package are identified as
175 * GNU GPL, so it's a pretty safe bet that was their intent.
177 ****************************************************************************/
179 const char *opt; /* option name */
180 int inv; /* true if flag value should be inverted */
181 int mask; /* flag mask value */
184 static const struct opt_map opt_map[] = {
185 /* these flags are parsed by mount, not Lustre */
186 { .opt = "async", .mask = MS_SYNCHRONOUS, .inv = 1 }, /* asynchronous I/O */
187 { .opt = "atime", .mask = MS_NOATIME, .inv = 1 }, /* set access time */
188 { .opt = "auto" }, /* allow auto mount */
189 { .opt = "defaults" }, /* default options */
190 { .opt = "dev", .mask = MS_NODEV, .inv = 1 }, /* interpret devs */
191 { .opt = "exec", .mask = MS_NOEXEC, .inv = 1 }, /* allow execution */
193 { .opt = "noatime", .mask = MS_NOATIME }, /* do not set atime */
194 { .opt = "noauto" }, /* mount explicitly */
195 { .opt = "nodev", .mask = MS_NODEV }, /* no interpret devs */
196 { .opt = "noowner", .inv = 1 }, /* no special privs */
197 { .opt = "nosuid", .mask = MS_NOSUID }, /* do not honor suid */
198 { .opt = "nouser", .inv = 1 }, /* users cannot mount */
199 { .opt = "nousers", .inv = 1 }, /* users cannot mount */
200 { .opt = "_netdev" }, /* network only */
201 { .opt = "noexec", .mask = MS_NOEXEC }, /* no execute */
202 { .opt = "remount", .mask = MS_REMOUNT }, /* remount */
203 { .opt = "ro", .mask = MS_RDONLY }, /* read-only */
204 { .opt = "rw", .mask = MS_RDONLY, .inv = 1 }, /* read-write */
205 { .opt = "suid", .mask = MS_NOSUID, .inv = 1 }, /* honor suid */
206 { .opt = "sync", .mask = MS_SYNCHRONOUS }, /* synchronous I/O */
208 { .opt = "diratime", /* set access time */
209 .mask = MS_NODIRATIME, .inv = 1 }, /* on read */
210 { .opt = "nodiratime", /* do not set access */
211 .mask = MS_NODIRATIME }, /* time on read */
214 { .opt = "norelatime", /* do not set rel */
215 .mask = MS_RELATIME, .inv = 1 }, /* access time */
216 { .opt = "relatime", /* set relative */
217 .mask = MS_RELATIME }, /* access time */
219 #ifdef MS_STRICTATIME
220 { .opt = "strictatime",
221 .mask = MS_STRICTATIME }, /* strict access time */
224 /****************************************************************************/
227 * 1 = don't pass on to lustre
228 * 0 = pass on to lustre
230 static int parse_one_option(const char *check, int *flagp)
232 const struct opt_map *opt;
234 for (opt = &opt_map[0]; opt->opt != NULL; opt++) {
235 if (strncmp(check, opt->opt, strlen(opt->opt)) == 0) {
238 *flagp &= ~(opt->mask);
246 * Assume any unknown options are valid and pass them on. The mount
247 * 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);
294 * Replace options with subset of Lustre-specific options, and
295 * fill in mount flags
297 int parse_options(struct mount_opts *mop, char *orig_options,
298 int *flagp, size_t options_len)
300 char *options, *opt, *nextopt, *arg, *val;
303 options = calloc(strlen(orig_options) + 1, 1);
308 nextopt = orig_options;
309 while ((opt = strsep(&nextopt, ","))) {
314 /* Handle retries in a slightly different manner */
316 val = strchr(opt, '=');
318 * please note that some ldiskfs mount options are also in
319 * the form of param=value. We should pay attention not to
320 * remove those mount options, see bug 22097.
322 if (val && strncmp(arg, "max_sectors_kb", 14) == 0) {
323 mop->mo_max_sectors_kb = atoi(val + 1);
325 strncmp(arg, "md_stripe_cache_size", 20) == 0) {
326 mop->mo_md_stripe_cache_size = atoi(val + 1);
327 } else if (val && strncmp(arg, "retry", 5) == 0) {
328 mop->mo_retry = atoi(val + 1);
329 if (mop->mo_retry > MAX_RETRIES)
330 mop->mo_retry = MAX_RETRIES;
331 else if (mop->mo_retry < 0)
333 } else if (val && strncmp(arg, "mgssec", 6) == 0) {
334 rc = append_option(options, options_len, opt, NULL);
337 } else if (strncmp(arg, "nosvc", 5) == 0) {
339 rc = append_option(options, options_len, opt, NULL);
342 } else if (strcmp(opt, "force") == 0) {
343 /* XXX special check for 'force' option */
345 printf("force: %d\n", mop->mo_force);
347 } else if (val && strncmp(opt, "skpath=", 7) == 0) {
348 if (strlen(val) + 1 >= sizeof(mop->mo_skpath)) {
350 "%s: shared key path too long\n",
355 strncpy(mop->mo_skpath, val + 1,
356 sizeof(mop->mo_skpath) - 1);
358 #ifdef HAVE_LUSTRE_CRYPTO
359 } else if (strncmp(arg, "test_dummy_encryption", 21) == 0) {
360 #ifdef HAVE_LIBKEYUTILS
361 /* Using dummy encryption mode requires inserting a
362 * special dummy key into the session keyring.
363 * Key type is "logon", key description is
364 * "fscrypt:4242424242424242", and key payload has to be
365 * in the form <mode><raw><size>, where:
366 * <mode> is "\x00\x00\x00\x00"
367 * <raw> is "$(printf ""\\\\x%02x"" {0..63})"
368 * <size> is "\x40\x00\x00\x00" for little endian,
369 * "\x00\x00\x00\x40" for big endian.
372 int *p = (int *)payload;
373 char *q = (char *)(p + 1);
383 key = add_key("logon", "fscrypt:4242424242424242",
384 (const void *)payload, sizeof(payload),
385 KEY_SPEC_SESSION_KEYRING);
389 "%s: test dummy encryption option ignored: could not insert dummy encryption key into session keyring\n",
392 /* pass this on as an option */
393 rc = append_option(options, options_len, opt,
398 #else /* HAVE_LIBKEYUTILS */
400 "%s: test dummy encryption option ignored: Lustre not built with libkeyutils support\n",
404 } else if (parse_one_option(opt, flagp) == 0) {
405 /* pass this on as an option */
406 rc = append_option(options, options_len, opt, NULL);
411 #ifdef MS_STRICTATIME
412 #if LUSTRE_VERSION_CODE > OBD_OCD_VERSION(3, 2, 53, 0)
415 * In the future when upstream fixes land in all supported kernels
416 * we should stop forcing MS_STRICTATIME in lustre mounts.
417 * We override the kernel level default of MS_RELATIME for now
418 * due to a kernel vfs level bug in atime updates that fails
419 * to reset timestamps from the future.
421 #warn "remove MS_STRICTATIME override if kernel updates atime from the future"
424 * set strictatime to default if NOATIME or RELATIME
427 if (!(*flagp & (MS_NOATIME | MS_RELATIME)))
428 *flagp |= MS_STRICTATIME;
430 strcpy(orig_options, options);
437 #ifdef HAVE_SERVER_SUPPORT
438 /* Add mgsnids from ldd params */
439 static int add_mgsnids(struct mount_opts *mop, char *options,
440 const char *params, size_t options_len)
442 char *ptr = (char *)params;
446 while ((ptr = strstr(ptr, PARAM_MGSNODE)) != NULL) {
447 sep = strchr(ptr, ' ');
452 rc = append_option(options, options_len, ptr, NULL);
455 mop->mo_have_mgsnid++;
468 static int clear_update_ondisk(char *source, struct lustre_disk_data *ldd)
470 char wanted_mountopts[512] = "";
471 struct mkfs_opts mkop;
475 memset(&mkop, 0, sizeof(mkop));
477 mkop.mo_ldd.ldd_flags &= ~LDD_F_UPDATE;
478 mkop.mo_flags = MO_NOHOSTID_CHECK; /* Ignore missing hostid */
479 if (strlen(source) > sizeof(mkop.mo_device) - 1) {
481 fprintf(stderr, "Device name too long: %s\n", source);
484 strncpy(mkop.mo_device, source, sizeof(mkop.mo_device));
486 ret = osd_prepare_lustre(&mkop,
487 wanted_mountopts, sizeof(wanted_mountopts));
490 fprintf(stderr, "Can't prepare device %s: %s\n",
491 source, strerror(ret));
495 /* Create the loopback file */
496 if (mkop.mo_flags & MO_IS_LOOP) {
497 ret = access(mkop.mo_device, F_OK);
501 fprintf(stderr, "Can't access device %s: %s\n",
502 source, strerror(ret));
506 ret = loop_setup(&mkop);
509 fprintf(stderr, "Loop device setup for %s failed: %s\n",
510 mkop.mo_device, strerror(ret));
514 ret = osd_write_ldd(&mkop);
517 fprintf(stderr, "failed to write local files: %s\n",
521 ret2 = loop_cleanup(&mkop);
528 static int parse_ldd(char *source, struct mount_opts *mop,
529 char *options, size_t options_len)
531 struct lustre_disk_data *ldd = &mop->mo_ldd;
536 rc = osd_is_lustre(source, &ldd->ldd_mount_type);
539 "%s: %s has not been formatted with mkfs.lustre or the backend filesystem type is not supported by this tool\n",
544 rc = osd_read_ldd(source, ldd);
547 "%s: %s failed to read permanent mount data: %s\n",
548 progname, source, rc >= 0 ? strerror(rc) : "");
552 if ((IS_MDT(ldd) || IS_OST(ldd)) &&
553 (ldd->ldd_flags & LDD_F_NEED_INDEX)) {
555 "%s: %s has no index assigned (probably formatted with old mkfs)\n",
560 if (ldd->ldd_flags & LDD_F_UPDATE)
561 clear_update_ondisk(source, ldd);
563 /* Since we never rewrite ldd, ignore temp flags */
564 ldd->ldd_flags &= ~(LDD_F_VIRGIN | LDD_F_WRITECONF |
565 LDD_F_NO_LOCAL_LOGS);
567 /* This is to make sure default options go first */
568 temp_options = strdup(options);
570 fprintf(stderr, "%s: can't allocate memory for temp_options\n",
574 strncpy(options, ldd->ldd_mount_opts, options_len);
575 rc = append_option(options, options_len, temp_options, NULL);
580 /* svname of the form lustre:OST1234 means never registered */
581 rc = strlen(ldd->ldd_svname);
582 if (strcmp(ldd->ldd_svname, "MGS") != 0) {
584 fprintf(stderr, "%s: invalid name '%s'\n",
585 progname, ldd->ldd_svname);
587 } else if (ldd->ldd_svname[rc - 8] == ':') {
588 ldd->ldd_svname[rc - 8] = '-';
589 ldd->ldd_flags |= LDD_F_VIRGIN;
590 } else if (ldd->ldd_svname[rc - 8] == '=') {
591 ldd->ldd_svname[rc - 8] = '-';
592 ldd->ldd_flags |= LDD_F_WRITECONF;
593 } else if (ldd->ldd_svname[rc - 8] == '+') {
594 ldd->ldd_svname[rc - 8] = '-';
595 ldd->ldd_flags |= LDD_F_NO_LOCAL_LOGS;
598 /* backend osd type */
599 rc = append_option(options, options_len, "osd=",
600 mt_type(ldd->ldd_mount_type));
604 if (!mop->mo_have_mgsnid) {
606 * Only use disk data if mount -o mgsnode=nid wasn't
609 if (ldd->ldd_flags & LDD_F_SV_TYPE_MGS) {
610 rc = append_option(options, options_len, "mgs", NULL);
613 mop->mo_have_mgsnid++;
615 if (add_mgsnids(mop, options, ldd->ldd_params,
620 /* Better have an mgsnid by now */
621 if (!mop->mo_have_mgsnid) {
622 fprintf(stderr, "%s: missing option mgsnode=<nid>\n",
627 if (ldd->ldd_flags & LDD_F_VIRGIN) {
628 rc = append_option(options, options_len, "virgin", NULL);
632 if (ldd->ldd_flags & LDD_F_UPDATE) {
633 rc = append_option(options, options_len, "update", NULL);
637 if (ldd->ldd_flags & LDD_F_WRITECONF) {
638 rc = append_option(options, options_len, "writeconf", NULL);
642 if (ldd->ldd_flags & LDD_F_NO_LOCAL_LOGS) {
643 rc = append_option(options, options_len, "nolocallogs", NULL);
647 if (ldd->ldd_flags & LDD_F_NO_PRIMNODE) {
648 rc = append_option(options, options_len, "noprimnode", NULL);
654 * prefix every lustre parameter with param= so that in-kernel
655 * mount can recognize them properly and send to MGS at registration
657 start = ldd->ldd_params;
658 while (start && *start != '\0') {
659 while (*start == ' ')
664 start = strchr(cur, ' ');
669 rc = append_option(options, options_len, "param=", cur);
674 /* svname must be last option */
675 rc = append_option(options, options_len, "svname=", ldd->ldd_svname);
679 #endif /* HAVE_SERVER_SUPPORT */
681 static void set_defaults(struct mount_opts *mop)
683 memset(mop, 0, sizeof(*mop));
684 mop->mo_usource = NULL;
685 mop->mo_source = NULL;
690 mop->mo_have_mgsnid = 0;
691 mop->mo_md_stripe_cache_size = 16384;
692 mop->mo_orig_options = "";
694 mop->mo_max_sectors_kb = -1;
697 static int parse_opts(int argc, char *const argv[], struct mount_opts *mop)
699 static struct option long_opts[] = {
700 { .val = 1, .name = "force", .has_arg = no_argument },
701 { .val = 'f', .name = "fake", .has_arg = no_argument },
702 { .val = 'h', .name = "help", .has_arg = no_argument },
703 { .val = 'n', .name = "nomtab", .has_arg = no_argument },
704 { .val = 'o', .name = "options", .has_arg = required_argument },
705 { .val = 'v', .name = "verbose", .has_arg = no_argument },
706 { .val = 'V', .name = "version", .has_arg = no_argument },
708 char real_path[PATH_MAX] = {'\0'};
710 char path[256], name[256];
715 while ((opt = getopt_long(argc, argv, "fhno:vV",
716 long_opts, NULL)) != EOF){
720 printf("force: %d\n", mop->mo_force);
724 printf("fake: %d\n", mop->mo_fake);
731 printf("nomtab: %d\n", mop->mo_nomtab);
734 mop->mo_orig_options = optarg;
741 fprintf(stdout, "%s %s %s\n", progname,
742 LUSTRE_VERSION_STRING, WITH_LIBMOUNT);
745 fprintf(stderr, "%s: unknown option '%c'\n",
752 if (optind + 2 > argc) {
753 fprintf(stderr, "%s: too few arguments\n", progname);
757 mop->mo_usource = argv[optind];
758 if (!mop->mo_usource)
762 * Try to get the real path to the device, in case it is a
763 * symbolic link for instance
765 if (realpath(mop->mo_usource, real_path) != NULL) {
766 ptr = strrchr(real_path, '/');
767 if (ptr && strncmp(ptr, "/dm-", 4) == 0 &&
768 isdigit(*(ptr + 4))) {
769 snprintf(path, sizeof(path), "/sys/block/%s/dm/name",
771 if ((f = fopen(path, "r"))) {
772 /* read "<name>\n" from sysfs */
773 if (fgets(name, sizeof(name), f) &&
774 (sz = strlen(name)) > 1) {
776 snprintf(real_path, sizeof(real_path),
777 "/dev/mapper/%s", name);
782 mop->mo_usource = strdup(real_path);
785 ptr = strstr(mop->mo_usource, ":/");
787 mop->mo_source = convert_hostnames(mop->mo_usource);
791 mop->mo_source = strdup(mop->mo_usource);
794 if (realpath(argv[optind + 1], mop->mo_target) == NULL) {
796 fprintf(stderr, "warning: %s: cannot resolve: %s\n",
797 argv[optind + 1], strerror(errno));
804 #ifdef HAVE_SERVER_SUPPORT
806 * change label from <fsname>:<index> to
807 * <fsname>-<index> to indicate the device has
808 * been registered. only if the label is
809 * supposed to be changed and target service
810 * is supposed to start
812 static void label_lustre(struct mount_opts *mop)
817 if (mop->mo_ldd.ldd_flags & (LDD_F_VIRGIN | LDD_F_WRITECONF |
818 LDD_F_NO_LOCAL_LOGS)) {
819 (void)osd_label_lustre(mop);
821 struct lustre_disk_data ldd;
825 * device label could be changed after journal recovery,
826 * it should also be relabeled for mount has succeeded.
828 memset(&ldd, 0, sizeof(ldd));
829 ldd.ldd_mount_type = mop->mo_ldd.ldd_mount_type;
830 rc = osd_read_ldd(mop->mo_source, &ldd);
832 rc = strlen(ldd.ldd_svname);
833 if (rc >= 8 && ldd.ldd_svname[rc - 8] != '-')
834 (void)osd_label_lustre(mop);
838 #endif /* HAVE_SERVER_SUPPORT */
840 int main(int argc, char *const argv[])
842 struct mount_opts mop;
850 progname = strrchr(argv[0], '/');
851 progname = progname ? progname + 1 : argv[0];
855 g_pagesize = sysconf(_SC_PAGESIZE);
856 if (g_pagesize == -1) {
858 printf("error: %d failed to get page size.\n", rc);
861 maxopt_len = MIN(g_pagesize, 64 * 1024);
863 rc = parse_opts(argc, argv, &mop);
868 for (i = 0; i < argc; i++)
869 printf("arg[%d] = %s\n", i, argv[i]);
870 printf("source = %s (%s), target = %s\n", mop.mo_usource,
871 mop.mo_source, mop.mo_target);
872 printf("options = %s\n", mop.mo_orig_options);
875 options = malloc(maxopt_len);
877 fprintf(stderr, "can't allocate memory for options\n");
882 if (strlen(mop.mo_orig_options) >= maxopt_len) {
883 fprintf(stderr, "error: mount options too long\n");
888 strcpy(options, mop.mo_orig_options);
889 rc = parse_options(&mop, options, &flags, maxopt_len);
891 fprintf(stderr, "%s: can't parse options: %s\n",
897 rc = check_mtab_entry(mop.mo_usource, mop.mo_source,
898 mop.mo_target, "lustre");
899 if (rc && !(flags & MS_REMOUNT)) {
901 "%s: according to %s %s is already mounted on %s\n",
902 progname, MOUNTED, mop.mo_usource,
907 if (!rc && (flags & MS_REMOUNT)) {
909 "%s: according to %s %s is not already mounted on %s\n",
910 progname, MOUNTED, mop.mo_usource,
916 if (flags & MS_REMOUNT)
919 rc = access(mop.mo_target, F_OK);
922 fprintf(stderr, "%s: %s inaccessible: %s\n", progname,
923 mop.mo_target, strerror(errno));
927 client = (strstr(mop.mo_usource, ":/") != NULL);
929 #ifdef HAVE_SERVER_SUPPORT
934 rc = parse_ldd(mop.mo_source, &mop, options, maxopt_len);
939 fprintf(stderr, "%s: cannot mount %s: no server support\n",
940 progname, mop.mo_usource);
946 * In Linux 2.4, the target device doesn't get passed to any of our
947 * functions. So we'll stick it on the end of the options.
949 rc = append_option(options, maxopt_len, "device=", mop.mo_source);
954 printf("mounting device %s at %s, flags=%#x options=%s\n",
955 mop.mo_source, mop.mo_target, flags, options);
957 #ifdef HAVE_SERVER_SUPPORT
958 if (!client && osd_tune_lustre(mop.mo_source, &mop)) {
961 "%s: unable to set tunables for %s (may cause reduced IO performance)\n",
962 argv[0], mop.mo_source);
966 if (mop.mo_skpath[0] != '\0') {
967 /* Treat shared key failures as fatal */
968 rc = load_shared_keys(&mop);
970 fprintf(stderr, "%s: Error loading shared keys: %s\n",
971 progname, strerror(rc));
975 #endif /* HAVE_GSS */
980 /* Prefer filesystem type given on mount command line
981 * so it appears correctly in the /proc/mounts output.
983 if (strstr(argv[0], "mount.lustre_tgt"))
984 fstype = "lustre_tgt";
988 * flags and target get to lustre_get_sb(), but not
989 * lustre_fill_super(). Lustre ignores the flags, but mount
992 for (i = 0, rc = -EAGAIN; i <= mop.mo_retry && rc != 0; i++) {
993 rc = mount(mop.mo_source, mop.mo_target, fstype,
994 flags, (void *)options);
998 "%s: mount -t %s %s at %s failed: %s retries left: %d\n",
999 basename(progname), fstype,
1000 mop.mo_usource, mop.mo_target,
1005 /* Pre-2.13 Lustre without 'lustre_tgt' type?
1006 * Try with 'lustre' instead. Eventually this
1007 * can be removed (e.g. 2.18 or whenever).
1009 if (errno == ENODEV &&
1010 strcmp(fstype, "lustre_tgt") == 0) {
1017 int limit = i / 2 > 5 ? i / 2 : 5;
1023 #ifdef HAVE_SERVER_SUPPORT
1037 cli = strrchr(mop.mo_usource, ':');
1038 if (cli && (strlen(cli) > 2))
1043 fprintf(stderr, "%s: mount %s at %s failed: %s\n", progname,
1044 mop.mo_usource, mop.mo_target, strerror(errno));
1047 "Is the backend filesystem mounted?\n Check /etc/mtab and /proc/mounts\n");
1048 if (errno == ENODEV)
1050 "Are the lustre modules loaded?\n Check /etc/modprobe.conf and /proc/filesystems\n");
1051 if (errno == ENOTBLK)
1052 fprintf(stderr, "Do you need -o loop?\n");
1053 if (errno == ENOMEDIUM)
1055 "This filesystem needs at least 1 OST\n");
1056 if (errno == ENOENT) {
1057 fprintf(stderr, "Is the MGS specification correct?\n");
1058 fprintf(stderr, "Is the filesystem name correct?\n");
1060 "If upgrading, is the copied client log valid? (see upgrade docs)\n");
1062 if (errno == EALREADY)
1064 "The target service is already running. (%s)\n",
1068 "The target service failed to start (bad config log?) (%s). See /var/log/messages.\n",
1071 fprintf(stderr, "Is the MGS running?\n");
1072 if (errno == EADDRINUSE)
1074 "The target service's index is already in use. (%s)\n",
1076 if (errno == EINVAL) {
1077 fprintf(stderr, "This may have multiple causes.\n");
1080 "Is '%s' the correct filesystem name?\n",
1082 fprintf(stderr, "Are the mount options correct?\n");
1083 fprintf(stderr, "Check the syslog for more info.\n");
1086 /* May as well try to clean up loop devs */
1087 if (strncmp(mop.mo_usource, "/dev/loop", 9) == 0) {
1091 sprintf(cmd, "/sbin/losetup -d %s", mop.mo_usource);
1092 if ((ret = system(cmd)) < 0)
1095 rc = WEXITSTATUS(ret);
1100 * Deal with utab just for client. Note that we ignore
1101 * the return value here since it is not worth to fail
1102 * mount by prevent some rare cases
1104 if (strstr(mop.mo_usource, ":/") != NULL)
1105 update_utab_entry(&mop);
1106 if (!mop.mo_nomtab) {
1107 rc = update_mtab_entry(mop.mo_usource, mop.mo_target,
1108 "lustre", mop.mo_orig_options,
1114 #ifdef HAVE_SERVER_SUPPORT
1122 /* mo_usource should be freed, but we can rely on the kernel */
1123 free(mop.mo_source);