Patchwork [v2,11/45] scsi-disk: Factor out scsi_disk_emulate_start_stop()

login
register
mail settings
Submitter Markus Armbruster
Date Aug. 3, 2011, 1:07 p.m.
Message ID <1312376904-16115-12-git-send-email-armbru@redhat.com>
Download mbox | patch
Permalink /patch/108289/
State New
Headers show

Comments

Markus Armbruster - Aug. 3, 2011, 1:07 p.m.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 hw/scsi-disk.c |   17 +++++++++++++----
 1 files changed, 13 insertions(+), 4 deletions(-)
Hannes Reinecke - Aug. 4, 2011, 6:12 a.m.
On 08/03/2011 03:07 PM, Markus Armbruster wrote:
> Signed-off-by: Markus Armbruster<armbru@redhat.com>
> ---
>   hw/scsi-disk.c |   17 +++++++++++++----
>   1 files changed, 13 insertions(+), 4 deletions(-)
>
> diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
> index fa198f9..d549cb7 100644
> --- a/hw/scsi-disk.c
> +++ b/hw/scsi-disk.c
> @@ -820,6 +820,18 @@ static int scsi_disk_emulate_read_toc(SCSIRequest *req, uint8_t *outbuf)
>       return toclen;
>   }
>
> +static void scsi_disk_emulate_start_stop(SCSIDiskReq *r)
> +{
> +    SCSIRequest *req =&r->req;
> +    SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, req->dev);
> +    bool start = req->cmd.buf[4]&  1;
> +    bool loej = req->cmd.buf[4]&  2;
> +
> +    if (s->qdev.type == TYPE_ROM&&  loej) {
> +        bdrv_eject(s->bs, !start);
> +    }
> +}
> +
>   static int scsi_disk_emulate_command(SCSIDiskReq *r, uint8_t *outbuf)
>   {
>       SCSIRequest *req =&r->req;
> @@ -873,10 +885,7 @@ static int scsi_disk_emulate_command(SCSIDiskReq *r, uint8_t *outbuf)
>               goto illegal_request;
>           break;
>       case START_STOP:
> -        if (s->qdev.type == TYPE_ROM&&  (req->cmd.buf[4]&  2)) {
> -            /* load/eject medium */
> -            bdrv_eject(s->bs, !(req->cmd.buf[4]&  1));
> -        }
> +        scsi_disk_emulate_start_stop(r);
>           break;
>       case ALLOW_MEDIUM_REMOVAL:
>           bdrv_set_locked(s->bs, req->cmd.buf[4]&  1);

Acked-by: Hannes Reinecke <hare@suse.de>

Cheers,

Hannes
Kevin Wolf - Sept. 2, 2011, 10:26 a.m.
Am 03.08.2011 15:07, schrieb Markus Armbruster:
> Signed-off-by: Markus Armbruster <armbru@redhat.com>
> ---
>  hw/scsi-disk.c |   17 +++++++++++++----
>  1 files changed, 13 insertions(+), 4 deletions(-)
> 
> diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
> index fa198f9..d549cb7 100644
> --- a/hw/scsi-disk.c
> +++ b/hw/scsi-disk.c
> @@ -820,6 +820,18 @@ static int scsi_disk_emulate_read_toc(SCSIRequest *req, uint8_t *outbuf)
>      return toclen;
>  }
>  
> +static void scsi_disk_emulate_start_stop(SCSIDiskReq *r)
> +{
> +    SCSIRequest *req = &r->req;
> +    SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, req->dev);
> +    bool start = req->cmd.buf[4] & 1;
> +    bool loej = req->cmd.buf[4] & 2;
> +
> +    if (s->qdev.type == TYPE_ROM && loej) {
> +        bdrv_eject(s->bs, !start);
> +    }
> +}
> +
>  static int scsi_disk_emulate_command(SCSIDiskReq *r, uint8_t *outbuf)
>  {
>      SCSIRequest *req = &r->req;
> @@ -873,10 +885,7 @@ static int scsi_disk_emulate_command(SCSIDiskReq *r, uint8_t *outbuf)
>              goto illegal_request;
>          break;
>      case START_STOP:
> -        if (s->qdev.type == TYPE_ROM && (req->cmd.buf[4] & 2)) {
> -            /* load/eject medium */

So here we actually had the comment before. Can we retain it?

Kevin
Markus Armbruster - Sept. 2, 2011, 2:55 p.m.
Kevin Wolf <kwolf@redhat.com> writes:

> Am 03.08.2011 15:07, schrieb Markus Armbruster:
>> Signed-off-by: Markus Armbruster <armbru@redhat.com>
>> ---
>>  hw/scsi-disk.c |   17 +++++++++++++----
>>  1 files changed, 13 insertions(+), 4 deletions(-)
>> 
>> diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
>> index fa198f9..d549cb7 100644
>> --- a/hw/scsi-disk.c
>> +++ b/hw/scsi-disk.c
>> @@ -820,6 +820,18 @@ static int scsi_disk_emulate_read_toc(SCSIRequest *req, uint8_t *outbuf)
>>      return toclen;
>>  }
>>  
>> +static void scsi_disk_emulate_start_stop(SCSIDiskReq *r)
>> +{
>> +    SCSIRequest *req = &r->req;
>> +    SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, req->dev);
>> +    bool start = req->cmd.buf[4] & 1;
>> +    bool loej = req->cmd.buf[4] & 2;
>> +
>> +    if (s->qdev.type == TYPE_ROM && loej) {
>> +        bdrv_eject(s->bs, !start);
>> +    }
>> +}
>> +
>>  static int scsi_disk_emulate_command(SCSIDiskReq *r, uint8_t *outbuf)
>>  {
>>      SCSIRequest *req = &r->req;
>> @@ -873,10 +885,7 @@ static int scsi_disk_emulate_command(SCSIDiskReq *r, uint8_t *outbuf)
>>              goto illegal_request;
>>          break;
>>      case START_STOP:
>> -        if (s->qdev.type == TYPE_ROM && (req->cmd.buf[4] & 2)) {
>> -            /* load/eject medium */
>
> So here we actually had the comment before. Can we retain it?

We never had it in atapi.c, actually.

The fact that my scsi_disk_emulate_command() is very similar to
atapi.c's cmd_start_stop_unit() is no accident.  Whatever comment I'll
add to atapi.c, I'll add here, too.

Patch

diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
index fa198f9..d549cb7 100644
--- a/hw/scsi-disk.c
+++ b/hw/scsi-disk.c
@@ -820,6 +820,18 @@  static int scsi_disk_emulate_read_toc(SCSIRequest *req, uint8_t *outbuf)
     return toclen;
 }
 
+static void scsi_disk_emulate_start_stop(SCSIDiskReq *r)
+{
+    SCSIRequest *req = &r->req;
+    SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, req->dev);
+    bool start = req->cmd.buf[4] & 1;
+    bool loej = req->cmd.buf[4] & 2;
+
+    if (s->qdev.type == TYPE_ROM && loej) {
+        bdrv_eject(s->bs, !start);
+    }
+}
+
 static int scsi_disk_emulate_command(SCSIDiskReq *r, uint8_t *outbuf)
 {
     SCSIRequest *req = &r->req;
@@ -873,10 +885,7 @@  static int scsi_disk_emulate_command(SCSIDiskReq *r, uint8_t *outbuf)
             goto illegal_request;
         break;
     case START_STOP:
-        if (s->qdev.type == TYPE_ROM && (req->cmd.buf[4] & 2)) {
-            /* load/eject medium */
-            bdrv_eject(s->bs, !(req->cmd.buf[4] & 1));
-        }
+        scsi_disk_emulate_start_stop(r);
         break;
     case ALLOW_MEDIUM_REMOVAL:
         bdrv_set_locked(s->bs, req->cmd.buf[4] & 1);