qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Kevin Wolf <kwolf@redhat.com>
To: anthony@codemonkey.ws
Cc: kwolf@redhat.com, qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH 12/29] scsi-disk: Remove 'drive_kind'
Date: Wed,  3 Aug 2011 16:14:07 +0200	[thread overview]
Message-ID: <1312380864-15605-13-git-send-email-kwolf@redhat.com> (raw)
In-Reply-To: <1312380864-15605-1-git-send-email-kwolf@redhat.com>

From: Hannes Reinecke <hare@suse.de>

Instead of using its own definitions scsi-disk should
be using the device type of the parent device.

Signed-off-by: Hannes Reinecke <hare@suse.de>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
 hw/scsi-defs.h |    6 +++++-
 hw/scsi-disk.c |   46 ++++++++++++++++++++++------------------------
 2 files changed, 27 insertions(+), 25 deletions(-)

diff --git a/hw/scsi-defs.h b/hw/scsi-defs.h
index f644860..27010b7 100644
--- a/hw/scsi-defs.h
+++ b/hw/scsi-defs.h
@@ -164,6 +164,7 @@
 
 #define TYPE_DISK           0x00
 #define TYPE_TAPE           0x01
+#define TYPE_PRINTER        0x02
 #define TYPE_PROCESSOR      0x03    /* HP scanners use this */
 #define TYPE_WORM           0x04    /* Treated as ROM by our system */
 #define TYPE_ROM            0x05
@@ -171,6 +172,9 @@
 #define TYPE_MOD            0x07    /* Magneto-optical disk -
 				     * - treated as TYPE_DISK */
 #define TYPE_MEDIUM_CHANGER 0x08
-#define TYPE_ENCLOSURE	    0x0d    /* Enclosure Services Device */
+#define TYPE_STORAGE_ARRAY  0x0c    /* Storage array device */
+#define TYPE_ENCLOSURE      0x0d    /* Enclosure Services Device */
+#define TYPE_RBC            0x0e    /* Simplified Direct-Access Device */
+#define TYPE_OSD            0x11    /* Object-storage Device */
 #define TYPE_NO_LUN         0x7f
 
diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
index 03f244e..fa198f9 100644
--- a/hw/scsi-disk.c
+++ b/hw/scsi-disk.c
@@ -59,8 +59,6 @@ typedef struct SCSIDiskReq {
     uint32_t status;
 } SCSIDiskReq;
 
-typedef enum { SCSI_HD, SCSI_CD } SCSIDriveKind;
-
 struct SCSIDiskState
 {
     SCSIDevice qdev;
@@ -74,7 +72,6 @@ struct SCSIDiskState
     char *version;
     char *serial;
     SCSISense sense;
-    SCSIDriveKind drive_kind;
 };
 
 static int scsi_handle_rw_error(SCSIDiskReq *r, int error, int type);
@@ -382,7 +379,7 @@ static int scsi_disk_emulate_inquiry(SCSIRequest *req, uint8_t *outbuf)
             return -1;
         }
 
