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