Whamcloud - gitweb
b=19689
[fs/lustre-release.git] / lustre / utils / mount_lustre.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * GPL HEADER START
5  *
6  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 only,
10  * as published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * General Public License version 2 for more details (a copy is included
16  * in the LICENSE file that accompanied this code).
17  *
18  * You should have received a copy of the GNU General Public License
19  * version 2 along with this program; If not, see
20  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
21  *
22  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23  * CA 95054 USA or visit www.sun.com if you need additional information or
24  * have any questions.
25  *
26  * GPL HEADER END
27  */
28 /*
29  * Copyright  2008 Sun Microsystems, Inc. All rights reserved
30  * Use is subject to license terms.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  *
36  * lustre/utils/mount_lustre.c
37  *
38  * Author: Robert Read <rread@clusterfs.com>
39  * Author: Nathan Rutman <nathan@clusterfs.com>
40  */
41
42
43 #ifndef _GNU_SOURCE
44 #define _GNU_SOURCE
45 #endif
46 #include <stdlib.h>
47 #include <stdio.h>
48 #include <unistd.h>
49 #include <fcntl.h>
50 #include <errno.h>
51 #include <string.h>
52 #include <sys/mount.h>
53 #include <mntent.h>
54 #include <getopt.h>
55 #include "obdctl.h"
56 #include <lustre_ver.h>
57 #include <glob.h>
58 #include <ctype.h>
59 #include <limits.h>
60 #include "mount_utils.h"
61
62 #define MAX_HW_SECTORS_KB_PATH  "queue/max_hw_sectors_kb"
63 #define MAX_SECTORS_KB_PATH     "queue/max_sectors_kb"
64 #define STRIPE_CACHE_SIZE       "md/stripe_cache_size"
65 #define MAX_RETRIES 99
66
67 int          verbose = 0;
68 int          nomtab = 0;
69 int          fake = 0;
70 int          force = 0;
71 int          retry = 0;
72 int          md_stripe_cache_size = 2048;
73 char         *progname = NULL;
74
75 void usage(FILE *out)
76 {
77         fprintf(out, "%s v"LUSTRE_VERSION_STRING"\n", progname);
78         fprintf(out, "\nThis mount helper should only be invoked via the "
79                 "mount (8) command,\ne.g. mount -t lustre dev dir\n\n");
80         fprintf(out, "usage: %s [-fhnv] [-o <mntopt>] <device> <mountpt>\n",
81                 progname);
82         fprintf(out,
83                 "\t<device>: the disk device, or for a client:\n"
84                 "\t\t<mgmtnid>[:<altmgtnid>...]:/<filesystem>-client\n"
85                 "\t<filesystem>: name of the Lustre filesystem (e.g. lustre1)\n"
86                 "\t<mountpt>: filesystem mountpoint (e.g. /mnt/lustre)\n"
87                 "\t-f|--fake: fake mount (updates /etc/mtab)\n"
88                 "\t-o force|--force: force mount even if already in /etc/mtab\n"
89                 "\t-h|--help: print this usage message\n"
90                 "\t-n|--nomtab: do not update /etc/mtab after mount\n"
91                 "\t-v|--verbose: print verbose config settings\n"
92                 "\t<mntopt>: one or more comma separated of:\n"
93                 "\t\t(no)flock,(no)user_xattr,(no)acl\n"
94                 "\t\tnosvc: only start MGC/MGS obds\n"
95                 "\t\tnomgs: only start target obds, using existing MGS\n"
96                 "\t\texclude=<ostname>[:<ostname>] : colon-separated list of "
97                 "inactive OSTs (e.g. lustre-OST0001)\n"
98                 "\t\tretry=<num>: number of times mount is retried by client\n"
99                 "\t\tmd_stripe_cache_size=<num>: set the raid stripe cache "
100                 "size for the underlying raid if present\n"
101                 );
102         exit((out != stdout) ? EINVAL : 0);
103 }
104
105 static int check_mtab_entry(char *spec, char *mtpt, char *type)
106 {
107         FILE *fp;
108         struct mntent *mnt;
109
110         fp = setmntent(MOUNTED, "r");
111         if (fp == NULL)
112                 return(0);
113
114         while ((mnt = getmntent(fp)) != NULL) {
115                 if (strcmp(mnt->mnt_fsname, spec) == 0 &&
116                         strcmp(mnt->mnt_dir, mtpt) == 0 &&
117                         strcmp(mnt->mnt_type, type) == 0) {
118                         endmntent(fp);
119                         return(EEXIST);
120                 }
121         }
122         endmntent(fp);
123
124         return(0);
125 }
126
127 static int
128 update_mtab_entry(char *spec, char *mtpt, char *type, char *opts,
129                   int flags, int freq, int pass)
130 {
131         FILE *fp;
132         struct mntent mnt;
133         int rc = 0;
134
135         mnt.mnt_fsname = spec;
136         mnt.mnt_dir = mtpt;
137         mnt.mnt_type = type;
138         mnt.mnt_opts = opts ? opts : "";
139         mnt.mnt_freq = freq;
140         mnt.mnt_passno = pass;
141
142         fp = setmntent(MOUNTED, "a+");
143         if (fp == NULL) {
144                 fprintf(stderr, "%s: setmntent(%s): %s:",
145                         progname, MOUNTED, strerror (errno));
146                 rc = 16;
147         } else {
148                 if ((addmntent(fp, &mnt)) == 1) {
149                         fprintf(stderr, "%s: addmntent: %s:",
150                                 progname, strerror (errno));
151                         rc = 16;
152                 }
153                 endmntent(fp);
154         }
155
156         return rc;
157 }
158
159 /* Get rid of symbolic hostnames for tcp, since kernel can't do lookups */
160 #define MAXNIDSTR 1024
161 static char *convert_hostnames(char *s1)
162 {
163         char *converted, *s2 = 0, *c;
164         char sep;
165         int left = MAXNIDSTR;
166         lnet_nid_t nid;
167
168         converted = malloc(left);
169         if (converted == NULL) {
170                 fprintf(stderr, "out of memory: needed %d bytes\n",
171                         MAXNIDSTR);
172                 return NULL;
173         }
174         c = converted;
175         while ((left > 0) && (*s1 != '/')) {
176                 s2 = strpbrk(s1, ",:");
177                 if (!s2)
178                         goto out_free;
179                 sep = *s2;
180                 *s2 = '\0';
181                 nid = libcfs_str2nid(s1);
182                 *s2 = sep;                      /* back to original string */
183                 if (nid == LNET_NID_ANY)
184                         goto out_free;
185                 c += snprintf(c, left, "%s%c", libcfs_nid2str(nid), sep);
186                 left = converted + MAXNIDSTR - c;
187                 s1 = s2 + 1;
188         }
189         snprintf(c, left, "%s", s1);
190         return converted;
191 out_free:
192         fprintf(stderr, "%s: Can't parse NID '%s'\n", progname, s1);
193         free(converted);
194         return NULL;
195 }
196
197 /*****************************************************************************
198  *
199  * This part was cribbed from util-linux/mount/mount.c.  There was no clear
200  * license information, but many other files in the package are identified as
201  * GNU GPL, so it's a pretty safe bet that was their intent.
202  *
203  ****************************************************************************/
204 struct opt_map {
205         const char *opt;        /* option name */
206         int inv;                /* true if flag value should be inverted */
207         int mask;               /* flag mask value */
208 };
209
210 static const struct opt_map opt_map[] = {
211   /*"optname", inv,ms_mask */
212   /* These flags are parsed by mount, not lustre */
213   { "defaults", 0, 0         },      /* default options */
214   { "remount",  0, MS_REMOUNT},      /* remount with different options */
215   { "rw",       1, MS_RDONLY },      /* read-write */
216   { "ro",       0, MS_RDONLY },      /* read-only */
217   { "exec",     1, MS_NOEXEC },      /* permit execution of binaries */
218   { "noexec",   0, MS_NOEXEC },      /* don't execute binaries */
219   { "suid",     1, MS_NOSUID },      /* honor suid executables */
220   { "nosuid",   0, MS_NOSUID },      /* don't honor suid executables */
221   { "dev",      1, MS_NODEV  },      /* interpret device files  */
222   { "nodev",    0, MS_NODEV  },      /* don't interpret devices */
223   { "sync",     0, MS_SYNCHRONOUS},  /* synchronous I/O */
224   { "async",    1, MS_SYNCHRONOUS},  /* asynchronous I/O */
225   { "atime",    1, MS_NOATIME  },    /* set file access time on read */
226   { "noatime",  0, MS_NOATIME  },    /* do not set file access time on read */
227 #ifdef MS_NODIRATIME
228   { "diratime", 1, MS_NODIRATIME },  /* set file access time on read */
229   { "nodiratime",0,MS_NODIRATIME },  /* do not set file access time on read */
230 #endif
231 #ifdef MS_RELATIME
232   { "relatime", 0, MS_RELATIME },  /* set file access time on read */
233   { "norelatime",1,MS_RELATIME },  /* do not set file access time on read */
234 #endif
235   { "auto",     0, 0         },      /* Can be mounted using -a */
236   { "noauto",   0, 0         },      /* Can only be mounted explicitly */
237   { "nousers",  1, 0         },      /* Forbid ordinary user to mount */
238   { "nouser",   1, 0         },      /* Forbid ordinary user to mount */
239   { "noowner",  1, 0         },      /* Device owner has no special privs */
240   { "_netdev",  0, 0         },      /* Device accessible only via network */
241   { NULL,       0, 0         }
242 };
243 /****************************************************************************/
244
245 /* 1  = don't pass on to lustre
246    0  = pass on to lustre */
247 static int parse_one_option(const char *check, int *flagp)
248 {
249         const struct opt_map *opt;
250
251         for (opt = &opt_map[0]; opt->opt != NULL; opt++) {
252                 if (strncmp(check, opt->opt, strlen(opt->opt)) == 0) {
253                         if (opt->mask) {
254                                 if (opt->inv)
255                                         *flagp &= ~(opt->mask);
256                                 else
257                                         *flagp |= opt->mask;
258                         }
259                         return 1;
260                 }
261         }
262         /* Assume any unknown options are valid and pass them on.  The mount
263            will fail if lmd_parse, ll_options or ldiskfs doesn't recognize it.*/
264         return 0;
265 }
266
267 /* Replace options with subset of Lustre-specific options, and
268    fill in mount flags */
269 int parse_options(char *orig_options, int *flagp)
270 {
271         char *options, *opt, *nextopt, *arg, *val;
272
273         options = calloc(strlen(orig_options) + 1, 1);
274         *flagp = 0;
275         nextopt = orig_options;
276         while ((opt = strsep(&nextopt, ","))) {
277                 if (!*opt)
278                         /* empty option */
279                         continue;
280
281                 /* Handle retries in a slightly different
282                  * manner */
283                 arg = opt;
284                 val = strchr(opt, '=');
285                 if (val != NULL) {
286                         if (strncmp(arg, "md_stripe_cache_size", 20) == 0) {
287                                 md_stripe_cache_size = atoi(val + 1);
288                         } else if (strncmp(arg, "retry", 5) == 0) {
289                                 retry = atoi(val + 1);
290                                 if (retry > MAX_RETRIES)
291                                         retry = MAX_RETRIES;
292                                 else if (retry < 0)
293                                         retry = 0;
294                         }
295                 } else if (strncmp(opt, "force", 5) == 0) {
296                         //XXX special check for 'force' option
297                         ++force;
298                         printf("force: %d\n", force);
299                 } else if (parse_one_option(opt, flagp) == 0) {
300                         /* pass this on as an option */
301                         if (*options)
302                                 strcat(options, ",");
303                         strcat(options, opt);
304                 }
305         }
306         strcpy(orig_options, options);
307         free(options);
308         return 0;
309 }
310
311
312 int read_file(char *path, char *buf, int size)
313 {
314         FILE *fd;
315
316         fd = fopen(path, "r");
317         if (fd == NULL)
318                 return errno;
319
320         /* should not ignore fgets(3)'s return value */
321         if (!fgets(buf, size, fd)) {
322                 fprintf(stderr, "reading from %s: %s", path, strerror(errno));
323                 fclose(fd);
324                 return 1;
325         }
326         fclose(fd);
327         return 0;
328 }
329
330 int write_file(char *path, char *buf)
331 {
332         FILE *fd;
333
334         fd = fopen(path, "w");
335         if (fd == NULL)
336                 return errno;
337
338         fputs(buf, fd);
339         fclose(fd);
340         return 0;
341 }
342
343 /* This is to tune the kernel for good SCSI performance.
344  * For that we set the value of /sys/block/{dev}/queue/max_sectors_kb
345  * to the value of /sys/block/{dev}/queue/max_hw_sectors_kb */
346 int set_blockdev_tunables(char *source)
347 {
348         glob_t glob_info;
349         struct stat stat_buf;
350         char *chk_major, *chk_minor;
351         char *savept = NULL, *dev;
352         char *ret_path;
353         char buf[PATH_MAX] = {'\0'}, path[PATH_MAX] = {'\0'};
354         char real_path[PATH_MAX] = {'\0'};
355         int i, rc = 0;
356         int major, minor;
357
358         if (!source)
359                 return -EINVAL;
360
361         ret_path = realpath(source, real_path);
362         if (ret_path == NULL) {
363                 if (verbose)
364                         fprintf(stderr, "warning: %s: cannot resolve: %s\n",
365                                 source, strerror(errno));
366                 return -EINVAL;
367         }
368
369         if (strncmp(real_path, "/dev/loop", 9) == 0)
370                 return 0;
371
372         if ((real_path[0] != '/') && (strpbrk(real_path, ",:") != NULL))
373                 return 0;
374
375         snprintf(path, sizeof(path), "/sys/block%s", real_path + 4);
376         if (access(path, X_OK) == 0)
377                 goto set_params;
378
379         /* The name of the device say 'X' specified in /dev/X may not
380          * match any entry under /sys/block/. In that case we need to
381          * match the major/minor number to find the entry under
382          * sys/block corresponding to /dev/X */
383         dev = real_path + strlen(real_path);
384         while (--dev > real_path && isdigit(*dev))
385                 *dev = 0;
386
387         if (strncmp(real_path, "/dev/md_", 8) == 0)
388                 *dev = 0;
389
390         rc = stat(real_path, &stat_buf);
391         if (rc) {
392                 if (verbose)
393                         fprintf(stderr, "warning: %s, device %s stat failed\n",
394                                 strerror(errno), real_path);
395                 return rc;
396         }
397
398         major = major(stat_buf.st_rdev);
399         minor = minor(stat_buf.st_rdev);
400         rc = glob("/sys/block/*", GLOB_NOSORT, NULL, &glob_info);
401         if (rc) {
402                 if (verbose)
403                         fprintf(stderr, "warning: failed to read entries under "
404                                 "/sys/block\n");
405                 return rc;
406         }
407
408         for (i = 0; i < glob_info.gl_pathc; i++){
409                 snprintf(path, sizeof(path), "%s/dev", glob_info.gl_pathv[i]);
410
411                 rc = read_file(path, buf, sizeof(buf));
412                 if (rc)
413                         continue;
414
415                 if (buf[strlen(buf) - 1] == '\n')
416                         buf[strlen(buf) - 1] = '\0';
417
418                 chk_major = strtok_r(buf, ":", &savept);
419                 chk_minor = savept;
420                 if (major == atoi(chk_major) &&minor == atoi(chk_minor))
421                         break;
422         }
423
424         if (i == glob_info.gl_pathc) {
425                 if (verbose)
426                         fprintf(stderr,"warning: device %s does not match any "
427                                 "entry under /sys/block\n", real_path);
428                 globfree(&glob_info);
429                 return -EINVAL;
430         }
431
432         /* Chop off "/dev" from path we found */
433         path[strlen(glob_info.gl_pathv[i])] = '\0';
434         globfree(&glob_info);
435
436 set_params:
437         if (strncmp(real_path, "/dev/md", 7) == 0) {
438                 snprintf(real_path, sizeof(real_path), "%s/%s", path,
439                          STRIPE_CACHE_SIZE);
440
441                 rc = read_file(real_path, buf, sizeof(buf));
442                 if (rc) {
443                         if (verbose)
444                                 fprintf(stderr, "warning: opening %s: %s\n",
445                                         real_path, strerror(errno));
446                         return rc;
447                 }
448
449                 if (atoi(buf) >= md_stripe_cache_size)
450                         return 0;
451
452                 if (strlen(buf) - 1 > 0) {
453                         snprintf(buf, sizeof(buf), "%d", md_stripe_cache_size);
454                         rc = write_file(real_path, buf);
455                         if (rc && verbose)
456                                 fprintf(stderr, "warning: opening %s: %s\n",
457                                         real_path, strerror(errno));
458                 }
459                 /* Return since raid and disk tunables are different */
460                 return rc;
461         }
462
463         snprintf(real_path, sizeof(real_path), "%s/%s", path,
464                  MAX_HW_SECTORS_KB_PATH);
465         rc = read_file(real_path, buf, sizeof(buf));
466         if (rc) {
467                 if (verbose)
468                         fprintf(stderr, "warning: opening %s: %s\n",
469                                 real_path, strerror(errno));
470                 return rc;
471         }
472
473         if (strlen(buf) - 1 > 0) {
474                 snprintf(real_path, sizeof(real_path), "%s/%s", path,
475                          MAX_SECTORS_KB_PATH);
476                 rc = write_file(real_path, buf);
477                 if (rc && verbose)
478                         fprintf(stderr, "warning: writing to %s: %s\n",
479                                 real_path, strerror(errno));
480         }
481         return rc;
482 }
483
484 int main(int argc, char *const argv[])
485 {
486         char default_options[] = "";
487         char *usource, *source, *target, *ptr;
488         char *options, *optcopy, *orig_options = default_options;
489         int i, nargs = 3, opt, rc, flags, optlen;
490         static struct option long_opt[] = {
491                 {"fake", 0, 0, 'f'},
492                 {"force", 0, 0, 1},
493                 {"help", 0, 0, 'h'},
494                 {"nomtab", 0, 0, 'n'},
495                 {"options", 1, 0, 'o'},
496                 {"verbose", 0, 0, 'v'},
497                 {0, 0, 0, 0}
498         };
499
500         progname = strrchr(argv[0], '/');
501         progname = progname ? progname + 1 : argv[0];
502
503         while ((opt = getopt_long(argc, argv, "fhno:v",
504                                   long_opt, NULL)) != EOF){
505                 switch (opt) {
506                 case 1:
507                         ++force;
508                         printf("force: %d\n", force);
509                         nargs++;
510                         break;
511                 case 'f':
512                         ++fake;
513                         printf("fake: %d\n", fake);
514                         nargs++;
515                         break;
516                 case 'h':
517                         usage(stdout);
518                         break;
519                 case 'n':
520                         ++nomtab;
521                         printf("nomtab: %d\n", nomtab);
522                         nargs++;
523                         break;
524                 case 'o':
525                         orig_options = optarg;
526                         nargs++;
527                         break;
528                 case 'v':
529                         ++verbose;
530                         nargs++;
531                         break;
532                 default:
533                         fprintf(stderr, "%s: unknown option '%c'\n",
534                                 progname, opt);
535                         usage(stderr);
536                         break;
537                 }
538         }
539
540         if (optind + 2 > argc) {
541                 fprintf(stderr, "%s: too few arguments\n", progname);
542                 usage(stderr);
543         }
544
545         usource = argv[optind];
546         if (!usource) {
547                 usage(stderr);
548         }
549
550         source = convert_hostnames(usource);
551         if (!source) {
552                 usage(stderr);
553         }
554
555         target = argv[optind + 1];
556         ptr = target + strlen(target) - 1;
557         while ((ptr > target) && (*ptr == '/')) {
558                 *ptr = 0;
559                 ptr--;
560         }
561
562         if (verbose) {
563                 for (i = 0; i < argc; i++)
564                         printf("arg[%d] = %s\n", i, argv[i]);
565                 printf("source = %s (%s), target = %s\n", usource, source, target);
566                 printf("options = %s\n", orig_options);
567         }
568
569         options = malloc(strlen(orig_options) + 1);
570         if (options == NULL) {
571                 fprintf(stderr, "can't allocate memory for options\n");
572                 return -1;
573         }
574         strcpy(options, orig_options);
575         rc = parse_options(options, &flags);
576         if (rc) {
577                 fprintf(stderr, "%s: can't parse options: %s\n",
578                         progname, options);
579                 return(EINVAL);
580         }
581
582         if (!force) {
583                 rc = check_mtab_entry(usource, target, "lustre");
584                 if (rc && !(flags & MS_REMOUNT)) {
585                         fprintf(stderr, "%s: according to %s %s is "
586                                 "already mounted on %s\n",
587                                 progname, MOUNTED, usource, target);
588                         return(EEXIST);
589                 }
590                 if (!rc && (flags & MS_REMOUNT)) {
591                         fprintf(stderr, "%s: according to %s %s is "
592                                 "not already mounted on %s\n",
593                                 progname, MOUNTED, usource, target);
594                         return(ENOENT);
595                 }
596         }
597         if (flags & MS_REMOUNT)
598                 nomtab++;
599
600         rc = access(target, F_OK);
601         if (rc) {
602                 rc = errno;
603                 fprintf(stderr, "%s: %s inaccessible: %s\n", progname, target,
604                         strerror(errno));
605                 return rc;
606         }
607
608         /* In Linux 2.4, the target device doesn't get passed to any of our
609            functions.  So we'll stick it on the end of the options. */
610         optlen = strlen(options) + strlen(",device=") + strlen(source) + 1;
611         optcopy = malloc(optlen);
612         if (optcopy == NULL) {
613                 fprintf(stderr, "can't allocate memory to optcopy\n");
614                 return -1;
615         }
616         strcpy(optcopy, options);
617         if (*optcopy)
618                 strcat(optcopy, ",");
619         strcat(optcopy, "device=");
620         strcat(optcopy, source);
621
622         if (verbose)
623                 printf("mounting device %s at %s, flags=%#x options=%s\n",
624                        source, target, flags, optcopy);
625
626         if (!strstr(usource, ":/") && set_blockdev_tunables(source)) {
627                 if (verbose)
628                         fprintf(stderr, "%s: unable to set tunables for %s"
629                                 " (may cause reduced IO performance)\n",
630                                 argv[0], source);
631         }
632
633         register_service_tags(usource, source, target);
634
635         if (!fake) {
636                 /* flags and target get to lustre_get_sb, but not
637                    lustre_fill_super.  Lustre ignores the flags, but mount
638                    does not. */
639                 for (i = 0, rc = -EAGAIN; i <= retry && rc != 0; i++) {
640                         rc = mount(source, target, "lustre", flags,
641                                    (void *)optcopy);
642                         if (rc) {
643                                 if (verbose) {
644                                         fprintf(stderr, "%s: mount %s at %s "
645                                                 "failed: %s retries left: "
646                                                 "%d\n", basename(progname),
647                                                 usource, target,
648                                                 strerror(errno), retry-i);
649                                 }
650
651                                 if (retry) {
652                                         sleep(1 << max((i/2), 5));
653                                 }
654                                 else {
655                                         rc = errno;
656                                 }
657                         }
658                 }
659         }
660
661         if (rc) {
662                 char *cli;
663
664                 rc = errno;
665
666                 cli = strrchr(usource, ':');
667                 if (cli && (strlen(cli) > 2))
668                         cli += 2;
669                 else
670                         cli = NULL;
671
672                 fprintf(stderr, "%s: mount %s at %s failed: %s\n", progname,
673                         usource, target, strerror(errno));
674                 if (errno == ENODEV)
675                         fprintf(stderr, "Are the lustre modules loaded?\n"
676                                 "Check /etc/modprobe.conf and /proc/filesystems"
677                                 "\nNote 'alias lustre llite' should be removed"
678                                 " from modprobe.conf\n");
679                 if (errno == ENOTBLK)
680                         fprintf(stderr, "Do you need -o loop?\n");
681                 if (errno == ENOMEDIUM)
682                         fprintf(stderr,
683                                 "This filesystem needs at least 1 OST\n");
684                 if (errno == ENOENT) {
685                         fprintf(stderr, "Is the MGS specification correct?\n");
686                         fprintf(stderr, "Is the filesystem name correct?\n");
687                         fprintf(stderr, "If upgrading, is the copied client log"
688                                 " valid? (see upgrade docs)\n");
689                 }
690                 if (errno == EALREADY)
691                         fprintf(stderr, "The target service is already running."
692                                 " (%s)\n", usource);
693                 if (errno == ENXIO)
694                         fprintf(stderr, "The target service failed to start "
695                                 "(bad config log?) (%s).  "
696                                 "See /var/log/messages.\n", usource);
697                 if (errno == EIO)
698                         fprintf(stderr, "Is the MGS running?\n");
699                 if (errno == EADDRINUSE)
700                         fprintf(stderr, "The target service's index is already "
701                                 "in use. (%s)\n", usource);
702                 if (errno == EINVAL) {
703                         fprintf(stderr, "This may have multiple causes.\n");
704                         if (cli)
705                                 fprintf(stderr, "Is '%s' the correct filesystem"
706                                         " name?\n", cli);
707                         fprintf(stderr, "Are the mount options correct?\n");
708                         fprintf(stderr, "Check the syslog for more info.\n");
709                 }
710
711                 /* May as well try to clean up loop devs */
712                 if (strncmp(usource, "/dev/loop", 9) == 0) {
713                         char cmd[256];
714                         int ret;
715                         sprintf(cmd, "/sbin/losetup -d %s", usource);
716                         if ((ret = system(cmd)) < 0)
717                                 rc = errno;
718                         else if (ret > 0)
719                                 rc = WEXITSTATUS(ret);
720                 }
721
722         } else if (!nomtab) {
723                 rc = update_mtab_entry(usource, target, "lustre", orig_options,
724                                        0,0,0);
725         }
726
727         free(optcopy);
728         free(source);
729         return rc;
730 }