f2fs crypto: avoid unneeded memory allocation when {en/de}crypting symlink
PATCH 1/1 f2fs crypto: avoid unneeded memory allocation when {en/de}crypting symlink
This patch adopts f2fs with codes of ext4, it removes unneeded memory allocation in creating/accessing path of symlink.
Signed-off-by Chao Yu <[email protected]>
--- fs/f2fs/crypto_fname.c | 21 +++++++++------ fs/f2fs/f2fs.h | 1 + fs/f2fs/namei.c | 72 ++++++++++++++++++++++++-------------------------- 3 files changed, 48 insertions(+), 46 deletions(-)
fs/f2fs/crypto_fname.c +13 -8
@@ -257,6 +257,18 @@ u32 f2fs_fname_crypto_round_up(u32 size, u32 blksize)return ((size + blksize -1 ) / blksize) * blksize; } +unsigned f2fs_fname_encrypted_size (struct inode *inode,u32 ilen) +{ +struct f2fs_crypt_info *ci =F2FS_I (inode)->i_crypt_info; +int padding =32 ; + +if (ci) + padding =4 << (ci->ci_flags &F2FS_POLICY_FLAGS_PAD_MASK ); +if (ilen <F2FS_CRYPTO_BLOCK_SIZE ) + ilen =F2FS_CRYPTO_BLOCK_SIZE ; +return f2fs_fname_crypto_round_up (ilen, padding); +} +/** * f2fs_fname_crypto_alloc_obuff() - *
@@ -266,15 +278,8 @@ u32 f2fs_fname_crypto_round_up(u32 size, u32 blksize)int f2fs_fname_crypto_alloc_buffer (struct inode *inode,u32 ilen,struct f2fs_str *crypto_str) { -unsigned int olen; -int padding =32 ; -struct f2fs_crypt_info *ci =F2FS_I (inode)->i_crypt_info; +unsigned int olen =f2fs_fname_encrypted_size (inode, ilen); -if (ci) - padding =4 << (ci->ci_flags &F2FS_POLICY_FLAGS_PAD_MASK ); -if (ilen <F2FS_CRYPTO_BLOCK_SIZE ) - ilen =F2FS_CRYPTO_BLOCK_SIZE ; - olen =f2fs_fname_crypto_round_up (ilen, padding); crypto_str->len = olen;if (olen <F2FS_FNAME_CRYPTO_DIGEST_SIZE *2 ) olen =F2FS_FNAME_CRYPTO_DIGEST_SIZE *2 ;
fs/f2fs/f2fs.h +1 -0
@@ -2225,6 +2225,7 @@ int _f2fs_get_encryption_info(struct inode *inode);/* crypto_fname.c */ bool f2fs_valid_filenames_enc_mode (uint32_t );u32 f2fs_fname_crypto_round_up (u32 ,u32 ); +unsigned f2fs_fname_encrypted_size (struct inode *,u32 );int f2fs_fname_crypto_alloc_buffer (struct inode *,u32 ,struct f2fs_str *);int f2fs_fname_disk_to_usr (struct inode *,f2fs_hash_t *,const struct f2fs_str *,struct f2fs_str *);
fs/f2fs/namei.c +34 -38
136 lines not on this page · raw message
Signature · 1 line
2.7.0