Skip to content

vioscsi misses last target and last LUN #1442

@hrosenfeld

Description

@hrosenfeld

I'm currently working on porting the virtio-scsi device from FreeBSD bhyve to illumos bhyve, improving it in the process by adding support for multiple targets. During my tests with a Windows VM using virtio-win-0.1.285, I noticed that the target with the highest target id isn't detected.

I presume this is caused by this check right at the beginning of VioScsiBuildIo():

    if ((SRB_PATH_ID(Srb) > (UCHAR)adaptExt->num_queues) || (TargetId >= adaptExt->scsi_config.max_target) ||
        (Lun >= adaptExt->scsi_config.max_lun) || adaptExt->bRemoved)
    {
        SRB_SET_SRB_STATUS(Srb, SRB_STATUS_NO_DEVICE);
        SRB_SET_DATA_TRANSFER_LENGTH(Srb, 0);
        StorPortNotification(RequestComplete, DeviceExtension, Srb);
        return FALSE;
    }

To quote from the virtio spec (https://docs.oasis-open.org/virtio/virtio/v1.2/csd01/virtio-v1.2-csd01.html#x1-3470004), section 5.6.4:

max_channel, max_target and max_lun
can be used by the driver as hints to constrain scanning the logical units on the host to channel/target/logical unit numbers that are less than or equal to the value of the fields. max_channel SHOULD be zero. max_target SHOULD be less than or equal to 255. max_lun SHOULD be less than or equal to 16383.

In accordance with the spec, the virtio-scsi device of bhyve sets max_target to the highest target id configured. On all released versions of FreeBSD, this means that max_target is set to 0 as only one target with id=0 is supported, leading to a situation where the virtio-win vioscsi driver would not detect any target at all. With the multi-target support I'm currently developing for virtio-scsi for bhyve, all but the last targets are detected for the same reason.

Obviously, the check against max_target should be >, not >=, as TargetID == max_target is perfectly valid. The same is true for the check against max_lun.

A similar bug was present in the vioscsi driver in illumos, which I've fixed recently: https://www.illumos.org/issues/17609

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions