1 From: Mark Fasheh <mfasheh@suse.com>
2 Date: Wed, 12 Nov 2008 15:16:38 -0800
3 Subject: ocfs2: turn __ocfs2_remove_inode_range() into ocfs2_remove_btree_range()
6 This patch genericizes the high level handling of extent removal.
7 ocfs2_remove_btree_range() is nearly identical to
8 __ocfs2_remove_inode_range(), except that extent tree operations have been
9 used where necessary. We update ocfs2_remove_inode_range() to use the
10 generic helper. Now extent tree based structures have an easy way to
13 Signed-off-by: Mark Fasheh <mfasheh@suse.com>
14 Acked-by: Joel Becker <joel.becker@oracle.com>
16 fs/ocfs2/alloc.c | 72 +++++++++++++++++++++++++++++++++++++++++++++
17 fs/ocfs2/alloc.h | 5 +++
18 fs/ocfs2/file.c | 85 +++--------------------------------------------------
19 3 files changed, 82 insertions(+), 80 deletions(-)
21 Index: linux-2.6.27-ocfs2/fs/ocfs2/alloc.c
22 ===================================================================
23 --- linux-2.6.27-ocfs2.orig/fs/ocfs2/alloc.c
24 +++ linux-2.6.27-ocfs2/fs/ocfs2/alloc.c
25 @@ -5264,6 +5264,78 @@ out:
29 +int ocfs2_remove_btree_range(struct inode *inode,
30 + struct ocfs2_extent_tree *et,
31 + u32 cpos, u32 phys_cpos, u32 len,
32 + struct ocfs2_cached_dealloc_ctxt *dealloc)
35 + u64 phys_blkno = ocfs2_clusters_to_blocks(inode->i_sb, phys_cpos);
36 + struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
37 + struct inode *tl_inode = osb->osb_tl_inode;
39 + struct ocfs2_alloc_context *meta_ac = NULL;
41 + ret = ocfs2_lock_allocators(inode, et, 0, 1, NULL, &meta_ac);
47 + mutex_lock(&tl_inode->i_mutex);
49 + if (ocfs2_truncate_log_needs_flush(osb)) {
50 + ret = __ocfs2_flush_truncate_log(osb);
57 + handle = ocfs2_start_trans(osb, OCFS2_REMOVE_EXTENT_CREDITS);
58 + if (IS_ERR(handle)) {
59 + ret = PTR_ERR(handle);
64 + ret = ocfs2_journal_access(handle, inode, et->et_root_bh,
65 + OCFS2_JOURNAL_ACCESS_WRITE);
71 + ret = ocfs2_remove_extent(inode, et, cpos, len, handle, meta_ac,
78 + ocfs2_et_update_clusters(inode, et, -len);
80 + ret = ocfs2_journal_dirty(handle, et->et_root_bh);
86 + ret = ocfs2_truncate_log_append(osb, handle, phys_blkno, len);
91 + ocfs2_commit_trans(osb, handle);
93 + mutex_unlock(&tl_inode->i_mutex);
96 + ocfs2_free_alloc_context(meta_ac);
101 int ocfs2_truncate_log_needs_flush(struct ocfs2_super *osb)
103 struct buffer_head *tl_bh = osb->osb_tl_bh;
104 Index: linux-2.6.27-ocfs2/fs/ocfs2/alloc.h
105 ===================================================================
106 --- linux-2.6.27-ocfs2.orig/fs/ocfs2/alloc.h
107 +++ linux-2.6.27-ocfs2/fs/ocfs2/alloc.h
108 @@ -110,6 +110,11 @@ int ocfs2_remove_extent(struct inode *in
109 u32 cpos, u32 len, handle_t *handle,
110 struct ocfs2_alloc_context *meta_ac,
111 struct ocfs2_cached_dealloc_ctxt *dealloc);
112 +int ocfs2_remove_btree_range(struct inode *inode,
113 + struct ocfs2_extent_tree *et,
114 + u32 cpos, u32 phys_cpos, u32 len,
115 + struct ocfs2_cached_dealloc_ctxt *dealloc);
117 int ocfs2_num_free_extents(struct ocfs2_super *osb,
119 struct ocfs2_extent_tree *et);
120 Index: linux-2.6.27-ocfs2/fs/ocfs2/file.c
121 ===================================================================
122 --- linux-2.6.27-ocfs2.orig/fs/ocfs2/file.c
123 +++ linux-2.6.27-ocfs2/fs/ocfs2/file.c
124 @@ -1226,83 +1226,6 @@ out:
128 -static int __ocfs2_remove_inode_range(struct inode *inode,
129 - struct buffer_head *di_bh,
130 - u32 cpos, u32 phys_cpos, u32 len,
131 - struct ocfs2_cached_dealloc_ctxt *dealloc)
134 - u64 phys_blkno = ocfs2_clusters_to_blocks(inode->i_sb, phys_cpos);
135 - struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
136 - struct inode *tl_inode = osb->osb_tl_inode;
138 - struct ocfs2_alloc_context *meta_ac = NULL;
139 - struct ocfs2_dinode *di = (struct ocfs2_dinode *)di_bh->b_data;
140 - struct ocfs2_extent_tree et;
142 - ocfs2_init_dinode_extent_tree(&et, inode, di_bh);
144 - ret = ocfs2_lock_allocators(inode, &et, 0, 1, NULL, &meta_ac);
150 - mutex_lock(&tl_inode->i_mutex);
152 - if (ocfs2_truncate_log_needs_flush(osb)) {
153 - ret = __ocfs2_flush_truncate_log(osb);
160 - handle = ocfs2_start_trans(osb, OCFS2_REMOVE_EXTENT_CREDITS);
161 - if (IS_ERR(handle)) {
162 - ret = PTR_ERR(handle);
167 - ret = ocfs2_journal_access(handle, inode, di_bh,
168 - OCFS2_JOURNAL_ACCESS_WRITE);
174 - ret = ocfs2_remove_extent(inode, &et, cpos, len, handle, meta_ac,
181 - OCFS2_I(inode)->ip_clusters -= len;
182 - di->i_clusters = cpu_to_le32(OCFS2_I(inode)->ip_clusters);
184 - ret = ocfs2_journal_dirty(handle, di_bh);
190 - ret = ocfs2_truncate_log_append(osb, handle, phys_blkno, len);
195 - ocfs2_commit_trans(osb, handle);
197 - mutex_unlock(&tl_inode->i_mutex);
200 - ocfs2_free_alloc_context(meta_ac);
206 * Truncate a byte range, avoiding pages within partial clusters. This
207 * preserves those pages for the zeroing code to write to.
208 @@ -1402,7 +1325,9 @@ static int ocfs2_remove_inode_range(stru
209 struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
210 struct ocfs2_cached_dealloc_ctxt dealloc;
211 struct address_space *mapping = inode->i_mapping;
212 + struct ocfs2_extent_tree et;
214 + ocfs2_init_dinode_extent_tree(&et, inode, di_bh);
215 ocfs2_init_dealloc_ctxt(&dealloc);
218 @@ -1458,9 +1383,9 @@ static int ocfs2_remove_inode_range(stru
220 /* Only do work for non-holes */
221 if (phys_cpos != 0) {
222 - ret = __ocfs2_remove_inode_range(inode, di_bh, cpos,
223 - phys_cpos, alloc_size,
225 + ret = ocfs2_remove_btree_range(inode, &et, cpos,
226 + phys_cpos, alloc_size,