From 23994a5f524aa575c7a4b2e5250f17b127d2cf2f Mon Sep 17 00:00:00 2001 From: Pavel Butsykin Date: Thu, 14 Apr 2016 13:20:15 +0300 Subject: [PATCH] nbd: fix assert() on qemu-nbd stop From time to time qemu-nbd is crashing on the following assert: assert(state == TERMINATING); nbd_export_closed nbd_export_put main and the state at the moment of the crash is evaluated to TERMINATE. During shutdown process of the client the nbd_client_thread thread sends SIGTERM signal and the main thread calls the nbd_client_closed callback. If the SIGTERM callback will be executed after change the state to TERMINATING, then the state will once again be TERMINATE. To solve the issue, we must change the state to TERMINATE only if the state is RUNNING. In the other case we are shutting down already. Signed-off-by: Pavel Butsykin Signed-off-by: Denis V. Lunev CC: Paolo Bonzini Message-id: 1460629215-11567-1-git-send-email-den@openvz.org Signed-off-by: Max Reitz --- qemu-nbd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qemu-nbd.c b/qemu-nbd.c index b5751f853b..2c9754e5d6 100644 --- a/qemu-nbd.c +++ b/qemu-nbd.c @@ -215,7 +215,7 @@ static int find_partition(BlockBackend *blk, int partition, static void termsig_handler(int signum) { - state = TERMINATE; + atomic_cmpxchg(&state, RUNNING, TERMINATE); qemu_notify_event(); }