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.

Merge tag 'ext4_for_linus_stable' of git://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4

Pull ext4 fixes from Ted Ts'o:
"A large number of ext4 bug fixes and cleanups for v4.13"

* tag 'ext4_for_linus_stable' of git://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4:
ext4: fix copy paste error in ext4_swap_extents()
ext4: fix overflow caused by missing cast in ext4_resize_fs()
ext4, project: expand inode extra size if possible
ext4: cleanup ext4_expand_extra_isize_ea()
ext4: restructure ext4_expand_extra_isize
ext4: fix forgetten xattr lock protection in ext4_expand_extra_isize
ext4: make xattr inode reads faster
ext4: inplace xattr block update fails to deduplicate blocks
ext4: remove unused mode parameter
ext4: fix warning about stack corruption
ext4: fix dir_nlink behaviour
ext4: silence array overflow warning
ext4: fix SEEK_HOLE/SEEK_DATA for blocksize < pagesize
ext4: release discard bio after sending discard commands
ext4: convert swap_inode_data() over to use swap() on most of the fields
ext4: error should be cleared if ea_inode isn't added to the cache
ext4: Don't clear SGID when inheriting ACLs
ext4: preserve i_mode if __ext4_set_acl() fails
ext4: remove unused metadata accounting variables
ext4: correct comment references to ext4_ext_direct_IO()

