From 9e8a7e0f787eecc18a779ae1217b0a222d3be6ce Mon Sep 17 00:00:00 2001
Message-Id: <9e8a7e0f787eecc18a779ae1217b0a222d3be6ce.1372244120.git.minovotn@redhat.com>
In-Reply-To: <24977988cb53a0f50e2996977c2221c5a358a4b8.1372244120.git.minovotn@redhat.com>
References: <24977988cb53a0f50e2996977c2221c5a358a4b8.1372244120.git.minovotn@redhat.com>
From: Pavel Hrdina <phrdina@redhat.com>
Date: Wed, 19 Jun 2013 13:17:20 +0200
Subject: [PATCH 09/12] scsi: change "removable" field to host many features

RH-Author: Pavel Hrdina <phrdina@redhat.com>
Message-id: <5a25d4daba013bee41f10c2ec74789bede2a5019.1371646058.git.phrdina@redhat.com>
Patchwork-id: 52003
O-Subject: [RHEL-6.5 qemu-kvm PATCH 1/2] scsi: change "removable" field to host many features
Bugzilla: 890011
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
RH-Acked-by: Michal Novotny <minovotn@redhat.com>

From: Paolo Bonzini <pbonzini@redhat.com>

It is pointless to add a uint32_t field for every new feature.
Since we will need a new feature soon, convert accesses to "removable"
to look at bit 0 only.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
(cherry picked from commit bfe3d7ac6d838b1931678d96d01c45d84c7e3de8)
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
---
 hw/scsi-disk.c | 23 +++++++++++++++--------
 1 file changed, 15 insertions(+), 8 deletions(-)

Signed-off-by: Michal Novotny <minovotn@redhat.com>
---
 hw/scsi-disk.c | 23 +++++++++++++++--------
 1 file changed, 15 insertions(+), 8 deletions(-)

diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
index e13141c..bdb106a 100644
--- a/hw/scsi-disk.c
+++ b/hw/scsi-disk.c
@@ -57,10 +57,12 @@ typedef struct SCSIDiskReq {
     BlockAcctCookie acct;
 } SCSIDiskReq;
 
+#define SCSI_DISK_F_REMOVABLE   0
+
 struct SCSIDiskState
 {
     SCSIDevice qdev;
-    uint32_t removable;
+    uint32_t features;
     bool media_changed;
     bool media_event;
     bool eject_request;
@@ -634,7 +636,7 @@ 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;
+    outbuf[1] = (s->features & (1 << SCSI_DISK_F_REMOVABLE)) ? 0x80 : 0;
     if (s->qdev.type == TYPE_ROM) {
         memcpy(&outbuf[16], "QEMU CD-ROM     ", 16);
     } else {
@@ -1705,7 +1707,8 @@ static int scsi_initfn(SCSIDevice *dev)
         return -1;
     }
 
-    if (!s->removable && !bdrv_is_inserted(s->qdev.conf.bs)) {
+    if (!(s->features & (1 << SCSI_DISK_F_REMOVABLE)) &&
+        !bdrv_is_inserted(s->qdev.conf.bs)) {
         error_report("Device needs media, but drive is empty");
         return -1;
     }
@@ -1727,7 +1730,7 @@ static int scsi_initfn(SCSIDevice *dev)
         return -1;
     }
 
-    if (s->removable) {
+    if (s->features & (1 << SCSI_DISK_F_REMOVABLE)) {
         bdrv_set_dev_ops(s->qdev.conf.bs, &scsi_disk_removable_block_ops, s);
     } else {
         bdrv_set_dev_ops(s->qdev.conf.bs, &scsi_disk_block_ops, s);
@@ -1752,7 +1755,7 @@ static int scsi_cd_initfn(SCSIDevice *dev)
     SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, dev);
     s->qdev.blocksize = 2048;
     s->qdev.type = TYPE_ROM;
-    s->removable = true;
+    s->features |= 1 << SCSI_DISK_F_REMOVABLE;
     return scsi_initfn(&s->qdev);
 }
 
@@ -1822,7 +1825,9 @@ static int get_device_type(SCSIDiskState *s)
         return -1;
     }
     s->qdev.type = buf[0];
-    s->removable = (buf[1] & 0x80) != 0;
+    if (buf[1] & 0x80) {
+        s->features |= 1 << SCSI_DISK_F_REMOVABLE;
+    }
     return 0;
 }
 
@@ -1950,7 +1955,8 @@ static SCSIDeviceInfo scsi_disk_info[] = {
         .unit_attention_reported = scsi_disk_unit_attention_reported,
         .qdev.props   = (Property[]) {
             DEFINE_SCSI_DISK_PROPERTIES(),
-            DEFINE_PROP_BIT("removable", SCSIDiskState, removable, 0, false),
+            DEFINE_PROP_BIT("removable", SCSIDiskState, features,
+                            SCSI_DISK_F_REMOVABLE, false),
             DEFINE_PROP_END_OF_LIST(),
         }
     },{
@@ -1998,7 +2004,8 @@ static SCSIDeviceInfo scsi_disk_info[] = {
         .unit_attention_reported = scsi_disk_unit_attention_reported,
         .qdev.props   = (Property[]) {
             DEFINE_SCSI_DISK_PROPERTIES(),
-            DEFINE_PROP_BIT("removable", SCSIDiskState, removable, 0, false),
+            DEFINE_PROP_BIT("removable", SCSIDiskState, features,
+                            SCSI_DISK_F_REMOVABLE, false),
             DEFINE_PROP_END_OF_LIST(),
         }
     }
-- 
1.7.11.7

