Hi Benoît,
Hm, opening a reference should only result in the refcount of the
respective BDS being incremented through bdrv_ref(). Since no new BDS is
created, nothing should be added to bdrv_states. When the BDS “closed”
through bdrv_unref(), it is only actually closed/deleted if the refcount
reaches zero. Until then, it remains in bdrv_states so it can be
referenced (since it has not been closed) and closed through
bdrv_close_all().
I don't really see how bdrv_close_all() closes the BDS “a second time” –
bdrv_unref() should only close the BDS if its refcount reaches zero. And
if that's the case, it should be removed from bdrv_states anyway.
Kind regards,
Max