Whamcloud - gitweb
LU-13239 ldiskfs: pass inode timestamps at initial creation
[fs/lustre-release.git] / ldiskfs / kernel_patches / patches / rhel8 / ext4-ialloc-uid-gid-and-pass-owner-down.patch
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
5
6 pass inode timestamps at initial creation
7 ---
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(-)
12
13 diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
14 index f2ed50c..548bb43 100644
15 --- a/fs/ext4/ext4.h
16 +++ b/fs/ext4/ext4.h
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,
21 -                                     int nblocks);
22 +                                     int nblocks, struct iattr *iattr);
23  
24  #define ext4_new_inode(handle, dir, mode, qstr, goal, owner, i_flags) \
25         __ext4_new_inode((handle), (dir), (mode), (qstr), (goal), (owner), \
26 -                        i_flags, 0, 0, 0)
27 +                        i_flags, 0, 0, 0, NULL)
28  #define ext4_new_inode_start_handle(dir, mode, qstr, goal, owner, \
29                                     type, nblocks)                  \
30         __ext4_new_inode(NULL, (dir), (mode), (qstr), (goal), (owner), \
31 -                        0, (type), __LINE__, (nblocks))
32 +                        0, (type), __LINE__, (nblocks), NULL)
33  
34  
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,
40 -                                      uid_t *owner);
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,
53 -                              int nblocks)
54 +                              int nblocks, struct iattr *iattr)
55  {
56         struct super_block *sb;
57         struct buffer_head *inode_bitmap_bh = NULL;
58 @@ -1143,6 +1143,15 @@ got:
59         if (err)
60                 goto fail_drop;
61  
62 +       if (iattr) {
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;
69 +       }
70 +
71         /*
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
76 --- a/fs/ext4/namei.c
77 +++ b/fs/ext4/namei.c
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,
82 -                               uid_t *owner)
83 +                               struct iattr *iattr)
84  {
85         struct inode *inode;
86 +       uid_t owner[2] = {0, 0};
87  
88 -       inode = ext4_new_inode(handle, dir, mode, NULL, 0, owner, 0);
89 +       if (iattr) {
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);
94 +       }
95 +
96 +       inode = __ext4_new_inode(handle, dir, mode, NULL, 0, owner, 0,
97 +                                0, 0, 0, iattr);
98         if (!IS_ERR(inode)) {
99                 if (S_ISCHR(mode) || S_ISBLK(mode) || S_ISFIFO(mode)) {
100  #ifdef CONFIG_LDISKFS_FS_XATTR
101 -- 
102 2.25.1
103