Whamcloud - gitweb
b=22514 kernel update for rhel5.5 & oel5.5.
[fs/lustre-release.git] / ldiskfs / kernel_patches / patches / 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: b/fs/ext4/namei.c
6 ===================================================================
7 --- a/fs/ext4/namei.c
8 +++ b/fs/ext4/namei.c
9 @@ -121,22 +121,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 @@ -225,6 +216,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 @@ -378,7 +379,7 @@ dx_probe(struct dentry *dentry, struct i
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 buffer_head *bh;
62         struct dx_frame *frame = frame_in;
63         u32 hash;
64 @@ -388,18 +389,19 @@ dx_probe(struct dentry *dentry, struct i
65                 dir = dentry->d_parent->d_inode;
66         if (!(bh = ext4_bread (NULL,dir, 0, 0, err)))
67                 goto fail;
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 +
73 +       info = dx_get_dx_info((struct ext4_dir_entry_2*)bh->b_data);
74 +       if (info->hash_version != DX_HASH_TEA &&
75 +           info->hash_version != DX_HASH_HALF_MD4 &&
76 +           info->hash_version != DX_HASH_LEGACY) {
77                 ext4_warning(dir->i_sb, __func__,
78                              "Unrecognised inode hash code %d for directory "
79 -                            "#%lu", root->info.hash_version, dir->i_ino);
80 +                            "#%lu", info->hash_version, dir->i_ino);
81                 brelse(bh);
82                 *err = ERR_BAD_DX_DIR;
83                 goto fail;
84         }
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 @@ -398,29 +399,28 @@ dx_probe(struct dentry *dentry, struct i
91                 ext4fs_dirhash(dentry->d_name.name, dentry->d_name.len, hinfo);
92         hash = hinfo->hash;
93  
94 -       if (root->info.unused_flags & 1) {
95 +       if (info->unused_flags & 1) {
96                 ext4_warning(dir->i_sb, __func__,
97                              "Unimplemented inode hash flags: %#06x",
98 -                            root->info.unused_flags);
99 +                            info->unused_flags);
100                 brelse(bh);
101                 *err = ERR_BAD_DX_DIR;
102                 goto fail;
103         }
104  
105 -       if ((indirect = root->info.indirect_levels) > 1) {
106 +       if ((indirect = info->indirect_levels) > 1) {
107                 ext4_warning(dir->i_sb, __func__,
108                              "Unimplemented inode hash depth: %#06x",
109 -                            root->info.indirect_levels);
110 +                            info->indirect_levels);
111                 brelse(bh);
112                 *err = ERR_BAD_DX_DIR;
113                 goto fail;
114         }
115  
116 -       entries = (struct dx_entry *) (((char *)&root->info) +
117 -                                      root->info.info_length);
118 +       entries = (struct dx_entry *) (((char *)info) + info->info_length);
119  
120         if (dx_get_limit(entries) != dx_root_limit(dir,
121 -                                                  root->info.info_length)) {
122 +                                                  info->info_length)) {
123                 ext4_warning(dir->i_sb, __func__,
124                              "dx entry: limit != root limit");
125                 brelse(bh);
126 @@ -509,10 +510,12 @@ fail:
127  
128  static void dx_release (struct dx_frame *frames)
129  {
130 +       struct dx_root_info *info;
131         if (frames[0].bh == NULL)
132                 return;
133  
134 -       if (((struct dx_root *) frames[0].bh->b_data)->info.indirect_levels)
135 +       info = dx_get_dx_info((struct ext4_dir_entry_2*)frames[0].bh->b_data);
136 +       if (info->indirect_levels)
137                 brelse(frames[1].bh);
138         brelse(frames[0].bh);
139  }
140 @@ -1430,17 +1433,16 @@ static int make_indexed_dir(handle_t *ha
141         const char      *name = dentry->d_name.name;
142         int             namelen = dentry->d_name.len;
143         struct buffer_head *bh2;
144 -       struct dx_root  *root;
145         struct dx_frame frames[2], *frame;
146         struct dx_entry *entries;
147 -       struct ext4_dir_entry_2 *de, *de2;
148 +       struct ext4_dir_entry_2 *de, *de2, *dot_de, *dotdot_de;
149         char            *data1, *top;
150         unsigned        len;
151         int             retval;
152         unsigned        blocksize;
153         struct dx_hash_info hinfo;
154         ext4_lblk_t  block;
155 -       struct fake_dirent *fde;
156 +       struct dx_root_info *dx_info;
157  
158         blocksize =  dir->i_sb->s_blocksize;
159         dxtrace(printk("Creating index\n"));
160 @@ -1450,7 +1452,6 @@ static int make_indexed_dir(handle_t *ha
161                 brelse(bh);
162                 return retval;
163         }
164 -       root = (struct dx_root *) bh->b_data;
165  
166         bh2 = ext4_append (handle, dir, &block, &retval);
167         if (!(bh2)) {
168 @@ -1460,18 +1461,20 @@ static int make_indexed_dir(handle_t *ha
169         }
170         root = (struct dx_root *) bh->b_data;
171  
172 +       dot_de = (struct ext4_dir_entry_2 *) bh->b_data;
173 +       dotdot_de = ext4_next_entry(dot_de, blocksize);
174 +
175         /* The 0th block becomes the root, move the dirents out */
176 -       fde = &root->dotdot;
177 -       de = (struct ext4_dir_entry_2 *)((char *)fde +
178 -               ext4_rec_len_from_disk(fde->rec_len, blocksize));
179 +       de = (struct ext4_dir_entry_2 *)((char *)dotdot_de +
180 +               ext4_rec_len_from_disk(dotdot_de->rec_len, blocksize));
181 -       if ((char *) de >= (((char *) root) + blocksize)) {
182 +       if ((char *) de >= (((char *) dot_de) + blocksize)) {
183                 ext4_error(dir->i_sb, __func__,
184                            "invalid rec_len for '..' in inode %lu",
185                            dir->i_ino);
186                 brelse(bh);
187                 return -EIO;
188         }
189 -       len = ((char *) root) + blocksize - (char *) de;
190 +       len = ((char *) dot_de) + blocksize - (char *) de;
191  
192         /* Allocate new block for the 0th block's dirents */
193         bh2 = ext4_append(handle, dir, &block, &retval);
194 @@ -1472,19 +1475,23 @@ static int make_indexed_dir(handle_t *ha
195         de->rec_len = ext4_rec_len_to_disk(data1 + blocksize - (char *) de);
196                                            blocksize);
197         /* Initialize the root; the dot dirents already exist */
198 -       de = (struct ext4_dir_entry_2 *) (&root->dotdot);
199 -       de->rec_len = ext4_rec_len_to_disk(blocksize - EXT4_DIR_REC_LEN(2),
200 -                                          blocksize);
201 -       memset (&root->info, 0, sizeof(root->info));
202 -       root->info.info_length = sizeof(root->info);
203 -       root->info.hash_version = EXT4_SB(dir->i_sb)->s_def_hash_version;
204 -       entries = root->entries;
205 -       dx_set_block(entries, 1);
206 -       dx_set_count(entries, 1);
207 -       dx_set_limit(entries, dx_root_limit(dir, sizeof(root->info)));
208 +       dotdot_de->rec_len = ext4_rec_len_to_disk(blocksize -
209 +                       le16_to_cpu(dot_de->rec_len), blocksize);
210 +
211 +       /* initialize hashing info */
212 +       dx_info = dx_get_dx_info(dot_de);
213 +       memset (dx_info, 0, sizeof(*dx_info));
214 +       dx_info->info_length = sizeof(*dx_info);
215 +       dx_info->hash_version = EXT4_SB(dir->i_sb)->s_def_hash_version;
216 +
217 +       entries = (void *)dx_info + sizeof(*dx_info);
218 +
219 +       dx_set_block(entries, 1);
220 +       dx_set_count(entries, 1);
221 +       dx_set_limit(entries, dx_root_limit(dir, sizeof(*dx_info)));
222  
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 @@ -1724,6 +1733,7 @@ static int ext4_dx_add_entry(handle_t *h
230                                 goto journal_error;
231                         brelse (bh2);
232                 } else {
233 +                       struct dx_root_info * info;
234                         dxtrace(printk(KERN_DEBUG
235                                        "Creating second level index...\n"));
236                         memcpy((char *) entries2, (char *) entries,
237 @@ -1732,7 +1742,9 @@ static int ext4_dx_add_entry(handle_t *h
238                         /* Set up root */
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;
245  
246                         /* Add new access path frame */
247                         frame = frames + 1;