@@ -107,6 +107,7 @@ enum {
107107 Opt_noextent_cache ,
108108 Opt_noinline_data ,
109109 Opt_data_flush ,
110+ Opt_reserve_root ,
110111 Opt_mode ,
111112 Opt_io_size_bits ,
112113 Opt_fault_injection ,
@@ -157,6 +158,7 @@ static match_table_t f2fs_tokens = {
157158 {Opt_noextent_cache , "noextent_cache" },
158159 {Opt_noinline_data , "noinline_data" },
159160 {Opt_data_flush , "data_flush" },
161+ {Opt_reserve_root , "reserve_root=%u" },
160162 {Opt_mode , "mode=%s" },
161163 {Opt_io_size_bits , "io_bits=%u" },
162164 {Opt_fault_injection , "fault_injection=%u" },
@@ -191,6 +193,19 @@ void f2fs_msg(struct super_block *sb, const char *level, const char *fmt, ...)
191193 va_end (args );
192194}
193195
196+ static inline void limit_reserve_root (struct f2fs_sb_info * sbi )
197+ {
198+ block_t limit = (sbi -> user_block_count << 1 ) / 1000 ;
199+
200+ /* limit is 0.2% */
201+ if (test_opt (sbi , RESERVE_ROOT ) && sbi -> root_reserved_blocks > limit ) {
202+ sbi -> root_reserved_blocks = limit ;
203+ f2fs_msg (sbi -> sb , KERN_INFO ,
204+ "Reduce reserved blocks for root = %u" ,
205+ sbi -> root_reserved_blocks );
206+ }
207+ }
208+
194209static void init_once (void * foo )
195210{
196211 struct f2fs_inode_info * fi = (struct f2fs_inode_info * ) foo ;
@@ -488,6 +503,18 @@ static int parse_options(struct super_block *sb, char *options)
488503 case Opt_data_flush :
489504 set_opt (sbi , DATA_FLUSH );
490505 break ;
506+ case Opt_reserve_root :
507+ if (args -> from && match_int (args , & arg ))
508+ return - EINVAL ;
509+ if (test_opt (sbi , RESERVE_ROOT )) {
510+ f2fs_msg (sb , KERN_INFO ,
511+ "Preserve previous reserve_root=%u" ,
512+ sbi -> root_reserved_blocks );
513+ } else {
514+ sbi -> root_reserved_blocks = arg ;
515+ set_opt (sbi , RESERVE_ROOT );
516+ }
517+ break ;
491518 case Opt_mode :
492519 name = match_strdup (& args [0 ]);
493520
@@ -1006,7 +1033,10 @@ static int f2fs_statfs(struct dentry *dentry, struct kstatfs *buf)
10061033 buf -> f_blocks = total_count - start_count ;
10071034 buf -> f_bfree = user_block_count - valid_user_blocks (sbi ) -
10081035 sbi -> current_reserved_blocks ;
1009- buf -> f_bavail = buf -> f_bfree ;
1036+ if (buf -> f_bfree > sbi -> root_reserved_blocks )
1037+ buf -> f_bavail = buf -> f_bfree - sbi -> root_reserved_blocks ;
1038+ else
1039+ buf -> f_bavail = 0 ;
10101040
10111041 avail_node_count = sbi -> total_node_count - sbi -> nquota_files -
10121042 F2FS_RESERVED_NODE_NUM ;
@@ -1135,6 +1165,9 @@ static int f2fs_show_options(struct seq_file *seq, struct dentry *root)
11351165 else if (test_opt (sbi , LFS ))
11361166 seq_puts (seq , "lfs" );
11371167 seq_printf (seq , ",active_logs=%u" , sbi -> active_logs );
1168+ if (test_opt (sbi , RESERVE_ROOT ))
1169+ seq_printf (seq , ",reserve_root=%u" ,
1170+ sbi -> root_reserved_blocks );
11381171 if (F2FS_IO_SIZE_BITS (sbi ))
11391172 seq_printf (seq , ",io_size=%uKB" , F2FS_IO_SIZE_KB (sbi ));
11401173#ifdef CONFIG_F2FS_FAULT_INJECTION
@@ -1333,6 +1366,7 @@ static int f2fs_remount(struct super_block *sb, int *flags, char *data)
13331366 sb -> s_flags = (sb -> s_flags & ~SB_POSIXACL ) |
13341367 (test_opt (sbi , POSIX_ACL ) ? SB_POSIXACL : 0 );
13351368
1369+ limit_reserve_root (sbi );
13361370 return 0 ;
13371371restore_gc :
13381372 if (need_restart_gc ) {
@@ -2569,6 +2603,7 @@ static int f2fs_fill_super(struct super_block *sb, void *data, int silent)
25692603 sbi -> last_valid_block_count = sbi -> total_valid_block_count ;
25702604 sbi -> reserved_blocks = 0 ;
25712605 sbi -> current_reserved_blocks = 0 ;
2606+ limit_reserve_root (sbi );
25722607
25732608 for (i = 0 ; i < NR_INODE_TYPE ; i ++ ) {
25742609 INIT_LIST_HEAD (& sbi -> inode_list [i ]);
0 commit comments