Skip to content

Commit

Permalink
block-backend: align max_transfer to request alignment
Browse files Browse the repository at this point in the history
Block device requests must be aligned to bs->bl.request_alignment.
It makes sense for drivers to align bs->bl.max_transfer the same
way; however when there is no specified limit, blk_get_max_transfer
just returns INT_MAX.  Since the contract of the function does not
specify that INT_MAX means "no maximum", just align the outcome
of the function (whether INT_MAX or bs->bl.max_transfer) before
returning it.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
  • Loading branch information
bonzini committed Jun 25, 2021
1 parent c979745 commit b99f7fa
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions block/block-backend.c
Expand Up @@ -1957,12 +1957,12 @@ uint32_t blk_get_request_alignment(BlockBackend *blk)
uint32_t blk_get_max_transfer(BlockBackend *blk)
{
BlockDriverState *bs = blk_bs(blk);
uint32_t max = 0;
uint32_t max = INT_MAX;

if (bs) {
max = bs->bl.max_transfer;
max = MIN_NON_ZERO(max, bs->bl.max_transfer);
}
return MIN_NON_ZERO(max, INT_MAX);
return ROUND_DOWN(max, blk_get_request_alignment(blk));
}

int blk_get_max_iov(BlockBackend *blk)
Expand Down

0 comments on commit b99f7fa

Please sign in to comment.