Skip to contentSkip to conversation

scsi: Make device scsi-disk reject /dev/sg*

PATCH Applied Markus Armbruster 5 participants 7 messages Feb 25, 2010 – Mar 9, 2010

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 scsi: Make device scsi-disk reject /dev/sg*

You're supposed to use scsi-generic for that. Which rejects anything but /dev/sg*.

---
 hw/scsi-disk.c |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)
hw/scsi-disk.c +5 -0
index b2f61fe..ad8eb24 100644
@@ -1027,6 +1027,11 @@ static int scsi_disk_initfn(SCSIDevice *dev)
     }
     s->bs = s->qdev.conf.dinfo->bdrv;
 
+    if (bdrv_is_sg(s->bs)) {
+        qemu_error("scsi-disk: unwanted /dev/sg*\n");
+        return -1;
+    }
+
     if (bdrv_get_type_hint(s->bs) == BDRV_TYPE_CDROM) {
         s->cluster_size = 4;
     } else {
Signature · 1 line
1.6.6
#1 lore raw
Quoted 2 lines · Markus Armbruster

You're supposed to use scsi-generic for that. Which rejects anything but /dev/sg*.

Well, it isn't *that* easy. The SG_IO ioctl used by scsi-generic works on tons of devices in linux, not only /dev/sg*. I've seen patches floading around which change the check bdrv_is_sg() into "try SG_IO and see if it works", which would allow to use /dev/sda with both scsi-disk and scsi-generic depending on what you want. Which makes alot of sense.

Making that change needs some extra care though to avoid existing configurations switching from scsi-disk to scsi-generic unnoticed.

cheers,
Gerd

#2 lore raw
Quoted 6 lines · Gerd Hoffmann
Quoted 2 lines · Markus Armbruster

You're supposed to use scsi-generic for that. Which rejects anything but /dev/sg*.

Well, it isn't *that* easy. The SG_IO ioctl used by scsi-generic works on tons of devices in linux, not only /dev/sg*. I've seen

Yes, the existing check in scsi-generic is pretty cheesy. My patch just makes scsi-disk consistently cheesy ;)

Quoted 7 lines

patches floading around which change the check bdrv_is_sg() into "try SG_IO and see if it works", which would allow to use /dev/sda with both scsi-disk and scsi-generic depending on what you want. Which makes alot of sense.

Making that change needs some extra care though to avoid existing configurations switching from scsi-disk to scsi-generic unnoticed.

Would be nice to have some day.

#3 lore raw
In reply to Gerd Hoffmann
Quoted 12 lines · Markus Armbruster
Quoted 2 lines

You're supposed to use scsi-generic for that. Which rejects anything but /dev/sg*.

Well, it isn't *that* easy. The SG_IO ioctl used by scsi-generic works on tons of devices in linux, not only /dev/sg*. I've seen patches floading around which change the check bdrv_is_sg() into "try SG_IO and see if it works", which would allow to use /dev/sda with both scsi-disk and scsi-generic depending on what you want. Which makes alot of sense.

Making that change needs some extra care though to avoid existing configurations switching from scsi-disk to scsi-generic unnoticed.

Don't we really want to be testing !bdrv_is_block() ?

Paul

#4 lore raw
Quoted 10 lines · Paul Brook
Quoted 10 lines · Markus Armbruster
Quoted 2 lines

You're supposed to use scsi-generic for that. Which rejects anything but /dev/sg*.

Well, it isn't *that* easy. The SG_IO ioctl used by scsi-generic works on tons of devices in linux, not only /dev/sg*. I've seen patches floading around which change the check bdrv_is_sg() into "try SG_IO and see if it works", which would allow to use /dev/sda with both scsi-disk and scsi-generic depending on what you want. Which makes alot of sense.

Quoted 4 lines
Quoted 2 lines

Making that change needs some extra care though to avoid existing configurations switching from scsi-disk to scsi-generic unnoticed.

Don't we really want to be testing !bdrv_is_block() ?

That would work for linux. Dunno about the BSD.

cheers,
Gerd

#5 lore raw
In reply to Markus Armbruster
Quoted 13 lines · Markus Armbruster

You're supposed to use scsi-generic for that. Which rejects anything but /dev/sg*.

---
 hw/scsi-disk.c |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)
hw/scsi-disk.c +0 -0
index b2f61fe..ad8eb24 100644

hw/scsi-disk.c static int scsi_disk_initfn(SCSIDevice *dev) · line 1032

Quoted 6 lines
hw/scsi-disk.c +3 -0
@@ -1027,6 +1027,11 @@ static int scsi_disk_initfn(SCSIDevice *dev)
     }
     s->bs = s->qdev.conf.dinfo->bdrv;
 
+    if (bdrv_is_sg(s->bs)) {
+        qemu_error("scsi-disk: unwanted /dev/sg*\n");
+        return -1;

Can we make the error message a bit more verbose?
E.g. "scsi-disk does not support /dev/sg*, please use *** instead". Where *** tells user what to do.

Quoted 9 lines
hw/scsi-disk.c +2 -0
+    }
+
     if (bdrv_get_type_hint(s->bs) == BDRV_TYPE_CDROM) {
         s->cluster_size = 4;
     } else {
Signature · 1 line
1.6.6
#6 lore raw
In reply to Markus Armbruster
Quoted 6 lines · Markus Armbruster

You're supposed to use scsi-generic for that. Which rejects anything but /dev/sg*.

---

Applied. Thanks.

Regards,

Anthony Liguori

Quoted 20 lines
  hw/scsi-disk.c |    5 +++++
  1 files changed, 5 insertions(+), 0 deletions(-)
hw/scsi-disk.c +5 -0
index b2f61fe..ad8eb24 100644
@@ -1027,6 +1027,11 @@ static int scsi_disk_initfn(SCSIDevice *dev)
      }
      s->bs = s->qdev.conf.dinfo->bdrv;
 
+    if (bdrv_is_sg(s->bs)) {
+        qemu_error("scsi-disk: unwanted /dev/sg*\n");
+        return -1;
+    }
+
      if (bdrv_get_type_hint(s->bs) == BDRV_TYPE_CDROM) {
          s->cluster_size = 4;
      } else {