linux-cifs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Paulo Alcantara <pc@cjr.nz>
To: linux-cifs@vger.kernel.org, smfrench@gmail.com
Cc: Paulo Alcantara <pc@cjr.nz>
Subject: [PATCH 1/3] cifs: introduce smb3_options_for_each() helper
Date: Tue, 11 May 2021 13:36:07 -0300	[thread overview]
Message-ID: <20210511163609.11019-2-pc@cjr.nz> (raw)
In-Reply-To: <20210511163609.11019-1-pc@cjr.nz>

Introduce a new helper to walk through the mount options and avoid
duplicating it all over the cifs code.

Signed-off-by: Paulo Alcantara (SUSE) <pc@cjr.nz>
---
 fs/cifs/cifsglob.h | 16 ++++++++++++++++
 fs/cifs/misc.c     | 48 ++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 64 insertions(+)

diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
index ea90c53386b8..6c65e39f0509 100644
--- a/fs/cifs/cifsglob.h
+++ b/fs/cifs/cifsglob.h
@@ -1960,4 +1960,20 @@ static inline bool is_tcon_dfs(struct cifs_tcon *tcon)
 		tcon->share_flags & (SHI1005_FLAGS_DFS | SHI1005_FLAGS_DFS_ROOT);
 }
 
+char *smb3_parse_option(char *options, char sep, char **nkey, char **nval);
+
+static inline char *smb3_parse_options_sep(char *options, char *sep, char **nkey, char **nval)
+{
+	*sep = ',';
+	if (!strncmp(options, "sep=", 4)) {
+		*sep = options[4];
+		options += 5;
+	}
+	return smb3_parse_option(options, *sep, nkey, nval);
+}
+
+#define smb3_options_for_each(opts, nopts, sep, key, val) \
+	for (nopts = (opts), nopts = smb3_parse_options_sep(nopts, &sep, &(key), &(val)); \
+	     (key); nopts = smb3_parse_option(nopts, sep, &(key), &(val)))
+
 #endif	/* _CIFS_GLOB_H */
diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
index cd705f8a4e31..7b3b1ea76baf 100644
--- a/fs/cifs/misc.c
+++ b/fs/cifs/misc.c
@@ -1284,3 +1284,51 @@ int update_super_prepath(struct cifs_tcon *tcon, char *prefix)
 	cifs_put_tcon_super(sb);
 	return rc;
 }
+
+/**
+ * Parse a string that is in key[=val][,key[=val]]* form.
+ *
+ * @options: The options to parse
+ * @sep: The options separator
+ * @nkey: The next key pointer
+ * @nval: The next value pointer
+ *
+ * Returns next key-value pair to be parsed, otherwise NULL.
+ */
+char *smb3_parse_option(char *options, char sep, char **nkey, char **nval)
+{
+	char *key, *value;
+	char sepstr[2] = {sep, '\0'};
+
+	*nkey = NULL;
+	*nval = NULL;
+
+	if (!options || !options[0])
+		return NULL;
+
+	while ((key = strsep(&options, sepstr)) != NULL) {
+		size_t len;
+
+		if (*key == 0)
+			return NULL;
+
+		while (options && options[0] == sep) {
+			len = strlen(key);
+			strcpy(key + len, options);
+			options = strchr(options, sep);
+			if (options)
+				*options++ = 0;
+		}
+
+		value = strchr(key, '=');
+		if (value) {
+			if (value == key)
+				continue;
+			*value++ = 0;
+		}
+		break;
+	}
+	*nkey = key;
+	*nval = value;
+	return options;
+}
-- 
2.31.1


  reply	other threads:[~2021-05-11 16:36 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-11 16:36 [PATCH 0/3] Support multiple ips per hostname Paulo Alcantara
2021-05-11 16:36 ` Paulo Alcantara [this message]
2021-05-11 18:15   ` [PATCH 1/3] cifs: introduce smb3_options_for_each() helper kernel test robot
2021-05-11 16:36 ` [PATCH 2/3] cifs: handle multiple ip addresses per hostname Paulo Alcantara
2021-05-11 18:47   ` kernel test robot
2021-05-11 18:47   ` kernel test robot
2021-05-11 16:36 ` [PATCH 3/3] cifs: fix find_root_ses() when refresing dfs cache Paulo Alcantara

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=20210511163609.11019-2-pc@cjr.nz \
    --to=pc@cjr.nz \
    --cc=linux-cifs@vger.kernel.org \
    --cc=smfrench@gmail.com \
    --subject='Re: [PATCH 1/3] cifs: introduce smb3_options_for_each() helper' \
    /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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).