public inbox for linux-nfs@vger.kernel.org
 help / color / mirror / Atom feed
From: Chuck Lever <chuck.lever@oracle.com>
To: steved@redhat.com
Cc: linux-nfs@vger.kernel.org
Subject: [PATCH 1/5] text-based mount command: make po_rightmost() work for N options
Date: Thu, 08 Jan 2009 12:32:42 -0500	[thread overview]
Message-ID: <20090108173241.19893.57156.stgit@ingres.1015granger.net> (raw)
In-Reply-To: <20090108172526.19893.91621.stgit-07a7zB5ZJzbwdl/1UfZZQIVfYA8g3rJ/@public.gmane.org>

Sometimes we need to choose the rightmost option among multiple
different mount options.  For example, we want to find the rightmost
of "proto," "tcp," and "udp".  Or, the rightmost of "vers," "nfsvers,"
"v2," and "v3".

Update po_rightmost() to choose among N options instead of just two.

Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
---

 utils/mount/parse_opt.c |   28 ++++++++++++++++------------
 utils/mount/parse_opt.h |    9 ++-------
 utils/mount/stropts.c   |   28 +++++++++++++++++++++++-----
 3 files changed, 41 insertions(+), 24 deletions(-)

diff --git a/utils/mount/parse_opt.c b/utils/mount/parse_opt.c
index f61d0dd..4934508 100644
--- a/utils/mount/parse_opt.c
+++ b/utils/mount/parse_opt.c
@@ -421,34 +421,38 @@ po_found_t po_get_numeric(struct mount_options *options, char *keyword, long *va
 #endif	/* HAVE_STRTOL */
 
 /**
- * po_rightmost - determine the relative position of two options
+ * po_rightmost - determine the relative position of several options
  * @options: pointer to mount options
- * @key1: pointer to a C string containing an option keyword
- * @key2: pointer to a C string containing another option keyword
+ * @keys: pointer to an array of C strings containing option keywords
+ *
+ * This function can be used to determine which of several similar
+ * options will be the one to take effect.
  *
  * The kernel parses the mount option string from left to right.
  * If an option is specified more than once (for example, "intr"
  * and "nointr", the rightmost option is the last to be parsed,
  * and it therefore takes precedence over previous similar options.
  *
- * This function can be used to determine which of two similar
- * options will be the one to take effect.
+ * This can also distinguish among multiple synonymous options, such
+ * as "proto=," "udp" and "tcp."
+ *
+ * Returns the index into @keys of the option that is rightmost.
+ * If none of the options are present, returns zero.
  */
-po_rightmost_t po_rightmost(struct mount_options *options,
-			    char *key1, char *key2)
+unsigned int po_rightmost(struct mount_options *options, const char *keys[])
 {
 	struct mount_option *option;
+	unsigned int i;
 
 	if (options) {
 		for (option = options->tail; option; option = option->prev) {
-			if (key2 && strcmp(option->keyword, key2) == 0)
-				return PO_KEY2_RIGHTMOST;
-			if (key1 && strcmp(option->keyword, key1) == 0)
-				return PO_KEY1_RIGHTMOST;
+			for (i = 0; keys[i] != NULL; i++)
+				if (strcmp(option->keyword, keys[i]) == 0)
+					return i;
 		}
 	}
 
-	return PO_NEITHER_FOUND;
+	return 0;
 }
 
 /**
diff --git a/utils/mount/parse_opt.h b/utils/mount/parse_opt.h
index 199630f..e132b1c 100644
--- a/utils/mount/parse_opt.h
+++ b/utils/mount/parse_opt.h
@@ -35,12 +35,6 @@ typedef enum {
 	PO_BAD_VALUE = 2,
 } po_found_t;
 
-typedef enum {
-	PO_KEY1_RIGHTMOST = -1,
-	PO_NEITHER_FOUND = 0,
-	PO_KEY2_RIGHTMOST = 1,
-} po_rightmost_t;
-
 struct mount_options;
 
 struct mount_options *	po_split(char *);
@@ -53,7 +47,8 @@ po_found_t		po_contains(struct mount_options *, char *);
 char *			po_get(struct mount_options *, char *);
 po_found_t		po_get_numeric(struct mount_options *,
 					char *, long *);
-po_rightmost_t		po_rightmost(struct mount_options *, char *, char *);
+unsigned int		po_rightmost(struct mount_options *,
+					const char *keys[]);
 po_found_t		po_remove_all(struct mount_options *, char *);
 void			po_destroy(struct mount_options *);
 
diff --git a/utils/mount/stropts.c b/utils/mount/stropts.c
index 43791e6..bd127ab 100644
--- a/utils/mount/stropts.c
+++ b/utils/mount/stropts.c
@@ -224,9 +224,15 @@ static int nfs_fix_mounthost_option(const sa_family_t family,
  * Returns zero if the "lock" option is in effect, but statd
  * can't be started.  Otherwise, returns 1.
  */
+static const char *nfs_lock_opttbl[] = {
+	"nolock",
+	"lock",
+	NULL,
+};
+
 static int nfs_verify_lock_option(struct mount_options *options)
 {
-	if (po_rightmost(options, "nolock", "lock") == PO_KEY1_RIGHTMOST)
+	if (po_rightmost(options, nfs_lock_opttbl) == 1)
 		return 1;
 
 	if (!start_statd()) {
@@ -316,6 +322,12 @@ static int nfs_is_permanent_error(int error)
  * Returns a new group of mount options if successful; otherwise
  * NULL is returned if some failure occurred.
  */
+static const char *nfs_transport_opttbl[] = {
+	"udp",
+	"tcp",
+	NULL,
+};
+
 static struct mount_options *nfs_rewrite_mount_options(char *str)
 {
 	struct mount_options *options;
@@ -395,12 +407,12 @@ static struct mount_options *nfs_rewrite_mount_options(char *str)
 			po_remove_all(options, "proto");
 		}
 	}
-	p = po_rightmost(options, "tcp", "udp");
+	p = po_rightmost(options, nfs_transport_opttbl);
 	switch (p) {
-	case PO_KEY2_RIGHTMOST:
+	case 1:
 		nfs_server.pmap.pm_prot = IPPROTO_UDP;
 		break;
-	case PO_KEY1_RIGHTMOST:
+	case 2:
 		nfs_server.pmap.pm_prot = IPPROTO_TCP;
 		break;
 	}
@@ -722,12 +734,18 @@ static int nfsmount_bg(struct nfsmount_info *mi)
  *
  * Returns a valid mount command exit code.
  */
+static const char *nfs_background_opttbl[] = {
+	"bg",
+	"fg",
+	NULL,
+};
+
 static int nfsmount_start(struct nfsmount_info *mi)
 {
 	if (!nfs_validate_options(mi))
 		return EX_FAIL;
 
-	if (po_rightmost(mi->options, "bg", "fg") == PO_KEY1_RIGHTMOST)
+	if (po_rightmost(mi->options, nfs_background_opttbl) == 1)
 		return nfsmount_bg(mi);
 	else
 		return nfsmount_fg(mi);


  parent reply	other threads:[~2009-01-08 17:33 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-01-08 17:32 [PATCH 0/5] struct pmap stuffing Chuck Lever
     [not found] ` <20090108172526.19893.91621.stgit-07a7zB5ZJzbwdl/1UfZZQIVfYA8g3rJ/@public.gmane.org>
2009-01-08 17:32   ` Chuck Lever [this message]
2009-01-08 17:32   ` [PATCH 2/5] text-based mount command: Function to stuff "struct pmap" from mount options Chuck Lever
2009-01-08 17:32   ` [PATCH 3/5] text-based mount options: Use new pmap stuffer when rewriting " Chuck Lever
2009-01-08 17:32   ` [PATCH 4/5] text-based mount command: fix mount option rewriting logic Chuck Lever
2009-01-08 17:33   ` [PATCH 5/5] text-based mount command: support AF_INET6 in rewrite_mount_options() Chuck Lever
2009-01-27 23:02   ` [PATCH 0/5] struct pmap stuffing Steve Dickson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20090108173241.19893.57156.stgit@ingres.1015granger.net \
    --to=chuck.lever@oracle.com \
    --cc=linux-nfs@vger.kernel.org \
    --cc=steved@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox