[Top][All Lists]

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

Re: [PATCH] nbd: Grab aio context lock in more places

From: Eric Blake
Subject: Re: [PATCH] nbd: Grab aio context lock in more places
Date: Mon, 23 Sep 2019 09:14:29 -0500
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0

On 9/23/19 9:10 AM, Sergio Lopez wrote:
> Eric Blake <address@hidden> writes:
>> When iothreads are in use, the failure to grab the aio context results
>> in an assertion failure when trying to unlock things during blk_unref,
>> when trying to unlock a mutex that was not locked.  In short, all
>> calls to nbd_export_put need to done while within the correct aio
>> context.  But since nbd_export_put can recursively reach itself via
>> nbd_export_close, and recursively grabbing the context would deadlock,
>> we can't do the context grab directly in those functions, but must do
>> so in their callers.
>> Hoist the use of the correct aio_context from nbd_export_new() to its
>> caller qmp_nbd_server_add().  Then tweak qmp_nbd_server_remove(),
>> nbd_eject_notifier(), and nbd_esport_close_all() to grab the right
>> context, so that all callers during qemu now own the context before
>> nbd_export_put() can call blk_unref().
>> Remaining uses in qemu-nbd don't matter (since that use case does not
>> support iothreads).
>> Suggested-by: Kevin Wolf <address@hidden>
>> Signed-off-by: Eric Blake <address@hidden>
>> ---
>> With this in place, my emailed formula [1] for causing an iothread
>> assertion failure no longer hits, and all the -nbd and -qcow2 iotests
>> still pass.  I would still like to update iotests to cover things (I
>> could not quickly figure out how to make iotest 222 use iothreads -
>> either we modify that one or add a new one), but wanted to get review
>> started on this first.
>> [1] https://lists.gnu.org/archive/html/qemu-devel/2019-09/msg03383.html

I ended up patch 223 instead, as patch 2/1 in reply to the original.

>>  void nbd_export_close(NBDExport *exp)
>>  {
>>      NBDClient *client, *next;
>>      nbd_export_get(exp);
>> +
> I'm not sure if this new line was added here on purpose.

Spurious leftovers from an alternative attempt.  Will drop this.

>>      /*
>>       * TODO: Should we expand QMP NbdServerRemoveNode enum to allow a
>>       * close mode that stops advertising the export to new clients but
>> @@ -1684,9 +1695,13 @@ BlockBackend *nbd_export_get_blockdev(NBDExport *exp)
>>  void nbd_export_close_all(void)
>>  {
>>      NBDExport *exp, *next;
>> +    AioContext *aio_context;
>>      QTAILQ_FOREACH_SAFE(exp, &exports, next, next) {
>> +        aio_context = exp->ctx;
>> +        aio_context_acquire(aio_context);
>>          nbd_export_close(exp);
>> +        aio_context_release(aio_context);
>>      }
>>  }
> Otherwise, LGTM.
> Reviewed-by: Sergio Lopez <address@hidden>

Thanks; queuing this on my NBD tree, along with the iotest followup
(although there's still a bit of time for that to get a review before I
send the pull request later today).

Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature

reply via email to

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