History

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.

Miao Xie committed 9 years ago

Commit cf0a5e81 parent 3b10fdc2 files · +36 −40Browse files

Unified · Split

2 files
  1. fs/ext4/inode.c +28 −39
  2. fs/ext4/xattr.c +8 −1
fs/ext4/inode.c+28−39
@@ -5706,21 +5706,35 @@ ext4_reserve_inode_write(handle_t *handle, struct inode *inode, · 5705 unmodified lines
57065706 * Expand an inode by new_extra_isize bytes.
57075707 * Returns 0 on success or negative error number on failure.
57085708 */
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)
57135713 {
57145714 struct ext4_inode *raw_inode;
57155715 struct ext4_xattr_ibody_header *header;
57165716 int no_expand;
57175717 int error;
57185718
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;
57215735
57225736 if (ext4_write_trylock_xattr(inode, &no_expand) == 0)
5723− return 0;
5737+ return -EBUSY;
57245738
57255739 raw_inode = ext4_raw_inode(&iloc);
57265740
@@ -5747,6 +5761,7 @@ static int ext4_expand_extra_isize(struct inode *inode, · 20 unmodified lines
57475761 no_expand = 1;
57485762 }
57495763 ext4_write_unlock_xattr(inode, &no_expand);
5764+
57505765 return error;
57515766 }
57525767
@@ -5767,44 +5782,18 @@ int ext4_mark_inode_dirty(handle_t *handle, struct inode *inode) · 14 unmodified lines
57675782 {
57685783 struct ext4_iloc iloc;
57695784 struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb);
5770− static unsigned int mnt_count;
5771− int err, ret;
5785+ int err;
57725786
57735787 might_sleep();
57745788 trace_ext4_mark_inode_dirty(inode, _RET_IP_);
57755789 err = ext4_reserve_inode_write(handle, inode, &iloc);
57765790 if (err)
57775791 return err;
5778− if (EXT4_I(inode)->i_extra_isize < sbi->s_want_extra_isize &&
5779− !ext4_test_inode_state(inode, EXT4_STATE_NO_EXPAND)) {
5780− /*
5781− * In nojournal mode, we can immediately attempt to expand
5782− * the inode. When journaled, we first need to obtain extra
5783− * buffer credits since we may write into the EA block
5784− * with this same handle. If journal_extend fails, then it will
5785− * only result in a minor loss of functionality for that inode.
5786− * If this is felt to be critical, then e2fsck should be run to
5787− * force a large enough s_min_extra_isize.
5788− */
5789− if (!ext4_handle_valid(handle) ||
5790− jbd2_journal_extend(handle,
5791− EXT4_DATA_TRANS_BLOCKS(inode->i_sb)) == 0) {
5792− ret = ext4_expand_extra_isize(inode,
5793− sbi->s_want_extra_isize,
5794− iloc, handle);
5795− if (ret) {
5796− if (mnt_count !=
5797− le16_to_cpu(sbi->s_es->s_mnt_count)) {
5798− ext4_warning(inode->i_sb,
5799− "Unable to expand inode %lu. Delete"
5800− " some EAs or run e2fsck.",
5801− inode->i_ino);
5802− mnt_count =
5803− le16_to_cpu(sbi->s_es->s_mnt_count);
5804− }
5805− }
5806− }
5807− }
5792+
5793+ if (EXT4_I(inode)->i_extra_isize < sbi->s_want_extra_isize)
5794+ ext4_try_to_expand_extra_isize(inode, sbi->s_want_extra_isize,
5795+ iloc, handle);
5796+
58085797 return ext4_mark_iloc_dirty(handle, inode, &iloc);
58095798 }
58105799
fs/ext4/xattr.c+8−1
@@ -2638,12 +2638,14 @@ int ext4_expand_extra_isize_ea(struct inode *inode, int new_extra_isize, · 2637 unmodified lines
26382638 {
26392639 struct ext4_xattr_ibody_header *header;
26402640 struct buffer_head *bh = NULL;
2641+ struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb);
2642+ static unsigned int mnt_count;
26412643 size_t min_offs;
26422644 size_t ifree, bfree;
26432645 int total_ino;
26442646 void *base, *end;
26452647 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);
26472649 int isize_diff; /* How much do we need to grow i_extra_isize */
26482650
26492651 retry:
@@ -2731,6 +2733,11 @@ out: · 81 unmodified lines
27312733
27322734 cleanup:
27332735 brelse(bh);
2736+ if (mnt_count != le16_to_cpu(sbi->s_es->s_mnt_count)) {
2737+ ext4_warning(inode->i_sb, "Unable to expand inode %lu. Delete some EAs or run e2fsck.",
2738+ inode->i_ino);
2739+ mnt_count = le16_to_cpu(sbi->s_es->s_mnt_count);
2740+ }
27342741 return error;
27352742 }
27362743