On 8/13/20 11:29 AM, Kevin Wolf wrote:
Closing export is somewhat convoluted because nbd_export_close() and
nbd_export_put() call each other and the ways they actually end up being
nested is not necessarily obvious.

You are in a maze of twisty little passages, all alike.

Yes, I've always hated that part of the code; thanks for tackling a cleanup.


However, it is not really necessary to call nbd_export_close() from
nbd_export_put() when putting the last reference because it only does
three things:

1. Close all clients. We're going to refcount 0 and all clients hold a
    reference, so we know there is no active client any more.

2. Close the user reference (represented by exp->name being non-NULL).
    The same argument applies: If the export were still named, we would
    still have a reference.

3. Freeing exp->description. This is really cleanup work to be done when
    the export is finally freed. There is no reason to already clear it
    while clients are still in the process of shutting down.

So after moving the cleanup of exp->description, the code can be
simplified so that only nbd_export_close() calls nbd_export_put(), but
never the other way around.

Signed-off-by: Kevin Wolf <kw...@redhat.com>
---
  nbd/server.c | 17 ++++-------------
  1 file changed, 4 insertions(+), 13 deletions(-)


Reviewed-by: Eric Blake <ebl...@redhat.com>

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


Reply via email to