Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/gerg/m68knommu
[pandora-kernel.git] / fs / ecryptfs / inode.c
index f0ad965..340c657 100644 (file)
@@ -147,7 +147,6 @@ static int ecryptfs_interpose(struct dentry *lower_dentry,
  * @lower_dir_inode: inode of the parent in the lower fs of the new file
  * @dentry: New file's dentry
  * @mode: The mode of the new file
- * @nd: nameidata of ecryptfs' parent's dentry & vfsmount
  *
  * Creates the file in the lower file system.
  *
@@ -155,31 +154,10 @@ static int ecryptfs_interpose(struct dentry *lower_dentry,
  */
 static int
 ecryptfs_create_underlying_file(struct inode *lower_dir_inode,
-                               struct dentry *dentry, int mode,
-                               struct nameidata *nd)
+                               struct dentry *dentry, int mode)
 {
        struct dentry *lower_dentry = ecryptfs_dentry_to_lower(dentry);
-       struct vfsmount *lower_mnt = ecryptfs_dentry_to_lower_mnt(dentry);
-       struct dentry *dentry_save;
-       struct vfsmount *vfsmount_save;
-       unsigned int flags_save;
-       int rc;
-
-       if (nd) {
-               dentry_save = nd->path.dentry;
-               vfsmount_save = nd->path.mnt;
-               flags_save = nd->flags;
-               nd->path.dentry = lower_dentry;
-               nd->path.mnt = lower_mnt;
-               nd->flags &= ~LOOKUP_OPEN;
-       }
-       rc = vfs_create(lower_dir_inode, lower_dentry, mode, nd);
-       if (nd) {
-               nd->path.dentry = dentry_save;
-               nd->path.mnt = vfsmount_save;
-               nd->flags = flags_save;
-       }
-       return rc;
+       return vfs_create(lower_dir_inode, lower_dentry, mode, NULL);
 }
 
 /**
@@ -197,8 +175,7 @@ ecryptfs_create_underlying_file(struct inode *lower_dir_inode,
  */
 static int
 ecryptfs_do_create(struct inode *directory_inode,
-                  struct dentry *ecryptfs_dentry, int mode,
-                  struct nameidata *nd)
+                  struct dentry *ecryptfs_dentry, int mode)
 {
        int rc;
        struct dentry *lower_dentry;
@@ -213,7 +190,7 @@ ecryptfs_do_create(struct inode *directory_inode,
                goto out;
        }
        rc = ecryptfs_create_underlying_file(lower_dir_dentry->d_inode,
-                                            ecryptfs_dentry, mode, nd);
+                                            ecryptfs_dentry, mode);
        if (rc) {
                printk(KERN_ERR "%s: Failure to create dentry in lower fs; "
                       "rc = [%d]\n", __func__, rc);
@@ -294,7 +271,7 @@ ecryptfs_create(struct inode *directory_inode, struct dentry *ecryptfs_dentry,
        int rc;
 
        /* ecryptfs_do_create() calls ecryptfs_interpose() */
-       rc = ecryptfs_do_create(directory_inode, ecryptfs_dentry, mode, nd);
+       rc = ecryptfs_do_create(directory_inode, ecryptfs_dentry, mode);
        if (unlikely(rc)) {
                ecryptfs_printk(KERN_WARNING, "Failed to create file in"
                                "lower filesystem\n");
@@ -307,105 +284,90 @@ out:
        return rc;
 }
 
+static int ecryptfs_i_size_read(struct dentry *dentry, struct inode *inode)
+{
+       struct ecryptfs_crypt_stat *crypt_stat;
+       int rc;
+
+       rc = ecryptfs_get_lower_file(dentry, inode);
+       if (rc) {
+               printk(KERN_ERR "%s: Error attempting to initialize "
+                       "the lower file for the dentry with name "
+                       "[%s]; rc = [%d]\n", __func__,
+                       dentry->d_name.name, rc);
+               return rc;
+       }
+
+       crypt_stat = &ecryptfs_inode_to_private(inode)->crypt_stat;
+       /* TODO: lock for crypt_stat comparison */
+       if (!(crypt_stat->flags & ECRYPTFS_POLICY_APPLIED))
+               ecryptfs_set_default_sizes(crypt_stat);
+
+       rc = ecryptfs_read_and_validate_header_region(inode);
+       ecryptfs_put_lower_file(inode);
+       if (rc) {
+               rc = ecryptfs_read_and_validate_xattr_region(dentry, inode);
+               if (!rc)
+                       crypt_stat->flags |= ECRYPTFS_METADATA_IN_XATTR;
+       }
+
+       /* Must return 0 to allow non-eCryptfs files to be looked up, too */
+       return 0;
+}
+
 /**
  * ecryptfs_lookup_interpose - Dentry interposition for a lookup
  */
-static int ecryptfs_lookup_interpose(struct dentry *ecryptfs_dentry,
+static int ecryptfs_lookup_interpose(struct dentry *dentry,
                                     struct dentry *lower_dentry,
-                                    struct inode *ecryptfs_dir_inode)
+                                    struct inode *dir_inode)
 {
-       struct dentry *lower_dir_dentry;
+       struct inode *inode, *lower_inode = lower_dentry->d_inode;
+       struct ecryptfs_dentry_info *dentry_info;
        struct vfsmount *lower_mnt;
-       struct inode *inode, *lower_inode;
-       struct ecryptfs_crypt_stat *crypt_stat;
-       char *page_virt = NULL;
-       int put_lower = 0, rc = 0;
-
-       lower_dir_dentry = lower_dentry->d_parent;
-       lower_mnt = mntget(ecryptfs_dentry_to_lower_mnt(
-                                  ecryptfs_dentry->d_parent));
-       lower_inode = lower_dentry->d_inode;
-       fsstack_copy_attr_atime(ecryptfs_dir_inode, lower_dir_dentry->d_inode);
+       int rc = 0;
+
+       lower_mnt = mntget(ecryptfs_dentry_to_lower_mnt(dentry->d_parent));
+       fsstack_copy_attr_atime(dir_inode, lower_dentry->d_parent->d_inode);
        BUG_ON(!lower_dentry->d_count);
-       ecryptfs_set_dentry_private(ecryptfs_dentry,
-                                   kmem_cache_alloc(ecryptfs_dentry_info_cache,
-                                                    GFP_KERNEL));
-       if (!ecryptfs_dentry_to_private(ecryptfs_dentry)) {
-               rc = -ENOMEM;
+
+       dentry_info = kmem_cache_alloc(ecryptfs_dentry_info_cache, GFP_KERNEL);
+       ecryptfs_set_dentry_private(dentry, dentry_info);
+       if (!dentry_info) {
                printk(KERN_ERR "%s: Out of memory whilst attempting "
                       "to allocate ecryptfs_dentry_info struct\n",
                        __func__);
-               goto out_put;
+               dput(lower_dentry);
+               mntput(lower_mnt);
+               d_drop(dentry);
+               return -ENOMEM;
        }
-       ecryptfs_set_dentry_lower(ecryptfs_dentry, lower_dentry);
-       ecryptfs_set_dentry_lower_mnt(ecryptfs_dentry, lower_mnt);
+       ecryptfs_set_dentry_lower(dentry, lower_dentry);
+       ecryptfs_set_dentry_lower_mnt(dentry, lower_mnt);
+
        if (!lower_dentry->d_inode) {
                /* We want to add because we couldn't find in lower */
-               d_add(ecryptfs_dentry, NULL);
-               goto out;
+               d_add(dentry, NULL);
+               return 0;
        }
-       inode = __ecryptfs_get_inode(lower_inode, ecryptfs_dir_inode->i_sb);
+       inode = __ecryptfs_get_inode(lower_inode, dir_inode->i_sb);
        if (IS_ERR(inode)) {
-               rc = PTR_ERR(inode);
-               printk(KERN_ERR "%s: Error interposing; rc = [%d]\n",
-                      __func__, rc);
-               goto out;
-       }
-       if (!S_ISREG(inode->i_mode)) {
-               if (inode->i_state & I_NEW)
-                       unlock_new_inode(inode);
-               d_add(ecryptfs_dentry, inode);
-               goto out;
-       }
-       /* Released in this function */
-       page_virt = kmem_cache_zalloc(ecryptfs_header_cache_2, GFP_USER);
-       if (!page_virt) {
-               printk(KERN_ERR "%s: Cannot kmem_cache_zalloc() a page\n",
-                      __func__);
-               rc = -ENOMEM;
-               make_bad_inode(inode);
-               goto out;
-       }
-       rc = ecryptfs_get_lower_file(ecryptfs_dentry, inode);
-       if (rc) {
-               printk(KERN_ERR "%s: Error attempting to initialize "
-                       "the lower file for the dentry with name "
-                       "[%s]; rc = [%d]\n", __func__,
-                       ecryptfs_dentry->d_name.name, rc);
-               make_bad_inode(inode);
-               goto out_free_kmem;
+               printk(KERN_ERR "%s: Error interposing; rc = [%ld]\n",
+                      __func__, PTR_ERR(inode));
+               return PTR_ERR(inode);
        }
-       put_lower = 1;
-       crypt_stat = &ecryptfs_inode_to_private(inode)->crypt_stat;
-       /* TODO: lock for crypt_stat comparison */
-       if (!(crypt_stat->flags & ECRYPTFS_POLICY_APPLIED))
-                       ecryptfs_set_default_sizes(crypt_stat);
-       rc = ecryptfs_read_and_validate_header_region(page_virt, inode);
-       if (rc) {
-               memset(page_virt, 0, PAGE_CACHE_SIZE);
-               rc = ecryptfs_read_and_validate_xattr_region(page_virt,
-                                                            inode);
+       if (S_ISREG(inode->i_mode)) {
+               rc = ecryptfs_i_size_read(dentry, inode);
                if (rc) {
-                       rc = 0;
-                       goto unlock_inode;
+                       make_bad_inode(inode);
+                       return rc;
                }
-               crypt_stat->flags |= ECRYPTFS_METADATA_IN_XATTR;
        }
-       ecryptfs_i_size_init(page_virt, inode);
-unlock_inode:
+
        if (inode->i_state & I_NEW)
                unlock_new_inode(inode);
-       d_add(ecryptfs_dentry, inode);
-out_free_kmem:
-       kmem_cache_free(ecryptfs_header_cache_2, page_virt);
-       goto out;
-out_put:
-       dput(lower_dentry);
-       mntput(lower_mnt);
-       d_drop(ecryptfs_dentry);
-out:
-       if (put_lower)
-               ecryptfs_put_lower_file(inode);
+       d_add(dentry, inode);
+
        return rc;
 }
 
@@ -957,10 +919,8 @@ int ecryptfs_truncate(struct dentry *dentry, loff_t new_length)
 }
 
 static int
-ecryptfs_permission(struct inode *inode, int mask, unsigned int flags)
+ecryptfs_permission(struct inode *inode, int mask)
 {
-       if (flags & IPERM_FLAG_RCU)
-               return -ECHILD;
        return inode_permission(ecryptfs_inode_to_lower(inode), mask);
 }