---
test log:
'''
[root@rhel-83 nfs-utils]# mount.nfs -s -onoquota,vers=4.1,nosuid,nodev,noexec 192.168.122.1:/ /mnt/nfsmp -v
mount.nfs: timeout set for Thu Jun 10 05:32:15 2021
mount.nfs: trying text-based options 'noquota,vers=4.1,sloppy,addr=192.168.122.1,clientaddr=192.168.122.90'
^^^^^^ append
mount.nfs: mount(2): Invalid argument
mount.nfs: an incorrect mount option was specified
[root@rhel-83 nfs-utils]# ./utils/mount/mount.nfs -s -onoquota,vers=4.1,nosuid,nodev,noexec 192.168.122.1:/ /mnt/nfsmp -v
mount.nfs: timeout set for Thu Jun 10 05:32:27 2021
mount.nfs: trying text-based options 'sloppy,vers=4.1,addr=192.168.122.1,clientaddr=192.168.122.90'
^^^^^^ insert head
192.168.122.1:/ on /mnt/nfsmp type nfs (noquota,vers=4.1,nosuid,nodev,noexec)
'''
utils/mount/parse_opt.c | 33 +++++++++++++++++++++++++++++++++
utils/mount/parse_opt.h | 1 +
utils/mount/stropts.c | 6 +++---
3 files changed, 37 insertions(+), 3 deletions(-)
diff --git a/utils/mount/parse_opt.c b/utils/mount/parse_opt.c
index b6065cad..d2d0b651 100644
--- a/utils/mount/parse_opt.c
+++ b/utils/mount/parse_opt.c
@@ -178,6 +178,22 @@ static void options_tail_insert(struct mount_options *options,
options->count++;
}
+static void options_head_insert(struct mount_options *options,
+ struct mount_option *option)
+{
+ struct mount_option *ohead = options->head;
+
+ option->prev = NULL;
+ option->next = ohead;
+ if (ohead)
+ ohead->prev = option;
+ else
+ options->tail = option;
+ options->head = option;
+
+ options->count++;
+}
+
static void options_delete(struct mount_options *options,
struct mount_option *option)
{
@@ -373,6 +389,23 @@ po_return_t po_join(struct mount_options *options, char **str)
return PO_SUCCEEDED;
}
+/**
+ * po_insert - insert an option into a group of options
+ * @options: pointer to mount options
+ * @option: pointer to a C string containing the option to add
+ *
+ */
+po_return_t po_insert(struct mount_options *options, char *str)
+{
+ struct mount_option *option = option_create(str);
+
+ if (option) {
+ options_head_insert(options, option);
+ return PO_SUCCEEDED;
+ }
+ return PO_FAILED;
+}
+
/**
* po_append - concatenate an option onto a group of options
* @options: pointer to mount options
diff --git a/utils/mount/parse_opt.h b/utils/mount/parse_opt.h
index 0a153768..181e7bf1 100644
--- a/utils/mount/parse_opt.h
+++ b/utils/mount/parse_opt.h
@@ -43,6 +43,7 @@ void po_replace(struct mount_options *,
struct mount_options *);
po_return_t po_join(struct mount_options *, char **);
+po_return_t po_insert(struct mount_options *, char *);
po_return_t po_append(struct mount_options *, char *);
po_found_t po_contains(struct mount_options *, char *);
po_found_t po_contains_prefix(struct mount_options *options,
diff --git a/utils/mount/stropts.c b/utils/mount/stropts.c
index 174a05f6..82b054a5 100644
--- a/utils/mount/stropts.c
+++ b/utils/mount/stropts.c
@@ -337,12 +337,12 @@ static int nfs_verify_lock_option(struct mount_options *options)
return 1;
}
-static int nfs_append_sloppy_option(struct mount_options *options)
+static int nfs_insert_sloppy_option(struct mount_options *options)
{
if (!sloppy || linux_version_code() < MAKE_VERSION(2, 6, 27))
return 1;
- if (po_append(options, "sloppy") == PO_FAILED)
+ if (po_insert(options, "sloppy") == PO_FAILED)
return 0;
return 1;
}
@@ -425,7 +425,7 @@ static int nfs_validate_options(struct nfsmount_info *mi)
if (!nfs_set_version(mi))
return 0;
- if (!nfs_append_sloppy_option(mi->options))
+ if (!nfs_insert_sloppy_option(mi->options))
return 0;
return 1;