1 From: Joel Becker <joel.becker@oracle.com>
2 Subject: ocfs2: Add an insertion check to ocfs2_extent_tree_operations.
3 Patch-mainline: 2.6.28?
6 A couple places check an extent_tree for a valid inode. We move that
7 out to add an eo_insert_check() operation. It can be called from
8 ocfs2_insert_extent() and elsewhere.
10 We also have the wrapper calls ocfs2_et_insert_check() and
11 ocfs2_et_sanity_check() ignore NULL ops. That way we don't have to
12 provide useless operations for xattr types.
14 Signed-off-by: Joel Becker <joel.becker@oracle.com>
15 Acked-by: Mark Fasheh <mark.fasheh@suse.com>
17 fs/ocfs2/alloc.c | 69 ++++++++++++++++++++++++++++++++++-------------------
18 1 files changed, 44 insertions(+), 25 deletions(-)
20 diff --git a/fs/ocfs2/alloc.c b/fs/ocfs2/alloc.c
21 index 243bacf..2083c2c 100644
22 --- a/fs/ocfs2/alloc.c
23 +++ b/fs/ocfs2/alloc.c
24 @@ -71,6 +71,9 @@ struct ocfs2_extent_tree_operations {
25 void (*eo_update_clusters)(struct inode *inode,
26 struct ocfs2_extent_tree *et,
28 + int (*eo_insert_check)(struct inode *inode,
29 + struct ocfs2_extent_tree *et,
30 + struct ocfs2_extent_rec *rec);
31 int (*eo_sanity_check)(struct inode *inode, struct ocfs2_extent_tree *et);
33 /* These are internal to ocfs2_extent_tree and don't have
34 @@ -125,6 +128,25 @@ static void ocfs2_dinode_update_clusters(struct inode *inode,
35 spin_unlock(&OCFS2_I(inode)->ip_lock);
38 +static int ocfs2_dinode_insert_check(struct inode *inode,
39 + struct ocfs2_extent_tree *et,
40 + struct ocfs2_extent_rec *rec)
42 + struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
44 + BUG_ON(OCFS2_I(inode)->ip_dyn_features & OCFS2_INLINE_DATA_FL);
45 + mlog_bug_on_msg(!ocfs2_sparse_alloc(osb) &&
46 + (OCFS2_I(inode)->ip_clusters != rec->e_cpos),
47 + "Device %s, asking for sparse allocation: inode %llu, "
48 + "cpos %u, clusters %u\n",
50 + (unsigned long long)OCFS2_I(inode)->ip_blkno,
52 + OCFS2_I(inode)->ip_clusters);
57 static int ocfs2_dinode_sanity_check(struct inode *inode,
58 struct ocfs2_extent_tree *et)
60 @@ -148,6 +170,7 @@ static struct ocfs2_extent_tree_operations ocfs2_dinode_et_ops = {
61 .eo_set_last_eb_blk = ocfs2_dinode_set_last_eb_blk,
62 .eo_get_last_eb_blk = ocfs2_dinode_get_last_eb_blk,
63 .eo_update_clusters = ocfs2_dinode_update_clusters,
64 + .eo_insert_check = ocfs2_dinode_insert_check,
65 .eo_sanity_check = ocfs2_dinode_sanity_check,
66 .eo_fill_root_el = ocfs2_dinode_fill_root_el,
68 @@ -186,17 +209,10 @@ static void ocfs2_xattr_value_update_clusters(struct inode *inode,
69 le32_add_cpu(&xv->xr_clusters, clusters);
72 -static int ocfs2_xattr_value_sanity_check(struct inode *inode,
73 - struct ocfs2_extent_tree *et)
78 static struct ocfs2_extent_tree_operations ocfs2_xattr_value_et_ops = {
79 .eo_set_last_eb_blk = ocfs2_xattr_value_set_last_eb_blk,
80 .eo_get_last_eb_blk = ocfs2_xattr_value_get_last_eb_blk,
81 .eo_update_clusters = ocfs2_xattr_value_update_clusters,
82 - .eo_sanity_check = ocfs2_xattr_value_sanity_check,
83 .eo_fill_root_el = ocfs2_xattr_value_fill_root_el,
86 @@ -241,17 +257,10 @@ static void ocfs2_xattr_tree_update_clusters(struct inode *inode,
87 le32_add_cpu(&xb->xb_attrs.xb_root.xt_clusters, clusters);
90 -static int ocfs2_xattr_tree_sanity_check(struct inode *inode,
91 - struct ocfs2_extent_tree *et)
96 static struct ocfs2_extent_tree_operations ocfs2_xattr_tree_et_ops = {
97 .eo_set_last_eb_blk = ocfs2_xattr_tree_set_last_eb_blk,
98 .eo_get_last_eb_blk = ocfs2_xattr_tree_get_last_eb_blk,
99 .eo_update_clusters = ocfs2_xattr_tree_update_clusters,
100 - .eo_sanity_check = ocfs2_xattr_tree_sanity_check,
101 .eo_fill_root_el = ocfs2_xattr_tree_fill_root_el,
102 .eo_fill_max_leaf_clusters = ocfs2_xattr_tree_fill_max_leaf_clusters,
104 @@ -344,10 +353,25 @@ static inline void ocfs2_et_update_clusters(struct inode *inode,
105 et->et_ops->eo_update_clusters(inode, et, clusters);
108 +static inline int ocfs2_et_insert_check(struct inode *inode,
109 + struct ocfs2_extent_tree *et,
110 + struct ocfs2_extent_rec *rec)
114 + if (et->et_ops->eo_insert_check)
115 + ret = et->et_ops->eo_insert_check(inode, et, rec);
119 static inline int ocfs2_et_sanity_check(struct inode *inode,
120 struct ocfs2_extent_tree *et)
122 - return et->et_ops->eo_sanity_check(inode, et);
125 + if (et->et_ops->eo_sanity_check)
126 + ret = et->et_ops->eo_sanity_check(inode, et);
130 static void ocfs2_free_truncate_context(struct ocfs2_truncate_context *tc);
131 @@ -4408,24 +4432,19 @@ static int ocfs2_insert_extent(struct ocfs2_super *osb,
132 struct ocfs2_insert_type insert = {0, };
133 struct ocfs2_extent_rec rec;
135 - BUG_ON(OCFS2_I(inode)->ip_dyn_features & OCFS2_INLINE_DATA_FL);
137 mlog(0, "add %u clusters at position %u to inode %llu\n",
138 new_clusters, cpos, (unsigned long long)OCFS2_I(inode)->ip_blkno);
140 - mlog_bug_on_msg(!ocfs2_sparse_alloc(osb) &&
141 - (OCFS2_I(inode)->ip_clusters != cpos),
142 - "Device %s, asking for sparse allocation: inode %llu, "
143 - "cpos %u, clusters %u\n",
145 - (unsigned long long)OCFS2_I(inode)->ip_blkno, cpos,
146 - OCFS2_I(inode)->ip_clusters);
148 memset(&rec, 0, sizeof(rec));
149 rec.e_cpos = cpu_to_le32(cpos);
150 rec.e_blkno = cpu_to_le64(start_blk);
151 rec.e_leaf_clusters = cpu_to_le16(new_clusters);
153 + status = ocfs2_et_insert_check(inode, et, &rec);
155 + mlog_errno(status);
159 status = ocfs2_figure_insert_type(inode, et, &last_eb_bh, &rec,
160 &free_records, &insert);