Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

ext4: restructure ext4_expand_extra_isize

Current ext4_expand_extra_isize just tries to expand extra isize, if
someone is holding xattr lock or some check fails, it will give up.
So rename its name to ext4_try_to_expand_extra_isize.

Besides that, we clean up unnecessary check and move some relative checks
into it.

Signed-off-by: Miao Xie <miaoxie@huawei.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Reviewed-by: Wang Shilong <wshilong@ddn.com>

authored by

Miao Xie and committed by
Theodore Ts'o
cf0a5e81 3b10fdc6

+36 -40
+28 -39
fs/ext4/inode.c
··· 5706 5706 * Expand an inode by new_extra_isize bytes. 5707 5707 * Returns 0 on success or negative error number on failure. 5708 5708 */ 5709 - static int ext4_expand_extra_isize(struct inode *inode, 5710 - unsigned int new_extra_isize, 5711 - struct ext4_iloc iloc, 5712 - handle_t *handle) 5709 + static int ext4_try_to_expand_extra_isize(struct inode *inode, 5710 + unsigned int new_extra_isize, 5711 + struct ext4_iloc iloc, 5712 + handle_t *handle) 5713 5713 { 5714 5714 struct ext4_inode *raw_inode; 5715 5715 struct ext4_xattr_ibody_header *header; 5716 5716 int no_expand; 5717 5717 int error; 5718 5718 5719 - if (EXT4_I(inode)->i_extra_isize >= new_extra_isize) 5720 - return 0; 5719 + if (ext4_test_inode_state(inode, EXT4_STATE_NO_EXPAND)) 5720 + return -EOVERFLOW; 5721 + 5722 + /* 5723 + * In nojournal mode, we can immediately attempt to expand 5724 + * the inode. When journaled, we first need to obtain extra 5725 + * buffer credits since we may write into the EA block 5726 + * with this same handle. If journal_extend fails, then it will 5727 + * only result in a minor loss of functionality for that inode. 5728 + * If this is felt to be critical, then e2fsck should be run to 5729 + * force a large enough s_min_extra_isize. 5730 + */ 5731 + if (ext4_handle_valid(handle) && 5732 + jbd2_journal_extend(handle, 5733 + EXT4_DATA_TRANS_BLOCKS(inode->i_sb)) != 0) 5734 + return -ENOSPC; 5721 5735 5722 5736 if (ext4_write_trylock_xattr(inode, &no_expand) == 0) 5723 - return 0; 5737 + return -EBUSY; 5724 5738 5725 5739 raw_inode = ext4_raw_inode(&iloc); 5726 5740 ··· 5761 5747 no_expand = 1; 5762 5748 } 5763 5749 ext4_write_unlock_xattr(inode, &no_expand); 5750 + 5764 5751 return error; 5765 5752 } 5766 5753 ··· 5782 5767 { 5783 5768 struct ext4_iloc iloc; 5784 5769 struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb); 5785 - static unsigned int mnt_count; 5786 - int err, ret; 5770 + int err; 5787 5771 5788 5772 might_sleep(); 5789 5773 trace_ext4_mark_inode_dirty(inode, _RET_IP_); 5790 5774 err = ext4_reserve_inode_write(handle, inode, &iloc); 5791 5775 if (err) 5792 5776 return err; 5793 - if (EXT4_I(inode)->i_extra_isize < sbi->s_want_extra_isize && 5794 - !ext4_test_inode_state(inode, EXT4_STATE_NO_EXPAND)) { 5795 - /* 5796 - * In nojournal mode, we can immediately attempt to expand 5797 - * the inode. When journaled, we first need to obtain extra 5798 - * buffer credits since we may write into the EA block 5799 - * with this same handle. If journal_extend fails, then it will 5800 - * only result in a minor loss of functionality for that inode. 5801 - * If this is felt to be critical, then e2fsck should be run to 5802 - * force a large enough s_min_extra_isize. 5803 - */ 5804 - if (!ext4_handle_valid(handle) || 5805 - jbd2_journal_extend(handle, 5806 - EXT4_DATA_TRANS_BLOCKS(inode->i_sb)) == 0) { 5807 - ret = ext4_expand_extra_isize(inode, 5808 - sbi->s_want_extra_isize, 5809 - iloc, handle); 5810 - if (ret) { 5811 - if (mnt_count != 5812 - le16_to_cpu(sbi->s_es->s_mnt_count)) { 5813 - ext4_warning(inode->i_sb, 5814 - "Unable to expand inode %lu. Delete" 5815 - " some EAs or run e2fsck.", 5816 - inode->i_ino); 5817 - mnt_count = 5818 - le16_to_cpu(sbi->s_es->s_mnt_count); 5819 - } 5820 - } 5821 - } 5822 - } 5777 + 5778 + if (EXT4_I(inode)->i_extra_isize < sbi->s_want_extra_isize) 5779 + ext4_try_to_expand_extra_isize(inode, sbi->s_want_extra_isize, 5780 + iloc, handle); 5781 + 5823 5782 return ext4_mark_iloc_dirty(handle, inode, &iloc); 5824 5783 } 5825 5784
+8 -1
fs/ext4/xattr.c
··· 2638 2638 { 2639 2639 struct ext4_xattr_ibody_header *header; 2640 2640 struct buffer_head *bh = NULL; 2641 + struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb); 2642 + static unsigned int mnt_count; 2641 2643 size_t min_offs; 2642 2644 size_t ifree, bfree; 2643 2645 int total_ino; 2644 2646 void *base, *end; 2645 2647 int error = 0, tried_min_extra_isize = 0; 2646 - int s_min_extra_isize = le16_to_cpu(EXT4_SB(inode->i_sb)->s_es->s_min_extra_isize); 2648 + int s_min_extra_isize = le16_to_cpu(sbi->s_es->s_min_extra_isize); 2647 2649 int isize_diff; /* How much do we need to grow i_extra_isize */ 2648 2650 2649 2651 retry: ··· 2733 2731 2734 2732 cleanup: 2735 2733 brelse(bh); 2734 + if (mnt_count != le16_to_cpu(sbi->s_es->s_mnt_count)) { 2735 + ext4_warning(inode->i_sb, "Unable to expand inode %lu. Delete some EAs or run e2fsck.", 2736 + inode->i_ino); 2737 + mnt_count = le16_to_cpu(sbi->s_es->s_mnt_count); 2738 + } 2736 2739 return error; 2737 2740 } 2738 2741