Skip to content

Commit

Permalink
block: Give nonzero result to blk_get_max_transfer_length()
Browse files Browse the repository at this point in the history
Making all callers special-case 0 as unlimited is awkward,
and we DO have a hard maximum of BDRV_REQUEST_MAX_SECTORS given
our current block layer API limits.

In the case of scsi, this means that we now always advertise a
limit to the guest, even in cases where the underlying layers
previously use 0 for no inherent limit beyond the block layer.

Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Fam Zheng <famz@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
  • Loading branch information
ebblake authored and kevmw committed Jul 5, 2016
1 parent efaf478 commit 24ce9a2
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
7 changes: 4 additions & 3 deletions block/block-backend.c
Expand Up @@ -1303,15 +1303,16 @@ int blk_get_flags(BlockBackend *blk)
}
}

/* Returns the maximum transfer length, in sectors; guaranteed nonzero */
int blk_get_max_transfer_length(BlockBackend *blk)
{
BlockDriverState *bs = blk_bs(blk);
int max = 0;

if (bs) {
return bs->bl.max_transfer_length;
} else {
return 0;
max = bs->bl.max_transfer_length;
}
return MIN_NON_ZERO(max, BDRV_REQUEST_MAX_SECTORS);
}

int blk_get_max_iov(BlockBackend *blk)
Expand Down
3 changes: 1 addition & 2 deletions hw/block/virtio-blk.c
Expand Up @@ -384,7 +384,7 @@ static int multireq_compare(const void *a, const void *b)
void virtio_blk_submit_multireq(BlockBackend *blk, MultiReqBuffer *mrb)
{
int i = 0, start = 0, num_reqs = 0, niov = 0, nb_sectors = 0;
int max_xfer_len = 0;
int max_xfer_len;
int64_t sector_num = 0;

if (mrb->num_reqs == 1) {
Expand All @@ -394,7 +394,6 @@ void virtio_blk_submit_multireq(BlockBackend *blk, MultiReqBuffer *mrb)
}

max_xfer_len = blk_get_max_transfer_length(mrb->reqs[0]->dev->blk);
max_xfer_len = MIN_NON_ZERO(max_xfer_len, BDRV_REQUEST_MAX_SECTORS);

qsort(mrb->reqs, mrb->num_reqs, sizeof(*mrb->reqs),
&multireq_compare);
Expand Down
12 changes: 6 additions & 6 deletions hw/scsi/scsi-generic.c
Expand Up @@ -227,12 +227,12 @@ static void scsi_read_complete(void * opaque, int ret)
r->req.cmd.buf[2] == 0xb0) {
uint32_t max_xfer_len = blk_get_max_transfer_length(s->conf.blk) /
(s->blocksize / BDRV_SECTOR_SIZE);
if (max_xfer_len) {
stl_be_p(&r->buf[8], max_xfer_len);
/* Also take care of the opt xfer len. */
if (ldl_be_p(&r->buf[12]) > max_xfer_len) {
stl_be_p(&r->buf[12], max_xfer_len);
}

assert(max_xfer_len);
stl_be_p(&r->buf[8], max_xfer_len);
/* Also take care of the opt xfer len. */
if (ldl_be_p(&r->buf[12]) > max_xfer_len) {
stl_be_p(&r->buf[12], max_xfer_len);
}
}
scsi_req_data(&r->req, len);
Expand Down

0 comments on commit 24ce9a2

Please sign in to comment.