Skip to content

Commit c79d967

Browse files
Christoph Hellwigjankara
authored andcommitted
quota: move remount handling into the filesystem
Currently do_remount_sb calls into the dquot code to tell it about going from rw to ro and ro to rw. Move this code into the filesystem to not depend on the dquot code in the VFS - note ocfs2 already ignores these calls and handles remount by itself. This gets rid of overloading the quotactl calls and allows to unify the VFS and XFS codepaths in that area later. Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Jan Kara <jack@suse.cz>
1 parent eea7feb commit c79d967

8 files changed

Lines changed: 84 additions & 14 deletions

File tree

‎fs/ext2/super.c‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1241,13 +1241,22 @@ static int ext2_remount (struct super_block * sb, int * flags, char * data)
12411241
spin_unlock(&sbi->s_lock);
12421242
return 0;
12431243
}
1244+
12441245
/*
12451246
* OK, we are remounting a valid rw partition rdonly, so set
12461247
* the rdonly flag and then mark the partition as valid again.
12471248
*/
12481249
es->s_state = cpu_to_le16(sbi->s_mount_state);
12491250
es->s_mtime = cpu_to_le32(get_seconds());
12501251
spin_unlock(&sbi->s_lock);
1252+
1253+
err = vfs_dq_off(sb, 1);
1254+
if (err < 0 && err != -ENOSYS) {
1255+
err = -EBUSY;
1256+
spin_lock(&sbi->s_lock);
1257+
goto restore_opts;
1258+
}
1259+
12511260
ext2_sync_super(sb, es, 1);
12521261
} else {
12531262
__le32 ret = EXT2_HAS_RO_COMPAT_FEATURE(sb,
@@ -1269,8 +1278,12 @@ static int ext2_remount (struct super_block * sb, int * flags, char * data)
12691278
if (!ext2_setup_super (sb, es, 0))
12701279
sb->s_flags &= ~MS_RDONLY;
12711280
spin_unlock(&sbi->s_lock);
1281+
12721282
ext2_write_super(sb);
1283+
1284+
vfs_dq_quota_on_remount(sb);
12731285
}
1286+
12741287
return 0;
12751288
restore_opts:
12761289
sbi->s_mount_opt = old_opts.s_mount_opt;

‎fs/ext3/super.c‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2551,6 +2551,7 @@ static int ext3_remount (struct super_block * sb, int * flags, char * data)
25512551
ext3_fsblk_t n_blocks_count = 0;
25522552
unsigned long old_sb_flags;
25532553
struct ext3_mount_options old_opts;
2554+
int enable_quota = 0;
25542555
int err;
25552556
#ifdef CONFIG_QUOTA
25562557
int i;
@@ -2597,6 +2598,12 @@ static int ext3_remount (struct super_block * sb, int * flags, char * data)
25972598
}
25982599

