[libvirt] [PATCH 5/6] Add an an internal API for emergency dump of debug buffer

Daniel Veillard veillard at redhat.com
Mon Mar 7 13:18:46 UTC 2011


On Mon, Mar 07, 2011 at 10:18:57AM +0000, Daniel P. Berrange wrote:
> On Mon, Mar 07, 2011 at 03:06:18PM +0800, Daniel Veillard wrote:
> > On Fri, Mar 04, 2011 at 08:53:55AM -0700, Eric Blake wrote:
> > > Is virLogLock async-signal-safe?
> > 
> >   I could not find, I'm afraid it's implementation dependant. I would
> > expect the lock to be done in user space using an atomic test and set
> > op and hence being safe at least on i386 and x86_64.
> >   The problem is that if we drop the lock we can crash if used on USR2
> > while another thread is legitimately running.
> 
> Even if the impl was robust there is an architectural problem
> with mixing of mutexes and signals. If a thread is running
> virLogMessage(), it will be holding the log mutex. If a signal
> is processed, and it calls into this new log code, it will
> likely deadlock.

  right this is the only thing that really makes the USR2 debug
dangerous IMHO, and we should try to fix it.

> Is there a way we can somehow make the global log buffer into
> something that can be lockless for readers. ie although our
> main log funcs would still need to use the mutex in general
> when writing to the buffer, we could read the log buffer
> without any locks.

  the problem is that I really want to empty the buffer as a
result of emitting the logs, i.e. the reader will emit only once
the content at most.

> It would probably suffice to make sure we use atomic integer
> arithmetic on virLogLen, virLogStart and virLogEnd, and update
> them in a specific order to avoid a reader seeing garbage.

honnestly I would not be chagrined by the probability of emitting
a little bit of garbage when flushing the logs or one or two items.
I think we can work lockless there, by registering the initial values
of virLogStart and virLogEnd when entering the routine, emit whever is
in those boundaries with the tiny risk that some of it may be
overwritten (at the beginning hence the less interesting stuff) and
on exit set back virLogStart = virLogEnd and virLogLen = 0, possibly
loosing whetver might have been emitted between the beginning of the
save and the exit from the routine.

Daniel

-- 
Daniel Veillard      | libxml Gnome XML XSLT toolkit  http://xmlsoft.org/
daniel at veillard.com  | Rpmfind RPM search engine http://rpmfind.net/
http://veillard.com/ | virtualization library  http://libvirt.org/




More information about the libvir-list mailing list