virtio-blk: add acct_failed param to virtio_blk_handle_rw_error()

We add acct_failed param in order to use virtio_blk_handle_rw_error()
also when is not required to call block_acct_failed(). (eg. a discard
operation is failed)

Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
Message-id: 20190221103314.58500-2-sgarzare@redhat.com
Message-Id: <20190221103314.58500-2-sgarzare@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
This commit is contained in:
Stefano Garzarella 2019-02-21 11:33:05 +01:00 committed by Stefan Hajnoczi
parent 9942586b3f
commit 00f639fb8f

View File

@ -65,7 +65,7 @@ static void virtio_blk_req_complete(VirtIOBlockReq *req, unsigned char status)
} }
static int virtio_blk_handle_rw_error(VirtIOBlockReq *req, int error, static int virtio_blk_handle_rw_error(VirtIOBlockReq *req, int error,
bool is_read) bool is_read, bool acct_failed)
{ {
VirtIOBlock *s = req->dev; VirtIOBlock *s = req->dev;
BlockErrorAction action = blk_get_error_action(s->blk, is_read, error); BlockErrorAction action = blk_get_error_action(s->blk, is_read, error);
@ -78,7 +78,9 @@ static int virtio_blk_handle_rw_error(VirtIOBlockReq *req, int error,
s->rq = req; s->rq = req;
} else if (action == BLOCK_ERROR_ACTION_REPORT) { } else if (action == BLOCK_ERROR_ACTION_REPORT) {
virtio_blk_req_complete(req, VIRTIO_BLK_S_IOERR); virtio_blk_req_complete(req, VIRTIO_BLK_S_IOERR);
if (acct_failed) {
block_acct_failed(blk_get_stats(s->blk), &req->acct); block_acct_failed(blk_get_stats(s->blk), &req->acct);
}
virtio_blk_free_request(req); virtio_blk_free_request(req);
} }
@ -116,7 +118,7 @@ static void virtio_blk_rw_complete(void *opaque, int ret)
* the memory until the request is completed (which will * the memory until the request is completed (which will
* happen on the other side of the migration). * happen on the other side of the migration).
*/ */
if (virtio_blk_handle_rw_error(req, -ret, is_read)) { if (virtio_blk_handle_rw_error(req, -ret, is_read, true)) {
continue; continue;
} }
} }
@ -135,7 +137,7 @@ static void virtio_blk_flush_complete(void *opaque, int ret)
aio_context_acquire(blk_get_aio_context(s->conf.conf.blk)); aio_context_acquire(blk_get_aio_context(s->conf.conf.blk));
if (ret) { if (ret) {
if (virtio_blk_handle_rw_error(req, -ret, 0)) { if (virtio_blk_handle_rw_error(req, -ret, 0, true)) {
goto out; goto out;
} }
} }