nfsd4: simplify lease/grace interaction
[safe/jmp/linux-2.6] / fs / ext2 / namei.c
index ad1432a..dd7175c 100644 (file)
 #include "acl.h"
 #include "xip.h"
 
-/*
- * Couple of helper functions - make the code slightly cleaner.
- */
-
-static inline void ext2_inc_count(struct inode *inode)
-{
-       inode->i_nlink++;
-       mark_inode_dirty(inode);
-}
-
-static inline void ext2_dec_count(struct inode *inode)
-{
-       inode->i_nlink--;
-       mark_inode_dirty(inode);
-}
-
 static inline int ext2_add_nondir(struct dentry *dentry, struct inode *inode)
 {
        int err = ext2_add_link(dentry, inode);
        if (!err) {
                d_instantiate(dentry, inode);
+               unlock_new_inode(inode);
                return 0;
        }
-       ext2_dec_count(inode);
+       inode_dec_link_count(inode);
+       unlock_new_inode(inode);
        iput(inode);
        return err;
 }
@@ -76,39 +62,31 @@ static struct dentry *ext2_lookup(struct inode * dir, struct dentry *dentry, str
        if (dentry->d_name.len > EXT2_NAME_LEN)
                return ERR_PTR(-ENAMETOOLONG);
 
-       ino = ext2_inode_by_name(dir, dentry);
+       ino = ext2_inode_by_name(dir, &dentry->d_name);
        inode = NULL;
        if (ino) {
-               inode = iget(dir->i_sb, ino);
-               if (!inode)
-                       return ERR_PTR(-EACCES);
+               inode = ext2_iget(dir->i_sb, ino);
+               if (unlikely(IS_ERR(inode))) {
+                       if (PTR_ERR(inode) == -ESTALE) {
+                               ext2_error(dir->i_sb, __func__,
+                                               "deleted inode referenced: %lu",
+                                               (unsigned long) ino);
+                               return ERR_PTR(-EIO);
+                       } else {
+                               return ERR_CAST(inode);
+                       }
+               }
        }
        return d_splice_alias(inode, dentry);
 }
 
 struct dentry *ext2_get_parent(struct dentry *child)
 {
-       unsigned long ino;
-       struct dentry *parent;
-       struct inode *inode;
-       struct dentry dotdot;
-
-       dotdot.d_name.name = "..";
-       dotdot.d_name.len = 2;
-
-       ino = ext2_inode_by_name(child->d_inode, &dotdot);
+       struct qstr dotdot = {.name = "..", .len = 2};
+       unsigned long ino = ext2_inode_by_name(child->d_inode, &dotdot);
        if (!ino)
                return ERR_PTR(-ENOENT);
-       inode = iget(child->d_inode->i_sb, ino);
-
-       if (!inode)
-               return ERR_PTR(-EACCES);
-       parent = d_alloc_anon(inode);
-       if (!parent) {
-               iput(inode);
-               parent = ERR_PTR(-ENOMEM);
-       }
-       return parent;
+       return d_obtain_alias(ext2_iget(child->d_inode->i_sb, ino));
 } 
 
 /*
@@ -201,7 +179,8 @@ out:
        return err;
 
 out_fail:
-       ext2_dec_count(inode);
+       inode_dec_link_count(inode);
+       unlock_new_inode(inode);
        iput (inode);
        goto out;
 }
@@ -210,15 +189,23 @@ static int ext2_link (struct dentry * old_dentry, struct inode * dir,
        struct dentry *dentry)
 {
        struct inode *inode = old_dentry->d_inode;
+       int err;
 
        if (inode->i_nlink >= EXT2_LINK_MAX)
                return -EMLINK;
 
        inode->i_ctime = CURRENT_TIME_SEC;
-       ext2_inc_count(inode);
+       inode_inc_link_count(inode);
        atomic_inc(&inode->i_count);
 
-       return ext2_add_nondir(dentry, inode);
+       err = ext2_add_link(dentry, inode);
+       if (!err) {
+               d_instantiate(dentry, inode);
+               return 0;
+       }
+       inode_dec_link_count(inode);
+       iput(inode);
+       return err;
 }
 
 static int ext2_mkdir(struct inode * dir, struct dentry * dentry, int mode)
@@ -229,7 +216,7 @@ static int ext2_mkdir(struct inode * dir, struct dentry * dentry, int mode)
        if (dir->i_nlink >= EXT2_LINK_MAX)
                goto out;
 
-       ext2_inc_count(dir);
+       inode_inc_link_count(dir);
 
        inode = ext2_new_inode (dir, S_IFDIR | mode);
        err = PTR_ERR(inode);
@@ -243,7 +230,7 @@ static int ext2_mkdir(struct inode * dir, struct dentry * dentry, int mode)
        else
                inode->i_mapping->a_ops = &ext2_aops;
 
-       ext2_inc_count(inode);
+       inode_inc_link_count(inode);
 
        err = ext2_make_empty(inode, dir);
        if (err)
@@ -254,15 +241,17 @@ static int ext2_mkdir(struct inode * dir, struct dentry * dentry, int mode)
                goto out_fail;
 
        d_instantiate(dentry, inode);
+       unlock_new_inode(inode);
 out:
        return err;
 
 out_fail:
-       ext2_dec_count(inode);
-       ext2_dec_count(inode);
+       inode_dec_link_count(inode);
+       inode_dec_link_count(inode);
+       unlock_new_inode(inode);
        iput(inode);
 out_dir:
-       ext2_dec_count(dir);
+       inode_dec_link_count(dir);
        goto out;
 }
 
@@ -273,7 +262,7 @@ static int ext2_unlink(struct inode * dir, struct dentry *dentry)
        struct page * page;
        int err = -ENOENT;
 
-       de = ext2_find_entry (dir, dentry, &page);
+       de = ext2_find_entry (dir, &dentry->d_name, &page);
        if (!de)
                goto out;
 
@@ -282,7 +271,7 @@ static int ext2_unlink(struct inode * dir, struct dentry *dentry)
                goto out;
 
        inode->i_ctime = dir->i_ctime;
-       ext2_dec_count(inode);
+       inode_dec_link_count(inode);
        err = 0;
 out:
        return err;
@@ -297,8 +286,8 @@ static int ext2_rmdir (struct inode * dir, struct dentry *dentry)
                err = ext2_unlink(dir, dentry);
                if (!err) {
                        inode->i_size = 0;
-                       ext2_dec_count(inode);
-                       ext2_dec_count(dir);
+                       inode_dec_link_count(inode);
+                       inode_dec_link_count(dir);
                }
        }
        return err;
@@ -315,7 +304,7 @@ static int ext2_rename (struct inode * old_dir, struct dentry * old_dentry,
        struct ext2_dir_entry_2 * old_de;
        int err = -ENOENT;
 
-       old_de = ext2_find_entry (old_dir, old_dentry, &old_page);
+       old_de = ext2_find_entry (old_dir, &old_dentry->d_name, &old_page);
        if (!old_de)
                goto out;
 
@@ -335,44 +324,49 @@ static int ext2_rename (struct inode * old_dir, struct dentry * old_dentry,
                        goto out_dir;
 
                err = -ENOENT;
-               new_de = ext2_find_entry (new_dir, new_dentry, &new_page);
+               new_de = ext2_find_entry (new_dir, &new_dentry->d_name, &new_page);
                if (!new_de)
                        goto out_dir;
-               ext2_inc_count(old_inode);
-               ext2_set_link(new_dir, new_de, new_page, old_inode);
+               inode_inc_link_count(old_inode);
+               ext2_set_link(new_dir, new_de, new_page, old_inode, 1);
                new_inode->i_ctime = CURRENT_TIME_SEC;
                if (dir_de)
-                       new_inode->i_nlink--;
-               ext2_dec_count(new_inode);
+                       drop_nlink(new_inode);
+               inode_dec_link_count(new_inode);
        } else {
                if (dir_de) {
                        err = -EMLINK;
                        if (new_dir->i_nlink >= EXT2_LINK_MAX)
                                goto out_dir;
                }
-               ext2_inc_count(old_inode);
+               inode_inc_link_count(old_inode);
                err = ext2_add_link(new_dentry, old_inode);
                if (err) {
-                       ext2_dec_count(old_inode);
+                       inode_dec_link_count(old_inode);
                        goto out_dir;
                }
                if (dir_de)
-                       ext2_inc_count(new_dir);
+                       inode_inc_link_count(new_dir);
        }
 
        /*
         * Like most other Unix systems, set the ctime for inodes on a
         * rename.
-        * ext2_dec_count() will mark the inode dirty.
+        * inode_dec_link_count() will mark the inode dirty.
         */
        old_inode->i_ctime = CURRENT_TIME_SEC;
 
        ext2_delete_entry (old_de, old_page);
