Patchwork [v3,11/27] scsi-disk: Track tray locked state

login
register
mail settings
Submitter Markus Armbruster
Date Sept. 6, 2011, 4:58 p.m.
Message ID <1315328340-6192-12-git-send-email-armbru@redhat.com>
Download mbox | patch
Permalink /patch/113647/
State New
Headers show

Comments

Markus Armbruster - Sept. 6, 2011, 4:58 p.m.
We already track it in BlockDriverState.  Just like tray open/close
state, we should track it in the device models instead, because it's
device state.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 hw/scsi-disk.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
Paolo Bonzini - Sept. 7, 2011, 7:05 a.m.
On 09/06/2011 06:58 PM, Markus Armbruster wrote:
> We already track it in BlockDriverState.  Just like tray open/close
> state, we should track it in the device models instead, because it's
> device state.
>
> Signed-off-by: Markus Armbruster<armbru@redhat.com>
> ---
>   hw/scsi-disk.c |    4 +++-
>   1 files changed, 3 insertions(+), 1 deletions(-)
>
> diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
> index f35ada4..e7358e3 100644
> --- a/hw/scsi-disk.c
> +++ b/hw/scsi-disk.c
> @@ -73,6 +73,7 @@ struct SCSIDiskState
>       char *version;
>       char *serial;
>       bool tray_open;
> +    bool tray_locked;
>   };
>
>   static int scsi_handle_rw_error(SCSIDiskReq *r, int error, int type);
> @@ -671,7 +672,7 @@ static int mode_sense_page(SCSIDiskState *s, int page, uint8_t **p_outbuf,
>           p[5] = 0xff; /* CD DA, DA accurate, RW supported,
>                           RW corrected, C2 errors, ISRC,
>                           UPC, Bar code */
> -        p[6] = 0x2d | (bdrv_is_locked(s->bs)? 2 : 0);
> +        p[6] = 0x2d | (s->tray_locked ? 2 : 0);
>           /* Locking supported, jumper present, eject, tray */
>           p[7] = 0; /* no volume&  mute control, no
>                        changer */
> @@ -882,6 +883,7 @@ static int scsi_disk_emulate_command(SCSIDiskReq *r, uint8_t *outbuf)
>           scsi_disk_emulate_start_stop(r);
>           break;
>       case ALLOW_MEDIUM_REMOVAL:
> +        s->tray_locked = req->cmd.buf[4]&  1;
>           bdrv_set_locked(s->bs, req->cmd.buf[4]&  1);
>           break;
>       case READ_CAPACITY_10:

Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>

Patch

diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
index f35ada4..e7358e3 100644
--- a/hw/scsi-disk.c
+++ b/hw/scsi-disk.c
@@ -73,6 +73,7 @@  struct SCSIDiskState
     char *version;
     char *serial;
     bool tray_open;
+    bool tray_locked;
 };
 
 static int scsi_handle_rw_error(SCSIDiskReq *r, int error, int type);
@@ -671,7 +672,7 @@  static int mode_sense_page(SCSIDiskState *s, int page, uint8_t **p_outbuf,
         p[5] = 0xff; /* CD DA, DA accurate, RW supported,
                         RW corrected, C2 errors, ISRC,
                         UPC, Bar code */
-        p[6] = 0x2d | (bdrv_is_locked(s->bs)? 2 : 0);
+        p[6] = 0x2d | (s->tray_locked ? 2 : 0);
         /* Locking supported, jumper present, eject, tray */
         p[7] = 0; /* no volume & mute control, no
                      changer */
@@ -882,6 +883,7 @@  static int scsi_disk_emulate_command(SCSIDiskReq *r, uint8_t *outbuf)
         scsi_disk_emulate_start_stop(r);
         break;
     case ALLOW_MEDIUM_REMOVAL:
+        s->tray_locked = req->cmd.buf[4] & 1;
         bdrv_set_locked(s->bs, req->cmd.buf[4] & 1);
         break;
     case READ_CAPACITY_10: