diff options
author | Tyler Hicks <tyhicks@linux.vnet.ibm.com> | 2011-05-24 05:56:23 -0400 |
---|---|---|
committer | Tyler Hicks <tyhicks@linux.vnet.ibm.com> | 2011-05-29 15:24:24 -0400 |
commit | 778aeb42a708d2a57e491d2cbb5a1e74f61270b9 (patch) | |
tree | 6651d8a2356b9075e6978285cbcfa7aab16e9b7a /fs/ecryptfs/crypto.c | |
parent | 7a86617e553f47761b10f57de472d7262562b7de (diff) |
eCryptfs: Cleanup and optimize ecryptfs_lookup_interpose()
ecryptfs_lookup_interpose() has turned into spaghetti code over the
years. This is an effort to clean it up.
- Shorten overly descriptive variable names such as ecryptfs_dentry
- Simplify gotos and error paths
- Create helper function for reading plaintext i_size from metadata
It also includes an optimization when reading i_size from the metadata.
A complete page-sized kmem_cache_alloc() was being done to read in 16
bytes of metadata. The buffer for that is now statically declared.
Signed-off-by: Tyler Hicks <tyhicks@linux.vnet.ibm.com>
Diffstat (limited to 'fs/ecryptfs/crypto.c')
-rw-r--r-- | fs/ecryptfs/crypto.c | 45 |
1 files changed, 21 insertions, 24 deletions
diff --git a/fs/ecryptfs/crypto.c b/fs/ecryptfs/crypto.c index 162f9baf9eb5..66d8e6748a46 100644 --- a/fs/ecryptfs/crypto.c +++ b/fs/ecryptfs/crypto.c | |||
@@ -1201,24 +1201,19 @@ int ecryptfs_cipher_code_to_string(char *str, u8 cipher_code) | |||
1201 | return rc; | 1201 | return rc; |
1202 | } | 1202 | } |
1203 | 1203 | ||
1204 | int ecryptfs_read_and_validate_header_region(char *data, | 1204 | int ecryptfs_read_and_validate_header_region(struct inode *inode) |
1205 | struct inode *ecryptfs_inode) | ||
1206 | { | 1205 | { |
1207 | struct ecryptfs_crypt_stat *crypt_stat = | 1206 | u8 file_size[ECRYPTFS_SIZE_AND_MARKER_BYTES]; |
1208 | &(ecryptfs_inode_to_private(ecryptfs_inode)->crypt_stat); | 1207 | u8 *marker = file_size + ECRYPTFS_FILE_SIZE_BYTES; |
1209 | int rc; | 1208 | int rc; |
1210 | 1209 | ||
1211 | if (crypt_stat->extent_size == 0) | 1210 | rc = ecryptfs_read_lower(file_size, 0, ECRYPTFS_SIZE_AND_MARKER_BYTES, |
1212 | crypt_stat->extent_size = ECRYPTFS_DEFAULT_EXTENT_SIZE; | 1211 | inode); |
1213 | rc = ecryptfs_read_lower(data, 0, crypt_stat->extent_size, | 1212 | if (rc < ECRYPTFS_SIZE_AND_MARKER_BYTES) |
1214 | ecryptfs_inode); | 1213 | return rc >= 0 ? -EINVAL : rc; |
1215 | if (rc < 0) { | 1214 | rc = ecryptfs_validate_marker(marker); |
1216 | printk(KERN_ERR "%s: Error reading header region; rc = [%d]\n", | 1215 | if (!rc) |
1217 | __func__, rc); | 1216 | ecryptfs_i_size_init(file_size, inode); |
1218 | goto out; | ||
1219 | } | ||
1220 | rc = ecryptfs_validate_marker(data + ECRYPTFS_FILE_SIZE_BYTES); | ||
1221 | out: | ||
1222 | return rc; | 1217 | return rc; |
1223 | } | 1218 | } |
1224 | 1219 | ||
@@ -1562,19 +1557,21 @@ out: | |||
1562 | return rc; | 1557 | return rc; |
1563 | } | 1558 | } |
1564 | 1559 | ||
1565 | int ecryptfs_read_and_validate_xattr_region(char *page_virt, | 1560 | int ecryptfs_read_and_validate_xattr_region(struct dentry *dentry, |
1566 | struct inode *inode) | 1561 | struct inode *inode) |
1567 | { | 1562 | { |
1563 | u8 file_size[ECRYPTFS_SIZE_AND_MARKER_BYTES]; | ||
1564 | u8 *marker = file_size + ECRYPTFS_FILE_SIZE_BYTES; | ||
1568 | int rc; | 1565 | int rc; |
1569 | 1566 | ||
1570 | rc = ecryptfs_read_xattr_region(page_virt, inode); | 1567 | rc = ecryptfs_getxattr_lower(ecryptfs_dentry_to_lower(dentry), |
1571 | if (rc) | 1568 | ECRYPTFS_XATTR_NAME, file_size, |
1572 | goto out; | 1569 | ECRYPTFS_SIZE_AND_MARKER_BYTES); |
1573 | rc = ecryptfs_validate_marker(page_virt + ECRYPTFS_FILE_SIZE_BYTES); | 1570 | if (rc < ECRYPTFS_SIZE_AND_MARKER_BYTES) |
1574 | if (rc) | 1571 | return rc >= 0 ? -EINVAL : rc; |
1575 | printk(KERN_WARNING "Valid data found in [%s] xattr, but " | 1572 | rc = ecryptfs_validate_marker(marker); |
1576 | "the marker is invalid\n", ECRYPTFS_XATTR_NAME); | 1573 | if (!rc) |
1577 | out: | 1574 | ecryptfs_i_size_init(file_size, inode); |
1578 | return rc; | 1575 | return rc; |
1579 | } | 1576 | } |
1580 | 1577 | ||