nfsd4.1: fix session memory use calculation
[safe/jmp/linux-2.6] / fs / jfs / namei.c
index 1abe734..c79a427 100644 (file)
@@ -4,22 +4,23 @@
  *
  *   This program is free software;  you can redistribute it and/or modify
  *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or 
+ *   the Free Software Foundation; either version 2 of the License, or
  *   (at your option) any later version.
- * 
+ *
  *   This program is distributed in the hope that it will be useful,
  *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
  *   the GNU General Public License for more details.
  *
  *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software 
+ *   along with this program;  if not, write to the Free Software
  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  */
 
 #include <linux/fs.h>
 #include <linux/ctype.h>
 #include <linux/quotaops.h>
+#include <linux/exportfs.h>
 #include "jfs_incore.h"
 #include "jfs_superblock.h"
 #include "jfs_inode.h"
 /*
  * forward references
  */
-struct dentry_operations jfs_ci_dentry_operations;
+const struct dentry_operations jfs_ci_dentry_operations;
 
 static s64 commitZeroLink(tid_t, struct inode *);
 
 /*
  * NAME:       free_ea_wmap(inode)
  *
- * FUNCTION:   free uncommitted extended attributes from working map 
+ * FUNCTION:   free uncommitted extended attributes from working map
  *
  */
 static inline void free_ea_wmap(struct inode *inode)
@@ -62,7 +63,7 @@ static inline void free_ea_wmap(struct inode *inode)
  * FUNCTION:   create a regular file in the parent directory <dip>
  *             with name = <from dentry> and mode = <mode>
  *
- * PARAMETER:  dip     - parent directory vnode
+ * PARAMETER:  dip     - parent directory vnode
  *             dentry  - dentry of new file
  *             mode    - create mode (rwxrwxrwx).
  *             nd- nd struct
