On 21/07/2020 21:33, Goffredo Baroncelli wrote:
From: Goffredo Baroncelli <kreijack@xxxxxxxxx>
When more than one subvol= options are passed, btrfs try to mount
each subvolume until the first one succeed. Up to 5 subvol= options
can be passed.
Signed-off-by: Goffredo Baroncelli <kreijack@xxxxxxxxx>
---
fs/btrfs/super.c | 71 ++++++++++++++++++++++++++++++------------------
1 file changed, 45 insertions(+), 26 deletions(-)
diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
index bc73fd670702..12d066e8d52c 100644
--- a/fs/btrfs/super.c
+++ b/fs/btrfs/super.c
@@ -52,6 +52,8 @@
#define CREATE_TRACE_POINTS
#include <trace/events/btrfs.h>
+#define SUBVOL_NAMES_COUNT 5
As this is a maximum, perhaps MAX_SUBVOL_NAMES or SUBVOL_NAMES_MAX
+
static const struct super_operations btrfs_super_ops;
/*
@@ -974,12 +976,13 @@ static int btrfs_parse_device_options(const char *options, fmode_t flags,
*
* The value is later passed to mount_subvol()
*/
-static int btrfs_parse_subvol_options(const char *options, char **subvol_name,
- u64 *subvol_objectid)
+static int btrfs_parse_subvol_options(const char *options, char **subvol_names,
+ u64 *subvol_objectid)
{
substring_t args[MAX_OPT_ARGS];
char *opts, *orig, *p;
int error = 0;
+ int svi = 0;
u64 subvolid;
if (!options)
@@ -1002,12 +1005,17 @@ static int btrfs_parse_subvol_options(const char *options, char **subvol_name,
token = match_token(p, tokens, args);
switch (token) {
case Opt_subvol:
- kfree(*subvol_name);
- *subvol_name = match_strdup(&args[0]);
- if (!*subvol_name) {
+ if (svi >= SUBVOL_NAMES_COUNT) {
+ pr_err("BTRFS: too much 'subvol=' mount options\n");
s/too much/too many/
Perhaps also include ", maximum is %d", SUBVOL_NAMES_COUNT
--snip--
--
Steven Davies