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