qemu with hax to log dma reads & writes jcs.org/2018/11/12/vfio

scsi: turn "is this a SCSI device?" into a conditional hint

If the user does not have permissions to send ioctls to the device (due to
SELinux or cgroups, for example), the output can look like

qemu-kvm: -device scsi-block,drive=disk: cannot get SG_IO version number:
Operation not permitted. Is this a SCSI device?

but this is confusing because the ioctl was blocked _before_ the device
even received the SG_GET_VERSION_NUM ioctl. Therefore, for EPERM errors
the suggestion should be eliminated. To make that simpler, change the
code to use error_append_hint.

Reported-by: Ala Hino <ahino@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

+8 -6
+4 -3
hw/scsi/scsi-disk.c
··· 2607 2607 /* check we are using a driver managing SG_IO (version 3 and after) */ 2608 2608 rc = blk_ioctl(s->qdev.conf.blk, SG_GET_VERSION_NUM, &sg_version); 2609 2609 if (rc < 0) { 2610 - error_setg(errp, "cannot get SG_IO version number: %s. " 2611 - "Is this a SCSI device?", 2612 - strerror(-rc)); 2610 + error_setg_errno(errp, -rc, "cannot get SG_IO version number"); 2611 + if (rc != -EPERM) { 2612 + error_append_hint(errp, "Is this a SCSI device?\n"); 2613 + } 2613 2614 return; 2614 2615 } 2615 2616 if (sg_version < 30000) {
+4 -3
hw/scsi/scsi-generic.c
··· 500 500 /* check we are using a driver managing SG_IO (version 3 and after */ 501 501 rc = blk_ioctl(s->conf.blk, SG_GET_VERSION_NUM, &sg_version); 502 502 if (rc < 0) { 503 - error_setg(errp, "cannot get SG_IO version number: %s. " 504 - "Is this a SCSI device?", 505 - strerror(-rc)); 503 + error_setg_errno(errp, -rc, "cannot get SG_IO version number"); 504 + if (rc != -EPERM) { 505 + error_append_hint(errp, "Is this a SCSI device?\n"); 506 + } 506 507 return; 507 508 } 508 509 if (sg_version < 30000) {