]> git.decadent.org.uk Git - nfs-utils.git/blob - debian/patches/02-fix-retry-option.patch
Imported Debian patch 1.1.2-3
[nfs-utils.git] / debian / patches / 02-fix-retry-option.patch
1 text-based mount command: Fix retry= option
2
3 Steinar Gunderson reports:
4
5 "It seems retry= is now additive with the text-based mount interface. In
6 particular, "mount -o retry=0" still gives a two-minute timeout."
7
8 Make retry option parsing more robust, while we're at it.
9
10 Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
11 ---
12
13  utils/mount/stropts.c |   55 ++++++++++++++++++++++++++++++++++++++-----------
14  1 files changed, 43 insertions(+), 12 deletions(-)
15
16 diff --git a/utils/mount/stropts.c b/utils/mount/stropts.c
17 index cadb1f4..4df9ad9 100644
18 --- a/utils/mount/stropts.c
19 +++ b/utils/mount/stropts.c
20 @@ -65,6 +65,14 @@
21  #define NFS_MAXPATHNAME                (1024)
22  #endif
23  
24 +#ifndef NFS_DEF_FG_TIMEOUT_MINUTES
25 +#define NFS_DEF_FG_TIMEOUT_MINUTES     (2ul)
26 +#endif
27 +
28 +#ifndef NFS_DEF_BG_TIMEOUT_MINUTES
29 +#define NFS_DEF_BG_TIMEOUT_MINUTES     (10000ul)
30 +#endif
31 +
32  extern int nfs_mount_data_version;
33  extern char *progname;
34  extern int verbose;
35 @@ -141,6 +149,35 @@ static int fill_ipv4_sockaddr(const char *hostname, struct sockaddr_in *addr)
36  }
37  
38  /*
39 + * Set up a timeout value based on the value of the "retry=" option.
40 + *
41 + * Returns 1 if the option was parsed successfully, otherwise zero.
42 + * Returns the parsed timeout, or the default, in *timeout.
43 + */
44 +static int parse_retry_option(time_t *timeout, struct mount_options *options,
45 +                             unsigned long timeout_minutes)
46 +{
47 +       char *retry_option, *endptr;
48 +
49 +       retry_option = po_get(options, "retry");
50 +       if (retry_option) {
51 +               long tmp;
52 +
53 +               errno = 0;
54 +               tmp = strtol(retry_option, &endptr, 10);
55 +               if (errno || endptr == retry_option || tmp < 0) {
56 +                       nfs_error(_("%s: incorrect retry timeout specified"),
57 +                                       progname);
58 +                       return 0;
59 +               }
60 +               timeout_minutes = tmp;
61 +       }
62 +
63 +       *timeout = time(NULL) + (time_t)(timeout_minutes * 60);
64 +       return 1;
65 +}
66 +
67 +/*
68   * Append the 'addr=' option to the options string to pass a resolved
69   * server address to the kernel.  After a successful mount, this address
70   * is also added to /etc/mtab for use when unmounting.
71 @@ -535,13 +572,10 @@ static int nfsmount_fg(const char *spec, const char *node,
72                        char **extra_opts)
73  {
74         unsigned int secs = 1;
75 -       time_t timeout = time(NULL);
76 -       char *retry;
77 +       time_t timeout;
78  
79 -       timeout += 60 * 2;              /* default: 2 minutes */
80 -       retry = po_get(options, "retry");
81 -       if (retry)
82 -               timeout += 60 * atoi(retry);
83 +       if (!parse_retry_option(&timeout, options, NFS_DEF_FG_TIMEOUT_MINUTES))
84 +               return EX_FAIL;
85  
86         if (verbose)
87                 printf(_("%s: timeout set for %s"),
88 @@ -612,13 +646,10 @@ static int nfsmount_child(const char *spec, const char *node,
89                           int fake, char **extra_opts)
90  {
91         unsigned int secs = 1;
92 -       time_t timeout = time(NULL);
93 -       char *retry;
94 +       time_t timeout;
95  
96 -       timeout += 60 * 10000;          /* default: 10,000 minutes */
97 -       retry = po_get(options, "retry");
98 -       if (retry)
99 -               timeout += 60 * atoi(retry);
100 +       if (!parse_retry_option(&timeout, options, NFS_DEF_BG_TIMEOUT_MINUTES))
101 +               return EX_FAIL;
102  
103         for (;;) {
104                 if (sleep(secs))