Skip to content

Commit 5bd57eb

Browse files
lukasstraub2jasowang
authored andcommitted
net/colo-compare.c: Correct ordering in complete and finalize
In colo_compare_complete, insert CompareState into net_compares only after everything has been initialized. In colo_compare_finalize, remove CompareState from net_compares before anything is deinitialized. Signed-off-by: Lukas Straub <[email protected]> Reviewed-by: Zhang Chen <[email protected]> Signed-off-by: Zhang Chen <[email protected]> Signed-off-by: Jason Wang <[email protected]>
1 parent 45942b7 commit 5bd57eb

File tree

1 file changed

+23
-22
lines changed

1 file changed

+23
-22
lines changed

net/colo-compare.c

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1283,15 +1283,6 @@ static void colo_compare_complete(UserCreatable *uc, Error **errp)
12831283
s->vnet_hdr);
12841284
}
12851285

1286-
qemu_mutex_lock(&colo_compare_mutex);
1287-
if (!colo_compare_active) {
1288-
qemu_mutex_init(&event_mtx);
1289-
qemu_cond_init(&event_complete_cond);
1290-
colo_compare_active = true;
1291-
}
1292-
QTAILQ_INSERT_TAIL(&net_compares, s, next);
1293-
qemu_mutex_unlock(&colo_compare_mutex);
1294-
12951286
s->out_sendco.s = s;
12961287
s->out_sendco.chr = &s->chr_out;
12971288
s->out_sendco.notify_remote_frame = false;
@@ -1314,6 +1305,16 @@ static void colo_compare_complete(UserCreatable *uc, Error **errp)
13141305
connection_destroy);
13151306

13161307
colo_compare_iothread(s);
1308+
1309+
qemu_mutex_lock(&colo_compare_mutex);
1310+
if (!colo_compare_active) {
1311+
qemu_mutex_init(&event_mtx);
1312+
qemu_cond_init(&event_complete_cond);
1313+
colo_compare_active = true;
1314+
}
1315+
QTAILQ_INSERT_TAIL(&net_compares, s, next);
1316+
qemu_mutex_unlock(&colo_compare_mutex);
1317+
13171318
return;
13181319
}
13191320

@@ -1382,19 +1383,6 @@ static void colo_compare_finalize(Object *obj)
13821383
CompareState *s = COLO_COMPARE(obj);
13831384
CompareState *tmp = NULL;
13841385

1385-
qemu_chr_fe_deinit(&s->chr_pri_in, false);
1386-
qemu_chr_fe_deinit(&s->chr_sec_in, false);
1387-
qemu_chr_fe_deinit(&s->chr_out, false);
1388-
if (s->notify_dev) {
1389-
qemu_chr_fe_deinit(&s->chr_notify_dev, false);
1390-
}
1391-
1392-
if (s->iothread) {
1393-
colo_compare_timer_del(s);
1394-
}
1395-
1396-
qemu_bh_delete(s->event_bh);
1397-
13981386
qemu_mutex_lock(&colo_compare_mutex);
13991387
QTAILQ_FOREACH(tmp, &net_compares, next) {
14001388
if (tmp == s) {
@@ -1409,6 +1397,19 @@ static void colo_compare_finalize(Object *obj)
14091397
}
14101398
qemu_mutex_unlock(&colo_compare_mutex);
14111399

1400+
qemu_chr_fe_deinit(&s->chr_pri_in, false);
1401+
qemu_chr_fe_deinit(&s->chr_sec_in, false);
1402+
qemu_chr_fe_deinit(&s->chr_out, false);
1403+
if (s->notify_dev) {
1404+
qemu_chr_fe_deinit(&s->chr_notify_dev, false);
1405+
}
1406+
1407+
if (s->iothread) {
1408+
colo_compare_timer_del(s);
1409+
}
1410+
1411+
qemu_bh_delete(s->event_bh);
1412+
14121413
AioContext *ctx = iothread_get_aio_context(s->iothread);
14131414
aio_context_acquire(ctx);
14141415
AIO_WAIT_WHILE(ctx, !s->out_sendco.done);

0 commit comments

Comments
 (0)