1 diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
2 index 9308f35..eeb3d05 100644
5 @@ -377,16 +377,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 @@ -434,6 +436,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 @@ -685,6 +688,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 @@ -942,6 +946,7 @@ struct ext4_inode_info {
45 /* Precomputed uuid+inum+igen checksum for seeding inode checksums */
51 @@ -1531,6 +1536,7 @@ static inline void ext4_clear_state_flags(struct ext4_inode_info *ei)
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 @@ -1580,7 +1586,8 @@ static inline void ext4_clear_state_flags(struct ext4_inode_info *ei)
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 @@ -1588,6 +1595,11 @@ static inline void ext4_clear_state_flags(struct ext4_inode_info *ei)
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 @@ -2145,6 +2157,7 @@ extern int ext4_zero_partial_blocks(handle_t *handle, struct inode *inode,
82 extern int ext4_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf);
83 extern int ext4_filemap_fault(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);
88 extern int ext4_issue_zeroout(struct inode *inode, ext4_lblk_t lblk,
89 diff --git a/fs/ext4/ialloc.c b/fs/ext4/ialloc.c
90 index ac644c3..10ca9dd 100644
91 --- a/fs/ext4/ialloc.c
92 +++ b/fs/ext4/ialloc.c
93 @@ -756,6 +756,11 @@ struct inode *__ext4_new_inode(handle_t *handle, struct inode *dir,
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 diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
106 index f094263..34877ac 100644
107 --- a/fs/ext4/inode.c
108 +++ b/fs/ext4/inode.c
109 @@ -4099,6 +4099,14 @@ static inline void ext4_iget_extra_inode(struct inode *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 @@ -4110,6 +4118,7 @@ struct inode *ext4_iget(struct super_block *sb, unsigned long ino)
130 inode = iget_locked(sb, ino);
132 @@ -4159,12 +4168,20 @@ struct inode *ext4_iget(struct super_block *sb, unsigned long ino)
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 @@ -4395,6 +4412,7 @@ static int ext4_do_update_inode(handle_t *handle,
154 int need_datasync = 0, set_large_file = 0;
159 spin_lock(&ei->i_raw_lock);
161 @@ -4407,6 +4425,7 @@ static int ext4_do_update_inode(handle_t *handle,
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 @@ -4486,6 +4505,14 @@ static int ext4_do_update_inode(handle_t *handle,
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 diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c
185 index a43d2f4..aead238 100644
186 --- a/fs/ext4/namei.c
187 +++ b/fs/ext4/namei.c
188 @@ -2927,6 +2927,11 @@ static int ext4_link(struct dentry *old_dentry,
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 @@ -3201,6 +3206,11 @@ static int ext4_rename(struct inode *old_dir, struct dentry *old_dentry,
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 @@ -3385,6 +3395,14 @@ static int ext4_cross_rename(struct inode *old_dir, struct dentry *old_dentry,
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 diff --git a/fs/ext4/super.c b/fs/ext4/super.c
228 index 24ef7b2..8189081 100644
229 --- a/fs/ext4/super.c
230 +++ b/fs/ext4/super.c
231 @@ -1075,6 +1075,7 @@ static const struct dquot_operations ext4_quota_operations = {
232 .write_info = ext4_write_info,
233 .alloc_dquot = dquot_alloc,
234 .destroy_dquot = dquot_destroy,
235 + .get_projid = ext4_get_projid,
238 static const struct quotactl_ops ext4_qctl_operations = {