Message ID | 1465939839-30097-8-git-send-email-eblake@redhat.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
On Tue, 06/14 15:30, Eric Blake wrote: > 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> > > --- > v2: new patch > --- > block/block-backend.c | 7 ++++--- > hw/block/virtio-blk.c | 3 +-- > hw/scsi/scsi-generic.c | 12 ++++++------ > 3 files changed, 11 insertions(+), 11 deletions(-) > > diff --git a/block/block-backend.c b/block/block-backend.c > index 34500e6..1fb070b 100644 > --- a/block/block-backend.c > +++ b/block/block-backend.c > @@ -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) > diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c > index 284e646..1d2792e 100644 > --- a/hw/block/virtio-blk.c > +++ b/hw/block/virtio-blk.c > @@ -382,7 +382,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) { > @@ -392,7 +392,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); > diff --git a/hw/scsi/scsi-generic.c b/hw/scsi/scsi-generic.c > index 71372a8..db04a76 100644 > --- a/hw/scsi/scsi-generic.c > +++ b/hw/scsi/scsi-generic.c > @@ -226,12 +226,12 @@ static void scsi_read_complete(void * opaque, int ret) > r->req.cmd.buf[0] == INQUIRY && > r->req.cmd.buf[2] == 0xb0) { > uint32_t max_xfer_len = blk_get_max_transfer_length(s->conf.blk); > - 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); Paolo: should we take s->blocksize into account? I missed it when I wrote this piece of code. Fam > } > } > scsi_req_data(&r->req, len); > -- > 2.5.5 > >
On 16/06/2016 07:25, Fam Zheng wrote: >> > + 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); > Paolo: should we take s->blocksize into account? I missed it when I wrote this > piece of code. Hmm, the maximum and optimal transfer length is in logical blocks, so yes. There is one thing that isn't great: at least Linux reads the capacity before the block limits page, but we cannot know for sure that everyone does it. I think it's a good idea to send a READ CAPACITY(10) at startup, like we do in get_stream_blocksize. We only need it for the blocksize, not for the capacity, so it's not necessary to use READ CAPACITY(16). The snooping is still necessary for the max_lba (which is used by scsi_disk_dma_command), so we might as well keep the assignment to s->blocksize in there too. But let's add a best effort READ CAPACITY(10) at startup. Paolo
diff --git a/block/block-backend.c b/block/block-backend.c index 34500e6..1fb070b 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -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) diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c index 284e646..1d2792e 100644 --- a/hw/block/virtio-blk.c +++ b/hw/block/virtio-blk.c @@ -382,7 +382,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) { @@ -392,7 +392,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); diff --git a/hw/scsi/scsi-generic.c b/hw/scsi/scsi-generic.c index 71372a8..db04a76 100644 --- a/hw/scsi/scsi-generic.c +++ b/hw/scsi/scsi-generic.c @@ -226,12 +226,12 @@ static void scsi_read_complete(void * opaque, int ret) r->req.cmd.buf[0] == INQUIRY && r->req.cmd.buf[2] == 0xb0) { uint32_t max_xfer_len = blk_get_max_transfer_length(s->conf.blk); - 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);
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> --- v2: new patch --- block/block-backend.c | 7 ++++--- hw/block/virtio-blk.c | 3 +-- hw/scsi/scsi-generic.c | 12 ++++++------ 3 files changed, 11 insertions(+), 11 deletions(-)