nfsd4.1: fix session memory use calculation
[safe/jmp/linux-2.6] / fs / jfs / namei.c
index 7ab4756..c79a427 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"
@@ -34,7 +35,7 @@
 /*
  * forward references
  */
-struct dentry_operations jfs_ci_dentry_operations;
+const struct dentry_operations jfs_ci_dentry_operations;
 
 static s64 commitZeroLink(tid_t, struct inode *);
 
@@ -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;
@@ -170,9 +170,12 @@ static int jfs_create(struct inode *dip, struct dentry *dentry, int mode,
        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);
@@ -288,7 +291,6 @@ 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 */
@@ -305,9 +307,12 @@ static int jfs_mkdir(struct inode *dip, struct dentry *dentry, int mode)
        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);
@@ -328,7 +333,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:
@@ -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)) {
@@ -478,7 +483,7 @@ 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;
@@ -517,7 +522,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 +601,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 +681,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,
@@ -855,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
  *
@@ -1018,7 +1023,6 @@ 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;
@@ -1038,9 +1042,12 @@ static int jfs_symlink(struct inode *dip, struct dentry *dentry,
        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);
@@ -1052,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)
@@ -1102,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;
                }
@@ -1129,7 +1136,7 @@ static int jfs_rename(struct inode *old_dir, struct dentry *old_dentry,
        } else if (new_ip) {
                IWRITE_LOCK(new_ip, RDWRLOCK_NORMAL);
                /* Init inode for quota operations. */
-               DQUOT_INIT(new_ip);
+               vfs_dq_init(new_ip);
        }
 
        /*
@@ -1331,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)
@@ -1398,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;
@@ -1416,9 +1422,12 @@ static int jfs_mknod(struct inode *dir, struct dentry *dentry,
        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);
@@ -1454,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);
@@ -1477,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,
@@ -1519,7 +1543,7 @@ 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
 };
 
@@ -1527,7 +1551,11 @@ 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
+       .llseek         = generic_file_llseek,
 };
 
 static int jfs_ci_hash(struct dentry *dir, struct qstr *this)
@@ -1567,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,