1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-22 17:35:59 +03:00
lvm2/daemons/clvmd
Petr Rockai d28c8ccfbd Fix a deadlock in clvmd.
The signalling code (pthread_cond_signal/pthread_cond_wait) in the
pre_and_post_thread was using the wait mutex (see man pthread_cond_wait)
incorrectly, and this could cause clvmd to deadlock when timing was
right. Detailed explanation of the problem follows.

There is a single mutex around (L for Lock, U for Unlock), a signal (S) and a
wait (W). C for pthread_create. Time flows from left to right, each arrow is a
thread.

So first the "naive" scenario, with no mutex (PPT = pre_and_post_thread, MCT =
main clvmd thread; well actually the thread that does read_from_local_sock). I
will also use X, for a moment when MCT actually waits for something to happen
that PPT was supposed to do.


MCT -----C ------S--X-----S----X----------------------S------XXXXXXXXX
         |                everything OK up to this --> <-- point...
PPT       -----WWW-----WWWW------------------------------WWWWWWWWWWWWW

Ok, so pthread API actually does not let you use W/S like that. It goes out of
its way to tell you that you need a mutex to protect the W so that the above
cannot happen. *But* if you are creative and just lock around the W's and S's,
this happens:

MCT ----C-----LSU----X-----LSU----X------------LSU------XXXXXXX
        |
PPT      ---LWWWU-------LWWWWU-----------------------LWWWWWWWWW

Ooops. Nothing changed (the above is what actually was done by clvmd before
this satch). So let's do it differently, holding L locked *all* the time in
PPT, unless we are actually in W (this is something that the pthread API does
itself, see the man page).

MCT ----C-----LSU------X---LSU---X-----LLLLLLLSU----X----
        |                             (and they live happily ever after)
PPT     L---WWWWW---------WWWW----------------W----------

So W actually ensures that L is unlocked *atomically* together with entering
the wait. That means that unless PPT is actually waiting, it cannot be
signalled by MCT. So if MCT happens to signal it too soon (it wasn't waiting
yet), it (MCT) will be blocked on the mutex (L), until PPT is actually ready to
do something.
2010-10-20 14:46:45 +00:00
..
clvm.h Change clvmd to communicate with lvm via a socket in /var/run/lvm. (mbroz) 2010-07-28 13:55:42 +00:00
clvmd-cman.c Various cleanups following recent commits. 2010-06-21 15:56:57 +00:00
clvmd-command.c Fix a deadlock in clvmd. 2010-10-20 14:46:45 +00:00
clvmd-common.h Various cleanups following recent commits. 2010-06-21 15:56:57 +00:00
clvmd-comms.h Avoid duplicate definitions. 2010-03-23 14:35:08 +00:00
clvmd-corosync.c Various cleanups following recent commits. 2010-06-21 15:56:57 +00:00
clvmd-gulm.c Various cleanups following recent commits. 2010-06-21 15:56:57 +00:00
clvmd-gulm.h Clean up cluster lock mode and flags definition. 2010-06-17 12:48:54 +00:00
clvmd-openais.c Various cleanups following recent commits. 2010-06-21 15:56:57 +00:00
clvmd-singlenode.c Fix wrong use of LCK_WRITE 2010-08-19 23:26:31 +00:00
clvmd.c Fix a deadlock in clvmd. 2010-10-20 14:46:45 +00:00
clvmd.h Change clvmd to communicate with lvm via a socket in /var/run/lvm. (mbroz) 2010-07-28 13:55:42 +00:00
lvm-functions.c Use 'SINGLENODE' instead of 'dead' in clvmd singlenode messages. 2010-08-17 19:25:05 +00:00
lvm-functions.h Allow internal suspend and resume of origin without its snapshots. 2010-08-17 16:25:32 +00:00
Makefile.in INSTALL rules updates 2010-04-09 21:42:48 +00:00
refresh_clvmd.c Fix another segfault in clvmd -R if no response from daemon received. 2010-07-01 21:46:09 +00:00
refresh_clvmd.h Add -S command to clvmd, so it can restart itself and still 2010-04-20 14:07:37 +00:00
tcp-comms.c Various cleanups following recent commits. 2010-06-21 15:56:57 +00:00
tcp-comms.h Fix clvmd if compiled with gulm support. (2.02.26) 2007-07-24 15:35:11 +00:00