]> git.decadent.org.uk Git - nfs-utils.git/blob - utils/mount/stropts.c
mount.nfs: rearchitect mount version/protocol negotiation logic
[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  * Distinguish between permanent and temporary errors.
291  *
292  * Returns 0 if the passed-in error is temporary, thus the
293  * mount system call should be retried; returns one if the
294  * passed-in error is permanent, thus the mount system call
295  * should not be retried.
296  */
297 static int nfs_is_permanent_error(int error)
298 {
299         switch (error) {
300         case ESTALE:
301         case ETIMEDOUT:
302         case ECONNREFUSED:
303                 return 0;       /* temporary */
304         default:
305                 return 1;       /* permanent */
306         }
307 }
308
309 /*
310  * Get NFS/mnt server addresses from mount options
311  *
312  * Returns 1 and fills in @nfs_saddr, @nfs_salen, @mnt_saddr, and @mnt_salen
313  * if all goes well; otherwise zero.
314  */
315 static int nfs_extract_server_addresses(struct mount_options *options,
316                                         struct sockaddr *nfs_saddr,
317                                         socklen_t *nfs_salen,
318                                         struct sockaddr *mnt_saddr,
319                                         socklen_t *mnt_salen)
320 {
321         char *option;
322
323         option = po_get(options, "addr");
324         if (option == NULL)
325                 return 0;
326         if (!nfs_string_to_sockaddr(option, strlen(option),
327                                                 nfs_saddr, nfs_salen))
328                 return 0;
329
330         option = po_get(options, "mountaddr");
331         if (option == NULL) {
332                 memcpy(mnt_saddr, nfs_saddr, *nfs_salen);
333                 *mnt_salen = *nfs_salen;
334         } else if (!nfs_string_to_sockaddr(option, strlen(option),
335                                                 mnt_saddr, mnt_salen))
336                 return 0;
337
338         return 1;
339 }
340
341 static int nfs_construct_new_options(struct mount_options *options,
342                                      struct pmap *nfs_pmap,
343                                      struct pmap *mnt_pmap)
344 {
345         char new_option[64];
346
347         po_remove_all(options, "nfsprog");
348         po_remove_all(options, "mountprog");
349
350         po_remove_all(options, "v2");
351         po_remove_all(options, "v3");
352         po_remove_all(options, "vers");
353         po_remove_all(options, "nfsvers");
354         snprintf(new_option, sizeof(new_option) - 1,
355                  "vers=%lu", nfs_pmap->pm_vers);
356         if (po_append(options, new_option) == PO_FAILED)
357                 return 0;
358
359         po_remove_all(options, "proto");
360         po_remove_all(options, "udp");
361         po_remove_all(options, "tcp");
362         switch (nfs_pmap->pm_prot) {
363         case IPPROTO_TCP:
364                 snprintf(new_option, sizeof(new_option) - 1,
365                          "proto=tcp");
366                 if (po_append(options, new_option) == PO_FAILED)
367                         return 0;
368                 break;
369         case IPPROTO_UDP:
370                 snprintf(new_option, sizeof(new_option) - 1,
371                          "proto=udp");
372                 if (po_append(options, new_option) == PO_FAILED)
373                         return 0;
374                 break;
375         }
376
377         po_remove_all(options, "port");
378         if (nfs_pmap->pm_port != NFS_PORT) {
379                 snprintf(new_option, sizeof(new_option) - 1,
380                          "port=%lu", nfs_pmap->pm_port);
381                 if (po_append(options, new_option) == PO_FAILED)
382                         return 0;
383         }
384
385         po_remove_all(options, "mountvers");
386         snprintf(new_option, sizeof(new_option) - 1,
387                  "mountvers=%lu", mnt_pmap->pm_vers);
388         if (po_append(options, new_option) == PO_FAILED)
389                 return 0;
390
391         po_remove_all(options, "mountproto");
392         switch (mnt_pmap->pm_prot) {
393         case IPPROTO_TCP:
394                 snprintf(new_option, sizeof(new_option) - 1,
395                          "mountproto=tcp");
396                 if (po_append(options, new_option) == PO_FAILED)
397                         return 0;
398                 break;
399         case IPPROTO_UDP:
400                 snprintf(new_option, sizeof(new_option) - 1,
401                          "mountproto=udp");
402                 if (po_append(options, new_option) == PO_FAILED)
403                         return 0;
404                 break;
405         }
406
407         po_remove_all(options, "mountport");
408         snprintf(new_option, sizeof(new_option) - 1,
409                  "mountport=%lu", mnt_pmap->pm_port);
410         if (po_append(options, new_option) == PO_FAILED)
411                 return 0;
412
413         return 1;
414 }
415
416 /*
417  * Reconstruct the mount option string based on a portmapper probe
418  * of the server.  Returns one if the server's portmapper returned
419  * something we can use, otherwise zero.
420  *
421  * To handle version and transport protocol fallback properly, we
422  * need to parse some of the mount options in order to set up a
423  * portmap probe.  Mount options that nfs_rewrite_mount_options()
424  * doesn't recognize are left alone.
425  *
426  * Returns a new group of mount options if successful; otherwise
427  * NULL is returned if some failure occurred.
428  */
429 static struct mount_options *nfs_rewrite_mount_options(char *str)
430 {
431         struct mount_options *options;
432         struct sockaddr_storage nfs_address;
433         struct sockaddr *nfs_saddr = (struct sockaddr *)&nfs_address;
434         socklen_t nfs_salen;
435         struct pmap nfs_pmap;
436         struct sockaddr_storage mnt_address;
437         struct sockaddr *mnt_saddr = (struct sockaddr *)&mnt_address;
438         socklen_t mnt_salen;
439         struct pmap mnt_pmap;
440         char *option;
441
442         options = po_split(str);
443         if (!options) {
444                 errno = EFAULT;
445                 return NULL;
446         }
447
448         /*
449          * Skip option negotiation for proto=rdma mounts.
450          */
451         option = po_get(options, "proto");
452         if (option && strcmp(option, "rdma") == 0)
453                 goto out;
454
455         /*
456          * Extract just the options needed to contact server.
457          * Bail now if any of these have bad values.
458          */
459         if (!nfs_extract_server_addresses(options, nfs_saddr, &nfs_salen,
460                                                 mnt_saddr, &mnt_salen)) {
461                 errno = EINVAL;
462                 goto err;
463         }
464         if (!nfs_options2pmap(options, &nfs_pmap, &mnt_pmap)) {
465                 errno = EINVAL;
466                 goto err;
467         }
468
469         /*
470          * The kernel NFS client doesn't support changing the RPC
471          * program number for these services, so force the value of
472          * these fields before probing the server's ports.
473          */
474         nfs_pmap.pm_prog = NFS_PROGRAM;
475         mnt_pmap.pm_prog = MOUNTPROG;
476
477         /*
478          * If the server's rpcbind service isn't available, we can't
479          * negotiate.  Bail now if we can't contact it.
480          */
481         if (!nfs_probe_bothports(mnt_saddr, mnt_salen, &mnt_pmap,
482                                  nfs_saddr, nfs_salen, &nfs_pmap)) {
483                 errno = ESPIPE;
484                 goto err;
485         }
486
487         if (!nfs_construct_new_options(options, &nfs_pmap, &mnt_pmap)) {
488                 errno = EINVAL;
489                 goto err;
490         }
491
492 out:
493         errno = 0;
494         return options;
495
496 err:
497         po_destroy(options);
498         return NULL;
499 }
500
501 /*
502  * Do the mount(2) system call.
503  *
504  * Returns 1 if successful, otherwise zero.
505  * "errno" is set to reflect the individual error.
506  */
507 static int nfs_sys_mount(const struct nfsmount_info *mi, const char *type,
508                          const char *options)
509 {
510         int result;
511
512         result = mount(mi->spec, mi->node, type,
513                                 mi->flags & ~(MS_USER|MS_USERS), options);
514         if (verbose && result) {
515                 int save = errno;
516                 nfs_error(_("%s: mount(2): %s"), progname, strerror(save));
517                 errno = save;
518         }
519         return !result;
520 }
521
522 /*
523  * Retry an NFS mount that failed because the requested service isn't
524  * available on the server.
525  *
526  * Returns 1 if successful.  Otherwise, returns zero.
527  * "errno" is set to reflect the individual error.
528  *
529  * Side effect: If the retry is successful, both 'options' and
530  * 'extra_opts' are updated to reflect the mount options that worked.
531  * If the retry fails, 'options' and 'extra_opts' are left unchanged.
532  */
533 static int nfs_retry_nfs23mount(struct nfsmount_info *mi)
534 {
535         struct mount_options *retry_options;
536         char *retry_str = NULL;
537         char **extra_opts = mi->extra_opts;
538
539         retry_options = nfs_rewrite_mount_options(*extra_opts);
540         if (!retry_options)
541                 return 0;
542
543         if (po_join(retry_options, &retry_str) == PO_FAILED) {
544                 po_destroy(retry_options);
545                 errno = EIO;
546                 return 0;
547         }
548
549         if (verbose)
550                 printf(_("%s: text-based options (retry): '%s'\n"),
551                         progname, retry_str);
552
553         if (mi->fake)
554                 return 1;
555
556         if (!nfs_sys_mount(mi, "nfs", retry_str)) {
557                 po_destroy(retry_options);
558                 free(retry_str);
559                 return 0;
560         }
561
562         free(*extra_opts);
563         *extra_opts = retry_str;
564         po_replace(mi->options, retry_options);
565         return 1;
566 }
567
568 /*
569  * Attempt an NFSv2/3 mount via a mount(2) system call.  If the kernel
570  * claims the requested service isn't supported on the server, probe
571  * the server to see what's supported, rewrite the mount options,
572  * and retry the request.
573  *
574  * Returns 1 if successful.  Otherwise, returns zero.
575  * "errno" is set to reflect the individual error.
576  *
577  * Side effect: If the retry is successful, both 'options' and
578  * 'extra_opts' are updated to reflect the mount options that worked.
579  * If the retry fails, 'options' and 'extra_opts' are left unchanged.
580  */
581 static int nfs_try_nfs23mount(struct nfsmount_info *mi)
582 {
583         char **extra_opts = mi->extra_opts;
584
585         if (po_join(mi->options, extra_opts) == PO_FAILED) {
586                 errno = EIO;
587                 return 0;
588         }
589
590         if (verbose)
591                 printf(_("%s: text-based options: '%s'\n"),
592                         progname, *extra_opts);
593
594         return nfs_retry_nfs23mount(mi);
595 }
596
597 /*
598  * Attempt an NFS v4 mount via a mount(2) system call.
599  *
600  * Returns 1 if successful.  Otherwise, returns zero.
601  * "errno" is set to reflect the individual error.
602  */
603 static int nfs_try_nfs4mount(struct nfsmount_info *mi)
604 {
605         char **extra_opts = mi->extra_opts;
606
607         if (po_join(mi->options, extra_opts) == PO_FAILED) {
608                 errno = EIO;
609                 return 0;
610         }
611
612         if (verbose)
613                 printf(_("%s: text-based options: '%s'\n"),
614                         progname, *extra_opts);
615
616         if (mi->fake)
617                 return 1;
618
619         return nfs_sys_mount(mi, "nfs4", *extra_opts);
620 }
621
622 /*
623  * Perform either an NFSv2/3 mount, or an NFSv4 mount system call.
624  *
625  * Returns 1 if successful.  Otherwise, returns zero.
626  * "errno" is set to reflect the individual error.
627  */
628 static int nfs_try_mount(struct nfsmount_info *mi)
629 {
630         if (strncmp(mi->type, "nfs4", 4) == 0)
631                 return nfs_try_nfs4mount(mi);
632         else
633                 return nfs_try_nfs23mount(mi);
634 }
635
636 /*
637  * Handle "foreground" NFS mounts.
638  *
639  * Retry the mount request for as long as the 'retry=' option says.
640  *
641  * Returns a valid mount command exit code.
642  */
643 static int nfsmount_fg(struct nfsmount_info *mi)
644 {
645         unsigned int secs = 1;
646         time_t timeout;
647
648         timeout = nfs_parse_retry_option(mi->options,
649                                          NFS_DEF_FG_TIMEOUT_MINUTES);
650         if (verbose)
651                 printf(_("%s: timeout set for %s"),
652                         progname, ctime(&timeout));
653
654         for (;;) {
655                 if (nfs_try_mount(mi))
656                         return EX_SUCCESS;
657
658                 if (nfs_is_permanent_error(errno))
659                         break;
660
661                 if (time(NULL) > timeout) {
662                         errno = ETIMEDOUT;
663                         break;
664                 }
665
666                 if (errno != ETIMEDOUT) {
667                         if (sleep(secs))
668                                 break;
669                         secs <<= 1;
670                         if (secs > 10)
671                                 secs = 10;
672                 }
673         };
674
675         mount_error(mi->spec, mi->node, errno);
676         return EX_FAIL;
677 }
678
679 /*
680  * Handle "background" NFS mount [first try]
681  *
682  * Returns a valid mount command exit code.
683  *
684  * EX_BG should cause the caller to fork and invoke nfsmount_child.
685  */
686 static int nfsmount_parent(struct nfsmount_info *mi)
687 {
688         if (nfs_try_mount(mi))
689                 return EX_SUCCESS;
690
691         if (nfs_is_permanent_error(errno)) {
692                 mount_error(mi->spec, mi->node, errno);
693                 return EX_FAIL;
694         }
695
696         sys_mount_errors(mi->hostname, errno, 1, 1);
697         return EX_BG;
698 }
699
700 /*
701  * Handle "background" NFS mount [retry daemon]
702  *
703  * Returns a valid mount command exit code: EX_SUCCESS if successful,
704  * EX_FAIL if a failure occurred.  There's nothing to catch the
705  * error return, though, so we use sys_mount_errors to log the
706  * failure.
707  */
708 static int nfsmount_child(struct nfsmount_info *mi)
709 {
710         unsigned int secs = 1;
711         time_t timeout;
712
713         timeout = nfs_parse_retry_option(mi->options,
714                                          NFS_DEF_BG_TIMEOUT_MINUTES);
715
716         for (;;) {
717                 if (sleep(secs))
718                         break;
719                 secs <<= 1;
720                 if (secs > 120)
721                         secs = 120;
722
723                 if (nfs_try_mount(mi))
724                         return EX_SUCCESS;
725
726                 if (nfs_is_permanent_error(errno))
727                         break;
728
729                 if (time(NULL) > timeout)
730                         break;
731
732                 sys_mount_errors(mi->hostname, errno, 1, 1);
733         };
734
735         sys_mount_errors(mi->hostname, errno, 1, 0);
736         return EX_FAIL;
737 }
738
739 /*
740  * Handle "background" NFS mount
741  *
742  * Returns a valid mount command exit code.
743  */
744 static int nfsmount_bg(struct nfsmount_info *mi)
745 {
746         if (!mi->child)
747                 return nfsmount_parent(mi);
748         else
749                 return nfsmount_child(mi);
750 }
751
752 /*
753  * Process mount options and try a mount system call.
754  *
755  * Returns a valid mount command exit code.
756  */
757 static const char *nfs_background_opttbl[] = {
758         "bg",
759         "fg",
760         NULL,
761 };
762
763 static int nfsmount_start(struct nfsmount_info *mi)
764 {
765         if (!nfs_validate_options(mi))
766                 return EX_FAIL;
767
768         if (po_rightmost(mi->options, nfs_background_opttbl) == 0)
769                 return nfsmount_bg(mi);
770         else
771                 return nfsmount_fg(mi);
772 }
773
774 /**
775  * nfsmount_string - Mount an NFS file system using C string options
776  * @spec: C string specifying remote share to mount ("hostname:path")
777  * @node: C string pathname of local mounted-on directory
778  * @type: C string that represents file system type ("nfs" or "nfs4")
779  * @flags: MS_ style mount flags
780  * @extra_opts: pointer to C string containing fs-specific mount options
781  *              (input and output argument)
782  * @fake: flag indicating whether to carry out the whole operation
783  * @child: one if this is a mount daemon (bg)
784  */
785 int nfsmount_string(const char *spec, const char *node, const char *type,
786                     int flags, char **extra_opts, int fake, int child)
787 {
788         struct nfsmount_info mi = {
789                 .spec           = spec,
790                 .node           = node,
791                 .type           = type,
792                 .extra_opts     = extra_opts,
793                 .flags          = flags,
794                 .fake           = fake,
795                 .child          = child,
796         };
797         int retval = EX_FAIL;
798
799         mi.options = po_split(*extra_opts);
800         if (mi.options) {
801                 retval = nfsmount_start(&mi);
802                 po_destroy(mi.options);
803         } else
804                 nfs_error(_("%s: internal option parsing error"), progname);
805
806         free(mi.hostname);
807         return retval;
808 }