From c718e380247fa37d7e6b7a9845432b879ef9d3c3 Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Wed, 22 Feb 2012 14:12:21 +0100 Subject: [PATCH 065/109] scsi-disk: small clean up to INQUIRY RH-Author: Paolo Bonzini Message-id: <1329919979-20948-65-git-send-email-pbonzini@redhat.com> Patchwork-id: 37545 O-Subject: [RHEL 6.3 qemu-kvm PATCH v2 064/102] scsi-disk: small clean up to INQUIRY Bugzilla: 782029 RH-Acked-by: Laszlo Ersek RH-Acked-by: Orit Wasserman RH-Acked-by: Gerd Hoffmann Set s->removable, s->qdev.blocksize and s->qdev.type in the callers of scsi_initfn. With this in place, any s->qdev.type is allowed, and we can just reuse it as the first byte in VPD data (just like we do in standard INQUIRY data). Also set s->removable consistently so we can use it. Signed-off-by: Paolo Bonzini Signed-off-by: Kevin Wolf (cherry picked from e39be4823215e511d0e85aa33b2a5ade71064c72) Conflicts: hw/scsi-disk.c (trivial, due to different context) --- hw/scsi-disk.c | 46 ++++++++++++++++++++-------------------------- 1 files changed, 20 insertions(+), 26 deletions(-) Signed-off-by: Michal Novotny --- hw/scsi-disk.c | 46 ++++++++++++++++++++-------------------------- 1 files changed, 20 insertions(+), 26 deletions(-) diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c index 422f826..9188196 100644 --- a/hw/scsi-disk.c +++ b/hw/scsi-disk.c @@ -419,11 +419,7 @@ static int scsi_disk_emulate_inquiry(SCSIRequest *req, uint8_t *outbuf) return -1; } - if (s->qdev.type == TYPE_ROM) { - outbuf[buflen++] = 5; - } else { - outbuf[buflen++] = 0; - } + outbuf[buflen++] = s->qdev.type & 0x1f; outbuf[buflen++] = page_code ; // this page outbuf[buflen++] = 0x00; @@ -564,11 +560,10 @@ static int scsi_disk_emulate_inquiry(SCSIRequest *req, uint8_t *outbuf) memset(outbuf, 0, buflen); outbuf[0] = s->qdev.type & 0x1f; + outbuf[1] = s->removable ? 0x80 : 0; if (s->qdev.type == TYPE_ROM) { - outbuf[1] = 0x80; memcpy(&outbuf[16], "QEMU CD-ROM ", 16); } else { - outbuf[1] = s->removable ? 0x80 : 0; memcpy(&outbuf[16], "QEMU HARDDISK ", 16); } memcpy(&outbuf[8], "QEMU ", 8); @@ -1577,7 +1572,7 @@ static void scsi_disk_unit_attention_reported(SCSIDevice *dev) } } -static int scsi_initfn(SCSIDevice *dev, uint8_t scsi_type) +static int scsi_initfn(SCSIDevice *dev) { SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, dev); DriveInfo *dinfo; @@ -1587,7 +1582,7 @@ static int scsi_initfn(SCSIDevice *dev, uint8_t scsi_type) return -1; } - if (scsi_type == TYPE_DISK && !bdrv_is_inserted(s->qdev.conf.bs)) { + if (!s->removable && !bdrv_is_inserted(s->qdev.conf.bs)) { error_report("Device needs media, but drive is empty"); return -1; } @@ -1609,18 +1604,11 @@ static int scsi_initfn(SCSIDevice *dev, uint8_t scsi_type) return -1; } - if (scsi_type == TYPE_ROM) { + if (s->removable) { bdrv_set_dev_ops(s->qdev.conf.bs, &scsi_cd_block_ops, s); - s->qdev.blocksize = 2048; - } else if (scsi_type == TYPE_DISK) { - s->qdev.blocksize = s->qdev.conf.logical_block_size; - } else { - error_report("scsi-disk: Unhandled SCSI type %02x", scsi_type); - return -1; } s->qdev.conf.bs->buffer_alignment = s->qdev.blocksize; - s->qdev.type = scsi_type; qemu_add_vm_change_state_handler(scsi_dma_restart_cb, s); add_boot_device_path(s->qdev.conf.bootindex, &dev->qdev, ",0"); return 0; @@ -1628,26 +1616,32 @@ static int scsi_initfn(SCSIDevice *dev, uint8_t scsi_type) static int scsi_hd_initfn(SCSIDevice *dev) { - return scsi_initfn(dev, TYPE_DISK); + SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, dev); + s->qdev.blocksize = s->qdev.conf.logical_block_size; + s->qdev.type = TYPE_DISK; + return scsi_initfn(&s->qdev); } static int scsi_cd_initfn(SCSIDevice *dev) { - return scsi_initfn(dev, TYPE_ROM); + SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, dev); + s->qdev.blocksize = 2048; + s->qdev.type = TYPE_ROM; + s->removable = true; + return scsi_initfn(&s->qdev); } static int scsi_disk_initfn(SCSIDevice *dev) { - uint8_t scsi_type; - if (!dev->conf.bs) { - scsi_type = TYPE_DISK; /* will die in scsi_initfn() */ - } else { - scsi_type = bdrv_get_type_hint(dev->conf.bs) == BDRV_TYPE_CDROM - ? TYPE_ROM : TYPE_DISK; + return scsi_initfn(dev); /* ... and die there */ } - return scsi_initfn(dev, scsi_type); + if (bdrv_get_type_hint(dev->conf.bs) == BDRV_TYPE_CDROM) { + return scsi_cd_initfn(dev); + } else { + return scsi_hd_initfn(dev); + } } static SCSIReqOps scsi_disk_reqops = { -- 1.7.7.6