Whamcloud - gitweb
LU-12335 ldiskfs: fixed size preallocation table
[fs/lustre-release.git] / ldiskfs / kernel_patches / patches / rhel7 / ext4-projid-quotas.patch
1 Index: linux-stage/fs/ext4/inode.c
2 ===================================================================
3 --- linux-stage.orig/fs/ext4/inode.c
4 +++ linux-stage/fs/ext4/inode.c
5 @@ -4195,7 +4195,10 @@ static inline void ext4_iget_extra_inode
6  
7  int ext4_get_projid(struct inode *inode, kprojid_t *projid)
8  {
9 -       if (!EXT4_HAS_RO_COMPAT_FEATURE(inode->i_sb, EXT4_FEATURE_RO_COMPAT_PROJECT))
10 +       struct ext4_super_block *sbi = EXT4_SB(inode->i_sb)->s_es;
11 +
12 +       if (!EXT4_HAS_RO_COMPAT_FEATURE(inode->i_sb, EXT4_FEATURE_RO_COMPAT_PROJECT) &&
13 +           !sbi->s_prj_quota_inum)
14                 return -EOPNOTSUPP;
15         *projid = EXT4_I(inode)->i_projid;
16         return 0;
17 Index: linux-stage/fs/ext4/super.c
18 ===================================================================
19 --- linux-stage.orig/fs/ext4/super.c
20 +++ linux-stage/fs/ext4/super.c
21 @@ -1085,8 +1085,8 @@ static int bdev_try_to_free_page(struct
22  }
23  
24  #ifdef CONFIG_QUOTA
25 -#define QTYPE2NAME(t) ((t) == USRQUOTA ? "user" : "group")
26 -#define QTYPE2MOPT(on, t) ((t) == USRQUOTA?((on)##USRJQUOTA):((on)##GRPJQUOTA))
27 +static char *quotatypes[] = INITQFNAMES;
28 +#define QTYPE2NAME(t) (quotatypes[t])
29  
30  static int ext4_write_dquot(struct dquot *dquot);
31  static int ext4_acquire_dquot(struct dquot *dquot);
32 @@ -5234,6 +5234,48 @@ restore_opts:
33         return err;
34  }
35  
36 +#ifdef CONFIG_QUOTA
37 +static int ext4_statfs_project(struct super_block *sb,
38 +                              kprojid_t projid, struct kstatfs *buf)
39 +{
40 +       struct kqid qid;
41 +       struct dquot *dquot;
42 +       u64 limit;
43 +       u64 curblock;
44 +
45 +       qid = make_kqid_projid(projid);
46 +       dquot = dqget(sb, qid);
47 +       if (IS_ERR(dquot))
48 +               return PTR_ERR(dquot);
49 +       spin_lock(&dq_data_lock);
50 +
51 +       limit = dquot->dq_dqb.dqb_bsoftlimit ?
52 +               dquot->dq_dqb.dqb_bsoftlimit :
53 +               dquot->dq_dqb.dqb_bhardlimit;
54 +       if (limit && buf->f_blocks * buf->f_bsize > limit) {
55 +               curblock = dquot->dq_dqb.dqb_curspace / buf->f_bsize;
56 +               buf->f_blocks = limit / buf->f_bsize;
57 +               buf->f_bfree = buf->f_bavail =
58 +                       (buf->f_blocks > curblock) ?
59 +                        (buf->f_blocks - curblock) : 0;
60 +       }
61 +
62 +       limit = dquot->dq_dqb.dqb_isoftlimit ?
63 +               dquot->dq_dqb.dqb_isoftlimit :
64 +               dquot->dq_dqb.dqb_ihardlimit;
65 +       if (limit && buf->f_files > limit) {
66 +               buf->f_files = limit;
67 +               buf->f_ffree =
68 +                       (buf->f_files > dquot->dq_dqb.dqb_curinodes) ?
69 +                        (buf->f_files - dquot->dq_dqb.dqb_curinodes) : 0;
70 +       }
71 +
72 +       spin_unlock(&dq_data_lock);
73 +       dqput(dquot);
74 +       return 0;
75 +}
76 +#endif
77 +
78  static int ext4_statfs(struct dentry *dentry, struct kstatfs *buf)
79  {
80         struct super_block *sb = dentry->d_sb;
81 @@ -5242,6 +5284,7 @@ static int ext4_statfs(struct dentry *de
82         ext4_fsblk_t overhead = 0, resv_blocks;
83         u64 fsid;
84         s64 bfree;
85 +       struct inode *inode = dentry->d_inode;
86         resv_blocks = EXT4_C2B(sbi, atomic64_read(&sbi->s_resv_clusters));
87  
88         if (!test_opt(sb, MINIX_DF))
89 @@ -5266,6 +5309,11 @@ static int ext4_statfs(struct dentry *de
90         buf->f_fsid.val[0] = fsid & 0xFFFFFFFFUL;
91         buf->f_fsid.val[1] = (fsid >> 32) & 0xFFFFFFFFUL;
92  
93 +#ifdef CONFIG_QUOTA
94 +       if (ext4_test_inode_flag(inode, EXT4_INODE_PROJINHERIT) &&
95 +           sb_has_quota_limits_enabled(sb, PRJQUOTA))
96 +               ext4_statfs_project(sb, EXT4_I(inode)->i_projid, buf);
97 +#endif
98         return 0;
99  }
100  
101 @@ -5448,7 +5496,8 @@ static int ext4_quota_enable(struct supe
102         struct inode *qf_inode;
103         unsigned long qf_inums[EXT4_MAXQUOTAS] = {
104                 le32_to_cpu(EXT4_SB(sb)->s_es->s_usr_quota_inum),
105 -               le32_to_cpu(EXT4_SB(sb)->s_es->s_grp_quota_inum)
106 +               le32_to_cpu(EXT4_SB(sb)->s_es->s_grp_quota_inum),
107 +               le32_to_cpu(EXT4_SB(sb)->s_es->s_prj_quota_inum)
108         };
109  
110         BUG_ON(!EXT4_HAS_RO_COMPAT_FEATURE(sb, EXT4_FEATURE_RO_COMPAT_QUOTA));
111 @@ -5479,7 +5528,8 @@ static int ext4_enable_quotas(struct sup
112         int type, err = 0;
113         unsigned long qf_inums[EXT4_MAXQUOTAS] = {
114                 le32_to_cpu(EXT4_SB(sb)->s_es->s_usr_quota_inum),
115 -               le32_to_cpu(EXT4_SB(sb)->s_es->s_grp_quota_inum)
116 +               le32_to_cpu(EXT4_SB(sb)->s_es->s_grp_quota_inum),
117 +               le32_to_cpu(EXT4_SB(sb)->s_es->s_prj_quota_inum)
118         };
119  
120         sb_dqopt(sb)->flags |= DQUOT_QUOTA_SYS_FILE;
121 Index: linux-stage/fs/ext4/ext4.h
122 ===================================================================
123 --- linux-stage.orig/fs/ext4/ext4.h
124 +++ linux-stage/fs/ext4/ext4.h
125 @@ -1138,7 +1138,7 @@ extern void ext4_set_bits(void *bm, int
126  #define EXT4_CRC32C_CHKSUM             1
127  
128  /* Number of quota types we support */
129 -#define EXT4_MAXQUOTAS 2
130 +#define EXT4_MAXQUOTAS 3
131  
132  /*
133   * Structure of the super block
134 @@ -1253,7 +1253,9 @@ struct ext4_super_block {
135         __le32  s_grp_quota_inum;       /* inode for tracking group quota */
136         __le32  s_overhead_clusters;    /* overhead blocks/clusters in fs */
137         __le32  s_backup_bgs[2];        /* groups with sparse_super2 SBs */
138 -       __le32  s_reserved[106];        /* Padding to the end of the block */
139 +       __le32  s_padding[6];           /* reserved for upstream usage */
140 +       __le32  s_prj_quota_inum;       /* inode for tracking project quota */
141 +       __le32  s_reserved[99]; /* Padding to the end of the block */
142         __le32  s_checksum;             /* crc32c(superblock) */
143  };
144