17
17
#include <linux/writeback.h>
18
18
#include <linux/mount.h>
19
19
#include <linux/fs_context.h>
20
+ #include <linux/fs_parser.h>
20
21
#include <linux/namei.h>
21
22
#include "hostfs.h"
22
23
#include <init.h>
@@ -927,7 +928,6 @@ static const struct inode_operations hostfs_link_iops = {
927
928
static int hostfs_fill_super (struct super_block * sb , struct fs_context * fc )
928
929
{
929
930
struct hostfs_fs_info * fsi = sb -> s_fs_info ;
930
- const char * host_root = fc -> source ;
931
931
struct inode * root_inode ;
932
932
int err ;
933
933
@@ -941,15 +941,6 @@ static int hostfs_fill_super(struct super_block *sb, struct fs_context *fc)
941
941
if (err )
942
942
return err ;
943
943
944
- /* NULL is printed as '(null)' by printf(): avoid that. */
945
- if (fc -> source == NULL )
946
- host_root = "" ;
947
-
948
- fsi -> host_root_path =
949
- kasprintf (GFP_KERNEL , "%s/%s" , root_ino , host_root );
950
- if (fsi -> host_root_path == NULL )
951
- return - ENOMEM ;
952
-
953
944
root_inode = hostfs_iget (sb , fsi -> host_root_path );
954
945
if (IS_ERR (root_inode ))
955
946
return PTR_ERR (root_inode );
@@ -975,6 +966,58 @@ static int hostfs_fill_super(struct super_block *sb, struct fs_context *fc)
975
966
return 0 ;
976
967
}
977
968
969
+ enum hostfs_parma {
970
+ Opt_hostfs ,
971
+ };
972
+
973
+ static const struct fs_parameter_spec hostfs_param_specs [] = {
974
+ fsparam_string_empty ("hostfs" , Opt_hostfs ),
975
+ {}
976
+ };
977
+
978
+ static int hostfs_parse_param (struct fs_context * fc , struct fs_parameter * param )
979
+ {
980
+ struct hostfs_fs_info * fsi = fc -> s_fs_info ;
981
+ struct fs_parse_result result ;
982
+ char * host_root ;
983
+ int opt ;
984
+
985
+ opt = fs_parse (fc , hostfs_param_specs , param , & result );
986
+ if (opt < 0 )
987
+ return opt ;
988
+
989
+ switch (opt ) {
990
+ case Opt_hostfs :
991
+ host_root = param -> string ;
992
+ if (!* host_root )
993
+ host_root = "" ;
994
+ fsi -> host_root_path =
995
+ kasprintf (GFP_KERNEL , "%s/%s" , root_ino , host_root );
996
+ if (fsi -> host_root_path == NULL )
997
+ return - ENOMEM ;
998
+ break ;
999
+ }
1000
+
1001
+ return 0 ;
1002
+ }
1003
+
1004
+ static int hostfs_parse_monolithic (struct fs_context * fc , void * data )
1005
+ {
1006
+ struct hostfs_fs_info * fsi = fc -> s_fs_info ;
1007
+ char * host_root = (char * )data ;
1008
+
1009
+ /* NULL is printed as '(null)' by printf(): avoid that. */
1010
+ if (host_root == NULL )
1011
+ host_root = "" ;
1012
+
1013
+ fsi -> host_root_path =
1014
+ kasprintf (GFP_KERNEL , "%s/%s" , root_ino , host_root );
1015
+ if (fsi -> host_root_path == NULL )
1016
+ return - ENOMEM ;
1017
+
1018
+ return 0 ;
1019
+ }
1020
+
978
1021
static int hostfs_fc_get_tree (struct fs_context * fc )
979
1022
{
980
1023
return get_tree_nodev (fc , hostfs_fill_super );
@@ -992,6 +1035,8 @@ static void hostfs_fc_free(struct fs_context *fc)
992
1035
}
993
1036
994
1037
static const struct fs_context_operations hostfs_context_ops = {
1038
+ .parse_monolithic = hostfs_parse_monolithic ,
1039
+ .parse_param = hostfs_parse_param ,
995
1040
.get_tree = hostfs_fc_get_tree ,
996
1041
.free = hostfs_fc_free ,
997
1042
};
0 commit comments