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