1 Index: linux-stage/fs/ext4/ext4.h
2 ===================================================================
3 --- linux-stage.orig/fs/ext4/ext4.h
4 +++ linux-stage/fs/ext4/ext4.h
5 @@ -392,16 +392,18 @@ struct flex_groups {
6 #define EXT4_EA_INODE_FL 0x00200000 /* Inode used for large EA */
7 #define EXT4_EOFBLOCKS_FL 0x00400000 /* Blocks allocated beyond EOF */
8 #define EXT4_INLINE_DATA_FL 0x10000000 /* Inode has inline data. */
9 +#define EXT4_PROJINHERIT_FL 0x20000000 /* Create with parents projid */
10 #define EXT4_RESERVED_FL 0x80000000 /* reserved for ext4 lib */
12 -#define EXT4_FL_USER_VISIBLE 0x004BDFFF /* User visible flags */
13 -#define EXT4_FL_USER_MODIFIABLE 0x004380FF /* User modifiable flags */
14 +#define EXT4_FL_USER_VISIBLE 0x304BDFFF /* User visible flags */
15 +#define EXT4_FL_USER_MODIFIABLE 0x204380FF /* User modifiable flags */
17 /* Flags that should be inherited by new inodes from their parent. */
18 #define EXT4_FL_INHERITED (EXT4_SECRM_FL | EXT4_UNRM_FL | EXT4_COMPR_FL |\
19 EXT4_SYNC_FL | EXT4_NODUMP_FL | EXT4_NOATIME_FL |\
20 EXT4_NOCOMPR_FL | EXT4_JOURNAL_DATA_FL |\
21 - EXT4_NOTAIL_FL | EXT4_DIRSYNC_FL)
22 + EXT4_NOTAIL_FL | EXT4_DIRSYNC_FL |\
23 + EXT4_PROJINHERIT_FL)
25 /* Flags that are appropriate for regular files (all but dir-specific ones). */
26 #define EXT4_REG_FLMASK (~(EXT4_DIRSYNC_FL | EXT4_TOPDIR_FL))
27 @@ -449,6 +451,7 @@ enum {
28 EXT4_INODE_EA_INODE = 21, /* Inode used for large EA */
29 EXT4_INODE_EOFBLOCKS = 22, /* Blocks allocated beyond EOF */
30 EXT4_INODE_INLINE_DATA = 28, /* Data in inode. */
31 + EXT4_INODE_PROJINHERIT = 29, /* Create with parents projid */
32 EXT4_INODE_RESERVED = 31, /* reserved for ext4 lib */
35 @@ -698,6 +701,7 @@ struct ext4_inode {
36 __le32 i_crtime; /* File Creation time */
37 __le32 i_crtime_extra; /* extra FileCreationtime (nsec << 2 | epoch) */
38 __le32 i_version_hi; /* high 32 bits for 64-bit version */
39 + __le32 i_projid; /* Project ID */
43 @@ -953,6 +957,7 @@ struct ext4_inode_info {
45 /* Precomputed uuid+inum+igen checksum for seeding inode checksums */
51 @@ -1555,6 +1560,7 @@ static inline void ext4_clear_state_flag
52 * GDT_CSUM bits are mutually exclusive.
54 #define EXT4_FEATURE_RO_COMPAT_METADATA_CSUM 0x0400
55 +#define EXT4_FEATURE_RO_COMPAT_PROJECT 0x2000
57 #define EXT4_FEATURE_INCOMPAT_COMPRESSION 0x0001
58 #define EXT4_FEATURE_INCOMPAT_FILETYPE 0x0002
59 @@ -1607,7 +1613,8 @@ static inline void ext4_clear_state_flag
60 EXT4_FEATURE_RO_COMPAT_HUGE_FILE |\
61 EXT4_FEATURE_RO_COMPAT_BIGALLOC |\
62 EXT4_FEATURE_RO_COMPAT_METADATA_CSUM|\
63 - EXT4_FEATURE_RO_COMPAT_QUOTA)
64 + EXT4_FEATURE_RO_COMPAT_QUOTA |\
65 + EXT4_FEATURE_RO_COMPAT_PROJECT)
68 * Default values for user and/or group using reserved blocks
69 @@ -1615,6 +1622,11 @@ static inline void ext4_clear_state_flag
70 #define EXT4_DEF_RESUID 0
71 #define EXT4_DEF_RESGID 0
74 + * Default project ID
76 +#define EXT4_DEF_PROJID 0
78 #define EXT4_DEF_INODE_READAHEAD_BLKS 32
81 @@ -2303,6 +2315,7 @@ extern int ext4_zero_partial_blocks(hand
82 loff_t lstart, loff_t lend);
83 extern int ext4_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf);
84 extern qsize_t *ext4_get_reserved_space(struct inode *inode);
85 +extern int ext4_get_projid(struct inode *inode, kprojid_t *projid);
86 extern void ext4_da_update_reserve_space(struct inode *inode,
87 int used, int quota_claim);
89 Index: linux-stage/fs/ext4/ialloc.c
90 ===================================================================
91 --- linux-stage.orig/fs/ext4/ialloc.c
92 +++ linux-stage/fs/ext4/ialloc.c
93 @@ -732,6 +732,11 @@ struct inode *__ext4_new_inode(handle_t
94 inode->i_gid = dir->i_gid;
96 inode_init_owner(inode, dir, mode);
97 + if (EXT4_HAS_RO_COMPAT_FEATURE(sb, EXT4_FEATURE_RO_COMPAT_PROJECT) &&
98 + ext4_test_inode_flag(dir, EXT4_INODE_PROJINHERIT))
99 + ei->i_projid = EXT4_I(dir)->i_projid;
101 + ei->i_projid = make_kprojid(&init_user_ns, EXT4_DEF_PROJID);
102 dquot_initialize(inode);
105 Index: linux-stage/fs/ext4/inode.c
106 ===================================================================
107 --- linux-stage.orig/fs/ext4/inode.c
108 +++ linux-stage/fs/ext4/inode.c
109 @@ -3937,6 +3937,14 @@ static inline void ext4_iget_extra_inode
110 EXT4_I(inode)->i_inline_off = 0;
113 +int ext4_get_projid(struct inode *inode, kprojid_t *projid)
115 + if (!EXT4_HAS_RO_COMPAT_FEATURE(inode->i_sb, EXT4_FEATURE_RO_COMPAT_PROJECT))
116 + return -EOPNOTSUPP;
117 + *projid = EXT4_I(inode)->i_projid;
121 struct inode *ext4_iget(struct super_block *sb, unsigned long ino)
123 struct ext4_iloc iloc;
124 @@ -3948,6 +3956,7 @@ struct inode *ext4_iget(struct super_blo
130 inode = iget_locked(sb, ino);
132 @@ -3997,12 +4006,20 @@ struct inode *ext4_iget(struct super_blo
133 inode->i_mode = le16_to_cpu(raw_inode->i_mode);
134 i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
135 i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
136 + if (EXT4_HAS_RO_COMPAT_FEATURE(sb, EXT4_FEATURE_RO_COMPAT_PROJECT) &&
137 + EXT4_INODE_SIZE(sb) > EXT4_GOOD_OLD_INODE_SIZE &&
138 + EXT4_FITS_IN_INODE(raw_inode, ei, i_projid))
139 + i_projid = (projid_t)le32_to_cpu(raw_inode->i_projid);
141 + i_projid = EXT4_DEF_PROJID;
143 if (!(test_opt(inode->i_sb, NO_UID32))) {
144 i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
145 i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
147 i_uid_write(inode, i_uid);
148 i_gid_write(inode, i_gid);
149 + ei->i_projid = make_kprojid(&init_user_ns, i_projid);;
150 set_nlink(inode, le16_to_cpu(raw_inode->i_links_count));
152 ext4_clear_state_flags(ei); /* Only relevant on 32-bit archs */
153 @@ -4233,6 +4250,7 @@ static int ext4_do_update_inode(handle_t
154 int need_datasync = 0, set_large_file = 0;
159 spin_lock(&ei->i_raw_lock);
161 @@ -4245,6 +4263,7 @@ static int ext4_do_update_inode(handle_t
162 raw_inode->i_mode = cpu_to_le16(inode->i_mode);
163 i_uid = i_uid_read(inode);
164 i_gid = i_gid_read(inode);
165 + i_projid = from_kprojid(&init_user_ns, ei->i_projid);
166 if (!(test_opt(inode->i_sb, NO_UID32))) {
167 raw_inode->i_uid_low = cpu_to_le16(low_16_bits(i_uid));
168 raw_inode->i_gid_low = cpu_to_le16(low_16_bits(i_gid));
169 @@ -4324,6 +4343,14 @@ static int ext4_do_update_inode(handle_t
173 + BUG_ON(!EXT4_HAS_RO_COMPAT_FEATURE(inode->i_sb,
174 + EXT4_FEATURE_RO_COMPAT_PROJECT) &&
175 + i_projid != EXT4_DEF_PROJID);
177 + if (EXT4_INODE_SIZE(inode->i_sb) > EXT4_GOOD_OLD_INODE_SIZE &&
178 + EXT4_FITS_IN_INODE(raw_inode, ei, i_projid))
179 + raw_inode->i_projid = cpu_to_le32(i_projid);
181 ext4_inode_csum_set(inode, raw_inode, ei);
183 spin_unlock(&ei->i_raw_lock);
184 Index: linux-stage/fs/ext4/namei.c
185 ===================================================================
186 --- linux-stage.orig/fs/ext4/namei.c
187 +++ linux-stage/fs/ext4/namei.c
188 @@ -3650,6 +3650,11 @@ static int ext4_link(struct dentry *old_
189 if (inode->i_nlink >= EXT4_LINK_MAX)
192 + if ((ext4_test_inode_flag(dir, EXT4_INODE_PROJINHERIT)) &&
193 + (!projid_eq(EXT4_I(dir)->i_projid,
194 + EXT4_I(old_dentry->d_inode)->i_projid)))
197 dquot_initialize(dir);
200 @@ -3924,6 +3929,11 @@ static int ext4_rename(struct inode *old
204 + if ((ext4_test_inode_flag(new_dir, EXT4_INODE_PROJINHERIT)) &&
205 + (!projid_eq(EXT4_I(new_dir)->i_projid,
206 + EXT4_I(old_dentry->d_inode)->i_projid)))
209 dquot_initialize(old.dir);
210 dquot_initialize(new.dir);
212 @@ -4108,6 +4118,14 @@ static int ext4_cross_rename(struct inod
216 + if ((ext4_test_inode_flag(new_dir, EXT4_INODE_PROJINHERIT) &&
217 + !projid_eq(EXT4_I(new_dir)->i_projid,
218 + EXT4_I(old_dentry->d_inode)->i_projid)) ||
219 + (ext4_test_inode_flag(old_dir, EXT4_INODE_PROJINHERIT) &&
220 + !projid_eq(EXT4_I(old_dir)->i_projid,
221 + EXT4_I(new_dentry->d_inode)->i_projid)))
224 dquot_initialize(old.dir);
225 dquot_initialize(new.dir);
227 Index: linux-stage/fs/ext4/super.c
228 ===================================================================
229 --- linux-stage.orig/fs/ext4/super.c
230 +++ linux-stage/fs/ext4/super.c
231 @@ -1109,6 +1109,9 @@ static const struct dquot_operations ext
232 .write_info = ext4_write_info,
233 .alloc_dquot = dquot_alloc,
234 .destroy_dquot = dquot_destroy,
235 +#ifdef HAVE_PROJECT_QUOTA
236 + .get_projid = ext4_get_projid,
240 static const struct quotactl_ops ext4_qctl_operations = {