1. 13 7月, 2018 1 次提交
    • D
      scsi-disk: Block Device Characteristics emulation fix · 740842c9
      Daniel Henrique Barboza 提交于
      The current BDC VPD page (page 0xb1) is too short. This can be
      seen running sg_utils:
      
      $ sg_vpd --page=bdc /dev/sda
      Block device characteristics VPD page (SBC):
      Block device characteristics VPD page length too short=8
      
      By the SCSI spec, the expected size of the SBC page is 0x40.
      There is no telling how the guest will behave with a shorter
      message - it can ignore it, or worse, make (wrong)
      assumptions.
      
      This patch fixes the emulation by setting the size to 0x40.
      This is the output of the previous sg_vpd command after
      applying it:
      
      $ sg_vpd --page=bdc /dev/sda -v
          inquiry cdb: 12 01 b1 00 fc 00
      Block device characteristics VPD page (SBC):
         [PQual=0  Peripheral device type: disk]
        Medium rotation rate is not reported
        Product type: Not specified
        WABEREQ=0
        WACEREQ=0
        Nominal form factor not reported
        FUAB=0
        VBULS=0
      
      To improve readability, this patch also adds the VBULS value
      explictly and add comments on the existing fields we're
      setting.
      Signed-off-by: NDaniel Henrique Barboza <danielhb413@gmail.com>
      Acked-by: NPaolo Bonzini <pbonzini@redhat.com>
      Signed-off-by: NKevin Wolf <kwolf@redhat.com>
      740842c9
  2. 10 7月, 2018 1 次提交
  3. 02 7月, 2018 1 次提交
  4. 29 6月, 2018 3 次提交
    • D
      hw/scsi: add VPD Block Limits emulation · a71c775b
      Daniel Henrique Barboza 提交于
      The VPD Block Limits Inquiry page is optional, allowing SCSI devices
      to not implement it. This is the case for devices like the MegaRAID
      SAS 9361-8i and Microsemi PM8069.
      
      In case of SCSI passthrough, the response of this request is used by
      the QEMU SCSI layer to set the max_io_sectors that the guest
      device will support, based on the value of the max_sectors_kb that
      the device has set in the host at that time. Without this response,
      the guest kernel is free to assume any value of max_io_sectors
      for the SCSI device. If this value is greater than the value from
      the host, SCSI Sense errors will occur because the guest will send
      read/write requests that are larger than the underlying host device
      is configured to support. An example of this behavior can be seen
      in [1].
      
      A workaround is to set the max_sectors_kb host value back in the guest
      kernel (a process that can be automated using rc.local startup scripts
      and the like), but this has several drawbacks:
      
      - it can be troublesome if the guest has many passthrough devices that
      needs this tuning;
      
      - if a change in max_sectors_kb is made in the host side, manual change
      in the guests will also be required;
      
      - during an OS install it is difficult, and sometimes not possible, to
      go to a terminal and change the max_sectors_kb prior to the installation.
      This means that the disk can't be used during the install process. The
      easiest alternative here is to roll back to scsi-hd, install the guest
      and then go back to SCSI passthrough when the installation is done and
      max_sectors_kb can be set.
      
      An easier way would be to QEMU handle the absence of the Block Limits
      VPD device response, setting max_io_sectors accordingly and allowing
      the guest to use the device without the hassle.
      
      This patch adds emulation of the Block Limits VPD response for
      SCSI passthrough devices of type TYPE_DISK that doesn't support
      it. The following changes were made:
      
      - scsi_handle_inquiry_reply will now check the available VPD
      pages from the Inquiry EVPD reply. In case the device does not
      
      - a new function called scsi_generic_set_vpd_bl_emulation,
      that is called during device realize,  was created to set a
      new flag 'needs_vpd_bl_emulation' of the device. This function
      retrieves the Inquiry EVPD response of the device to check for
      VPD BL support.
      
      - scsi_handle_inquiry_reply will now check the available VPD
      pages from the Inquiry EVPD reply in case the device needs
      VPD BL emulation, adding the Block Limits page (0xb0) to
      the list. This will make the guest kernel aware of the
      support that we're now providing by emulation.
      
      - a new function scsi_emulate_block_limits creates the
      emulated Block Limits response. This function is called
      inside scsi_read_complete in case the device requires
      Block Limits VPD emulation and we detected a SCSI Sense
      error in the VPD Block Limits reply that was issued
      from the guest kernel to the device. This error is
      expected: we're reporting support from our side, but
      the device isn't aware of it.
      
      With this patch, the guest now queries the Block Limits
      page during the device configuration because it is being
      advertised in the Supported Pages response. It will either
      receive the Block Limits page from the hardware, if it supports
      it, or will receive an emulated response from QEMU. At any rate,
      the guest now has the information to set the max_sectors_kb
      parameter accordingly, sparing the user of SCSI sense errors
      that would happen without the emulated response and in the
      absence of Block Limits support from the hardware.
      
      [1] https://bugzilla.redhat.com/show_bug.cgi?id=1566195
      
      Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1566195Reported-by: NDac Nguyen <dacng@us.ibm.com>
      Signed-off-by: NDaniel Henrique Barboza <danielhb413@gmail.com>
      Message-Id: <20180627172432.11120-4-danielhb413@gmail.com>
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      a71c775b
    • D
      hw/scsi: centralize SG_IO calls into single function · a0c7e35b
      Daniel Henrique Barboza 提交于
      For the VPD Block Limits emulation with SCSI passthrough,
      we'll issue an Inquiry request with EVPD set to retrieve
      the available VPD pages of the device. This would be done in
      a way similar of what scsi_generic_read_device_identification
      does: create a SCSI command and a reply buffer, fill in the
      sg_io_hdr_t structure, call blk_ioctl, check if an error
      occurred, process the response.
      
      This same process is done in other 2 functions, get_device_type
      and get_stream_blocksize. They differ in the command/reply
      buffer and post-processing, everything else is almost a
      copy/paste.
      
      Instead of adding a forth copy/pasted-ish code when adding
      the passthrough VPD BL emulation, this patch extirpates
      this repetition of those 3 functions and put it into
      a new one called scsi_SG_IO_FROM_DEV. Any future code that
      wants to execute an SG_DXFER_FROM_DEV to the device can
      use it, avoiding filling sg_io_hdr_t again and et cetera.
      Signed-off-by: NDaniel Henrique Barboza <danielhb413@gmail.com>
      Message-Id: <20180627172432.11120-3-danielhb413@gmail.com>
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      a0c7e35b
    • D
      hw/scsi: cleanups before VPD BL emulation · 0a96ca24
      Daniel Henrique Barboza 提交于
      To add support for the emulation of Block Limits VPD page
      for passthrough devices, a few adjustments in the current code
      base is required to avoid repetition and improve clarity.
      
      In scsi-generic.c, detach the Inquiry handling from
      scsi_read_complete and put it into a new function called
      scsi_handle_inquiry_reply. This change aims to avoid
      cluttering of scsi_read_complete when we more logic in the
      Inquiry response handling is added in the next patches,
      centralizing the changes in the new function.
      
      In scsi-disk.c, take the build of all emulated VPD pages
      from scsi_disk_emulate_inquiry and make it available to
      other files into a non-static function called
      scsi_disk_emulate_vpd_page. Making it public will allow
      the future VPD BL emulation code for passthrough devices
      to use it from scsi-generic.c, avoiding copy/pasting this
      code solely for that purpose. It also has the advantage of
      providing emulation of all VPD pages in case we need to
      emulate other pages in other scenarios. As a bonus,
      scsi_disk_emulate_inquiry got tidier.
      Signed-off-by: NDaniel Henrique Barboza <danielhb413@gmail.com>
      Message-Id: <20180627172432.11120-2-danielhb413@gmail.com>
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      0a96ca24
  5. 15 6月, 2018 1 次提交
  6. 09 4月, 2018 3 次提交
    • D
      hw/scsi: support SCSI-2 passthrough without PI · 29e560f0
      Daniel Henrique Barboza 提交于
      QEMU SCSI code makes assumptions about how the PROTECT and BYTCHK
      works in the protocol, denying support for PI (Protection
      Information) in case the guest OS requests it. However, in SCSI versions 2
      and older, there is no PI concept in the protocol.
      
      This means that when dealing with such devices:
      
      - there is no PROTECT bit in byte 5 of the standard INQUIRY response. The
      whole byte is marked as "Reserved";
      
      - there is no RDPROTECT in byte 2 of READ. We have 'Logical Unit Number'
      in this field instead;
      
      - there is no VRPROTECT in byte 2 of VERIFY. We have 'Logical Unit Number'
      in this field instead. This also means that the BYTCHK bit in this case
      is not related to PI.
      
      Since QEMU does not consider these changes, a SCSI passthrough using
      a SCSI-2 device will not work. It will mistake these fields with
      PI information and return Illegal Request SCSI SENSE thinking
      that the driver is asking for PI support.
      
      This patch fixes it by adding a new attribute called 'scsi_version'
      that is read from the standard INQUIRY response of passthrough
      devices. This allows for a version verification before applying
      conditions related to PI that doesn't apply for older versions.
      Reported-by: NDac Nguyen <dacng@us.ibm.com>
      Signed-off-by: NDaniel Henrique Barboza <danielhb@linux.vnet.ibm.com>
      Message-Id: <20180327211451.14647-1-danielhb@linux.vnet.ibm.com>
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      29e560f0
    • P
      scsi-disk: allow customizing the SCSI version · 2343be0d
      Paolo Bonzini 提交于
      We would like to have different behavior for passthrough devices
      depending on the SCSI version they expose.  To prepare for that,
      allow the user of emulated devices to specify the desired SCSI
      level, and adjust the emulation according to the property value.
      The next patch will set the level for scsi-block and scsi-generic
      devices.
      
      Based on a patch by Daniel Henrique Barboza
      <danielhb@linux.vnet.ibm.com>.
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      2343be0d
    • F
      scsi-disk: Don't enlarge min_io_size to max_io_size · 37c51741
      Fam Zheng 提交于
      Some backends report big max_io_sectors. Making min_io_size the same
      value in this case will make it impossible for guest to align memory,
      therefore the disk may not be usable at all.
      
      Do not enlarge them when they are zero.
      Reported-by: NDavid Gibson <dgibson@redhat.com>
      Signed-off-by: NFam Zheng <famz@redhat.com>
      
      Message-Id: <20180327164141.19075-1-famz@redhat.com>
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      37c51741
  7. 26 3月, 2018 1 次提交
  8. 12 3月, 2018 2 次提交
    • P
      scsi: support NDOB (no data-out buffer) for WRITE SAME commands · 4397a018
      Paolo Bonzini 提交于
      A NDOB bit set to one specifies that the disk shall not transfer data
      from the data-out buffer and shall process the command as if the data-out
      buffer contained user data set to all zeroes.
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      4397a018
    • D
      scsi-disk.c: consider bl->max_transfer in INQUIRY emulation · d082d16a
      Daniel Henrique Barboza 提交于
      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: NDaniel Henrique Barboza <danielhb@linux.vnet.ibm.com>
      Reviewed-by: NFam Zheng <famz@redhat.com>
      Message-Id: <20180306154411.18462-1-danielhb@linux.vnet.ibm.com>
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      d082d16a
  9. 16 1月, 2018 1 次提交
    • S
      scsi-disk: release AioContext in unaligned WRITE SAME case · 24355b79
      Stefan Hajnoczi 提交于
      scsi_write_same_complete() can retry the write if the request was
      unaligned.  Make sure to release the AioContext when that code path is
      taken!
      
      This patch fixes a hang when QEMU terminates after an unaligned WRITE
      SAME request has been processed with dataplane.  The hang occurs because
      iothread_stop_all() cannot acquire the AioContext lock that was leaked
      by the IOThread in scsi_write_same_complete().
      
      Fixes: b9e413dd ("block: explicitly acquire aiocontext in aio callbacks that need it").
      Cc: Paolo Bonzini <pbonzini@redhat.com>
      Cc: qemu-stable@nongnu.org
      Reported-by: NCong Li <coli@redhat.com>
      Signed-off-by: NStefan Hajnoczi <stefanha@redhat.com>
      Message-Id: <20180104142502.15175-1-stefanha@redhat.com>
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      24355b79
  10. 21 12月, 2017 1 次提交
  11. 19 12月, 2017 1 次提交
    • M
      hw/block: Use errp directly rather than local_err · ceff3e1f
      Mao Zhongyi 提交于
      [Drop virtio_blk_data_plane_create() change that misinterprets return
      value when the virtio transport does not support dataplane.
      --Stefan]
      
      Cc: John Snow <jsnow@redhat.com>
      Cc: Kevin Wolf <kwolf@redhat.com>
      Cc: Max Reitz <mreitz@redhat.com>
      Cc: Keith Busch <keith.busch@intel.com>
      Cc: Stefan Hajnoczi <stefanha@redhat.com>
      Cc: "Michael S. Tsirkin" <mst@redhat.com>
      Cc: Paolo Bonzini <pbonzini@redhat.com>
      Cc: Gerd Hoffmann <kraxel@redhat.com>
      Cc: Markus Armbruster <armbru@redhat.com>
      Signed-off-by: NMao Zhongyi <maozy.fnst@cn.fujitsu.com>
      Reviewed-by: NStefan Hajnoczi <stefanha@redhat.com>
      Message-id: e77848d3735ba590f23ffbf8094379c646c33d79.1511317952.git.maozy.fnst@cn.fujitsu.com
      Signed-off-by: NStefan Hajnoczi <stefanha@redhat.com>
      ceff3e1f
  12. 18 10月, 2017 1 次提交
  13. 12 10月, 2017 1 次提交
    • D
      scsi-disk: support reporting of rotation rate · 070f8009
      Daniel P. Berrange 提交于
      The Linux kernel will query the SCSI "Block device characteristics"
      VPD to determine the rotations per minute of the disk. If this has
      the value 1, it is taken to be an SSD and so Linux sets the
      'rotational' flag to 0 for the I/O queue and will stop using that
      disk as a source of random entropy. Other operating systems may
      also take into account rotation rate when setting up default
      behaviour.
      
      Mgmt apps should be able to set the rotation rate for virtualized
      block devices, based on characteristics of the host storage in use,
      so that the guest OS gets sensible behaviour out of the box. This
      patch thus adds a 'rotation-rate' parameter for 'scsi-hd' and
      'scsi-block' device types. For the latter, this parameter will be
      ignored unless the host device has TYPE_DISK.
      Signed-off-by: NDaniel P. Berrange <berrange@redhat.com>
      Message-Id: <20171004114008.14849-2-berrange@redhat.com>
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      070f8009
  14. 19 9月, 2017 4 次提交
  15. 18 7月, 2017 1 次提交
  16. 01 3月, 2017 3 次提交
  17. 21 2月, 2017 1 次提交
  18. 25 1月, 2017 1 次提交
  19. 17 1月, 2017 1 次提交
  20. 22 12月, 2016 1 次提交
  21. 28 10月, 2016 1 次提交
  22. 14 9月, 2016 2 次提交
    • F
      scsi-disk: Cleaning up around tray open state · cd723b85
      Fam Zheng 提交于
      Even if tray is not open, it can be empty (blk_is_inserted() == false).
      Handle both cases correctly by replacing the s->tray_open checks with
      blk_is_available(), which is an AND of the two.
      
      Also simplify successive checks of them into blk_is_available(), in a
      couple cases.
      Signed-off-by: NFam Zheng <famz@redhat.com>
      Message-Id: <1473848224-24809-2-git-send-email-famz@redhat.com>
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      cd723b85
    • R
      scsi-disk: change disk serial length from 20 to 36 · 48b62063
      Rony Weng 提交于
      Openstack Cinder assigns volume a 36 characters uuid as serial.
      QEMU will shrinks the uuid to 20 characters, which does not match
      the original uuid.
      
      Note that there is no limit to the length of the serial number in
      the SCSI spec.  20 was copy-pasted from virtio-blk which in turn was
      copy-pasted from ATA; 36 is even more arbitrary.  However, bumping it
      up too much might cause issues (e.g. 252 seems to make sense because
      then the maximum amount of returned data is 256; but who knows there's
      no off-by-one somewhere for such a nicely rounded number).
      Signed-off-by: NRony Weng <ronyweng@synology.com>
      Message-Id: <1472457138-23386-1-git-send-email-ronyweng@synology.com>
      Cc: qemu-stable@nongnu.org
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      48b62063
  23. 06 9月, 2016 1 次提交
  24. 20 7月, 2016 1 次提交
  25. 13 7月, 2016 2 次提交
  26. 17 6月, 2016 1 次提交
  27. 07 6月, 2016 2 次提交