25992600
if (*flags & MS_RDONLY) {
2601+
err = vfs_dq_off(sb, 1);
2602+
if (err < 0 && err != -ENOSYS) {
2603+
err = -EBUSY;
2604+
goto restore_opts;
2605+
}
2606+
26002607
/*
26012608
* First of all, the unconditional stuff we have to do
26022609
* to disable replay of the journal when we next remount
@@ -2651,6 +2658,7 @@ static int ext3_remount (struct super_block * sb, int * flags, char * data)
26512658
goto restore_opts;
26522659
if (!ext3_setup_super (sb, es, 0))
26532660
sb->s_flags &= ~MS_RDONLY;
2661+
enable_quota = 1;
26542662
}
26552663
}
26562664
#ifdef CONFIG_QUOTA
@@ -2662,6 +2670,9 @@ static int ext3_remount (struct super_block * sb, int * flags, char * data)
26622670
#endif
26632671
unlock_super(sb);
26642672
unlock_kernel();
2673+
2674+
if (enable_quota)
2675+
vfs_dq_quota_on_remount(sb);
26652676
return 0;
26662677
restore_opts:
26672678
sb->s_flags = old_sb_flags;

‎fs/ext4/super.c‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3574,6 +3574,7 @@ static int ext4_remount(struct super_block *sb, int *flags, char *data)
35743574
ext4_fsblk_t n_blocks_count = 0;
35753575
unsigned long old_sb_flags;
35763576
struct ext4_mount_options old_opts;
3577+
int enable_quota = 0;
35773578
ext4_group_t g;
35783579
unsigned int journal_ioprio = DEFAULT_JOURNAL_IOPRIO;
35793580
int err;
@@ -3630,6 +3631,12 @@ static int ext4_remount(struct super_block *sb, int *flags, char *data)
36303631
}
36313632

36323633
if (*flags & MS_RDONLY) {
3634+
err = vfs_dq_off(sb, 1);
3635+
if (err < 0 && err != -ENOSYS) {
3636+
err = -EBUSY;
3637+
goto restore_opts;
3638+
}
3639+
36333640
/*
36343641
* First of all, the unconditional stuff we have to do
36353642
* to disable replay of the journal when we next remount
@@ -3698,6 +3705,7 @@ static int ext4_remount(struct super_block *sb, int *flags, char *data)
36983705
goto restore_opts;
36993706
if (!ext4_setup_super(sb, es, 0))
37003707
sb->s_flags &= ~MS_RDONLY;
3708+
enable_quota = 1;
37013709
}
37023710
}
37033711
ext4_setup_system_zone(sb);
@@ -3713,6 +3721,8 @@ static int ext4_remount(struct super_block *sb, int *flags, char *data)
37133721
#endif
37143722
unlock_super(sb);
37153723
unlock_kernel();
3724+
if (enable_quota)
3725+
vfs_dq_quota_on_remount(sb);
37163726
return 0;
37173727

37183728
restore_opts:

‎fs/jfs/super.c‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,10 +396,20 @@ static int jfs_remount(struct super_block *sb, int *flags, char *data)
396396

397397
JFS_SBI(sb)->flag = flag;
398398
ret = jfs_mount_rw(sb, 1);
399+
400+
/* mark the fs r/w for quota activity */
401+
sb->s_flags &= ~MS_RDONLY;
402+
399403
unlock_kernel();
404+
vfs_dq_quota_on_remount(sb);
400405
return ret;
401406
}
402407
if ((!(sb->s_flags & MS_RDONLY)) && (*flags & MS_RDONLY)) {
408+
rc = vfs_dq_off(sb, 1);
409+
if (rc < 0 && rc != -ENOSYS) {
410+
unlock_kernel();
411+
return -EBUSY;
412+
}
403413
rc = jfs_umount_rw(sb);
404414
JFS_SBI(sb)->flag = flag;
405415
unlock_kernel();

‎fs/reiserfs/super.c‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1242,6 +1242,13 @@ static int reiserfs_remount(struct super_block *s, int *mount_flags, char *arg)
12421242
if (s->s_flags & MS_RDONLY)
12431243
/* it is read-only already */
12441244
goto out_ok;
1245+
1246+
err = vfs_dq_off(s, 1);
1247+
if (err < 0 && err != -ENOSYS) {
1248+
err = -EBUSY;
1249+
goto out_err;
1250+
}
1251+
12451252
/* try to remount file system with read-only permissions */
12461253
if (sb_umount_state(rs) == REISERFS_VALID_FS
12471254
|| REISERFS_SB(s)->s_mount_state != REISERFS_VALID_FS) {
@@ -1295,6 +1302,7 @@ static int reiserfs_remount(struct super_block *s, int *mount_flags, char *arg)
12951302
s->s_dirt = 0;
12961303

12971304
if (!(*mount_flags & MS_RDONLY)) {
1305+
vfs_dq_quota_on_remount(s);
12981306
finish_unfinished(s);
12991307
reiserfs_xattr_init(s, *mount_flags);
13001308
}

‎fs/super.c‎

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ struct super_block *user_get_super(dev_t dev)
524524
int do_remount_sb(struct super_block *sb, int flags, void *data, int force)
525525
{
526526
int retval;
527-
int remount_rw, remount_ro;
527+
int remount_ro;
528528

529529
if (sb->s_frozen != SB_UNFROZEN)
530530
return -EBUSY;
@@ -540,7 +540,6 @@ int do_remount_sb(struct super_block *sb, int flags, void *data, int force)
540540
sync_filesystem(sb);
541541

542542
remount_ro = (flags & MS_RDONLY) && !(sb->s_flags & MS_RDONLY);
543-
remount_rw = !(flags & MS_RDONLY) && (sb->s_flags & MS_RDONLY);
544543

545544
/* If we are remounting RDONLY and current sb is read/write,
546545
make sure there are no rw files opened */
@@ -549,9 +548,6 @@ int do_remount_sb(struct super_block *sb, int flags, void *data, int force)
549548
mark_files_ro(sb);
550549
else if (!fs_may_remount_ro(sb))
551550
return -EBUSY;
552-
retval = vfs_dq_off(sb, 1);
553-
if (retval < 0 && retval != -ENOSYS)
554-
return -EBUSY;
555551
}
556552

557553
if (sb->s_op->remount_fs) {
@@ -560,8 +556,7 @@ int do_remount_sb(struct super_block *sb, int flags, void *data, int force)
560556
return retval;
561557
}
562558
sb->s_flags = (sb->s_flags & ~MS_RMT_MASK) | (flags & MS_RMT_MASK);
563-
if (remount_rw)
564-
vfs_dq_quota_on_remount(sb);
559+
565560
/*
566561
* Some filesystems modify their metadata via some other path than the
567562
* bdev buffer cache (eg. use a private mapping, or directories in

‎fs/udf/super.c‎

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
#include <linux/vmalloc.h>
5555
#include <linux/errno.h>
5656
#include <linux/mount.h>
57+
#include <linux/quotaops.h>
5758
#include <linux/seq_file.h>
5859
#include <linux/bitmap.h>
5960
#include <linux/crc-itu-t.h>
@@ -557,6 +558,7 @@ static int udf_remount_fs(struct super_block *sb, int *flags, char *options)
557558
{
558559
struct udf_options uopt;
559560
struct udf_sb_info *sbi = UDF_SB(sb);
561+
int error = 0;
560562

561563
uopt.flags = sbi->s_flags;
562564
uopt.uid = sbi->s_uid;
@@ -582,17 +584,26 @@ static int udf_remount_fs(struct super_block *sb, int *flags, char *options)
582584
*flags |= MS_RDONLY;
583585
}
584586

585-
if ((*flags & MS_RDONLY) == (sb->s_flags & MS_RDONLY)) {
586-
unlock_kernel();
587-
return 0;
588-
}
589-
if (*flags & MS_RDONLY)
587+
if ((*flags & MS_RDONLY) == (sb->s_flags & MS_RDONLY))
588+
goto out_unlock;
589+
590+
if (*flags & MS_RDONLY) {
590591
udf_close_lvid(sb);
591-
else
592+
593+
error = vfs_dq_off(sb, 1);
594+
if (error < 0 && error != -ENOSYS)
595+
error = -EBUSY;
596+
} else {
592597
udf_open_lvid(sb);
593598

599+
/* mark the fs r/w for quota activity */
600+
sb->s_flags &= ~MS_RDONLY;
601+
vfs_dq_quota_on_remount(sb);
602+
}
603+
604+
out_unlock:
594605
unlock_kernel();
595-
return 0;
606+
return error;
596607
}
597608

