Skip to content

Commit 25d1d50

Browse files
dgibsonmartinkpetersen
authored andcommitted
scsi: virtio_scsi: Always try to read VPD pages
Passed through SCSI targets may have transfer limits which come from the host SCSI controller or something on the host side other than the target itself. To make this work properly, the hypervisor can adjust the target's VPD information to advertise these limits. But for that to work, the guest has to look at the VPD pages, which we won't do by default if it is an SPC-2 device, even if it does actually support it. This adds a workaround to address this, forcing devices attached to a virtio-scsi controller to always check the VPD pages. This is modelled on a similar workaround for the storvsc (Hyper-V) SCSI controller, although that exists for slightly different reasons. A specific case which causes this is a volume from IBM's IPR RAID controller (which presents as an SPC-2 device, although it does support VPD) passed through with qemu's 'scsi-block' device. [mkp: fixed typo] Signed-off-by: David Gibson <david@gibson.dropbear.id.au> Acked-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
1 parent ea98ab3 commit 25d1d50

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

drivers/scsi/virtio_scsi.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <scsi/scsi_device.h>
3030
#include <scsi/scsi_cmnd.h>
3131
#include <scsi/scsi_tcq.h>
32+
#include <scsi/scsi_devinfo.h>
3233
#include <linux/seqlock.h>
3334
#include <linux/blk-mq-virtio.h>
3435

@@ -705,6 +706,28 @@ static int virtscsi_device_reset(struct scsi_cmnd *sc)
705706
return virtscsi_tmf(vscsi, cmd);
706707
}
707708

709+
static int virtscsi_device_alloc(struct scsi_device *sdevice)
710+
{
711+
/*
712+
* Passed through SCSI targets (e.g. with qemu's 'scsi-block')
713+
* may have transfer limits which come from the host SCSI
714+
* controller or something on the host side other than the
715+
* target itself.
716+
*
717+
* To make this work properly, the hypervisor can adjust the
718+
* target's VPD information to advertise these limits. But
719+
* for that to work, the guest has to look at the VPD pages,
720+
* which we won't do by default if it is an SPC-2 device, even
721+
* if it does actually support it.
722+
*
723+
* So, set the blist to always try to read the VPD pages.
724+
*/
725+
sdevice->sdev_bflags = BLIST_TRY_VPD_PAGES;
726+
727+
return 0;
728+
}
729+
730+
708731
/**
709732
* virtscsi_change_queue_depth() - Change a virtscsi target's queue depth
710733
* @sdev: Virtscsi target whose queue depth to change
@@ -783,6 +806,7 @@ static struct scsi_host_template virtscsi_host_template_single = {
783806
.change_queue_depth = virtscsi_change_queue_depth,
784807
.eh_abort_handler = virtscsi_abort,
785808
.eh_device_reset_handler = virtscsi_device_reset,
809+
.slave_alloc = virtscsi_device_alloc,
786810

787811
.can_queue = 1024,
788812
.dma_boundary = UINT_MAX,

0 commit comments

Comments
 (0)