1 From: Joel Becker <joel.becker@oracle.com>
2 Date: Fri, 24 Oct 2008 18:47:33 -0700
3 Subject: ocfs2: Wrap journal_access/journal_dirty for xattr buckets.
6 A common action is to call ocfs2_journal_access() and
7 ocfs2_journal_dirty() on the buffer heads of an xattr bucket. Let's
10 While we're there, let's drop the places that try to be smart by writing
11 only the first and last blocks of a bucket. A bucket is contiguous, so
12 writing the whole thing is actually more efficient.
14 Signed-off-by: Joel Becker <joel.becker@oracle.com>
15 Signed-off-by: Mark Fasheh <mfasheh@suse.com>
17 fs/ocfs2/xattr.c | 140 +++++++++++++++++++++++++-----------------------------
18 1 files changed, 64 insertions(+), 76 deletions(-)
20 diff --git a/fs/ocfs2/xattr.c b/fs/ocfs2/xattr.c
21 index fa13fa4..99aefe4 100644
22 --- a/fs/ocfs2/xattr.c
23 +++ b/fs/ocfs2/xattr.c
24 @@ -210,6 +210,37 @@ static int ocfs2_read_xattr_bucket(struct inode *inode,
28 +static int ocfs2_xattr_bucket_journal_access(handle_t *handle,
29 + struct inode *inode,
30 + struct ocfs2_xattr_bucket *bucket,
34 + int blks = ocfs2_blocks_per_xattr_bucket(inode->i_sb);
36 + for (i = 0; i < blks; i++) {
37 + rc = ocfs2_journal_access(handle, inode,
38 + bucket->bu_bhs[i], type);
48 +static void ocfs2_xattr_bucket_journal_dirty(handle_t *handle,
49 + struct inode *inode,
50 + struct ocfs2_xattr_bucket *bucket)
52 + int i, blks = ocfs2_blocks_per_xattr_bucket(inode->i_sb);
54 + for (i = 0; i < blks; i++)
55 + ocfs2_journal_dirty(handle, bucket->bu_bhs[i]);
59 static inline const char *ocfs2_xattr_prefix(int name_index)
61 struct xattr_handler *handler = NULL;
62 @@ -3218,8 +3249,8 @@ static int ocfs2_divide_xattr_bucket(struct inode *inode,
66 - ret = ocfs2_journal_access(handle, inode, s_bucket.bu_bhs[0],
67 - OCFS2_JOURNAL_ACCESS_WRITE);
68 + ret = ocfs2_xattr_bucket_journal_access(handle, inode, &s_bucket,
69 + OCFS2_JOURNAL_ACCESS_WRITE);
73 @@ -3235,15 +3266,13 @@ static int ocfs2_divide_xattr_bucket(struct inode *inode,
77 - for (i = 0; i < blk_per_bucket; i++) {
78 - ret = ocfs2_journal_access(handle, inode, t_bucket.bu_bhs[i],
80 - OCFS2_JOURNAL_ACCESS_CREATE :
81 - OCFS2_JOURNAL_ACCESS_WRITE);
86 + ret = ocfs2_xattr_bucket_journal_access(handle, inode, &t_bucket,
88 + OCFS2_JOURNAL_ACCESS_CREATE :
89 + OCFS2_JOURNAL_ACCESS_WRITE);
95 xh = bucket_xh(&s_bucket);
96 @@ -3339,11 +3368,7 @@ set_num_buckets:
98 xh->xh_num_buckets = 0;
100 - for (i = 0; i < blk_per_bucket; i++) {
101 - ocfs2_journal_dirty(handle, t_bucket.bu_bhs[i]);
105 + ocfs2_xattr_bucket_journal_dirty(handle, inode, &t_bucket);
107 /* store the first_hash of the new bucket. */
109 @@ -3364,9 +3389,7 @@ set_num_buckets:
110 xh->xh_free_start = cpu_to_le16(name_offset);
111 xh->xh_name_value_len = cpu_to_le16(name_value_len);
113 - ocfs2_journal_dirty(handle, s_bucket.bu_bhs[0]);
116 + ocfs2_xattr_bucket_journal_dirty(handle, inode, &s_bucket);
119 ocfs2_xattr_bucket_relse(inode, &s_bucket);
120 @@ -3413,20 +3436,18 @@ static int ocfs2_cp_xattr_bucket(struct inode *inode,
124 - for (i = 0; i < blk_per_bucket; i++) {
125 - ret = ocfs2_journal_access(handle, inode, t_bucket.bu_bhs[i],
127 - OCFS2_JOURNAL_ACCESS_CREATE :
128 - OCFS2_JOURNAL_ACCESS_WRITE);
132 + ret = ocfs2_xattr_bucket_journal_access(handle, inode, &t_bucket,
134 + OCFS2_JOURNAL_ACCESS_CREATE :
135 + OCFS2_JOURNAL_ACCESS_WRITE);
139 for (i = 0; i < blk_per_bucket; i++) {
140 memcpy(bucket_block(&t_bucket, i), bucket_block(&s_bucket, i),
142 - ocfs2_journal_dirty(handle, t_bucket.bu_bhs[i]);
144 + ocfs2_xattr_bucket_journal_dirty(handle, inode, &t_bucket);
147 ocfs2_xattr_bucket_relse(inode, &s_bucket);
148 @@ -3799,9 +3820,9 @@ static int ocfs2_extend_xattr_bucket(struct inode *inode,
151 * We will touch all the buckets after the start_bh(include it).
152 - * Add one more bucket and modify the first_bh.
153 + * Then we add one more bucket.
155 - credits = end_blk - start_blk + 2 * blk_per_bucket + 1;
156 + credits = end_blk - start_blk + 3 * blk_per_bucket + 1;
157 handle = ocfs2_start_trans(osb, credits);
158 if (IS_ERR(handle)) {
159 ret = PTR_ERR(handle);
160 @@ -4077,33 +4098,6 @@ set_new_name_value:
164 -static int ocfs2_xattr_bucket_handle_journal(struct inode *inode,
166 - struct ocfs2_xattr_search *xs,
167 - struct buffer_head **bhs,
170 - int ret = 0, off, block_off;
171 - struct ocfs2_xattr_entry *xe = xs->here;
174 - * First calculate all the blocks we should journal_access
175 - * and journal_dirty. The first block should always be touched.
177 - ret = ocfs2_journal_dirty(handle, bhs[0]);
181 - /* calc the data. */
182 - off = le16_to_cpu(xe->xe_name_offset);
183 - block_off = off >> inode->i_sb->s_blocksize_bits;
184 - ret = ocfs2_journal_dirty(handle, bhs[block_off]);
192 * Set the xattr entry in the specified bucket.
193 * The bucket is indicated by xs->bucket and it should have the enough
194 @@ -4115,7 +4109,7 @@ static int ocfs2_xattr_set_entry_in_bucket(struct inode *inode,
200 handle_t *handle = NULL;
201 u16 blk_per_bucket = ocfs2_blocks_per_xattr_bucket(inode->i_sb);
202 struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
203 @@ -4143,22 +4137,16 @@ static int ocfs2_xattr_set_entry_in_bucket(struct inode *inode,
207 - for (i = 0; i < blk_per_bucket; i++) {
208 - ret = ocfs2_journal_access(handle, inode, xs->bucket.bu_bhs[i],
209 - OCFS2_JOURNAL_ACCESS_WRITE);
214 + ret = ocfs2_xattr_bucket_journal_access(handle, inode, &xs->bucket,
215 + OCFS2_JOURNAL_ACCESS_WRITE);
221 ocfs2_xattr_set_entry_normal(inode, xi, xs, name_hash, local);
222 + ocfs2_xattr_bucket_journal_dirty(handle, inode, &xs->bucket);
224 - /*Only dirty the blocks we have touched in set xattr. */
225 - ret = ocfs2_xattr_bucket_handle_journal(inode, handle, xs,
226 - xs->bucket.bu_bhs, blk_per_bucket);
230 ocfs2_commit_trans(osb, handle);
232 @@ -4398,15 +4386,16 @@ static void ocfs2_xattr_bucket_remove_xs(struct inode *inode,
233 le16_to_cpu(xh->xh_count) - 1];
236 - handle = ocfs2_start_trans((OCFS2_SB(inode->i_sb)), 1);
237 + handle = ocfs2_start_trans((OCFS2_SB(inode->i_sb)),
238 + ocfs2_blocks_per_xattr_bucket(inode->i_sb));
239 if (IS_ERR(handle)) {
240 ret = PTR_ERR(handle);
245 - ret = ocfs2_journal_access(handle, inode, xs->bucket.bu_bhs[0],
246 - OCFS2_JOURNAL_ACCESS_WRITE);
247 + ret = ocfs2_xattr_bucket_journal_access(handle, inode, &xs->bucket,
248 + OCFS2_JOURNAL_ACCESS_WRITE);
252 @@ -4418,9 +4407,8 @@ static void ocfs2_xattr_bucket_remove_xs(struct inode *inode,
253 memset(last, 0, sizeof(struct ocfs2_xattr_entry));
254 le16_add_cpu(&xh->xh_count, -1);
256 - ret = ocfs2_journal_dirty(handle, xs->bucket.bu_bhs[0]);
259 + ocfs2_xattr_bucket_journal_dirty(handle, inode, &xs->bucket);
262 ocfs2_commit_trans(OCFS2_SB(inode->i_sb), handle);