+291 -197
+17 -8
fs/ext4/acl.c
··· 193 193 switch (type) { 194 194 case ACL_TYPE_ACCESS: 195 195 name_index = EXT4_XATTR_INDEX_POSIX_ACL_ACCESS; 196 - if (acl) { 197 - error = posix_acl_update_mode(inode, &inode->i_mode, &acl); 198 - if (error) 199 - return error; 200 - inode->i_ctime = current_time(inode); 201 - ext4_mark_inode_dirty(handle, inode); 202 - } 203 196 break; 204 197 205 198 case ACL_TYPE_DEFAULT: ··· 214 221 value, size, xattr_flags); 215 222 216 223 kfree(value); 217 - if (!error) 224 + if (!error) { 218 225 set_cached_acl(inode, type, acl); 226 + } 219 227 220 228 return error; 221 229 } ··· 227 233 handle_t *handle; 228 234 int error, credits, retries = 0; 229 235 size_t acl_size = acl ? ext4_acl_size(acl->a_count) : 0; 236 + umode_t mode = inode->i_mode; 237 + int update_mode = 0; 230 238 231 239 error = dquot_initialize(inode); 232 240 if (error) ··· 243 247 if (IS_ERR(handle)) 244 248 return PTR_ERR(handle); 245 249 250 + if ((type == ACL_TYPE_ACCESS) && acl) { 251 + error = posix_acl_update_mode(inode, &mode, &acl); 252 + if (error) 253 + goto out_stop; 254 + update_mode = 1; 255 + } 256 + 246 257 error = __ext4_set_acl(handle, inode, type, acl, 0 /* xattr_flags */); 258 + if (!error && update_mode) { 259 + inode->i_mode = mode; 260 + inode->i_ctime = current_time(inode); 261 + ext4_mark_inode_dirty(handle, inode); 262 + } 263 + out_stop: 247 264 ext4_journal_stop(handle); 248 265 if (error == -ENOSPC && ext4_should_retry_alloc(inode->i_sb, &retries)) 249 266 goto retry;
+7 -6
fs/ext4/ext4.h
··· 961 961 /* 962 962 * i_block_group is the number of the block group which contains 963 963 * this file's inode. Constant across the lifetime of the inode, 964 - * it is ued for making block allocation decisions - we try to 964 + * it is used for making block allocation decisions - we try to 965 965 * place a file's data blocks near its inode block, and new inodes 966 966 * near to their parent directory's inode. 967 967 */ ··· 1049 1049 ext4_group_t i_last_alloc_group; 1050 1050 1051 1051 /* allocation reservation info for delalloc */ 1052 - /* In case of bigalloc, these refer to clusters rather than blocks */ 1052 + /* In case of bigalloc, this refer to clusters rather than blocks */ 1053 1053 unsigned int i_reserved_data_blocks; 1054 - unsigned int i_reserved_meta_blocks; 1055 - unsigned int i_allocated_meta_blocks; 1056 1054 ext4_lblk_t i_da_metadata_calc_last_lblock; 1057 1055 int i_da_metadata_calc_len; 1058 1056 ··· 2020 2022 2021 2023 #define is_dx(dir) (ext4_has_feature_dir_index((dir)->i_sb) && \ 2022 2024 ext4_test_inode_flag((dir), EXT4_INODE_INDEX)) 2023 - #define EXT4_DIR_LINK_MAX(dir) (!is_dx(dir) && (dir)->i_nlink >= EXT4_LINK_MAX) 2025 + #define EXT4_DIR_LINK_MAX(dir) unlikely((dir)->i_nlink >= EXT4_LINK_MAX && \ 2026 + !(ext4_has_feature_dir_nlink((dir)->i_sb) && is_dx(dir))) 2024 2027 #define EXT4_DIR_LINK_EMPTY(dir) ((dir)->i_nlink == 2 || (dir)->i_nlink == 1) 2025 2028 2026 2029 /* Legal values for the dx_root hash_version field: */ ··· 2461 2462 int ext4_inode_is_fast_symlink(struct inode *inode); 2462 2463 struct buffer_head *ext4_getblk(handle_t *, struct inode *, ext4_lblk_t, int); 2463 2464 struct buffer_head *ext4_bread(handle_t *, struct inode *, ext4_lblk_t, int); 2465 + int ext4_bread_batch(struct inode *inode, ext4_lblk_t block, int bh_count, 2466 + bool wait, struct buffer_head **bhs); 2464 2467 int ext4_get_block_unwritten(struct inode *inode, sector_t iblock, 2465 2468 struct buffer_head *bh_result, int create); 2466 2469 int ext4_get_block(struct inode *inode, sector_t iblock, ··· 3075 3074 struct inode *inode, 3076 3075 struct buffer_head *bh); 3077 3076 #define S_SHIFT 12 3078 - static const unsigned char ext4_type_by_mode[S_IFMT >> S_SHIFT] = { 3077 + static const unsigned char ext4_type_by_mode[(S_IFMT >> S_SHIFT) + 1] = { 3079 3078 [S_IFREG >> S_SHIFT] = EXT4_FT_REG_FILE, 3080 3079 [S_IFDIR >> S_SHIFT] = EXT4_FT_DIR, 3081 3080 [S_IFCHR >> S_SHIFT] = EXT4_FT_CHRDEV,
+3
fs/ext4/ext4_jbd2.h
··· 227 227 228 228 int ext4_mark_inode_dirty(handle_t *handle, struct inode *inode); 229 229 230 + int ext4_expand_extra_isize(struct inode *inode, 231 + unsigned int new_extra_isize, 232 + struct ext4_iloc *iloc); 230 233 /* 231 234 * Wrapper functions with which ext4 calls into JBD. 232 235 */
+5 -6
fs/ext4/extents.c
··· 4652 4652 4653 4653 static int ext4_alloc_file_blocks(struct file *file, ext4_lblk_t offset, 4654 4654 ext4_lblk_t len, loff_t new_size, 4655 - int flags, int mode) 4655 + int flags) 4656 4656 { 4657 4657 struct inode *inode = file_inode(file); 4658 4658 handle_t *handle; ··· 4815 4815 round_down(offset, 1 << blkbits) >> blkbits, 4816 4816 (round_up((offset + len), 1 << blkbits) - 4817 4817 round_down(offset, 1 << blkbits)) >> blkbits, 4818 - new_size, flags, mode); 4818 + new_size, flags); 4819 4819 if (ret) 4820 4820 goto out_dio; 4821 4821 ··· 4841 4841 inode->i_mtime = inode->i_ctime = current_time(inode); 4842 4842 4843 4843 ret = ext4_alloc_file_blocks(file, lblk, max_blocks, new_size, 4844 - flags, mode); 4844 + flags); 4845 4845 up_write(&EXT4_I(inode)->i_mmap_sem); 4846 4846 if (ret) 4847 4847 goto out_dio; ··· 4976 4976 ext4_inode_block_unlocked_dio(inode); 4977 4977 inode_dio_wait(inode); 4978 4978 4979 - ret = ext4_alloc_file_blocks(file, lblk, max_blocks, new_size, 4980 - flags, mode); 4979 + ret = ext4_alloc_file_blocks(file, lblk, max_blocks, new_size, flags); 4981 4980 ext4_inode_resume_unlocked_dio(inode); 4982 4981 if (ret) 4983 4982 goto out; ··· 5836 5837 if (e1_blk > lblk1) 5837 5838 next1 = e1_blk; 5838 5839 if (e2_blk > lblk2) 5839 - next2 = e1_blk; 5840 + next2 = e2_blk; 5840 5841 /* Do we have something to swap */ 5841 5842 if (next1 == EXT_MAX_BLOCKS || next2 == EXT_MAX_BLOCKS) 5842 5843 goto finish;
+3
fs/ext4/file.c
··· 537 537 lastoff = page_offset(page); 538 538 bh = head = page_buffers(page); 539 539 do { 540 + if (lastoff + bh->b_size <= startoff) 541 + goto next; 540 542 if (buffer_uptodate(bh) || 541 543 buffer_unwritten(bh)) { 542 544 if (whence == SEEK_DATA) ··· 553 551 unlock_page(page); 554 552 goto out; 555 553 } 554 + next: 556 555 lastoff += bh->b_size; 557 556 bh = bh->b_this_page; 558 557 } while (bh != head);
+150 -48
fs/ext4/inode.c
··· 892 892 /* 893 893 * Get block function for non-AIO DIO writes when we create unwritten extent if 894 894 * blocks are not allocated yet. The extent will be converted to written 895 - * after IO is complete from ext4_ext_direct_IO() function. 895 + * after IO is complete by ext4_direct_IO_write(). 896 896 */ 897 897 static int ext4_dio_get_block_unwritten_sync(struct inode *inode, 898 898 sector_t iblock, struct buffer_head *bh_result, int create) ··· 907 907 908 908 /* 909 909 * Mark inode as having pending DIO writes to unwritten extents. 910 - * ext4_ext_direct_IO() checks this flag and converts extents to 910 + * ext4_direct_IO_write() checks this flag and converts extents to 911 911 * written. 912 912 */ 913 913 if (!ret && buffer_unwritten(bh_result)) ··· 1013 1013 return bh; 1014 1014 put_bh(bh); 1015 1015 return ERR_PTR(-EIO); 1016 + } 1017 + 1018 + /* Read a contiguous batch of blocks. */ 1019 + int ext4_bread_batch(struct inode *inode, ext4_lblk_t block, int bh_count, 1020 + bool wait, struct buffer_head **bhs) 1021 + { 1022 + int i, err; 1023 + 1024 + for (i = 0; i < bh_count; i++) { 1025 + bhs[i] = ext4_getblk(NULL, inode, block + i, 0 /* map_flags */); 1026 + if (IS_ERR(bhs[i])) { 1027 + err = PTR_ERR(bhs[i]); 1028 + bh_count = i; 1029 + goto out_brelse; 1030 + } 1031 + } 1032 + 1033 + for (i = 0; i < bh_count; i++) 1034 + /* Note that NULL bhs[i] is valid because of holes. */ 1035 + if (bhs[i] && !buffer_uptodate(bhs[i])) 1036 + ll_rw_block(REQ_OP_READ, REQ_META | REQ_PRIO, 1, 1037 + &bhs[i]); 1038 + 1039 + if (!wait) 1040 + return 0; 1041 + 1042 + for (i = 0; i < bh_count; i++) 1043 + if (bhs[i]) 1044 + wait_on_buffer(bhs[i]); 1045 + 1046 + for (i = 0; i < bh_count; i++) { 1047 + if (bhs[i] && !buffer_uptodate(bhs[i])) { 1048 + err = -EIO; 1049 + goto out_brelse; 1050 + } 1051 + } 1052 + return 0; 1053 + 1054 + out_brelse: 1055 + for (i = 0; i < bh_count; i++) { 1056 + brelse(bhs[i]); 1057 + bhs[i] = NULL; 1058 + } 1059 + return err; 1016 1060 } 1017 1061 1018 1062 int ext4_walk_page_buffers(handle_t *handle, ··· 5702 5658 return err; 5703 5659 } 5704 5660 5705 - /* 5706 - * Expand an inode by new_extra_isize bytes. 5707 - * Returns 0 on success or negative error number on failure. 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) 5661 + static int __ext4_expand_extra_isize(struct inode *inode, 5662 + unsigned int new_extra_isize, 5663 + struct ext4_iloc *iloc, 5664 + handle_t *handle, int *no_expand) 5713 5665 { 5714 5666 struct ext4_inode *raw_inode; 5715 5667 struct ext4_xattr_ibody_header *header; 5668 + int error; 5716 5669 5717 - if (EXT4_I(inode)->i_extra_isize >= new_extra_isize) 5718 - return 0; 5719 - 5720 - raw_inode = ext4_raw_inode(&iloc); 5670 + raw_inode = ext4_raw_inode(iloc); 5721 5671 5722 5672 header = IHDR(inode, raw_inode); 5723 5673 ··· 5726 5688 } 5727 5689 5728 5690 /* try to expand with EAs present */ 5729 - return ext4_expand_extra_isize_ea(inode, new_extra_isize, 5730 - raw_inode, handle); 5691 + error = ext4_expand_extra_isize_ea(inode, new_extra_isize, 5692 + raw_inode, handle); 5693 + if (error) { 5694 + /* 5695 + * Inode size expansion failed; don't try again 5696 + */ 5697 + *no_expand = 1; 5698 + } 5699 + 5700 + return error; 5701 + } 5702 + 5703 + /* 5704 + * Expand an inode by new_extra_isize bytes. 5705 + * Returns 0 on success or negative error number on failure. 5706 + */ 5707 + static int ext4_try_to_expand_extra_isize(struct inode *inode, 5708 + unsigned int new_extra_isize, 5709 + struct ext4_iloc iloc, 5710 + handle_t *handle) 5711 + { 5712 + int no_expand; 5713 + int error; 5714 + 5715 + if (ext4_test_inode_state(inode, EXT4_STATE_NO_EXPAND)) 5716 + return -EOVERFLOW; 5717 + 5718 + /* 5719 + * In nojournal mode, we can immediately attempt to expand 5720 + * the inode. When journaled, we first need to obtain extra 5721 + * buffer credits since we may write into the EA block 5722 + * with this same handle. If journal_extend fails, then it will 5723 + * only result in a minor loss of functionality for that inode. 5724 + * If this is felt to be critical, then e2fsck should be run to 5725 + * force a large enough s_min_extra_isize. 5726 + */ 5727 + if (ext4_handle_valid(handle) && 5728 + jbd2_journal_extend(handle, 5729 + EXT4_DATA_TRANS_BLOCKS(inode->i_sb)) != 0) 5730 + return -ENOSPC; 5731 + 5732 + if (ext4_write_trylock_xattr(inode, &no_expand) == 0) 5733 + return -EBUSY; 5734 + 5735 + error = __ext4_expand_extra_isize(inode, new_extra_isize, &iloc, 5736 + handle, &no_expand); 5737 + ext4_write_unlock_xattr(inode, &no_expand); 5738 + 5739 + return error; 5740 + } 5741 + 5742 + int ext4_expand_extra_isize(struct inode *inode, 5743 + unsigned int new_extra_isize, 5744 + struct ext4_iloc *iloc) 5745 + { 5746 + handle_t *handle; 5747 + int no_expand; 5748 + int error, rc; 5749 + 5750 + if (ext4_test_inode_state(inode, EXT4_STATE_NO_EXPAND)) { 5751 + brelse(iloc->bh); 5752 + return -EOVERFLOW; 5753 + } 5754 + 5755 + handle = ext4_journal_start(inode, EXT4_HT_INODE, 5756 + EXT4_DATA_TRANS_BLOCKS(inode->i_sb)); 5757 + if (IS_ERR(handle)) { 5758 + error = PTR_ERR(handle); 5759 + brelse(iloc->bh); 5760 + return error; 5761 + } 5762 + 5763 + ext4_write_lock_xattr(inode, &no_expand); 5764 + 5765 + BUFFER_TRACE(iloc.bh, "get_write_access"); 5766 + error = ext4_journal_get_write_access(handle, iloc->bh); 5767 + if (error) { 5768 + brelse(iloc->bh); 5769 + goto out_stop; 5770 + } 5771 + 5772 + error = __ext4_expand_extra_isize(inode, new_extra_isize, iloc, 5773 + handle, &no_expand); 5774 + 5775 + rc = ext4_mark_iloc_dirty(handle, inode, iloc); 5776 + if (!error) 5777 + error = rc; 5778 + 5779 + ext4_write_unlock_xattr(inode, &no_expand); 5780 + out_stop: 5781 + ext4_journal_stop(handle); 5782 + return error; 5731 5783 } 5732 5784 5733 5785 /* ··· 5837 5709 { 5838 5710 struct ext4_iloc iloc; 5839 5711 struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb); 5840 - static unsigned int mnt_count; 5841 - int err, ret; 5712 + int err; 5842 5713 5843 5714 might_sleep(); 5844 5715 trace_ext4_mark_inode_dirty(inode, _RET_IP_); 5845 5716 err = ext4_reserve_inode_write(handle, inode, &iloc); 5846 5717 if (err) 5847 5718 return err; 5848 - if (EXT4_I(inode)->i_extra_isize < sbi->s_want_extra_isize && 5849 - !ext4_test_inode_state(inode, EXT4_STATE_NO_EXPAND)) { 5850 - /* 5851 - * In nojournal mode, we can immediately attempt to expand 5852 - * the inode. When journaled, we first need to obtain extra 5853 - * buffer credits since we may write into the EA block 5854 - * with this same handle. If journal_extend fails, then it will 5855 - * only result in a minor loss of functionality for that inode. 5856 - * If this is felt to be critical, then e2fsck should be run to 5857 - * force a large enough s_min_extra_isize. 5858 - */ 5859 - if (!ext4_handle_valid(handle) || 5860 - jbd2_journal_extend(handle, 5861 - EXT4_DATA_TRANS_BLOCKS(inode->i_sb)) == 0) { 5862 - ret = ext4_expand_extra_isize(inode, 5863 - sbi->s_want_extra_isize, 5864 - iloc, handle); 5865 - if (ret) { 5866 - if (mnt_count != 5867 - le16_to_cpu(sbi->s_es->s_mnt_count)) { 5868 - ext4_warning(inode->i_sb, 5869 - "Unable to expand inode %lu. Delete" 5870 - " some EAs or run e2fsck.", 5871 - inode->i_ino); 5872 - mnt_count = 5873 - le16_to_cpu(sbi->s_es->s_mnt_count); 5874 - } 5875 - } 5876 - } 5877 - } 5719 + 5720 + if (EXT4_I(inode)->i_extra_isize < sbi->s_want_extra_isize) 5721 + ext4_try_to_expand_extra_isize(inode, sbi->s_want_extra_isize, 5722 + iloc, handle); 5723 + 5878 5724 return ext4_mark_iloc_dirty(handle, inode, &iloc); 5879 5725 } 5880 5726
+14 -13
fs/ext4/ioctl.c
··· 64 64 ei1 = EXT4_I(inode1); 65 65 ei2 = EXT4_I(inode2); 66 66 67 - memswap(&inode1->i_flags, &inode2->i_flags, sizeof(inode1->i_flags)); 68 - memswap(&inode1->i_version, &inode2->i_version, 69 - sizeof(inode1->i_version)); 70 - memswap(&inode1->i_blocks, &inode2->i_blocks, 71 - sizeof(inode1->i_blocks)); 72 - memswap(&inode1->i_bytes, &inode2->i_bytes, sizeof(inode1->i_bytes)); 73 - memswap(&inode1->i_atime, &inode2->i_atime, sizeof(inode1->i_atime)); 74 - memswap(&inode1->i_mtime, &inode2->i_mtime, sizeof(inode1->i_mtime)); 67 + swap(inode1->i_flags, inode2->i_flags); 68 + swap(inode1->i_version, inode2->i_version); 69 + swap(inode1->i_blocks, inode2->i_blocks); 70 + swap(inode1->i_bytes, inode2->i_bytes); 71 + swap(inode1->i_atime, inode2->i_atime); 72 + swap(inode1->i_mtime, inode2->i_mtime); 75 73 76 74 memswap(ei1->i_data, ei2->i_data, sizeof(ei1->i_data)); 77 - memswap(&ei1->i_flags, &ei2->i_flags, sizeof(ei1->i_flags)); 78 - memswap(&ei1->i_disksize, &ei2->i_disksize, sizeof(ei1->i_disksize)); 75 + swap(ei1->i_flags, ei2->i_flags); 76 + swap(ei1->i_disksize, ei2->i_disksize); 79 77 ext4_es_remove_extent(inode1, 0, EXT_MAX_BLOCKS); 80 78 ext4_es_remove_extent(inode2, 0, EXT_MAX_BLOCKS); 81 79 ··· 349 351 350 352 raw_inode = ext4_raw_inode(&iloc); 351 353 if (!EXT4_FITS_IN_INODE(raw_inode, ei, i_projid)) { 352 - err = -EOVERFLOW; 354 + err = ext4_expand_extra_isize(inode, 355 + EXT4_SB(sb)->s_want_extra_isize, 356 + &iloc); 357 + if (err) 358 + goto out_unlock; 359 + } else { 353 360 brelse(iloc.bh); 354 - goto out_unlock; 355 361 } 356 - brelse(iloc.bh); 357 362 358 363 dquot_initialize(inode); 359 364
+9 -6
fs/ext4/mballoc.c
··· 2295 2295 int err, buddy_loaded = 0; 2296 2296 struct ext4_buddy e4b; 2297 2297 struct ext4_group_info *grinfo; 2298 + unsigned char blocksize_bits = min_t(unsigned char, 2299 + sb->s_blocksize_bits, 2300 + EXT4_MAX_BLOCK_LOG_SIZE); 2298 2301 struct sg { 2299 2302 struct ext4_group_info info; 2300 - ext4_grpblk_t counters[EXT4_MAX_BLOCK_LOG_SIZE + 2]; 2303 + ext4_grpblk_t counters[blocksize_bits + 2]; 2301 2304 } sg; 2302 2305 2303 2306 group--; ··· 2309 2306 " 2^0 2^1 2^2 2^3 2^4 2^5 2^6 " 2310 2307 " 2^7 2^8 2^9 2^10 2^11 2^12 2^13 ]\n"); 2311 2308 2312 - i = (sb->s_blocksize_bits + 2) * sizeof(sg.info.bb_counters[0]) + 2313 - sizeof(struct ext4_group_info); 2314 2309 grinfo = ext4_get_group_info(sb, group); 2315 2310 /* Load the group info in memory only if not already loaded. */ 2316 2311 if (unlikely(EXT4_MB_GRP_NEED_INIT(grinfo))) { ··· 2320 2319 buddy_loaded = 1; 2321 2320 } 2322 2321 2323 - memcpy(&sg, ext4_get_group_info(sb, group), i); 2322 + memcpy(&sg, ext4_get_group_info(sb, group), sizeof(sg)); 2324 2323 2325 2324 if (buddy_loaded) 2326 2325 ext4_mb_unload_buddy(&e4b); ··· 2328 2327 seq_printf(seq, "#%-5u: %-5u %-5u %-5u [", group, sg.info.bb_free, 2329 2328 sg.info.bb_fragments, sg.info.bb_first_free); 2330 2329 for (i = 0; i <= 13; i++) 2331 - seq_printf(seq, " %-5u", i <= sb->s_blocksize_bits + 1 ? 2330 + seq_printf(seq, " %-5u", i <= blocksize_bits + 1 ? 2332 2331 sg.info.bb_counters[i] : 0); 2333 2332 seq_printf(seq, " ]\n"); 2334 2333 ··· 2893 2892 break; 2894 2893 } 2895 2894 2896 - if (discard_bio) 2895 + if (discard_bio) { 2897 2896 submit_bio_wait(discard_bio); 2897 + bio_put(discard_bio); 2898 + } 2898 2899 } 2899 2900 2900 2901 list_for_each_entry_safe(entry, tmp, &freed_data_list, efd_list)
+26 -38
fs/ext4/namei.c
··· 1342 1342 struct super_block *sb; 1343 1343 struct buffer_head *bh_use[NAMEI_RA_SIZE]; 1344 1344 struct buffer_head *bh, *ret = NULL; 1345 - ext4_lblk_t start, block, b; 1345 + ext4_lblk_t start, block; 1346 1346 const u8 *name = d_name->name; 1347 - int ra_max = 0; /* Number of bh's in the readahead 1347 + size_t ra_max = 0; /* Number of bh's in the readahead 1348 1348 buffer, bh_use[] */ 1349 - int ra_ptr = 0; /* Current index into readahead 1349 + size_t ra_ptr = 0; /* Current index into readahead 1350 1350 buffer */ 1351 - int num = 0; 1352 1351 ext4_lblk_t nblocks; 1353 1352 int i, namelen, retval; 1354 1353 struct ext4_filename fname; ··· 1410 1411 if (ra_ptr >= ra_max) { 1411 1412 /* Refill the readahead buffer */ 1412 1413 ra_ptr = 0; 1413 - b = block; 1414 - for (ra_max = 0; ra_max < NAMEI_RA_SIZE; ra_max++) { 1415 - /* 1416 - * Terminate if we reach the end of the 1417 - * directory and must wrap, or if our 1418 - * search has finished at this block. 1419 - */ 1420 - if (b >= nblocks || (num && block == start)) { 1421 - bh_use[ra_max] = NULL; 1422 - break; 1423 - } 1424 - num++; 1425 - bh = ext4_getblk(NULL, dir, b++, 0); 1426 - if (IS_ERR(bh)) { 1427 - if (ra_max == 0) { 1428 - ret = bh; 1429 - goto cleanup_and_exit; 1430 - } 1431 - break; 1432 - } 1433 - bh_use[ra_max] = bh; 1434 - if (bh) 1435 - ll_rw_block(REQ_OP_READ, 1436 - REQ_META | REQ_PRIO, 1437 - 1, &bh); 1414 + if (block < start) 1415 + ra_max = start - block; 1416 + else 1417 + ra_max = nblocks - block; 1418 + ra_max = min(ra_max, ARRAY_SIZE(bh_use)); 1419 + retval = ext4_bread_batch(dir, block, ra_max, 1420 + false /* wait */, bh_use); 1421 + if (retval) { 1422 + ret = ERR_PTR(retval); 1423 + ra_max = 0; 1424 + goto cleanup_and_exit; 1438 1425 } 1439 1426 } 1440 1427 if ((bh = bh_use[ra_ptr++]) == NULL) ··· 2380 2395 } 2381 2396 2382 2397 /* 2383 - * DIR_NLINK feature is set if 1) nlinks > EXT4_LINK_MAX or 2) nlinks == 2, 2384 - * since this indicates that nlinks count was previously 1. 2398 + * Set directory link count to 1 if nlinks > EXT4_LINK_MAX, or if nlinks == 2 2399 + * since this indicates that nlinks count was previously 1 to avoid overflowing 2400 + * the 16-bit i_links_count field on disk. Directories with i_nlink == 1 mean 2401 + * that subdirectory link counts are not being maintained accurately. 2402 + * 2403 + * The caller has already checked for i_nlink overflow in case the DIR_LINK 2404 + * feature is not enabled and returned -EMLINK. The is_dx() check is a proxy 2405 + * for checking S_ISDIR(inode) (since the INODE_INDEX feature will not be set 2406 + * on regular files) and to avoid creating huge/slow non-HTREE directories. 2385 2407 */ 2386 2408 static void ext4_inc_count(handle_t *handle, struct inode *inode) 2387 2409 { 2388 2410 inc_nlink(inode); 2389 - if (is_dx(inode) && inode->i_nlink > 1) { 2390 - /* limit is 16-bit i_links_count */ 2391 - if (inode->i_nlink >= EXT4_LINK_MAX || inode->i_nlink == 2) { 2392 - set_nlink(inode, 1); 2393 - ext4_set_feature_dir_nlink(inode->i_sb); 2394 - } 2395 - } 2411 + if (is_dx(inode) && 2412 + (inode->i_nlink > EXT4_LINK_MAX || inode->i_nlink == 2)) 2413 + set_nlink(inode, 1); 2396 2414 } 2397 2415 2398 2416 /*
+2 -1
fs/ext4/resize.c
··· 1927 1927 n_desc_blocks = o_desc_blocks + 1928 1928 le16_to_cpu(es->s_reserved_gdt_blocks); 1929 1929 n_group = n_desc_blocks * EXT4_DESC_PER_BLOCK(sb); 1930 - n_blocks_count = n_group * EXT4_BLOCKS_PER_GROUP(sb); 1930 + n_blocks_count = (ext4_fsblk_t)n_group * 1931 + EXT4_BLOCKS_PER_GROUP(sb); 1931 1932 n_group--; /* set to last group number */ 1932 1933 } 1933 1934
-2
fs/ext4/super.c
··· 978 978 ei->i_es_shk_nr = 0; 979 979 ei->i_es_shrink_lblk = 0; 980 980 ei->i_reserved_data_blocks = 0; 981 - ei->i_reserved_meta_blocks = 0; 982 - ei->i_allocated_meta_blocks = 0; 983 981 ei->i_da_metadata_calc_len = 0; 984 982 ei->i_da_metadata_calc_last_lblock = 0; 985 983 spin_lock_init(&(ei->i_block_reservation_lock));
+47 -42
fs/ext4/xattr.c
··· 317 317 */ 318 318 static int ext4_xattr_inode_read(struct inode *ea_inode, void *buf, size_t size) 319 319 { 320 - unsigned long block = 0; 321 - struct buffer_head *bh; 322 - int blocksize = ea_inode->i_sb->s_blocksize; 323 - size_t csize, copied = 0; 324 - void *copy_pos = buf; 320 + int blocksize = 1 << ea_inode->i_blkbits; 321 + int bh_count = (size + blocksize - 1) >> ea_inode->i_blkbits; 322 + int tail_size = (size % blocksize) ?: blocksize; 323 + struct buffer_head *bhs_inline[8]; 324 + struct buffer_head **bhs = bhs_inline; 325 + int i, ret; 325 326 326 - while (copied < size) { 327 - csize = (size - copied) > blocksize ? blocksize : size - copied; 328 - bh = ext4_bread(NULL, ea_inode, block, 0); 329 - if (IS_ERR(bh)) 330 - return PTR_ERR(bh); 331 - if (!bh) 332 - return -EFSCORRUPTED; 333 - 334 - memcpy(copy_pos, bh->b_data, csize); 335 - brelse(bh); 336 - 337 - copy_pos += csize; 338 - block += 1; 339 - copied += csize; 327 + if (bh_count > ARRAY_SIZE(bhs_inline)) { 328 + bhs = kmalloc_array(bh_count, sizeof(*bhs), GFP_NOFS); 329 + if (!bhs) 330 + return -ENOMEM; 340 331 } 341 - return 0; 332 + 333 + ret = ext4_bread_batch(ea_inode, 0 /* block */, bh_count, 334 + true /* wait */, bhs); 335 + if (ret) 336 + goto free_bhs; 337 + 338 + for (i = 0; i < bh_count; i++) { 339 + /* There shouldn't be any holes in ea_inode. */ 340 + if (!bhs[i]) { 341 + ret = -EFSCORRUPTED; 342 + goto put_bhs; 343 + } 344 + memcpy((char *)buf + blocksize * i, bhs[i]->b_data, 345 + i < bh_count - 1 ? blocksize : tail_size); 346 + } 347 + ret = 0; 348 + put_bhs: 349 + for (i = 0; i < bh_count; i++) 350 + brelse(bhs[i]); 351 + free_bhs: 352 + if (bhs != bhs_inline) 353 + kfree(bhs); 354 + return ret; 342 355 } 343 356 344 357 static int ext4_xattr_inode_iget(struct inode *parent, unsigned long ea_ino, ··· 464 451 } 465 452 /* Do not add ea_inode to the cache. */ 466 453 ea_inode_cache = NULL; 454 + err = 0; 467 455 } else if (err) 468 456 goto out; 469 457 ··· 1829 1815 ea_bdebug(bs->bh, "modifying in-place"); 1830 1816 error = ext4_xattr_set_entry(i, s, handle, inode, 1831 1817 true /* is_block */); 1832 - if (!error) 1833 - ext4_xattr_block_cache_insert(ea_block_cache, 1834 - bs->bh); 1835 1818 ext4_xattr_block_csum_set(inode, bs->bh); 1836 1819 unlock_buffer(bs->bh); 1837 1820 if (error == -EFSCORRUPTED) ··· 1984 1973 } else if (bs->bh && s->base == bs->bh->b_data) { 1985 1974 /* We were modifying this block in-place. */ 1986 1975 ea_bdebug(bs->bh, "keeping this block"); 1976 + ext4_xattr_block_cache_insert(ea_block_cache, bs->bh); 1987 1977 new_bh = bs->bh; 1988 1978 get_bh(new_bh); 1989 1979 } else { ··· 2637 2625 struct ext4_inode *raw_inode, handle_t *handle) 2638 2626 { 2639 2627 struct ext4_xattr_ibody_header *header; 2640 - struct buffer_head *bh = NULL; 2628 + struct buffer_head *bh; 2629 + struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb); 2630 + static unsigned int mnt_count; 2641 2631 size_t min_offs; 2642 2632 size_t ifree, bfree; 2643 2633 int total_ino; 2644 2634 void *base, *end; 2645 2635 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); 2636 + int s_min_extra_isize = le16_to_cpu(sbi->s_es->s_min_extra_isize); 2647 2637 int isize_diff; /* How much do we need to grow i_extra_isize */ 2648 - int no_expand; 2649 - 2650 - if (ext4_write_trylock_xattr(inode, &no_expand) == 0) 2651 - return 0; 2652 2638 2653 2639 retry: 2654 2640 isize_diff = new_extra_isize - EXT4_I(inode)->i_extra_isize; 2655 2641 if (EXT4_I(inode)->i_extra_isize >= new_extra_isize) 2656 - goto out; 2642 + return 0; 2657 2643 2658 2644 header = IHDR(inode, raw_inode); 2659 2645 ··· 2686 2676 EXT4_ERROR_INODE(inode, "bad block %llu", 2687 2677 EXT4_I(inode)->i_file_acl); 2688 2678 error = -EFSCORRUPTED; 2679 + brelse(bh); 2689 2680 goto cleanup; 2690 2681 } 2691 2682 base = BHDR(bh); ··· 2694 2683 min_offs = end - base; 2695 2684 bfree = ext4_xattr_free_space(BFIRST(bh), &min_offs, base, 2696 2685 NULL); 2686 + brelse(bh); 2697 2687 if (bfree + ifree < isize_diff) { 2698 2688 if (!tried_min_extra_isize && s_min_extra_isize) { 2699 2689 tried_min_extra_isize++; 2700 2690 new_extra_isize = s_min_extra_isize; 2701 - brelse(bh); 2702 2691 goto retry; 2703 2692 } 2704 2693 error = -ENOSPC; ··· 2716 2705 s_min_extra_isize) { 2717 2706 tried_min_extra_isize++; 2718 2707 new_extra_isize = s_min_extra_isize; 2719 - brelse(bh); 2720 2708 goto retry; 2721 2709 } 2722 2710 goto cleanup; ··· 2727 2717 EXT4_GOOD_OLD_INODE_SIZE + new_extra_isize, 2728 2718 (void *)header, total_ino); 2729 2719 EXT4_I(inode)->i_extra_isize = new_extra_isize; 2730 - brelse(bh); 2731 - out: 2732 - ext4_write_unlock_xattr(inode, &no_expand); 2733 - return 0; 2734 2720 2735 2721 cleanup: 2736 - brelse(bh); 2737 - /* 2738 - * Inode size expansion failed; don't try again 2739 - */ 2740 - no_expand = 1; 2741 - ext4_write_unlock_xattr(inode, &no_expand); 2722 + if (error && (mnt_count != le16_to_cpu(sbi->s_es->s_mnt_count))) { 2723 + ext4_warning(inode->i_sb, "Unable to expand inode %lu. Delete some EAs or run e2fsck.", 2724 + inode->i_ino); 2725 + mnt_count = le16_to_cpu(sbi->s_es->s_mnt_count); 2726 + } 2742 2727 return error; 2743 2728 } 2744 2729
+8 -27
include/trace/events/ext4.h
··· 937 937 TP_STRUCT__entry( 938 938 __field( dev_t, dev ) 939 939 __field( ino_t, ino ) 940 - __field( unsigned int, data_blocks ) 941 - __field( unsigned int, meta_blocks ) 940 + __field( unsigned int, data_blocks ) 942 941 ), 943 942 944 943 TP_fast_assign( 945 944 __entry->dev = inode->i_sb->s_dev; 946 945 __entry->ino = inode->i_ino; 947 946 __entry->data_blocks = EXT4_I(inode)->i_reserved_data_blocks; 948 - __entry->meta_blocks = EXT4_I(inode)->i_reserved_meta_blocks; 949 947 ), 950 948 951 - TP_printk("dev %d,%d ino %lu data_blocks %u meta_blocks %u", 949 + TP_printk("dev %d,%d ino %lu reserved_data_blocks %u", 952 950 MAJOR(__entry->dev), MINOR(__entry->dev), 953 951 (unsigned long) __entry->ino, 954 - __entry->data_blocks, __entry->meta_blocks) 952 + __entry->data_blocks) 955 953 ); 956 954 957 955 TRACE_EVENT(ext4_mballoc_alloc, ··· 1151 1153 __field( __u64, i_blocks ) 1152 1154 __field( int, used_blocks ) 1153 1155 __field( int, reserved_data_blocks ) 1154 - __field( int, reserved_meta_blocks ) 1155 - __field( int, allocated_meta_blocks ) 1156 1156 __field( int, quota_claim ) 1157 1157 __field( __u16, mode ) 1158 1158 ), ··· 1162 1166 __entry->used_blocks = used_blocks; 1163 1167 __entry->reserved_data_blocks = 1164 1168 EXT4_I(inode)->i_reserved_data_blocks; 1165 - __entry->reserved_meta_blocks = 1166 - EXT4_I(inode)->i_reserved_meta_blocks; 1167 - __entry->allocated_meta_blocks = 1168 - EXT4_I(inode)->i_allocated_meta_blocks; 1169 1169 __entry->quota_claim = quota_claim; 1170 1170 __entry->mode = inode->i_mode; 1171 1171 ), 1172 1172 1173 1173 TP_printk("dev %d,%d ino %lu mode 0%o i_blocks %llu used_blocks %d " 1174 - "reserved_data_blocks %d reserved_meta_blocks %d " 1175 - "allocated_meta_blocks %d quota_claim %d", 1174 + "reserved_data_blocks %d quota_claim %d", 1176 1175 MAJOR(__entry->dev), MINOR(__entry->dev), 1177 1176 (unsigned long) __entry->ino, 1178 1177 __entry->mode, __entry->i_blocks, 1179 1178 __entry->used_blocks, __entry->reserved_data_blocks, 1180 - __entry->reserved_meta_blocks, __entry->allocated_meta_blocks, 1181 1179 __entry->quota_claim) 1182 1180 ); 1183 1181 ··· 1185 1195 __field( ino_t, ino ) 1186 1196 __field( __u64, i_blocks ) 1187 1197 __field( int, reserved_data_blocks ) 1188 - __field( int, reserved_meta_blocks ) 1189 1198 __field( __u16, mode ) 1190 1199 ), 1191 1200 ··· 1193 1204 __entry->ino = inode->i_ino; 1194 1205 __entry->i_blocks = inode->i_blocks; 1195 1206 __entry->reserved_data_blocks = EXT4_I(inode)->i_reserved_data_blocks; 1196 - __entry->reserved_meta_blocks = EXT4_I(inode)->i_reserved_meta_blocks; 1197 1207 __entry->mode = inode->i_mode; 1198 1208 ), 1199 1209 1200 1210 TP_printk("dev %d,%d ino %lu mode 0%o i_blocks %llu " 1201 - "reserved_data_blocks %d reserved_meta_blocks %d", 1211 + "reserved_data_blocks %d", 1202 1212 MAJOR(__entry->dev), MINOR(__entry->dev), 1203 1213 (unsigned long) __entry->ino, 1204 1214 __entry->mode, __entry->i_blocks, 1205 - __entry->reserved_data_blocks, 1206 - __entry->reserved_meta_blocks) 1215 + __entry->reserved_data_blocks) 1207 1216 ); 1208 1217 1209 1218 TRACE_EVENT(ext4_da_release_space, ··· 1215 1228 __field( __u64, i_blocks ) 1216 1229 __field( int, freed_blocks ) 1217 1230 __field( int, reserved_data_blocks ) 1218 - __field( int, reserved_meta_blocks ) 1219 - __field( int, allocated_meta_blocks ) 1220 1231 __field( __u16, mode ) 1221 1232 ), 1222 1233 ··· 1224 1239 __entry->i_blocks = inode->i_blocks; 1225 1240 __entry->freed_blocks = freed_blocks; 1226 1241 __entry->reserved_data_blocks = EXT4_I(inode)->i_reserved_data_blocks; 1227 - __entry->reserved_meta_blocks = EXT4_I(inode)->i_reserved_meta_blocks; 1228 - __entry->allocated_meta_blocks = EXT4_I(inode)->i_allocated_meta_blocks; 1229 1242 __entry->mode = inode->i_mode; 1230 1243 ), 1231 1244 1232 1245 TP_printk("dev %d,%d ino %lu mode 0%o i_blocks %llu freed_blocks %d " 1233 - "reserved_data_blocks %d reserved_meta_blocks %d " 1234 - "allocated_meta_blocks %d", 1246 + "reserved_data_blocks %d", 1235 1247 MAJOR(__entry->dev), MINOR(__entry->dev), 1236 1248 (unsigned long) __entry->ino, 1237 1249 __entry->mode, __entry->i_blocks, 1238 - __entry->freed_blocks, __entry->reserved_data_blocks, 1239 - __entry->reserved_meta_blocks, __entry->allocated_meta_blocks) 1250 + __entry->freed_blocks, __entry->reserved_data_blocks) 1240 1251 ); 1241 1252 1242 1253 DECLARE_EVENT_CLASS(ext4__bitmap_load,