Skip to content

Commit e001d14

Browse files
committed
fs: factor out vfs_parse_monolithic_sep() helper
Factor out vfs_parse_monolithic_sep() from generic_parse_monolithic(), so filesystems could use it with a custom option separator callback. Acked-by: Christian Brauner <[email protected]> Signed-off-by: Amir Goldstein <[email protected]>
1 parent 94f6f05 commit e001d14

File tree

2 files changed

+31
-5
lines changed

2 files changed

+31
-5
lines changed

fs/fs_context.c

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -192,17 +192,19 @@ int vfs_parse_fs_string(struct fs_context *fc, const char *key,
192192
EXPORT_SYMBOL(vfs_parse_fs_string);
193193

194194
/**
195-
* generic_parse_monolithic - Parse key[=val][,key[=val]]* mount data
195+
* vfs_parse_monolithic_sep - Parse key[=val][,key[=val]]* mount data
196196
* @fc: The superblock configuration to fill in.
197197
* @data: The data to parse
198+
* @sep: callback for separating next option
198199
*
199-
* Parse a blob of data that's in key[=val][,key[=val]]* form. This can be
200-
* called from the ->monolithic_mount_data() fs_context operation.
200+
* Parse a blob of data that's in key[=val][,key[=val]]* form with a custom
201+
* option separator callback.
201202
*
202203
* Returns 0 on success or the error returned by the ->parse_option() fs_context
203204
* operation on failure.
204205
*/
205-
int generic_parse_monolithic(struct fs_context *fc, void *data)
206+
int vfs_parse_monolithic_sep(struct fs_context *fc, void *data,
207+
char *(*sep)(char **))
206208
{
207209
char *options = data, *key;
208210
int ret = 0;
@@ -214,7 +216,7 @@ int generic_parse_monolithic(struct fs_context *fc, void *data)
214216
if (ret)
215217
return ret;
216218

217-
while ((key = strsep(&options, ",")) != NULL) {
219+
while ((key = sep(&options)) != NULL) {
218220
if (*key) {
219221
size_t v_len = 0;
220222
char *value = strchr(key, '=');
@@ -233,6 +235,28 @@ int generic_parse_monolithic(struct fs_context *fc, void *data)
233235

234236
return ret;
235237
}
238+
EXPORT_SYMBOL(vfs_parse_monolithic_sep);
239+
240+
static char *vfs_parse_comma_sep(char **s)
241+
{
242+
return strsep(s, ",");
243+
}
244+
245+
/**
246+
* generic_parse_monolithic - Parse key[=val][,key[=val]]* mount data
247+
* @fc: The superblock configuration to fill in.
248+
* @data: The data to parse
249+
*
250+
* Parse a blob of data that's in key[=val][,key[=val]]* form. This can be
251+
* called from the ->monolithic_mount_data() fs_context operation.
252+
*
253+
* Returns 0 on success or the error returned by the ->parse_option() fs_context
254+
* operation on failure.
255+
*/
256+
int generic_parse_monolithic(struct fs_context *fc, void *data)
257+
{
258+
return vfs_parse_monolithic_sep(fc, data, vfs_parse_comma_sep);
259+
}
236260
EXPORT_SYMBOL(generic_parse_monolithic);
237261

238262
/**

include/linux/fs_context.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ extern struct fs_context *vfs_dup_fs_context(struct fs_context *fc);
136136
extern int vfs_parse_fs_param(struct fs_context *fc, struct fs_parameter *param);
137137
extern int vfs_parse_fs_string(struct fs_context *fc, const char *key,
138138
const char *value, size_t v_size);
139+
int vfs_parse_monolithic_sep(struct fs_context *fc, void *data,
140+
char *(*sep)(char **));
139141
extern int generic_parse_monolithic(struct fs_context *fc, void *data);
140142
extern int vfs_get_tree(struct fs_context *fc);
141143
extern void put_fs_context(struct fs_context *fc);

0 commit comments

Comments
 (0)