eCryptfs: Consolidate inode functions into inode.c
authorTyler Hicks <tyhicks@linux.vnet.ibm.com>
Tue, 24 May 2011 02:18:20 +0000 (21:18 -0500)
committerTyler Hicks <tyhicks@linux.vnet.ibm.com>
Sun, 29 May 2011 17:49:53 +0000 (12:49 -0500)
These functions should live in inode.c since their focus is on inodes
and they're primarily used by functions in inode.c.

Also does a simple cleanup of ecryptfs_inode_test() and rolls
ecryptfs_init_inode() into ecryptfs_inode_set().

Signed-off-by: Tyler Hicks <tyhicks@linux.vnet.ibm.com>
Tested-by: David <david@unsolicited.net>
fs/ecryptfs/ecryptfs_kernel.h
fs/ecryptfs/inode.c
fs/ecryptfs/main.c
fs/ecryptfs/super.c

index e70282775e2c193f11da232c897f6859a2e4334b..37224b5fb12ab9a2e5b82f5822c8bca5f58aa9d2 100644 (file)
@@ -625,10 +625,8 @@ struct ecryptfs_open_req {
        struct list_head kthread_ctl_list;
 };
 
-#define ECRYPTFS_INTERPOSE_FLAG_D_ADD                 0x00000001
-int ecryptfs_interpose(struct dentry *hidden_dentry,
-                      struct dentry *this_dentry, struct super_block *sb,
-                      u32 flags);
+struct inode *ecryptfs_get_inode(struct inode *lower_inode,
+                                struct super_block *sb);
 void ecryptfs_i_size_init(const char *page_virt, struct inode *inode);
 int ecryptfs_lookup_and_interpose_lower(struct dentry *ecryptfs_dentry,
                                        struct dentry *lower_dentry,
@@ -679,9 +677,6 @@ int
 ecryptfs_parse_packet_set(struct ecryptfs_crypt_stat *crypt_stat,
                          unsigned char *src, struct dentry *ecryptfs_dentry);
 int ecryptfs_truncate(struct dentry *dentry, loff_t new_length);
-int ecryptfs_inode_test(struct inode *inode, void *candidate_lower_inode);
-int ecryptfs_inode_set(struct inode *inode, void *lower_inode);
-void ecryptfs_init_inode(struct inode *inode, struct inode *lower_inode);
 ssize_t
 ecryptfs_getxattr_lower(struct dentry *lower_dentry, const char *name,
                        void *value, size_t size);
index 94ab3c06317a87283094b18f06ab466064ac8817..704a8c8fe19ae45285dabf696c7efcd1c20cc4cd 100644 (file)
@@ -51,6 +51,95 @@ static void unlock_dir(struct dentry *dir)
        dput(dir);
 }
 
