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.
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.
16 - struct fake_dirent dot;
18 - struct fake_dirent dotdot;
19 - char dotdot_name[4];
22 - __le32 reserved_zero;
24 - u8 info_length; /* 8 */
29 - struct dx_entry entries[0];
30 + __le32 reserved_zero;
32 + u8 info_length; /* 8 */
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.
42 +struct dx_root_info *dx_get_dx_info(struct ext4_dir_entry_2 *de)
44 + /* get dotdot first */
45 + de = (struct ext4_dir_entry_2 *)((char *)de + EXT4_DIR_REC_LEN(1));
47 + /* dx root info is after dotdot entry */
48 + de = (struct ext4_dir_entry_2 *)((char *)de + EXT4_DIR_REC_LEN(2));
50 + return (struct dx_root_info *)de;
53 static inline ext4_lblk_t dx_get_block(struct dx_entry *entry)
55 @@ -673,7 +674,7 @@ dx_probe(const struct qstr *d_name, stru
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 buffer_head *bh;
62 struct dx_frame *frame = frame_in;
64 @@ -684,17 +685,18 @@ dx_probe(const struct qstr *d_name, stru
68 - root = (struct dx_root *) 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 - ext4_warning(dir->i_sb, "Unrecognised inode hash code %d for directory "
73 - "#%lu", root->info.hash_version, dir->i_ino);
75 + info = dx_get_dx_info((struct ext4_dir_entry_2 *)bh->b_data);
76 + if (info->hash_version != DX_HASH_TEA &&
77 + info->hash_version != DX_HASH_HALF_MD4 &&
78 + info->hash_version != DX_HASH_LEGACY) {
79 + ext4_warning(dir->i_sb, "inode #%lu: unrecognised hash code %u",
80 + dir->i_ino, info->hash_version);
82 *err = ERR_BAD_DX_DIR;
85 - hinfo->hash_version = root->info.hash_version;
86 + hinfo->hash_version = info->hash_version;
87 if (hinfo->hash_version <= DX_HASH_TEA)
88 hinfo->hash_version += EXT4_SB(dir->i_sb)->s_hash_unsigned;
89 hinfo->seed = EXT4_SB(dir->i_sb)->s_hash_seed;
90 @@ -702,28 +704,33 @@ dx_probe(const struct qstr *d_name, stru
91 ext4fs_dirhash(d_name->name, d_name->len, hinfo);
94 - if (root->info.unused_flags & 1) {
95 - ext4_warning(dir->i_sb, "Unimplemented inode hash flags: %#06x",
96 - root->info.unused_flags);
97 + if (info->unused_flags & 1) {
98 + ext4_warning(dir->i_sb,
99 + "inode #%lu: unimplemented hash flags: %#06x",
100 + dir->i_ino, info->unused_flags);
102 *err = ERR_BAD_DX_DIR;
106 - if ((indirect = root->info.indirect_levels) > 1) {
107 - ext4_warning(dir->i_sb, "Unimplemented inode hash depth: %#06x",
108 - root->info.indirect_levels);
109 + indirect = info->indirect_levels;
110 + if (indirect > 1) {
111 + ext4_warning(dir->i_sb,
112 + "inode #%lu: unimplemented hash depth %u",
113 + dir->i_ino, info->indirect_levels);
115 *err = ERR_BAD_DX_DIR;
119 - entries = (struct dx_entry *) (((char *)&root->info) +
120 - root->info.info_length);
121 + entries = (struct dx_entry *)(((char *)info) + info->info_length);
123 if (dx_get_limit(entries) != dx_root_limit(dir,
124 - root->info.info_length)) {
125 - ext4_warning(dir->i_sb, "dx entry: limit != root limit");
126 + info->info_length)) {
127 + ext4_warning(dir->i_sb, "dx entry: limit != root limit "
128 + "inode #%lu: dx entry: limit %u != root limit %u",
129 + dir->i_ino, dx_get_limit(entries),
130 + dx_root_limit(dir, info->info_length));
132 *err = ERR_BAD_DX_DIR;
134 @@ -807,10 +808,12 @@ fail:
136 static void dx_release (struct dx_frame *frames)
138 + struct dx_root_info *info;
139 if (frames[0].bh == NULL)
142 - if (((struct dx_root *) frames[0].bh->b_data)->info.indirect_levels)
143 + info = dx_get_dx_info((struct ext4_dir_entry_2 *)frames[0].bh->b_data);
144 + if (info->indirect_levels)
145 brelse(frames[1].bh);
146 brelse(frames[0].bh);
148 @@ -1787,10 +1790,9 @@ static int make_indexed_dir(handle_t *ha
149 const char *name = dentry->d_name.name;
150 int namelen = dentry->d_name.len;
151 struct buffer_head *bh2;
152 - struct dx_root *root;
153 struct dx_frame frames[2], *frame;
154 struct dx_entry *entries;
155 - struct ext4_dir_entry_2 *de, *de2;
156 + struct ext4_dir_entry_2 *de, *de2, *dot_de, *dotdot_de;
157 struct ext4_dir_entry_tail *t;
160 @@ -1798,7 +1800,7 @@ static int make_indexed_dir(handle_t *ha
162 struct dx_hash_info hinfo;
164 - struct fake_dirent *fde;
165 + struct dx_root_info *dx_info;
168 if (EXT4_HAS_RO_COMPAT_FEATURE(inode->i_sb,
169 @@ -1813,18 +1815,19 @@ static int make_indexed_dir(handle_t *ha
173 - root = (struct dx_root *) bh->b_data;
175 + dot_de = (struct ext4_dir_entry_2 *)bh->b_data;
176 + dotdot_de = ext4_next_entry(dot_de, blocksize);
178 /* The 0th block becomes the root, move the dirents out */
179 - fde = &root->dotdot;
180 - de = (struct ext4_dir_entry_2 *)((char *)fde +
181 - ext4_rec_len_from_disk(fde->rec_len, blocksize));
182 - if ((char *) de >= (((char *) root) + blocksize)) {
183 + de = (struct ext4_dir_entry_2 *)((char *)dotdot_de +
184 + ext4_rec_len_from_disk(dotdot_de->rec_len, blocksize));
185 + if ((char *)de >= (((char *)dot_de) + blocksize)) {
186 EXT4_ERROR_INODE(dir, "invalid rec_len for '..'");
190 - len = ((char *) root) + (blocksize - csum_size) - (char *) de;
191 + len = ((char *)dot_de) + (blocksize - csum_size) - (char *)de;
193 /* Allocate new block for the 0th block's dirents */
194 bh2 = ext4_append(handle, dir, &block);
195 @@ -1850,19 +1853,24 @@ static int make_indexed_dir(handle_t *ha
198 /* Initialize the root; the dot dirents already exist */
199 - de = (struct ext4_dir_entry_2 *) (&root->dotdot);
200 - de->rec_len = ext4_rec_len_to_disk(blocksize - EXT4_DIR_REC_LEN(2),
202 - memset (&root->info, 0, sizeof(root->info));
203 - root->info.info_length = sizeof(root->info);
204 - root->info.hash_version = EXT4_SB(dir->i_sb)->s_def_hash_version;
205 - entries = root->entries;
206 + dotdot_de->rec_len =
207 + ext4_rec_len_to_disk(blocksize - le16_to_cpu(dot_de->rec_len),
210 + /* initialize hashing info */
211 + dx_info = dx_get_dx_info(dot_de);
212 + memset(dx_info, 0, sizeof(*dx_info));
213 + dx_info->info_length = sizeof(*dx_info);
214 + dx_info->hash_version = EXT4_SB(dir->i_sb)->s_def_hash_version;
216 + entries = (void *)dx_info + sizeof(*dx_info);
218 dx_set_block(entries, 1);
219 dx_set_count(entries, 1);
220 - dx_set_limit(entries, dx_root_limit(dir, sizeof(root->info)));
221 + dx_set_limit(entries, dx_root_limit(dir, sizeof(*dx_info)));
223 /* Initialize as for dx_probe */
224 - hinfo.hash_version = root->info.hash_version;
225 + hinfo.hash_version = dx_info->hash_version;
226 if (hinfo.hash_version <= DX_HASH_TEA)
227 hinfo.hash_version += EXT4_SB(dir->i_sb)->s_hash_unsigned;
228 hinfo.seed = EXT4_SB(dir->i_sb)->s_hash_seed;
229 @@ -2152,6 +2159,7 @@ static int ext4_dx_add_entry(handle_t *h
233 + struct dx_root_info *info;
234 dxtrace(printk(KERN_DEBUG
235 "Creating second level index...\n"));
236 memcpy((char *) entries2, (char *) entries,
237 @@ -2161,7 +2169,9 @@ static int ext4_dx_add_entry(handle_t *h
239 dx_set_count(entries, 1);
240 dx_set_block(entries + 0, newblock);
241 - ((struct dx_root *) frames[0].bh->b_data)->info.indirect_levels = 1;
242 + info = dx_get_dx_info((struct ext4_dir_entry_2 *)
243 + frames[0].bh->b_data);
244 + info->indirect_levels = 1;
246 /* Add new access path frame */