-       ext2_dec_count(old_inode);
+       inode_dec_link_count(old_inode);
 
        if (dir_de) {
-               ext2_set_link(old_inode, dir_de, dir_page, new_dir);
-               ext2_dec_count(old_dir);
+               if (old_dir != new_dir)
+                       ext2_set_link(old_inode, dir_de, dir_page, new_dir, 0);
+               else {
+                       kunmap(dir_page);
+                       page_cache_release(dir_page);
+               }
+               inode_dec_link_count(old_dir);
        }
        return 0;
 
@@ -389,7 +383,7 @@ out:
        return err;
 }
 
-struct inode_operations ext2_dir_inode_operations = {
+const struct inode_operations ext2_dir_inode_operations = {
        .create         = ext2_create,
        .lookup         = ext2_lookup,
        .link           = ext2_link,
@@ -406,10 +400,10 @@ struct inode_operations ext2_dir_inode_operations = {
        .removexattr    = generic_removexattr,
 #endif
        .setattr        = ext2_setattr,
-       .permission     = ext2_permission,
+       .check_acl      = ext2_check_acl,
 };
 
-struct inode_operations ext2_special_inode_operations = {
+const struct inode_operations ext2_special_inode_operations = {
 #ifdef CONFIG_EXT2_FS_XATTR
        .setxattr       = generic_setxattr,
        .getxattr       = generic_getxattr,
@@ -417,5 +411,5 @@ struct inode_operations ext2_special_inode_operations = {
        .removexattr    = generic_removexattr,
 #endif
        .setattr        = ext2_setattr,
-       .permission     = ext2_permission,
+       .check_acl      = ext2_check_acl,
 };