-        if (s->drive_kind == SCSI_CD) {
+        if (s->qdev.type == TYPE_ROM) {
             outbuf[buflen++] = 5;
         } else {
             outbuf[buflen++] = 0;
@@ -401,7 +398,7 @@ static int scsi_disk_emulate_inquiry(SCSIRequest *req, uint8_t *outbuf)
             if (s->serial)
                 outbuf[buflen++] = 0x80; // unit serial number
             outbuf[buflen++] = 0x83; // device identification
-            if (s->drive_kind == SCSI_HD) {
+            if (s->qdev.type == TYPE_DISK) {
                 outbuf[buflen++] = 0xb0; // block limits
                 outbuf[buflen++] = 0xb2; // thin provisioning
             }
@@ -460,7 +457,7 @@ static int scsi_disk_emulate_inquiry(SCSIRequest *req, uint8_t *outbuf)
             unsigned int opt_io_size =
                     s->qdev.conf.opt_io_size / s->qdev.blocksize;
 
-            if (s->drive_kind == SCSI_CD) {
+            if (s->qdev.type == TYPE_ROM) {
                 DPRINTF("Inquiry (EVPD[%02X] not supported for CDROM\n",
                         page_code);
                 return -1;
@@ -530,12 +527,11 @@ static int scsi_disk_emulate_inquiry(SCSIRequest *req, uint8_t *outbuf)
         return buflen;
     }
 
-    if (s->drive_kind == SCSI_CD) {
-        outbuf[0] = 5;
+    outbuf[0] = s->qdev.type & 0x1f;
+    if (s->qdev.type == TYPE_ROM) {
         outbuf[1] = 0x80;
         memcpy(&outbuf[16], "QEMU CD-ROM     ", 16);
     } else {
-        outbuf[0] = 0;
         outbuf[1] = s->removable ? 0x80 : 0;
         memcpy(&outbuf[16], "QEMU HARDDISK   ", 16);
     }
@@ -661,7 +657,7 @@ static int mode_sense_page(SCSIRequest *req, int page, uint8_t *p,
         return p[1] + 2;
 
     case 0x2a: /* CD Capabilities and Mechanical Status page. */
-        if (s->drive_kind != SCSI_CD)
+        if (s->qdev.type != TYPE_ROM)
             return 0;
         p[0] = 0x2a;
         p[1] = 0x14;
@@ -877,7 +873,7 @@ static int scsi_disk_emulate_command(SCSIDiskReq *r, uint8_t *outbuf)
             goto illegal_request;
         break;
     case START_STOP:
-        if (s->drive_kind == SCSI_CD && (req->cmd.buf[4] & 2)) {
+        if (s->qdev.type == TYPE_ROM && (req->cmd.buf[4] & 2)) {
             /* load/eject medium */
             bdrv_eject(s->bs, !(req->cmd.buf[4] & 1));
         }
@@ -1183,7 +1179,7 @@ static void scsi_destroy(SCSIDevice *dev)
     blockdev_mark_auto_del(s->qdev.conf.bs);
 }
 
-static int scsi_initfn(SCSIDevice *dev, SCSIDriveKind kind)
+static int scsi_initfn(SCSIDevice *dev, uint8_t scsi_type)
 {
     SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, dev);
     DriveInfo *dinfo;
@@ -1193,9 +1189,8 @@ static int scsi_initfn(SCSIDevice *dev, SCSIDriveKind kind)
         return -1;
     }
     s->bs = s->qdev.conf.bs;
-    s->drive_kind = kind;
 
-    if (kind == SCSI_HD && !bdrv_is_inserted(s->bs)) {
+    if (scsi_type == TYPE_DISK && !bdrv_is_inserted(s->bs)) {
         error_report("Device needs media, but drive is empty");
         return -1;
     }
@@ -1217,44 +1212,47 @@ static int scsi_initfn(SCSIDevice *dev, SCSIDriveKind kind)
         return -1;
     }
 
-    if (kind == SCSI_CD) {
+    if (scsi_type == TYPE_ROM) {
         s->qdev.blocksize = 2048;
-    } else {
+    } 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->cluster_size = s->qdev.blocksize / 512;
     s->bs->buffer_alignment = s->qdev.blocksize;
 
-    s->qdev.type = TYPE_DISK;
+    s->qdev.type = scsi_type;
     qemu_add_vm_change_state_handler(scsi_dma_restart_cb, s);
-    bdrv_set_removable(s->bs, kind == SCSI_CD);
+    bdrv_set_removable(s->bs, scsi_type == TYPE_ROM);
     add_boot_device_path(s->qdev.conf.bootindex, &dev->qdev, ",0");
     return 0;
 }
 
 static int scsi_hd_initfn(SCSIDevice *dev)
 {
-    return scsi_initfn(dev, SCSI_HD);
+    return scsi_initfn(dev, TYPE_DISK);
 }
 
 static int scsi_cd_initfn(SCSIDevice *dev)
 {
-    return scsi_initfn(dev, SCSI_CD);
+    return scsi_initfn(dev, TYPE_ROM);
 }
 
 static int scsi_disk_initfn(SCSIDevice *dev)
 {
-    SCSIDriveKind kind;
     DriveInfo *dinfo;
+    uint8_t scsi_type;
 
     if (!dev->conf.bs) {
-        kind = SCSI_HD;         /* will die in scsi_initfn() */
+        scsi_type = TYPE_DISK;  /* will die in scsi_initfn() */
     } else {
         dinfo = drive_get_by_blockdev(dev->conf.bs);
-        kind = dinfo->media_cd ? SCSI_CD : SCSI_HD;
+        scsi_type = dinfo->media_cd ? TYPE_ROM : TYPE_DISK;
     }
 
-    return scsi_initfn(dev, kind);
+    return scsi_initfn(dev, scsi_type);
 }
 
 #define DEFINE_SCSI_DISK_PROPERTIES()                           \
-- 
1.7.6

  parent reply	other threads:[~2011-08-03 14:11 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-08-03 14:13 [Qemu-devel] [PULL 00/29] Block patches Kevin Wolf
2011-08-03 14:13 ` [Qemu-devel] [PATCH 01/29] blockdev: Make eject fail for non-removable drives even with -f Kevin Wolf
2011-08-03 14:13 ` [Qemu-devel] [PATCH 02/29] block: Reset device model callbacks on detach Kevin Wolf
2011-08-03 14:13 ` [Qemu-devel] [PATCH 03/29] block/raw-win32: Drop disabled code for removable host devices Kevin Wolf
2011-08-03 14:13 ` [Qemu-devel] [PATCH 04/29] block: Make BlockDriver method bdrv_set_locked() return void Kevin Wolf
2011-08-03 14:14 ` [Qemu-devel] [PATCH 05/29] block: Make BlockDriver method bdrv_eject() " Kevin Wolf
2011-08-03 14:14 ` [Qemu-devel] [PATCH 06/29] block: Don't let locked flag prevent medium load Kevin Wolf
2011-08-03 14:14 ` [Qemu-devel] [PATCH 07/29] block/vpc.c: Detect too-large vpc file Kevin Wolf
2011-08-03 14:14 ` [Qemu-devel] [PATCH 08/29] scsi-disk: Codingstyle fixes Kevin Wolf
2011-08-03 14:14 ` [Qemu-devel] [PATCH 09/29] scsi: Remove references to SET_WINDOW Kevin Wolf
2011-08-03 14:14 ` [Qemu-devel] [PATCH 10/29] scsi: Remove REZERO_UNIT emulation Kevin Wolf
2011-08-03 14:14 ` [Qemu-devel] [PATCH 11/29] scsi: Sanitize command definitions Kevin Wolf
2011-08-03 14:14 ` Kevin Wolf [this message]
2011-08-03 14:14 ` [Qemu-devel] [PATCH 13/29] block: Removed unused function bdrv_write_sync Kevin Wolf
2011-08-03 14:14 ` [Qemu-devel] [PATCH 14/29] raw-posix: Typo fix Kevin Wolf
2011-08-03 14:14 ` [Qemu-devel] [PATCH 15/29] raw-posix: Always check paio_init result Kevin Wolf
2011-08-03 14:14 ` [Qemu-devel] [PATCH 16/29] coroutine: introduce coroutines Kevin Wolf
2011-08-03 14:14 ` [Qemu-devel] [PATCH 17/29] coroutine: implement coroutines using gthread Kevin Wolf
2011-08-03 14:14 ` [Qemu-devel] [PATCH 18/29] coroutine: add test-coroutine automated tests Kevin Wolf
2011-08-03 14:14 ` [Qemu-devel] [PATCH 19/29] coroutine: add test-coroutine --benchmark-lifecycle Kevin Wolf
2011-08-03 14:14 ` [Qemu-devel] [PATCH 20/29] block: Add bdrv_co_readv/writev Kevin Wolf
2011-08-03 14:14 ` [Qemu-devel] [PATCH 21/29] block: Emulate AIO functions with bdrv_co_readv/writev Kevin Wolf
2011-08-03 14:14 ` [Qemu-devel] [PATCH 22/29] block: Add bdrv_co_readv/writev emulation Kevin Wolf
2011-08-03 14:14 ` [Qemu-devel] [PATCH 23/29] coroutines: Locks Kevin Wolf
2011-08-03 14:14 ` [Qemu-devel] [PATCH 24/29] qcow2: Use coroutines Kevin Wolf
2011-08-03 14:14 ` [Qemu-devel] [PATCH 25/29] qcow: " Kevin Wolf
2011-08-03 14:14 ` [Qemu-devel] [PATCH 26/29] async: Remove AsyncContext Kevin Wolf
2011-08-03 14:14 ` [Qemu-devel] [PATCH 27/29] coroutines: Use one global bottom half for CoQueue Kevin Wolf
2011-08-03 14:14 ` [Qemu-devel] [PATCH 28/29] posix-aio-compat: Allow read after EOF Kevin Wolf
2011-08-03 14:14 ` [Qemu-devel] [PATCH 29/29] block: Use bdrv_co_* instead of synchronous versions in coroutines Kevin Wolf
2011-08-04 22:07 ` [Qemu-devel] [PULL 00/29] Block patches Anthony Liguori

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1312380864-15605-13-git-send-email-kwolf@redhat.com \
    --to=kwolf@redhat.com \
    --cc=anthony@codemonkey.ws \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).