diff mbox series

[v2,1/3] fs_parser: add helper to define parameters with string and flag types

Message ID 20240307160225.23841-2-lhenriques@suse.de (mailing list archive)
State New, archived
Headers show
Series fs_parser: handle parameters that can be empty and don't have a value | expand

Commit Message

Luis Henriques March 7, 2024, 4:02 p.m. UTC
Add a new helper macro that defines two new parameters, both with the same
name, but one of type 'string' and another of type 'flag'.  The 'string'
parameter may also be empty (i.e. without value).  In practice this helper
allows a filesystem to easily define a parameter that can be empty (flag)
or have a value (string).

Suggested-by: Christian Brauner <brauner@kernel.org>
Signed-off-by: Luis Henriques <lhenriques@suse.de>
---
 include/linux/fs_parser.h | 8 ++++++++
 1 file changed, 8 insertions(+)
diff mbox series

Patch

diff --git a/include/linux/fs_parser.h b/include/linux/fs_parser.h
index 01542c4b87a2..f582fb7bdc22 100644
--- a/include/linux/fs_parser.h
+++ b/include/linux/fs_parser.h
@@ -131,5 +131,13 @@  static inline bool fs_validate_description(const char *name,
 #define fsparam_bdev(NAME, OPT)	__fsparam(fs_param_is_blockdev, NAME, OPT, 0, NULL)
 #define fsparam_path(NAME, OPT)	__fsparam(fs_param_is_path, NAME, OPT, 0, NULL)
 #define fsparam_fd(NAME, OPT)	__fsparam(fs_param_is_fd, NAME, OPT, 0, NULL)
+/*
+ * Define two parameters with the same name, with types string and flag.  The
+ * string parameter can be empty, and thus it effectively allows the parameter
+ * to have a value or to be empty.
+ */
+#define fsparam_string_or_flag(NAME, OPT)				\
+	__fsparam(fs_param_is_string, NAME, OPT, fs_param_can_be_empty, NULL), \
+	fsparam_flag(NAME, OPT)
 
 #endif /* _LINUX_FS_PARSER_H */