Pull ext4 updates from Ted Ts'o: "Scalability improvements when allocating inodes, and some miscellaneous bug fixes and cleanups" * tag 'ext4_for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4: ext4: avoid Y2038 overflow in recently_deleted() ext4: fix fault handling when mounted with -o dax,ro ext4: fix quota inconsistency during orphan cleanup for read-only mounts ext4: fix incorrect quotaoff if the quota feature is enabled ext4: remove useless test and assignment in strtohash functions ext4: backward compatibility support for Lustre ea_inode implementation ext4: remove timebomb in ext4_decode_extra_time() ext4: use sizeof(*ptr) ext4: in ext4_seek_{hole,data}, return -ENXIO for negative offsets ext4: reduce lock contention in __ext4_new_inode ext4: cleanup goto next group ext4: do not unnecessarily allocate buffer in recently_deleted()
Unified · Split
| @@ -411,7 +411,7 @@ static struct dir_private_info *ext4_htree_create_dir_info(struct file *filp, · 410 unmodified lines | ||
| 411 | 411 | { |
| 412 | 412 | struct dir_private_info *p; |
| 413 | 413 | |
| 414 | − p = kzalloc(sizeof(struct dir_private_info), GFP_KERNEL); | |
| 414 | + p = kzalloc(sizeof(*p), GFP_KERNEL); | |
| 415 | 415 | if (!p) |
| 416 | 416 | return NULL; |
| 417 | 417 | p->curr_hash = pos2maj_hash(filp, pos); |
| @@ -838,13 +838,11 @@ static inline void ext4_decode_extra_time(struct timespec *time, __le32 extra) · 837 unmodified lines | ||
| 838 | 838 | { |
| 839 | 839 | if (unlikely(sizeof(time->tv_sec) > 4 && |
| 840 | 840 | (extra & cpu_to_le32(EXT4_EPOCH_MASK)))) { |
| 841 | −#if LINUX_VERSION_CODE < KERNEL_VERSION(4,20,0) | |
| 841 | + | |
| 842 | +#if 1 | |
| 842 | 843 | /* Handle legacy encoding of pre-1970 dates with epoch |
| 843 | − * bits 1,1. We assume that by kernel version 4.20, | |
| 844 | − * everyone will have run fsck over the affected | |
| 845 | − * filesystems to correct the problem. (This | |
| 846 | − * backwards compatibility may be removed before this | |
| 847 | − * time, at the discretion of the ext4 developers.) | |
| 844 | + * bits 1,1. (This backwards compatibility may be removed | |
| 845 | + * at the discretion of the ext4 developers.) | |
| 848 | 846 | */ |
| 849 | 847 | u64 extra_bits = le32_to_cpu(extra) & EXT4_EPOCH_MASK; |
| 850 | 848 | if (extra_bits == 3 && ((time->tv_sec) & 0x80000000) != 0) |
| @@ -1567,6 +1565,7 @@ enum { · 716 unmodified lines | ||
| 1567 | 1565 | nolocking */ |
| 1568 | 1566 | EXT4_STATE_MAY_INLINE_DATA, /* may have in-inode data */ |
| 1569 | 1567 | EXT4_STATE_EXT_PRECACHED, /* extents have been precached */ |
| 1568 | + EXT4_STATE_LUSTRE_EA_INODE, /* Lustre-style ea_inode */ | |
| 1570 | 1569 | }; |
| 1571 | 1570 | |
| 1572 | 1571 | #define EXT4_INODE_BIT_FNS(name, field, offset) \ |
| @@ -279,7 +279,20 @@ static int ext4_dax_huge_fault(struct vm_fault *vmf, · 278 unmodified lines | ||
| 279 | 279 | handle_t *handle = NULL; |
| 280 | 280 | struct inode *inode = file_inode(vmf->vma->vm_file); |
| 281 | 281 | struct super_block *sb = inode->i_sb; |
| 282 | − bool write = vmf->flags & FAULT_FLAG_WRITE; | |
| 282 | + | |
| 283 | + /* | |
| 284 | + * We have to distinguish real writes from writes which will result in a | |
| 285 | + * COW page; COW writes should *not* poke the journal (the file will not | |
| 286 | + * be changed). Doing so would cause unintended failures when mounted | |
| 287 | + * read-only. | |
| 288 | + * | |
| 289 | + * We check for VM_SHARED rather than vmf->cow_page since the latter is | |
| 290 | + * unset for pe_size != PE_SIZE_PTE (i.e. only in do_cow_fault); for | |
| 291 | + * other sizes, dax_iomap_fault will handle splitting / fallback so that | |
| 292 | + * we eventually come back with a COW page. | |
| 293 | + */ | |
| 294 | + bool write = (vmf->flags & FAULT_FLAG_WRITE) && | |
| 295 | + (vmf->vma->vm_flags & VM_SHARED); | |
| 283 | 296 | |
| 284 | 297 | if (write) { |
| 285 | 298 | sb_start_pagefault(sb); |
| @@ -595,7 +608,7 @@ static loff_t ext4_seek_data(struct file *file, loff_t offset, loff_t maxsize) · 309 unmodified lines | ||
| 595 | 608 | inode_lock(inode); |
| 596 | 609 | |
| 597 | 610 | isize = i_size_read(inode); |
| 598 | − if (offset >= isize) { | |
| 611 | + if (offset < 0 || offset >= isize) { | |
| 599 | 612 | inode_unlock(inode); |
| 600 | 613 | return -ENXIO; |
| 601 | 614 | } |
| @@ -658,7 +671,7 @@ static loff_t ext4_seek_hole(struct file *file, loff_t offset, loff_t maxsize) · 56 unmodified lines | ||
| 658 | 671 | inode_lock(inode); |
| 659 | 672 | |
| 660 | 673 | isize = i_size_read(inode); |
| 661 | − if (offset >= isize) { | |
| 674 | + if (offset < 0 || offset >= isize) { | |
| 662 | 675 | inode_unlock(inode); |
| 663 | 676 | return -ENXIO; |
| 664 | 677 | } |
| @@ -148,8 +148,6 @@ static void str2hashbuf_signed(const char *msg, int len, __u32 *buf, int num) · 147 unmodified lines | ||
| 148 | 148 | if (len > num*4) |
| 149 | 149 | len = num * 4; |
| 150 | 150 | for (i = 0; i < len; i++) { |
| 151 | − if ((i % 4) == 0) | |
| 152 | − val = pad; | |
| 153 | 151 | val = ((int) scp[i]) + (val << 8); |
| 154 | 152 | if ((i % 4) == 3) { |
| 155 | 153 | *buf++ = val; |
| @@ -176,8 +174,6 @@ static void str2hashbuf_unsigned(const char *msg, int len, __u32 *buf, int num) · 20 unmodified lines | ||
| 176 | 174 | if (len > num*4) |
| 177 | 175 | len = num * 4; |
| 178 | 176 | for (i = 0; i < len; i++) { |
| 179 | − if ((i % 4) == 0) | |
| 180 | − val = pad; | |
| 181 | 177 | val = ((int) ucp[i]) + (val << 8); |
| 182 | 178 | if ((i % 4) == 3) { |
| 183 | 179 | *buf++ = val; |
| @@ -692,24 +692,25 @@ static int find_group_other(struct super_block *sb, struct inode *parent, · 691 unmodified lines | ||
| 692 | 692 | * somewhat arbitrary...) |
| 693 | 693 | */ |
| 694 | 694 | #define RECENTCY_MIN 5 |
| 695 | −#define RECENTCY_DIRTY 30 | |
| 695 | +#define RECENTCY_DIRTY 300 | |
| 696 | 696 | |
| 697 | 697 | static int recently_deleted(struct super_block *sb, ext4_group_t group, int ino) |
| 698 | 698 | { |
| 699 | 699 | struct ext4_group_desc *gdp; |
| 700 | 700 | struct ext4_inode *raw_inode; |
| 701 | 701 | struct buffer_head *bh; |
| 702 | − unsigned long dtime, now; | |
| 703 | − int inodes_per_block = EXT4_SB(sb)->s_inodes_per_block; | |
| 704 | − int offset, ret = 0, recentcy = RECENTCY_MIN; | |
| 702 | + int inodes_per_block = EXT4_SB(sb)->s_inodes_per_block; | |
| 703 | + int offset, ret = 0; | |
| 704 | + int recentcy = RECENTCY_MIN; | |
| 705 | + u32 dtime, now; | |
| 705 | 706 | |
| 706 | 707 | gdp = ext4_get_group_desc(sb, group, NULL); |
| 707 | 708 | if (unlikely(!gdp)) |
| 708 | 709 | return 0; |
| 709 | 710 | |
| 710 | − bh = sb_getblk(sb, ext4_inode_table(sb, gdp) + | |
| 711 | + bh = sb_find_get_block(sb, ext4_inode_table(sb, gdp) + | |
| 711 | 712 | (ino / inodes_per_block)); |
| 712 | − if (unlikely(!bh) || !buffer_uptodate(bh)) | |
| 713 | + if (!bh || !buffer_uptodate(bh)) | |
| 713 | 714 | /* |
| 714 | 715 | * If the block is not in the buffer cache, then it |
| 715 | 716 | * must have been written out. |
| @@ -718,18 +719,45 @@ static int recently_deleted(struct super_block *sb, ext4_group_t group, int ino) · 2 unmodified lines | ||
| 718 | 719 | |
| 719 | 720 | offset = (ino % inodes_per_block) * EXT4_INODE_SIZE(sb); |
| 720 | 721 | raw_inode = (struct ext4_inode *) (bh->b_data + offset); |
| 722 | + | |
| 723 | + /* i_dtime is only 32 bits on disk, but we only care about relative | |
| 724 | + * times in the range of a few minutes (i.e. long enough to sync a | |
| 725 | + * recently-deleted inode to disk), so using the low 32 bits of the | |
| 726 | + * clock (a 68 year range) is enough, see time_before32() */ | |
| 721 | 727 | dtime = le32_to_cpu(raw_inode->i_dtime); |
| 722 | − now = get_seconds(); | |
| 728 | + now = ktime_get_real_seconds(); | |
| 723 | 729 | if (buffer_dirty(bh)) |
| 724 | 730 | recentcy += RECENTCY_DIRTY; |
| 725 | 731 | |
| 726 | − if (dtime && (dtime < now) && (now < dtime + recentcy)) | |
| 732 | + if (dtime && time_before32(dtime, now) && | |
| 733 | + time_before32(now, dtime + recentcy)) | |
| 727 | 734 | ret = 1; |
| 728 | 735 | out: |
| 729 | 736 | brelse(bh); |
| 730 | 737 | return ret; |
| 731 | 738 | } |
| 732 | 739 | |
| 740 | +static int find_inode_bit(struct super_block *sb, ext4_group_t group, | |
| 741 | + struct buffer_head *bitmap, unsigned long *ino) | |
| 742 | +{ | |
| 743 | +next: | |
| 744 | + *ino = ext4_find_next_zero_bit((unsigned long *) | |
| 745 | + bitmap->b_data, | |
| 746 | + EXT4_INODES_PER_GROUP(sb), *ino); | |
| 747 | + if (*ino >= EXT4_INODES_PER_GROUP(sb)) | |
| 748 | + return 0; | |
| 749 | + | |
| 750 | + if ((EXT4_SB(sb)->s_journal == NULL) && | |
| 751 | + recently_deleted(sb, group, *ino)) { | |
| 752 | + *ino = *ino + 1; | |
| 753 | + if (*ino < EXT4_INODES_PER_GROUP(sb)) | |
| 754 | + goto next; | |
| 755 | + return 0; | |
| 756 | + } | |
| 757 | + | |
| 758 | + return 1; | |
| 759 | +} | |
| 760 | + | |
| 733 | 761 | /* |
| 734 | 762 | * There are two policies for allocating an inode. If the new inode is |
| 735 | 763 | * a directory, then a forward search is made for a block group with both |
| @@ -892,19 +920,13 @@ got_group: · 156 unmodified lines | ||
| 892 | 920 | /* |
| 893 | 921 | * Check free inodes count before loading bitmap. |
| 894 | 922 | */ |
| 895 | − if (ext4_free_inodes_count(sb, gdp) == 0) { | |
| 896 | − if (++group == ngroups) | |
| 897 | − group = 0; | |
| 898 | − continue; | |
| 899 | − } | |
| 923 | + if (ext4_free_inodes_count(sb, gdp) == 0) | |
| 924 | + goto next_group; | |
| 900 | 925 | |
| 901 | 926 | grp = ext4_get_group_info(sb, group); |
| 902 | 927 | /* Skip groups with already-known suspicious inode tables */ |
| 903 | − if (EXT4_MB_GRP_IBITMAP_CORRUPT(grp)) { | |
| 904 | − if (++group == ngroups) | |
| 905 | − group = 0; | |
| 906 | − continue; | |
| 907 | − } | |
| 928 | + if (EXT4_MB_GRP_IBITMAP_CORRUPT(grp)) | |
| 929 | + goto next_group; | |
| 908 | 930 | |
| 909 | 931 | brelse(inode_bitmap_bh); |
| 910 | 932 | inode_bitmap_bh = ext4_read_inode_bitmap(sb, group); |
| @@ -912,27 +934,20 @@ got_group: · 1 unmodified line | ||
| 912 | 934 | if (EXT4_MB_GRP_IBITMAP_CORRUPT(grp) || |
| 913 | 935 | IS_ERR(inode_bitmap_bh)) { |
| 914 | 936 | inode_bitmap_bh = NULL; |
| 915 | − if (++group == ngroups) | |
| 916 | − group = 0; | |
| 917 | − continue; | |
| 937 | + goto next_group; | |
| 918 | 938 | } |
| 919 | 939 | |
| 920 | 940 | repeat_in_this_group: |
| 921 | − ino = ext4_find_next_zero_bit((unsigned long *) | |
| 922 | − inode_bitmap_bh->b_data, | |
| 923 | − EXT4_INODES_PER_GROUP(sb), ino); | |
| 924 | − if (ino >= EXT4_INODES_PER_GROUP(sb)) | |
| 941 | + ret2 = find_inode_bit(sb, group, inode_bitmap_bh, &ino); | |
| 942 | + if (!ret2) | |
| 925 | 943 | goto next_group; |
| 926 | − if (group == 0 && (ino+1) < EXT4_FIRST_INO(sb)) { | |
| 944 | + | |
| 945 | + if (group == 0 && (ino + 1) < EXT4_FIRST_INO(sb)) { | |
| 927 | 946 | ext4_error(sb, "reserved inode found cleared - " |
| 928 | 947 | "inode=%lu", ino + 1); |
| 929 | − continue; | |
| 930 | − } | |
| 931 | − if ((EXT4_SB(sb)->s_journal == NULL) && | |
| 932 | − recently_deleted(sb, group, ino)) { | |
| 933 | − ino++; | |
| 934 | − goto next_inode; | |
| 948 | + goto next_group; | |
| 935 | 949 | } |
| 950 | + | |
| 936 | 951 | if (!handle) { |
| 937 | 952 | BUG_ON(nblocks <= 0); |
| 938 | 953 | handle = __ext4_journal_start_sb(dir->i_sb, line_no, |
| @@ -952,11 +967,23 @@ repeat_in_this_group: · 13 unmodified lines | ||
| 952 | 967 | } |
| 953 | 968 | ext4_lock_group(sb, group); |
| 954 | 969 | ret2 = ext4_test_and_set_bit(ino, inode_bitmap_bh->b_data); |
| 970 | + if (ret2) { | |
| 971 | + /* Someone already took the bit. Repeat the search | |
| 972 | + * with lock held. | |
| 973 | + */ | |
| 974 | + ret2 = find_inode_bit(sb, group, inode_bitmap_bh, &ino); | |
| 975 | + if (ret2) { | |
| 976 | + ext4_set_bit(ino, inode_bitmap_bh->b_data); | |
| 977 | + ret2 = 0; | |
| 978 | + } else { | |
| 979 | + ret2 = 1; /* we didn't grab the inode */ | |
| 980 | + } | |
| 981 | + } | |
| 955 | 982 | ext4_unlock_group(sb, group); |
| 956 | 983 | ino++; /* the inode bitmap is zero-based */ |
| 957 | 984 | if (!ret2) |
| 958 | 985 | goto got; /* we grabbed the inode! */ |
| 959 | −next_inode: | |
| 986 | + | |
| 960 | 987 | if (ino < EXT4_INODES_PER_GROUP(sb)) |
| 961 | 988 | goto repeat_in_this_group; |
| 962 | 989 | next_group: |
| @@ -4897,14 +4897,6 @@ struct inode *ext4_iget(struct super_block *sb, unsigned long ino) · 4896 unmodified lines | ||
| 4897 | 4897 | brelse(iloc.bh); |
| 4898 | 4898 | ext4_set_inode_flags(inode); |
| 4899 | 4899 | |
| 4900 | − if (ei->i_flags & EXT4_EA_INODE_FL) { | |
| 4901 | − ext4_xattr_inode_set_class(inode); | |
| 4902 | − | |
| 4903 | − inode_lock(inode); | |
| 4904 | − inode->i_flags |= S_NOQUOTA; | |
| 4905 | − inode_unlock(inode); | |
| 4906 | − } | |
| 4907 | − | |
| 4908 | 4900 | unlock_new_inode(inode); |
| 4909 | 4901 | return inode; |
| 4910 | 4902 | |
| @@ -367,7 +367,7 @@ skip: · 366 unmodified lines | ||
| 367 | 367 | goto failed; |
| 368 | 368 | } |
| 369 | 369 | |
| 370 | − mmpd_data = kmalloc(sizeof(struct mmpd_data), GFP_KERNEL); | |
| 370 | + mmpd_data = kmalloc(sizeof(*mmpd_data), GFP_KERNEL); | |
| 371 | 371 | if (!mmpd_data) { |
| 372 | 372 | ext4_warning(sb, "not enough memory for mmpd_data"); |
| 373 | 373 | goto failed; |
| @@ -2404,6 +2404,7 @@ static void ext4_orphan_cleanup(struct super_block *sb, · 2403 unmodified lines | ||
| 2404 | 2404 | unsigned int s_flags = sb->s_flags; |
| 2405 | 2405 | int ret, nr_orphans = 0, nr_truncates = 0; |
| 2406 | 2406 | #ifdef CONFIG_QUOTA |
| 2407 | + int quota_update = 0; | |
| 2407 | 2408 | int i; |
| 2408 | 2409 | #endif |
| 2409 | 2410 | if (!es->s_last_orphan) { |
| @@ -2442,14 +2443,32 @@ static void ext4_orphan_cleanup(struct super_block *sb, · 32 unmodified lines | ||
| 2442 | 2443 | #ifdef CONFIG_QUOTA |
| 2443 | 2444 | /* Needed for iput() to work correctly and not trash data */ |
| 2444 | 2445 | sb->s_flags |= MS_ACTIVE; |
| 2445 | − /* Turn on quotas so that they are updated correctly */ | |
| 2446 | + | |
| 2447 | + /* | |
| 2448 | + * Turn on quotas which were not enabled for read-only mounts if | |
| 2449 | + * filesystem has quota feature, so that they are updated correctly. | |
| 2450 | + */ | |
| 2451 | + if (ext4_has_feature_quota(sb) && (s_flags & MS_RDONLY)) { | |
| 2452 | + int ret = ext4_enable_quotas(sb); | |
| 2453 | + | |
| 2454 | + if (!ret) | |
| 2455 | + quota_update = 1; | |
| 2456 | + else | |
| 2457 | + ext4_msg(sb, KERN_ERR, | |
| 2458 | + "Cannot turn on quotas: error %d", ret); | |
| 2459 | + } | |
| 2460 | + | |
| 2461 | + /* Turn on journaled quotas used for old sytle */ | |
| 2446 | 2462 | for (i = 0; i < EXT4_MAXQUOTAS; i++) { |
| 2447 | 2463 | if (EXT4_SB(sb)->s_qf_names[i]) { |
| 2448 | 2464 | int ret = ext4_quota_on_mount(sb, i); |
| 2449 | − if (ret < 0) | |
| 2465 | + | |
| 2466 | + if (!ret) | |
| 2467 | + quota_update = 1; | |
| 2468 | + else | |
| 2450 | 2469 | ext4_msg(sb, KERN_ERR, |
| 2451 | 2470 | "Cannot turn on journaled " |
| 2452 | − "quota: error %d", ret); | |
| 2471 | + "quota: type %d: error %d", i, ret); | |
| 2453 | 2472 | } |
| 2454 | 2473 | } |
| 2455 | 2474 | #endif |
| @@ -2510,10 +2529,12 @@ static void ext4_orphan_cleanup(struct super_block *sb, · 54 unmodified lines | ||
| 2510 | 2529 | ext4_msg(sb, KERN_INFO, "%d truncate%s cleaned up", |
| 2511 | 2530 | PLURAL(nr_truncates)); |
| 2512 | 2531 | #ifdef CONFIG_QUOTA |
| 2513 | − /* Turn quotas off */ | |
| 2514 | − for (i = 0; i < EXT4_MAXQUOTAS; i++) { | |
| 2515 | − if (sb_dqopt(sb)->files[i]) | |
| 2516 | − dquot_quota_off(sb, i); | |
| 2532 | + /* Turn off quotas if they were enabled for orphan cleanup */ | |
| 2533 | + if (quota_update) { | |
| 2534 | + for (i = 0; i < EXT4_MAXQUOTAS; i++) { | |
| 2535 | + if (sb_dqopt(sb)->files[i]) | |
| 2536 | + dquot_quota_off(sb, i); | |
| 2537 | + } | |
| 2517 | 2538 | } |
| 2518 | 2539 | #endif |
| 2519 | 2540 | sb->s_flags = s_flags; /* Restore MS_RDONLY status */ |
| @@ -5512,6 +5533,9 @@ static int ext4_enable_quotas(struct super_block *sb) · 2992 unmodified lines | ||
| 5512 | 5533 | DQUOT_USAGE_ENABLED | |
| 5513 | 5534 | (quota_mopt[type] ? DQUOT_LIMITS_ENABLED : 0)); |
| 5514 | 5535 | if (err) { |
| 5536 | + for (type--; type >= 0; type--) | |
| 5537 | + dquot_quota_off(sb, type); | |
| 5538 | + | |
| 5515 | 5539 | ext4_warning(sb, |
| 5516 | 5540 | "Failed to enable quota tracking " |
| 5517 | 5541 | "(type=%d, err=%d). Please run " |
| @@ -354,8 +354,10 @@ free_bhs: · 353 unmodified lines | ||
| 354 | 354 | return ret; |
| 355 | 355 | } |
| 356 | 356 | |
| 357 | +#define EXT4_XATTR_INODE_GET_PARENT(inode) ((__u32)(inode)->i_mtime.tv_sec) | |
| 358 | + | |
| 357 | 359 | static int ext4_xattr_inode_iget(struct inode *parent, unsigned long ea_ino, |
| 358 | − struct inode **ea_inode) | |
| 360 | + u32 ea_inode_hash, struct inode **ea_inode) | |
| 359 | 361 | { |
| 360 | 362 | struct inode *inode; |
| 361 | 363 | int err; |
| @@ -385,6 +387,24 @@ static int ext4_xattr_inode_iget(struct inode *parent, unsigned long ea_ino, · 23 unmodified lines | ||
| 385 | 387 | goto error; |
| 386 | 388 | } |
| 387 | 389 | |
| 390 | + ext4_xattr_inode_set_class(inode); | |
| 391 | + | |
| 392 | + /* | |
| 393 | + * Check whether this is an old Lustre-style xattr inode. Lustre | |
| 394 | + * implementation does not have hash validation, rather it has a | |
| 395 | + * backpointer from ea_inode to the parent inode. | |
| 396 | + */ | |
| 397 | + if (ea_inode_hash != ext4_xattr_inode_get_hash(inode) && | |
| 398 | + EXT4_XATTR_INODE_GET_PARENT(inode) == parent->i_ino && | |
| 399 | + inode->i_generation == parent->i_generation) { | |
| 400 | + ext4_set_inode_state(inode, EXT4_STATE_LUSTRE_EA_INODE); | |
| 401 | + ext4_xattr_inode_set_ref(inode, 1); | |
| 402 | + } else { | |
| 403 | + inode_lock(inode); | |
| 404 | + inode->i_flags |= S_NOQUOTA; | |
| 405 | + inode_unlock(inode); | |
| 406 | + } | |
| 407 | + | |
| 388 | 408 | *ea_inode = inode; |
| 389 | 409 | return 0; |
| 390 | 410 | error: |
| @@ -417,8 +437,6 @@ ext4_xattr_inode_verify_hashes(struct inode *ea_inode, · 26 unmodified lines | ||
| 417 | 437 | return 0; |
| 418 | 438 | } |
| 419 | 439 | |
| 420 | −#define EXT4_XATTR_INODE_GET_PARENT(inode) ((__u32)(inode)->i_mtime.tv_sec) | |
| 421 | − | |
| 422 | 440 | /* |
| 423 | 441 | * Read xattr value from the EA inode. |
| 424 | 442 | */ |
| @@ -431,7 +449,7 @@ ext4_xattr_inode_get(struct inode *inode, struct ext4_xattr_entry *entry, · 6 unmodified lines | ||
| 431 | 449 | int err; |
| 432 | 450 | |
| 433 | 451 | err = ext4_xattr_inode_iget(inode, le32_to_cpu(entry->e_value_inum), |
| 434 | − &ea_inode); | |
| 452 | + le32_to_cpu(entry->e_hash), &ea_inode); | |
| 435 | 453 | if (err) { |
| 436 | 454 | ea_inode = NULL; |
| 437 | 455 | goto out; |
| @@ -449,29 +467,20 @@ ext4_xattr_inode_get(struct inode *inode, struct ext4_xattr_entry *entry, · 11 unmodified lines | ||
| 449 | 467 | if (err) |
| 450 | 468 | goto out; |
| 451 | 469 | |
| 452 | − err = ext4_xattr_inode_verify_hashes(ea_inode, entry, buffer, size); | |
| 453 | − /* | |
| 454 | − * Compatibility check for old Lustre ea_inode implementation. Old | |
| 455 | − * version does not have hash validation, but it has a backpointer | |
| 456 | − * from ea_inode to the parent inode. | |
| 457 | − */ | |
| 458 | − if (err == -EFSCORRUPTED) { | |
| 459 | − if (EXT4_XATTR_INODE_GET_PARENT(ea_inode) != inode->i_ino || | |
| 460 | − ea_inode->i_generation != inode->i_generation) { | |
| 470 | + if (!ext4_test_inode_state(ea_inode, EXT4_STATE_LUSTRE_EA_INODE)) { | |
| 471 | + err = ext4_xattr_inode_verify_hashes(ea_inode, entry, buffer, | |
| 472 | + size); | |
| 473 | + if (err) { | |
| 461 | 474 | ext4_warning_inode(ea_inode, |
| 462 | 475 | "EA inode hash validation failed"); |
| 463 | 476 | goto out; |
| 464 | 477 | } |
| 465 | − /* Do not add ea_inode to the cache. */ | |
| 466 | − ea_inode_cache = NULL; | |
| 467 | − err = 0; | |
| 468 | − } else if (err) | |
| 469 | − goto out; | |
| 470 | 478 | |
| 471 | − if (ea_inode_cache) | |
| 472 | − mb_cache_entry_create(ea_inode_cache, GFP_NOFS, | |
| 473 | − ext4_xattr_inode_get_hash(ea_inode), | |
| 474 | − ea_inode->i_ino, true /* reusable */); | |
| 479 | + if (ea_inode_cache) | |
| 480 | + mb_cache_entry_create(ea_inode_cache, GFP_NOFS, | |
| 481 | + ext4_xattr_inode_get_hash(ea_inode), | |
| 482 | + ea_inode->i_ino, true /* reusable */); | |
| 483 | + } | |
| 475 | 484 | out: |
| 476 | 485 | iput(ea_inode); |
| 477 | 486 | return err; |
| @@ -838,10 +847,15 @@ static int ext4_xattr_inode_alloc_quota(struct inode *inode, size_t len) · 360 unmodified lines | ||
| 838 | 847 | return err; |
| 839 | 848 | } |
| 840 | 849 | |
| 841 | −static void ext4_xattr_inode_free_quota(struct inode *inode, size_t len) | |
| 850 | +static void ext4_xattr_inode_free_quota(struct inode *parent, | |
| 851 | + struct inode *ea_inode, | |
| 852 | + size_t len) | |
| 842 | 853 | { |
| 843 | − dquot_free_space_nodirty(inode, round_up_cluster(inode, len)); | |
| 844 | − dquot_free_inode(inode); | |
| 854 | + if (ea_inode && | |
| 855 | + ext4_test_inode_state(ea_inode, EXT4_STATE_LUSTRE_EA_INODE)) | |
| 856 | + return; | |
| 857 | + dquot_free_space_nodirty(parent, round_up_cluster(parent, len)); | |
| 858 | + dquot_free_inode(parent); | |
| 845 | 859 | } |
| 846 | 860 | |
| 847 | 861 | int __ext4_xattr_set_credits(struct super_block *sb, struct inode *inode, |
| @@ -1071,7 +1085,9 @@ static int ext4_xattr_inode_inc_ref_all(handle_t *handle, struct inode *parent, · 223 unmodified lines | ||
| 1071 | 1085 | if (!entry->e_value_inum) |
| 1072 | 1086 | continue; |
| 1073 | 1087 | ea_ino = le32_to_cpu(entry->e_value_inum); |
| 1074 | − err = ext4_xattr_inode_iget(parent, ea_ino, &ea_inode); | |
| 1088 | + err = ext4_xattr_inode_iget(parent, ea_ino, | |
| 1089 | + le32_to_cpu(entry->e_hash), | |
| 1090 | + &ea_inode); | |
| 1075 | 1091 | if (err) |
| 1076 | 1092 | goto cleanup; |
| 1077 | 1093 | err = ext4_xattr_inode_inc_ref(handle, ea_inode); |
| @@ -1093,7 +1109,9 @@ cleanup: · 15 unmodified lines | ||
| 1093 | 1109 | if (!entry->e_value_inum) |
| 1094 | 1110 | continue; |
| 1095 | 1111 | ea_ino = le32_to_cpu(entry->e_value_inum); |
| 1096 | − err = ext4_xattr_inode_iget(parent, ea_ino, &ea_inode); | |
| 1112 | + err = ext4_xattr_inode_iget(parent, ea_ino, | |
| 1113 | + le32_to_cpu(entry->e_hash), | |
| 1114 | + &ea_inode); | |
| 1097 | 1115 | if (err) { |
| 1098 | 1116 | ext4_warning(parent->i_sb, |
| 1099 | 1117 | "cleanup ea_ino %u iget error %d", ea_ino, |
| @@ -1131,7 +1149,9 @@ ext4_xattr_inode_dec_ref_all(handle_t *handle, struct inode *parent, · 31 unmodified lines | ||
| 1131 | 1149 | if (!entry->e_value_inum) |
| 1132 | 1150 | continue; |
| 1133 | 1151 | ea_ino = le32_to_cpu(entry->e_value_inum); |
| 1134 | − err = ext4_xattr_inode_iget(parent, ea_ino, &ea_inode); | |
| 1152 | + err = ext4_xattr_inode_iget(parent, ea_ino, | |
| 1153 | + le32_to_cpu(entry->e_hash), | |
| 1154 | + &ea_inode); | |
| 1135 | 1155 | if (err) |
| 1136 | 1156 | continue; |
| 1137 | 1157 | |
| @@ -1159,7 +1179,7 @@ ext4_xattr_inode_dec_ref_all(handle_t *handle, struct inode *parent, · 21 unmodified lines | ||
| 1159 | 1179 | } |
| 1160 | 1180 | |
| 1161 | 1181 | if (!skip_quota) |
| 1162 | − ext4_xattr_inode_free_quota(parent, | |
| 1182 | + ext4_xattr_inode_free_quota(parent, ea_inode, | |
| 1163 | 1183 | le32_to_cpu(entry->e_value_size)); |
| 1164 | 1184 | |
| 1165 | 1185 | /* |
| @@ -1591,6 +1611,7 @@ static int ext4_xattr_set_entry(struct ext4_xattr_info *i, · 425 unmodified lines | ||
| 1591 | 1611 | if (!s->not_found && here->e_value_inum) { |
| 1592 | 1612 | ret = ext4_xattr_inode_iget(inode, |
| 1593 | 1613 | le32_to_cpu(here->e_value_inum), |
| 1614 | + le32_to_cpu(here->e_hash), | |
| 1594 | 1615 | &old_ea_inode); |
| 1595 | 1616 | if (ret) { |
| 1596 | 1617 | old_ea_inode = NULL; |
| @@ -1609,7 +1630,7 @@ static int ext4_xattr_set_entry(struct ext4_xattr_info *i, · 12 unmodified lines | ||
| 1609 | 1630 | &new_ea_inode); |
| 1610 | 1631 | if (ret) { |
| 1611 | 1632 | new_ea_inode = NULL; |
| 1612 | − ext4_xattr_inode_free_quota(inode, i->value_len); | |
| 1633 | + ext4_xattr_inode_free_quota(inode, NULL, i->value_len); | |
| 1613 | 1634 | goto out; |
| 1614 | 1635 | } |
| 1615 | 1636 | } |
| @@ -1628,13 +1649,13 @@ static int ext4_xattr_set_entry(struct ext4_xattr_info *i, · 12 unmodified lines | ||
| 1628 | 1649 | ext4_warning_inode(new_ea_inode, |
| 1629 | 1650 | "dec ref new_ea_inode err=%d", |
| 1630 | 1651 | err); |
| 1631 | − ext4_xattr_inode_free_quota(inode, | |
| 1652 | + ext4_xattr_inode_free_quota(inode, new_ea_inode, | |
| 1632 | 1653 | i->value_len); |
| 1633 | 1654 | } |
| 1634 | 1655 | goto out; |
| 1635 | 1656 | } |
| 1636 | 1657 | |
| 1637 | − ext4_xattr_inode_free_quota(inode, | |
| 1658 | + ext4_xattr_inode_free_quota(inode, old_ea_inode, | |
| 1638 | 1659 | le32_to_cpu(here->e_value_size)); |
| 1639 | 1660 | } |
| 1640 | 1661 | |
| @@ -1805,8 +1826,10 @@ ext4_xattr_block_set(handle_t *handle, struct inode *inode, · 164 unmodified lines | ||
| 1805 | 1826 | struct mb_cache_entry *ce = NULL; |
| 1806 | 1827 | int error = 0; |
| 1807 | 1828 | struct mb_cache *ea_block_cache = EA_BLOCK_CACHE(inode); |
| 1808 | − struct inode *ea_inode = NULL; | |
| 1809 | − size_t old_ea_inode_size = 0; | |
| 1829 | + struct inode *ea_inode = NULL, *tmp_inode; | |
| 1830 | + size_t old_ea_inode_quota = 0; | |
| 1831 | + unsigned int ea_ino; | |
| 1832 | + | |
| 1810 | 1833 | |
| 1811 | 1834 | #define header(x) ((struct ext4_xattr_header *)(x)) |
| 1812 | 1835 | |
| @@ -1865,12 +1888,24 @@ ext4_xattr_block_set(handle_t *handle, struct inode *inode, · 52 unmodified lines | ||
| 1865 | 1888 | * like it has an empty value. |
| 1866 | 1889 | */ |
| 1867 | 1890 | if (!s->not_found && s->here->e_value_inum) { |
| 1868 | − /* | |
| 1869 | − * Defer quota free call for previous inode | |
| 1870 | − * until success is guaranteed. | |
| 1871 | − */ | |
| 1872 | − old_ea_inode_size = le32_to_cpu( | |
| 1891 | + ea_ino = le32_to_cpu(s->here->e_value_inum); | |
| 1892 | + error = ext4_xattr_inode_iget(inode, ea_ino, | |
| 1893 | + le32_to_cpu(s->here->e_hash), | |
| 1894 | + &tmp_inode); | |
| 1895 | + if (error) | |
| 1896 | + goto cleanup; | |
| 1897 | + | |
| 1898 | + if (!ext4_test_inode_state(tmp_inode, | |
| 1899 | + EXT4_STATE_LUSTRE_EA_INODE)) { | |
| 1900 | + /* | |
| 1901 | + * Defer quota free call for previous | |
| 1902 | + * inode until success is guaranteed. | |
| 1903 | + */ | |
| 1904 | + old_ea_inode_quota = le32_to_cpu( | |
| 1873 | 1905 | s->here->e_value_size); |
| 1906 | + } | |
| 1907 | + iput(tmp_inode); | |
| 1908 | + | |
| 1874 | 1909 | s->here->e_value_inum = 0; |
| 1875 | 1910 | s->here->e_value_size = 0; |
| 1876 | 1911 | } |
| @@ -1897,8 +1932,6 @@ ext4_xattr_block_set(handle_t *handle, struct inode *inode, · 20 unmodified lines | ||
| 1897 | 1932 | goto cleanup; |
| 1898 | 1933 | |
| 1899 | 1934 | if (i->value && s->here->e_value_inum) { |
| 1900 | − unsigned int ea_ino; | |
| 1901 | − | |
| 1902 | 1935 | /* |
| 1903 | 1936 | * A ref count on ea_inode has been taken as part of the call to |
| 1904 | 1937 | * ext4_xattr_set_entry() above. We would like to drop this |
| @@ -1906,7 +1939,9 @@ ext4_xattr_block_set(handle_t *handle, struct inode *inode, · 1 unmodified line | ||
| 1906 | 1939 | * initialized and has its own ref count on the ea_inode. |
| 1907 | 1940 | */ |
| 1908 | 1941 | ea_ino = le32_to_cpu(s->here->e_value_inum); |
| 1909 | − error = ext4_xattr_inode_iget(inode, ea_ino, &ea_inode); | |
| 1942 | + error = ext4_xattr_inode_iget(inode, ea_ino, | |
| 1943 | + le32_to_cpu(s->here->e_hash), | |
| 1944 | + &ea_inode); | |
| 1910 | 1945 | if (error) { |
| 1911 | 1946 | ea_inode = NULL; |
| 1912 | 1947 | goto cleanup; |
| @@ -2056,8 +2091,8 @@ getblk_failed: · 143 unmodified lines | ||
| 2056 | 2091 | } |
| 2057 | 2092 | } |
| 2058 | 2093 | |
| 2059 | − if (old_ea_inode_size) | |
| 2060 | − ext4_xattr_inode_free_quota(inode, old_ea_inode_size); | |
| 2094 | + if (old_ea_inode_quota) | |
| 2095 | + ext4_xattr_inode_free_quota(inode, NULL, old_ea_inode_quota); | |
| 2061 | 2096 | |
| 2062 | 2097 | /* Update the inode. */ |
| 2063 | 2098 | EXT4_I(inode)->i_file_acl = new_bh ? new_bh->b_blocknr : 0; |
| @@ -2084,7 +2119,7 @@ cleanup: · 20 unmodified lines | ||
| 2084 | 2119 | |
| 2085 | 2120 | /* If there was an error, revert the quota charge. */ |
| 2086 | 2121 | if (error) |
| 2087 | − ext4_xattr_inode_free_quota(inode, | |
| 2122 | + ext4_xattr_inode_free_quota(inode, ea_inode, | |
| 2088 | 2123 | i_size_read(ea_inode)); |
| 2089 | 2124 | iput(ea_inode); |
| 2090 | 2125 | } |
| @@ -2800,6 +2835,7 @@ int ext4_xattr_delete_inode(handle_t *handle, struct inode *inode, · 709 unmodified lines | ||
| 2800 | 2835 | struct ext4_xattr_ibody_header *header; |
| 2801 | 2836 | struct ext4_iloc iloc = { .bh = NULL }; |
| 2802 | 2837 | struct ext4_xattr_entry *entry; |
| 2838 | + struct inode *ea_inode; | |
| 2803 | 2839 | int error; |
| 2804 | 2840 | |
| 2805 | 2841 | error = ext4_xattr_ensure_credits(handle, inode, extra_credits, |
| @@ -2854,10 +2890,19 @@ int ext4_xattr_delete_inode(handle_t *handle, struct inode *inode, · 48 unmodified lines | ||
| 2854 | 2890 | |
| 2855 | 2891 | if (ext4_has_feature_ea_inode(inode->i_sb)) { |
| 2856 | 2892 | for (entry = BFIRST(bh); !IS_LAST_ENTRY(entry); |
| 2857 | − entry = EXT4_XATTR_NEXT(entry)) | |
| 2858 | − if (entry->e_value_inum) | |
| 2859 | − ext4_xattr_inode_free_quota(inode, | |
| 2893 | + entry = EXT4_XATTR_NEXT(entry)) { | |
| 2894 | + if (!entry->e_value_inum) | |
| 2895 | + continue; | |
| 2896 | + error = ext4_xattr_inode_iget(inode, | |
| 2897 | + le32_to_cpu(entry->e_value_inum), | |
| 2898 | + le32_to_cpu(entry->e_hash), | |
| 2899 | + &ea_inode); | |
| 2900 | + if (error) | |
| 2901 | + continue; | |
| 2902 | + ext4_xattr_inode_free_quota(inode, ea_inode, | |
| 2860 | 2903 | le32_to_cpu(entry->e_value_size)); |
| 2904 | + iput(ea_inode); | |
| 2905 | + } | |
| 2861 | 2906 | |
| 2862 | 2907 | } |
| 2863 | 2908 | |
| @@ -285,4 +285,19 @@ static inline bool itimerspec64_valid(const struct itimerspec64 *its) · 284 unmodified lines | ||
| 285 | 285 | return true; |
| 286 | 286 | } |
| 287 | 287 | |
| 288 | +/** | |
| 289 | + * time_after32 - compare two 32-bit relative times | |
| 290 | + * @a: the time which may be after @b | |
| 291 | + * @b: the time which may be before @a | |
| 292 | + * | |
| 293 | + * time_after32(a, b) returns true if the time @a is after time @b. | |
| 294 | + * time_before32(b, a) returns true if the time @b is before time @a. | |
| 295 | + * | |
| 296 | + * Similar to time_after(), compare two 32-bit timestamps for relative | |
| 297 | + * times. This is useful for comparing 32-bit seconds values that can't | |
| 298 | + * be converted to 64-bit values (e.g. due to disk format or wire protocol | |
| 299 | + * issues) when it is known that the times are less than 68 years apart. | |
| 300 | + */ | |
| 301 | +#define time_after32(a, b) ((s32)((u32)(b) - (u32)(a)) < 0) | |
| 302 | +#define time_before32(b, a) time_after32(a, b) | |
| 288 | 303 | #endif |