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