From 7a7872d37313a93576a3ec35c321d47f76b093ca Mon Sep 17 00:00:00 2001 From: Fam Zheng Date: Fri, 8 Jul 2016 05:20:17 +0200 Subject: [PATCH 06/11] scsi-generic: Merge block max xfer len in INQUIRY response RH-Author: Fam Zheng Message-id: <1467955219-6507-2-git-send-email-famz@redhat.com> Patchwork-id: 71068 O-Subject: [RHEV-7.3 qemu-kvm-rhev PATCH v2 1/3] scsi-generic: Merge block max xfer len in INQUIRY response Bugzilla: 1353816 RH-Acked-by: John Snow RH-Acked-by: Paolo Bonzini RH-Acked-by: Stefan Hajnoczi The rationale is similar to the above mode sense response interception: this is practically the only channel to communicate restraints from elsewhere such as host and block driver. The scsi bus we attach onto can have a larger max xfer len than what is accepted by the host file system (guarding between the host scsi LUN and QEMU), in which case the SG_IO we generate would get -EINVAL. Signed-off-by: Fam Zheng Message-Id: <1464243305-10661-3-git-send-email-famz@redhat.com> Signed-off-by: Paolo Bonzini (cherry picked from commit 063143d5b1fde0fdcbae30bc7d6d14e76fa607d2) Signed-off-by: Fam Zheng Signed-off-by: Miroslav Rezanina --- hw/scsi/scsi-generic.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/hw/scsi/scsi-generic.c b/hw/scsi/scsi-generic.c index 7459465..71372a8 100644 --- a/hw/scsi/scsi-generic.c +++ b/hw/scsi/scsi-generic.c @@ -222,6 +222,18 @@ static void scsi_read_complete(void * opaque, int ret) r->buf[3] |= 0x80; } } + if (s->type == TYPE_DISK && + 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); + } + } + } scsi_req_data(&r->req, len); scsi_req_unref(&r->req); } -- 1.8.3.1