Whamcloud - gitweb
LU-1812 ldiskfs: Add kernel patch series for SLES11SP2
[fs/lustre-release.git] / ldiskfs / kernel_patches / patches / sles11sp2 / ext4-kill-dx_root.patch
1 diff -r -u linux-stage.orig/fs/ext4/namei.c linux-stage/fs/ext4/namei.c
2 --- linux-stage.orig/fs/ext4/namei.c    2012-12-31 15:03:28.000000000 -0500
3 +++ linux-stage/fs/ext4/namei.c 2012-12-31 15:06:16.000000000 -0500
4 @@ -115,22 +115,13 @@
5   * hash version mod 4 should never be 0.  Sincerely, the paranoia department.
6   */
7
8 -struct dx_root
9 +struct dx_root_info
10  {
11 -       struct fake_dirent dot;
12 -       char dot_name[4];
13 -       struct fake_dirent dotdot;
14 -       char dotdot_name[4];
15 -       struct dx_root_info
16 -       {
17 -               __le32 reserved_zero;
18 -               u8 hash_version;
19 -               u8 info_length; /* 8 */
20 -               u8 indirect_levels;
21 -               u8 unused_flags;
22 -       }
23 -       info;
24 -       struct dx_entry entries[0];
25 +       __le32 reserved_zero;
26 +       u8 hash_version;
27 +       u8 info_length; /* 8 */
28 +       u8 indirect_levels;
29 +       u8 unused_flags;
30  };
31
32  struct dx_node
33 @@ -220,6 +211,16 @@
34   * Future: use high four bits of block for coalesce-on-delete flags
35   * Mask them off for now.
36   */
37 +struct dx_root_info * dx_get_dx_info(struct ext4_dir_entry_2 *de)
38 +{
39 +       /* get dotdot first */
40 +       de = (struct ext4_dir_entry_2 *)((char *)de + EXT4_DIR_REC_LEN(1));
41 +
42 +       /* dx root info is after dotdot entry */
43 +       de = (struct ext4_dir_entry_2 *)((char *)de + EXT4_DIR_REC_LEN(2));
44 +
45 +       return (struct dx_root_info *) de;
46 +}
47
48  static inline ext4_lblk_t dx_get_block(struct dx_entry *entry)
49  {
50 @@ -374,7 +375,7 @@
51  {
52         unsigned count, indirect;
53         struct dx_entry *at, *entries, *p, *q, *m;
54 -       struct dx_root *root;
55 +       struct dx_root_info * info;
56         struct buffer_head *bh;
57         struct dx_frame *frame = frame_in;
58         u32 hash;
59 @@ -382,17 +383,18 @@
60         frame->bh = NULL;
61         if (!(bh = ext4_bread (NULL,dir, 0, 0, err)))
62                 goto fail;
63 -       root = (struct dx_root *) bh->b_data;
64 -       if (root->info.hash_version != DX_HASH_TEA &&
65 -           root->info.hash_version != DX_HASH_HALF_MD4 &&
66 -           root->info.hash_version != DX_HASH_LEGACY) {
67 +
68 +       info = dx_get_dx_info((struct ext4_dir_entry_2*)bh->b_data);
69 +       if (info->hash_version != DX_HASH_TEA &&
70 +           info->hash_version != DX_HASH_HALF_MD4 &&
71 +           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);
74 +                             "#%lu", info->hash_version, dir->i_ino);
75                 brelse(bh);
76                 *err = ERR_BAD_DX_DIR;
77                 goto fail;
78         }
79 -       hinfo->hash_version = root->info.hash_version;
80 +       hinfo->hash_version = info->hash_version;
81         if (hinfo->hash_version <= DX_HASH_TEA)
82                 hinfo->hash_version += EXT4_SB(dir->i_sb)->s_hash_unsigned;
83         hinfo->seed = EXT4_SB(dir->i_sb)->s_hash_seed;
84 @@ -400,27 +402,26 @@
85                 ext4fs_dirhash(d_name->name, d_name->len, hinfo);
86         hash = hinfo->hash;
87
88 -       if (root->info.unused_flags & 1) {
89 +       if (info->unused_flags & 1) {
90                 ext4_warning(dir->i_sb, "Unimplemented inode hash flags: %#06x",
91 -                            root->info.unused_flags);
92 +                            info->unused_flags);
93                 brelse(bh);
94                 *err = ERR_BAD_DX_DIR;
95                 goto fail;
96         }
97
98 -       if ((indirect = root->info.indirect_levels) > 1) {
99 +       if ((indirect = info->indirect_levels) > 1) {
100                 ext4_warning(dir->i_sb, "Unimplemented inode hash depth: %#06x",
101 -                            root->info.indirect_levels);
102 +                            info->indirect_levels);
103                 brelse(bh);
104                 *err = ERR_BAD_DX_DIR;
105                 goto fail;
106         }
107
108 -       entries = (struct dx_entry *) (((char *)&root->info) +
109 -                                      root->info.info_length);
110 +       entries = (struct dx_entry *) (((char *)info) + info->info_length);
111
112         if (dx_get_limit(entries) != dx_root_limit(dir,
113 -                                                  root->info.info_length)) {
114 +                                                  info->info_length)) {
115                 ext4_warning(dir->i_sb, "dx entry: limit != root limit");
116                 brelse(bh);
117                 *err = ERR_BAD_DX_DIR;
118 @@ -501,10 +502,12 @@
119
120  static void dx_release (struct dx_frame *frames)
121  {
122 +       struct dx_root_info *info;
123         if (frames[0].bh == NULL)
124                 return;
125
126 -       if (((struct dx_root *) frames[0].bh->b_data)->info.indirect_levels)
127 +       info = dx_get_dx_info((struct ext4_dir_entry_2*)frames[0].bh->b_data);
128 +       if (info->indirect_levels)
129                 brelse(frames[1].bh);
130         brelse(frames[0].bh);
131  }
132 @@ -1400,17 +1403,16 @@
133         const char      *name = dentry->d_name.name;
134         int             namelen = dentry->d_name.len;
135         struct buffer_head *bh2;
136 -       struct dx_root  *root;
137         struct dx_frame frames[2], *frame;
138         struct dx_entry *entries;
139 -       struct ext4_dir_entry_2 *de, *de2;
140 +       struct ext4_dir_entry_2 *de, *de2, *dot_de, *dotdot_de;
141         char            *data1, *top;
142         unsigned        len;
143         int             retval;
144         unsigned        blocksize;
145         struct dx_hash_info hinfo;
146         ext4_lblk_t  block;
147 -       struct fake_dirent *fde;
148 +       struct dx_root_info *dx_info;
149
150         blocksize =  dir->i_sb->s_blocksize;
151         dxtrace(printk(KERN_DEBUG "Creating index: inode %lu\n", dir->i_ino));
152 @@ -1420,18 +1422,19 @@
153                 brelse(bh);
154                 return retval;
155         }
156 -       root = (struct dx_root *) bh->b_data;
157 +
158 +       dot_de = (struct ext4_dir_entry_2 *) bh->b_data;
159 +       dotdot_de = ext4_next_entry(dot_de, blocksize);
160
161         /* The 0th block becomes the root, move the dirents out */
162 -       fde = &root->dotdot;
163 -       de = (struct ext4_dir_entry_2 *)((char *)fde +
164 -               ext4_rec_len_from_disk(fde->rec_len, blocksize));
165 -       if ((char *) de >= (((char *) root) + blocksize)) {
166 +       de = (struct ext4_dir_entry_2 *)((char *)dotdot_de +
167 +               ext4_rec_len_from_disk(dotdot_de->rec_len, blocksize));
168 +       if ((char *) de >= (((char *) dot_de) + blocksize)) {
169                 EXT4_ERROR_INODE(dir, "invalid rec_len for '..'");
170                 brelse(bh);
171                 return -EIO;
172         }
173 -       len = ((char *) root) + blocksize - (char *) de;
174 +       len = ((char *) dot_de) + blocksize - (char *) de;
175
176         /* Allocate new block for the 0th block's dirents */
177         bh2 = ext4_append(handle, dir, &block, &retval);
178 @@ -1450,19 +1453,23 @@
179         de->rec_len = ext4_rec_len_to_disk(data1 + blocksize - (char *) de,
180                                            blocksize);
181         /* Initialize the root; the dot dirents already exist */
182 -       de = (struct ext4_dir_entry_2 *) (&root->dotdot);
183 -       de->rec_len = ext4_rec_len_to_disk(blocksize - EXT4_DIR_REC_LEN(2),
184 -                                          blocksize);
185 -       memset (&root->info, 0, sizeof(root->info));
186 -       root->info.info_length = sizeof(root->info);
187 -       root->info.hash_version = EXT4_SB(dir->i_sb)->s_def_hash_version;
188 -       entries = root->entries;
189 +       dotdot_de->rec_len = ext4_rec_len_to_disk(blocksize -
190 +                       le16_to_cpu(dot_de->rec_len), blocksize);
191 +
192 +       /* initialize hashing info */
193 +       dx_info = dx_get_dx_info(dot_de);
194 +       memset (dx_info, 0, sizeof(*dx_info));
195 +       dx_info->info_length = sizeof(*dx_info);
196 +       dx_info->hash_version = EXT4_SB(dir->i_sb)->s_def_hash_version;
197 +
198 +       entries = (void *)dx_info + sizeof(*dx_info);
199 +
200         dx_set_block(entries, 1);
201         dx_set_count(entries, 1);
202 -       dx_set_limit(entries, dx_root_limit(dir, sizeof(root->info)));
203 +       dx_set_limit(entries, dx_root_limit(dir, sizeof(*dx_info)));
204
205         /* Initialize as for dx_probe */
206 -       hinfo.hash_version = root->info.hash_version;
207 +       hinfo.hash_version = dx_info->hash_version;
208         if (hinfo.hash_version <= DX_HASH_TEA)
209                 hinfo.hash_version += EXT4_SB(dir->i_sb)->s_hash_unsigned;
210         hinfo.seed = EXT4_SB(dir->i_sb)->s_hash_seed;
211 @@ -1723,6 +1730,7 @@
212                                 goto journal_error;
213                         brelse (bh2);
214                 } else {
215 +                       struct dx_root_info * info;
216                         dxtrace(printk(KERN_DEBUG
217                                        "Creating second level index...\n"));
218                         memcpy((char *) entries2, (char *) entries,
219 @@ -1732,7 +1740,9 @@
220                         /* Set up root */
221                         dx_set_count(entries, 1);
222                         dx_set_block(entries + 0, newblock);
223 -                       ((struct dx_root *) frames[0].bh->b_data)->info.indirect_levels = 1;
224 +                       info = dx_get_dx_info((struct ext4_dir_entry_2*)
225 +                                       frames[0].bh->b_data);
226 +                       info->indirect_levels = 1;
227
228                         /* Add new access path frame */
229                         frame = frames + 1;