memcg: oom wakeup filter
[safe/jmp/linux-2.6] / fs / jfs / namei.c
index 932797b..a9cf8e8 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 *);
 
@@ -84,6 +85,8 @@ static int jfs_create(struct inode *dip, struct dentry *dentry, int mode,
 
        jfs_info("jfs_create: dip:0x%p name:%s", dip, dentry->d_name.name);
 
+       dquot_initialize(dip);
+
        /*
         * search parent directory for entry/freespace
         * (dtSearch() returns parent directory page pinned)
@@ -154,7 +157,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 +172,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);
@@ -212,6 +217,8 @@ static int jfs_mkdir(struct inode *dip, struct dentry *dentry, int mode)
 
        jfs_info("jfs_mkdir: dip:0x%p name:%s", dip, dentry->d_name.name);
 
+       dquot_initialize(dip);
+
        /* link count overflow on parent directory ? */
        if (dip->i_nlink == JFS_LINK_MAX) {
                rc = -EMLINK;
@@ -288,7 +295,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 +311,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);
@@ -351,7 +360,8 @@ 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);
+       dquot_initialize(dip);
+       dquot_initialize(ip);
 
        /* directory must be empty to be removed */
        if (!dtEmpty(ip)) {
@@ -478,7 +488,8 @@ 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);
+       dquot_initialize(dip);
+       dquot_initialize(ip);
 
        if ((rc = get_UCSname(&dname, dentry)))
                goto out;
@@ -800,6 +811,8 @@ static int jfs_link(struct dentry *old_dentry,
        if (ip->i_nlink == 0)
                return -ENOENT;
 
+       dquot_initialize(dir);
+
        tid = txBegin(ip->i_sb, 0);
 
        mutex_lock_nested(&JFS_IP(dir)->commit_mutex, COMMIT_MUTEX_PARENT);
@@ -891,6 +904,8 @@ static int jfs_symlink(struct inode *dip, struct dentry *dentry,
 
        jfs_info("jfs_symlink: dip:0x%p name:%s", dip, name);
 
+       dquot_initialize(dip);
+
        ssize = strlen(name) + 1;
 
        /*
@@ -941,7 +956,7 @@ static int jfs_symlink(struct inode *dip, struct dentry *dentry,
         */
 
        if (ssize <= IDATASIZE) {
-               ip->i_op = &jfs_symlink_inode_operations;
+               ip->i_op = &jfs_fast_symlink_inode_operations;
 
                i_fastsymlink = JFS_IP(ip)->i_inline;
                memcpy(i_fastsymlink, name, ssize);
@@ -963,7 +978,7 @@ static int jfs_symlink(struct inode *dip, struct dentry *dentry,
        else {
                jfs_info("jfs_symlink: allocate extent ip:0x%p", ip);
 
-               ip->i_op = &page_symlink_inode_operations;
+               ip->i_op = &jfs_symlink_inode_operations;
                ip->i_mapping->a_ops = &jfs_aops;
 
                /*
@@ -1018,7 +1033,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 +1052,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);
@@ -1080,6 +1097,9 @@ static int jfs_rename(struct inode *old_dir, struct dentry *old_dentry,
        jfs_info("jfs_rename: %s %s", old_dentry->d_name.name,
                 new_dentry->d_name.name);
 
+       dquot_initialize(old_dir);
+       dquot_initialize(new_dir);
+
        old_ip = old_dentry->d_inode;
        new_ip = new_dentry->d_inode;
 
@@ -1102,8 +1122,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 +1149,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);
+               dquot_initialize(new_ip);
        }
 
        /*
@@ -1353,6 +1373,8 @@ static int jfs_mknod(struct inode *dir, struct dentry *dentry,
 
        jfs_info("jfs_mknod: %s", dentry->d_name.name);
 
+       dquot_initialize(dir);
+
        if ((rc = get_UCSname(&dname, dentry)))
                goto out;
 
@@ -1398,7 +1420,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 +1437,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 +1478,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,62 +1499,47 @@ static struct dentry *jfs_lookup(struct inode *dip, struct dentry *dentry, struc
        return dentry;
 }
 
-struct dentry *jfs_get_dentry(struct super_block *sb, void *vobjp)
+static struct inode *jfs_nfs_get_inode(struct super_block *sb,
+               u64 ino, u32 generation)
 {
-       __u32 *objp = vobjp;
-       unsigned long ino = objp[0];
-       __u32 generation = objp[1];
        struct inode *inode;
-       struct dentry *result;
 
        if (ino == 0)
                return ERR_PTR(-ESTALE);
-       inode = iget(sb, ino);
-       if (inode == NULL)
-               return ERR_PTR(-ENOMEM);
-
-       if (is_bad_inode(inode) ||
-           (generation && inode->i_generation != generation)) {
-               result = ERR_PTR(-ESTALE);
-               goto out_iput;
-       }
+       inode = jfs_iget(sb, ino);
+       if (IS_ERR(inode))
+               return ERR_CAST(inode);
 
-       result = d_alloc_anon(inode);
-       if (!result) {
-               result = ERR_PTR(-ENOMEM);
-               goto out_iput;
+       if (generation && inode->i_generation != generation) {
+               iput(inode);
+               return ERR_PTR(-ESTALE);
        }
-       return result;
 
- out_iput:
-       iput(inode);
-       return result;
+       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;
-       struct dentry *parent = ERR_PTR(-ENOENT);
-       struct inode *inode;
        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));
 }
 
 const struct inode_operations jfs_dir_inode_operations = {
@@ -1549,9 +1556,9 @@ const struct inode_operations jfs_dir_inode_operations = {
        .getxattr       = jfs_getxattr,
        .listxattr      = jfs_listxattr,
        .removexattr    = jfs_removexattr,
-#ifdef CONFIG_JFS_POSIX_ACL
        .setattr        = jfs_setattr,
-       .permission     = jfs_permission,
+#ifdef CONFIG_JFS_POSIX_ACL
+       .check_acl      = jfs_check_acl,
 #endif
 };
 
@@ -1559,7 +1566,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)
@@ -1599,7 +1610,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,