summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
29ac873)
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: Steve Dickson <steved@redhat.com>
#endif /* HAVE_STRTOL */
/**
#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
* @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.
*
*
* 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;
{
struct mount_option *option;
if (options) {
for (option = options->tail; option; option = option->prev) {
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;
PO_BAD_VALUE = 2,
} po_found_t;
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 *);
struct mount_options;
struct mount_options * po_split(char *);
char * po_get(struct mount_options *, char *);
po_found_t po_get_numeric(struct mount_options *,
char *, long *);
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 *);
po_found_t po_remove_all(struct mount_options *, char *);
void po_destroy(struct mount_options *);
* Returns zero if the "lock" option is in effect, but statd
* can't be started. Otherwise, returns 1.
*/
* 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)
{
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()) {
return 1;
if (!start_statd()) {
* Returns a new group of mount options if successful; otherwise
* NULL is returned if some failure occurred.
*/
* 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;
static struct mount_options *nfs_rewrite_mount_options(char *str)
{
struct mount_options *options;
po_remove_all(options, "proto");
}
}
po_remove_all(options, "proto");
}
}
- p = po_rightmost(options, "tcp", "udp");
+ p = po_rightmost(options, nfs_transport_opttbl);
- case PO_KEY2_RIGHTMOST:
nfs_server.pmap.pm_prot = IPPROTO_UDP;
break;
nfs_server.pmap.pm_prot = IPPROTO_UDP;
break;
- case PO_KEY1_RIGHTMOST:
nfs_server.pmap.pm_prot = IPPROTO_TCP;
break;
}
nfs_server.pmap.pm_prot = IPPROTO_TCP;
break;
}
*
* Returns a valid mount command exit code.
*/
*
* 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;
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);
return nfsmount_bg(mi);
else
return nfsmount_fg(mi);