<html><head><meta http-equiv="content-type" content="text/html; charset=UTF-8"><style>body { line-height: 1.5; }blockquote { margin-top: 0px; margin-bottom: 0px; margin-left: 0.5em; }body { font-size: 10.5pt; font-family: 微软雅黑; color: rgb(0, 0, 0); line-height: 1.5; }</style></head><body>
<div><span></span>Yes, this is CentOS 6 only, The monitor socket is by default set to NONBLOCK with CentOS 7.</div><div><br></div><div>I compare the udev code on centos6 and centos7,</div><div><br></div><div>in udev-147 on centos6:</div><div>udev_monitor->sock = socket(PF_NETLINK, SOCK_DGRAM|SOCK_CLOEXEC, NETLINK_KOBJECT_UEVENT);</div><div><br></div><div>in systemd-219 on centos7:</div><div>udev_monitor->sock = socket(PF_NETLINK, SOCK_RAW|SOCK_CLOEXEC|SOCK_NONBLOCK, NETLINK_KOBJECT_UEVENT);</div><hr style="width: 210px; height: 1px;" color="#b5c4df" size="1" align="left">
<div><span><div style="MARGIN: 10px; FONT-FAMILY: verdana; FONT-SIZE: 10pt"><div>owen.si@ucloud.cn</div></div></span></div>
<blockquote style="margin-Top: 0px; margin-Bottom: 0px; margin-Left: 0.5em"><div> </div><div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0cm 0cm 0cm"><div style="PADDING-RIGHT: 8px; PADDING-LEFT: 8px; FONT-SIZE: 12px;FONT-FAMILY:tahoma;COLOR:#000000; BACKGROUND: #efefef; PADDING-BOTTOM: 8px; PADDING-TOP: 8px"><div><b>From:</b> <a href="mailto:jferlan@redhat.com">John Ferlan</a></div><div><b>Date:</b> 2018-10-17 05:57</div><div><b>To:</b> <a href="mailto:owen.si@ucloud.cn">Bingsong Si</a>; <a href="mailto:libvir-list@redhat.com">libvir-list</a></div><div><b>CC:</b> <a href="mailto:eskultet@redhat.com">Erik Skultety</a></div><div><b>Subject:</b> Re: [libvirt] [PATCH] libvirtd: fix potential deadlock when starting vm</div></div></div><div><div> </div>
<div> </div>
<div>On 10/11/18 4:13 AM, Bingsong Si wrote:</div>
<div>> On CentOS 6, udev_monitor_receive_device will block until the socket becomes</div>
<div> </div>
<div>Is this really CentOS6 only or just where you've seen it?</div>
<div> </div>
<div>> readable, udevEventHandleThread will hold the lock all the time and</div>
<div>> udevEventHandleCallback hard to get the lock, will block the event poll.</div>
<div>> To fix this, set dataReady to false after receive an udev event.</div>
<div>> </div>
<div>> Signed-off-by: Bingsong Si <owen.si@ucloud.cn></div>
<div>> ---</div>
<div>>  src/node_device/node_device_udev.c | 5 +----</div>
<div>>  1 file changed, 1 insertion(+), 4 deletions(-)</div>
<div>> </div>
<div> </div>
<div>I've CC'd Erik since he wrote and perhaps remembers all the "gotchas" he</div>
<div>discovered in the udev callback code.</div>
<div> </div>
<div>I wonder if this has to do with the EAGAIN and EWOULDBLOCK @errno checks</div>
<div>done in the !device loop that are different in "older" (much older) code.</div>
<div> </div>
<div>Although I have this very vague recollection that there was some problem</div>
<div>with centos6 that was fixed by some OS patch.  Hopefully Erik remembers</div>
<div>(and maybe we should log it in the code at this point ;-)) - I did do</div>
<div>some searching, but came up empty.</div>
<div> </div>
<div>John</div>
<div> </div>
<div>> diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_device_udev.c</div>
<div>> index 22897591de..ce1101d7cc 100644</div>
<div>> --- a/src/node_device/node_device_udev.c</div>
<div>> +++ b/src/node_device/node_device_udev.c</div>
<div>> @@ -1616,6 +1616,7 @@ udevEventHandleThread(void *opaque ATTRIBUTE_UNUSED)</div>
<div>>  </div>
<div>>          errno = 0;</div>
<div>>          device = udev_monitor_receive_device(priv->udev_monitor);</div>
<div>> +        priv->dataReady = false;</div>
<div>>          virObjectUnlock(priv);</div>
<div>>  </div>
<div>>          if (!device) {</div>
<div>> @@ -1637,10 +1638,6 @@ udevEventHandleThread(void *opaque ATTRIBUTE_UNUSED)</div>
<div>>                  return;</div>
<div>>              }</div>
<div>>  </div>
<div>> -            virObjectLock(priv);</div>
<div>> -            priv->dataReady = false;</div>
<div>> -            virObjectUnlock(priv);</div>
<div>> -</div>
<div>>              continue;</div>
<div>>          }</div>
<div>>  </div>
<div>> </div>
</div></blockquote>
</body></html>