From: Hanna Czenczek <[email protected]> The acct_failed argument to virtio_blk_handle_rw_error() tells whether there is accounting for this operation or not. The only operation for which there is none is discarding, which seems to be because at the time of the introducing commit 37b06f8d46f ("virtio-blk: add DISCARD and WRITE_ZEROES features"), BlockAcctType did not yet have a BLOCK_ACCT_UNMAP variant.
It does have that now, though, so we may as well track those discard operations with it, and can thus remove the acct_failed parameter. Signed-off-by: Hanna Czenczek <[email protected]> Reviewed-by: Michael S. Tsirkin <[email protected]> Reviewed-by: Stefan Hajnoczi <[email protected]> Signed-off-by: Michael S. Tsirkin <[email protected]> Message-ID: <[email protected]> --- hw/block/virtio-blk.c | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c index cb6a276a82..4110380392 100644 --- a/hw/block/virtio-blk.c +++ b/hw/block/virtio-blk.c @@ -69,7 +69,7 @@ void virtio_blk_req_complete(VirtIOBlockReq *req, unsigned char status) } static int virtio_blk_handle_rw_error(VirtIOBlockReq *req, int error, - bool is_read, bool acct_failed) + bool is_read) { VirtIOBlock *s = req->dev; BlockErrorAction action = blk_get_error_action(s->blk, is_read, error); @@ -85,9 +85,7 @@ static int virtio_blk_handle_rw_error(VirtIOBlockReq *req, int error, } } else if (action == BLOCK_ERROR_ACTION_REPORT) { 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); g_free(req); } @@ -124,7 +122,7 @@ static void virtio_blk_rw_complete(void *opaque, int ret) * the memory until the request is completed (which will * happen on the other side of the migration). */ - if (virtio_blk_handle_rw_error(req, -ret, is_read, true)) { + if (virtio_blk_handle_rw_error(req, -ret, is_read)) { continue; } } @@ -140,7 +138,7 @@ static void virtio_blk_flush_complete(void *opaque, int ret) VirtIOBlockReq *req = opaque; VirtIOBlock *s = req->dev; - if (ret && virtio_blk_handle_rw_error(req, -ret, 0, true)) { + if (ret && virtio_blk_handle_rw_error(req, -ret, 0)) { return; } @@ -153,17 +151,13 @@ static void virtio_blk_discard_write_zeroes_complete(void *opaque, int ret) { VirtIOBlockReq *req = opaque; VirtIOBlock *s = req->dev; - bool is_write_zeroes = (virtio_ldl_p(VIRTIO_DEVICE(s), &req->out.type) & - ~VIRTIO_BLK_T_BARRIER) == VIRTIO_BLK_T_WRITE_ZEROES; - if (ret && virtio_blk_handle_rw_error(req, -ret, false, is_write_zeroes)) { + if (ret && virtio_blk_handle_rw_error(req, -ret, false)) { return; } virtio_blk_req_complete(req, VIRTIO_BLK_S_OK); - if (is_write_zeroes) { - block_acct_done(blk_get_stats(s->blk), &req->acct); - } + block_acct_done(blk_get_stats(s->blk), &req->acct); g_free(req); } @@ -443,6 +437,9 @@ static uint8_t virtio_blk_handle_discard_write_zeroes(VirtIOBlockReq *req, goto err; } + block_acct_start(blk_get_stats(s->blk), &req->acct, bytes, + BLOCK_ACCT_UNMAP); + blk_aio_pdiscard(s->blk, sector << BDRV_SECTOR_BITS, bytes, virtio_blk_discard_write_zeroes_complete, req); } @@ -450,9 +447,8 @@ static uint8_t virtio_blk_handle_discard_write_zeroes(VirtIOBlockReq *req, return VIRTIO_BLK_S_OK; err: - if (is_write_zeroes) { - block_acct_invalid(blk_get_stats(s->blk), BLOCK_ACCT_WRITE); - } + block_acct_invalid(blk_get_stats(s->blk), + is_write_zeroes ? BLOCK_ACCT_WRITE : BLOCK_ACCT_UNMAP); return err_status; } -- MST
