mirror of https://gitee.com/openkylin/libvirt.git
Make error reporting in libvirtd thread safe
Bug https://bugzilla.redhat.com/show_bug.cgi?id=689374 reported libvirtd crash during error dispatch. The reason is that libvirtd uses remoteDispatchConnError() with non-NULL conn parameter which means that virConnGetLastError() is used instead of its thread safe replacement virGetLastError(). So when several libvirtd threads are reporting errors at the same time, the errors can get mixed or corrupted or in case of bad luck libvirtd itself crashes. Since Daniel B. is going to rewrite this code from scratch on top of his RPC infrastructure, I tried to come up with a minimal fix. Thus, remoteDispatchConnError() now just ignores its conn argument and always calls virGetLastError(). However, several callers had to be touched as well, since no libvirt API is allowed to be called before dispatching the error. Doing so would reset the error and we would have nothing to dispatch. As a result of that, the code is not very nice but that doesn't really make daemon/remote.c worse than it is now :-) And it will all die soon, which is good. The bug report also contains a reproducer in C which detects both mixed up error messages and libvirtd crash. Before this patch, I was able to crash libvirtd in about 20 seconds up to 3 minutes depending on number of CPU cores (more is better) and luck.
This commit is contained in:
parent
9450a7cbef
commit
f44bfb7fb9
|
@ -113,14 +113,10 @@ void remoteDispatchOOMError (remote_error *rerr)
|
|||
|
||||
|
||||
void remoteDispatchConnError (remote_error *rerr,
|
||||
virConnectPtr conn)
|
||||
virConnectPtr conn ATTRIBUTE_UNUSED)
|
||||
{
|
||||
virErrorPtr verr;
|
||||
virErrorPtr verr = virGetLastError();
|
||||
|
||||
if (conn)
|
||||
verr = virConnGetLastError(conn);
|
||||
else
|
||||
verr = virGetLastError();
|
||||
if (verr)
|
||||
remoteDispatchCopyError(rerr, verr);
|
||||
else
|
||||
|
|
240
daemon/remote.c
240
daemon/remote.c
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue