fs/inode.c | 1 fs/namei.c | 66 ++++++++++++++++++++++++++++++++++++++--------------- include/linux/fs.h | 11 ++++---- 3 files changed, 54 insertions(+), 24 deletions(-) Index: linux-2.4.21-suse2/fs/namei.c =================================================================== --- linux-2.4.21-suse2.orig/fs/namei.c 2004-08-19 13:45:04.000000000 +0400 +++ linux-2.4.21-suse2/fs/namei.c 2004-08-19 15:57:51.000000000 +0400 @@ -103,6 +103,38 @@ } EXPORT_SYMBOL(intent_release); +void *lock_dir(struct inode *dir, struct qstr *name) +{ + unsigned long hash; + + if (!IS_PDIROPS(dir)) { + down(&dir->i_sem); + return 0; + } + + /* OK. fs understands parallel directory operations. + * so, we try to acquire lock for hash of requested + * filename in order to prevent any operations with + * same name in same time -bzzz */ + + /* calculate name hash */ + hash = full_name_hash(name->name, name->len); + + /* lock this hash */ + return dynlock_lock(&dir->i_dcache_lock, hash, 1, GFP_ATOMIC); +} +EXPORT_SYMBOL(lock_dir); + +void unlock_dir(struct inode *dir, void *lock) +{ + if (!IS_PDIROPS(dir)) { + up(&dir->i_sem); + return; + } + dynlock_unlock(&dir->i_dcache_lock, lock); +} +EXPORT_SYMBOL(unlock_dir); + /* In order to reduce some races, while at the same time doing additional * checking and hopefully speeding things up, we copy filenames to the * kernel data space before using them.. @@ -305,10 +337,11 @@ struct dentry * result; struct inode *dir = parent->d_inode; int counter = 0; + void *lock; again: counter++; - down(&dir->i_sem); + lock = lock_dir(dir, name); /* * First re-do the cached lookup just in case it was created * while we waited for the directory semaphore.. @@ -332,7 +365,7 @@ else result = dentry; } - up(&dir->i_sem); + unlock_dir(dir, lock); return result; } @@ -340,7 +373,7 @@ * Uhhuh! Nasty case: the cache was re-populated while * we waited on the semaphore. Need to revalidate. */ - up(&dir->i_sem); + unlock_dir(dir, lock); if (result->d_op && result->d_op->d_revalidate) { if (!result->d_op->d_revalidate(result, flags) && !d_invalidate(result)) { dput(result); @@ -1186,13 +1219,13 @@ goto exit; dir = nd->dentry; - down(&dir->d_inode->i_sem); + nd->lock = lock_dir(dir->d_inode, &nd->last); dentry = lookup_hash_it(&nd->last, nd->dentry, it); do_last: error = PTR_ERR(dentry); if (IS_ERR(dentry)) { - up(&dir->d_inode->i_sem); + unlock_dir(dir->d_inode, nd->lock); goto exit; } @@ -1202,7 +1235,7 @@ if (!IS_POSIXACL(dir->d_inode)) mode &= ~current->fs->umask; error = vfs_create_it(dir->d_inode, dentry, mode, it); - up(&dir->d_inode->i_sem); + unlock_dir(dir->d_inode, nd->lock); #ifndef DENTRY_WASTE_RAM if (error) d_drop(dentry); @@ -1220,7 +1253,7 @@ /* * It already exists. */ - up(&dir->d_inode->i_sem); + unlock_dir(dir->d_inode, nd->lock); error = -EEXIST; if (flag & O_EXCL) @@ -1367,7 +1400,7 @@ goto exit; } dir = nd->dentry; - down(&dir->d_inode->i_sem); + nd->lock = lock_dir(dir->d_inode, &nd->last); dentry = lookup_hash_it(&nd->last, nd->dentry, it); putname(nd->last.name); goto do_last; @@ -1385,7 +1418,7 @@ { struct dentry *dentry; - down(&nd->dentry->d_inode->i_sem); + nd->lock = lock_dir(nd->dentry->d_inode, &nd->last); dentry = ERR_PTR(-EEXIST); if (nd->last_type != LAST_NORM) goto fail; @@ -1479,7 +1512,7 @@ } dput(dentry); } - up(&nd.dentry->d_inode->i_sem); + unlock_dir(nd.dentry->d_inode, nd.lock); out2: path_release(&nd); out: @@ -1547,7 +1580,7 @@ error = vfs_mkdir(nd.dentry->d_inode, dentry, mode); dput(dentry); } - up(&nd.dentry->d_inode->i_sem); + unlock_dir(nd.dentry->d_inode, nd.lock); out2: path_release(&nd); out: @@ -1657,14 +1690,14 @@ if (error != -EOPNOTSUPP) goto exit1; } - down(&nd.dentry->d_inode->i_sem); + nd.lock = lock_dir(nd.dentry->d_inode, &nd.last); dentry = lookup_hash_it(&nd.last, nd.dentry, NULL); error = PTR_ERR(dentry); if (!IS_ERR(dentry)) { error = vfs_rmdir(nd.dentry->d_inode, dentry); dput(dentry); } - up(&nd.dentry->d_inode->i_sem); + unlock_dir(nd.dentry->d_inode, nd.lock); exit1: path_release(&nd); exit: @@ -1723,7 +1756,7 @@ if (error != -EOPNOTSUPP) goto exit1; } - down(&nd.dentry->d_inode->i_sem); + nd.lock = lock_dir(nd.dentry->d_inode, &nd.last); dentry = lookup_hash_it(&nd.last, nd.dentry, NULL); error = PTR_ERR(dentry); if (!IS_ERR(dentry)) { @@ -1734,7 +1767,7 @@ exit2: dput(dentry); } - up(&nd.dentry->d_inode->i_sem); + unlock_dir(nd.dentry->d_inode, nd.lock); exit1: path_release(&nd); exit: @@ -1808,7 +1841,7 @@ error = vfs_symlink(nd.dentry->d_inode, dentry, from); dput(dentry); } - up(&nd.dentry->d_inode->i_sem); + unlock_dir(nd.dentry->d_inode, nd.lock); out2: path_release(&nd); out: @@ -1904,7 +1937,7 @@ error = vfs_link(old_nd.dentry, nd.dentry->d_inode, new_dentry); dput(new_dentry); } - up(&nd.dentry->d_inode->i_sem); + unlock_dir(nd.dentry->d_inode, nd.lock); out_release: path_release(&nd); out: Index: linux-2.4.21-suse2/fs/inode.c =================================================================== --- linux-2.4.21-suse2.orig/fs/inode.c 2004-08-19 13:45:04.000000000 +0400 +++ linux-2.4.21-suse2/fs/inode.c 2004-08-19 13:51:49.000000000 +0400 @@ -121,6 +121,7 @@ mapping->host = inode; mapping->gfp_mask = GFP_HIGHUSER; inode->i_mapping = mapping; + dynlock_init(&inode->i_dcache_lock); } return inode; } Index: linux-2.4.21-suse2/include/linux/fs.h =================================================================== --- linux-2.4.21-suse2.orig/include/linux/fs.h 2004-08-19 13:45:04.000000000 +0400 +++ linux-2.4.21-suse2/include/linux/fs.h 2004-08-19 13:51:49.000000000 +0400 @@ -22,6 +22,7 @@ #include #include #include +#include #include #include @@ -141,6 +142,7 @@ #define S_IMMUTABLE 16 /* Immutable file */ #define S_DEAD 32 /* removed, but still open directory */ #define S_NOQUOTA 64 /* Inode is not counted to quota */ +#define S_PDIROPS 256 /* Parallel directory operations */ /* * Note that nosuid etc flags are inode-specific: setting some file-system @@ -168,6 +170,7 @@ #define IS_NOATIME(inode) (__IS_FLG(inode, MS_NOATIME) || ((inode)->i_flags & S_NOATIME)) #define IS_NODIRATIME(inode) __IS_FLG(inode, MS_NODIRATIME) #define IS_POSIXACL(inode) __IS_FLG(inode, MS_POSIXACL) +#define IS_PDIROPS(inode) __IS_FLG(inode, S_PDIROPS) #define IS_DEADDIR(inode) ((inode)->i_flags & S_DEAD) @@ -525,6 +528,7 @@ atomic_t i_writecount; unsigned int i_attr_flags; __u32 i_generation; + struct dynlock i_dcache_lock; /* for parallel directory ops */ union { struct minix_inode_info minix_i; struct ext2_inode_info ext2_i; @@ -806,6 +810,7 @@ unsigned int flags; int last_type; struct lookup_intent *intent; + void *lock; }; /* @@ -1793,12 +1798,6 @@ return dget(dentry->d_parent); } -static inline void unlock_dir(struct dentry *dir) -{ - up(&dir->d_inode->i_sem); - dput(dir); -} - /* * Whee.. Deadlock country. Happily there are only two VFS * operations that does this..