1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-01-03 05:18:29 +03:00

clvmd: add special lvm thread exit

When multiple threads act on the same 'quit' variable
the order of exit becomes unpredictable.

So let the main_loop() finish first and then clean up
all queued lvm jobs.

Do not add any new work, when lvm_thread_exit is set.
This commit is contained in:
Zdenek Kabelac 2014-03-21 18:01:38 +01:00
parent 05a532e171
commit 8431d47b3b

View File

@ -89,6 +89,7 @@ static pthread_t lvm_thread;
/* Stack size 128KiB for thread, must be bigger then DEFAULT_RESERVED_STACK */ /* Stack size 128KiB for thread, must be bigger then DEFAULT_RESERVED_STACK */
static const size_t STACK_SIZE = 128 * 1024; static const size_t STACK_SIZE = 128 * 1024;
static pthread_attr_t stack_attr; static pthread_attr_t stack_attr;
static int lvm_thread_exit = 0;
static pthread_mutex_t lvm_thread_mutex; static pthread_mutex_t lvm_thread_mutex;
static pthread_cond_t lvm_thread_cond; static pthread_cond_t lvm_thread_cond;
static pthread_barrier_t lvm_start_barrier; static pthread_barrier_t lvm_start_barrier;
@ -617,6 +618,7 @@ int main(int argc, char *argv[])
main_loop(local_sock, cmd_timeout); main_loop(local_sock, cmd_timeout);
pthread_mutex_lock(&lvm_thread_mutex); pthread_mutex_lock(&lvm_thread_mutex);
lvm_thread_exit = 1;
pthread_cond_signal(&lvm_thread_cond); pthread_cond_signal(&lvm_thread_cond);
pthread_mutex_unlock(&lvm_thread_mutex); pthread_mutex_unlock(&lvm_thread_mutex);
if ((errno = pthread_join(lvm_thread, NULL))) if ((errno = pthread_join(lvm_thread, NULL)))
@ -2081,7 +2083,7 @@ static void *lvm_thread_fn(void *arg)
/* Now wait for some actual work */ /* Now wait for some actual work */
pthread_mutex_lock(&lvm_thread_mutex); pthread_mutex_lock(&lvm_thread_mutex);
while (!quit) { while (!lvm_thread_exit)
if (dm_list_empty(&lvm_cmd_head)) { if (dm_list_empty(&lvm_cmd_head)) {
DEBUGLOG("LVM thread waiting for work\n"); DEBUGLOG("LVM thread waiting for work\n");
pthread_cond_wait(&lvm_thread_cond, &lvm_thread_mutex); pthread_cond_wait(&lvm_thread_cond, &lvm_thread_mutex);
@ -2097,7 +2099,6 @@ static void *lvm_thread_fn(void *arg)
pthread_mutex_lock(&lvm_thread_mutex); pthread_mutex_lock(&lvm_thread_mutex);
} }
}
pthread_mutex_unlock(&lvm_thread_mutex); pthread_mutex_unlock(&lvm_thread_mutex);
@ -2110,6 +2111,9 @@ static int add_to_lvmqueue(struct local_client *client, struct clvm_header *msg,
{ {
struct lvm_thread_cmd *cmd; struct lvm_thread_cmd *cmd;
if (lvm_thread_exit)
return -1; /* We are about to exit */
cmd = malloc(sizeof(struct lvm_thread_cmd)); cmd = malloc(sizeof(struct lvm_thread_cmd));
if (!cmd) if (!cmd)
return ENOMEM; return ENOMEM;