1414#include <linux/init.h>
1515#include <linux/list.h>
1616#include <linux/string.h>
17- #include <linux/mount.h>
1817#include <linux/seq_file.h>
1918#include <linux/ramfs.h>
20- #include <linux/parser.h>
19+ #include <linux/fs_parser.h>
20+ #include <linux/fs_context.h>
2121#include <linux/sched.h>
2222#include <linux/magic.h>
2323#include <linux/pstore.h>
@@ -226,37 +226,38 @@ static struct inode *pstore_get_inode(struct super_block *sb)
226226}
227227
228228enum {
229- Opt_kmsg_bytes , Opt_err
229+ Opt_kmsg_bytes
230230};
231231
232- static const match_table_t tokens = {
233- { Opt_kmsg_bytes , "kmsg_bytes=%u" } ,
234- {Opt_err , NULL }
232+ static const struct fs_parameter_spec pstore_param_spec [] = {
233+ fsparam_u32 ( "kmsg_bytes" , Opt_kmsg_bytes ) ,
234+ {}
235235};
236236
237- static void parse_options (char * options )
238- {
239- char * p ;
240- substring_t args [MAX_OPT_ARGS ];
241- int option ;
242-
243- if (!options )
244- return ;
237+ struct pstore_context {
238+ unsigned int kmsg_bytes ;
239+ };
245240
246- while ((p = strsep (& options , "," )) != NULL ) {
247- int token ;
241+ static int pstore_parse_param (struct fs_context * fc , struct fs_parameter * param )
242+ {
243+ struct pstore_context * ctx = fc -> fs_private ;
244+ struct fs_parse_result result ;
245+ int opt ;
248246
249- if (!* p )
250- continue ;
247+ opt = fs_parse (fc , pstore_param_spec , param , & result );
248+ /* pstore has historically ignored invalid kmsg_bytes param */
249+ if (opt < 0 )
250+ return 0 ;
251251
252- token = match_token (p , tokens , args );
253- switch (token ) {
254- case Opt_kmsg_bytes :
255- if (!match_int (& args [0 ], & option ))
256- pstore_set_kmsg_bytes (option );
257- break ;
258- }
252+ switch (opt ) {
253+ case Opt_kmsg_bytes :
254+ ctx -> kmsg_bytes = result .uint_32 ;
255+ break ;
256+ default :
257+ return - EINVAL ;
259258 }
259+
260+ return 0 ;
260261}
261262
262263/*
@@ -269,10 +270,12 @@ static int pstore_show_options(struct seq_file *m, struct dentry *root)
269270 return 0 ;
270271}
271272
272- static int pstore_remount (struct super_block * sb , int * flags , char * data )
273+ static int pstore_reconfigure (struct fs_context * fc )
273274{
274- sync_filesystem (sb );
275- parse_options (data );
275+ struct pstore_context * ctx = fc -> fs_private ;
276+
277+ sync_filesystem (fc -> root -> d_sb );
278+ pstore_set_kmsg_bytes (ctx -> kmsg_bytes );
276279
277280 return 0 ;
278281}
@@ -281,7 +284,6 @@ static const struct super_operations pstore_ops = {
281284 .statfs = simple_statfs ,
282285 .drop_inode = generic_delete_inode ,
283286 .evict_inode = pstore_evict_inode ,
284- .remount_fs = pstore_remount ,
285287 .show_options = pstore_show_options ,
286288};
287289
@@ -406,8 +408,9 @@ void pstore_get_records(int quiet)
406408 inode_unlock (d_inode (root ));
407409}
408410
409- static int pstore_fill_super (struct super_block * sb , void * data , int silent )
411+ static int pstore_fill_super (struct super_block * sb , struct fs_context * fc )
410412{
413+ struct pstore_context * ctx = fc -> fs_private ;
411414 struct inode * inode ;
412415
413416 sb -> s_maxbytes = MAX_LFS_FILESIZE ;
@@ -417,7 +420,7 @@ static int pstore_fill_super(struct super_block *sb, void *data, int silent)
417420 sb -> s_op = & pstore_ops ;
418421 sb -> s_time_gran = 1 ;
419422
420- parse_options ( data );
423+ pstore_set_kmsg_bytes ( ctx -> kmsg_bytes );
421424
422425 inode = pstore_get_inode (sb );
423426 if (inode ) {
@@ -438,12 +441,26 @@ static int pstore_fill_super(struct super_block *sb, void *data, int silent)
438441 return 0 ;
439442}
440443
441- static struct dentry * pstore_mount (struct file_system_type * fs_type ,
442- int flags , const char * dev_name , void * data )
444+ static int pstore_get_tree (struct fs_context * fc )
445+ {
446+ if (fc -> root )
447+ return pstore_reconfigure (fc );
448+
449+ return get_tree_single (fc , pstore_fill_super );
450+ }
451+
452+ static void pstore_free_fc (struct fs_context * fc )
443453{
444- return mount_single ( fs_type , flags , data , pstore_fill_super );
454+ kfree ( fc -> fs_private );
445455}
446456
457+ static const struct fs_context_operations pstore_context_ops = {
458+ .parse_param = pstore_parse_param ,
459+ .get_tree = pstore_get_tree ,
460+ .reconfigure = pstore_reconfigure ,
461+ .free = pstore_free_fc ,
462+ };
463+
447464static void pstore_kill_sb (struct super_block * sb )
448465{
449466 guard (mutex )(& pstore_sb_lock );
@@ -456,11 +473,33 @@ static void pstore_kill_sb(struct super_block *sb)
456473 INIT_LIST_HEAD (& records_list );
457474}
458475
476+ static int pstore_init_fs_context (struct fs_context * fc )
477+ {
478+ struct pstore_context * ctx ;
479+
480+ ctx = kzalloc (sizeof (struct pstore_context ), GFP_KERNEL );
481+ if (!ctx )
482+ return - ENOMEM ;
483+
484+ /*
485+ * Global kmsg_bytes is initialized to default, and updated
486+ * every time we (re)mount the single-sb filesystem with the
487+ * option specified.
488+ */
489+ ctx -> kmsg_bytes = kmsg_bytes ;
490+
491+ fc -> fs_private = ctx ;
492+ fc -> ops = & pstore_context_ops ;
493+
494+ return 0 ;
495+ }
496+
459497static struct file_system_type pstore_fs_type = {
460498 .owner = THIS_MODULE ,
461499 .name = "pstore" ,
462- .mount = pstore_mount ,
463500 .kill_sb = pstore_kill_sb ,
501+ .init_fs_context = pstore_init_fs_context ,
502+ .parameters = pstore_param_spec ,
464503};
465504
466505int __init pstore_init_fs (void )
0 commit comments