2 fs/ext4/ext4.h | 6 +++++
3 fs/ext4/ext4_extents.h | 10 +++++++++
4 fs/ext4/ext4_jbd2.h | 3 ++
5 fs/ext4/extents.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++++
6 fs/ext4/super.c | 12 +++++++++++
7 5 files changed, 81 insertions(+)
11 @@ -1826,6 +1829,9 @@ extern void ext4_add_groupblocks(handle_
12 ext4_fsblk_t block, unsigned long count);
13 extern int ext4_trim_fs(struct super_block *, struct fstrim_range *);
15 +extern void ext4_mb_discard_inode_preallocations(struct inode *);
19 struct buffer_head *ext4_getblk(handle_t *, struct inode *,
20 ext4_lblk_t, int, int *);
21 --- a/fs/ext4/ext4_extents.h
22 +++ b/fs/ext4/ext4_extents.h
28 + * define EXT4_ALLOC_NEEDED to 0 since block bitmap, group desc. and sb
29 + * are now accounted in ext4_ext_calc_credits_for_insert()
31 +#define EXT4_ALLOC_NEEDED 0
32 +#define HAVE_EXT_PREPARE_CB_EXTENT
33 +#define HAVE_EXT4_EXT_PBLOCK
36 * ext4_inode has i_block array (60 bytes total).
37 @@ -241,6 +248,7 @@ static inline ext4_fsblk_t ext4_ext_pblo
38 block |= ((ext4_fsblk_t) le16_to_cpu(ex->ee_start_hi) << 31) << 1;
41 +#define ext_pblock(ex) ext4_ext_pblock(ex)
45 @@ -287,6 +295,8 @@ extern int ext4_extent_tree_init(handle_
46 extern int ext4_ext_calc_credits_for_single_extent(struct inode *inode,
48 struct ext4_ext_path *path);
49 +extern int ext4_ext_calc_credits_for_insert(struct inode *,
50 + struct ext4_ext_path *);
51 extern int ext4_can_extents_be_merged(struct inode *inode,
52 struct ext4_extent *ex1,
53 struct ext4_extent *ex2);
54 --- a/fs/ext4/ext4_jbd2.h
55 +++ b/fs/ext4/ext4_jbd2.h
56 @@ -175,6 +177,7 @@ static inline void ext4_journal_callback
57 list_del_init(&jce->jce_list);
58 spin_unlock(&sbi->s_md_lock);
60 +#define HAVE_EXT4_JOURNAL_CALLBACK_ADD
63 ext4_mark_iloc_dirty(handle_t *handle,
64 --- a/fs/ext4/extents.c
65 +++ b/fs/ext4/extents.c
66 @@ -2205,6 +2205,56 @@ int ext4_ext_calc_credits_for_single_ext
70 + * This routine returns max. credits extent tree can consume.
71 + * It should be OK for low-performance paths like ->writepage()
72 + * To allow many writing process to fit a single transaction,
73 + * caller should calculate credits under truncate_mutex and
76 +int ext4_ext_calc_credits_for_insert(struct inode *inode,
77 + struct ext4_ext_path *path)
82 + /* probably there is space in leaf? */
83 + depth = path->p_depth;
84 + if (le16_to_cpu(path[depth].p_hdr->eh_entries)
85 + < le16_to_cpu(path[depth].p_hdr->eh_max))
90 + * given 32bit logical block (4294967296 blocks), max. tree
91 + * can be 4 levels in depth -- 4 * 340^4 == 53453440000.
92 + * let's also add one more level for imbalance.
96 + /* allocation of new data block(s) */
100 + * tree can be full, so it'd need to grow in depth:
101 + * we need one credit to modify old root, credits for
102 + * new root will be added in split accounting
106 + * Index split can happen, we'd need:
107 + * allocate intermediate indexes (bitmap + group)
108 + * + change two blocks at each level, but root (already included)
110 + needed += (depth * 2) + (depth * 2);
112 + /* any allocation modifies superblock */
117 +EXPORT_SYMBOL(ext4_ext_calc_credits_for_insert);
120 * How many index/leaf blocks need to change/allocate to modify nrblocks?
122 * if nrblocks are fit in a single extent (chunk flag is 1), then