598609
/* Check Volume Structure Descriptors (ECMA 167 2/9.1) */

‎fs/ufs/super.c‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1248,7 +1248,9 @@ static int ufs_remount (struct super_block *sb, int *mount_flags, char *data)
12481248
struct ufs_super_block_first * usb1;
12491249
struct ufs_super_block_third * usb3;
12501250
unsigned new_mount_opt, ufstype;
1251+
int enable_quota = 0;
12511252
unsigned flags;
1253+
int err;
12521254

12531255
lock_kernel();
12541256
lock_super(sb);
@@ -1289,6 +1291,13 @@ static int ufs_remount (struct super_block *sb, int *mount_flags, char *data)
12891291
* fs was mouted as rw, remounting ro
12901292
*/
12911293
if (*mount_flags & MS_RDONLY) {
1294+
err = vfs_dq_off(sb, 1);
1295+
if (err < 0 && err != -ENOSYS) {
1296+
unlock_super(sb);
1297+
unlock_kernel();
1298+
return -EBUSY;
1299+
}
1300+
12921301
ufs_put_super_internal(sb);
12931302
usb1->fs_time = cpu_to_fs32(sb, get_seconds());
12941303
if ((flags & UFS_ST_MASK) == UFS_ST_SUN
@@ -1327,11 +1336,14 @@ static int ufs_remount (struct super_block *sb, int *mount_flags, char *data)
13271336
return -EPERM;
13281337
}
13291338
sb->s_flags &= ~MS_RDONLY;
1339+
enable_quota = 1;
13301340
#endif
13311341
}
13321342
UFS_SB(sb)->s_mount_opt = new_mount_opt;
13331343
unlock_super(sb);
13341344
unlock_kernel();
1345+
if (enable_quota)
1346+
vfs_dq_quota_on_remount(sb);
13351347
return 0;
13361348
}
13371349

0 commit comments

Comments
 (0)