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