qmp: cleanup qmp queues properly
Marc-André Lureau reported that we can have this happen:
1. client1 connects, send command C1
2. client1 disconnects before getting response for C1
3. client2 connects, who might receive response of C1
However client2 should not receive remaining responses for client1.
Basically, we should clean up the request/response queue elements when:
- after a session is closed
- before destroying the queues
Some helpers are introduced to achieve that. We need to make sure we're
with the lock when operating on those queues. This also needed the
declaration of QMPRequest moved earlier.
Reported-by: Marc-André Lureau <[email protected]>
Signed-off-by: Peter Xu <[email protected]>
Message-Id: <
20180326063901[email protected]>
Reviewed-by: Marc-André Lureau <[email protected]>
[eblake: drop pointless qmp_response_free(), drop queue flush on connect
since a clean queue on disconnect is sufficient]
Tested-by: Christian Borntraeger <[email protected]>
Signed-off-by: Eric Blake <[email protected]>