Subtype was initilized at the wrong place from the wrong source
(fstype->fs_type->name, which does not ever contain a subtype).

Set subtype from do_new_mount(), where it actually does something.
Verified with fuse.

Signed-off-by: Miklos Szeredi <mszer...@redhat.com>
---
 fs/fs_context.c | 34 ----------------------------------
 fs/namespace.c  | 21 +++++++++++++++++++++
 2 files changed, 21 insertions(+), 34 deletions(-)

diff --git a/fs/fs_context.c b/fs/fs_context.c
index ceaf42559016..c0ecbb1ecdfe 100644
--- a/fs/fs_context.c
+++ b/fs/fs_context.c
@@ -684,27 +684,6 @@ static int legacy_validate(struct fs_context *fc)
                                     ctx->secdata);
 }
 
-/*
- * Determine the superblock subtype.
- */
-static int legacy_set_subtype(struct fs_context *fc)
-{
-       const char *subtype = strchr(fc->fs_type->name, '.');
-
-       if (subtype) {
-               subtype++;
-               if (!subtype[0])
-                       return -EINVAL;
-       } else {
-               subtype = "";
-       }
-
-       fc->subtype = kstrdup(subtype, GFP_KERNEL);
-       if (!fc->subtype)
-               return -ENOMEM;
-       return 0;
-}
-
 /*
  * Get a mountable root with the legacy mount command.
  */
@@ -713,7 +692,6 @@ static int legacy_get_tree(struct fs_context *fc)
        struct legacy_fs_context *ctx = fc->fs_private;
        struct super_block *sb;
        struct dentry *root;
-       int ret;
 
        root = fc->fs_type->mount(fc->fs_type, fc->sb_flags,
                                      fc->source, ctx->legacy_data,
@@ -724,20 +702,8 @@ static int legacy_get_tree(struct fs_context *fc)
        sb = root->d_sb;
        BUG_ON(!sb);
 
-       if ((fc->fs_type->fs_flags & FS_HAS_SUBTYPE) &&
-           !fc->subtype) {
-               ret = legacy_set_subtype(fc);
-               if (ret < 0)
-                       goto err_sb;
-       }
-
        fc->root = root;
        return 0;
-
-err_sb:
-       dput(root);
-       deactivate_locked_super(sb);
-       return ret;
 }
 
 /*
diff --git a/fs/namespace.c b/fs/namespace.c
index 865b6f2c5e7d..7671c1f6fc22 100644
--- a/fs/namespace.c
+++ b/fs/namespace.c
@@ -2617,6 +2617,7 @@ static int do_new_mount(struct path *mountpoint, const 
char *fstype,
 {
        struct file_system_type *fs_type;
        struct fs_context *fc;
+       const char *subtype = NULL;
        int err;
 
        if (!fstype)
@@ -2627,6 +2628,19 @@ static int do_new_mount(struct path *mountpoint, const 
char *fstype,
        if (!fs_type)
                goto out;
 
+       if (fs_type->fs_flags & FS_HAS_SUBTYPE) {
+               subtype = strchr(fstype, '.');
+               if (subtype) {
+                       subtype++;
+                       if (!subtype[0]) {
+                               put_filesystem(fs_type);
+                               return -EINVAL;
+                       }
+               } else {
+                       subtype = "";
+               }
+       }
+
        fc = vfs_new_fs_context(fs_type, NULL, sb_flags, sb_flags,
                                FS_CONTEXT_FOR_USER_MOUNT);
        put_filesystem(fs_type);
@@ -2635,6 +2649,13 @@ static int do_new_mount(struct path *mountpoint, const 
char *fstype,
                goto out;
        }
 
+       if (subtype) {
+               fc->subtype = kstrdup(subtype, GFP_KERNEL);
+               err = -ENOMEM;
+               if (!fc->subtype)
+                       goto out;
+       }
+
        if (name) {
                err = vfs_parse_fs_string(fc, "source", name, strlen(name));
                if (err < 0)
-- 
2.14.3

Reply via email to