@@ -914,6 +914,18 @@ static inline void ext4_quota_off_umount(struct super_block *sb)
914
914
for (type = 0 ; type < EXT4_MAXQUOTAS ; type ++ )
915
915
ext4_quota_off (sb , type );
916
916
}
917
+
918
+ /*
919
+ * This is a helper function which is used in the mount/remount
920
+ * codepaths (which holds s_umount) to fetch the quota file name.
921
+ */
922
+ static inline char * get_qf_name (struct super_block * sb ,
923
+ struct ext4_sb_info * sbi ,
924
+ int type )
925
+ {
926
+ return rcu_dereference_protected (sbi -> s_qf_names [type ],
927
+ lockdep_is_held (& sb -> s_umount ));
928
+ }
917
929
#else
918
930
static inline void ext4_quota_off_umount (struct super_block * sb )
919
931
{
@@ -965,7 +977,7 @@ static void ext4_put_super(struct super_block *sb)
965
977
percpu_free_rwsem (& sbi -> s_journal_flag_rwsem );
966
978
#ifdef CONFIG_QUOTA
967
979
for (i = 0 ; i < EXT4_MAXQUOTAS ; i ++ )
968
- kfree (sbi -> s_qf_names [ i ] );
980
+ kfree (get_qf_name ( sb , sbi , i ) );
969
981
#endif
970
982
971
983
/* Debugging code just in case the in-memory inode orphan list
@@ -1531,11 +1543,10 @@ static const char deprecated_msg[] =
1531
1543
static int set_qf_name (struct super_block * sb , int qtype , substring_t * args )
1532
1544
{
1533
1545
struct ext4_sb_info * sbi = EXT4_SB (sb );
1534
- char * qname ;
1546
+ char * qname , * old_qname = get_qf_name ( sb , sbi , qtype ) ;
1535
1547
int ret = -1 ;
1536
1548
1537
- if (sb_any_quota_loaded (sb ) &&
1538
- !sbi -> s_qf_names [qtype ]) {
1549
+ if (sb_any_quota_loaded (sb ) && !old_qname ) {
1539
1550
ext4_msg (sb , KERN_ERR ,
1540
1551
"Cannot change journaled "
1541
1552
"quota options when quota turned on" );
@@ -1552,8 +1563,8 @@ static int set_qf_name(struct super_block *sb, int qtype, substring_t *args)
1552
1563
"Not enough memory for storing quotafile name" );
1553
1564
return -1 ;
1554
1565
}
1555
- if (sbi -> s_qf_names [ qtype ] ) {
1556
- if (strcmp (sbi -> s_qf_names [ qtype ] , qname ) == 0 )
1566
+ if (old_qname ) {
1567
+ if (strcmp (old_qname , qname ) == 0 )
1557
1568
ret = 1 ;
1558
1569
else
1559
1570
ext4_msg (sb , KERN_ERR ,
@@ -1566,7 +1577,7 @@ static int set_qf_name(struct super_block *sb, int qtype, substring_t *args)
1566
1577
"quotafile must be on filesystem root" );
1567
1578
goto errout ;
1568
1579
}
1569
- sbi -> s_qf_names [qtype ] = qname ;
1580
+ rcu_assign_pointer ( sbi -> s_qf_names [qtype ], qname ) ;
1570
1581
set_opt (sb , QUOTA );
1571
1582
return 1 ;
1572
1583
errout :
@@ -1578,15 +1589,16 @@ static int clear_qf_name(struct super_block *sb, int qtype)
1578
1589
{
1579
1590
1580
1591
struct ext4_sb_info * sbi = EXT4_SB (sb );
1592
+ char * old_qname = get_qf_name (sb , sbi , qtype );
1581
1593
1582
- if (sb_any_quota_loaded (sb ) &&
1583
- sbi -> s_qf_names [qtype ]) {
1594
+ if (sb_any_quota_loaded (sb ) && old_qname ) {
1584
1595
ext4_msg (sb , KERN_ERR , "Cannot change journaled quota options"
1585
1596
" when quota turned on" );
1586
1597
return -1 ;
1587
1598
}
1588
- kfree (sbi -> s_qf_names [qtype ]);
1589
- sbi -> s_qf_names [qtype ] = NULL ;
1599
+ rcu_assign_pointer (sbi -> s_qf_names [qtype ], NULL );
1600
+ synchronize_rcu ();
1601
+ kfree (old_qname );
1590
1602
return 1 ;
1591
1603
}
1592
1604
#endif
@@ -1961,7 +1973,7 @@ static int parse_options(char *options, struct super_block *sb,
1961
1973
int is_remount )
1962
1974
{
1963
1975
struct ext4_sb_info * sbi = EXT4_SB (sb );
1964
- char * p ;
1976
+ char * p , __maybe_unused * usr_qf_name , __maybe_unused * grp_qf_name ;
1965
1977
substring_t args [MAX_OPT_ARGS ];
1966
1978
int token ;
1967
1979
@@ -1992,11 +2004,13 @@ static int parse_options(char *options, struct super_block *sb,
1992
2004
"Cannot enable project quota enforcement." );
1993
2005
return 0 ;
1994
2006
}
1995
- if (sbi -> s_qf_names [USRQUOTA ] || sbi -> s_qf_names [GRPQUOTA ]) {
1996
- if (test_opt (sb , USRQUOTA ) && sbi -> s_qf_names [USRQUOTA ])
2007
+ usr_qf_name = get_qf_name (sb , sbi , USRQUOTA );
2008
+ grp_qf_name = get_qf_name (sb , sbi , GRPQUOTA );
2009
+ if (usr_qf_name || grp_qf_name ) {
2010
+ if (test_opt (sb , USRQUOTA ) && usr_qf_name )
1997
2011
clear_opt (sb , USRQUOTA );
1998
2012
1999
- if (test_opt (sb , GRPQUOTA ) && sbi -> s_qf_names [ GRPQUOTA ] )
2013
+ if (test_opt (sb , GRPQUOTA ) && grp_qf_name )
2000
2014
clear_opt (sb , GRPQUOTA );
2001
2015
2002
2016
if (test_opt (sb , GRPQUOTA ) || test_opt (sb , USRQUOTA )) {
@@ -2030,6 +2044,7 @@ static inline void ext4_show_quota_options(struct seq_file *seq,
2030
2044
{
2031
2045
#if defined(CONFIG_QUOTA )
2032
2046
struct ext4_sb_info * sbi = EXT4_SB (sb );
2047
+ char * usr_qf_name , * grp_qf_name ;
2033
2048
2034
2049
if (sbi -> s_jquota_fmt ) {
2035
2050
char * fmtname = "" ;
@@ -2048,11 +2063,14 @@ static inline void ext4_show_quota_options(struct seq_file *seq,
2048
2063
seq_printf (seq , ",jqfmt=%s" , fmtname );
2049
2064
}
2050
2065
2051
- if (sbi -> s_qf_names [USRQUOTA ])
2052
- seq_show_option (seq , "usrjquota" , sbi -> s_qf_names [USRQUOTA ]);
2053
-
2054
- if (sbi -> s_qf_names [GRPQUOTA ])
2055
- seq_show_option (seq , "grpjquota" , sbi -> s_qf_names [GRPQUOTA ]);
2066
+ rcu_read_lock ();
2067
+ usr_qf_name = rcu_dereference (sbi -> s_qf_names [USRQUOTA ]);
2068
+ grp_qf_name = rcu_dereference (sbi -> s_qf_names [GRPQUOTA ]);
2069
+ if (usr_qf_name )
2070
+ seq_show_option (seq , "usrjquota" , usr_qf_name );
2071
+ if (grp_qf_name )
2072
+ seq_show_option (seq , "grpjquota" , grp_qf_name );
2073
+ rcu_read_unlock ();
2056
2074
#endif
2057
2075
}
2058
2076
@@ -5104,6 +5122,7 @@ static int ext4_remount(struct super_block *sb, int *flags, char *data)
5104
5122
int err = 0 ;
5105
5123
#ifdef CONFIG_QUOTA
5106
5124
int i , j ;
5125
+ char * to_free [EXT4_MAXQUOTAS ];
5107
5126
#endif
5108
5127
char * orig_data = kstrdup (data , GFP_KERNEL );
5109
5128
@@ -5123,8 +5142,9 @@ static int ext4_remount(struct super_block *sb, int *flags, char *data)
5123
5142
old_opts .s_jquota_fmt = sbi -> s_jquota_fmt ;
5124
5143
for (i = 0 ; i < EXT4_MAXQUOTAS ; i ++ )
5125
5144
if (sbi -> s_qf_names [i ]) {
5126
- old_opts .s_qf_names [i ] = kstrdup (sbi -> s_qf_names [i ],
5127
- GFP_KERNEL );
5145
+ char * qf_name = get_qf_name (sb , sbi , i );
5146
+
5147
+ old_opts .s_qf_names [i ] = kstrdup (qf_name , GFP_KERNEL );
5128
5148
if (!old_opts .s_qf_names [i ]) {
5129
5149
for (j = 0 ; j < i ; j ++ )
5130
5150
kfree (old_opts .s_qf_names [j ]);
@@ -5353,9 +5373,12 @@ static int ext4_remount(struct super_block *sb, int *flags, char *data)
5353
5373
#ifdef CONFIG_QUOTA
5354
5374
sbi -> s_jquota_fmt = old_opts .s_jquota_fmt ;
5355
5375
for (i = 0 ; i < EXT4_MAXQUOTAS ; i ++ ) {
5356
- kfree ( sbi -> s_qf_names [i ]);
5357
- sbi -> s_qf_names [i ] = old_opts .s_qf_names [i ];
5376
+ to_free [i ] = get_qf_name ( sb , sbi , i );
5377
+ rcu_assign_pointer ( sbi -> s_qf_names [i ], old_opts .s_qf_names [i ]) ;
5358
5378
}
5379
+ synchronize_rcu ();
5380
+ for (i = 0 ; i < EXT4_MAXQUOTAS ; i ++ )
5381
+ kfree (to_free [i ]);
5359
5382
#endif
5360
5383
kfree (orig_data );
5361
5384
return err ;
@@ -5546,7 +5569,7 @@ static int ext4_write_info(struct super_block *sb, int type)
5546
5569
*/
5547
5570
static int ext4_quota_on_mount (struct super_block * sb , int type )
5548
5571
{
5549
- return dquot_quota_on_mount (sb , EXT4_SB (sb )-> s_qf_names [ type ] ,
5572
+ return dquot_quota_on_mount (sb , get_qf_name ( sb , EXT4_SB (sb ), type ) ,
5550
5573
EXT4_SB (sb )-> s_jquota_fmt , type );
5551
5574
}
5552
5575
0 commit comments