Whamcloud - gitweb
Branch HEAD
[fs/lustre-release.git] / lustre / kernel_patches / patches / ext3-pdirops-2.6.7.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.6.7/fs/ext3/namei.c
10 ===================================================================
11 --- linux-2.6.7.orig/fs/ext3/namei.c    2004-08-26 17:12:39.000000000 +0400
12 +++ linux-2.6.7/fs/ext3/namei.c 2004-09-07 17:32:13.000000000 +0400
13 @@ -53,6 +53,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 @@ -60,6 +63,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 @@ -136,6 +141,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 @@ -144,6 +151,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 @@ -155,7 +186,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 @@ -167,15 +198,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, 
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 @@ -319,6 +353,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 @@ -328,19 +450,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 @@ -356,8 +479,8 @@
224         }
225         hinfo->hash_version = root->info.hash_version;
226         hinfo->seed = EXT3_SB(dir->i_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 @@ -369,7 +492,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 @@ -377,56 +512,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 @@ -440,8 +565,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 @@ -482,8 +606,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 @@ -509,13 +635,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 err; /* 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 @@ -602,7 +732,7 @@
384         }
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 @@ -674,7 +804,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 @@ -707,7 +838,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 @@ -719,6 +851,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 @@ -799,7 +932,8 @@
421   * to brelse() it when appropriate.
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 @@ -815,6 +949,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 @@ -823,9 +958,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 @@ -834,8 +970,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 @@ -908,12 +1050,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 @@ -928,11 +1075,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 @@ -967,6 +1125,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 @@ -977,14 +1137,16 @@
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  
527 -       bh = ext3_find_entry(dentry, &de);
528 +       bh = ext3_find_entry(dentry, &de, 0, &lock);
529         inode = NULL;
530         if (bh) {
531                 unsigned long ino = le32_to_cpu(de->inode);
532 +               ext3_unlock_htree(dir, lock);
533                 brelse (bh);
534                 inode = iget(dir->i_sb, ino);
535  
536 @@ -1006,17 +1168,19 @@
537         struct dentry dotdot;
538         struct ext3_dir_entry_2 * de;
539         struct buffer_head *bh;
540 +       void *lock = NULL;
541  
542         dotdot.d_name.name = "..";
543         dotdot.d_name.len = 2;
544         dotdot.d_parent = child; /* confusing, isn't it! */
545  
546 -       bh = ext3_find_entry(&dotdot, &de);
547 +       bh = ext3_find_entry(&dotdot, &de, 0, &lock);
548         inode = NULL;
549         if (!bh)
550                 return ERR_PTR(-ENOENT);
551         ino = le32_to_cpu(de->inode);
552         brelse(bh);
553 +       ext3_unlock_htree(child->d_inode, lock);
554         inode = iget(child->d_inode->i_sb, ino);
555  
556         if (!inode)
557 @@ -1055,7 +1219,8 @@
558         unsigned rec_len = 0;
559  
560         while (count--) {
561 -               struct ext3_dir_entry_2 *de = (struct ext3_dir_entry_2 *) (from + map->offs);
562 +               struct ext3_dir_entry_2 *de =
563 +                       (struct ext3_dir_entry_2 *) (from + map->offs);
564                 rec_len = EXT3_DIR_REC_LEN(de->name_len);
565                 memcpy (to, de, rec_len);
566                 ((struct ext3_dir_entry_2 *) to)->rec_len =
567 @@ -1069,7 +1234,8 @@
568  
569  static struct ext3_dir_entry_2* dx_pack_dirents(char *base, int size)
570  {
571 -       struct ext3_dir_entry_2 *next, *to, *prev, *de = (struct ext3_dir_entry_2 *) base;
572 +       struct ext3_dir_entry_2 *next, *to, *prev;
573 +       struct ext3_dir_entry_2 *de = (struct ext3_dir_entry_2 *) base;
574         unsigned rec_len = 0;
575  
576         prev = to = de;
577 @@ -1091,7 +1257,8 @@
578  
579  static struct ext3_dir_entry_2 *do_split(handle_t *handle, struct inode *dir,
580                         struct buffer_head **bh,struct dx_frame *frame,
581 -                       struct dx_hash_info *hinfo, int *error)
582 +                       struct dx_hash_info *hinfo, void **target,
583 +                       int *error)
584  {
585         unsigned blocksize = dir->i_sb->s_blocksize;
586         unsigned count, continued;
587 @@ -1138,23 +1305,30 @@
588         hash2 = map[split].hash;
589         continued = hash2 == map[split - 1].hash;
590         dxtrace(printk("Split block %i at %x, %i/%i\n",
591 -               dx_get_block(frame->at), hash2, split, count-split));
592 -
593 +               frame->leaf, hash2, split, count-split));
594 +       
595         /* Fancy dance to stay within two buffers */
596         de2 = dx_move_dirents(data1, data2, map + split, count - split);
597         de = dx_pack_dirents(data1,blocksize);
598         de->rec_len = cpu_to_le16(data1 + blocksize - (char *) de);
599         de2->rec_len = cpu_to_le16(data2 + blocksize - (char *) de2);
600 -       dxtrace(dx_show_leaf (hinfo, (struct ext3_dir_entry_2 *) data1, blocksize, 1));
601 -       dxtrace(dx_show_leaf (hinfo, (struct ext3_dir_entry_2 *) data2, blocksize, 1));
602 +       dxtrace(dx_show_leaf(hinfo,(struct ext3_dir_entry_2*) data1, blocksize, 1));
603 +       dxtrace(dx_show_leaf(hinfo,(struct ext3_dir_entry_2*) data2, blocksize, 1));
604  
605         /* Which block gets the new entry? */
606 +       *target = NULL;
607         if (hinfo->hash >= hash2)
608         {
609                 swap(*bh, bh2);
610                 de = de2;
611 -       }
612 -       dx_insert_block (frame, hash2 + continued, newblock);
613 +
614 +               /* entry will be stored into new block
615 +                * we have to lock it before add_dirent_to_buf */
616 +               *target = ext3_lock_htree(dir, newblock, 1);
617 +       }
618 +       dx_lock_bh(frame->bh);
619 +       dx_insert_block (dir, frame, hash2 + continued, newblock, frame->curidx);
620 +       dx_unlock_bh(frame->bh);
621         err = ext3_journal_dirty_metadata (handle, bh2);
622         if (err)
623                 goto journal_error;
624 @@ -1228,7 +1402,8 @@
625         nlen = EXT3_DIR_REC_LEN(de->name_len);
626         rlen = le16_to_cpu(de->rec_len);
627         if (de->inode) {
628 -               struct ext3_dir_entry_2 *de1 = (struct ext3_dir_entry_2 *)((char *)de + nlen);
629 +               struct ext3_dir_entry_2 *de1 =
630 +                       (struct ext3_dir_entry_2 *)((char *)de + nlen);
631                 de1->rec_len = cpu_to_le16(rlen - nlen);
632                 de->rec_len = cpu_to_le16(nlen);
633                 de = de1;
634 @@ -1287,6 +1462,7 @@
635         struct dx_hash_info hinfo;
636         u32             block;
637         struct fake_dirent *fde;
638 +       void            *lock, *new_lock;
639  
640         blocksize =  dir->i_sb->s_blocksize;
641         dxtrace(printk("Creating index\n"));
642 @@ -1306,6 +1482,8 @@
643         EXT3_I(dir)->i_flags |= EXT3_INDEX_FL;
644         data1 = bh2->b_data;
645  
646 +       lock = ext3_lock_htree(dir, block, 1);
647 +
648         /* The 0th block becomes the root, move the dirents out */
649         fde = &root->dotdot;
650         de = (struct ext3_dir_entry_2 *)((char *)fde + le16_to_cpu(fde->rec_len));
651 @@ -1335,13 +1513,25 @@
652         frame->entries = entries;
653         frame->at = entries;
654         frame->bh = bh;
655 +       frame->curidx = 0;
656 +       frame->leaf = 0;
657 +       frame[1].bh = NULL;
658         bh = bh2;
659 -       de = do_split(handle,dir, &bh, frame, &hinfo, &retval);
660 +       de = do_split(handle,dir, &bh, frame, &hinfo, &new_lock, &retval);
661         dx_release (frames);
662         if (!(de))
663 -               return retval;
664 +               goto cleanup;
665 +
666 +       retval = add_dirent_to_buf(handle, dentry, inode, de, bh);
667 +cleanup:
668 +       if (new_lock)
669 +               ext3_unlock_htree(dir, new_lock);
670 +       /* we mark directory indexed in order to
671 +        * avoid races while htree being created -bzzz */
672 +       EXT3_I(dir)->i_flags |= EXT3_INDEX_FL;
673 +       ext3_unlock_htree(dir, lock);
674  
675 -       return add_dirent_to_buf(handle, dentry, inode, de, bh);
676 +       return retval;
677  }
678  #endif
679  
680 @@ -1370,11 +1560,13 @@
681         unsigned blocksize;
682         unsigned nlen, rlen;
683         u32 block, blocks;
684 +       void *lock;
685  
686         sb = dir->i_sb;
687         blocksize = sb->s_blocksize;
688         if (!dentry->d_name.len)
689                 return -EINVAL;
690 +repeat:
691  #ifdef CONFIG_EXT3_INDEX
692         if (is_dx(dir)) {
693                 retval = ext3_dx_add_entry(handle, dentry, inode);
694 @@ -1385,36 +1577,53 @@
695                 ext3_mark_inode_dirty(handle, dir);
696         }
697  #endif
698 +       lock = ext3_lock_htree(dir, 0, 1);
699 +       if (is_dx(dir)) {
700 +               /* we got lock for block 0
701 +                * probably previous holder of the lock
702 +                * created htree -bzzz */
703 +               ext3_unlock_htree(dir, lock);
704 +               goto repeat;
705 +       }
706 +       
707         blocks = dir->i_size >> sb->s_blocksize_bits;
708         for (block = 0, offset = 0; block < blocks; block++) {
709                 bh = ext3_bread(handle, dir, block, 0, &retval);
710 -               if(!bh)
711 +               if(!bh) {
712 +                       ext3_unlock_htree(dir, lock);
713                         return retval;
714 +               }
715                 retval = add_dirent_to_buf(handle, dentry, inode, 0, bh);
716 -               if (retval != -ENOSPC)
717 +               if (retval != -ENOSPC) {
718 +                       ext3_unlock_htree(dir, lock);
719                         return retval;
720 +               }
721  
722  #ifdef CONFIG_EXT3_INDEX
723                 if (blocks == 1 && !dx_fallback &&
724 -                   EXT3_HAS_COMPAT_FEATURE(sb, EXT3_FEATURE_COMPAT_DIR_INDEX))
725 -                       return make_indexed_dir(handle, dentry, inode, bh);
726 +                   EXT3_HAS_COMPAT_FEATURE(sb, EXT3_FEATURE_COMPAT_DIR_INDEX)) {
727 +                       retval = make_indexed_dir(handle, dentry, inode, bh);
728 +                       ext3_unlock_htree(dir, lock);
729 +                       return retval;
730 +               }
731  #endif
732                 brelse(bh);
733         }
734         bh = ext3_append(handle, dir, &block, &retval);
735 -       if (!bh)
736 +       if (!bh) {
737 +               ext3_unlock_htree(dir, lock);
738                 return retval;
739 +       }
740         de = (struct ext3_dir_entry_2 *) bh->b_data;
741         de->inode = 0;
742         de->rec_len = cpu_to_le16(rlen = blocksize);
743         nlen = 0;
744 -       return add_dirent_to_buf(handle, dentry, inode, de, bh);
745 +       retval = add_dirent_to_buf(handle, dentry, inode, de, bh);
746 +       ext3_unlock_htree(dir, lock);
747 +       return retval;
748  }
749  
750  #ifdef CONFIG_EXT3_INDEX
751 -/*
752 - * Returns 0 for success, or a negative error value
753 - */
754  static int ext3_dx_add_entry(handle_t *handle, struct dentry *dentry,
755                              struct inode *inode)
756  {
757 @@ -1426,15 +1635,28 @@
758         struct super_block * sb = dir->i_sb;
759         struct ext3_dir_entry_2 *de;
760         int err;
761 -
762 -       frame = dx_probe(dentry, 0, &hinfo, frames, &err);
763 +       int curidx;
764 +       void *idx_lock, *leaf_lock, *newleaf_lock;
765 +       
766 +repeat:
767 +       frame = dx_probe(&dentry->d_name, dir, &hinfo, frames, &err);
768         if (!frame)
769                 return err;
770 -       entries = frame->entries;
771 -       at = frame->at;
772  
773 -       if (!(bh = ext3_bread(handle,dir, dx_get_block(frame->at), 0, &err)))
774 +       /* we're going to chage leaf, so lock it first */
775 +       leaf_lock = ext3_lock_htree(dir, frame->leaf, 1);
776 +
777 +       /* while locking leaf we just found may get splitted
778 +        * so we need to check this */
779 +       if (!dx_check_full_path(frames, &hinfo)) {
780 +               ext3_unlock_htree(dir, leaf_lock);
781 +               dx_release(frames);
782 +               goto repeat;
783 +       }
784 +       if (!(bh = ext3_bread(handle,dir, frame->leaf, 0, &err))) {
785 +               printk("can't ext3_bread(%d) = %d\n", (int) frame->leaf, err);
786                 goto cleanup;
787 +       }
788  
789         BUFFER_TRACE(bh, "get_write_access");
790         err = ext3_journal_get_write_access(handle, bh);
791 @@ -1447,6 +1669,35 @@
792                 goto cleanup;
793         }
794  
795 +       /* our leaf has no enough space. hence, we have to
796 +        * split it. so lock index for this leaf first */
797 +       curidx = frame->curidx;
798 +       idx_lock = ext3_lock_htree(dir, curidx, 1);
799 +
800 +       /* now check did path get changed? */
801 +       dx_release(frames);
802 +
803 +       frame = dx_probe(&dentry->d_name, dentry->d_parent->d_inode,
804 +                       &hinfo, frames, &err);
805 +       if (!frame) {
806 +               /* FIXME: error handling here */
807 +               brelse(bh);
808 +               ext3_unlock_htree(dir, idx_lock);
809 +               return err;
810 +       }
811 +       
812 +       if (frame->curidx != curidx) {
813 +               /* path has been changed. we have to drop old lock
814 +                * and repeat */
815 +               brelse(bh);
816 +               ext3_unlock_htree(dir, idx_lock);
817 +               ext3_unlock_htree(dir, leaf_lock);
818 +               dx_release(frames);
819 +               goto repeat;
820 +       }
821 +       entries = frame->entries;
822 +       at = frame->at;
823 +
824         /* Block full, should compress but for now just split */
825         dxtrace(printk("using %u of %u node entries\n",
826                        dx_get_count(entries), dx_get_limit(entries)));
827 @@ -1458,7 +1709,8 @@
828                 struct dx_entry *entries2;
829                 struct dx_node *node2;
830                 struct buffer_head *bh2;
831 -
832 +               void *nb_lock;
833 +               
834                 if (levels && (dx_get_count(frames->entries) ==
835                                dx_get_limit(frames->entries))) {
836                         ext3_warning(sb, __FUNCTION__,
837 @@ -1469,6 +1721,7 @@
838                 bh2 = ext3_append (handle, dir, &newblock, &err);
839                 if (!(bh2))
840                         goto cleanup;
841 +               nb_lock = ext3_lock_htree(dir, newblock, 1);
842                 node2 = (struct dx_node *)(bh2->b_data);
843                 entries2 = node2->entries;
844                 node2->fake.rec_len = cpu_to_le16(sb->s_blocksize);
845 @@ -1480,27 +1733,73 @@
846                 if (levels) {
847                         unsigned icount1 = icount/2, icount2 = icount - icount1;
848                         unsigned hash2 = dx_get_hash(entries + icount1);
849 -                       dxtrace(printk("Split index %i/%i\n", icount1, icount2));
850 +                       void *ri_lock;
851  
852 -                       BUFFER_TRACE(frame->bh, "get_write_access"); /* index root */
853 +                       /* we have to protect root htree index against
854 +                        * another dx_add_entry() which would want to
855 +                        * split it too -bzzz */
856 +                       ri_lock = ext3_lock_htree(dir, 0, 1);
857 +
858 +                       /* as root index block blocked we must repeat
859 +                        * searching for current position of our 2nd index -bzzz */
860 +                       dx_lock_bh(frame->bh);
861 +                       frames->at = dx_find_position(frames->entries, hinfo.hash);
862 +                       dx_unlock_bh(frame->bh);
863 +                       
864 +                       dxtrace(printk("Split index %i/%i\n", icount1, icount2));
865 +       
866 +                       BUFFER_TRACE(frame->bh, "get_write_access");
867                         err = ext3_journal_get_write_access(handle,
868                                                              frames[0].bh);
869                         if (err)
870                                 goto journal_error;
871  
872 +                       /* copy index into new one */
873                         memcpy ((char *) entries2, (char *) (entries + icount1),
874                                 icount2 * sizeof(struct dx_entry));
875 -                       dx_set_count (entries, icount1);
876                         dx_set_count (entries2, icount2);
877                         dx_set_limit (entries2, dx_node_limit(dir));
878  
879                         /* Which index block gets the new entry? */
880                         if (at - entries >= icount1) {
881 +                               /* unlock index we won't use */
882 +                               ext3_unlock_htree(dir, idx_lock);
883 +                               idx_lock = nb_lock;
884                                 frame->at = at = at - entries - icount1 + entries2;
885 -                               frame->entries = entries = entries2;
886 +                               frame->entries = entries2;
887 +                               frame->curidx = curidx = newblock;
888                                 swap(frame->bh, bh2);
889 +                       } else {
890 +                               /* we'll use old index,so new one may be freed */
891 +                               ext3_unlock_htree(dir, nb_lock);
892                         }
893 -                       dx_insert_block (frames + 0, hash2, newblock);
894 +               
895 +                       /* NOTE: very subtle piece of code
896 +                        * competing dx_probe() may find 2nd level index in root
897 +                        * index, then we insert new index here and set new count
898 +                        * in that 2nd level index. so, dx_probe() may see 2nd
899 +                        * level index w/o hash it looks for. the solution is
900 +                        * to check root index after we locked just founded 2nd
901 +                        * level index -bzzz */
902 +                       dx_lock_bh(frames[0].bh);
903 +                       dx_insert_block (dir, frames + 0, hash2, newblock, 0);
904 +                       dx_unlock_bh(frames[0].bh);
905 +                       
906 +                       /* now old and new 2nd level index blocks contain
907 +                        * all pointers, so dx_probe() may find it in the both.
908 +                        * it's OK -bzzz */
909 +                       
910 +                       dx_lock_bh(frame->bh);
911 +                       dx_set_count(entries, icount1);
912 +                       dx_unlock_bh(frame->bh);
913 +
914 +                       /* now old 2nd level index block points to first half
915 +                        * of leafs. it's importand that dx_probe() must
916 +                        * check root index block for changes under
917 +                        * dx_lock_bh(frame->bh) -bzzz */
918 +
919 +                       ext3_unlock_htree(dir, ri_lock);
920 +               
921                         dxtrace(dx_show_index ("node", frames[1].entries));
922                         dxtrace(dx_show_index ("node",
923                                ((struct dx_node *) bh2->b_data)->entries));
924 @@ -1509,38 +1808,61 @@
925                                 goto journal_error;
926                         brelse (bh2);
927                 } else {
928 +                       unsigned long leaf = frame->leaf;
929 +
930                         dxtrace(printk("Creating second level index...\n"));
931                         memcpy((char *) entries2, (char *) entries,
932                                icount * sizeof(struct dx_entry));
933                         dx_set_limit(entries2, dx_node_limit(dir));
934  
935                         /* Set up root */
936 +                       dx_lock_bh(frames[0].bh);
937                         dx_set_count(entries, 1);
938                         dx_set_block(entries + 0, newblock);
939                         ((struct dx_root *) frames[0].bh->b_data)->info.indirect_levels = 1;
940 +                       dx_unlock_bh(frames[0].bh);
941  
942                         /* Add new access path frame */
943                         frame = frames + 1;
944                         frame->at = at = at - entries + entries2;
945                         frame->entries = entries = entries2;
946                         frame->bh = bh2;
947 +                       frame->curidx = newblock;
948 +                       frame->leaf = leaf;
949                         err = ext3_journal_get_write_access(handle,
950                                                              frame->bh);
951                         if (err)
952                                 goto journal_error;
953 +
954 +                       /* first level index was root. it's already initialized */
955 +                       /* we my unlock it now */
956 +                       ext3_unlock_htree(dir, idx_lock);
957 +
958 +                       /* current index is just created 2nd level index */
959 +                       curidx = newblock;
960 +                       idx_lock = nb_lock;
961                 }
962                 ext3_journal_dirty_metadata(handle, frames[0].bh);
963         }
964 -       de = do_split(handle, dir, &bh, frame, &hinfo, &err);
965 +       de = do_split(handle, dir, &bh, frame, &hinfo, &newleaf_lock, &err);
966         if (!de)
967                 goto cleanup;
968 +
969 +       /* index splitted */
970 +       ext3_unlock_htree(dir, idx_lock);
971 +       
972         err = add_dirent_to_buf(handle, dentry, inode, de, bh);
973 +
974 +       if (newleaf_lock)
975 +               ext3_unlock_htree(dir, newleaf_lock);
976 +       
977         bh = 0;
978         goto cleanup;
979  
980  journal_error:
981         ext3_std_error(dir->i_sb, err);
982  cleanup:
983 +       ext3_unlock_htree(dir, leaf_lock);
984         if (bh)
985                 brelse(bh);
986         dx_release(frames);
987 @@ -1981,6 +2303,7 @@
988         struct buffer_head * bh;
989         struct ext3_dir_entry_2 * de;
990         handle_t *handle;
991 +       void *lock;
992  
993         /* Initialize quotas before so that eventual writes go in
994          * separate transaction */
995 @@ -1990,7 +2313,7 @@
996                 return PTR_ERR(handle);
997  
998         retval = -ENOENT;
999 -       bh = ext3_find_entry (dentry, &de);
1000 +       bh = ext3_find_entry (dentry, &de, 1, &lock);
1001         if (!bh)
1002                 goto end_rmdir;
1003  
1004 @@ -2000,14 +2323,19 @@
1005         inode = dentry->d_inode;
1006  
1007         retval = -EIO;
1008 -       if (le32_to_cpu(de->inode) != inode->i_ino)
1009 +       if (le32_to_cpu(de->inode) != inode->i_ino) {
1010 +               ext3_unlock_htree(dir, lock);
1011                 goto end_rmdir;
1012 +       }
1013  
1014         retval = -ENOTEMPTY;
1015 -       if (!empty_dir (inode))
1016 +       if (!empty_dir (inode)) {
1017 +               ext3_unlock_htree(dir, lock);
1018                 goto end_rmdir;
1019 +       }
1020  
1021         retval = ext3_delete_entry(handle, dir, de, bh);
1022 +       ext3_unlock_htree(dir, lock);
1023         if (retval)
1024                 goto end_rmdir;
1025         if (inode->i_nlink != 2)
1026 @@ -2040,6 +2368,7 @@
1027         struct buffer_head * bh;
1028         struct ext3_dir_entry_2 * de;
1029         handle_t *handle;
1030 +       void *lock;
1031  
1032         /* Initialize quotas before so that eventual writes go
1033          * in separate transaction */
1034 @@ -2052,15 +2381,17 @@
1035                 handle->h_sync = 1;
1036  
1037         retval = -ENOENT;
1038 -       bh = ext3_find_entry (dentry, &de);
1039 +       bh = ext3_find_entry (dentry, &de, 1, &lock);
1040         if (!bh)
1041                 goto end_unlink;
1042  
1043         inode = dentry->d_inode;
1044  
1045         retval = -EIO;
1046 -       if (le32_to_cpu(de->inode) != inode->i_ino)
1047 +       if (le32_to_cpu(de->inode) != inode->i_ino) {
1048 +               ext3_unlock_htree(dir, lock);
1049                 goto end_unlink;
1050 +       }
1051  
1052         if (!inode->i_nlink) {
1053                 ext3_warning (inode->i_sb, "ext3_unlink",
1054 @@ -2069,6 +2400,7 @@
1055                 inode->i_nlink = 1;
1056         }
1057         retval = ext3_delete_entry(handle, dir, de, bh);
1058 +       ext3_unlock_htree(dir, lock);
1059         if (retval)
1060                 goto end_unlink;
1061         dir->i_ctime = dir->i_mtime = CURRENT_TIME;
1062 @@ -2182,6 +2514,7 @@
1063         struct buffer_head * old_bh, * new_bh, * dir_bh;
1064         struct ext3_dir_entry_2 * old_de, * new_de;
1065         int retval;
1066 +       void *lock1 = NULL, *lock2 = NULL, *lock3 = NULL;
1067  
1068         old_bh = new_bh = dir_bh = NULL;
1069  
1070 @@ -2197,7 +2530,10 @@
1071         if (IS_DIRSYNC(old_dir) || IS_DIRSYNC(new_dir))
1072                 handle->h_sync = 1;
1073  
1074 -       old_bh = ext3_find_entry (old_dentry, &old_de);
1075 +       if (old_dentry->d_parent == new_dentry->d_parent)
1076 +               down(&EXT3_I(old_dentry->d_parent->d_inode)->i_rename_sem);
1077 +
1078 +       old_bh = ext3_find_entry (old_dentry, &old_de, 1, &lock1 /* FIXME */);
1079         /*
1080          *  Check for inode number is _not_ due to possible IO errors.
1081          *  We might rmdir the source, keep it as pwd of some process
1082 @@ -2210,7 +2546,7 @@
1083                 goto end_rename;
1084  
1085         new_inode = new_dentry->d_inode;
1086 -       new_bh = ext3_find_entry (new_dentry, &new_de);
1087 +       new_bh = ext3_find_entry (new_dentry, &new_de, 1, &lock2 /* FIXME */);
1088         if (new_bh) {
1089                 if (!new_inode) {
1090                         brelse (new_bh);
1091 @@ -2274,7 +2610,7 @@
1092                 struct buffer_head *old_bh2;
1093                 struct ext3_dir_entry_2 *old_de2;
1094  
1095 -               old_bh2 = ext3_find_entry(old_dentry, &old_de2);
1096 +               old_bh2 = ext3_find_entry(old_dentry, &old_de2, 1, &lock3 /* FIXME */);
1097                 if (old_bh2) {
1098                         retval = ext3_delete_entry(handle, old_dir,
1099                                                    old_de2, old_bh2);
1100 @@ -2317,6 +2653,14 @@
1101         retval = 0;
1102  
1103  end_rename:
1104 +       if (lock1)
1105 +               ext3_unlock_htree(old_dentry->d_parent->d_inode, lock1);
1106 +       if (lock2)
1107 +               ext3_unlock_htree(new_dentry->d_parent->d_inode, lock2);
1108 +       if (lock3)
1109 +               ext3_unlock_htree(old_dentry->d_parent->d_inode, lock3);
1110 +       if (old_dentry->d_parent == new_dentry->d_parent)
1111 +               up(&EXT3_I(old_dentry->d_parent->d_inode)->i_rename_sem);
1112         brelse (dir_bh);
1113         brelse (old_bh);
1114         brelse (new_bh);
1115 @@ -2325,6 +2669,29 @@
1116  }
1117  
1118  /*
1119 + * this locking primitives are used to protect parts
1120 + * of dir's htree. protection unit is block: leaf or index
1121 + */
1122 +static inline void *ext3_lock_htree(struct inode *dir,
1123 +                                       unsigned long value, int rwlock)
1124 +{
1125 +       void *lock;
1126 +       
1127 +       if (!test_opt(dir->i_sb, PDIROPS))
1128 +               return NULL;
1129 +       lock = dynlock_lock(&EXT3_I(dir)->i_htree_lock, value, 1, GFP_KERNEL);
1130 +       return lock;
1131 +}
1132 +
1133 +static inline void ext3_unlock_htree(struct inode *dir,
1134 +                                       void *lock)
1135 +{
1136 +       if (!test_opt(dir->i_sb, PDIROPS) || !lock)
1137 +               return;
1138 +       dynlock_unlock(&EXT3_I(dir)->i_htree_lock, lock);
1139 +}
1140 +
1141 +/*
1142   * directories can handle most operations...
1143   */
1144  struct inode_operations ext3_dir_inode_operations = {
1145 Index: linux-2.6.7/fs/ext3/super.c
1146 ===================================================================
1147 --- linux-2.6.7.orig/fs/ext3/super.c    2004-09-07 14:12:13.000000000 +0400
1148 +++ linux-2.6.7/fs/ext3/super.c 2004-09-07 17:17:37.000000000 +0400
1149 @@ -453,6 +453,9 @@
1150         ei->i_default_acl = EXT3_ACL_NOT_CACHED;
1151  #endif
1152         ei->vfs_inode.i_version = 1;
1153 +       dynlock_init(&ei->i_htree_lock);
1154 +       sema_init(&ei->i_rename_sem, 1);
1155 +       sema_init(&ei->i_append_sem, 1);
1156         return &ei->vfs_inode;
1157  }
1158  
1159 @@ -586,7 +589,7 @@
1160         Opt_commit, Opt_journal_update, Opt_journal_inum,
1161         Opt_abort, Opt_data_journal, Opt_data_ordered, Opt_data_writeback,
1162         Opt_usrjquota, Opt_grpjquota, Opt_offusrjquota, Opt_offgrpjquota,
1163 -       Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0,
1164 +       Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0, Opt_pdirops,
1165         Opt_ignore, Opt_err,
1166  };
1167  
1168 @@ -632,6 +635,7 @@
1169         {Opt_ignore, "noquota"},
1170         {Opt_ignore, "quota"},
1171         {Opt_ignore, "usrquota"},
1172 +       {Opt_pdirops, "pdirops"},
1173         {Opt_err, NULL}
1174  };
1175  
1176 Index: linux-2.6.7/include/linux/ext3_fs.h
1177 ===================================================================
1178 --- linux-2.6.7.orig/include/linux/ext3_fs.h    2003-09-19 18:01:10.000000000 +0400
1179 +++ linux-2.6.7/include/linux/ext3_fs.h 2004-09-07 17:17:37.000000000 +0400
1180 @@ -306,6 +306,7 @@
1181  /*
1182   * Mount flags
1183   */
1184 +#define EXT3_MOUNT_PDIROPS             0x800000/* Parallel dir operations */
1185  #define EXT3_MOUNT_CHECK               0x0001  /* Do mount-time checks */
1186  #define EXT3_MOUNT_OLDALLOC            0x0002  /* Don't use the new Orlov allocator */
1187  #define EXT3_MOUNT_GRPID               0x0004  /* Create files with directory's group */
1188 Index: linux-2.6.7/include/linux/ext3_fs_i.h
1189 ===================================================================
1190 --- linux-2.6.7.orig/include/linux/ext3_fs_i.h  2003-12-30 08:32:44.000000000 +0300
1191 +++ linux-2.6.7/include/linux/ext3_fs_i.h       2004-09-07 17:17:37.000000000 +0400
1192 @@ -17,6 +17,7 @@
1193  #define _LINUX_EXT3_FS_I
1194  
1195  #include <linux/rwsem.h>
1196 +#include <linux/dynlocks.h>
1197  
1198  /*
1199   * second extended file system inode data in memory
1200 @@ -108,6 +109,11 @@
1201          */
1202         struct semaphore truncate_sem;
1203         struct inode vfs_inode;
1204
1205 +       /* following fields for parallel directory operations -bzzz */
1206 +       struct dynlock i_htree_lock;
1207 +       struct semaphore i_append_sem;
1208 +       struct semaphore i_rename_sem;
1209  };
1210  
1211  #endif /* _LINUX_EXT3_FS_I */