Commit 7aeb7222 authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Dave Chinner

xfs: refactor xfs_buf_item_format_segment

Add two helpers to make the code more readable.
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarDave Chinner <dchinner@redhat.com>
Signed-off-by: default avatarDave Chinner <david@fromorbit.com>
parent 9597df6b
...@@ -182,6 +182,34 @@ xfs_buf_item_size( ...@@ -182,6 +182,34 @@ xfs_buf_item_size(
trace_xfs_buf_item_size(bip); trace_xfs_buf_item_size(bip);
} }
static inline struct xfs_log_iovec *
xfs_buf_item_copy_iovec(
struct xfs_log_iovec *vecp,
struct xfs_buf *bp,
uint offset,
int first_bit,
uint nbits)
{
offset += first_bit * XFS_BLF_CHUNK;
vecp->i_type = XLOG_REG_TYPE_BCHUNK;
vecp->i_addr = xfs_buf_offset(bp, offset);
vecp->i_len = nbits * XFS_BLF_CHUNK;
return vecp + 1;
}
static inline bool
xfs_buf_item_straddle(
struct xfs_buf *bp,
uint offset,
int next_bit,
int last_bit)
{
return xfs_buf_offset(bp, offset + (next_bit << XFS_BLF_SHIFT)) !=
(xfs_buf_offset(bp, offset + (last_bit << XFS_BLF_SHIFT)) +
XFS_BLF_CHUNK);
}
static struct xfs_log_iovec * static struct xfs_log_iovec *
xfs_buf_item_format_segment( xfs_buf_item_format_segment(
struct xfs_buf_log_item *bip, struct xfs_buf_log_item *bip,
...@@ -196,7 +224,6 @@ xfs_buf_item_format_segment( ...@@ -196,7 +224,6 @@ xfs_buf_item_format_segment(
int last_bit; int last_bit;
int next_bit; int next_bit;
uint nbits; uint nbits;
uint buffer_offset;
/* copy the flags across from the base format item */ /* copy the flags across from the base format item */
blfp->blf_flags = bip->__bli_format.blf_flags; blfp->blf_flags = bip->__bli_format.blf_flags;
...@@ -239,7 +266,6 @@ xfs_buf_item_format_segment( ...@@ -239,7 +266,6 @@ xfs_buf_item_format_segment(
/* /*
* Fill in an iovec for each set of contiguous chunks. * Fill in an iovec for each set of contiguous chunks.
*/ */
last_bit = first_bit; last_bit = first_bit;
nbits = 1; nbits = 1;
for (;;) { for (;;) {
...@@ -252,42 +278,22 @@ xfs_buf_item_format_segment( ...@@ -252,42 +278,22 @@ xfs_buf_item_format_segment(
next_bit = xfs_next_bit(blfp->blf_data_map, blfp->blf_map_size, next_bit = xfs_next_bit(blfp->blf_data_map, blfp->blf_map_size,
(uint)last_bit + 1); (uint)last_bit + 1);
/* /*
* If we run out of bits fill in the last iovec and get * If we run out of bits fill in the last iovec and get out of
* out of the loop. * the loop. Else if we start a new set of bits then fill in
* Else if we start a new set of bits then fill in the * the iovec for the series we were looking at and start
* iovec for the series we were looking at and start * counting the bits in the new one. Else we're still in the
* counting the bits in the new one. * same set of bits so just keep counting and scanning.
* Else we're still in the same set of bits so just
* keep counting and scanning.
*/ */
if (next_bit == -1) { if (next_bit == -1) {
buffer_offset = offset + first_bit * XFS_BLF_CHUNK; xfs_buf_item_copy_iovec(vecp, bp, offset,
vecp->i_addr = xfs_buf_offset(bp, buffer_offset); first_bit, nbits);
vecp->i_len = nbits * XFS_BLF_CHUNK;
vecp->i_type = XLOG_REG_TYPE_BCHUNK;
nvecs++; nvecs++;
break; break;
} else if (next_bit != last_bit + 1) { } else if (next_bit != last_bit + 1 ||
buffer_offset = offset + first_bit * XFS_BLF_CHUNK; xfs_buf_item_straddle(bp, offset, next_bit, last_bit)) {
vecp->i_addr = xfs_buf_offset(bp, buffer_offset); vecp = xfs_buf_item_copy_iovec(vecp, bp, offset,
vecp->i_len = nbits * XFS_BLF_CHUNK; first_bit, nbits);
vecp->i_type = XLOG_REG_TYPE_BCHUNK;
nvecs++; nvecs++;
vecp++;
first_bit = next_bit;
last_bit = next_bit;
nbits = 1;
} else if (xfs_buf_offset(bp, offset +
(next_bit << XFS_BLF_SHIFT)) !=
(xfs_buf_offset(bp, offset +
(last_bit << XFS_BLF_SHIFT)) +
XFS_BLF_CHUNK)) {
buffer_offset = offset + first_bit * XFS_BLF_CHUNK;
vecp->i_addr = xfs_buf_offset(bp, buffer_offset);
vecp->i_len = nbits * XFS_BLF_CHUNK;
vecp->i_type = XLOG_REG_TYPE_BCHUNK;
nvecs++;
vecp++;
first_bit = next_bit; first_bit = next_bit;
last_bit = next_bit; last_bit = next_bit;
nbits = 1; nbits = 1;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment