@@ -63,22 +63,6 @@ __setup("devtmpfs.mount=", mount_param);
6363
6464static struct vfsmount * mnt ;
6565
66- static struct dentry * public_dev_mount (struct file_system_type * fs_type , int flags ,
67- const char * dev_name , void * data )
68- {
69- struct super_block * s = mnt -> mnt_sb ;
70- int err ;
71-
72- atomic_inc (& s -> s_active );
73- down_write (& s -> s_umount );
74- err = reconfigure_single (s , flags , data );
75- if (err < 0 ) {
76- deactivate_locked_super (s );
77- return ERR_PTR (err );
78- }
79- return dget (s -> s_root );
80- }
81-
8266static struct file_system_type internal_fs_type = {
8367 .name = "devtmpfs" ,
8468#ifdef CONFIG_TMPFS
@@ -89,9 +73,40 @@ static struct file_system_type internal_fs_type = {
8973 .kill_sb = kill_litter_super ,
9074};
9175
76+ /* Simply take a ref on the existing mount */
77+ static int devtmpfs_get_tree (struct fs_context * fc )
78+ {
79+ struct super_block * sb = mnt -> mnt_sb ;
80+
81+ atomic_inc (& sb -> s_active );
82+ down_write (& sb -> s_umount );
83+ fc -> root = dget (sb -> s_root );
84+ return 0 ;
85+ }
86+
87+ /* Ops are filled in during init depending on underlying shmem or ramfs type */
88+ struct fs_context_operations devtmpfs_context_ops = {};
89+
90+ /* Call the underlying initialization and set to our ops */
91+ static int devtmpfs_init_fs_context (struct fs_context * fc )
92+ {
93+ int ret ;
94+ #ifdef CONFIG_TMPFS
95+ ret = shmem_init_fs_context (fc );
96+ #else
97+ ret = ramfs_init_fs_context (fc );
98+ #endif
99+ if (ret < 0 )
100+ return ret ;
101+
102+ fc -> ops = & devtmpfs_context_ops ;
103+
104+ return 0 ;
105+ }
106+
92107static struct file_system_type dev_fs_type = {
93108 .name = "devtmpfs" ,
94- .mount = public_dev_mount ,
109+ .init_fs_context = devtmpfs_init_fs_context ,
95110};
96111
97112static int devtmpfs_submit_req (struct req * req , const char * tmp )
@@ -433,6 +448,31 @@ static int __ref devtmpfsd(void *p)
433448 return 0 ;
434449}
435450
451+ /*
452+ * Get the underlying (shmem/ramfs) context ops to build ours
453+ */
454+ static int devtmpfs_configure_context (void )
455+ {
456+ struct fs_context * fc ;
457+
458+ fc = fs_context_for_reconfigure (mnt -> mnt_root , mnt -> mnt_sb -> s_flags ,
459+ MS_RMT_MASK );
460+ if (IS_ERR (fc ))
461+ return PTR_ERR (fc );
462+
463+ /* Set up devtmpfs_context_ops based on underlying type */
464+ devtmpfs_context_ops .free = fc -> ops -> free ;
465+ devtmpfs_context_ops .dup = fc -> ops -> dup ;
466+ devtmpfs_context_ops .parse_param = fc -> ops -> parse_param ;
467+ devtmpfs_context_ops .parse_monolithic = fc -> ops -> parse_monolithic ;
468+ devtmpfs_context_ops .get_tree = & devtmpfs_get_tree ;
469+ devtmpfs_context_ops .reconfigure = fc -> ops -> reconfigure ;
470+
471+ put_fs_context (fc );
472+
473+ return 0 ;
474+ }
475+
436476/*
437477 * Create devtmpfs instance, driver-core devices will add their device
438478 * nodes here.
@@ -447,6 +487,13 @@ int __init devtmpfs_init(void)
447487 pr_err ("unable to create devtmpfs %ld\n" , PTR_ERR (mnt ));
448488 return PTR_ERR (mnt );
449489 }
490+
491+ err = devtmpfs_configure_context ();
492+ if (err ) {
493+ pr_err ("unable to configure devtmpfs type %d\n" , err );
494+ return err ;
495+ }
496+
450497 err = register_filesystem (& dev_fs_type );
451498 if (err ) {
452499 pr_err ("unable to register devtmpfs type %d\n" , err );
0 commit comments