diff options
author | Christoph Hellwig <hch@lst.de> | 2011-07-13 07:43:48 -0400 |
---|---|---|
committer | Christoph Hellwig <hch@lst.de> | 2011-07-13 07:43:48 -0400 |
commit | a230a1df40864ef68ff6fbd09302f16d2a216ea5 (patch) | |
tree | c01375ab1d95beef1066304a3b70eb66f43f5aa0 /fs/xfs/xfs_dir2_leaf.c | |
parent | a00b7745c6e68ee89a123cd81e1dbc52fb55868e (diff) |
xfs: factor out xfs_dir2_leaf_find_stale
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Alex Elder <aelder@sgi.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Diffstat (limited to 'fs/xfs/xfs_dir2_leaf.c')
-rw-r--r-- | fs/xfs/xfs_dir2_leaf.c | 83 |
1 files changed, 37 insertions, 46 deletions
diff --git a/fs/xfs/xfs_dir2_leaf.c b/fs/xfs/xfs_dir2_leaf.c index 487036d3751b..ca2386d82cdf 100644 --- a/fs/xfs/xfs_dir2_leaf.c +++ b/fs/xfs/xfs_dir2_leaf.c | |||
@@ -148,6 +148,38 @@ xfs_dir2_block_to_leaf( | |||
148 | return 0; | 148 | return 0; |
149 | } | 149 | } |
150 | 150 | ||
151 | STATIC void | ||
152 | xfs_dir2_leaf_find_stale( | ||
153 | struct xfs_dir2_leaf *leaf, | ||
154 | int index, | ||
155 | int *lowstale, | ||
156 | int *highstale) | ||
157 | { | ||
158 | /* | ||
159 | * Find the first stale entry before our index, if any. | ||
160 | */ | ||
161 | for (*lowstale = index - 1; *lowstale >= 0; --*lowstale) { | ||
162 | if (leaf->ents[*lowstale].address == | ||
163 | cpu_to_be32(XFS_DIR2_NULL_DATAPTR)) | ||
164 | break; | ||
165 | } | ||
166 | |||
167 | /* | ||
168 | * Find the first stale entry at or after our index, if any. | ||
169 | * Stop if the result would require moving more entries than using | ||
170 | * lowstale. | ||
171 | */ | ||
172 | for (*highstale = index; | ||
173 | *highstale < be16_to_cpu(leaf->hdr.count); | ||
174 | ++*highstale) { | ||
175 | if (leaf->ents[*highstale].address == | ||
176 | cpu_to_be32(XFS_DIR2_NULL_DATAPTR)) | ||
177 | break; | ||
178 | if (*lowstale >= 0 && index - *lowstale <= *highstale - index) | ||
179 | break; | ||
180 | } | ||
181 | } | ||
182 | |||
151 | struct xfs_dir2_leaf_entry * | 183 | struct xfs_dir2_leaf_entry * |
152 | xfs_dir2_leaf_find_entry( | 184 | xfs_dir2_leaf_find_entry( |
153 | xfs_dir2_leaf_t *leaf, /* leaf structure */ | 185 | xfs_dir2_leaf_t *leaf, /* leaf structure */ |
@@ -190,32 +222,8 @@ xfs_dir2_leaf_find_entry( | |||
190 | * If we didn't compact before, we need to find the nearest stale | 222 | * If we didn't compact before, we need to find the nearest stale |
191 | * entries before and after our insertion point. | 223 | * entries before and after our insertion point. |
192 | */ | 224 | */ |
193 | if (compact == 0) { | 225 | if (compact == 0) |
194 | /* | 226 | xfs_dir2_leaf_find_stale(leaf, index, &lowstale, &highstale); |
195 | * Find the first stale entry before the insertion point, | ||
196 | * if any. | ||
197 | */ | ||
198 | for (lowstale = index - 1; | ||
199 | lowstale >= 0 && | ||
200 | leaf->ents[lowstale].address != | ||
201 | cpu_to_be32(XFS_DIR2_NULL_DATAPTR); | ||
202 | lowstale--) | ||
203 | continue; | ||
204 | |||
205 | /* | ||
206 | * Find the next stale entry at or after the insertion point, | ||
207 | * if any. Stop if we go so far that the lowstale entry | ||
208 | * would be better. | ||
209 | */ | ||
210 | for (highstale = index; | ||
211 | highstale < be16_to_cpu(leaf->hdr.count) && | ||
212 | leaf->ents[highstale].address != | ||
213 | cpu_to_be32(XFS_DIR2_NULL_DATAPTR) && | ||
214 | (lowstale < 0 || | ||
215 | index - lowstale - 1 >= highstale - index); | ||
216 | highstale++) | ||
217 | continue; | ||
218 | } | ||
219 | 227 | ||
220 | /* | 228 | /* |
221 | * If the low one is better, use it. | 229 | * If the low one is better, use it. |
@@ -689,26 +697,9 @@ xfs_dir2_leaf_compact_x1( | |||
689 | leaf = bp->data; | 697 | leaf = bp->data; |
690 | ASSERT(be16_to_cpu(leaf->hdr.stale) > 1); | 698 | ASSERT(be16_to_cpu(leaf->hdr.stale) > 1); |
691 | index = *indexp; | 699 | index = *indexp; |
692 | /* | 700 | |
693 | * Find the first stale entry before our index, if any. | 701 | xfs_dir2_leaf_find_stale(leaf, index, &lowstale, &highstale); |
694 | */ | 702 | |
695 | for (lowstale = index - 1; | ||
696 | lowstale >= 0 && | ||
697 | leaf->ents[lowstale].address != | ||
698 | cpu_to_be32(XFS_DIR2_NULL_DATAPTR); | ||
699 | lowstale--) | ||
700 | continue; | ||
701 | /* | ||
702 | * Find the first stale entry at or after our index, if any. | ||
703 | * Stop if the answer would be worse than lowstale. | ||
704 | */ | ||
705 | for (highstale = index; | ||
706 | highstale < be16_to_cpu(leaf->hdr.count) && | ||
707 | leaf->ents[highstale].address != | ||
708 | cpu_to_be32(XFS_DIR2_NULL_DATAPTR) && | ||
709 | (lowstale < 0 || index - lowstale > highstale - index); | ||
710 | highstale++) | ||
711 | continue; | ||
712 | /* | 703 | /* |
713 | * Pick the better of lowstale and highstale. | 704 | * Pick the better of lowstale and highstale. |
714 | */ | 705 | */ |