qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Fam Zheng <famz@redhat.com>
To: Daniel Henrique Barboza <danielhb@linux.vnet.ibm.com>
Cc: qemu-devel@nongnu.org, pbonzini@redhat.com
Subject: Re: [Qemu-devel] [PATCH 1/1] scsi-disk.c: consider bl->max_transfer in INQUIRY emulation
Date: Wed, 7 Mar 2018 09:33:32 +0800	[thread overview]
Message-ID: <20180307013332.GE13844@lemon.usersys.redhat.com> (raw)
In-Reply-To: <20180306154411.18462-1-danielhb@linux.vnet.ibm.com>

On Tue, 03/06 12:44, Daniel Henrique Barboza wrote:
> The calculation of the max_transfer atribute of BlockDriverState
> makes considerations such as max_segments and transfer_length via
> the BLKSECTGET ioctl (if available).
> 
> However, bl->max_transfer isn't considered when emulating the INQUIRY
> 'Block Limit' response to the scsi-hd devices. This leads to situations
> where the declared max_sectors from the INQUIRY response is inconsistent
> with the block limits, which isn't ideal. It can also be misleading to the
> user that sets /sys/block/<dev>/queue/max_sectors_kb to a certain
> value, then finds a different value in the guest OS for the same disk.
> 
> Following the same logic scsi_read_complete from scsi-generic.c does
> when patching the response of the Block Limits VPD back to the guest,
> change the max_io_sectors value of the emulated Block Limits VPD
> response by considering the blk_get_max_transfer of the related
> BlockDriverState. Use MIN_NOT_ZERO to be sure that the minimal
> value is chosen.
> 
> Given that we're changing max_io_sectors, consider that min_io_sectors
> and opt_io_sectors can't be greater than the new calculated value.
> 
> Signed-off-by: Daniel Henrique Barboza <danielhb@linux.vnet.ibm.com>
> ---
>  hw/scsi/scsi-disk.c | 15 +++++++++++++++
>  1 file changed, 15 insertions(+)
> 
> diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c
> index 49d2559d93..c65c1ce56d 100644
> --- a/hw/scsi/scsi-disk.c
> +++ b/hw/scsi/scsi-disk.c
> @@ -704,6 +704,21 @@ static int scsi_disk_emulate_inquiry(SCSIRequest *req, uint8_t *outbuf)
>                          page_code);
>                  return -1;
>              }
> +            if (s->qdev.type == TYPE_DISK) {
> +                int max_transfer_blk = blk_get_max_transfer(s->qdev.conf.blk);
> +                int max_io_sectors_blk =
> +                    max_transfer_blk / s->qdev.blocksize;
> +
> +                max_io_sectors =
> +                    MIN_NON_ZERO(max_io_sectors_blk, max_io_sectors);
> +
> +                /* min_io_size and opt_io_size can't be greater than
> +                 * max_io_sectors */
> +                min_io_size =
> +                    MIN_NON_ZERO(min_io_size, max_io_sectors);
> +                opt_io_size =
> +                    MIN_NON_ZERO(opt_io_size, max_io_sectors);
> +            }
>              /* required VPD size with unmap support */
>              buflen = 0x40;
>              memset(outbuf + 4, 0, buflen - 4);
> -- 
> 2.14.3
> 

Reviewed-by: Fam Zheng <famz@redhat.com>

      reply	other threads:[~2018-03-07  1:33 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-06 15:44 [Qemu-devel] [PATCH 1/1] scsi-disk.c: consider bl->max_transfer in INQUIRY emulation Daniel Henrique Barboza
2018-03-07  1:33 ` Fam Zheng [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180307013332.GE13844@lemon.usersys.redhat.com \
    --to=famz@redhat.com \
    --cc=danielhb@linux.vnet.ibm.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).