aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristoph Hellwig <hch@infradead.org>2013-12-12 19:00:43 -0500
committerDave Chinner <david@fromorbit.com>2013-12-12 19:00:43 -0500
commit7aeb72224120e0c49ba4c93d75f8f0d6a87f6afd (patch)
treefc21d89b9ec2470b05529d4d9f7dc66f1f1af0fa
parent9597df6b26a1988a5a04762711149f98ec6ab388 (diff)
xfs: refactor xfs_buf_item_format_segment
Add two helpers to make the code more readable. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Dave Chinner <dchinner@redhat.com> Signed-off-by: Dave Chinner <david@fromorbit.com>
-rw-r--r--fs/xfs/xfs_buf_item.c72
1 files changed, 39 insertions, 33 deletions
diff --git a/fs/xfs/xfs_buf_item.c b/fs/xfs/xfs_buf_item.c
index a64f67ba25d3..a30c1fb1bec6 100644
--- a/fs/xfs/xfs_buf_item.c
+++ b/fs/xfs/xfs_buf_item.c
@@ -182,6 +182,34 @@ xfs_buf_item_size(
182 trace_xfs_buf_item_size(bip); 182 trace_xfs_buf_item_size(bip);
183} 183}
184 184
185static inline struct xfs_log_iovec *
186xfs_buf_item_copy_iovec(
187 struct xfs_log_iovec *vecp,
188 struct xfs_buf *bp,
189 uint offset,
190 int first_bit,
191 uint nbits)
192{
193 offset += first_bit * XFS_BLF_CHUNK;
194
195 vecp->i_type = XLOG_REG_TYPE_BCHUNK;
196 vecp->i_addr = xfs_buf_offset(bp, offset);
197 vecp->i_len = nbits * XFS_BLF_CHUNK;
198 return vecp + 1;
199}
200
201static inline bool
202xfs_buf_item_straddle(
203 struct xfs_buf *bp,
204 uint offset,
205 int next_bit,
206 int last_bit)
207{
208 return xfs_buf_offset(bp, offset + (next_bit << XFS_BLF_SHIFT)) !=
209 (xfs_buf_offset(bp, offset + (last_bit << XFS_BLF_SHIFT)) +
210 XFS_BLF_CHUNK);
211}
212
185static struct xfs_log_iovec * 213static struct xfs_log_iovec *
186xfs_buf_item_format_segment( 214xfs_buf_item_format_segment(
187 struct xfs_buf_log_item *bip, 215 struct xfs_buf_log_item *bip,
@@ -196,7 +224,6 @@ xfs_buf_item_format_segment(
196 int last_bit; 224 int last_bit;
197 int next_bit; 225 int next_bit;
198 uint nbits; 226 uint nbits;
199 uint buffer_offset;
200 227
201 /* copy the flags across from the base format item */ 228 /* copy the flags across from the base format item */
202 blfp->blf_flags = bip->__bli_format.blf_flags; 229 blfp->blf_flags = bip->__bli_format.blf_flags;
@@ -239,7 +266,6 @@ xfs_buf_item_format_segment(
239 /* 266 /*
240 * Fill in an iovec for each set of contiguous chunks. 267 * Fill in an iovec for each set of contiguous chunks.
241 */ 268 */
242
243 last_bit = first_bit; 269 last_bit = first_bit;
244 nbits = 1; 270 nbits = 1;
245 for (;;) { 271 for (;;) {
@@ -252,42 +278,22 @@ xfs_buf_item_format_segment(
252 next_bit = xfs_next_bit(blfp->blf_data_map, blfp->blf_map_size, 278 next_bit = xfs_next_bit(blfp->blf_data_map, blfp->blf_map_size,
253 (uint)last_bit + 1); 279 (uint)last_bit + 1);
254 /* 280 /*
255 * If we run out of bits fill in the last iovec and get 281 * If we run out of bits fill in the last iovec and get out of
256 * out of the loop. 282 * the loop. Else if we start a new set of bits then fill in
257 * Else if we start a new set of bits then fill in the 283 * the iovec for the series we were looking at and start
258 * iovec for the series we were looking at and start 284 * counting the bits in the new one. Else we're still in the
259 * counting the bits in the new one. 285 * same set of bits so just keep counting and scanning.
260 * Else we're still in the same set of bits so just
261 * keep counting and scanning.
262 */ 286 */
263 if (next_bit == -1) { 287 if (next_bit == -1) {
264 buffer_offset = offset + first_bit * XFS_BLF_CHUNK; 288 xfs_buf_item_copy_iovec(vecp, bp, offset,
265 vecp->i_addr = xfs_buf_offset(bp, buffer_offset); 289 first_bit, nbits);
266 vecp->i_len = nbits * XFS_BLF_CHUNK;
267 vecp->i_type = XLOG_REG_TYPE_BCHUNK;
268 nvecs++; 290 nvecs++;
269 break; 291 break;
270 } else if (next_bit != last_bit + 1) { 292 } else if (next_bit != last_bit + 1 ||
271 buffer_offset = offset + first_bit * XFS_BLF_CHUNK; 293 xfs_buf_item_straddle(bp, offset, next_bit, last_bit)) {
272 vecp->i_addr = xfs_buf_offset(bp, buffer_offset); 294 vecp = xfs_buf_item_copy_iovec(vecp, bp, offset,
273 vecp->i_len = nbits * XFS_BLF_CHUNK; 295 first_bit, nbits);
274 vecp->i_type = XLOG_REG_TYPE_BCHUNK;
275 nvecs++;
276 vecp++;
277 first_bit = next_bit;
278 last_bit = next_bit;
279 nbits = 1;
280 } else if (xfs_buf_offset(bp, offset +
281 (next_bit << XFS_BLF_SHIFT)) !=
282 (xfs_buf_offset(bp, offset +
283 (last_bit << XFS_BLF_SHIFT)) +
284 XFS_BLF_CHUNK)) {
285 buffer_offset = offset + first_bit * XFS_BLF_CHUNK;
286 vecp->i_addr = xfs_buf_offset(bp, buffer_offset);
287 vecp->i_len = nbits * XFS_BLF_CHUNK;
288 vecp->i_type = XLOG_REG_TYPE_BCHUNK;
289 nvecs++; 296 nvecs++;
290 vecp++;
291 first_bit = next_bit; 297 first_bit = next_bit;
292 last_bit = next_bit; 298 last_bit = next_bit;
293 nbits = 1; 299 nbits = 1;