@@ -97,15 +98,15 @@ static int jfs_create(struct inode *dip, struct dentry *dentry, int mode,
         * begin the transaction before we search the directory.
         */
        ip = ialloc(dip, mode);
-       if (ip == NULL) {
-               rc = -ENOSPC;
+       if (IS_ERR(ip)) {
+               rc = PTR_ERR(ip);
                goto out2;
        }
 
        tid = txBegin(dip->i_sb, 0);
 
-       down(&JFS_IP(dip)->commit_sem);
-       down(&JFS_IP(ip)->commit_sem);
+       mutex_lock_nested(&JFS_IP(dip)->commit_mutex, COMMIT_MUTEX_PARENT);
+       mutex_lock_nested(&JFS_IP(ip)->commit_mutex, COMMIT_MUTEX_CHILD);
 
        rc = jfs_init_acl(tid, ip, dip);
        if (rc)
@@ -154,7 +155,6 @@ static int jfs_create(struct inode *dip, struct dentry *dentry, int mode,
        ip->i_fop = &jfs_file_operations;
        ip->i_mapping->a_ops = &jfs_aops;
 
-       insert_inode_hash(ip);
        mark_inode_dirty(ip);
 
        dip->i_ctime = dip->i_mtime = CURRENT_TIME;
@@ -165,14 +165,17 @@ static int jfs_create(struct inode *dip, struct dentry *dentry, int mode,
 
       out3:
        txEnd(tid);
-       up(&JFS_IP(dip)->commit_sem);
-       up(&JFS_IP(ip)->commit_sem);
+       mutex_unlock(&JFS_IP(ip)->commit_mutex);
+       mutex_unlock(&JFS_IP(dip)->commit_mutex);
        if (rc) {
                free_ea_wmap(ip);
                ip->i_nlink = 0;
+               unlock_new_inode(ip);
                iput(ip);
-       } else
+       } else {
                d_instantiate(dentry, ip);
+               unlock_new_inode(ip);
+       }
 
       out2:
        free_UCSname(&dname);
@@ -190,7 +193,7 @@ static int jfs_create(struct inode *dip, struct dentry *dentry, int mode,
  * FUNCTION:   create a child directory in the parent directory <dip>
  *             with name = <from dentry> and mode = <mode>
  *
- * PARAMETER:  dip     - parent directory vnode
+ * PARAMETER:  dip     - parent directory vnode
  *             dentry  - dentry of child directory
  *             mode    - create mode (rwxrwxrwx).
  *
@@ -231,15 +234,15 @@ static int jfs_mkdir(struct inode *dip, struct dentry *dentry, int mode)
         * begin the transaction before we search the directory.
         */
        ip = ialloc(dip, S_IFDIR | mode);
-       if (ip == NULL) {
-               rc = -ENOSPC;
+       if (IS_ERR(ip)) {
+               rc = PTR_ERR(ip);
                goto out2;
        }
 
        tid = txBegin(dip->i_sb, 0);
 
-       down(&JFS_IP(dip)->commit_sem);
-       down(&JFS_IP(ip)->commit_sem);
+       mutex_lock_nested(&JFS_IP(dip)->commit_mutex, COMMIT_MUTEX_PARENT);
+       mutex_lock_nested(&JFS_IP(ip)->commit_mutex, COMMIT_MUTEX_CHILD);
 
        rc = jfs_init_acl(tid, ip, dip);
        if (rc)
@@ -288,11 +291,10 @@ static int jfs_mkdir(struct inode *dip, struct dentry *dentry, int mode)
        ip->i_op = &jfs_dir_inode_operations;
        ip->i_fop = &jfs_dir_operations;
 
-       insert_inode_hash(ip);
        mark_inode_dirty(ip);
 
        /* update parent directory inode */
-       dip->i_nlink++;         /* for '..' from child directory */
+       inc_nlink(dip);         /* for '..' from child directory */
        dip->i_ctime = dip->i_mtime = CURRENT_TIME;
        mark_inode_dirty(dip);
 
@@ -300,14 +302,17 @@ static int jfs_mkdir(struct inode *dip, struct dentry *dentry, int mode)
 
       out3:
        txEnd(tid);
-       up(&JFS_IP(dip)->commit_sem);
-       up(&JFS_IP(ip)->commit_sem);
+       mutex_unlock(&JFS_IP(ip)->commit_mutex);
+       mutex_unlock(&JFS_IP(dip)->commit_mutex);
        if (rc) {
                free_ea_wmap(ip);
                ip->i_nlink = 0;
+               unlock_new_inode(ip);
                iput(ip);
-       } else
+       } else {
                d_instantiate(dentry, ip);
+               unlock_new_inode(ip);
+       }
 
       out2:
        free_UCSname(&dname);
@@ -324,18 +329,18 @@ static int jfs_mkdir(struct inode *dip, struct dentry *dentry, int mode)
  *
  * FUNCTION:   remove a link to child directory
  *
- * PARAMETER:  dip     - parent inode
+ * PARAMETER:  dip     - parent inode
  *             dentry  - child directory dentry
  *
  * RETURN:     -EINVAL - if name is . or ..
- *             -EINVAL  - if . or .. exist but are invalid.
+ *             -EINVAL - if . or .. exist but are invalid.
  *             errors from subroutines
  *
  * note:
- * if other threads have the directory open when the last link 
- * is removed, the "." and ".." entries, if present, are removed before 
- * rmdir() returns and no new entries may be created in the directory, 
- * but the directory is not removed until the last reference to 
+ * if other threads have the directory open when the last link
+ * is removed, the "." and ".." entries, if present, are removed before
+ * rmdir() returns and no new entries may be created in the directory,
+ * but the directory is not removed until the last reference to
  * the directory is released (cf.unlink() of regular file).
  */
 static int jfs_rmdir(struct inode *dip, struct dentry *dentry)
@@ -351,7 +356,7 @@ static int jfs_rmdir(struct inode *dip, struct dentry *dentry)
        jfs_info("jfs_rmdir: dip:0x%p name:%s", dip, dentry->d_name.name);
 
        /* Init inode for quota operations. */
-       DQUOT_INIT(ip);
+       vfs_dq_init(ip);
 
        /* directory must be empty to be removed */
        if (!dtEmpty(ip)) {
@@ -365,8 +370,8 @@ static int jfs_rmdir(struct inode *dip, struct dentry *dentry)
 
        tid = txBegin(dip->i_sb, 0);
 
-       down(&JFS_IP(dip)->commit_sem);
-       down(&JFS_IP(ip)->commit_sem);
+       mutex_lock_nested(&JFS_IP(dip)->commit_mutex, COMMIT_MUTEX_PARENT);
+       mutex_lock_nested(&JFS_IP(ip)->commit_mutex, COMMIT_MUTEX_CHILD);
 
        iplist[0] = dip;
        iplist[1] = ip;
@@ -384,8 +389,8 @@ static int jfs_rmdir(struct inode *dip, struct dentry *dentry)
                if (rc == -EIO)
                        txAbort(tid, 1);
                txEnd(tid);
-               up(&JFS_IP(dip)->commit_sem);
-               up(&JFS_IP(ip)->commit_sem);
+               mutex_unlock(&JFS_IP(ip)->commit_mutex);
+               mutex_unlock(&JFS_IP(dip)->commit_mutex);
 
                goto out2;
        }
@@ -393,9 +398,8 @@ static int jfs_rmdir(struct inode *dip, struct dentry *dentry)
        /* update parent directory's link count corresponding
         * to ".." entry of the target directory deleted
         */
-       dip->i_nlink--;
        dip->i_ctime = dip->i_mtime = CURRENT_TIME;
-       mark_inode_dirty(dip);
+       inode_dec_link_count(dip);
 
        /*
         * OS/2 could have created EA and/or ACL
@@ -415,15 +419,15 @@ static int jfs_rmdir(struct inode *dip, struct dentry *dentry)
        JFS_IP(ip)->acl.flag = 0;
 
        /* mark the target directory as deleted */
-       ip->i_nlink = 0;
+       clear_nlink(ip);
        mark_inode_dirty(ip);
 
        rc = txCommit(tid, 2, &iplist[0], 0);
 
        txEnd(tid);
 
-       up(&JFS_IP(dip)->commit_sem);
-       up(&JFS_IP(ip)->commit_sem);
+       mutex_unlock(&JFS_IP(ip)->commit_mutex);
+       mutex_unlock(&JFS_IP(dip)->commit_mutex);
 
        /*
         * Truncating the directory index table is not guaranteed.  It
@@ -447,11 +451,11 @@ static int jfs_rmdir(struct inode *dip, struct dentry *dentry)
 /*
  * NAME:       jfs_unlink(dip, dentry)
  *
- * FUNCTION:   remove a link to object <vp> named by <name> 
+ * FUNCTION:   remove a link to object <vp> named by <name>
  *             from parent directory <dvp>
  *
- * PARAMETER:  dip     - inode of parent directory
- *             dentry  - dentry of object to be removed
+ * PARAMETER:  dip     - inode of parent directory
+ *             dentry  - dentry of object to be removed
  *
  * RETURN:     errors from subroutines
  *
@@ -479,17 +483,17 @@ static int jfs_unlink(struct inode *dip, struct dentry *dentry)
        jfs_info("jfs_unlink: dip:0x%p name:%s", dip, dentry->d_name.name);
 
        /* Init inode for quota operations. */
-       DQUOT_INIT(ip);
+       vfs_dq_init(ip);
 
        if ((rc = get_UCSname(&dname, dentry)))
                goto out;
 
-       IWRITE_LOCK(ip);
+       IWRITE_LOCK(ip, RDWRLOCK_NORMAL);
 
        tid = txBegin(dip->i_sb, 0);
 
-       down(&JFS_IP(dip)->commit_sem);
-       down(&JFS_IP(ip)->commit_sem);
+       mutex_lock_nested(&JFS_IP(dip)->commit_mutex, COMMIT_MUTEX_PARENT);
+       mutex_lock_nested(&JFS_IP(ip)->commit_mutex, COMMIT_MUTEX_CHILD);
 
        iplist[0] = dip;
        iplist[1] = ip;
@@ -503,8 +507,8 @@ static int jfs_unlink(struct inode *dip, struct dentry *dentry)
                if (rc == -EIO)
                        txAbort(tid, 1);        /* Marks FS Dirty */
                txEnd(tid);
-               up(&JFS_IP(dip)->commit_sem);
-               up(&JFS_IP(ip)->commit_sem);
+               mutex_unlock(&JFS_IP(ip)->commit_mutex);
+               mutex_unlock(&JFS_IP(dip)->commit_mutex);
                IWRITE_UNLOCK(ip);
                goto out1;
        }
@@ -515,11 +519,10 @@ static int jfs_unlink(struct inode *dip, struct dentry *dentry)
        mark_inode_dirty(dip);
 
        /* update target's inode */
-       ip->i_nlink--;
-       mark_inode_dirty(ip);
+       inode_dec_link_count(ip);
 
        /*
-        *      commit zero link count object
+        *      commit zero link count object
         */
        if (ip->i_nlink == 0) {
                assert(!test_cflag(COMMIT_Nolink, ip));
@@ -527,8 +530,8 @@ static int jfs_unlink(struct inode *dip, struct dentry *dentry)
                if ((new_size = commitZeroLink(tid, ip)) < 0) {
                        txAbort(tid, 1);        /* Marks FS Dirty */
                        txEnd(tid);
-                       up(&JFS_IP(dip)->commit_sem);
-                       up(&JFS_IP(ip)->commit_sem);
+                       mutex_unlock(&JFS_IP(ip)->commit_mutex);
+                       mutex_unlock(&JFS_IP(dip)->commit_mutex);
                        IWRITE_UNLOCK(ip);
                        rc = new_size;
                        goto out1;
@@ -556,13 +559,12 @@ static int jfs_unlink(struct inode *dip, struct dentry *dentry)
 
        txEnd(tid);
 
-       up(&JFS_IP(dip)->commit_sem);
-       up(&JFS_IP(ip)->commit_sem);
-
+       mutex_unlock(&JFS_IP(ip)->commit_mutex);
+       mutex_unlock(&JFS_IP(dip)->commit_mutex);
 
        while (new_size && (rc == 0)) {
                tid = txBegin(dip->i_sb, 0);
-               down(&JFS_IP(ip)->commit_sem);
+               mutex_lock(&JFS_IP(ip)->commit_mutex);
                new_size = xtTruncate_pmap(tid, ip, new_size);
                if (new_size < 0) {
                        txAbort(tid, 1);        /* Marks FS Dirty */
@@ -570,7 +572,7 @@ static int jfs_unlink(struct inode *dip, struct dentry *dentry)
                } else
                        rc = txCommit(tid, 2, &iplist[0], COMMIT_SYNC);
                txEnd(tid);
-               up(&JFS_IP(ip)->commit_sem);
+               mutex_unlock(&JFS_IP(ip)->commit_mutex);
        }
 
        if (ip->i_nlink == 0)
@@ -599,9 +601,9 @@ static int jfs_unlink(struct inode *dip, struct dentry *dentry)
 /*
  * NAME:       commitZeroLink()
  *
- * FUNCTION:    for non-directory, called by jfs_remove(),
+ * FUNCTION:   for non-directory, called by jfs_remove(),
  *             truncate a regular file, directory or symbolic
- *             link to zero length. return 0 if type is not 
+ *             link to zero length. return 0 if type is not
  *             one of these.
  *
  *             if the file is currently associated with a VM segment
@@ -611,7 +613,7 @@ static int jfs_unlink(struct inode *dip, struct dentry *dentry)
  *             map by ctrunc1.
  *             if there is no VM segment on entry, the resources are
  *             freed in both work and permanent map.
- *             (? for temporary file - memory object is cached even 
+ *             (? for temporary file - memory object is cached even
  *             after no reference:
  *             reference count > 0 -   )
  *
@@ -665,7 +667,7 @@ static s64 commitZeroLink(tid_t tid, struct inode *ip)
 
        /*
         * free xtree/data (truncate to zero length):
-        * free xtree/data pages from cache if COMMIT_PWMAP, 
+        * free xtree/data pages from cache if COMMIT_PWMAP,
         * free xtree/data blocks from persistent block map, and
         * free xtree/data blocks from working block map if COMMIT_PWMAP;
         */
@@ -679,8 +681,8 @@ static s64 commitZeroLink(tid_t tid, struct inode *ip)
 /*
  * NAME:       jfs_free_zero_link()
  *
- * FUNCTION:    for non-directory, called by iClose(),
- *             free resources of a file from cache and WORKING map 
+ * FUNCTION:   for non-directory, called by iClose(),
+ *             free resources of a file from cache and WORKING map
  *             for a file previously committed with zero link count
  *             while associated with a pager object,
  *
@@ -765,7 +767,7 @@ void jfs_free_zero_link(struct inode *ip)
  * FUNCTION:   create a link to <vp> by the name = <name>
  *             in the parent directory <dvp>
  *
- * PARAMETER:  vp      - target object
+ * PARAMETER:  vp      - target object
  *             dvp     - parent directory of new link
  *             name    - name of new link to target object
  *             crp     - credential
@@ -805,8 +807,8 @@ static int jfs_link(struct dentry *old_dentry,
 
        tid = txBegin(ip->i_sb, 0);
 
-       down(&JFS_IP(dir)->commit_sem);
-       down(&JFS_IP(ip)->commit_sem);
+       mutex_lock_nested(&JFS_IP(dir)->commit_mutex, COMMIT_MUTEX_PARENT);
+       mutex_lock_nested(&JFS_IP(ip)->commit_mutex, COMMIT_MUTEX_CHILD);
 
        /*
         * scan parent directory for entry/freespace
@@ -825,8 +827,9 @@ static int jfs_link(struct dentry *old_dentry,
                goto free_dname;
 
        /* update object inode */
-       ip->i_nlink++;          /* for new link */
+       inc_nlink(ip);          /* for new link */
        ip->i_ctime = CURRENT_TIME;
+       dir->i_ctime = dir->i_mtime = CURRENT_TIME;
        mark_inode_dirty(dir);
        atomic_inc(&ip->i_count);
 
@@ -835,7 +838,7 @@ static int jfs_link(struct dentry *old_dentry,
        rc = txCommit(tid, 2, &iplist[0], 0);
 
        if (rc) {
-               ip->i_nlink--;
+               ip->i_nlink--; /* never instantiated */
                iput(ip);
        } else
                d_instantiate(dentry, ip);
@@ -846,8 +849,8 @@ static int jfs_link(struct dentry *old_dentry,
       out:
        txEnd(tid);
 
-       up(&JFS_IP(dir)->commit_sem);
-       up(&JFS_IP(ip)->commit_sem);
+       mutex_unlock(&JFS_IP(ip)->commit_mutex);
+       mutex_unlock(&JFS_IP(dir)->commit_mutex);
 
        jfs_info("jfs_link: rc:%d", rc);
        return rc;
@@ -857,12 +860,12 @@ static int jfs_link(struct dentry *old_dentry,
  * NAME:       jfs_symlink(dip, dentry, name)
  *
  * FUNCTION:   creates a symbolic link to <symlink> by name <name>
- *                     in directory <dip>
+ *                     in directory <dip>
  *
- * PARAMETER:  dip         - parent directory vnode
- *                     dentry  - dentry of symbolic link
- *                     name    - the path name of the existing object 
- *                                   that will be the source of the link
+ * PARAMETER:  dip     - parent directory vnode
+ *             dentry  - dentry of symbolic link
+ *             name    - the path name of the existing object
+ *                       that will be the source of the link
  *
  * RETURN:     errors from subroutines
  *
@@ -908,15 +911,15 @@ static int jfs_symlink(struct inode *dip, struct dentry *dentry,
         * (iAlloc() returns new, locked inode)
         */
        ip = ialloc(dip, S_IFLNK | 0777);
-       if (ip == NULL) {
-               rc = -ENOSPC;
+       if (IS_ERR(ip)) {
+               rc = PTR_ERR(ip);
                goto out2;
        }
 
        tid = txBegin(dip->i_sb, 0);
 
-       down(&JFS_IP(dip)->commit_sem);
-       down(&JFS_IP(ip)->commit_sem);
+       mutex_lock_nested(&JFS_IP(dip)->commit_mutex, COMMIT_MUTEX_PARENT);
+       mutex_lock_nested(&JFS_IP(ip)->commit_mutex, COMMIT_MUTEX_CHILD);
 
        rc = jfs_init_security(tid, ip, dip);
        if (rc)
@@ -928,7 +931,7 @@ static int jfs_symlink(struct inode *dip, struct dentry *dentry,
        tblk->u.ixpxd = JFS_IP(ip)->ixpxd;
 
        /* fix symlink access permission
-        * (dir_create() ANDs in the u.u_cmask, 
+        * (dir_create() ANDs in the u.u_cmask,
         * but symlinks really need to be 777 access)
         */
        ip->i_mode |= 0777;
@@ -969,7 +972,7 @@ static int jfs_symlink(struct inode *dip, struct dentry *dentry,
                ip->i_mapping->a_ops = &jfs_aops;
 
                /*
-                * even though the data of symlink object (source 
+                * even though the data of symlink object (source
                 * path name) is treated as non-journaled user data,
                 * it is read/written thru buffer cache for performance.
                 */
@@ -980,7 +983,6 @@ static int jfs_symlink(struct inode *dip, struct dentry *dentry,
                xlen = xsize >> JFS_SBI(sb)->l2bsize;
                if ((rc = xtInsert(tid, ip, 0, 0, xlen, &xaddr, 0))) {
                        txAbort(tid, 0);
-                       rc = -ENOSPC;
                        goto out3;
                }
                extent = xaddr;
@@ -1021,9 +1023,10 @@ static int jfs_symlink(struct inode *dip, struct dentry *dentry,
                goto out3;
        }
 
-       insert_inode_hash(ip);
        mark_inode_dirty(ip);
 
+       dip->i_ctime = dip->i_mtime = CURRENT_TIME;
+       mark_inode_dirty(dip);
        /*
         * commit update of parent directory and link object
         */
@@ -1034,14 +1037,17 @@ static int jfs_symlink(struct inode *dip, struct dentry *dentry,
 
       out3:
        txEnd(tid);
-       up(&JFS_IP(dip)->commit_sem);
-       up(&JFS_IP(ip)->commit_sem);
+       mutex_unlock(&JFS_IP(ip)->commit_mutex);
+       mutex_unlock(&JFS_IP(dip)->commit_mutex);
        if (rc) {
                free_ea_wmap(ip);
                ip->i_nlink = 0;
+               unlock_new_inode(ip);
                iput(ip);
-       } else
+       } else {
                d_instantiate(dentry, ip);
+               unlock_new_inode(ip);
+       }
 
       out2:
        free_UCSname(&dname);
@@ -1053,9 +1059,9 @@ static int jfs_symlink(struct inode *dip, struct dentry *dentry,
 
 
 /*
- * NAME:        jfs_rename
+ * NAME:       jfs_rename
  *
- * FUNCTION:    rename a file or directory
+ * FUNCTION:   rename a file or directory
  */
 static int jfs_rename(struct inode *old_dir, struct dentry *old_dentry,
               struct inode *new_dir, struct dentry *new_dentry)
@@ -1103,8 +1109,8 @@ static int jfs_rename(struct inode *old_dir, struct dentry *old_dentry,
         * Make sure dest inode number (if any) is what we think it is
         */
        rc = dtSearch(new_dir, &new_dname, &ino, &btstack, JFS_LOOKUP);
-       if (rc == 0) {
-               if ((new_ip == 0) || (ino != new_ip->i_ino)) {
+       if (!rc) {
+               if ((!new_ip) || (ino != new_ip->i_ino)) {
                        rc = -ESTALE;
                        goto out3;
                }
@@ -1128,9 +1134,9 @@ static int jfs_rename(struct inode *old_dir, struct dentry *old_dentry,
                        goto out3;
                }
        } else if (new_ip) {
-               IWRITE_LOCK(new_ip);
+               IWRITE_LOCK(new_ip, RDWRLOCK_NORMAL);
                /* Init inode for quota operations. */
-               DQUOT_INIT(new_ip);
+               vfs_dq_init(new_ip);
        }
 
        /*
@@ -1138,13 +1144,21 @@ static int jfs_rename(struct inode *old_dir, struct dentry *old_dentry,
         */
        tid = txBegin(new_dir->i_sb, 0);
 
-       down(&JFS_IP(new_dir)->commit_sem);
-       down(&JFS_IP(old_ip)->commit_sem);
+       /*
+        * How do we know the locking is safe from deadlocks?
+        * The vfs does the hard part for us.  Any time we are taking nested
+        * commit_mutexes, the vfs already has i_mutex held on the parent.
+        * Here, the vfs has already taken i_mutex on both old_dir and new_dir.
+        */
+       mutex_lock_nested(&JFS_IP(new_dir)->commit_mutex, COMMIT_MUTEX_PARENT);
+       mutex_lock_nested(&JFS_IP(old_ip)->commit_mutex, COMMIT_MUTEX_CHILD);
        if (old_dir != new_dir)
-               down(&JFS_IP(old_dir)->commit_sem);
+               mutex_lock_nested(&JFS_IP(old_dir)->commit_mutex,
+                                 COMMIT_MUTEX_SECOND_PARENT);
 
        if (new_ip) {
-               down(&JFS_IP(new_ip)->commit_sem);
+               mutex_lock_nested(&JFS_IP(new_ip)->commit_mutex,
+                                 COMMIT_MUTEX_VICTIM);
                /*
                 * Change existing directory entry to new inode number
                 */
@@ -1153,14 +1167,15 @@ static int jfs_rename(struct inode *old_dir, struct dentry *old_dentry,
                              old_ip->i_ino, JFS_RENAME);
                if (rc)
                        goto out4;
-               new_ip->i_nlink--;
+               drop_nlink(new_ip);
                if (S_ISDIR(new_ip->i_mode)) {
-                       new_ip->i_nlink--;
+                       drop_nlink(new_ip);
                        if (new_ip->i_nlink) {
-                               up(&JFS_IP(new_dir)->commit_sem);
-                               up(&JFS_IP(old_ip)->commit_sem);
+                               mutex_unlock(&JFS_IP(new_ip)->commit_mutex);
                                if (old_dir != new_dir)
-                                       up(&JFS_IP(old_dir)->commit_sem);
+                                       mutex_unlock(&JFS_IP(old_dir)->commit_mutex);
+                               mutex_unlock(&JFS_IP(old_ip)->commit_mutex);
+                               mutex_unlock(&JFS_IP(new_dir)->commit_mutex);
                                if (!S_ISDIR(old_ip->i_mode) && new_ip)
                                        IWRITE_UNLOCK(new_ip);
                                jfs_error(new_ip->i_sb,
@@ -1175,7 +1190,7 @@ static int jfs_rename(struct inode *old_dir, struct dentry *old_dentry,
                        /* free block resources */
                        if ((new_size = commitZeroLink(tid, new_ip)) < 0) {
                                txAbort(tid, 1);        /* Marks FS Dirty */
-                               rc = new_size;          
+                               rc = new_size;
                                goto out4;
                        }
                        tblk = tid_to_tblock(tid);
@@ -1205,7 +1220,7 @@ static int jfs_rename(struct inode *old_dir, struct dentry *old_dentry,
                        goto out4;
                }
                if (S_ISDIR(old_ip->i_mode))
-                       new_dir->i_nlink++;
+                       inc_nlink(new_dir);
        }
        /*
         * Remove old directory entry
@@ -1220,7 +1235,7 @@ static int jfs_rename(struct inode *old_dir, struct dentry *old_dentry,
                goto out4;
        }
        if (S_ISDIR(old_ip->i_mode)) {
-               old_dir->i_nlink--;
+               drop_nlink(old_dir);
                if (old_dir != new_dir) {
                        /*
                         * Change inode number of parent for moved directory
@@ -1278,25 +1293,24 @@ static int jfs_rename(struct inode *old_dir, struct dentry *old_dentry,
 
       out4:
        txEnd(tid);
-
-       up(&JFS_IP(new_dir)->commit_sem);
-       up(&JFS_IP(old_ip)->commit_sem);
-       if (old_dir != new_dir)
-               up(&JFS_IP(old_dir)->commit_sem);
        if (new_ip)
-               up(&JFS_IP(new_ip)->commit_sem);
+               mutex_unlock(&JFS_IP(new_ip)->commit_mutex);
+       if (old_dir != new_dir)
+               mutex_unlock(&JFS_IP(old_dir)->commit_mutex);
+       mutex_unlock(&JFS_IP(old_ip)->commit_mutex);
+       mutex_unlock(&JFS_IP(new_dir)->commit_mutex);
 
        while (new_size && (rc == 0)) {
                tid = txBegin(new_ip->i_sb, 0);
-               down(&JFS_IP(new_ip)->commit_sem);
+               mutex_lock(&JFS_IP(new_ip)->commit_mutex);
                new_size = xtTruncate_pmap(tid, new_ip, new_size);
                if (new_size < 0) {
                        txAbort(tid, 1);
-                       rc = new_size;          
+                       rc = new_size;
                } else
                        rc = txCommit(tid, 1, &new_ip, COMMIT_SYNC);
                txEnd(tid);
-               up(&JFS_IP(new_ip)->commit_sem);
+               mutex_unlock(&JFS_IP(new_ip)->commit_mutex);
        }
        if (new_ip && (new_ip->i_nlink == 0))
                set_cflag(COMMIT_Nolink, new_ip);
@@ -1324,9 +1338,9 @@ static int jfs_rename(struct inode *old_dir, struct dentry *old_dentry,
 
 
 /*
- * NAME:        jfs_mknod
+ * NAME:       jfs_mknod
  *
- * FUNCTION:    Create a special file (device)
+ * FUNCTION:   Create a special file (device)
  */
 static int jfs_mknod(struct inode *dir, struct dentry *dentry,
                int mode, dev_t rdev)
@@ -1350,16 +1364,16 @@ static int jfs_mknod(struct inode *dir, struct dentry *dentry,
                goto out;
 
        ip = ialloc(dir, mode);
-       if (ip == NULL) {
-               rc = -ENOSPC;
+       if (IS_ERR(ip)) {
+               rc = PTR_ERR(ip);
                goto out1;
        }
        jfs_ip = JFS_IP(ip);
 
        tid = txBegin(dir->i_sb, 0);
 
-       down(&JFS_IP(dir)->commit_sem);
-       down(&JFS_IP(ip)->commit_sem);
+       mutex_lock_nested(&JFS_IP(dir)->commit_mutex, COMMIT_MUTEX_PARENT);
+       mutex_lock_nested(&JFS_IP(ip)->commit_mutex, COMMIT_MUTEX_CHILD);
 
        rc = jfs_init_acl(tid, ip, dir);
        if (rc)
@@ -1391,7 +1405,6 @@ static int jfs_mknod(struct inode *dir, struct dentry *dentry,
        jfs_ip->dev = new_encode_dev(rdev);
        init_special_inode(ip, ip->i_mode, rdev);
 
-       insert_inode_hash(ip);
        mark_inode_dirty(ip);
 
        dir->i_ctime = dir->i_mtime = CURRENT_TIME;
@@ -1404,14 +1417,17 @@ static int jfs_mknod(struct inode *dir, struct dentry *dentry,
 
       out3:
        txEnd(tid);
-       up(&JFS_IP(ip)->commit_sem);
-       up(&JFS_IP(dir)->commit_sem);
+       mutex_unlock(&JFS_IP(ip)->commit_mutex);
+       mutex_unlock(&JFS_IP(dir)->commit_mutex);
        if (rc) {
                free_ea_wmap(ip);
                ip->i_nlink = 0;
+               unlock_new_inode(ip);
                iput(ip);
-       } else
+       } else {
                d_instantiate(dentry, ip);
+               unlock_new_inode(ip);
+       }
 
       out1:
        free_UCSname(&dname);
@@ -1447,19 +1463,17 @@ static struct dentry *jfs_lookup(struct inode *dip, struct dentry *dentry, struc
                free_UCSname(&key);
                if (rc == -ENOENT) {
                        d_add(dentry, NULL);
-                       return ERR_PTR(0);
+                       return NULL;
                } else if (rc) {
                        jfs_err("jfs_lookup: dtSearch returned %d", rc);
                        return ERR_PTR(rc);
                }
        }
 
-       ip = iget(dip->i_sb, inum);
-       if (ip == NULL || is_bad_inode(ip)) {
+       ip = jfs_iget(dip->i_sb, inum);
+       if (IS_ERR(ip)) {
                jfs_err("jfs_lookup: iget failed on inum %d", (uint) inum);
-               if (ip)
-                       iput(ip);
-               return ERR_PTR(-EACCES);
+               return ERR_CAST(ip);
        }
 
        dentry = d_splice_alias(ip, dentry);
@@ -1470,33 +1484,50 @@ static struct dentry *jfs_lookup(struct inode *dip, struct dentry *dentry, struc
        return dentry;
 }
 
-struct dentry *jfs_get_parent(struct dentry *dentry)
+static struct inode *jfs_nfs_get_inode(struct super_block *sb,
+               u64 ino, u32 generation)
 {
-       struct super_block *sb = dentry->d_inode->i_sb;
-       struct dentry *parent = ERR_PTR(-ENOENT);
        struct inode *inode;
+
+       if (ino == 0)
+               return ERR_PTR(-ESTALE);
+       inode = jfs_iget(sb, ino);
+       if (IS_ERR(inode))
+               return ERR_CAST(inode);
+
+       if (generation && inode->i_generation != generation) {
+               iput(inode);
+               return ERR_PTR(-ESTALE);
+       }
+
+       return inode;
+}
+
+struct dentry *jfs_fh_to_dentry(struct super_block *sb, struct fid *fid,
+               int fh_len, int fh_type)
+{
+       return generic_fh_to_dentry(sb, fid, fh_len, fh_type,
+                                   jfs_nfs_get_inode);
+}
+
+struct dentry *jfs_fh_to_parent(struct super_block *sb, struct fid *fid,
+               int fh_len, int fh_type)
+{
+       return generic_fh_to_parent(sb, fid, fh_len, fh_type,
+                                   jfs_nfs_get_inode);
+}
+
+struct dentry *jfs_get_parent(struct dentry *dentry)
+{
        unsigned long parent_ino;
 
        parent_ino =
                le32_to_cpu(JFS_IP(dentry->d_inode)->i_dtroot.header.idotdot);
-       inode = iget(sb, parent_ino);
-       if (inode) {
-               if (is_bad_inode(inode)) {
-                       iput(inode);
-                       parent = ERR_PTR(-EACCES);
-               } else {
-                       parent = d_alloc_anon(inode);
-                       if (!parent) {
-                               parent = ERR_PTR(-ENOMEM);
-                               iput(inode);
-                       }
-               }
-       }
 
-       return parent;
+       return d_obtain_alias(jfs_iget(dentry->d_inode->i_sb, parent_ino));
 }
 
-struct inode_operations jfs_dir_inode_operations = {
+const struct inode_operations jfs_dir_inode_operations = {
        .create         = jfs_create,
        .lookup         = jfs_lookup,
        .link           = jfs_link,
@@ -1512,14 +1543,19 @@ struct inode_operations jfs_dir_inode_operations = {
        .removexattr    = jfs_removexattr,
 #ifdef CONFIG_JFS_POSIX_ACL
        .setattr        = jfs_setattr,
-       .permission     = jfs_permission,
+       .check_acl      = jfs_check_acl,
 #endif
 };
 
-struct file_operations jfs_dir_operations = {
+const struct file_operations jfs_dir_operations = {
        .read           = generic_read_dir,
        .readdir        = jfs_readdir,
        .fsync          = jfs_fsync,
+       .unlocked_ioctl = jfs_ioctl,
+#ifdef CONFIG_COMPAT
+       .compat_ioctl   = jfs_compat_ioctl,
+#endif
+       .llseek         = generic_file_llseek,
 };
 
 static int jfs_ci_hash(struct dentry *dir, struct qstr *this)
@@ -1559,7 +1595,7 @@ out:
        return result;
 }
 
-struct dentry_operations jfs_ci_dentry_operations =
+const struct dentry_operations jfs_ci_dentry_operations =
 {
        .d_hash = jfs_ci_hash,
        .d_compare = jfs_ci_compare,