qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH 06/14] scsi: change "removable" field to host many features
Date: Fri,  4 May 2012 10:45:46 +0200	[thread overview]
Message-ID: <1336121154-26517-7-git-send-email-pbonzini@redhat.com> (raw)
In-Reply-To: <1336121154-26517-1-git-send-email-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>
---
 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 fbb1041..e04b469 100644
--- a/hw/scsi-disk.c
+++ b/hw/scsi-disk.c
@@ -61,10 +61,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;
@@ -669,7 +671,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 {
@@ -1710,7 +1712,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;
     }
@@ -1732,7 +1735,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_cd_block_ops, s);
     }
     bdrv_set_buffer_alignment(s->qdev.conf.bs, s->qdev.blocksize);
@@ -1755,7 +1758,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);
 }
 
@@ -1828,7 +1831,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;
 }
 
@@ -1928,7 +1933,8 @@ static SCSIRequest *scsi_block_new_request(SCSIDevice *d, uint32_t tag,
 
 static Property scsi_hd_properties[] = {
     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(),
 };
 
@@ -2030,7 +2036,8 @@ static TypeInfo scsi_block_info = {
 
 static Property scsi_disk_properties[] = {
     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.9.3

  parent reply	other threads:[~2012-05-04  8:46 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-04  8:45 [Qemu-devel] [PULL 00/14] SCSI changes for 1.1 Paolo Bonzini
2012-05-04  8:45 ` [Qemu-devel] [PATCH 01/14] ISCSI: Add support for thin-provisioning via discard/UNMAP and bigger LUNs Paolo Bonzini
2012-05-04  8:45 ` [Qemu-devel] [PATCH 02/14] scsi: prevent data transfer overflow Paolo Bonzini
2012-05-04 16:28   ` Stefan Weil
2012-05-04 16:29     ` Paolo Bonzini
2012-05-04 16:51       ` Stefan Weil
2012-05-07 10:11         ` Paolo Bonzini
2012-05-04  8:45 ` [Qemu-devel] [PATCH 03/14] scsi: fix refcounting for reads Paolo Bonzini
2012-05-04  8:45 ` [Qemu-devel] [PATCH 04/14] scsi: fix WRITE SAME transfer length and direction Paolo Bonzini
2012-05-04  8:45 ` [Qemu-devel] [PATCH 05/14] scsi: Specify the xfer direction for UNMAP and ATA_PASSTHROUGH commands Paolo Bonzini
2012-05-04  8:45 ` Paolo Bonzini [this message]
2012-05-04 16:30   ` [Qemu-devel] [PATCH 06/14] scsi: change "removable" field to host many features Stefan Weil
2012-05-04 16:36     ` Paolo Bonzini
2012-05-04 16:49       ` Andreas Färber
2012-05-04  8:45 ` [Qemu-devel] [PATCH 07/14] scsi-disk: add dpofua property Paolo Bonzini
2012-05-04 16:32   ` Stefan Weil
2012-05-04  8:45 ` [Qemu-devel] [PATCH 08/14] scsi: do not report bogus overruns for commands in the 0x00-0x1F range Paolo Bonzini
2012-05-04  8:45 ` [Qemu-devel] [PATCH 09/14] scsi: parse 16-byte tape CDBs Paolo Bonzini
2012-05-04  8:45 ` [Qemu-devel] [PATCH 10/14] scsi: do not require a minimum allocation length for INQUIRY Paolo Bonzini
2012-05-04  8:45 ` [Qemu-devel] [PATCH 11/14] scsi: do not require a minimum allocation length for REQUEST SENSE Paolo Bonzini
2012-05-04  8:45 ` [Qemu-devel] [PATCH 12/14] scsi: set VALID bit to 0 in fixed format sense data Paolo Bonzini
2012-05-04  8:45 ` [Qemu-devel] [PATCH 13/14] scsi: remove useless debug messages Paolo Bonzini
2012-05-04  8:45 ` [Qemu-devel] [PATCH 14/14] scsi: Add assertion for use-after-free errors Paolo Bonzini
2012-05-08 16:11 ` [Qemu-devel] [PULL 00/14] SCSI changes for 1.1 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=1336121154-26517-7-git-send-email-pbonzini@redhat.com \
    --to=pbonzini@redhat.com \
    --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).