[libvirt] [PATCH v5] Add functions for handling exponential backoff loops.

Michal Privoznik mprivozn at redhat.com
Fri Apr 15 15:10:29 UTC 2016


On 15.04.2016 16:59, Peter Krempa wrote:
> On Fri, Apr 15, 2016 at 16:45:07 +0200, Michal Privoznik wrote:
>> On 15.04.2016 13:53, Richard W.M. Jones wrote:
>>> In a few places in libvirt we busy-wait for events, for example qemu
>>> creating a monitor socket.  This is problematic because:
>>>
>>>  - We need to choose a sufficiently small polling period so that
>>>    libvirt doesn't add unnecessary delays.
>>>
>>>  - We need to choose a sufficiently large polling period so that
>>>    the effect of busy-waiting doesn't affect the system.
>>>
>>> The solution to this conflict is to use an exponential backoff.
>>>
>>> This patch adds two functions to hide the details, and modifies a few
>>> places where we currently busy-wait.
>>> ---
>>>  src/fdstream.c           | 10 +++---
>>>  src/libvirt_private.syms |  2 ++
>>>  src/qemu/qemu_agent.c    |  9 +++---
>>>  src/qemu/qemu_monitor.c  | 10 +++---
>>>  src/util/virtime.c       | 81 ++++++++++++++++++++++++++++++++++++++++++++++++
>>>  src/util/virtime.h       | 11 +++++++
>>>  6 files changed, 111 insertions(+), 12 deletions(-)
>>
>> ACK. Sorry for making you send v5 to such simple patch.
> 
> GCC 5.3.0 doesn't like this very much:
> 
> qemu/qemu_agent.c:238:8: error: 'ret' may be used uninitialized in this function [-Werror=maybe-uninitialized]
>      if (ret != 0) {
> 
> qemu/qemu_monitor.c:369:8: error: 'ret' may be used uninitialized in this function [-Werror=maybe-uninitialized]
>      if (ret != 0) {
> 
> The static analyzer considers the possibility that the while loop will
> never execute, which would be possible in a very strange lockup of the
> host.
> 
> Please initialize ret to -1 before pushing in those two functions.
> 
> Peter
> 

I wonder why my compiler (gcc-4.9.3) hadn't caught those ... Well,
thanks Peter for pointing it out.

Michal




More information about the libvir-list mailing list