On 11/21/2011 02:39 PM, Gerd Hoffmann wrote:
> In case the guest sends a SYNCHRONIZE_CACHE command scsi_req_complete()
> is called twice:  Once because there is no data to transfer and
> scsi-disk thinks it is done with the command, and once when the flush is
> actually finished ...
> 
> Signed-off-by: Gerd Hoffmann<kra...@redhat.com>
> ---
>   hw/scsi-disk.c |    5 +++--
>   1 files changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
> index 62f538f..f3c75b3 100644
> --- a/hw/scsi-disk.c
> +++ b/hw/scsi-disk.c
> @@ -291,7 +291,7 @@ static void scsi_write_complete(void * opaque, int ret)
>           scsi_req_complete(&r->req, GOOD);
>       } else {
>           scsi_init_iovec(r);
> -        DPRINTF("Write complete tag=0x%x more=%d\n", r->req.tag, 
> r->qiov.size);
> +        DPRINTF("Write complete tag=0x%x more=%zd\n", r->req.tag, 
> r->qiov.size);
>           scsi_req_data(&r->req, r->qiov.size);
>       }
> 
> @@ -1421,7 +1421,8 @@ static int32_t scsi_send_command(SCSIRequest *req, 
> uint8_t *buf)
>           scsi_check_condition(r, SENSE_CODE(LBA_OUT_OF_RANGE));
>           return 0;
>       }
> -    if (r->sector_count == 0&&  r->iov.iov_len == 0) {
> +    if (r->sector_count == 0&&  r->iov.iov_len == 0&&
> +        command != SYNCHRONIZE_CACHE) {
>           scsi_req_complete(&r->req, GOOD);
>       }
>       len = r->sector_count * 512 + r->iov.iov_len;

/me is confused :)

    case SYNCHRONIZE_CACHE:
        /* The request is used as the AIO opaque value, so add a ref.  */
        scsi_req_ref(&r->req);
        bdrv_acct_start(s->qdev.conf.bs, &r->acct, 0, BDRV_ACCT_FLUSH);
        r->req.aiocb = bdrv_aio_flush(s->qdev.conf.bs, scsi_flush_complete, r);
        if (r->req.aiocb == NULL) {
            scsi_flush_complete(r, -EIO);
        }
        return 0;

Paolo

Reply via email to