summaryrefslogtreecommitdiffstats
path: root/fs/ext4/ialloc.c
diff options
context:
space:
mode:
authorTahsin Erdogan <tahsin@google.com>2017-07-06 00:01:59 -0400
committerTheodore Ts'o <tytso@mit.edu>2017-07-06 00:01:59 -0400
commitaf65207c76ce8e6263a3b097ea35365dde9913d0 (patch)
tree222298b2f179736a158d83341511cd9c7a81eca0 /fs/ext4/ialloc.c
parentad47f9533994d7e3d2dbfa4fffe85934a1627edc (diff)
ext4: fix __ext4_new_inode() journal credits calculation
ea_inode feature allows creating extended attributes that are up to 64k in size. Update __ext4_new_inode() to pick increased credit limits. To avoid overallocating too many journal credits, update __ext4_xattr_set_credits() to make a distinction between xattr create vs update. This helps __ext4_new_inode() because all attributes are known to be new, so we can save credits that are normally needed to delete old values. Also, have fscrypt specify its maximum context size so that we don't end up allocating credits for 64k size. Signed-off-by: Tahsin Erdogan <tahsin@google.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Diffstat (limited to 'fs/ext4/ialloc.c')
-rw-r--r--fs/ext4/ialloc.c52
1 files changed, 45 insertions, 7 deletions
diff --git a/fs/ext4/ialloc.c b/fs/ext4/ialloc.c
index 0c79e3efcaf7..507bfb3344d4 100644
--- a/fs/ext4/ialloc.c
+++ b/fs/ext4/ialloc.c
@@ -766,11 +766,13 @@ struct inode *__ext4_new_inode(handle_t *handle, struct inode *dir,
766 if (!dir || !dir->i_nlink) 766 if (!dir || !dir->i_nlink)
767 return ERR_PTR(-EPERM); 767 return ERR_PTR(-EPERM);
768 768
769 if (unlikely(ext4_forced_shutdown(EXT4_SB(dir->i_sb)))) 769 sb = dir->i_sb;
770 sbi = EXT4_SB(sb);
771
772 if (unlikely(ext4_forced_shutdown(sbi)))
770 return ERR_PTR(-EIO); 773 return ERR_PTR(-EIO);
771 774
772 if ((ext4_encrypted_inode(dir) || 775 if ((ext4_encrypted_inode(dir) || DUMMY_ENCRYPTION_ENABLED(sbi)) &&
773 DUMMY_ENCRYPTION_ENABLED(EXT4_SB(dir->i_sb))) &&
774 (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode)) && 776 (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode)) &&
775 !(i_flags & EXT4_EA_INODE_FL)) { 777 !(i_flags & EXT4_EA_INODE_FL)) {
776 err = fscrypt_get_encryption_info(dir); 778 err = fscrypt_get_encryption_info(dir);
@@ -778,19 +780,55 @@ struct inode *__ext4_new_inode(handle_t *handle, struct inode *dir,
778 return ERR_PTR(err); 780 return ERR_PTR(err);
779 if (!fscrypt_has_encryption_key(dir)) 781 if (!fscrypt_has_encryption_key(dir))
780 return ERR_PTR(-ENOKEY); 782 return ERR_PTR(-ENOKEY);
781 if (!handle)
782 nblocks += EXT4_DATA_TRANS_BLOCKS(dir->i_sb);
783 encrypt = 1; 783 encrypt = 1;
784 } 784 }
785 785
786 sb = dir->i_sb; 786 if (!handle && sbi->s_journal && !(i_flags & EXT4_EA_INODE_FL)) {
787#ifdef CONFIG_EXT4_FS_POSIX_ACL
788 struct posix_acl *p = get_acl(dir, ACL_TYPE_DEFAULT);
789
790 if (p) {
791 int acl_size = p->a_count * sizeof(ext4_acl_entry);
792
793 nblocks += (S_ISDIR(mode) ? 2 : 1) *
794 __ext4_xattr_set_credits(sb, NULL /* inode */,
795 NULL /* block_bh */, acl_size,
796 true /* is_create */);
797 posix_acl_release(p);
798 }
799#endif
800
801#ifdef CONFIG_SECURITY
802 {
803 int num_security_xattrs = 1;
804
805#ifdef CONFIG_INTEGRITY
806 num_security_xattrs++;
807#endif
808 /*
809 * We assume that security xattrs are never
810 * more than 1k. In practice they are under
811 * 128 bytes.
812 */
813 nblocks += num_security_xattrs *
814 __ext4_xattr_set_credits(sb, NULL /* inode */,
815 NULL /* block_bh */, 1024,
816 true /* is_create */);
817 }
818#endif
819 if (encrypt)
820 nblocks += __ext4_xattr_set_credits(sb,
821 NULL /* inode */, NULL /* block_bh */,
822 FSCRYPT_SET_CONTEXT_MAX_SIZE,
823 true /* is_create */);
824 }
825
787 ngroups = ext4_get_groups_count(sb); 826 ngroups = ext4_get_groups_count(sb);
788 trace_ext4_request_inode(dir, mode); 827 trace_ext4_request_inode(dir, mode);
789 inode = new_inode(sb); 828 inode = new_inode(sb);
790 if (!inode) 829 if (!inode)
791 return ERR_PTR(-ENOMEM); 830 return ERR_PTR(-ENOMEM);
792 ei = EXT4_I(inode); 831 ei = EXT4_I(inode);
793 sbi = EXT4_SB(sb);
794 832
795 /* 833 /*
796 * Initialize owners and quota early so that we don't have to account 834 * Initialize owners and quota early so that we don't have to account