scsi: Unify request unref in scsi_req_cancel
Before, scsi_req_cancel will take ownership of the canceled request and unref it. We did this because we didn't know whether AIO CB will be called or not during the cancelling, so we set the io_canceled flag before calling it, and skip unref in the potentially called callbacks, which is not very nice. Now, bdrv_aio_cancel has a stricter contract that the completion callbacks are always called, so we can remove the checks of req->io_canceled and just unref it in callbacks. It will also make implementing asynchronous cancellation easier. Signed-off-by: Fam Zheng <famz@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
parent
6c25fa6cf8
commit
3df9caf88f
|
@ -113,11 +113,6 @@ static void scsi_cancel_io(SCSIRequest *req)
|
||||||
DPRINTF("Cancel tag=0x%x\n", req->tag);
|
DPRINTF("Cancel tag=0x%x\n", req->tag);
|
||||||
if (r->req.aiocb) {
|
if (r->req.aiocb) {
|
||||||
bdrv_aio_cancel(r->req.aiocb);
|
bdrv_aio_cancel(r->req.aiocb);
|
||||||
|
|
||||||
/* This reference was left in by scsi_*_data. We take ownership of
|
|
||||||
* it the moment scsi_req_cancel is called, independent of whether
|
|
||||||
* bdrv_aio_cancel completes the request or not. */
|
|
||||||
scsi_req_unref(&r->req);
|
|
||||||
}
|
}
|
||||||
r->req.aiocb = NULL;
|
r->req.aiocb = NULL;
|
||||||
}
|
}
|
||||||
|
@ -197,9 +192,7 @@ static void scsi_aio_complete(void *opaque, int ret)
|
||||||
scsi_req_complete(&r->req, GOOD);
|
scsi_req_complete(&r->req, GOOD);
|
||||||
|
|
||||||
done:
|
done:
|
||||||
if (!r->req.io_canceled) {
|
scsi_req_unref(&r->req);
|
||||||
scsi_req_unref(&r->req);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool scsi_is_cmd_fua(SCSICommand *cmd)
|
static bool scsi_is_cmd_fua(SCSICommand *cmd)
|
||||||
|
@ -246,9 +239,7 @@ static void scsi_write_do_fua(SCSIDiskReq *r)
|
||||||
scsi_req_complete(&r->req, GOOD);
|
scsi_req_complete(&r->req, GOOD);
|
||||||
|
|
||||||
done:
|
done:
|
||||||
if (!r->req.io_canceled) {
|
scsi_req_unref(&r->req);
|
||||||
scsi_req_unref(&r->req);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void scsi_dma_complete_noio(void *opaque, int ret)
|
static void scsi_dma_complete_noio(void *opaque, int ret)
|
||||||
|
@ -280,9 +271,7 @@ static void scsi_dma_complete_noio(void *opaque, int ret)
|
||||||
}
|
}
|
||||||
|
|
||||||
done:
|
done:
|
||||||
if (!r->req.io_canceled) {
|
scsi_req_unref(&r->req);
|
||||||
scsi_req_unref(&r->req);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void scsi_dma_complete(void *opaque, int ret)
|
static void scsi_dma_complete(void *opaque, int ret)
|
||||||
|
@ -320,9 +309,7 @@ static void scsi_read_complete(void * opaque, int ret)
|
||||||
scsi_req_data(&r->req, r->qiov.size);
|
scsi_req_data(&r->req, r->qiov.size);
|
||||||
|
|
||||||
done:
|
done:
|
||||||
if (!r->req.io_canceled) {
|
scsi_req_unref(&r->req);
|
||||||
scsi_req_unref(&r->req);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Actually issue a read to the block device. */
|
/* Actually issue a read to the block device. */
|
||||||
|
@ -363,9 +350,7 @@ static void scsi_do_read(void *opaque, int ret)
|
||||||
}
|
}
|
||||||
|
|
||||||
done:
|
done:
|
||||||
if (!r->req.io_canceled) {
|
scsi_req_unref(&r->req);
|
||||||
scsi_req_unref(&r->req);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Read more data from scsi device into buffer. */
|
/* Read more data from scsi device into buffer. */
|
||||||
|
@ -481,9 +466,7 @@ static void scsi_write_complete(void * opaque, int ret)
|
||||||
}
|
}
|
||||||
|
|
||||||
done:
|
done:
|
||||||
if (!r->req.io_canceled) {
|
scsi_req_unref(&r->req);
|
||||||
scsi_req_unref(&r->req);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void scsi_write_data(SCSIRequest *req)
|
static void scsi_write_data(SCSIRequest *req)
|
||||||
|
@ -1582,9 +1565,7 @@ static void scsi_unmap_complete(void *opaque, int ret)
|
||||||
scsi_req_complete(&r->req, GOOD);
|
scsi_req_complete(&r->req, GOOD);
|
||||||
|
|
||||||
done:
|
done:
|
||||||
if (!r->req.io_canceled) {
|
scsi_req_unref(&r->req);
|
||||||
scsi_req_unref(&r->req);
|
|
||||||
}
|
|
||||||
g_free(data);
|
g_free(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1678,9 +1659,7 @@ static void scsi_write_same_complete(void *opaque, int ret)
|
||||||
scsi_req_complete(&r->req, GOOD);
|
scsi_req_complete(&r->req, GOOD);
|
||||||
|
|
||||||
done:
|
done:
|
||||||
if (!r->req.io_canceled) {
|
scsi_req_unref(&r->req);
|
||||||
scsi_req_unref(&r->req);
|
|
||||||
}
|
|
||||||
qemu_vfree(data->iov.iov_base);
|
qemu_vfree(data->iov.iov_base);
|
||||||
g_free(data);
|
g_free(data);
|
||||||
}
|
}
|
||||||
|
|
|
@ -137,9 +137,7 @@ static void scsi_command_complete(void *opaque, int ret)
|
||||||
|
|
||||||
scsi_req_complete(&r->req, status);
|
scsi_req_complete(&r->req, status);
|
||||||
done:
|
done:
|
||||||
if (!r->req.io_canceled) {
|
scsi_req_unref(&r->req);
|
||||||
scsi_req_unref(&r->req);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Cancel a pending data transfer. */
|
/* Cancel a pending data transfer. */
|
||||||
|
@ -150,11 +148,6 @@ static void scsi_cancel_io(SCSIRequest *req)
|
||||||
DPRINTF("Cancel tag=0x%x\n", req->tag);
|
DPRINTF("Cancel tag=0x%x\n", req->tag);
|
||||||
if (r->req.aiocb) {
|
if (r->req.aiocb) {
|
||||||
bdrv_aio_cancel(r->req.aiocb);
|
bdrv_aio_cancel(r->req.aiocb);
|
||||||
|
|
||||||
/* This reference was left in by scsi_*_data. We take ownership of
|
|
||||||
* it independent of whether bdrv_aio_cancel completes the request
|
|
||||||
* or not. */
|
|
||||||
scsi_req_unref(&r->req);
|
|
||||||
}
|
}
|
||||||
r->req.aiocb = NULL;
|
r->req.aiocb = NULL;
|
||||||
}
|
}
|
||||||
|
@ -214,9 +207,7 @@ static void scsi_read_complete(void * opaque, int ret)
|
||||||
bdrv_set_guest_block_size(s->conf.bs, s->blocksize);
|
bdrv_set_guest_block_size(s->conf.bs, s->blocksize);
|
||||||
|
|
||||||
scsi_req_data(&r->req, len);
|
scsi_req_data(&r->req, len);
|
||||||
if (!r->req.io_canceled) {
|
scsi_req_unref(&r->req);
|
||||||
scsi_req_unref(&r->req);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue