<div class="zcontentRow"><p style="font-size:14px;font-family:arial;">I just code review, found there may be problem.</p><p style="font-size:14px;font-family:arial;">The follow statement in founction qemuProcessReconnectHelper:</p><p style="font-size:14px;font-family:arial;">"if (virThreadCreate(&thread, false, qemuProcessReconnect, data) < 0) "</p><p style="font-size:14px;font-family:arial;">may be failed (no one can guarantee 'virThreadCreate' always success).</p><p style="font-size:14px;font-family:arial;">if ‘<span style="font-family: arial; line-height: 21px;">virThreadCreate</span>’ failed, the follow backstrace we will get:</p><p style="font-size:14px;font-family:arial;"><br></p><p>#0  0x00007fa89921203e in pthread_rwlock_wrlock () from /lib64/libpthread.so.0</p><p>#1  0x00007fa89ba218e5 in virRWLockWrite (m=<optimized out>) at util/virthread.c:122</p><p>#2  0x00007fa89b9f9ebb in virObjectRWLockWrite (anyobj=<optimized out>) at util/virobject.c:487</p><p>#3  0x00007fa89ba82a68 in virDomainObjListRemove (doms=0x7fa87411fde0, dom=0x7fa8740f94f0) at conf/virdomainobjlist.c:400</p><p>#4  0x00007fa87e1b9ace in qemuDomainRemoveInactive (driver=driver@entry=0x7fa87411aa20, vm=vm@entry=0x7fa8740f94f0) at qemu/qemu_domain.c:8309</p><p>#5  0x00007fa87e1b9c02 in qemuDomainRemoveInactiveJob (driver=0x7fa87411aa20, vm=0x7fa8740f94f0) at qemu/qemu_domain.c:8331</p><p>#6  0x00007fa87e1ef36d in qemuProcessReconnectHelper (obj=0x7fa8740f94f0, opaque=0x7fa87b4b3c30) at qemu/qemu_process.c:8035</p><p>#7  0x00007fa89ba81e9a in virDomainObjListHelper (payload=<optimized out>, name=<optimized out>, opaque=0x7fa87b4b3c00) at conf/virdomainobjlist.c:804</p><p>#8  0x00007fa89b9ccaa0 in virHashForEach (table=0x7fa87410e520, iter=iter@entry=0x7fa89ba81e90 <virDomainObjListHelper>, data=data@entry=0x7fa87b4b3c00)</p><p>    at util/virhash.c:580</p><p>#9  0x00007fa89ba83391 in virDomainObjListForEach (doms=0x7fa87411fde0, callback=callback@entry=0x7fa87e1ef220 <qemuProcessReconnectHelper>,</p><p>    opaque=opaque@entry=0x7fa87b4b3c30) at conf/virdomainobjlist.c:819</p><p>#10 0x00007fa87e1f1564 in qemuProcessReconnectAll (driver=<optimized out>) at qemu/qemu_process.c:8056</p><p>#11 0x00007fa87e227928 in qemuStateInitialize (privileged=true, callback=<optimized out>, opaque=<optimized out>) at qemu/qemu_driver.c:919</p><p>#12 0x00007fa89bb9f91f in virStateInitialize (privileged=true, callback=callback@entry=0x7fa89c547cd0 <daemonInhibitCallback>, opaque=opaque@entry=0x7fa89d875c00)</p><p>    at libvirt.c:662</p><p>#13 0x00007fa89c547d2b in daemonRunStateInit (opaque=0x7fa89d875c00) at remote/remote_daemon.c:803</p><p>#14 0x00007fa89ba21712 in virThreadHelper (data=<optimized out>) at util/virthread.c:206</p><p>#15 0x00007fa89920edc5 in start_thread () from /lib64/libpthread.so.0</p><p>#16 0x00007fa898b3673d in clone () from /lib64/libc.so.6</p><p style="font-size:14px;font-family:arial;"><br></p><p style="font-size:14px;font-family:arial;">frame 8, <span style="line-height: 21px;">virHashForEach has called virObjectLock(doms)</span></p><p style="font-size:14px;font-family:arial;">frame 3, <span style="line-height: 21px;">virDomainObjListRemove calls </span>virObjectRWLockWrite(doms) again.</p><p style="font-size:14px;font-family:arial;">thus deadlock occurs.</p><p style="font-size:14px;font-family:arial;"><br></p><p style="font-size:14px;font-family:arial;"><br></p><div><div class="zhistoryRow" style="display:block"><div class="zhistoryDes" style="width: 100%; height: 28px; line-height: 28px; background-color: #E0E5E9; color: #1388FF; text-align: center;" language-data="HistoryOrgTxt">原始邮件</div><div id="zwriteHistoryContainer"><div class="control-group zhistoryPanel"><div class="zhistoryHeader" style="padding: 8px; background-color: #F5F6F8;"><div><strong language-data="HistorySenderTxt">发件人:</strong><span class="zreadUserName">PeterKrempa <pkrempa@redhat.com></span></div><div><strong language-data="HistoryTOTxt">收件人:</strong><span class="zreadUserName" style="display: inline;">王业超10154425;</span></div><div><strong language-data="HistoryCCTxt">抄送人:</strong><span class="zreadUserName" style="display: inline;">libvir-list@redhat.com <libvir-list@redhat.com></span></div><div><strong language-data="HistoryDateTxt">日 期 :</strong><span class="">2018年09月13日 19:31</span></div><div><strong language-data="HistorySubjectTxt">主 题 :</strong><span class="zreadTitle"><strong>Re: [libvirt] [PATCH v2] qemu: fix deadlock if createqemuProcessReconnect thread failed</strong></span></div></div><div class="zhistoryContent"><div>On Thu, Sep 13, 2018 at 19:28:12 +0800, Wang Yechao wrote:<br>> qemuProcessReconnectHelper has hold the doms lock, if create<br>> qemuProcessReconnect thread failed, it will get the doms lock<br>> again to remove the dom from doms list.<br>> <br>> add obj->inReconnetCtx flag to avoid deadlock.<br><br>Please describe the situation more or provide a reproducer.<br><br>> <br>> Signed-off-by: Wang Yechao <wang.yechao255@zte.com.cn><br>> ---<br>>  src/conf/domain_conf.h      | 1 +<br>>  src/conf/virdomainobjlist.c | 6 ++++--<br>>  src/qemu/qemu_process.c     | 1 +<br>>  3 files changed, 6 insertions(+), 2 deletions(-)<br></div></div></div></div></div></div><p><br></p></div>