Whamcloud - gitweb
Land b1_2 onto HEAD (20040317_2319)
[fs/lustre-release.git] / lustre / kernel_patches / patches / ext3-pdirops-2.4.20-chaos.patch
1  fs/ext3/ialloc.c          |    3 
2  fs/ext3/inode.c           |    3 
3  fs/ext3/namei.c           |  582 +++++++++++++++++++++++++++++++++++++---------
4  fs/ext3/super.c           |   14 +
5  include/linux/ext3_fs.h   |    1 
6  include/linux/ext3_fs_i.h |    6 
7  6 files changed, 500 insertions(+), 109 deletions(-)
8
9 Index: linux-2.4.20/fs/ext3/namei.c
10 ===================================================================
11 --- linux-2.4.20.orig/fs/ext3/namei.c   Wed Mar 17 15:37:09 2004
12 +++ linux-2.4.20/fs/ext3/namei.c        Wed Mar 17 15:37:56 2004
13 @@ -51,6 +51,9 @@
14  {
15         struct buffer_head *bh;
16  
17 +       /* with parallel dir operations all appends
18 +        * have to be serialized -bzzz */
19 +       down(&EXT3_I(inode)->i_append_sem);
20         *block = inode->i_size >> inode->i_sb->s_blocksize_bits;
21  
22         if ((bh = ext3_bread(handle, inode, *block, 1, err))) {
23 @@ -58,6 +61,8 @@
24                 EXT3_I(inode)->i_disksize = inode->i_size;
25                 ext3_journal_get_write_access(handle,bh);
26         }
27 +       up(&EXT3_I(inode)->i_append_sem);
28 +       
29         return bh;
30  }
31  
32 @@ -134,6 +139,8 @@
33         struct buffer_head *bh;
34         struct dx_entry *entries;
35         struct dx_entry *at;
36 +       unsigned long leaf;
37 +       unsigned int curidx;
38  };
39  
40  struct dx_map_entry
41 @@ -142,6 +149,30 @@
42         u32 offs;
43  };
44  
45 +/* FIXME: this should be reworked using bb_spin_lock
46 + * introduced in -mm tree
47 + */
48 +#define BH_DXLock      25
49 +
50 +static inline void dx_lock_bh(struct buffer_head volatile *bh)
51 +{
52 +#ifdef CONFIG_SMP
53 +        while (test_and_set_bit(BH_DXLock, &bh->b_state)) {
54 +                while (test_bit(BH_DXLock, &bh->b_state))
55 +                        cpu_relax();
56 +        }
57 +#endif
58 +}
59 +
60 +static inline void dx_unlock_bh(struct buffer_head *bh)
61 +{
62 +#ifdef CONFIG_SMP
63 +        smp_mb__before_clear_bit();
64 +        clear_bit(BH_DXLock, &bh->b_state);
65 +#endif
66 +}
67 +
68 +
69  #ifdef CONFIG_EXT3_INDEX
70  static inline unsigned dx_get_block (struct dx_entry *entry);
71  static void dx_set_block (struct dx_entry *entry, unsigned value);
72 @@ -153,7 +184,7 @@
73  static void dx_set_limit (struct dx_entry *entries, unsigned value);
74  static unsigned dx_root_limit (struct inode *dir, unsigned infosize);
75  static unsigned dx_node_limit (struct inode *dir);
76 -static struct dx_frame *dx_probe(struct dentry *dentry,
77 +static struct dx_frame *dx_probe(struct qstr *name,
78                                  struct inode *dir,
79                                  struct dx_hash_info *hinfo,
80                                  struct dx_frame *frame,
81 @@ -165,15 +196,18 @@
82  static struct ext3_dir_entry_2 *dx_move_dirents (char *from, char *to,
83                 struct dx_map_entry *offsets, int count);
84  static struct ext3_dir_entry_2* dx_pack_dirents (char *base, int size);
85 -static void dx_insert_block (struct dx_frame *frame, u32 hash, u32 block);
86 +static void dx_insert_block (struct inode *, struct dx_frame *, u32, u32, u32);
87  static int ext3_htree_next_block(struct inode *dir, __u32 hash,
88                                  struct dx_frame *frame,
89                                  struct dx_frame *frames, int *err,
90                                  __u32 *start_hash);
91  static struct buffer_head * ext3_dx_find_entry(struct dentry *dentry,
92 -                      struct ext3_dir_entry_2 **res_dir, int *err);
93 +                      struct ext3_dir_entry_2 **res_dir, int *err,
94 +                      int rwlock, void **lock);
95  static int ext3_dx_add_entry(handle_t *handle, struct dentry *dentry,
96                              struct inode *inode);
97 +static inline void *ext3_lock_htree(struct inode *, unsigned long, int);
98 +static inline void ext3_unlock_htree(struct inode *, void *);
99  
100  /*
101   * Future: use high four bits of block for coalesce-on-delete flags
102 @@ -306,6 +340,94 @@
103  #endif /* DX_DEBUG */
104  
105  /*
106 + * dx_find_position
107 + *
108 + * search position of specified hash in index
109 + *
110 + */
111 +
112 +struct dx_entry * dx_find_position(struct dx_entry * entries, u32 hash)
113 +{
114 +       struct dx_entry *p, *q, *m;
115 +       int count;
116 +
117 +       count = dx_get_count(entries);
118 +       p = entries + 1;
119 +       q = entries + count - 1;
120 +       while (p <= q)
121 +       {
122 +               m = p + (q - p)/2;
123 +               if (dx_get_hash(m) > hash)
124 +                       q = m - 1;
125 +               else
126 +                       p = m + 1;
127 +       }
128 +       return p - 1;
129 +}
130 +
131 +/*
132 + * returns 1 if path is unchanged
133 + */
134 +int dx_check_path(struct dx_frame *frame, u32 hash)
135 +{
136 +       struct dx_entry *p;
137 +       int ret = 1;
138 +
139 +       dx_lock_bh(frame->bh);
140 +       p = dx_find_position(frame->entries, hash);
141 +       if (frame->leaf != dx_get_block(p))
142 +               ret = 0;
143 +       dx_unlock_bh(frame->bh);
144 +       
145 +       return ret;
146 +}
147 +
148 +/*
149 + * 0 - changed
150 + * 1 - hasn't changed
151 + */
152 +static int
153 +dx_check_full_path(struct dx_frame *frames, struct dx_hash_info *hinfo)
154 +{
155 +       struct dx_entry *p;
156 +       struct dx_frame *frame = frames;
157 +       u32 leaf;
158 +
159 +       /* check first level */
160 +       dx_lock_bh(frame->bh);
161 +       p = dx_find_position(frame->entries, hinfo->hash);
162 +       leaf = dx_get_block(p);
163 +       dx_unlock_bh(frame->bh);
164 +       
165 +       if (leaf != frame->leaf) 
166 +               return 0;
167 +       
168 +       /* is there 2nd level? */
169 +       frame++;
170 +       if (frame->bh == NULL)
171 +               return 1;
172 +
173 +       /* check second level */
174 +       dx_lock_bh(frame->bh);
175 +
176 +       /* probably 1st level got changed, check it */
177 +       if (!dx_check_path(frames, hinfo->hash)) {
178 +               /* path changed */
179 +               dx_unlock_bh(frame->bh);
180 +               return 0;
181 +       }
182 +
183 +       p = dx_find_position(frame->entries, hinfo->hash);
184 +       leaf = dx_get_block(p);
185 +       dx_unlock_bh(frame->bh);
186 +       
187 +       if (leaf != frame->leaf)
188 +               return 0;
189 +
190 +       return 1;
191 +}
192 +
193 +/*
194   * Probe for a directory leaf block to search.
195   *
196   * dx_probe can return ERR_BAD_DX_DIR, which means there was a format
197 @@ -315,19 +437,20 @@
198   * back to userspace.
199   */
200  static struct dx_frame *
201 -dx_probe(struct dentry *dentry, struct inode *dir,
202 +dx_probe(struct qstr *name, struct inode *dir,
203          struct dx_hash_info *hinfo, struct dx_frame *frame_in, int *err)
204  {
205 -       unsigned count, indirect;
206 -       struct dx_entry *at, *entries, *p, *q, *m;
207 +       unsigned indirect;
208 +       struct dx_entry *at, *entries;
209         struct dx_root *root;
210         struct buffer_head *bh;
211         struct dx_frame *frame = frame_in;
212         u32 hash;
213 +       unsigned int curidx;
214  
215         frame->bh = NULL;
216 -       if (dentry)
217 -               dir = dentry->d_parent->d_inode;
218 +       frame[1].bh = NULL;
219 +
220         if (!(bh = ext3_bread (NULL,dir, 0, 0, err)))
221                 goto fail;
222         root = (struct dx_root *) bh->b_data;
223 @@ -343,8 +466,8 @@
224         }
225         hinfo->hash_version = root->info.hash_version;
226         hinfo->seed = dir->i_sb->u.ext3_sb.s_hash_seed;
227 -       if (dentry)
228 -               ext3fs_dirhash(dentry->d_name.name, dentry->d_name.len, hinfo);
229 +       if (name)
230 +               ext3fs_dirhash(name->name, name->len, hinfo);
231         hash = hinfo->hash;
232  
233         if (root->info.unused_flags & 1) {
234 @@ -356,7 +479,19 @@
235                 goto fail;
236         }
237  
238 +repeat:
239 +       curidx = 0;
240 +       entries = (struct dx_entry *) (((char *)&root->info) +
241 +                                      root->info.info_length);
242 +       assert(dx_get_limit(entries) == dx_root_limit(dir,
243 +                                                     root->info.info_length));
244 +       dxtrace (printk("Look up %x", hash));
245 +       dx_lock_bh(bh);
246 +       /* indirect must be initialized under bh lock because
247 +        * 2nd level creation procedure may change it and dx_probe()
248 +        * will suggest htree is still single-level -bzzz */
249         if ((indirect = root->info.indirect_levels) > 1) {
250 +               dx_unlock_bh(bh);
251                 ext3_warning(dir->i_sb, __FUNCTION__,
252                              "Unimplemented inode hash depth: %#06x",
253                              root->info.indirect_levels);
254 @@ -364,56 +499,46 @@
255                 *err = ERR_BAD_DX_DIR;
256                 goto fail;
257         }
258 -
259 -       entries = (struct dx_entry *) (((char *)&root->info) +
260 -                                      root->info.info_length);
261 -       assert(dx_get_limit(entries) == dx_root_limit(dir,
262 -                                                     root->info.info_length));
263 -       dxtrace (printk("Look up %x", hash));
264 +       
265         while (1)
266         {
267 -               count = dx_get_count(entries);
268 -               assert (count && count <= dx_get_limit(entries));
269 -               p = entries + 1;
270 -               q = entries + count - 1;
271 -               while (p <= q)
272 -               {
273 -                       m = p + (q - p)/2;
274 -                       dxtrace(printk("."));
275 -                       if (dx_get_hash(m) > hash)
276 -                               q = m - 1;
277 -                       else
278 -                               p = m + 1;
279 -               }
280 -
281 -               if (0) // linear search cross check
282 -               {
283 -                       unsigned n = count - 1;
284 -                       at = entries;
285 -                       while (n--)
286 -                       {
287 -                               dxtrace(printk(","));
288 -                               if (dx_get_hash(++at) > hash)
289 -                               {
290 -                                       at--;
291 -                                       break;
292 -                               }
293 -                       }
294 -                       assert (at == p - 1);
295 -               }
296 -
297 -               at = p - 1;
298 -               dxtrace(printk(" %x->%u\n", at == entries? 0: dx_get_hash(at), dx_get_block(at)));
299 +               at = dx_find_position(entries, hinfo->hash);
300 +               dxtrace(printk(" %x->%u\n",
301 +                               at == entries? 0: dx_get_hash(at),
302 +                               dx_get_block(at)));
303                 frame->bh = bh;
304                 frame->entries = entries;
305                 frame->at = at;
306 -               if (!indirect--) return frame;
307 -               if (!(bh = ext3_bread (NULL,dir, dx_get_block(at), 0, err)))
308 +               frame->curidx = curidx;
309 +               frame->leaf = dx_get_block(at);
310 +               if (!indirect--) {
311 +                       dx_unlock_bh(bh);
312 +                       return frame;
313 +               }
314 +               
315 +               /* step into next htree level */
316 +               curidx = dx_get_block(at);
317 +               dx_unlock_bh(bh);
318 +               if (!(bh = ext3_bread (NULL,dir, frame->leaf, 0, err)))
319                         goto fail2;
320 +               
321 +               dx_lock_bh(bh);
322 +               /* splitting may change root index block and move
323 +                * hash we're looking for into another index block
324 +                * so, we have to check this situation and repeat
325 +                * from begining if path got changed -bzzz */
326 +               if (!dx_check_path(frame, hash)) {
327 +                       dx_unlock_bh(bh);
328 +                       bh = frame->bh;
329 +                       indirect++;
330 +                       goto repeat;
331 +               }
332 +               
333                 at = entries = ((struct dx_node *) bh->b_data)->entries;
334                 assert (dx_get_limit(entries) == dx_node_limit (dir));
335                 frame++;
336         }
337 +       dx_unlock_bh(bh);
338  fail2:
339         while (frame >= frame_in) {
340                 brelse(frame->bh);
341 @@ -427,8 +552,7 @@
342  {
343         if (frames[0].bh == NULL)
344                 return;
345 -
346 -       if (((struct dx_root *) frames[0].bh->b_data)->info.indirect_levels)
347 +       if (frames[1].bh != NULL)
348                 brelse(frames[1].bh);
349         brelse(frames[0].bh);
350  }
351 @@ -470,8 +594,10 @@
352          * nodes need to be read.
353          */
354         while (1) {
355 -               if (++(p->at) < p->entries + dx_get_count(p->entries))
356 +               if (++(p->at) < p->entries + dx_get_count(p->entries)) {
357 +                       p->leaf = dx_get_block(p->at);
358                         break;
359 +               }
360                 if (p == frames)
361                         return 0;
362                 num_frames++;
363 @@ -497,13 +623,17 @@
364          * block so no check is necessary
365          */
366         while (num_frames--) {
367 -               if (!(bh = ext3_bread(NULL, dir, dx_get_block(p->at),
368 -                                     0, err)))
369 +               u32 idx;
370 +               
371 +               idx = p->leaf = dx_get_block(p->at);
372 +               if (!(bh = ext3_bread(NULL, dir, idx, 0, err)))
373                         return -1; /* Failure */
374                 p++;
375                 brelse (p->bh);
376                 p->bh = bh;
377                 p->at = p->entries = ((struct dx_node *) bh->b_data)->entries;
378 +               p->curidx = idx;
379 +               p->leaf = dx_get_block(p->at);
380         }
381         return 1;
382  }
383 @@ -543,7 +673,7 @@
384         dir = dir_file->f_dentry->d_inode;
385         hinfo.hash = start_hash;
386         hinfo.minor_hash = 0;
387 -       frame = dx_probe(0, dir_file->f_dentry->d_inode, &hinfo, frames, &err);
388 +       frame = dx_probe(NULL, dir_file->f_dentry->d_inode, &hinfo, frames, &err);
389         if (!frame)
390                 return err;
391  
392 @@ -625,7 +755,8 @@
393                         count++;
394                 }
395                 /* XXX: do we need to check rec_len == 0 case? -Chris */
396 -               de = (struct ext3_dir_entry_2 *) ((char *) de + le16_to_cpu(de->rec_len));
397 +               de = (struct ext3_dir_entry_2 *)((char*)de +
398 +                               le16_to_cpu(de->rec_len));
399         }
400         return count;
401  }
402 @@ -658,7 +789,8 @@
403         } while(more);
404  }
405  
406 -static void dx_insert_block(struct dx_frame *frame, u32 hash, u32 block)
407 +static void dx_insert_block(struct inode *dir, struct dx_frame *frame,
408 +                       u32 hash, u32 block, u32 idx)
409  {
410         struct dx_entry *entries = frame->entries;
411         struct dx_entry *old = frame->at, *new = old + 1;
412 @@ -670,6 +802,7 @@
413         dx_set_hash(new, hash);
414         dx_set_block(new, block);
415         dx_set_count(entries, count + 1);
416 +       
417  }
418  #endif
419  
420 @@ -752,7 +885,8 @@
421  
422         
423  static struct buffer_head * ext3_find_entry (struct dentry *dentry,
424 -                                       struct ext3_dir_entry_2 ** res_dir)
425 +                                       struct ext3_dir_entry_2 ** res_dir,
426 +                                       int rwlock, void **lock)
427  {
428         struct super_block * sb;
429         struct buffer_head * bh_use[NAMEI_RA_SIZE];
430 @@ -768,6 +902,7 @@
431         int namelen;
432         const u8 *name;
433         unsigned blocksize;
434 +       int do_not_use_dx = 0;
435  
436         *res_dir = NULL;
437         sb = dir->i_sb;
438 @@ -776,9 +911,10 @@
439         name = dentry->d_name.name;
440         if (namelen > EXT3_NAME_LEN)
441                 return NULL;
442 +repeat:
443  #ifdef CONFIG_EXT3_INDEX
444         if (is_dx(dir)) {
445 -               bh = ext3_dx_find_entry(dentry, res_dir, &err);
446 +               bh = ext3_dx_find_entry(dentry, res_dir, &err, rwlock, lock);
447                 /*
448                  * On success, or if the error was file not found,
449                  * return.  Otherwise, fall back to doing a search the
450 @@ -787,8 +923,14 @@
451                 if (bh || (err != ERR_BAD_DX_DIR))
452                         return bh;
453                 dxtrace(printk("ext3_find_entry: dx failed, falling back\n"));
454 +               do_not_use_dx = 1;
455         }
456  #endif
457 +       *lock = ext3_lock_htree(dir, 0, rwlock);
458 +       if (is_dx(dir) && !do_not_use_dx) {
459 +               ext3_unlock_htree(dir, *lock);
460 +               goto repeat;
461 +       }
462         nblocks = dir->i_size >> EXT3_BLOCK_SIZE_BITS(sb);
463         start = EXT3_I(dir)->i_dir_start_lookup;
464         if (start >= nblocks)
465 @@ -860,12 +1002,17 @@
466         /* Clean up the read-ahead blocks */
467         for (; ra_ptr < ra_max; ra_ptr++)
468                 brelse (bh_use[ra_ptr]);
469 +       if (!ret) {
470 +               ext3_unlock_htree(dir, *lock);
471 +               *lock = NULL;
472 +       }
473         return ret;
474  }
475  
476  #ifdef CONFIG_EXT3_INDEX
477  static struct buffer_head * ext3_dx_find_entry(struct dentry *dentry,
478 -                      struct ext3_dir_entry_2 **res_dir, int *err)
479 +                      struct ext3_dir_entry_2 **res_dir, int *err,
480 +                      int rwlock, void **lock)
481  {
482         struct super_block * sb;
483         struct dx_hash_info     hinfo;
484 @@ -880,11 +1027,22 @@
485         struct inode *dir = dentry->d_parent->d_inode;
486         
487         sb = dir->i_sb;
488 -       if (!(frame = dx_probe (dentry, 0, &hinfo, frames, err)))
489 +repeat:
490 +       if (!(frame = dx_probe (&dentry->d_name, dir, &hinfo, frames, err)))
491                 return NULL;
492 +       
493 +       *lock = ext3_lock_htree(dir, frame->leaf, rwlock);
494 +       /* while locking leaf we just found may get splitted
495 +        * so, we need another leaf. check this */
496 +       if (!dx_check_full_path(frames, &hinfo)) {
497 +               ext3_unlock_htree(dir, *lock);
498 +               dx_release(frames);
499 +               goto repeat;
500 +       }
501 +
502         hash = hinfo.hash;
503         do {
504 -               block = dx_get_block(frame->at);
505 +               block = frame->leaf;
506                 if (!(bh = ext3_bread (NULL,dir, block, 0, err)))
507                         goto errout;
508                 de = (struct ext3_dir_entry_2 *) bh->b_data;
509 @@ -918,6 +1076,8 @@
510         *err = -ENOENT;
511  errout:
512         dxtrace(printk("%s not found\n", name));
513 +       ext3_unlock_htree(dir, *lock);
514 +       *lock = NULL;
515         dx_release (frames);
516         return NULL;
517  }
518 @@ -928,6 +1088,7 @@
519         struct inode * inode;
520         struct ext3_dir_entry_2 * de;
521         struct buffer_head * bh;
522 +    void *lock = NULL;
523  
524         if (dentry->d_name.len > EXT3_NAME_LEN)
525                 return ERR_PTR(-ENAMETOOLONG);
526 @@ -935,10 +1096,11 @@
527         if (ext3_check_for_iopen(dir, dentry))
528                 return NULL;
529  
530 -       bh = ext3_find_entry(dentry, &de);
531 +       bh = ext3_find_entry(dentry, &de, 0, &lock);
532         inode = NULL;
533         if (bh) {
534                 unsigned long ino = le32_to_cpu(de->inode);
535 +               ext3_unlock_htree(dir, lock);
536                 brelse (bh);
537                 inode = iget(dir->i_sb, ino);
538  
539 @@ -975,7 +1137,8 @@
540         unsigned rec_len = 0;
541  
542         while (count--) {
543 -               struct ext3_dir_entry_2 *de = (struct ext3_dir_entry_2 *) (from + map->offs);
544 +               struct ext3_dir_entry_2 *de =
545 +                       (struct ext3_dir_entry_2 *) (from + map->offs);
546                 rec_len = EXT3_DIR_REC_LEN(de->name_len);
547                 memcpy (to, de, rec_len);
548                 ((struct ext3_dir_entry_2 *) to)->rec_len = rec_len;
549 @@ -988,7 +1151,8 @@
550  
551  static struct ext3_dir_entry_2* dx_pack_dirents(char *base, int size)
552  {
553 -       struct ext3_dir_entry_2 *next, *to, *prev, *de = (struct ext3_dir_entry_2 *) base;
554 +       struct ext3_dir_entry_2 *next, *to, *prev;
555 +       struct ext3_dir_entry_2 *de = (struct ext3_dir_entry_2 *) base;
556         unsigned rec_len = 0;
557  
558         prev = to = de;
559 @@ -1010,7 +1174,8 @@
560  
561  static struct ext3_dir_entry_2 *do_split(handle_t *handle, struct inode *dir,
562                         struct buffer_head **bh,struct dx_frame *frame,
563 -                       struct dx_hash_info *hinfo, int *error)
564 +                       struct dx_hash_info *hinfo, void **target,
565 +                       int *error)
566  {
567         unsigned blocksize = dir->i_sb->s_blocksize;
568         unsigned count, continued;
569 @@ -1057,23 +1222,30 @@
570         hash2 = map[split].hash;
571         continued = hash2 == map[split - 1].hash;
572         dxtrace(printk("Split block %i at %x, %i/%i\n",
573 -               dx_get_block(frame->at), hash2, split, count-split));
574 -
575 +               frame->leaf, hash2, split, count-split));
576 +       
577         /* Fancy dance to stay within two buffers */
578         de2 = dx_move_dirents(data1, data2, map + split, count - split);
579         de = dx_pack_dirents(data1,blocksize);
580         de->rec_len = cpu_to_le16(data1 + blocksize - (char *) de);
581         de2->rec_len = cpu_to_le16(data2 + blocksize - (char *) de2);
582 -       dxtrace(dx_show_leaf (hinfo, (struct ext3_dir_entry_2 *) data1, blocksize, 1));
583 -       dxtrace(dx_show_leaf (hinfo, (struct ext3_dir_entry_2 *) data2, blocksize, 1));
584 +       dxtrace(dx_show_leaf(hinfo,(struct ext3_dir_entry_2*) data1, blocksize, 1));
585 +       dxtrace(dx_show_leaf(hinfo,(struct ext3_dir_entry_2*) data2, blocksize, 1));
586  
587         /* Which block gets the new entry? */
588 +       *target = NULL;
589         if (hinfo->hash >= hash2)
590         {
591                 swap(*bh, bh2);
592                 de = de2;
593 -       }
594 -       dx_insert_block (frame, hash2 + continued, newblock);
595 +
596 +               /* entry will be stored into new block
597 +                * we have to lock it before add_dirent_to_buf */
598 +               *target = ext3_lock_htree(dir, newblock, 1);
599 +       }
600 +       dx_lock_bh(frame->bh);
601 +       dx_insert_block (dir, frame, hash2 + continued, newblock, frame->curidx);
602 +       dx_unlock_bh(frame->bh);
603         err = ext3_journal_dirty_metadata (handle, bh2);
604         if (err)
605                 goto journal_error;
606 @@ -1147,7 +1319,8 @@
607         nlen = EXT3_DIR_REC_LEN(de->name_len);
608         rlen = le16_to_cpu(de->rec_len);
609         if (de->inode) {
610 -               struct ext3_dir_entry_2 *de1 = (struct ext3_dir_entry_2 *)((char *)de + nlen);
611 +               struct ext3_dir_entry_2 *de1 =
612 +                       (struct ext3_dir_entry_2 *)((char *)de + nlen);
613                 de1->rec_len = cpu_to_le16(rlen - nlen);
614                 de->rec_len = cpu_to_le16(nlen);
615                 de = de1;
616 @@ -1205,7 +1378,8 @@
617         unsigned        blocksize;
618         struct dx_hash_info hinfo;
619         u32             block;
620 -               
621 +       void            *lock, *new_lock;
622 +
623         blocksize =  dir->i_sb->s_blocksize;
624         dxtrace(printk("Creating index\n"));
625         retval = ext3_journal_get_write_access(handle, bh);
626 @@ -1216,7 +1390,6 @@
627         }
628         root = (struct dx_root *) bh->b_data;
629                 
630 -       EXT3_I(dir)->i_flags |= EXT3_INDEX_FL;
631         bh2 = ext3_append (handle, dir, &block, &retval);
632         if (!(bh2)) {
633                 brelse(bh);
634 @@ -1224,6 +1397,8 @@
635         }
636         data1 = bh2->b_data;
637  
638 +       lock = ext3_lock_htree(dir, block, 1);
639 +
640         /* The 0th block becomes the root, move the dirents out */
641         de = (struct ext3_dir_entry_2 *) &root->dotdot;
642         de = (struct ext3_dir_entry_2 *) ((char *)de + de->rec_len);
643 @@ -1253,13 +1428,25 @@
644         frame->entries = entries;
645         frame->at = entries;
646         frame->bh = bh;
647 +       frame->curidx = 0;
648 +       frame->leaf = 0;
649 +       frame[1].bh = NULL;
650         bh = bh2;
651 -       de = do_split(handle,dir, &bh, frame, &hinfo, &retval);
652 +       de = do_split(handle,dir, &bh, frame, &hinfo, &new_lock, &retval);
653         dx_release (frames);
654         if (!(de))
655 -               return retval;
656 +               goto cleanup;
657 +
658 +       retval = add_dirent_to_buf(handle, dentry, inode, de, bh);
659 +cleanup:
660 +       if (new_lock)
661 +               ext3_unlock_htree(dir, new_lock);
662 +       /* we mark directory indexed in order to
663 +        * avoid races while htree being created -bzzz */
664 +       EXT3_I(dir)->i_flags |= EXT3_INDEX_FL;
665 +       ext3_unlock_htree(dir, lock);
666  
667 -       return add_dirent_to_buf(handle, dentry, inode, de, bh);
668 +       return retval;
669  }
670  #endif
671  
672 @@ -1288,11 +1475,13 @@
673         unsigned blocksize;
674         unsigned nlen, rlen;
675         u32 block, blocks;
676 +       void *lock;
677  
678         sb = dir->i_sb;
679         blocksize = sb->s_blocksize;
680         if (!dentry->d_name.len)
681                 return -EINVAL;
682 +repeat:
683  #ifdef CONFIG_EXT3_INDEX
684         if (is_dx(dir)) {
685                 retval = ext3_dx_add_entry(handle, dentry, inode);
686 @@ -1303,36 +1492,53 @@
687                 ext3_mark_inode_dirty(handle, dir);
688         }
689  #endif
690 +       lock = ext3_lock_htree(dir, 0, 1);
691 +       if (is_dx(dir)) {
692 +               /* we got lock for block 0
693 +                * probably previous holder of the lock
694 +                * created htree -bzzz */
695 +               ext3_unlock_htree(dir, lock);
696 +               goto repeat;
697 +       }
698 +       
699         blocks = dir->i_size >> sb->s_blocksize_bits;
700         for (block = 0, offset = 0; block < blocks; block++) {
701                 bh = ext3_bread(handle, dir, block, 0, &retval);
702 -               if(!bh)
703 +               if(!bh) {
704 +                       ext3_unlock_htree(dir, lock);
705                         return retval;
706 +               }
707                 retval = add_dirent_to_buf(handle, dentry, inode, 0, bh);
708 -               if (retval != -ENOSPC)
709 +               if (retval != -ENOSPC) {
710 +                       ext3_unlock_htree(dir, lock);
711                         return retval;
712 +               }
713  
714  #ifdef CONFIG_EXT3_INDEX
715                 if (blocks == 1 && !dx_fallback &&
716 -                   EXT3_HAS_COMPAT_FEATURE(sb, EXT3_FEATURE_COMPAT_DIR_INDEX))
717 -                       return make_indexed_dir(handle, dentry, inode, bh);
718 +                   EXT3_HAS_COMPAT_FEATURE(sb, EXT3_FEATURE_COMPAT_DIR_INDEX)) {
719 +                       retval = make_indexed_dir(handle, dentry, inode, bh);
720 +                       ext3_unlock_htree(dir, lock);
721 +                       return retval;
722 +               }
723  #endif
724                 brelse(bh);
725         }
726         bh = ext3_append(handle, dir, &block, &retval);
727 -       if (!bh)
728 +       if (!bh) {
729 +               ext3_unlock_htree(dir, lock);
730                 return retval;
731 +       }
732         de = (struct ext3_dir_entry_2 *) bh->b_data;
733         de->inode = 0;
734         de->rec_len = cpu_to_le16(rlen = blocksize);
735         nlen = 0;
736 -       return add_dirent_to_buf(handle, dentry, inode, de, bh);
737 +       retval = add_dirent_to_buf(handle, dentry, inode, de, bh);
738 +       ext3_unlock_htree(dir, lock);
739 +       return retval;
740  }
741  
742  #ifdef CONFIG_EXT3_INDEX
743 -/*
744 - * Returns 0 for success, or a negative error value
745 - */
746  static int ext3_dx_add_entry(handle_t *handle, struct dentry *dentry,
747                              struct inode *inode)
748  {
749 @@ -1344,15 +1550,28 @@
750         struct super_block * sb = dir->i_sb;
751         struct ext3_dir_entry_2 *de;
752         int err;
753 -
754 -       frame = dx_probe(dentry, 0, &hinfo, frames, &err);
755 +       int curidx;
756 +       void *idx_lock, *leaf_lock, *newleaf_lock;
757 +       
758 +repeat:
759 +       frame = dx_probe(&dentry->d_name, dir, &hinfo, frames, &err);
760         if (!frame)
761                 return err;
762 -       entries = frame->entries;
763 -       at = frame->at;
764  
765 -       if (!(bh = ext3_bread(handle,dir, dx_get_block(frame->at), 0, &err)))
766 +       /* we're going to chage leaf, so lock it first */
767 +       leaf_lock = ext3_lock_htree(dir, frame->leaf, 1);
768 +
769 +       /* while locking leaf we just found may get splitted
770 +        * so we need to check this */
771 +       if (!dx_check_full_path(frames, &hinfo)) {
772 +               ext3_unlock_htree(dir, leaf_lock);
773 +               dx_release(frames);
774 +               goto repeat;
775 +       }
776 +       if (!(bh = ext3_bread(handle,dir, frame->leaf, 0, &err))) {
777 +               printk("can't ext3_bread(%d) = %d\n", (int) frame->leaf, err);
778                 goto cleanup;
779 +       }
780  
781         BUFFER_TRACE(bh, "get_write_access");
782         err = ext3_journal_get_write_access(handle, bh);
783 @@ -1365,6 +1584,35 @@
784                 goto cleanup;
785         }
786  
787 +       /* our leaf has no enough space. hence, we have to
788 +        * split it. so lock index for this leaf first */
789 +       curidx = frame->curidx;
790 +       idx_lock = ext3_lock_htree(dir, curidx, 1);
791 +
792 +       /* now check did path get changed? */
793 +       dx_release(frames);
794 +
795 +       frame = dx_probe(&dentry->d_name, dentry->d_parent->d_inode,
796 +                       &hinfo, frames, &err);
797 +       if (!frame) {
798 +               /* FIXME: error handling here */
799 +               brelse(bh);
800 +               ext3_unlock_htree(dir, idx_lock);
801 +               return err;
802 +       }
803 +       
804 +       if (frame->curidx != curidx) {
805 +               /* path has been changed. we have to drop old lock
806 +                * and repeat */
807 +               brelse(bh);
808 +               ext3_unlock_htree(dir, idx_lock);
809 +               ext3_unlock_htree(dir, leaf_lock);
810 +               dx_release(frames);
811 +               goto repeat;
812 +       }
813 +       entries = frame->entries;
814 +       at = frame->at;
815 +
816         /* Block full, should compress but for now just split */
817         dxtrace(printk("using %u of %u node entries\n",
818                        dx_get_count(entries), dx_get_limit(entries)));
819 @@ -1376,7 +1624,8 @@
820                 struct dx_entry *entries2;
821                 struct dx_node *node2;
822                 struct buffer_head *bh2;
823 -
824 +               void *nb_lock;
825 +               
826                 if (levels && (dx_get_count(frames->entries) ==
827                                dx_get_limit(frames->entries))) {
828                         ext3_warning(sb, __FUNCTION__,
829 @@ -1387,6 +1636,7 @@
830                 bh2 = ext3_append (handle, dir, &newblock, &err);
831                 if (!(bh2))
832                         goto cleanup;
833 +               nb_lock = ext3_lock_htree(dir, newblock, 1);
834                 node2 = (struct dx_node *)(bh2->b_data);
835                 entries2 = node2->entries;
836                 node2->fake.rec_len = cpu_to_le16(sb->s_blocksize);
837 @@ -1398,27 +1648,73 @@
838                 if (levels) {
839                         unsigned icount1 = icount/2, icount2 = icount - icount1;
840                         unsigned hash2 = dx_get_hash(entries + icount1);
841 +                       void *ri_lock;
842 +
843 +                       /* we have to protect root htree index against
844 +                        * another dx_add_entry() which would want to
845 +                        * split it too -bzzz */
846 +                       ri_lock = ext3_lock_htree(dir, 0, 1);
847 +
848 +                       /* as root index block blocked we must repeat
849 +                        * searching for current position of our 2nd index -bzzz */
850 +                       dx_lock_bh(frame->bh);
851 +                       frames->at = dx_find_position(frames->entries, hinfo.hash);
852 +                       dx_unlock_bh(frame->bh);
853 +                       
854                         dxtrace(printk("Split index %i/%i\n", icount1, icount2));
855 -                               
856 -                       BUFFER_TRACE(frame->bh, "get_write_access"); /* index root */
857 +       
858 +                       BUFFER_TRACE(frame->bh, "get_write_access");
859                         err = ext3_journal_get_write_access(handle,
860                                                              frames[0].bh);
861                         if (err)
862                                 goto journal_error;
863 -                               
864 +                       
865 +                       /* copy index into new one */
866                         memcpy ((char *) entries2, (char *) (entries + icount1),
867                                 icount2 * sizeof(struct dx_entry));
868 -                       dx_set_count (entries, icount1);
869                         dx_set_count (entries2, icount2);
870                         dx_set_limit (entries2, dx_node_limit(dir));
871  
872                         /* Which index block gets the new entry? */
873                         if (at - entries >= icount1) {
874 +                               /* unlock index we won't use */
875 +                               ext3_unlock_htree(dir, idx_lock);
876 +                               idx_lock = nb_lock;
877                                 frame->at = at = at - entries - icount1 + entries2;
878 -                               frame->entries = entries = entries2;
879 +                               frame->entries = entries2;
880 +                               frame->curidx = curidx = newblock;
881                                 swap(frame->bh, bh2);
882 +                       } else {
883 +                               /* we'll use old index,so new one may be freed */
884 +                               ext3_unlock_htree(dir, nb_lock);
885                         }
886 -                       dx_insert_block (frames + 0, hash2, newblock);
887 +               
888 +                       /* NOTE: very subtle piece of code
889 +                        * competing dx_probe() may find 2nd level index in root
890 +                        * index, then we insert new index here and set new count
891 +                        * in that 2nd level index. so, dx_probe() may see 2nd
892 +                        * level index w/o hash it looks for. the solution is
893 +                        * to check root index after we locked just founded 2nd
894 +                        * level index -bzzz */
895 +                       dx_lock_bh(frames[0].bh);
896 +                       dx_insert_block (dir, frames + 0, hash2, newblock, 0);
897 +                       dx_unlock_bh(frames[0].bh);
898 +                       
899 +                       /* now old and new 2nd level index blocks contain
900 +                        * all pointers, so dx_probe() may find it in the both.
901 +                        * it's OK -bzzz */
902 +                       
903 +                       dx_lock_bh(frame->bh);
904 +                       dx_set_count(entries, icount1);
905 +                       dx_unlock_bh(frame->bh);
906 +
907 +                       /* now old 2nd level index block points to first half
908 +                        * of leafs. it's importand that dx_probe() must
909 +                        * check root index block for changes under
910 +                        * dx_lock_bh(frame->bh) -bzzz */
911 +
912 +                       ext3_unlock_htree(dir, ri_lock);
913 +               
914                         dxtrace(dx_show_index ("node", frames[1].entries));
915                         dxtrace(dx_show_index ("node",
916                                ((struct dx_node *) bh2->b_data)->entries));
917 @@ -1427,38 +1723,61 @@
918                                 goto journal_error;
919                         brelse (bh2);
920                 } else {
921 +                       unsigned long leaf = frame->leaf;
922 +
923                         dxtrace(printk("Creating second level index...\n"));
924                         memcpy((char *) entries2, (char *) entries,
925                                icount * sizeof(struct dx_entry));
926                         dx_set_limit(entries2, dx_node_limit(dir));
927  
928                         /* Set up root */
929 +                       dx_lock_bh(frames[0].bh);
930                         dx_set_count(entries, 1);
931                         dx_set_block(entries + 0, newblock);
932                         ((struct dx_root *) frames[0].bh->b_data)->info.indirect_levels = 1;
933 +                       dx_unlock_bh(frames[0].bh);
934  
935                         /* Add new access path frame */
936                         frame = frames + 1;
937                         frame->at = at = at - entries + entries2;
938                         frame->entries = entries = entries2;
939                         frame->bh = bh2;
940 +                       frame->curidx = newblock;
941 +                       frame->leaf = leaf;
942                         err = ext3_journal_get_write_access(handle,
943                                                              frame->bh);
944                         if (err)
945                                 goto journal_error;
946 +
947 +                       /* first level index was root. it's already initialized */
948 +                       /* we my unlock it now */
949 +                       ext3_unlock_htree(dir, idx_lock);
950 +
951 +                       /* current index is just created 2nd level index */
952 +                       curidx = newblock;
953 +                       idx_lock = nb_lock;
954                 }
955                 ext3_journal_dirty_metadata(handle, frames[0].bh);
956         }
957 -       de = do_split(handle, dir, &bh, frame, &hinfo, &err);
958 +       de = do_split(handle, dir, &bh, frame, &hinfo, &newleaf_lock, &err);
959         if (!de)
960                 goto cleanup;
961 +
962 +       /* index splitted */
963 +       ext3_unlock_htree(dir, idx_lock);
964 +       
965         err = add_dirent_to_buf(handle, dentry, inode, de, bh);
966 +
967 +       if (newleaf_lock)
968 +               ext3_unlock_htree(dir, newleaf_lock);
969 +       
970         bh = 0;
971         goto cleanup;
972         
973  journal_error:
974         ext3_std_error(dir->i_sb, err);
975  cleanup:
976 +       ext3_unlock_htree(dir, leaf_lock);
977         if (bh)
978                 brelse(bh);
979         dx_release(frames);
980 @@ -1902,6 +2221,7 @@
981         struct buffer_head * bh;
982         struct ext3_dir_entry_2 * de;
983         handle_t *handle;
984 +       void *lock;
985  
986         handle = ext3_journal_start(dir, EXT3_DELETE_TRANS_BLOCKS);
987         if (IS_ERR(handle)) {
988 @@ -1909,7 +2229,7 @@
989         }
990  
991         retval = -ENOENT;
992 -       bh = ext3_find_entry (dentry, &de);
993 +       bh = ext3_find_entry (dentry, &de, 1, &lock);
994         if (!bh)
995                 goto end_rmdir;
996  
997 @@ -1920,14 +2240,19 @@
998         DQUOT_INIT(inode);
999  
1000         retval = -EIO;
1001 -       if (le32_to_cpu(de->inode) != inode->i_ino)
1002 +       if (le32_to_cpu(de->inode) != inode->i_ino) {
1003 +               ext3_unlock_htree(dir, lock);
1004                 goto end_rmdir;
1005 +       }
1006  
1007         retval = -ENOTEMPTY;
1008 -       if (!empty_dir (inode))
1009 +       if (!empty_dir (inode)) {
1010 +               ext3_unlock_htree(dir, lock);
1011                 goto end_rmdir;
1012 +       }
1013  
1014         retval = ext3_delete_entry(handle, dir, de, bh);
1015 +       ext3_unlock_htree(dir, lock);
1016         if (retval)
1017                 goto end_rmdir;
1018         if (inode->i_nlink != 2)
1019 @@ -1956,6 +2281,7 @@
1020         struct buffer_head * bh;
1021         struct ext3_dir_entry_2 * de;
1022         handle_t *handle;
1023 +       void *lock;
1024  
1025         handle = ext3_journal_start(dir, EXT3_DELETE_TRANS_BLOCKS);
1026         if (IS_ERR(handle)) {
1027 @@ -1966,7 +2292,7 @@
1028                 handle->h_sync = 1;
1029  
1030         retval = -ENOENT;
1031 -       bh = ext3_find_entry (dentry, &de);
1032 +       bh = ext3_find_entry (dentry, &de, 1, &lock);
1033         if (!bh)
1034                 goto end_unlink;
1035  
1036 @@ -1974,8 +2300,10 @@
1037         DQUOT_INIT(inode);
1038  
1039         retval = -EIO;
1040 -       if (le32_to_cpu(de->inode) != inode->i_ino)
1041 +       if (le32_to_cpu(de->inode) != inode->i_ino) {
1042 +               ext3_unlock_htree(dir, lock);
1043                 goto end_unlink;
1044 +       }
1045         
1046         if (!inode->i_nlink) {
1047                 ext3_warning (inode->i_sb, "ext3_unlink",
1048 @@ -1984,6 +2312,7 @@
1049                 inode->i_nlink = 1;
1050         }
1051         retval = ext3_delete_entry(handle, dir, de, bh);
1052 +       ext3_unlock_htree(dir, lock);
1053         if (retval)
1054                 goto end_unlink;
1055         dir->i_ctime = dir->i_mtime = CURRENT_TIME;
1056 @@ -2121,6 +2450,7 @@
1057         struct buffer_head * old_bh, * new_bh, * dir_bh;
1058         struct ext3_dir_entry_2 * old_de, * new_de;
1059         int retval;
1060 +       void *lock1 = NULL, *lock2 = NULL, *lock3 = NULL;
1061  
1062         old_bh = new_bh = dir_bh = NULL;
1063  
1064 @@ -2133,7 +2463,10 @@
1065         if (IS_SYNC(old_dir) || IS_SYNC(new_dir))
1066                 handle->h_sync = 1;
1067  
1068 -       old_bh = ext3_find_entry (old_dentry, &old_de);
1069 +       if (old_dentry->d_parent == new_dentry->d_parent)
1070 +               down(&EXT3_I(old_dentry->d_parent->d_inode)->i_rename_sem);
1071 +
1072 +       old_bh = ext3_find_entry (old_dentry, &old_de, 1, &lock1 /* FIXME */);
1073         /*
1074          *  Check for inode number is _not_ due to possible IO errors.
1075          *  We might rmdir the source, keep it as pwd of some process
1076 @@ -2146,7 +2479,7 @@
1077                 goto end_rename;
1078  
1079         new_inode = new_dentry->d_inode;
1080 -       new_bh = ext3_find_entry (new_dentry, &new_de);
1081 +       new_bh = ext3_find_entry (new_dentry, &new_de, 1, &lock2 /* FIXME */);
1082         if (new_bh) {
1083                 if (!new_inode) {
1084                         brelse (new_bh);
1085 @@ -2209,7 +2542,7 @@
1086                 struct buffer_head *old_bh2;
1087                 struct ext3_dir_entry_2 *old_de2;
1088                 
1089 -               old_bh2 = ext3_find_entry(old_dentry, &old_de2);
1090 +               old_bh2 = ext3_find_entry(old_dentry, &old_de2, 1, &lock3 /* FIXME */);
1091                 if (old_bh2) {
1092                         retval = ext3_delete_entry(handle, old_dir,
1093                                                    old_de2, old_bh2);
1094 @@ -2252,6 +2585,14 @@
1095         retval = 0;
1096  
1097  end_rename:
1098 +       if (lock1)
1099 +               ext3_unlock_htree(old_dentry->d_parent->d_inode, lock1);
1100 +       if (lock2)
1101 +               ext3_unlock_htree(new_dentry->d_parent->d_inode, lock2);
1102 +       if (lock3)
1103 +               ext3_unlock_htree(old_dentry->d_parent->d_inode, lock3);
1104 +       if (old_dentry->d_parent == new_dentry->d_parent)
1105 +               up(&EXT3_I(old_dentry->d_parent->d_inode)->i_rename_sem);
1106         brelse (dir_bh);
1107         brelse (old_bh);
1108         brelse (new_bh);
1109 @@ -2260,6 +2601,29 @@
1110  }
1111  
1112  /*
1113 + * this locking primitives are used to protect parts
1114 + * of dir's htree. protection unit is block: leaf or index
1115 + */
1116 +static inline void *ext3_lock_htree(struct inode *dir,
1117 +                                       unsigned long value, int rwlock)
1118 +{
1119 +       void *lock;
1120 +       
1121 +       if (!test_opt(dir->i_sb, PDIROPS))
1122 +               return NULL;
1123 +       lock = dynlock_lock(&EXT3_I(dir)->i_htree_lock, value, 1, GFP_KERNEL);
1124 +       return lock;
1125 +}
1126 +
1127 +static inline void ext3_unlock_htree(struct inode *dir,
1128 +                                       void *lock)
1129 +{
1130 +       if (!test_opt(dir->i_sb, PDIROPS) || !lock)
1131 +               return;
1132 +       dynlock_unlock(&EXT3_I(dir)->i_htree_lock, lock);
1133 +}
1134 +
1135 +/*
1136   * directories can handle most operations...
1137   */
1138  struct inode_operations ext3_dir_inode_operations = {
1139 Index: linux-2.4.20/fs/ext3/super.c
1140 ===================================================================
1141 --- linux-2.4.20.orig/fs/ext3/super.c   Wed Mar 17 15:37:09 2004
1142 +++ linux-2.4.20/fs/ext3/super.c        Wed Mar 17 15:37:10 2004
1143 @@ -796,6 +796,8 @@
1144                                 return 0;
1145                         }
1146                 }
1147 +               else if (!strcmp (this_char, "pdirops"))
1148 +                       set_opt (sbi->s_mount_opt, PDIROPS);
1149                 else if (!strcmp (this_char, "grpid") ||
1150                          !strcmp (this_char, "bsdgroups"))
1151                         set_opt (*mount_options, GRPID);
1152 @@ -822,6 +824,9 @@
1153                         if (want_numeric(value, "sb", sb_block))
1154                                 return 0;
1155                 }
1156 +               else if (!strcmp (this_char, "pdirops")) {
1157 +                       set_opt (sbi->s_mount_opt, PDIROPS);
1158 +               }
1159  #ifdef CONFIG_JBD_DEBUG
1160                 else if (!strcmp (this_char, "ro-after")) {
1161                         unsigned long v;
1162 @@ -985,6 +990,10 @@
1163                 ext3_check_inodes_bitmap (sb);
1164         }
1165  #endif
1166 +#ifdef S_PDIROPS
1167 +       if (test_opt (sb, PDIROPS))
1168 +               sb->s_flags |= S_PDIROPS;
1169 +#endif
1170         setup_ro_after(sb);
1171         return res;
1172  }
1173 @@ -1484,6 +1493,11 @@
1174                 test_opt(sb,DATA_FLAGS) == EXT3_MOUNT_ORDERED_DATA ? "ordered":
1175                 "writeback");
1176  
1177 +       if (test_opt(sb, PDIROPS)) {
1178 +               printk (KERN_INFO "EXT3-fs: mounted filesystem with parallel dirops\n");
1179 +               sb->s_flags |= S_PDIROPS;
1180 +       }
1181 +               
1182         return sb;
1183  
1184  failed_mount3:
1185 Index: linux-2.4.20/fs/ext3/inode.c
1186 ===================================================================
1187 --- linux-2.4.20.orig/fs/ext3/inode.c   Wed Mar 17 15:37:09 2004
1188 +++ linux-2.4.20/fs/ext3/inode.c        Wed Mar 17 15:37:10 2004
1189 @@ -2435,6 +2435,9 @@
1190         } else if (S_ISDIR(inode->i_mode)) {
1191                 inode->i_op = &ext3_dir_inode_operations;
1192                 inode->i_fop = &ext3_dir_operations;
1193 +               dynlock_init(&EXT3_I(inode)->i_htree_lock);
1194 +               sema_init(&EXT3_I(inode)->i_rename_sem, 1);
1195 +               sema_init(&EXT3_I(inode)->i_append_sem, 1);
1196         } else if (S_ISLNK(inode->i_mode)) {
1197                 if (ext3_inode_is_fast_symlink(inode))
1198                         inode->i_op = &ext3_fast_symlink_inode_operations;
1199 Index: linux-2.4.20/fs/ext3/ialloc.c
1200 ===================================================================
1201 --- linux-2.4.20.orig/fs/ext3/ialloc.c  Wed Mar 17 15:37:09 2004
1202 +++ linux-2.4.20/fs/ext3/ialloc.c       Wed Mar 17 15:37:10 2004
1203 @@ -601,6 +601,9 @@
1204                 return ERR_PTR(-EDQUOT);
1205         }
1206         ext3_debug ("allocating inode %lu\n", inode->i_ino);
1207 +       dynlock_init(&EXT3_I(inode)->i_htree_lock);
1208 +       sema_init(&EXT3_I(inode)->i_rename_sem, 1);
1209 +       sema_init(&EXT3_I(inode)->i_append_sem, 1);
1210         return inode;
1211  
1212  fail:
1213 Index: linux-2.4.20/include/linux/ext3_fs.h
1214 ===================================================================
1215 --- linux-2.4.20.orig/include/linux/ext3_fs.h   Wed Mar 17 15:37:09 2004
1216 +++ linux-2.4.20/include/linux/ext3_fs.h        Wed Mar 17 15:37:10 2004
1217 @@ -306,6 +306,7 @@
1218  /*
1219   * Mount flags
1220   */
1221 +#define EXT3_MOUNT_PDIROPS             0x800000/* Parallel dir operations */
1222  #define EXT3_MOUNT_CHECK               0x0001  /* Do mount-time checks */
1223  #define EXT3_MOUNT_GRPID               0x0004  /* Create files with directory's group */
1224  #define EXT3_MOUNT_DEBUG               0x0008  /* Some debugging messages */
1225 Index: linux-2.4.20/include/linux/ext3_fs_i.h
1226 ===================================================================
1227 --- linux-2.4.20.orig/include/linux/ext3_fs_i.h Thu Nov 22 11:46:19 2001
1228 +++ linux-2.4.20/include/linux/ext3_fs_i.h      Wed Mar 17 15:37:10 2004
1229 @@ -17,6 +17,7 @@
1230  #define _LINUX_EXT3_FS_I
1231  
1232  #include <linux/rwsem.h>
1233 +#include <linux/dynlocks.h>
1234  
1235  /*
1236   * second extended file system inode data in memory
1237 @@ -73,6 +74,11 @@
1238          * by other means, so we have truncate_sem.
1239          */
1240         struct rw_semaphore truncate_sem;
1241 +
1242 +       /* following fields for parallel directory operations -bzzz */
1243 +       struct dynlock i_htree_lock;
1244 +       struct semaphore i_append_sem;
1245 +       struct semaphore i_rename_sem;
1246  };
1247  
1248  #endif /* _LINUX_EXT3_FS_I */