]> git.decadent.org.uk Git - nfs-utils.git/blob - utils/mount/stropts.c
Change the fix_mounthost_option() function to support resolving IPv6
[nfs-utils.git] / utils / mount / stropts.c
1 /*
2  * stropts.c -- NFS mount using C string to pass options to kernel
3  *
4  * Copyright (C) 2007 Oracle.  All rights reserved.
5  * Copyright (C) 2007 Chuck Lever <chuck.lever@oracle.com>
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public
18  * License along with this program; if not, write to the
19  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20  * Boston, MA 021110-1307, USA.
21  *
22  */
23
24 #ifdef HAVE_CONFIG_H
25 #include <config.h>
26 #endif
27
28 #include <ctype.h>
29 #include <unistd.h>
30 #include <stdio.h>
31 #include <string.h>
32 #include <stdlib.h>
33 #include <errno.h>
34 #include <netdb.h>
35 #include <time.h>
36
37 #include <sys/socket.h>
38 #include <sys/mount.h>
39 #include <netinet/in.h>
40 #include <arpa/inet.h>
41
42 #include "xcommon.h"
43 #include "mount.h"
44 #include "nls.h"
45 #include "nfs_mount.h"
46 #include "mount_constants.h"
47 #include "stropts.h"
48 #include "error.h"
49 #include "network.h"
50 #include "parse_opt.h"
51 #include "version.h"
52
53 #ifdef HAVE_RPCSVC_NFS_PROT_H
54 #include <rpcsvc/nfs_prot.h>
55 #else
56 #include <linux/nfs.h>
57 #define nfsstat nfs_stat
58 #endif
59
60 #ifndef NFS_PORT
61 #define NFS_PORT 2049
62 #endif
63
64 #ifndef NFS_MAXHOSTNAME
65 #define NFS_MAXHOSTNAME         (255)
66 #endif
67
68 #ifndef NFS_MAXPATHNAME
69 #define NFS_MAXPATHNAME         (1024)
70 #endif
71
72 #ifndef NFS_DEF_FG_TIMEOUT_MINUTES
73 #define NFS_DEF_FG_TIMEOUT_MINUTES      (2u)
74 #endif
75
76 #ifndef NFS_DEF_BG_TIMEOUT_MINUTES
77 #define NFS_DEF_BG_TIMEOUT_MINUTES      (10000u)
78 #endif
79
80 extern int nfs_mount_data_version;
81 extern char *progname;
82 extern int verbose;
83 extern int sloppy;
84
85 struct nfsmount_info {
86         const char              *spec,          /* server:/path */
87                                 *node,          /* mounted-on dir */
88                                 *type;          /* "nfs" or "nfs4" */
89         char                    *hostname;      /* server's hostname */
90
91         struct mount_options    *options;       /* parsed mount options */
92         char                    **extra_opts;   /* string for /etc/mtab */
93
94         int                     flags,          /* MS_ flags */
95                                 fake,           /* actually do the mount? */
96                                 child;          /* forked bg child? */
97
98         sa_family_t             family;         /* supported address family */
99 };
100
101 static int nfs_parse_devname(struct nfsmount_info *mi)
102 {
103         int ret = 0;
104         char *dev, *pathname, *s;
105
106         dev = xstrdup(mi->spec);
107
108         if (!(pathname = strchr(dev, ':'))) {
109                 nfs_error(_("%s: remote share not in 'host:dir' format"),
110                                 progname);
111                 goto out;
112         }
113         *pathname = '\0';
114         pathname++;
115
116         /*
117          * We don't need a copy of the pathname, but let's
118          * sanity check it anyway.
119          */
120         if (strlen(pathname) > NFS_MAXPATHNAME) {
121                 nfs_error(_("%s: export pathname is too long"),
122                                 progname);
123                 goto out;
124         }
125
126         /*
127          * Ignore all but first hostname in replicated mounts
128          * until they can be fully supported. (mack@sgi.com)
129          */
130         if ((s = strchr(dev, ','))) {
131                 *s = '\0';
132                 nfs_error(_("%s: warning: multiple hostnames not supported"),
133                                 progname);
134                 nfs_error(_("%s: ignoring hostnames that follow the first one"),
135                                 progname);
136         }
137         mi->hostname = xstrdup(dev);
138         if (strlen(mi->hostname) > NFS_MAXHOSTNAME) {
139                 nfs_error(_("%s: server hostname is too long"),
140                                 progname);
141                 free(mi->hostname);
142                 mi->hostname = NULL;
143                 goto out;
144         }
145
146         ret = 1;
147
148 out:
149         free(dev);
150         return ret;
151 }
152
153 static int fill_ipv4_sockaddr(const char *hostname, struct sockaddr_in *addr)
154 {
155         struct hostent *hp;
156         addr->sin_family = AF_INET;
157
158         if (inet_aton(hostname, &addr->sin_addr))
159                 return 1;
160         if ((hp = gethostbyname(hostname)) == NULL) {
161                 nfs_error(_("%s: can't get address for %s\n"),
162                                 progname, hostname);
163                 return 0;
164         }
165         if (hp->h_length > sizeof(struct in_addr)) {
166                 nfs_error(_("%s: got bad hp->h_length"), progname);
167                 hp->h_length = sizeof(struct in_addr);
168         }
169         memcpy(&addr->sin_addr, hp->h_addr, hp->h_length);
170         return 1;
171 }
172
173 /*
174  * Obtain a retry timeout value based on the value of the "retry=" option.
175  *
176  * Returns a time_t timeout timestamp, in seconds.
177  */
178 static time_t nfs_parse_retry_option(struct mount_options *options,
179                                      unsigned int timeout_minutes)
180 {
181         char *retry_option, *endptr;
182
183         retry_option = po_get(options, "retry");
184         if (retry_option) {
185                 long tmp;
186
187                 errno = 0;
188                 tmp = strtol(retry_option, &endptr, 10);
189                 if (errno == 0 && endptr != retry_option && tmp >= 0)
190                         timeout_minutes = tmp;
191                 else if (verbose)
192                         nfs_error(_("%s: invalid retry timeout was specified; "
193                                         "using default timeout"), progname);
194         }
195
196         return time(NULL) + (time_t)(timeout_minutes * 60);
197 }
198
199 /*
200  * Convert the passed-in sockaddr-style address to presentation
201  * format, then append an option of the form "keyword=address".
202  *
203  * Returns 1 if the option was appended successfully; otherwise zero.
204  */
205 static int nfs_append_generic_address_option(const struct sockaddr *sap,
206                                              const socklen_t salen,
207                                              const char *keyword,
208                                              struct mount_options *options)
209 {
210         char address[NI_MAXHOST];
211         char new_option[512];
212
213         if (!nfs_present_sockaddr(sap, salen, address, sizeof(address)))
214                 goto out_err;
215
216         if (snprintf(new_option, sizeof(new_option), "%s=%s",
217                                         keyword, address) >= sizeof(new_option))
218                 goto out_err;
219
220         if (po_append(options, new_option) != PO_SUCCEEDED)
221                 goto out_err;
222
223         return 1;
224
225 out_err:
226         nfs_error(_("%s: failed to construct %s option"), progname, keyword);
227         return 0;
228 }
229
230 /*
231  * Append the 'addr=' option to the options string to pass a resolved
232  * server address to the kernel.  After a successful mount, this address
233  * is also added to /etc/mtab for use when unmounting.
234  *
235  * If 'addr=' is already present, we strip it out.  This prevents users
236  * from setting a bogus 'addr=' option themselves, and also allows bg
237  * retries to recompute the server's address, in case it has changed.
238  *
239  * Returns 1 if 'addr=' option appended successfully;
240  * otherwise zero.
241  */
242 static int nfs_append_addr_option(const struct sockaddr *sap,
243                                   socklen_t salen,
244                                   struct mount_options *options)
245 {
246         po_remove_all(options, "addr");
247         return nfs_append_generic_address_option(sap, salen, "addr", options);
248 }
249
250 /*
251  * Called to discover our address and append an appropriate 'clientaddr='
252  * option to the options string.
253  *
254  * Returns 1 if 'clientaddr=' option created successfully or if
255  * 'clientaddr=' option is already present; otherwise zero.
256  */
257 static int nfs_append_clientaddr_option(const struct sockaddr *sap,
258                                         socklen_t salen,
259                                         struct mount_options *options)
260 {
261         struct sockaddr_storage dummy;
262         struct sockaddr *my_addr = (struct sockaddr *)&dummy;
263         socklen_t my_len = sizeof(dummy);
264
265         if (po_contains(options, "clientaddr") == PO_FOUND)
266                 return 1;
267
268         nfs_callback_address(sap, salen, my_addr, &my_len);
269
270         return nfs_append_generic_address_option(my_addr, my_len,
271                                                         "clientaddr", options);
272 }
273
274 /*
275  * Resolve the 'mounthost=' hostname and append a new option using
276  * the resulting address.
277  */
278 static int nfs_fix_mounthost_option(const sa_family_t family,
279                                     struct mount_options *options)
280 {
281         struct sockaddr_storage dummy;
282         struct sockaddr *sap = (struct sockaddr *)&dummy;
283         socklen_t salen = sizeof(dummy);
284         char *mounthost;
285
286         mounthost = po_get(options, "mounthost");
287         if (!mounthost)
288                 return 1;
289
290         if (!nfs_name_to_address(mounthost, family, sap, &salen)) {
291                 nfs_error(_("%s: unable to determine mount server's address"),
292                                 progname);
293                 return 0;
294         }
295
296         return nfs_append_generic_address_option(sap, salen,
297                                                         "mountaddr", options);
298 }
299
300 /*
301  * Returns zero if the "lock" option is in effect, but statd
302  * can't be started.  Otherwise, returns 1.
303  */
304 static int verify_lock_option(struct mount_options *options)
305 {
306         if (po_rightmost(options, "nolock", "lock") == PO_KEY1_RIGHTMOST)
307                 return 1;
308
309         if (!start_statd()) {
310                 nfs_error(_("%s: rpc.statd is not running but is "
311                             "required for remote locking."), progname);
312                 nfs_error(_("%s: Either use '-o nolock' to keep "
313                             "locks local, or start statd."), progname);
314                 return 0;
315         }
316
317         return 1;
318 }
319
320 static int nfs_append_sloppy_option(struct mount_options *options)
321 {
322         if (!sloppy || linux_version_code() < MAKE_VERSION(2, 6, 27))
323                 return 1;
324
325         if (po_append(options, "sloppy") == PO_FAILED)
326                 return 0;
327         return 1;
328 }
329
330 /*
331  * Set up mandatory NFS mount options.
332  *
333  * Returns 1 if successful; otherwise zero.
334  */
335 static int nfs_validate_options(struct nfsmount_info *mi)
336 {
337         struct sockaddr_in saddr;
338
339         if (!fill_ipv4_sockaddr(mi->hostname, &saddr))
340                 return 0;
341
342         if (strncmp(mi->type, "nfs4", 4) == 0) {
343                 if (!nfs_append_clientaddr_option((struct sockaddr *)&saddr,
344                                                   sizeof(saddr), mi->options))
345                         return 0;
346         } else {
347                 if (!nfs_fix_mounthost_option(mi->family, mi->options))
348                         return 0;
349                 if (!mi->fake && !verify_lock_option(mi->options))
350                         return 0;
351         }
352
353         if (!nfs_append_sloppy_option(mi->options))
354                 return 0;
355
356         return nfs_append_addr_option((struct sockaddr *)&saddr,
357                                         sizeof(saddr), mi->options);
358 }
359
360 /*
361  * Distinguish between permanent and temporary errors.
362  *
363  * Returns 0 if the passed-in error is temporary, thus the
364  * mount system call should be retried; returns one if the
365  * passed-in error is permanent, thus the mount system call
366  * should not be retried.
367  */
368 static int is_permanent_error(int error)
369 {
370         switch (error) {
371         case ESTALE:
372         case ETIMEDOUT:
373         case ECONNREFUSED:
374                 return 0;       /* temporary */
375         default:
376                 return 1;       /* permanent */
377         }
378 }
379
380 /*
381  * Reconstruct the mount option string based on a portmapper probe
382  * of the server.  Returns one if the server's portmapper returned
383  * something we can use, otherwise zero.
384  *
385  * To handle version and transport protocol fallback properly, we
386  * need to parse some of the mount options in order to set up a
387  * portmap probe.  Mount options that rewrite_mount_options()
388  * doesn't recognize are left alone.
389  *
390  * Returns a new group of mount options if successful; otherwise
391  * NULL is returned if some failure occurred.
392  */
393 static struct mount_options *rewrite_mount_options(char *str)
394 {
395         struct mount_options *options;
396         char *option, new_option[64];
397         clnt_addr_t mnt_server = { };
398         clnt_addr_t nfs_server = { };
399         int p;
400
401         options = po_split(str);
402         if (!options) {
403                 errno = EFAULT;
404                 return NULL;
405         }
406
407         errno = EINVAL;
408         option = po_get(options, "addr");
409         if (option) {
410                 nfs_server.saddr.sin_family = AF_INET;
411                 if (!inet_aton((const char *)option, &nfs_server.saddr.sin_addr))
412                         goto err;
413         } else
414                 goto err;
415
416         option = po_get(options, "mountaddr");
417         if (option) {
418                 mnt_server.saddr.sin_family = AF_INET;
419                 if (!inet_aton((const char *)option, &mnt_server.saddr.sin_addr))
420                         goto err;
421         } else
422                 memcpy(&mnt_server.saddr, &nfs_server.saddr,
423                                 sizeof(mnt_server.saddr));
424
425         option = po_get(options, "mountport");
426         if (option)
427                 mnt_server.pmap.pm_port = atoi(option);
428         mnt_server.pmap.pm_prog = MOUNTPROG;
429         option = po_get(options, "mountvers");
430         if (option)
431                 mnt_server.pmap.pm_vers = atoi(option);
432
433         option = po_get(options, "port");
434         if (option) {
435                 nfs_server.pmap.pm_port = atoi(option);
436                 po_remove_all(options, "port");
437         }
438         nfs_server.pmap.pm_prog = NFS_PROGRAM;
439
440         option = po_get(options, "nfsvers");
441         if (option) {
442                 nfs_server.pmap.pm_vers = atoi(option);
443                 po_remove_all(options, "nfsvers");
444         }
445         option = po_get(options, "vers");
446         if (option) {
447                 nfs_server.pmap.pm_vers = atoi(option);
448                 po_remove_all(options, "vers");
449         }
450         option = po_get(options, "proto");
451         if (option) {
452                 if (strcmp(option, "tcp") == 0) {
453                         nfs_server.pmap.pm_prot = IPPROTO_TCP;
454                         po_remove_all(options, "proto");
455                 }
456                 if (strcmp(option, "udp") == 0) {
457                         nfs_server.pmap.pm_prot = IPPROTO_UDP;
458                         po_remove_all(options, "proto");
459                 }
460         }
461         p = po_rightmost(options, "tcp", "udp");
462         switch (p) {
463         case PO_KEY2_RIGHTMOST:
464                 nfs_server.pmap.pm_prot = IPPROTO_UDP;
465                 break;
466         case PO_KEY1_RIGHTMOST:
467                 nfs_server.pmap.pm_prot = IPPROTO_TCP;
468                 break;
469         }
470         po_remove_all(options, "tcp");
471         po_remove_all(options, "udp");
472
473         if (!probe_bothports(&mnt_server, &nfs_server)) {
474                 errno = ESPIPE;
475                 goto err;
476         }
477
478         snprintf(new_option, sizeof(new_option) - 1,
479                  "nfsvers=%lu", nfs_server.pmap.pm_vers);
480         if (po_append(options, new_option) == PO_FAILED)
481                 goto err;
482
483         if (nfs_server.pmap.pm_prot == IPPROTO_TCP)
484                 snprintf(new_option, sizeof(new_option) - 1,
485                          "proto=tcp");
486         else
487                 snprintf(new_option, sizeof(new_option) - 1,
488                          "proto=udp");
489         if (po_append(options, new_option) == PO_FAILED)
490                 goto err;
491
492         if (nfs_server.pmap.pm_port != NFS_PORT) {
493                 snprintf(new_option, sizeof(new_option) - 1,
494                          "port=%lu", nfs_server.pmap.pm_port);
495                 if (po_append(options, new_option) == PO_FAILED)
496                         goto err;
497
498         }
499
500         errno = 0;
501         return options;
502
503 err:
504         po_destroy(options);
505         return NULL;
506 }
507
508 /*
509  * Do the mount(2) system call.
510  *
511  * Returns 1 if successful, otherwise zero.
512  * "errno" is set to reflect the individual error.
513  */
514 static int nfs_sys_mount(const struct nfsmount_info *mi, const char *type,
515                          const char *options)
516 {
517         int result;
518
519         result = mount(mi->spec, mi->node, type,
520                                 mi->flags & ~(MS_USER|MS_USERS), options);
521         if (verbose && result) {
522                 int save = errno;
523                 nfs_error(_("%s: mount(2): %s"), progname, strerror(save));
524                 errno = save;
525         }
526         return !result;
527 }
528
529 /*
530  * Retry an NFS mount that failed because the requested service isn't
531  * available on the server.
532  *
533  * Returns 1 if successful.  Otherwise, returns zero.
534  * "errno" is set to reflect the individual error.
535  *
536  * Side effect: If the retry is successful, both 'options' and
537  * 'extra_opts' are updated to reflect the mount options that worked.
538  * If the retry fails, 'options' and 'extra_opts' are left unchanged.
539  */
540 static int nfs_retry_nfs23mount(struct nfsmount_info *mi)
541 {
542         struct mount_options *retry_options;
543         char *retry_str = NULL;
544         char **extra_opts = mi->extra_opts;
545
546         retry_options = rewrite_mount_options(*extra_opts);
547         if (!retry_options)
548                 return 0;
549
550         if (po_join(retry_options, &retry_str) == PO_FAILED) {
551                 po_destroy(retry_options);
552                 errno = EIO;
553                 return 0;
554         }
555
556         if (verbose)
557                 printf(_("%s: text-based options (retry): '%s'\n"),
558                         progname, retry_str);
559
560         if (!nfs_sys_mount(mi, "nfs", retry_str)) {
561                 po_destroy(retry_options);
562                 free(retry_str);
563                 return 0;
564         }
565
566         free(*extra_opts);
567         *extra_opts = retry_str;
568         po_replace(mi->options, retry_options);
569         return 1;
570 }
571
572 /*
573  * Attempt an NFSv2/3 mount via a mount(2) system call.  If the kernel
574  * claims the requested service isn't supported on the server, probe
575  * the server to see what's supported, rewrite the mount options,
576  * and retry the request.
577  *
578  * Returns 1 if successful.  Otherwise, returns zero.
579  * "errno" is set to reflect the individual error.
580  *
581  * Side effect: If the retry is successful, both 'options' and
582  * 'extra_opts' are updated to reflect the mount options that worked.
583  * If the retry fails, 'options' and 'extra_opts' are left unchanged.
584  */
585 static int nfs_try_nfs23mount(struct nfsmount_info *mi)
586 {
587         char **extra_opts = mi->extra_opts;
588
589         if (po_join(mi->options, extra_opts) == PO_FAILED) {
590                 errno = EIO;
591                 return 0;
592         }
593
594         if (verbose)
595                 printf(_("%s: text-based options: '%s'\n"),
596                         progname, *extra_opts);
597
598         if (mi->fake)
599                 return 1;
600
601         if (nfs_sys_mount(mi, "nfs", *extra_opts))
602                 return 1;
603
604         /*
605          * The kernel returns EOPNOTSUPP if the RPC bind failed,
606          * and EPROTONOSUPPORT if the version isn't supported.
607          */
608         if (errno != EOPNOTSUPP && errno != EPROTONOSUPPORT)
609                 return 0;
610
611         return nfs_retry_nfs23mount(mi);
612 }
613
614 /*
615  * Attempt an NFS v4 mount via a mount(2) system call.
616  *
617  * Returns 1 if successful.  Otherwise, returns zero.
618  * "errno" is set to reflect the individual error.
619  */
620 static int nfs_try_nfs4mount(struct nfsmount_info *mi)
621 {
622         char **extra_opts = mi->extra_opts;
623
624         if (po_join(mi->options, extra_opts) == PO_FAILED) {
625                 errno = EIO;
626                 return 0;
627         }
628
629         if (verbose)
630                 printf(_("%s: text-based options: '%s'\n"),
631                         progname, *extra_opts);
632
633         if (mi->fake)
634                 return 1;
635
636         return nfs_sys_mount(mi, "nfs4", *extra_opts);
637 }
638
639 /*
640  * Perform either an NFSv2/3 mount, or an NFSv4 mount system call.
641  *
642  * Returns 1 if successful.  Otherwise, returns zero.
643  * "errno" is set to reflect the individual error.
644  */
645 static int nfs_try_mount(struct nfsmount_info *mi)
646 {
647         if (strncmp(mi->type, "nfs4", 4) == 0)
648                 return nfs_try_nfs4mount(mi);
649         else
650                 return nfs_try_nfs23mount(mi);
651 }
652
653 /*
654  * Handle "foreground" NFS mounts.
655  *
656  * Retry the mount request for as long as the 'retry=' option says.
657  *
658  * Returns a valid mount command exit code.
659  */
660 static int nfsmount_fg(struct nfsmount_info *mi)
661 {
662         unsigned int secs = 1;
663         time_t timeout;
664
665         timeout = nfs_parse_retry_option(mi->options,
666                                          NFS_DEF_FG_TIMEOUT_MINUTES);
667         if (verbose)
668                 printf(_("%s: timeout set for %s"),
669                         progname, ctime(&timeout));
670
671         for (;;) {
672                 if (nfs_try_mount(mi))
673                         return EX_SUCCESS;
674
675                 if (is_permanent_error(errno))
676                         break;
677
678                 if (time(NULL) > timeout) {
679                         errno = ETIMEDOUT;
680                         break;
681                 }
682
683                 if (errno != ETIMEDOUT) {
684                         if (sleep(secs))
685                                 break;
686                         secs <<= 1;
687                         if (secs > 10)
688                                 secs = 10;
689                 }
690         };
691
692         mount_error(mi->spec, mi->node, errno);
693         return EX_FAIL;
694 }
695
696 /*
697  * Handle "background" NFS mount [first try]
698  *
699  * Returns a valid mount command exit code.
700  *
701  * EX_BG should cause the caller to fork and invoke nfsmount_child.
702  */
703 static int nfsmount_parent(struct nfsmount_info *mi)
704 {
705         if (nfs_try_mount(mi))
706                 return EX_SUCCESS;
707
708         if (is_permanent_error(errno)) {
709                 mount_error(mi->spec, mi->node, errno);
710                 return EX_FAIL;
711         }
712
713         sys_mount_errors(mi->hostname, errno, 1, 1);
714         return EX_BG;
715 }
716
717 /*
718  * Handle "background" NFS mount [retry daemon]
719  *
720  * Returns a valid mount command exit code: EX_SUCCESS if successful,
721  * EX_FAIL if a failure occurred.  There's nothing to catch the
722  * error return, though, so we use sys_mount_errors to log the
723  * failure.
724  */
725 static int nfsmount_child(struct nfsmount_info *mi)
726 {
727         unsigned int secs = 1;
728         time_t timeout;
729
730         timeout = nfs_parse_retry_option(mi->options,
731                                          NFS_DEF_BG_TIMEOUT_MINUTES);
732
733         for (;;) {
734                 if (sleep(secs))
735                         break;
736                 secs <<= 1;
737                 if (secs > 120)
738                         secs = 120;
739
740                 if (nfs_try_mount(mi))
741                         return EX_SUCCESS;
742
743                 if (is_permanent_error(errno))
744                         break;
745
746                 if (time(NULL) > timeout)
747                         break;
748
749                 sys_mount_errors(mi->hostname, errno, 1, 1);
750         };
751
752         sys_mount_errors(mi->hostname, errno, 1, 0);
753         return EX_FAIL;
754 }
755
756 /*
757  * Handle "background" NFS mount
758  *
759  * Returns a valid mount command exit code.
760  */
761 static int nfsmount_bg(struct nfsmount_info *mi)
762 {
763         if (!mi->child)
764                 return nfsmount_parent(mi);
765         else
766                 return nfsmount_child(mi);
767 }
768
769 /*
770  * Process mount options and try a mount system call.
771  *
772  * Returns a valid mount command exit code.
773  */
774 static int nfsmount_start(struct nfsmount_info *mi)
775 {
776         if (!nfs_validate_options(mi))
777                 return EX_FAIL;
778
779         if (po_rightmost(mi->options, "bg", "fg") == PO_KEY1_RIGHTMOST)
780                 return nfsmount_bg(mi);
781         else
782                 return nfsmount_fg(mi);
783 }
784
785 /**
786  * nfsmount_string - Mount an NFS file system using C string options
787  * @spec: C string specifying remote share to mount ("hostname:path")
788  * @node: C string pathname of local mounted-on directory
789  * @type: C string that represents file system type ("nfs" or "nfs4")
790  * @flags: MS_ style mount flags
791  * @extra_opts: pointer to C string containing fs-specific mount options
792  *              (input and output argument)
793  * @fake: flag indicating whether to carry out the whole operation
794  * @child: one if this is a mount daemon (bg)
795  */
796 int nfsmount_string(const char *spec, const char *node, const char *type,
797                     int flags, char **extra_opts, int fake, int child)
798 {
799         struct nfsmount_info mi = {
800                 .spec           = spec,
801                 .node           = node,
802                 .type           = type,
803                 .extra_opts     = extra_opts,
804                 .flags          = flags,
805                 .fake           = fake,
806                 .child          = child,
807 #ifdef IPV6_SUPPORTED
808                 .family         = AF_UNSPEC,    /* either IPv4 or v6 */
809 #else
810                 .family         = AF_INET,      /* only IPv4 */
811 #endif
812         };
813         int retval = EX_FAIL;
814
815         if (!nfs_parse_devname(&mi))
816                 return retval;
817
818         mi.options = po_split(*extra_opts);
819         if (mi.options) {
820                 retval = nfsmount_start(&mi);
821                 po_destroy(mi.options);
822         } else
823                 nfs_error(_("%s: internal option parsing error"), progname);
824
825         free(mi.hostname);
826         return retval;
827 }