aboutsummaryrefslogtreecommitdiffstats
path: root/fs/ecryptfs/file.c
diff options
context:
space:
mode:
authorMichael Halcrow <mhalcrow@us.ibm.com>2007-10-16 04:28:10 -0400
committerLinus Torvalds <torvalds@woody.linux-foundation.org>2007-10-16 12:43:12 -0400
commit2ed92554abc5c40d4450f9869c9565a1919a9242 (patch)
tree3b9be8b86474ad61d357990185476fc56ac2f490 /fs/ecryptfs/file.c
parentd7cdc5febf9f2664755002c3a2f84bd348389fe9 (diff)
eCryptfs: make open, truncate, and setattr use persistent file
Rather than open a new lower file for every eCryptfs file that is opened, truncated, or setattr'd, instead use the existing lower persistent file for the eCryptfs inode. Change truncate to use read_write.c functions. Change ecryptfs_getxattr() to use the common ecryptfs_getxattr_lower() function. Signed-off-by: Michael Halcrow <mhalcrow@us.ibm.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'fs/ecryptfs/file.c')
-rw-r--r--fs/ecryptfs/file.c50
1 files changed, 9 insertions, 41 deletions
diff --git a/fs/ecryptfs/file.c b/fs/ecryptfs/file.c
index df70bfa176d9..95be9a90c504 100644
--- a/fs/ecryptfs/file.c
+++ b/fs/ecryptfs/file.c
@@ -187,11 +187,7 @@ static int ecryptfs_open(struct inode *inode, struct file *file)
187 /* Private value of ecryptfs_dentry allocated in 187 /* Private value of ecryptfs_dentry allocated in
188 * ecryptfs_lookup() */ 188 * ecryptfs_lookup() */
189 struct dentry *lower_dentry = ecryptfs_dentry_to_lower(ecryptfs_dentry); 189 struct dentry *lower_dentry = ecryptfs_dentry_to_lower(ecryptfs_dentry);
190 struct inode *lower_inode = NULL;
191 struct file *lower_file = NULL;
192 struct vfsmount *lower_mnt;
193 struct ecryptfs_file_info *file_info; 190 struct ecryptfs_file_info *file_info;
194 int lower_flags;
195 191
196 mount_crypt_stat = &ecryptfs_superblock_to_private( 192 mount_crypt_stat = &ecryptfs_superblock_to_private(
197 ecryptfs_dentry->d_sb)->mount_crypt_stat; 193 ecryptfs_dentry->d_sb)->mount_crypt_stat;
@@ -219,26 +215,12 @@ static int ecryptfs_open(struct inode *inode, struct file *file)
219 if (!(crypt_stat->flags & ECRYPTFS_POLICY_APPLIED)) { 215 if (!(crypt_stat->flags & ECRYPTFS_POLICY_APPLIED)) {
220 ecryptfs_printk(KERN_DEBUG, "Setting flags for stat...\n"); 216 ecryptfs_printk(KERN_DEBUG, "Setting flags for stat...\n");
221 /* Policy code enabled in future release */ 217 /* Policy code enabled in future release */
222 crypt_stat->flags |= ECRYPTFS_POLICY_APPLIED; 218 crypt_stat->flags |= (ECRYPTFS_POLICY_APPLIED
223 crypt_stat->flags |= ECRYPTFS_ENCRYPTED; 219 | ECRYPTFS_ENCRYPTED);
224 } 220 }
225 mutex_unlock(&crypt_stat->cs_mutex); 221 mutex_unlock(&crypt_stat->cs_mutex);
226 lower_flags = file->f_flags; 222 ecryptfs_set_file_lower(
227 if ((lower_flags & O_ACCMODE) == O_WRONLY) 223 file, ecryptfs_inode_to_private(inode)->lower_file);
228 lower_flags = (lower_flags & O_ACCMODE) | O_RDWR;
229 if (file->f_flags & O_APPEND)
230 lower_flags &= ~O_APPEND;
231 lower_mnt = ecryptfs_dentry_to_lower_mnt(ecryptfs_dentry);
232 /* Corresponding fput() in ecryptfs_release() */
233 rc = ecryptfs_open_lower_file(&lower_file, lower_dentry, lower_mnt,
234 lower_flags);
235 if (rc) {
236 ecryptfs_printk(KERN_ERR, "Error opening lower file\n");
237 goto out_puts;
238 }
239 ecryptfs_set_file_lower(file, lower_file);
240 /* Isn't this check the same as the one in lookup? */
241 lower_inode = lower_dentry->d_inode;
242 if (S_ISDIR(ecryptfs_dentry->d_inode->i_mode)) { 224 if (S_ISDIR(ecryptfs_dentry->d_inode->i_mode)) {
243 ecryptfs_printk(KERN_DEBUG, "This is a directory\n"); 225 ecryptfs_printk(KERN_DEBUG, "This is a directory\n");
244 crypt_stat->flags &= ~(ECRYPTFS_ENCRYPTED); 226 crypt_stat->flags &= ~(ECRYPTFS_ENCRYPTED);
@@ -260,7 +242,7 @@ static int ecryptfs_open(struct inode *inode, struct file *file)
260 "and plaintext passthrough mode is not " 242 "and plaintext passthrough mode is not "
261 "enabled; returning -EIO\n"); 243 "enabled; returning -EIO\n");
262 mutex_unlock(&crypt_stat->cs_mutex); 244 mutex_unlock(&crypt_stat->cs_mutex);
263 goto out_puts; 245 goto out_free;
264 } 246 }
265 rc = 0; 247 rc = 0;
266 crypt_stat->flags &= ~(ECRYPTFS_ENCRYPTED); 248 crypt_stat->flags &= ~(ECRYPTFS_ENCRYPTED);
@@ -272,11 +254,8 @@ static int ecryptfs_open(struct inode *inode, struct file *file)
272 ecryptfs_printk(KERN_DEBUG, "inode w/ addr = [0x%p], i_ino = [0x%.16x] " 254 ecryptfs_printk(KERN_DEBUG, "inode w/ addr = [0x%p], i_ino = [0x%.16x] "
273 "size: [0x%.16x]\n", inode, inode->i_ino, 255 "size: [0x%.16x]\n", inode, inode->i_ino,
274 i_size_read(inode)); 256 i_size_read(inode));
275 ecryptfs_set_file_lower(file, lower_file);
276 goto out; 257 goto out;
277out_puts: 258out_free:
278 mntput(lower_mnt);
279 dput(lower_dentry);
280 kmem_cache_free(ecryptfs_file_info_cache, 259 kmem_cache_free(ecryptfs_file_info_cache,
281 ecryptfs_file_to_private(file)); 260 ecryptfs_file_to_private(file));
282out: 261out:
@@ -296,20 +275,9 @@ static int ecryptfs_flush(struct file *file, fl_owner_t td)
296 275
297static int ecryptfs_release(struct inode *inode, struct file *file) 276static int ecryptfs_release(struct inode *inode, struct file *file)
298{ 277{
299 struct file *lower_file = ecryptfs_file_to_lower(file); 278 kmem_cache_free(ecryptfs_file_info_cache,
300 struct ecryptfs_file_info *file_info = ecryptfs_file_to_private(file); 279 ecryptfs_file_to_private(file));
301 struct inode *lower_inode = ecryptfs_inode_to_lower(inode); 280 return 0;
302 int rc;
303
304 rc = ecryptfs_close_lower_file(lower_file);
305 if (rc) {
306 printk(KERN_ERR "Error closing lower_file\n");
307 goto out;
308 }
309 inode->i_blocks = lower_inode->i_blocks;
310 kmem_cache_free(ecryptfs_file_info_cache, file_info);
311out:
312 return rc;
313} 281}
314 282
315static int 283static int