]> err.no Git - linux-2.6/blobdiff - fs/jfs/namei.c
[Blackfin] arch: Equalize include files: Add PLL_DIV Masks
[linux-2.6] / fs / jfs / namei.c
index a6a8c16c872c886ba68f3e89c7d2682a1e9d429f..0ba6778edaa2ae73d9595d8f425c7d3e98dce7a7 100644 (file)
@@ -20,6 +20,7 @@
 #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"
@@ -104,8 +105,8 @@ static int jfs_create(struct inode *dip, struct dentry *dentry, int mode,
 
        tid = txBegin(dip->i_sb, 0);
 
-       mutex_lock(&JFS_IP(dip)->commit_mutex);
-       mutex_lock(&JFS_IP(ip)->commit_mutex);
+       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)
@@ -238,8 +239,8 @@ static int jfs_mkdir(struct inode *dip, struct dentry *dentry, int mode)
 
        tid = txBegin(dip->i_sb, 0);
 
-       mutex_lock(&JFS_IP(dip)->commit_mutex);
-       mutex_lock(&JFS_IP(ip)->commit_mutex);
+       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)
@@ -328,7 +329,7 @@ static int jfs_mkdir(struct inode *dip, struct dentry *dentry, int mode)
  *             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:
@@ -365,8 +366,8 @@ static int jfs_rmdir(struct inode *dip, struct dentry *dentry)
 
        tid = txBegin(dip->i_sb, 0);
 
-       mutex_lock(&JFS_IP(dip)->commit_mutex);
-       mutex_lock(&JFS_IP(ip)->commit_mutex);
+       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;
@@ -483,12 +484,12 @@ static int jfs_unlink(struct inode *dip, struct dentry *dentry)
        if ((rc = get_UCSname(&dname, dentry)))
                goto out;
 
-       IWRITE_LOCK(ip);
+       IWRITE_LOCK(ip, RDWRLOCK_NORMAL);
 
        tid = txBegin(dip->i_sb, 0);
 
-       mutex_lock(&JFS_IP(dip)->commit_mutex);
-       mutex_lock(&JFS_IP(ip)->commit_mutex);
+       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;
@@ -517,7 +518,7 @@ static int jfs_unlink(struct inode *dip, struct dentry *dentry)
        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));
@@ -596,7 +597,7 @@ 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
  *             one of these.
@@ -676,7 +677,7 @@ static s64 commitZeroLink(tid_t tid, struct inode *ip)
 /*
  * NAME:       jfs_free_zero_link()
  *
- * FUNCTION:    for non-directory, called by iClose(),
+ * 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,
@@ -802,8 +803,8 @@ static int jfs_link(struct dentry *old_dentry,
 
        tid = txBegin(ip->i_sb, 0);
 
-       mutex_lock(&JFS_IP(dir)->commit_mutex);
-       mutex_lock(&JFS_IP(ip)->commit_mutex);
+       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
@@ -855,12 +856,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
  *
@@ -913,8 +914,8 @@ static int jfs_symlink(struct inode *dip, struct dentry *dentry,
 
        tid = txBegin(dip->i_sb, 0);
 
-       mutex_lock(&JFS_IP(dip)->commit_mutex);
-       mutex_lock(&JFS_IP(ip)->commit_mutex);
+       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)
@@ -1052,9 +1053,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)
@@ -1102,8 +1103,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;
                }
@@ -1127,7 +1128,7 @@ 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);
        }
@@ -1137,13 +1138,21 @@ static int jfs_rename(struct inode *old_dir, struct dentry *old_dentry,
         */
        tid = txBegin(new_dir->i_sb, 0);
 
-       mutex_lock(&JFS_IP(new_dir)->commit_mutex);
-       mutex_lock(&JFS_IP(old_ip)->commit_mutex);
+       /*
+        * 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)
-               mutex_lock(&JFS_IP(old_dir)->commit_mutex);
+               mutex_lock_nested(&JFS_IP(old_dir)->commit_mutex,
+                                 COMMIT_MUTEX_SECOND_PARENT);
 
        if (new_ip) {
-               mutex_lock(&JFS_IP(new_ip)->commit_mutex);
+               mutex_lock_nested(&JFS_IP(new_ip)->commit_mutex,
+                                 COMMIT_MUTEX_VICTIM);
                /*
                 * Change existing directory entry to new inode number
                 */
@@ -1323,9 +1332,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)
@@ -1357,8 +1366,8 @@ static int jfs_mknod(struct inode *dir, struct dentry *dentry,
 
        tid = txBegin(dir->i_sb, 0);
 
-       mutex_lock(&JFS_IP(dir)->commit_mutex);
-       mutex_lock(&JFS_IP(ip)->commit_mutex);
+       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)
@@ -1453,12 +1462,10 @@ static struct dentry *jfs_lookup(struct inode *dip, struct dentry *dentry, struc
                }
        }
 
-       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);
@@ -1469,6 +1476,39 @@ static struct dentry *jfs_lookup(struct inode *dip, struct dentry *dentry, struc
        return dentry;
 }
 
+static struct inode *jfs_nfs_get_inode(struct super_block *sb,
+               u64 ino, u32 generation)
+{
+       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)
 {
        struct super_block *sb = dentry->d_inode->i_sb;
@@ -1478,24 +1518,21 @@ struct dentry *jfs_get_parent(struct dentry *dentry)
 
        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)) {
+       inode = jfs_iget(sb, parent_ino);
+       if (IS_ERR(inode)) {
+               parent = ERR_CAST(inode);
+       } else {
+               parent = d_alloc_anon(inode);
+               if (!parent) {
+                       parent = ERR_PTR(-ENOMEM);
                        iput(inode);
-                       parent = ERR_PTR(-EACCES);
-               } else {
-                       parent = d_alloc_anon(inode);
-                       if (!parent) {
-                               parent = ERR_PTR(-ENOMEM);
-                               iput(inode);
-                       }
                }
        }
 
        return parent;
 }
 
-struct inode_operations jfs_dir_inode_operations = {
+const struct inode_operations jfs_dir_inode_operations = {
        .create         = jfs_create,
        .lookup         = jfs_lookup,
        .link           = jfs_link,
@@ -1519,7 +1556,10 @@ const struct file_operations jfs_dir_operations = {
        .read           = generic_read_dir,
        .readdir        = jfs_readdir,
        .fsync          = jfs_fsync,
-       .ioctl          = jfs_ioctl,
+       .unlocked_ioctl = jfs_ioctl,
+#ifdef CONFIG_COMPAT
+       .compat_ioctl   = jfs_compat_ioctl,
+#endif
 };
 
 static int jfs_ci_hash(struct dentry *dir, struct qstr *this)