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