scsi: turn "is this a SCSI device?" into a conditional hint
PATCH 1/1 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.
--- hw/scsi/scsi-disk.c | 7 ++++--- hw/scsi/scsi-generic.c | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-)
hw/scsi/scsi-disk.c +4 -3
@@ -2637,9 +2637,10 @@ static void scsi_block_realize(SCSIDevice *dev, Error **errp)/* check we are using a driver managing SG_IO (version 3 and after) */ rc =blk_ioctl (s->qdev.conf.blk,SG_GET_VERSION_NUM , &sg_version);if (rc <0 ) { -error_setg (errp,"cannot get SG_IO version number: %s. " -"Is this a SCSI device?" , -strerror (-rc)); +error_setg (errp,"cannot get SG_IO version number: %s" ,strerror (-rc)); +if (rc != -EPERM ) { +error_append_hint (errp,"Is this a SCSI device?" ); + }return ; }if (sg_version <30000 ) {
hw/scsi/scsi-generic.c +4 -3
@@ -500,9 +500,10 @@ static void scsi_generic_realize(SCSIDevice *s, Error **errp)/* check we are using a driver managing SG_IO (version 3 and after */ rc =blk_ioctl (s->conf.blk,SG_GET_VERSION_NUM , &sg_version);if (rc <0 ) { -error_setg (errp,"cannot get SG_IO version number: %s. " -"Is this a SCSI device?" , -strerror (-rc)); +error_setg (errp,"cannot get SG_IO version number: %s" ,strerror (-rc)); +if (rc != -EPERM ) { +error_append_hint (errp,"Is this a SCSI device?" ); + }return ; }if (sg_version <30000 ) {
Signature · 1 line
2.16.2
Quoted 23 lines · Paolo Bonzini
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_IOversion 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_NUMioctl. Therefore, for EPERM errors the suggestion should be eliminated. To make that simpler, change the code to useerror_append_hint.Reported-by Ala Hino <[email protected]>Signed-off-by Paolo Bonzini <[email protected]>--- hw/scsi/scsi-disk.c | 7 ++++--- hw/scsi/scsi-generic.c | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-)hw/scsi/scsi-disk.c +0
-0
hw/scsi/scsi-disk.c static void scsi_block_realize(SCSIDevice *dev, Error **errp) · line 2640
Quoted 7 lines
hw/scsi/scsi-disk.c +1
-3@@ -2637,9 +2637,10 @@ static void scsi_block_realize(SCSIDevice *dev, Error **errp)/* check we are using a driver managing SG_IO (version 3 and after) */ rc =blk_ioctl (s->qdev.conf.blk,SG_GET_VERSION_NUM , &sg_version);if (rc <0 ) { -error_setg (errp,"cannot get SG_IO version number: %s. " -"Is this a SCSI device?" , -strerror (-rc)); +error_setg (errp,"cannot get SG_IO version number: %s" ,strerror (-rc));
You could use:
error_setg_errno(errp, -rc, "cannot get SG_IO version number");
Thanks,
Laurent
Quoted 35 lines · Laurent Vivier
Quoted 23 lines · Paolo Bonzini
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_IOversion 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_NUMioctl. Therefore, for EPERM errors the suggestion should be eliminated. To make that simpler, change the code to useerror_append_hint.Reported-by Ala Hino <[email protected]>Signed-off-by Paolo Bonzini <[email protected]>--- hw/scsi/scsi-disk.c | 7 ++++--- hw/scsi/scsi-generic.c | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-)hw/scsi/scsi-disk.c +0
-0hw/scsi/scsi-disk.c static void scsi_block_realize(SCSIDevice *dev, Error **errp) · line 2640
Quoted 7 lines
hw/scsi/scsi-disk.c +1
-3@@ -2637,9 +2637,10 @@ static void scsi_block_realize(SCSIDevice *dev, Error **errp)/* check we are using a driver managing SG_IO (version 3 and after) */ rc =blk_ioctl (s->qdev.conf.blk,SG_GET_VERSION_NUM , &sg_version);if (rc <0 ) { -error_setg (errp,"cannot get SG_IO version number: %s. " -"Is this a SCSI device?" , -strerror (-rc)); +error_setg (errp,"cannot get SG_IO version number: %s" ,strerror (-rc));You could use:
Quoted 1 line
error_setg_errno(errp, -rc, "cannot get SG_IO version number");
Nice, thanks. Will do.
Paolo
Quoted 21 lines · Paolo Bonzini
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_IOversion 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_NUMioctl. Therefore, for EPERM errors the suggestion should be eliminated. To make that simpler, change the code to useerror_append_hint.Reported-by Ala Hino <[email protected]>Signed-off-by Paolo Bonzini <[email protected]>--- hw/scsi/scsi-disk.c | 7 ++++--- hw/scsi/scsi-generic.c | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-)+++
b/hw/scsi/scsi-disk.c
hw/scsi/scsi-disk.c static void scsi_block_realize(SCSIDevice *dev, Error **errp) · line 2642
Quoted 9 lines
hw/scsi/scsi-disk.c +3
-3@@ -2637,9 +2637,10 @@ static void scsi_block_realize(SCSIDevice *dev, Error **errp)/* check we are using a driver managing SG_IO (version 3 and after) */ rc =blk_ioctl (s->qdev.conf.blk,SG_GET_VERSION_NUM , &sg_version);if (rc <0 ) { -error_setg (errp,"cannot get SG_IO version number: %s. " -"Is this a SCSI device?" , -strerror (-rc)); +error_setg (errp,"cannot get SG_IO version number: %s" ,strerror (-rc)); +if (rc != -EPERM ) { +error_append_hint (errp,"Is this a SCSI device?" );
Missing the \n (error_append_hint does NOT automatically add one, because sometimes hints are pieced together but should still display in one line).
hw/scsi/scsi-generic.c static void scsi_generic_realize(SCSIDevice *s, Error **errp) · line 505
Quoted 11 lines
hw/scsi/scsi-generic.c +4
-3+++ b/hw/scsi/scsi-generic.c@@ -500,9 +500,10 @@ static void scsi_generic_realize(SCSIDevice *s, Error **errp)/* check we are using a driver managing SG_IO (version 3 and after */ rc =blk_ioctl (s->conf.blk,SG_GET_VERSION_NUM , &sg_version);if (rc <0 ) { -error_setg (errp,"cannot get SG_IO version number: %s. " -"Is this a SCSI device?" , -strerror (-rc)); +error_setg (errp,"cannot get SG_IO version number: %s" ,strerror (-rc)); +if (rc != -EPERM ) { +error_append_hint (errp,"Is this a SCSI device?" );
And again. With that fixed,
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
Quoted 5 lines · Paolo Bonzini
hw/scsi/scsi-generic.c +0
-0
hw/scsi/scsi-generic.c static void scsi_generic_realize(SCSIDevice *s, Error **errp) · line 506
Quoted 10 lines
hw/scsi/scsi-generic.c +4
-3@@ -500,9 +500,10 @@ static void scsi_generic_realize(SCSIDevice *s, Error **errp)/* check we are using a driver managing SG_IO (version 3 and after */ rc =blk_ioctl (s->conf.blk,SG_GET_VERSION_NUM , &sg_version);if (rc <0 ) { -error_setg (errp,"cannot get SG_IO version number: %s. " -"Is this a SCSI device?" , -strerror (-rc)); +error_setg (errp,"cannot get SG_IO version number: %s" ,strerror (-rc)); +if (rc != -EPERM ) { +error_append_hint (errp,"Is this a SCSI device?" ); + }
Out of the scope of this patch but I find it a bit annoying that hints are not propagated up in QMP. So that if you hot plug from virsh, the user friendliness of the old message is lost. Not sure if that is a problem or not.
Fam