+static int ecryptfs_inode_test(struct inode *inode, void *lower_inode)
+{
+       if (ecryptfs_inode_to_lower(inode) == (struct inode *)lower_inode)
+               return 1;
+       return 0;
+}
+
+static int ecryptfs_inode_set(struct inode *inode, void *lower_inode)
+{
+       ecryptfs_set_inode_lower(inode, (struct inode *)lower_inode);
+       inode->i_ino = ((struct inode *)lower_inode)->i_ino;
+       inode->i_version++;
+       inode->i_op = &ecryptfs_main_iops;
+       inode->i_fop = &ecryptfs_main_fops;
+       inode->i_mapping->a_ops = &ecryptfs_aops;
+       return 0;
+}
+
+struct inode *ecryptfs_get_inode(struct inode *lower_inode,
+                                struct super_block *sb)
+{
+       struct inode *inode;
+       int rc = 0;
+
+       if (lower_inode->i_sb != ecryptfs_superblock_to_lower(sb)) {
+               rc = -EXDEV;
+               goto out;
+       }
+       if (!igrab(lower_inode)) {
+               rc = -ESTALE;
+               goto out;
+       }
+       inode = iget5_locked(sb, (unsigned long)lower_inode,
+                            ecryptfs_inode_test, ecryptfs_inode_set,
+                            lower_inode);
+       if (!inode) {
+               rc = -EACCES;
+               iput(lower_inode);
+               goto out;
+       }
+       if (inode->i_state & I_NEW)
+               unlock_new_inode(inode);
+       else
+               iput(lower_inode);
+       if (S_ISLNK(lower_inode->i_mode))
+               inode->i_op = &ecryptfs_symlink_iops;
+       else if (S_ISDIR(lower_inode->i_mode))
+               inode->i_op = &ecryptfs_dir_iops;
+       if (S_ISDIR(lower_inode->i_mode))
+               inode->i_fop = &ecryptfs_dir_fops;
+       if (special_file(lower_inode->i_mode))
+               init_special_inode(inode, lower_inode->i_mode,
+                                  lower_inode->i_rdev);
+       fsstack_copy_attr_all(inode, lower_inode);
+       /* This size will be overwritten for real files w/ headers and
+        * other metadata */
+       fsstack_copy_inode_size(inode, lower_inode);
+       return inode;
+out:
+       return ERR_PTR(rc);
+}
+
+#define ECRYPTFS_INTERPOSE_FLAG_D_ADD                 0x00000001
+/**
+ * ecryptfs_interpose
+ * @lower_dentry: Existing dentry in the lower filesystem
+ * @dentry: ecryptfs' dentry
+ * @sb: ecryptfs's super_block
+ * @flags: flags to govern behavior of interpose procedure
+ *
+ * Interposes upper and lower dentries.
+ *
+ * Returns zero on success; non-zero otherwise
+ */
+static int ecryptfs_interpose(struct dentry *lower_dentry,
+                             struct dentry *dentry, struct super_block *sb,
+                             u32 flags)
+{
+       struct inode *lower_inode = lower_dentry->d_inode;
+       struct inode *inode = ecryptfs_get_inode(lower_inode, sb);
+       if (IS_ERR(inode))
+               return PTR_ERR(inode);
+       if (flags & ECRYPTFS_INTERPOSE_FLAG_D_ADD)
+               d_add(dentry, inode);
+       else
+               d_instantiate(dentry, inode);
+       return 0;
+}
+
 /**
  * ecryptfs_create_underlying_file
  * @lower_dir_inode: inode of the parent in the lower fs of the new file
@@ -1079,21 +1168,6 @@ out:
        return rc;
 }
 
-int ecryptfs_inode_test(struct inode *inode, void *candidate_lower_inode)
-{
-       if ((ecryptfs_inode_to_lower(inode)
-            == (struct inode *)candidate_lower_inode))
-               return 1;
-       else
-               return 0;
-}
-
-int ecryptfs_inode_set(struct inode *inode, void *lower_inode)
-{
-       ecryptfs_init_inode(inode, (struct inode *)lower_inode);
-       return 0;
-}
-
 const struct inode_operations ecryptfs_symlink_iops = {
        .readlink = ecryptfs_readlink,
        .follow_link = ecryptfs_follow_link,
index 89b93389af8ee0a69b44cbfe709f4f766156a6c0..7c697abab39619f9d036842f86fe9e660ef0bcce 100644 (file)
@@ -168,75 +168,6 @@ void ecryptfs_put_lower_file(struct inode *inode)
        }
 }
 
-static struct inode *ecryptfs_get_inode(struct inode *lower_inode,
-                      struct super_block *sb)
-{
-       struct inode *inode;
-       int rc = 0;
-
-       if (lower_inode->i_sb != ecryptfs_superblock_to_lower(sb)) {
-               rc = -EXDEV;
-               goto out;
-       }
-       if (!igrab(lower_inode)) {
-               rc = -ESTALE;
-               goto out;
-       }
-       inode = iget5_locked(sb, (unsigned long)lower_inode,
-                            ecryptfs_inode_test, ecryptfs_inode_set,
-                            lower_inode);
-       if (!inode) {
-               rc = -EACCES;
-               iput(lower_inode);
-               goto out;
-       }
-       if (inode->i_state & I_NEW)
-               unlock_new_inode(inode);
-       else
-               iput(lower_inode);
-       if (S_ISLNK(lower_inode->i_mode))
-               inode->i_op = &ecryptfs_symlink_iops;
-       else if (S_ISDIR(lower_inode->i_mode))
-               inode->i_op = &ecryptfs_dir_iops;
-       if (S_ISDIR(lower_inode->i_mode))
-               inode->i_fop = &ecryptfs_dir_fops;
-       if (special_file(lower_inode->i_mode))
-               init_special_inode(inode, lower_inode->i_mode,
-                                  lower_inode->i_rdev);
-       fsstack_copy_attr_all(inode, lower_inode);
-       /* This size will be overwritten for real files w/ headers and
-        * other metadata */
-       fsstack_copy_inode_size(inode, lower_inode);
-       return inode;
-out:
-       return ERR_PTR(rc);
-}
-
-/**
- * ecryptfs_interpose
- * @lower_dentry: Existing dentry in the lower filesystem
- * @dentry: ecryptfs' dentry
- * @sb: ecryptfs's super_block
- * @flags: flags to govern behavior of interpose procedure
- *
- * Interposes upper and lower dentries.
- *
- * Returns zero on success; non-zero otherwise
- */
-int ecryptfs_interpose(struct dentry *lower_dentry, struct dentry *dentry,
-                      struct super_block *sb, u32 flags)
-{
-       struct inode *lower_inode = lower_dentry->d_inode;
-       struct inode *inode = ecryptfs_get_inode(lower_inode, sb);
-       if (IS_ERR(inode))
-               return PTR_ERR(inode);
-       if (flags & ECRYPTFS_INTERPOSE_FLAG_D_ADD)
-               d_add(dentry, inode);
-       else
-               d_instantiate(dentry, inode);
-       return 0;
-}
-
 enum { ecryptfs_opt_sig, ecryptfs_opt_ecryptfs_sig,
        ecryptfs_opt_cipher, ecryptfs_opt_ecryptfs_cipher,
        ecryptfs_opt_ecryptfs_key_bytes,
index 245b517bf1b65ec5dc5dfa294891e40038d201d7..dbd52d40df4c4c94100d650db5097e0567dad3d3 100644 (file)
@@ -92,22 +92,6 @@ static void ecryptfs_destroy_inode(struct inode *inode)
        call_rcu(&inode->i_rcu, ecryptfs_i_callback);
 }
 
-/**
- * ecryptfs_init_inode
- * @inode: The ecryptfs inode
- *
- * Set up the ecryptfs inode.
- */
-void ecryptfs_init_inode(struct inode *inode, struct inode *lower_inode)
-{
-       ecryptfs_set_inode_lower(inode, lower_inode);
-       inode->i_ino = lower_inode->i_ino;
-       inode->i_version++;
-       inode->i_op = &ecryptfs_main_iops;
-       inode->i_fop = &ecryptfs_main_fops;
-       inode->i_mapping->a_ops = &ecryptfs_aops;
-}
-
 /**
  * ecryptfs_statfs
  * @sb: The ecryptfs super block