Skip to content

Commit 57c32ea

Browse files
cgxu519tytso
authored andcommitted
ext4: choose hardlimit when softlimit is larger than hardlimit in ext4_statfs_project()
Setting softlimit larger than hardlimit seems meaningless for disk quota but currently it is allowed. In this case, there may be a bit of comfusion for users when they run df comamnd to directory which has project quota. For example, we set 20M softlimit and 10M hardlimit of block usage limit for project quota of test_dir(project id 123). [root@hades mnt_ext4]# repquota -P -a *** Report for project quotas on device /dev/loop0 Block grace time: 7days; Inode grace time: 7days Block limits File limits Project used soft hard grace used soft hard grace ---------------------------------------------------------------------- 0 -- 13 0 0 2 0 0 123 -- 10237 20480 10240 5 200 100 The result of df command as below: [root@hades mnt_ext4]# df -h test_dir Filesystem Size Used Avail Use% Mounted on /dev/loop0 20M 10M 10M 50% /home/cgxu/test/mnt_ext4 Even though it looks like there is another 10M free space to use, if we write new data to diretory test_dir(inherit project id), the write will fail with errno(-EDQUOT). After this patch, the df result looks like below. [root@hades mnt_ext4]# df -h test_dir Filesystem Size Used Avail Use% Mounted on /dev/loop0 10M 10M 3.0K 100% /home/cgxu/test/mnt_ext4 Signed-off-by: Chengguang Xu <[email protected]> Reviewed-by: Jan Kara <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Theodore Ts'o <[email protected]>
1 parent ec772f0 commit 57c32ea

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

fs/ext4/super.c

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5585,9 +5585,15 @@ static int ext4_statfs_project(struct super_block *sb,
55855585
return PTR_ERR(dquot);
55865586
spin_lock(&dquot->dq_dqb_lock);
55875587

5588-
limit = (dquot->dq_dqb.dqb_bsoftlimit ?
5589-
dquot->dq_dqb.dqb_bsoftlimit :
5590-
dquot->dq_dqb.dqb_bhardlimit) >> sb->s_blocksize_bits;
5588+
limit = 0;
5589+
if (dquot->dq_dqb.dqb_bsoftlimit &&
5590+
(!limit || dquot->dq_dqb.dqb_bsoftlimit < limit))
5591+
limit = dquot->dq_dqb.dqb_bsoftlimit;
5592+
if (dquot->dq_dqb.dqb_bhardlimit &&
5593+
(!limit || dquot->dq_dqb.dqb_bhardlimit < limit))
5594+
limit = dquot->dq_dqb.dqb_bhardlimit;
5595+
limit >>= sb->s_blocksize_bits;
5596+
55915597
if (limit && buf->f_blocks > limit) {
55925598
curblock = (dquot->dq_dqb.dqb_curspace +
55935599
dquot->dq_dqb.dqb_rsvspace) >> sb->s_blocksize_bits;
@@ -5597,9 +5603,14 @@ static int ext4_statfs_project(struct super_block *sb,
55975603
(buf->f_blocks - curblock) : 0;
55985604
}
55995605

5600-
limit = dquot->dq_dqb.dqb_isoftlimit ?
5601-
dquot->dq_dqb.dqb_isoftlimit :
5602-
dquot->dq_dqb.dqb_ihardlimit;
5606+
limit = 0;
5607+
if (dquot->dq_dqb.dqb_isoftlimit &&
5608+
(!limit || dquot->dq_dqb.dqb_isoftlimit < limit))
5609+
limit = dquot->dq_dqb.dqb_isoftlimit;
5610+
if (dquot->dq_dqb.dqb_ihardlimit &&
5611+
(!limit || dquot->dq_dqb.dqb_ihardlimit < limit))
5612+
limit = dquot->dq_dqb.dqb_ihardlimit;
5613+
56035614
if (limit && buf->f_files > limit) {
56045615
buf->f_files = limit;
56055616
buf->f_ffree =

0 commit comments

Comments
 (0)