1 From ead0a400ed5f3621b2450a5da61c2295a224e002 Mon Sep 17 00:00:00 2001
2 From: Shaun Tancheff <shaun.tancheff@hpe.com>
3 Date: Wed, 2 Dec 2020 13:02:37 -0600
4 Subject: [PATCH] ext4 ialloc uid gid and pass owner down
6 pass inode timestamps at initial creation
8 fs/ext4/ext4.h | 8 ++++----
9 fs/ext4/ialloc.c | 11 ++++++++++-
10 fs/ext4/namei.c | 13 +++++++++++--
11 3 files changed, 25 insertions(+), 7 deletions(-)
13 diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
14 index f2ed50c..548bb43 100644
17 @@ -2549,15 +2549,15 @@ extern struct inode *__ext4_new_inode(handle_t *, struct inode *, umode_t,
18 const struct qstr *qstr, __u32 goal,
19 uid_t *owner, __u32 i_flags,
20 int handle_type, unsigned int line_no,
22 + int nblocks, struct iattr *iattr);
24 #define ext4_new_inode(handle, dir, mode, qstr, goal, owner, i_flags) \
25 __ext4_new_inode((handle), (dir), (mode), (qstr), (goal), (owner), \
27 + i_flags, 0, 0, 0, NULL)
28 #define ext4_new_inode_start_handle(dir, mode, qstr, goal, owner, \
30 __ext4_new_inode(NULL, (dir), (mode), (qstr), (goal), (owner), \
31 - 0, (type), __LINE__, (nblocks))
32 + 0, (type), __LINE__, (nblocks), NULL)
35 extern void ext4_free_inode(handle_t *, struct inode *);
36 @@ -2695,7 +2695,7 @@ extern int ext4_orphan_add(handle_t *, struct inode *);
37 extern int ext4_orphan_del(handle_t *, struct inode *);
38 extern struct inode *ext4_create_inode(handle_t *handle,
39 struct inode *dir, int mode,
41 + struct iattr *iattr);
42 extern int ext4_delete_entry(handle_t *handle, struct inode * dir,
43 struct ext4_dir_entry_2 *de_del,
44 struct buffer_head *bh);
45 diff --git a/fs/ext4/ialloc.c b/fs/ext4/ialloc.c
46 index e771142..364fb49 100644
47 --- a/fs/ext4/ialloc.c
48 +++ b/fs/ext4/ialloc.c
49 @@ -744,7 +744,7 @@ struct inode *__ext4_new_inode(handle_t *handle, struct inode *dir,
50 umode_t mode, const struct qstr *qstr,
51 __u32 goal, uid_t *owner, __u32 i_flags,
52 int handle_type, unsigned int line_no,
54 + int nblocks, struct iattr *iattr)
56 struct super_block *sb;
57 struct buffer_head *inode_bitmap_bh = NULL;
58 @@ -1143,6 +1143,15 @@ got:
63 + if (iattr->ia_valid & ATTR_CTIME)
64 + inode->i_ctime = iattr->ia_ctime;
65 + if (iattr->ia_valid & ATTR_MTIME)
66 + inode->i_mtime = iattr->ia_mtime;
67 + if (iattr->ia_valid & ATTR_ATIME)
68 + inode->i_atime = iattr->ia_atime;
72 * Since the encryption xattr will always be unique, create it first so
73 * that it's less likely to end up in an external xattr block and
74 diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c
75 index 5d03e3a..dbb5a61 100644
78 @@ -3029,11 +3029,20 @@ static int ext4_add_nondir(handle_t *handle,
79 /* Return locked inode, then the caller can modify the inode's states/flags
80 * before others finding it. The caller should unlock the inode by itself. */
81 struct inode *ext4_create_inode(handle_t *handle, struct inode *dir, int mode,
83 + struct iattr *iattr)
86 + uid_t owner[2] = {0, 0};
88 - inode = ext4_new_inode(handle, dir, mode, NULL, 0, owner, 0);
90 + if (iattr->ia_valid & ATTR_UID)
91 + owner[0] = from_kuid(&init_user_ns, iattr->ia_uid);
92 + if (iattr->ia_valid & ATTR_GID)
93 + owner[1] = from_kgid(&init_user_ns, iattr->ia_gid);
96 + inode = __ext4_new_inode(handle, dir, mode, NULL, 0, owner, 0,
99 if (S_ISCHR(mode) || S_ISBLK(mode) || S_ISFIFO(mode)) {
100 #ifdef CONFIG_LDISKFS_FS_XATTR