1 From: Joel Becker <joel.becker@oracle.com>
2 Date: Mon, 27 Oct 2008 15:01:54 -0700
3 Subject: ocfs2: Use buckets in ocfs2_xattr_bucket_find().
6 Change the ocfs2_xattr_bucket_find() function to use ocfs2_xattr_bucket
7 as its abstraction. This makes for more efficient reads, as buckets are
8 linear blocks, and also has improved caching characteristics. It also
11 Signed-off-by: Joel Becker <joel.becker@oracle.com>
12 Signed-off-by: Mark Fasheh <mfasheh@suse.com>
14 fs/ocfs2/xattr.c | 89 +++++++++++++++++++-----------------------------------
15 1 files changed, 31 insertions(+), 58 deletions(-)
17 diff --git a/fs/ocfs2/xattr.c b/fs/ocfs2/xattr.c
18 index 766494e..46986c6 100644
19 --- a/fs/ocfs2/xattr.c
20 +++ b/fs/ocfs2/xattr.c
21 @@ -2248,7 +2248,7 @@ typedef int (xattr_bucket_func)(struct inode *inode,
24 static int ocfs2_find_xe_in_bucket(struct inode *inode,
25 - struct buffer_head *header_bh,
26 + struct ocfs2_xattr_bucket *bucket,
30 @@ -2256,11 +2256,9 @@ static int ocfs2_find_xe_in_bucket(struct inode *inode,
33 int i, ret = 0, cmp = 1, block_off, new_offset;
34 - struct ocfs2_xattr_header *xh =
35 - (struct ocfs2_xattr_header *)header_bh->b_data;
36 + struct ocfs2_xattr_header *xh = bucket_xh(bucket);
37 size_t name_len = strlen(name);
38 struct ocfs2_xattr_entry *xe = NULL;
39 - struct buffer_head *name_bh = NULL;
43 @@ -2291,19 +2289,8 @@ static int ocfs2_find_xe_in_bucket(struct inode *inode,
47 - ret = ocfs2_read_block(inode, header_bh->b_blocknr + block_off,
53 - xe_name = name_bh->b_data + new_offset;
55 - cmp = memcmp(name, xe_name, name_len);
60 + xe_name = bucket_block(bucket, block_off) + new_offset;
61 + if (!memcmp(name, xe_name, name_len)) {
65 @@ -2333,39 +2320,42 @@ static int ocfs2_xattr_bucket_find(struct inode *inode,
66 struct ocfs2_xattr_search *xs)
69 - struct buffer_head *bh = NULL;
70 - struct buffer_head *lower_bh = NULL;
71 struct ocfs2_xattr_header *xh = NULL;
72 struct ocfs2_xattr_entry *xe = NULL;
74 u16 blk_per_bucket = ocfs2_blocks_per_xattr_bucket(inode->i_sb);
75 int low_bucket = 0, bucket, high_bucket;
76 + struct ocfs2_xattr_bucket *search;
79 + u64 blkno, lower_blkno = 0;
81 - ret = ocfs2_read_block(inode, p_blkno, &bh);
82 + search = ocfs2_xattr_bucket_new(inode);
89 + ret = ocfs2_read_xattr_bucket(search, p_blkno);
95 - xh = (struct ocfs2_xattr_header *)bh->b_data;
96 + xh = bucket_xh(search);
97 high_bucket = le16_to_cpu(xh->xh_num_buckets) - 1;
99 while (low_bucket <= high_bucket) {
102 - bucket = (low_bucket + high_bucket) / 2;
103 + ocfs2_xattr_bucket_relse(search);
105 + bucket = (low_bucket + high_bucket) / 2;
106 blkno = p_blkno + bucket * blk_per_bucket;
108 - ret = ocfs2_read_block(inode, blkno, &bh);
109 + ret = ocfs2_read_xattr_bucket(search, blkno);
115 - xh = (struct ocfs2_xattr_header *)bh->b_data;
116 + xh = bucket_xh(search);
117 xe = &xh->xh_entries[0];
118 if (name_hash < le32_to_cpu(xe->xe_name_hash)) {
119 high_bucket = bucket - 1;
120 @@ -2382,10 +2372,8 @@ static int ocfs2_xattr_bucket_find(struct inode *inode,
122 last_hash = le32_to_cpu(xe->xe_name_hash);
124 - /* record lower_bh which may be the insert place. */
128 + /* record lower_blkno which may be the insert place. */
129 + lower_blkno = blkno;
131 if (name_hash > le32_to_cpu(xe->xe_name_hash)) {
132 low_bucket = bucket + 1;
133 @@ -2393,7 +2381,7 @@ static int ocfs2_xattr_bucket_find(struct inode *inode,
136 /* the searched xattr should reside in this bucket if exists. */
137 - ret = ocfs2_find_xe_in_bucket(inode, lower_bh,
138 + ret = ocfs2_find_xe_in_bucket(inode, search,
139 name_index, name, name_hash,
142 @@ -2408,35 +2396,21 @@ static int ocfs2_xattr_bucket_find(struct inode *inode,
143 * When the xattr's hash value is in the gap of 2 buckets, we will
144 * always set it to the previous bucket.
148 - * We can't find any bucket whose first name_hash is less
149 - * than the find name_hash.
151 - BUG_ON(bh->b_blocknr != p_blkno);
155 + lower_blkno = p_blkno;
157 + /* This should be in cache - we just read it during the search */
158 + ret = ocfs2_read_xattr_bucket(xs->bucket, lower_blkno);
163 - xs->bucket->bu_bhs[0] = lower_bh;
166 xs->header = bucket_xh(xs->bucket);
167 xs->base = bucket_block(xs->bucket, 0);
168 xs->end = xs->base + inode->i_sb->s_blocksize;
172 - * If we have found the xattr enty, read all the blocks in
175 - ret = ocfs2_read_blocks(inode, bucket_blkno(xs->bucket) + 1,
176 - blk_per_bucket - 1, &xs->bucket->bu_bhs[1],
183 xs->here = &xs->header->xh_entries[index];
184 mlog(0, "find xattr %s in bucket %llu, entry = %u\n", name,
185 (unsigned long long)bucket_blkno(xs->bucket), index);
186 @@ -2444,8 +2418,7 @@ static int ocfs2_xattr_bucket_find(struct inode *inode,
192 + ocfs2_xattr_bucket_free(search);