History

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

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()

Linus Torvalds committed 9 years ago

Commit be6297e2 parents 5791577 b5f515710 files · +222 −111Browse files

Unified · Split

10 files
  1. fs/ext4/dir.c +1 −1
  2. fs/ext4/ext4.h +5 −6
  3. fs/ext4/file.c +16 −3
  4. fs/ext4/hash.c +0 −4
  5. fs/ext4/ialloc.c +60 −33
  6. fs/ext4/inode.c +0 −8
  7. fs/ext4/mmp.c +1 −1
  8. fs/ext4/super.c +31 −7
  9. fs/ext4/xattr.c +93 −48
  10. include/linux/time.h +15 −0
fs/ext4/dir.c+1−1
@@ -411,7 +411,7 @@ static struct dir_private_info *ext4_htree_create_dir_info(struct file *filp, · 410 unmodified lines
411411 {
412412 struct dir_private_info *p;
413413
414− p = kzalloc(sizeof(struct dir_private_info), GFP_KERNEL);
414+ p = kzalloc(sizeof(*p), GFP_KERNEL);
415415 if (!p)
416416 return NULL;
417417 p->curr_hash = pos2maj_hash(filp, pos);
fs/ext4/ext4.h+5−6
@@ -838,13 +838,11 @@ static inline void ext4_decode_extra_time(struct timespec *time, __le32 extra) · 837 unmodified lines
838838 {
839839 if (unlikely(sizeof(time->tv_sec) > 4 &&
840840 (extra & cpu_to_le32(EXT4_EPOCH_MASK)))) {
841−#if LINUX_VERSION_CODE < KERNEL_VERSION(4,20,0)
841+
842+#if 1
842843 /* 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.)
848846 */
849847 u64 extra_bits = le32_to_cpu(extra) & EXT4_EPOCH_MASK;
850848 if (extra_bits == 3 && ((time->tv_sec) & 0x80000000) != 0)
@@ -1567,6 +1565,7 @@ enum { · 716 unmodified lines
15671565 nolocking */
15681566 EXT4_STATE_MAY_INLINE_DATA, /* may have in-inode data */
15691567 EXT4_STATE_EXT_PRECACHED, /* extents have been precached */
1568+ EXT4_STATE_LUSTRE_EA_INODE, /* Lustre-style ea_inode */
15701569 };
15711570
15721571 #define EXT4_INODE_BIT_FNS(name, field, offset) \
fs/ext4/file.c+16−3
@@ -279,7 +279,20 @@ static int ext4_dax_huge_fault(struct vm_fault *vmf, · 278 unmodified lines
279279 handle_t *handle = NULL;
280280 struct inode *inode = file_inode(vmf->vma->vm_file);
281281 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);
283296
284297 if (write) {
285298 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
595608 inode_lock(inode);
596609
597610 isize = i_size_read(inode);
598− if (offset >= isize) {
611+ if (offset < 0 || offset >= isize) {
599612 inode_unlock(inode);
600613 return -ENXIO;
601614 }
@@ -658,7 +671,7 @@ static loff_t ext4_seek_hole(struct file *file, loff_t offset, loff_t maxsize) · 56 unmodified lines
658671 inode_lock(inode);
659672
660673 isize = i_size_read(inode);
661− if (offset >= isize) {
674+ if (offset < 0 || offset >= isize) {
662675 inode_unlock(inode);
663676 return -ENXIO;
664677 }
fs/ext4/hash.c+0−4
@@ -148,8 +148,6 @@ static void str2hashbuf_signed(const char *msg, int len, __u32 *buf, int num) · 147 unmodified lines
148148 if (len > num*4)
149149 len = num * 4;
150150 for (i = 0; i < len; i++) {
151− if ((i % 4) == 0)
152− val = pad;
153151 val = ((int) scp[i]) + (val << 8);
154152 if ((i % 4) == 3) {
155153 *buf++ = val;
@@ -176,8 +174,6 @@ static void str2hashbuf_unsigned(const char *msg, int len, __u32 *buf, int num) · 20 unmodified lines
176174 if (len > num*4)
177175 len = num * 4;
178176 for (i = 0; i < len; i++) {
179− if ((i % 4) == 0)
180− val = pad;
181177 val = ((int) ucp[i]) + (val << 8);
182178 if ((i % 4) == 3) {
183179 *buf++ = val;
fs/ext4/ialloc.c+60−33
@@ -692,24 +692,25 @@ static int find_group_other(struct super_block *sb, struct inode *parent, · 691 unmodified lines
692692 * somewhat arbitrary...)
693693 */
694694 #define RECENTCY_MIN 5
695−#define RECENTCY_DIRTY 30
695+#define RECENTCY_DIRTY 300
696696
697697 static int recently_deleted(struct super_block *sb, ext4_group_t group, int ino)
698698 {
699699 struct ext4_group_desc *gdp;
700700 struct ext4_inode *raw_inode;
701701 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;
705706
706707 gdp = ext4_get_group_desc(sb, group, NULL);
707708 if (unlikely(!gdp))
708709 return 0;
709710
710− bh = sb_getblk(sb, ext4_inode_table(sb, gdp) +
711+ bh = sb_find_get_block(sb, ext4_inode_table(sb, gdp) +
711712 (ino / inodes_per_block));
712− if (unlikely(!bh) || !buffer_uptodate(bh))
713+ if (!bh || !buffer_uptodate(bh))
713714 /*
714715 * If the block is not in the buffer cache, then it
715716 * 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
718719
719720 offset = (ino % inodes_per_block) * EXT4_INODE_SIZE(sb);
720721 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() */
721727 dtime = le32_to_cpu(raw_inode->i_dtime);
722− now = get_seconds();
728+ now = ktime_get_real_seconds();
723729 if (buffer_dirty(bh))
724730 recentcy += RECENTCY_DIRTY;
725731
726− if (dtime && (dtime < now) && (now < dtime + recentcy))
732+ if (dtime && time_before32(dtime, now) &&
733+ time_before32(now, dtime + recentcy))
727734 ret = 1;
728735 out:
729736 brelse(bh);
730737 return ret;
731738 }
732739
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+
733761 /*
734762 * There are two policies for allocating an inode. If the new inode is
735763 * a directory, then a forward search is made for a block group with both
@@ -892,19 +920,13 @@ got_group: · 156 unmodified lines
892920 /*
893921 * Check free inodes count before loading bitmap.
894922 */
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;
900925
901926 grp = ext4_get_group_info(sb, group);
902927 /* 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;
908930
909931 brelse(inode_bitmap_bh);
910932 inode_bitmap_bh = ext4_read_inode_bitmap(sb, group);
@@ -912,27 +934,20 @@ got_group: · 1 unmodified line
912934 if (EXT4_MB_GRP_IBITMAP_CORRUPT(grp) ||
913935 IS_ERR(inode_bitmap_bh)) {
914936 inode_bitmap_bh = NULL;
915− if (++group == ngroups)
916− group = 0;
917− continue;
937+ goto next_group;
918938 }
919939
920940 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)
925943 goto next_group;
926− if (group == 0 && (ino+1) < EXT4_FIRST_INO(sb)) {
944+
945+ if (group == 0 && (ino + 1) < EXT4_FIRST_INO(sb)) {
927946 ext4_error(sb, "reserved inode found cleared - "
928947 "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;
935949 }
950+
936951 if (!handle) {
937952 BUG_ON(nblocks <= 0);
938953 handle = __ext4_journal_start_sb(dir->i_sb, line_no,
@@ -952,11 +967,23 @@ repeat_in_this_group: · 13 unmodified lines
952967 }
953968 ext4_lock_group(sb, group);
954969 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+ }
955982 ext4_unlock_group(sb, group);
956983 ino++; /* the inode bitmap is zero-based */
957984 if (!ret2)
958985 goto got; /* we grabbed the inode! */
959−next_inode:
986+
960987 if (ino < EXT4_INODES_PER_GROUP(sb))
961988 goto repeat_in_this_group;
962989 next_group:
fs/ext4/inode.c+0−8
@@ -4897,14 +4897,6 @@ struct inode *ext4_iget(struct super_block *sb, unsigned long ino) · 4896 unmodified lines
48974897 brelse(iloc.bh);
48984898 ext4_set_inode_flags(inode);
48994899
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−
49084900 unlock_new_inode(inode);
49094901 return inode;
49104902
fs/ext4/mmp.c+1−1
@@ -367,7 +367,7 @@ skip: · 366 unmodified lines
367367 goto failed;
368368 }
369369
370− mmpd_data = kmalloc(sizeof(struct mmpd_data), GFP_KERNEL);
370+ mmpd_data = kmalloc(sizeof(*mmpd_data), GFP_KERNEL);
371371 if (!mmpd_data) {
372372 ext4_warning(sb, "not enough memory for mmpd_data");
373373 goto failed;
fs/ext4/super.c+31−7
@@ -2404,6 +2404,7 @@ static void ext4_orphan_cleanup(struct super_block *sb, · 2403 unmodified lines
24042404 unsigned int s_flags = sb->s_flags;
24052405 int ret, nr_orphans = 0, nr_truncates = 0;
24062406 #ifdef CONFIG_QUOTA
2407+ int quota_update = 0;
24072408 int i;
24082409 #endif
24092410 if (!es->s_last_orphan) {
@@ -2442,14 +2443,32 @@ static void ext4_orphan_cleanup(struct super_block *sb, · 32 unmodified lines
24422443 #ifdef CONFIG_QUOTA
24432444 /* Needed for iput() to work correctly and not trash data */
24442445 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 */
24462462 for (i = 0; i < EXT4_MAXQUOTAS; i++) {
24472463 if (EXT4_SB(sb)->s_qf_names[i]) {
24482464 int ret = ext4_quota_on_mount(sb, i);
2449− if (ret < 0)
2465+
2466+ if (!ret)
2467+ quota_update = 1;
2468+ else
24502469 ext4_msg(sb, KERN_ERR,
24512470 "Cannot turn on journaled "
2452− "quota: error %d", ret);
2471+ "quota: type %d: error %d", i, ret);
24532472 }
24542473 }
24552474 #endif
@@ -2510,10 +2529,12 @@ static void ext4_orphan_cleanup(struct super_block *sb, · 54 unmodified lines
25102529 ext4_msg(sb, KERN_INFO, "%d truncate%s cleaned up",
25112530 PLURAL(nr_truncates));
25122531 #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+ }
25172538 }
25182539 #endif
25192540 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
55125533 DQUOT_USAGE_ENABLED |
55135534 (quota_mopt[type] ? DQUOT_LIMITS_ENABLED : 0));
55145535 if (err) {
5536+ for (type--; type >= 0; type--)
5537+ dquot_quota_off(sb, type);
5538+
55155539 ext4_warning(sb,
55165540 "Failed to enable quota tracking "
55175541 "(type=%d, err=%d). Please run "
fs/ext4/xattr.c+93−48
@@ -354,8 +354,10 @@ free_bhs: · 353 unmodified lines
354354 return ret;
355355 }
356356
357+#define EXT4_XATTR_INODE_GET_PARENT(inode) ((__u32)(inode)->i_mtime.tv_sec)
358+
357359 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)
359361 {
360362 struct inode *inode;
361363 int err;
@@ -385,6 +387,24 @@ static int ext4_xattr_inode_iget(struct inode *parent, unsigned long ea_ino, · 23 unmodified lines
385387 goto error;
386388 }
387389
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+
388408 *ea_inode = inode;
389409 return 0;
390410 error:
@@ -417,8 +437,6 @@ ext4_xattr_inode_verify_hashes(struct inode *ea_inode, · 26 unmodified lines
417437 return 0;
418438 }
419439
420−#define EXT4_XATTR_INODE_GET_PARENT(inode) ((__u32)(inode)->i_mtime.tv_sec)
421−
422440 /*
423441 * Read xattr value from the EA inode.
424442 */
@@ -431,7 +449,7 @@ ext4_xattr_inode_get(struct inode *inode, struct ext4_xattr_entry *entry, · 6 unmodified lines
431449 int err;
432450
433451 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);
435453 if (err) {
436454 ea_inode = NULL;
437455 goto out;
@@ -449,29 +467,20 @@ ext4_xattr_inode_get(struct inode *inode, struct ext4_xattr_entry *entry, · 11 unmodified lines
449467 if (err)
450468 goto out;
451469
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) {
461474 ext4_warning_inode(ea_inode,
462475 "EA inode hash validation failed");
463476 goto out;
464477 }
465− /* Do not add ea_inode to the cache. */
466− ea_inode_cache = NULL;
467− err = 0;
468− } else if (err)
469− goto out;
470478
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+ }
475484 out:
476485 iput(ea_inode);
477486 return err;
@@ -838,10 +847,15 @@ static int ext4_xattr_inode_alloc_quota(struct inode *inode, size_t len) · 360 unmodified lines
838847 return err;
839848 }
840849
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)
842853 {
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);
845859 }
846860
847861 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
10711085 if (!entry->e_value_inum)
10721086 continue;
10731087 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);
10751091 if (err)
10761092 goto cleanup;
10771093 err = ext4_xattr_inode_inc_ref(handle, ea_inode);
@@ -1093,7 +1109,9 @@ cleanup: · 15 unmodified lines
10931109 if (!entry->e_value_inum)
10941110 continue;
10951111 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);
10971115 if (err) {
10981116 ext4_warning(parent->i_sb,
10991117 "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
11311149 if (!entry->e_value_inum)
11321150 continue;
11331151 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);
11351155 if (err)
11361156 continue;
11371157
@@ -1159,7 +1179,7 @@ ext4_xattr_inode_dec_ref_all(handle_t *handle, struct inode *parent, · 21 unmodified lines
11591179 }
11601180
11611181 if (!skip_quota)
1162− ext4_xattr_inode_free_quota(parent,
1182+ ext4_xattr_inode_free_quota(parent, ea_inode,
11631183 le32_to_cpu(entry->e_value_size));
11641184
11651185 /*
@@ -1591,6 +1611,7 @@ static int ext4_xattr_set_entry(struct ext4_xattr_info *i, · 425 unmodified lines
15911611 if (!s->not_found && here->e_value_inum) {
15921612 ret = ext4_xattr_inode_iget(inode,
15931613 le32_to_cpu(here->e_value_inum),
1614+ le32_to_cpu(here->e_hash),
15941615 &old_ea_inode);
15951616 if (ret) {
15961617 old_ea_inode = NULL;
@@ -1609,7 +1630,7 @@ static int ext4_xattr_set_entry(struct ext4_xattr_info *i, · 12 unmodified lines
16091630 &new_ea_inode);
16101631 if (ret) {
16111632 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);
16131634 goto out;
16141635 }
16151636 }
@@ -1628,13 +1649,13 @@ static int ext4_xattr_set_entry(struct ext4_xattr_info *i, · 12 unmodified lines
16281649 ext4_warning_inode(new_ea_inode,
16291650 "dec ref new_ea_inode err=%d",
16301651 err);
1631− ext4_xattr_inode_free_quota(inode,
1652+ ext4_xattr_inode_free_quota(inode, new_ea_inode,
16321653 i->value_len);
16331654 }
16341655 goto out;
16351656 }
16361657
1637− ext4_xattr_inode_free_quota(inode,
1658+ ext4_xattr_inode_free_quota(inode, old_ea_inode,
16381659 le32_to_cpu(here->e_value_size));
16391660 }
16401661
@@ -1805,8 +1826,10 @@ ext4_xattr_block_set(handle_t *handle, struct inode *inode, · 164 unmodified lines
18051826 struct mb_cache_entry *ce = NULL;
18061827 int error = 0;
18071828 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+
18101833
18111834 #define header(x) ((struct ext4_xattr_header *)(x))
18121835
@@ -1865,12 +1888,24 @@ ext4_xattr_block_set(handle_t *handle, struct inode *inode, · 52 unmodified lines
18651888 * like it has an empty value.
18661889 */
18671890 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(
18731905 s->here->e_value_size);
1906+ }
1907+ iput(tmp_inode);
1908+
18741909 s->here->e_value_inum = 0;
18751910 s->here->e_value_size = 0;
18761911 }
@@ -1897,8 +1932,6 @@ ext4_xattr_block_set(handle_t *handle, struct inode *inode, · 20 unmodified lines
18971932 goto cleanup;
18981933
18991934 if (i->value && s->here->e_value_inum) {
1900− unsigned int ea_ino;
1901−
19021935 /*
19031936 * A ref count on ea_inode has been taken as part of the call to
19041937 * 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
19061939 * initialized and has its own ref count on the ea_inode.
19071940 */
19081941 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);
19101945 if (error) {
19111946 ea_inode = NULL;
19121947 goto cleanup;
@@ -2056,8 +2091,8 @@ getblk_failed: · 143 unmodified lines
20562091 }
20572092 }
20582093
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);
20612096
20622097 /* Update the inode. */
20632098 EXT4_I(inode)->i_file_acl = new_bh ? new_bh->b_blocknr : 0;
@@ -2084,7 +2119,7 @@ cleanup: · 20 unmodified lines
20842119
20852120 /* If there was an error, revert the quota charge. */
20862121 if (error)
2087− ext4_xattr_inode_free_quota(inode,
2122+ ext4_xattr_inode_free_quota(inode, ea_inode,
20882123 i_size_read(ea_inode));
20892124 iput(ea_inode);
20902125 }
@@ -2800,6 +2835,7 @@ int ext4_xattr_delete_inode(handle_t *handle, struct inode *inode, · 709 unmodified lines
28002835 struct ext4_xattr_ibody_header *header;
28012836 struct ext4_iloc iloc = { .bh = NULL };
28022837 struct ext4_xattr_entry *entry;
2838+ struct inode *ea_inode;
28032839 int error;
28042840
28052841 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
28542890
28552891 if (ext4_has_feature_ea_inode(inode->i_sb)) {
28562892 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,
28602903 le32_to_cpu(entry->e_value_size));
2904+ iput(ea_inode);
2905+ }
28612906
28622907 }
28632908
include/linux/time.h+15−0
@@ -285,4 +285,19 @@ static inline bool itimerspec64_valid(const struct itimerspec64 *its) · 284 unmodified lines
285285 return true;
286286 }
287287
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)
288303 #endif