Whamcloud - gitweb
LU-8871 kernel: kernel upgrade [SLES12 SP2 4.4.21-84]
[fs/lustre-release.git] / ldiskfs / kernel_patches / patches / sles12sp2 / ext4-kill-dx-root.patch
1 removes static definition of dx_root struct. so that "." and ".." dirent can
2 have extra data. This patch does not change any functionality but is required for
3 ext4_data_in_dirent patch.
4  
5 Index: linux-3.10.0-123.9.3.el7.x86_64/fs/ext4/namei.c
6 ===================================================================
7 --- linux-3.10.0-123.9.3.el7.x86_64.orig/fs/ext4/namei.c
8 +++ linux-3.10.0-123.9.3.el7.x86_64/fs/ext4/namei.c
9 @@ -193,22 +193,13 @@ struct dx_entry
10   * hash version mod 4 should never be 0.  Sincerely, the paranoia department.
11   */
12  
13 -struct dx_root
14 +struct dx_root_info
15  {
16 -       struct fake_dirent dot;
17 -       char dot_name[4];
18 -       struct fake_dirent dotdot;
19 -       char dotdot_name[4];
20 -       struct dx_root_info
21 -       {
22 -               __le32 reserved_zero;
23 -               u8 hash_version;
24 -               u8 info_length; /* 8 */
25 -               u8 indirect_levels;
26 -               u8 unused_flags;
27 -       }
28 -       info;
29 -       struct dx_entry entries[0];
30 +       __le32 reserved_zero;
31 +       u8 hash_version;
32 +       u8 info_length; /* 8 */
33 +       u8 indirect_levels;
34 +       u8 unused_flags;
35  };
36  
37  struct dx_node
38 @@ -511,6 +502,16 @@ ext4_next_entry(struct ext4_dir_entry_2
39   * Future: use high four bits of block for coalesce-on-delete flags
40   * Mask them off for now.
41   */
42 +struct dx_root_info *dx_get_dx_info(struct ext4_dir_entry_2 *de)
43 +{
44 +       /* get dotdot first */
45 +       de = (struct ext4_dir_entry_2 *)((char *)de + EXT4_DIR_REC_LEN(1));
46 +
47 +       /* dx root info is after dotdot entry */
48 +       de = (struct ext4_dir_entry_2 *)((char *)de + EXT4_DIR_REC_LEN(2));
49 +
50 +       return (struct dx_root_info *)de;
51 +}
52  
53  static inline ext4_lblk_t dx_get_block(struct dx_entry *entry)
54  {
55 @@ -673,7 +674,7 @@ dx_probe(const struct qstr *d_name, stru
56  {
57         unsigned count, indirect;
58         struct dx_entry *at, *entries, *p, *q, *m;
59 -       struct dx_root *root;
60 +       struct dx_root_info *info;
61         struct dx_frame *frame = frame_in;
62         u32 hash;
63  
64 @@ -684,17 +685,17 @@ dx_probe(const struct qstr *d_name, stru
65         if (IS_ERR(frame->bh))
66                 return (struct dx_frame *) frame->bh;
67  
68 -       root = (struct dx_root *) frame->bh->b_data;
69 -       if (root->info.hash_version != DX_HASH_TEA &&
70 -           root->info.hash_version != DX_HASH_HALF_MD4 &&
71 -           root->info.hash_version != DX_HASH_LEGACY) {
72 +       info = dx_get_dx_info((struct ext4_dir_entry_2 *)frame->bh->b_data);
73 +       if (info->hash_version != DX_HASH_TEA &&
74 +           info->hash_version != DX_HASH_HALF_MD4 &&
75 +           info->hash_version != DX_HASH_LEGACY) {
76                 ext4_warning_inode(dir, "Unrecognised inode hash code %u for directory "
77 -                                  "%lu", root->info.hash_version, dir->i_ino);
78 +                                  "%lu", info->hash_version, dir->i_ino);
79                 goto fail;
80         }
81         if (fname)
82                 hinfo = &fname->hinfo;
83 -       hinfo->hash_version = root->info.hash_version;
84 +       hinfo->hash_version = info->hash_version;
85         if (hinfo->hash_version <= DX_HASH_TEA)
86                 hinfo->hash_version += EXT4_SB(dir->i_sb)->s_hash_unsigned;
87         hinfo->seed = EXT4_SB(dir->i_sb)->s_hash_seed;
88 @@ -702,27 +704,26 @@ dx_probe(const struct qstr *d_name, stru
89                 ext4fs_dirhash(d_name->name, d_name->len, hinfo);
90         hash = hinfo->hash;
91  
92 -       if (root->info.unused_flags & 1) {
93 +       if (info->unused_flags & 1) {
94                 ext4_warning_inode(dir, "Unimplemented hash flags: %#06x",
95 -                                  root->info.unused_flags);
96 +                                  info->unused_flags);
97                 goto fail;
98         }
99  
100 -       indirect = root->info.indirect_levels;
101 +       indirect = info->indirect_levels;
102         if (indirect > 1) {
103                 ext4_warning_inode(dir, "Unimplemented hash depth: %#06x",
104 -                                  root->info.indirect_levels);
105 +                                  info->indirect_levels);
106                 goto fail;
107         }
108  
109 -       entries = (struct dx_entry *)(((char *)&root->info) +
110 -                                     root->info.info_length);
111 +       entries = (struct dx_entry *)(((char *)info) + info->info_length);
112  
113         if (dx_get_limit(entries) != dx_root_limit(dir,
114 -                                                  root->info.info_length)) {
115 +                                                  info->info_length)) {
116                 ext4_warning_inode(dir, "dx entry: limit %u != root limit %u",
117                                    dx_get_limit(entries),
118 -                                  dx_root_limit(dir, root->info.info_length));
119 +                                  dx_root_limit(dir, info->info_length));
120                 goto fail;
121         }
122  
123 @@ -1787,10 +1790,9 @@ static int make_indexed_dir(handle_t *ha
124         const char      *name = dentry->d_name.name;
125         int             namelen = dentry->d_name.len;
126         struct buffer_head *bh2;
127 -       struct dx_root  *root;
128         struct dx_frame frames[2], *frame;
129         struct dx_entry *entries;
130 -       struct ext4_dir_entry_2 *de, *de2;
131 +       struct ext4_dir_entry_2 *de, *de2, *dot_de, *dotdot_de;
132         struct ext4_dir_entry_tail *t;
133         char            *data1, *top;
134         unsigned        len;
135 @@ -1798,7 +1800,7 @@ static int make_indexed_dir(handle_t *ha
136         unsigned        blocksize;
137         struct dx_hash_info hinfo;
138         ext4_lblk_t  block;
139 -       struct fake_dirent *fde;
140 +       struct dx_root_info *dx_info;
141         int csum_size = 0;
142  
143         if (EXT4_HAS_RO_COMPAT_FEATURE(inode->i_sb,
144 @@ -1813,18 +1815,19 @@ static int make_indexed_dir(handle_t *ha
145                 brelse(bh);
146                 return retval;
147         }
148 -       root = (struct dx_root *) bh->b_data;
149 +
150 +       dot_de = (struct ext4_dir_entry_2 *)bh->b_data;
151 +       dotdot_de = ext4_next_entry(dot_de, blocksize);
152  
153         /* The 0th block becomes the root, move the dirents out */
154 -       fde = &root->dotdot;
155 -       de = (struct ext4_dir_entry_2 *)((char *)fde +
156 -               ext4_rec_len_from_disk(fde->rec_len, blocksize));
157 -       if ((char *) de >= (((char *) root) + blocksize)) {
158 +       de = (struct ext4_dir_entry_2 *)((char *)dotdot_de +
159 +               ext4_rec_len_from_disk(dotdot_de->rec_len, blocksize));
160 +       if ((char *)de >= (((char *)dot_de) + blocksize)) {
161                 EXT4_ERROR_INODE(dir, "invalid rec_len for '..'");
162                 brelse(bh);
163                 return -EFSCORRUPTED;
164         }
165 -       len = ((char *) root) + (blocksize - csum_size) - (char *) de;
166 +       len = ((char *)dot_de) + (blocksize - csum_size) - (char *)de;
167  
168         /* Allocate new block for the 0th block's dirents */
169         bh2 = ext4_append(handle, dir, &block);
170 @@ -1850,19 +1853,24 @@ static int make_indexed_dir(handle_t *ha
171         }
172  
173         /* Initialize the root; the dot dirents already exist */
174 -       de = (struct ext4_dir_entry_2 *) (&root->dotdot);
175 -       de->rec_len = ext4_rec_len_to_disk(blocksize - EXT4_DIR_REC_LEN(2),
176 -                                          blocksize);
177 -       memset (&root->info, 0, sizeof(root->info));
178 -       root->info.info_length = sizeof(root->info);
179 -       root->info.hash_version = EXT4_SB(dir->i_sb)->s_def_hash_version;
180 -       entries = root->entries;
181 +       dotdot_de->rec_len =
182 +               ext4_rec_len_to_disk(blocksize - le16_to_cpu(dot_de->rec_len),
183 +                                    blocksize);
184 +
185 +       /* initialize hashing info */
186 +       dx_info = dx_get_dx_info(dot_de);
187 +       memset(dx_info, 0, sizeof(*dx_info));
188 +       dx_info->info_length = sizeof(*dx_info);
189 +       dx_info->hash_version = EXT4_SB(dir->i_sb)->s_def_hash_version;
190 +
191 +       entries = (void *)dx_info + sizeof(*dx_info);
192 +
193         dx_set_block(entries, 1);
194         dx_set_count(entries, 1);
195 -       dx_set_limit(entries, dx_root_limit(dir, sizeof(root->info)));
196 +       dx_set_limit(entries, dx_root_limit(dir, sizeof(*dx_info)));
197  
198         /* Initialize as for dx_probe */
199 -       fname->hinfo.hash_version = root->info.hash_version;
200 +       fname->hinfo.hash_version = dx_info->hash_version;
201         if (fname->hinfo.hash_version <= DX_HASH_TEA)
202                 hinfo.hash_version += EXT4_SB(dir->i_sb)->s_hash_unsigned;
203         hinfo.seed = EXT4_SB(dir->i_sb)->s_hash_seed;
204 @@ -2152,6 +2159,7 @@ static int ext4_dx_add_entry(handle_t *h
205                                 goto journal_error;
206                         brelse (bh2);
207                 } else {
208 +                       struct dx_root_info *info;
209                         dxtrace(printk(KERN_DEBUG
210                                        "Creating second level index...\n"));
211                         memcpy((char *) entries2, (char *) entries,
212 @@ -2161,7 +2169,9 @@ static int ext4_dx_add_entry(handle_t *h
213                         /* Set up root */
214                         dx_set_count(entries, 1);
215                         dx_set_block(entries + 0, newblock);
216 -                       ((struct dx_root *) frames[0].bh->b_data)->info.indirect_levels = 1;
217 +                       info = dx_get_dx_info((struct ext4_dir_entry_2 *)
218 +                                             frames[0].bh->b_data);
219 +                       info->indirect_levels = 1;
220  
221                         /* Add new access path frame */
222                         frame = frames + 1;