qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH 19/19] block: make accounting thread-safe


From: Alberto Garcia
Subject: Re: [Qemu-devel] [PATCH 19/19] block: make accounting thread-safe
Date: Thu, 24 May 2018 15:49:00 +0200
User-agent: Notmuch/0.18.2 (http://notmuchmail.org) Emacs/24.4.1 (i586-pc-linux-gnu)

On Thu 24 May 2018 03:35:50 PM CEST, Alberto Garcia wrote:
> On Mon 05 Jun 2017 02:39:08 PM CEST, Paolo Bonzini wrote:
>> @@ -102,6 +107,8 @@ static void block_account_one_io(BlockAcctStats *stats, 
>> BlockAcctCookie *cookie,
>>  
>>      assert(cookie->type < BLOCK_MAX_IOTYPE);
>>  
>> +    qemu_mutex_lock(&stats->lock);
>
> QEMU crashes because this lock is not initialized if you do aio_read
> directly from a BDS not attached to a BlockBackend (should that
> operation be legal at all?)

I see, hmp_qemu_io() creates a temporary BlockBackend in these
situations, so I guess what we need is something like this:

diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c
index 9b3cd00af6..7b195ec4e3 100644
--- a/qemu-io-cmds.c
+++ b/qemu-io-cmds.c
@@ -1294,6 +1294,7 @@ static void aio_read_done(void *opaque, int ret)
     print_report("read", &t2, ctx->offset, ctx->qiov.size,
                  ctx->qiov.size, 1, ctx->Cflag);
 out:
+    blk_unref(ctx->blk);
     qemu_io_free(ctx->buf);
     qemu_iovec_destroy(&ctx->qiov);
     g_free(ctx);
@@ -1392,6 +1393,7 @@ static int aio_read_f(BlockBackend *blk, int argc, char 
**argv)
     gettimeofday(&ctx->t1, NULL);
     block_acct_start(blk_get_stats(blk), &ctx->acct, ctx->qiov.size,
                      BLOCK_ACCT_READ);
+    blk_ref(blk);
     blk_aio_preadv(blk, ctx->offset, &ctx->qiov, 0, aio_read_done,
     ctx);
     return 0;
 }

Berto



reply via email to

[Prev in Thread] Current Thread [Next in Thread]