|
15 | 15 | #include "node.h"
|
16 | 16 | #include <trace/events/f2fs.h>
|
17 | 17 |
|
| 18 | +static void __set_extent_info(struct extent_info *ei, |
| 19 | + unsigned int fofs, unsigned int len, |
| 20 | + block_t blk, bool keep_clen) |
| 21 | +{ |
| 22 | + ei->fofs = fofs; |
| 23 | + ei->blk = blk; |
| 24 | + ei->len = len; |
| 25 | + |
| 26 | + if (keep_clen) |
| 27 | + return; |
| 28 | + |
| 29 | +#ifdef CONFIG_F2FS_FS_COMPRESSION |
| 30 | + ei->c_len = 0; |
| 31 | +#endif |
| 32 | +} |
| 33 | + |
| 34 | +static bool f2fs_may_extent_tree(struct inode *inode) |
| 35 | +{ |
| 36 | + struct f2fs_sb_info *sbi = F2FS_I_SB(inode); |
| 37 | + |
| 38 | + /* |
| 39 | + * for recovered files during mount do not create extents |
| 40 | + * if shrinker is not registered. |
| 41 | + */ |
| 42 | + if (list_empty(&sbi->s_list)) |
| 43 | + return false; |
| 44 | + |
| 45 | + if (!test_opt(sbi, READ_EXTENT_CACHE) || |
| 46 | + is_inode_flag_set(inode, FI_NO_EXTENT) || |
| 47 | + (is_inode_flag_set(inode, FI_COMPRESSED_FILE) && |
| 48 | + !f2fs_sb_has_readonly(sbi))) |
| 49 | + return false; |
| 50 | + |
| 51 | + return S_ISREG(inode->i_mode); |
| 52 | +} |
| 53 | + |
| 54 | +static void __try_update_largest_extent(struct extent_tree *et, |
| 55 | + struct extent_node *en) |
| 56 | +{ |
| 57 | + if (en->ei.len <= et->largest.len) |
| 58 | + return; |
| 59 | + |
| 60 | + et->largest = en->ei; |
| 61 | + et->largest_updated = true; |
| 62 | +} |
| 63 | + |
| 64 | +static bool __is_extent_mergeable(struct extent_info *back, |
| 65 | + struct extent_info *front) |
| 66 | +{ |
| 67 | +#ifdef CONFIG_F2FS_FS_COMPRESSION |
| 68 | + if (back->c_len && back->len != back->c_len) |
| 69 | + return false; |
| 70 | + if (front->c_len && front->len != front->c_len) |
| 71 | + return false; |
| 72 | +#endif |
| 73 | + return (back->fofs + back->len == front->fofs && |
| 74 | + back->blk + back->len == front->blk); |
| 75 | +} |
| 76 | + |
| 77 | +static bool __is_back_mergeable(struct extent_info *cur, |
| 78 | + struct extent_info *back) |
| 79 | +{ |
| 80 | + return __is_extent_mergeable(back, cur); |
| 81 | +} |
| 82 | + |
| 83 | +static bool __is_front_mergeable(struct extent_info *cur, |
| 84 | + struct extent_info *front) |
| 85 | +{ |
| 86 | + return __is_extent_mergeable(cur, front); |
| 87 | +} |
| 88 | + |
18 | 89 | static struct rb_entry *__lookup_rb_tree_fast(struct rb_entry *cached_re,
|
19 | 90 | unsigned int ofs)
|
20 | 91 | {
|
@@ -591,16 +662,16 @@ static void f2fs_update_extent_tree_range(struct inode *inode,
|
591 | 662 |
|
592 | 663 | if (end < org_end && org_end - end >= F2FS_MIN_EXTENT_LEN) {
|
593 | 664 | if (parts) {
|
594 |
| - set_extent_info(&ei, end, |
595 |
| - end - dei.fofs + dei.blk, |
596 |
| - org_end - end); |
| 665 | + __set_extent_info(&ei, |
| 666 | + end, org_end - end, |
| 667 | + end - dei.fofs + dei.blk, false); |
597 | 668 | en1 = __insert_extent_tree(sbi, et, &ei,
|
598 | 669 | NULL, NULL, true);
|
599 | 670 | next_en = en1;
|
600 | 671 | } else {
|
601 |
| - en->ei.fofs = end; |
602 |
| - en->ei.blk += end - dei.fofs; |
603 |
| - en->ei.len -= end - dei.fofs; |
| 672 | + __set_extent_info(&en->ei, |
| 673 | + end, en->ei.len - (end - dei.fofs), |
| 674 | + en->ei.blk + (end - dei.fofs), true); |
604 | 675 | next_en = en;
|
605 | 676 | }
|
606 | 677 | parts++;
|
@@ -632,8 +703,7 @@ static void f2fs_update_extent_tree_range(struct inode *inode,
|
632 | 703 |
|
633 | 704 | /* 3. update extent in extent cache */
|
634 | 705 | if (blkaddr) {
|
635 |
| - |
636 |
| - set_extent_info(&ei, fofs, blkaddr, len); |
| 706 | + __set_extent_info(&ei, fofs, len, blkaddr, false); |
637 | 707 | if (!__try_merge_extent_node(sbi, et, &ei, prev_en, next_en))
|
638 | 708 | __insert_extent_tree(sbi, et, &ei,
|
639 | 709 | insert_p, insert_parent, leftmost);
|
@@ -692,7 +762,7 @@ void f2fs_update_extent_tree_range_compressed(struct inode *inode,
|
692 | 762 | if (en)
|
693 | 763 | goto unlock_out;
|
694 | 764 |
|
695 |
| - set_extent_info(&ei, fofs, blkaddr, llen); |
| 765 | + __set_extent_info(&ei, fofs, llen, blkaddr, true); |
696 | 766 | ei.c_len = c_len;
|
697 | 767 |
|
698 | 768 | if (!__try_merge_extent_node(sbi, et, &ei, prev_en, next_en))
|
|
0 commit comments