walters / rpms / nfs-utils

Forked from rpms/nfs-utils 6 years ago
Clone
70f8963
commit b5009d23525181846777349f2fc0e4a72b89d24d
70f8963
Author: Chuck Lever <chuck.lever@oracle.com>
70f8963
Date:   Wed Dec 17 14:21:10 2008 -0500
70f8963
70f8963
    text-based mount command: add function to parse numeric	mount options
70f8963
    
70f8963
    Introduce a function that is especially for parsing keyword mount options
70f8963
    that take a numeric value.
70f8963
    
70f8963
    Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
70f8963
    Signed-off-by: Steve Dickson <steved@redhat.com>
70f8963
70f8963
diff --git a/utils/mount/parse_opt.c b/utils/mount/parse_opt.c
70f8963
index cb398bd..f61d0dd 100644
70f8963
--- a/utils/mount/parse_opt.c
70f8963
+++ b/utils/mount/parse_opt.c
70f8963
@@ -36,6 +36,10 @@
70f8963
  */
70f8963
 
70f8963
 
70f8963
+#ifdef HAVE_CONFIG_H
70f8963
+#include <config.h>
70f8963
+#endif
70f8963
+
70f8963
 #include <ctype.h>
70f8963
 #include <unistd.h>
70f8963
 #include <stdio.h>
70f8963
@@ -366,6 +370,57 @@ char *po_get(struct mount_options *options, char *keyword)
70f8963
 }
70f8963
 
70f8963
 /**
70f8963
+ * po_get_numeric - return numeric value of rightmost instance of keyword option
70f8963
+ * @options: pointer to mount options
70f8963
+ * @keyword: pointer to a C string containing option keyword for which to search
70f8963
+ * @value: OUT: set to the value of the keyword
70f8963
+ *
70f8963
+ * This is specifically for parsing keyword options that take only a numeric
70f8963
+ * value.  If multiple instances of the same option are present in a mount
70f8963
+ * option list, the rightmost instance is always the effective one.
70f8963
+ *
70f8963
+ * Returns:
70f8963
+ *	* PO_FOUND if the keyword was found and the value is numeric; @value is
70f8963
+ *	  set to the keyword's value
70f8963
+ *	* PO_NOT_FOUND if the keyword was not found
70f8963
+ *	* PO_BAD_VALUE if the keyword was found, but the value is not numeric
70f8963
+ *
70f8963
+ * These last two are separate in case the caller wants to warn about bad mount
70f8963
+ * options instead of silently using a default.
70f8963
+ */
70f8963
+#ifdef HAVE_STRTOL
70f8963
+po_found_t po_get_numeric(struct mount_options *options, char *keyword, long *value)
70f8963
+{
70f8963
+	char *option, *endptr;
70f8963
+	long tmp;
70f8963
+
70f8963
+	option = po_get(options, keyword);
70f8963
+	if (option == NULL)
70f8963
+		return PO_NOT_FOUND;
70f8963
+
70f8963
+	errno = 0;
70f8963
+	tmp = strtol(option, &endptr, 10);
70f8963
+	if (errno == 0 && endptr != option) {
70f8963
+		*value = tmp;
70f8963
+		return PO_FOUND;
70f8963
+	}
70f8963
+	return PO_BAD_VALUE;
70f8963
+}
70f8963
+#else	/* HAVE_STRTOL */
70f8963
+po_found_t po_get_numeric(struct mount_options *options, char *keyword, long *value)
70f8963
+{
70f8963
+	char *option;
70f8963
+
70f8963
+	option = po_get(options, keyword);
70f8963
+	if (option == NULL)
70f8963
+		return PO_NOT_FOUND;
70f8963
+
70f8963
+	*value = atoi(option);
70f8963
+	return PO_FOUND;
70f8963
+}
70f8963
+#endif	/* HAVE_STRTOL */
70f8963
+
70f8963
+/**
70f8963
  * po_rightmost - determine the relative position of two options
70f8963
  * @options: pointer to mount options
70f8963
  * @key1: pointer to a C string containing an option keyword
70f8963
diff --git a/utils/mount/parse_opt.h b/utils/mount/parse_opt.h
70f8963
index fb003c3..199630f 100644
70f8963
--- a/utils/mount/parse_opt.h
70f8963
+++ b/utils/mount/parse_opt.h
70f8963
@@ -32,6 +32,7 @@ typedef enum {
70f8963
 typedef enum {
70f8963
 	PO_NOT_FOUND = 0,
70f8963
 	PO_FOUND = 1,
70f8963
+	PO_BAD_VALUE = 2,
70f8963
 } po_found_t;
70f8963
 
70f8963
 typedef enum {
70f8963
@@ -50,6 +51,8 @@ po_return_t		po_join(struct mount_options *, char **);
70f8963
 po_return_t		po_append(struct mount_options *, char *);
70f8963
 po_found_t		po_contains(struct mount_options *, char *);
70f8963
 char *			po_get(struct mount_options *, char *);
70f8963
+po_found_t		po_get_numeric(struct mount_options *,
70f8963
+					char *, long *);
70f8963
 po_rightmost_t		po_rightmost(struct mount_options *, char *, char *);
70f8963
 po_found_t		po_remove_all(struct mount_options *, char *);
70f8963
 void			po_destroy(struct mount_options *);
70f8963
commit 3f23f712477df48fd1d57376b65c44bb2a19ec16
70f8963
Author: Chuck Lever <chuck.lever@oracle.com>
70f8963
Date:   Wed Dec 17 14:23:43 2008 -0500
70f8963
70f8963
    text-based mount command: use po_get_numeric() for	handling retry
70f8963
    
70f8963
    Replace the logic in nfs_parse_retry_option() with a call to the new
70f8963
    po_get_numeric() function.
70f8963
    
70f8963
    Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
70f8963
    Signed-off-by: Steve Dickson <steved@redhat.com>
70f8963
70f8963
diff --git a/utils/mount/stropts.c b/utils/mount/stropts.c
70f8963
index 09fca86..43791e6 100644
70f8963
--- a/utils/mount/stropts.c
70f8963
+++ b/utils/mount/stropts.c
70f8963
@@ -99,19 +99,21 @@ struct nfsmount_info {
70f8963
 static time_t nfs_parse_retry_option(struct mount_options *options,
70f8963
 				     unsigned int timeout_minutes)
70f8963
 {
70f8963
-	char *retry_option, *endptr;
70f8963
+	long tmp;
70f8963
 
70f8963
-	retry_option = po_get(options, "retry");
70f8963
-	if (retry_option) {
70f8963
-		long tmp;
70f8963
-
70f8963
-		errno = 0;
70f8963
-		tmp = strtol(retry_option, &endptr, 10);
70f8963
-		if (errno == 0 && endptr != retry_option && tmp >= 0)
70f8963
+	switch (po_get_numeric(options, "retry", &tmp)) {
70f8963
+	case PO_NOT_FOUND:
70f8963
+		break;
70f8963
+	case PO_FOUND:
70f8963
+		if (tmp >= 0) {
70f8963
 			timeout_minutes = tmp;
70f8963
-		else if (verbose)
70f8963
+			break;
70f8963
+		}
70f8963
+	case PO_BAD_VALUE:
70f8963
+		if (verbose)
70f8963
 			nfs_error(_("%s: invalid retry timeout was specified; "
70f8963
 					"using default timeout"), progname);
70f8963
+		break;
70f8963
 	}
70f8963
 
70f8963
 	return time(NULL) + (time_t)(timeout_minutes * 60);