1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-21 13:34:40 +03:00

clvmd: move mutex init and detroy

Move the pthread mutex and condition creation and destroy
to correct place right after client memory is allocatedd
or is going to be released.

In the original place it's been in race with lvm thread
which could have still unlock mutex while it's been already
destroyed.
This commit is contained in:
Zdenek Kabelac 2014-04-09 08:06:16 +02:00
parent 91f4e09b48
commit cc0096ebdd
2 changed files with 8 additions and 12 deletions

View File

@ -1,5 +1,6 @@
Version 2.02.107 - Version 2.02.107 -
================================== ==================================
Shift mutex creation and destroy for localsock in clvmd to correct place.
Fix usage of --test option in clvmd. Fix usage of --test option in clvmd.
Skip more libraries to be mlocked in memory. Skip more libraries to be mlocked in memory.
Remove LOCKED flag for pvmove replaced with error target. Remove LOCKED flag for pvmove replaced with error target.

View File

@ -685,6 +685,10 @@ static int local_rendezvous_callback(struct local_client *thisfd, char *buf,
return 1; return 1;
} }
pthread_cond_init(&newfd->bits.localsock.cond, NULL);
pthread_mutex_init(&newfd->bits.localsock.mutex, NULL);
pthread_mutex_init(&newfd->bits.localsock.reply_mutex, NULL);
if (fcntl(client_fd, F_SETFD, 1)) if (fcntl(client_fd, F_SETFD, 1))
DEBUGLOG("Setting CLOEXEC on client fd failed: %s\n", strerror(errno)); DEBUGLOG("Setting CLOEXEC on client fd failed: %s\n", strerror(errno));
@ -1179,8 +1183,6 @@ static int cleanup_zombie(struct local_client *thisfd)
DEBUGLOG("Joined pre&post thread\n"); DEBUGLOG("Joined pre&post thread\n");
thisfd->bits.localsock.threadid = 0; thisfd->bits.localsock.threadid = 0;
pthread_cond_destroy(&thisfd->bits.localsock.cond);
pthread_mutex_destroy(&thisfd->bits.localsock.mutex);
/* Remove the pipe client */ /* Remove the pipe client */
if (thisfd->bits.localsock.pipe_client) { if (thisfd->bits.localsock.pipe_client) {
@ -1321,16 +1323,6 @@ static int read_from_local_sock(struct local_client *thisfd)
} }
} }
/*
* Initialise and lock the mutex so the subthread will wait
* after finishing the PRE routine
*/
if (!thisfd->bits.localsock.threadid) {
pthread_mutex_init(&thisfd->bits.localsock.mutex, NULL);
pthread_cond_init(&thisfd->bits.localsock.cond, NULL);
pthread_mutex_init(&thisfd->bits.localsock.reply_mutex, NULL);
}
/* Only run the command if all the cluster nodes are running CLVMD */ /* Only run the command if all the cluster nodes are running CLVMD */
if (((inheader->flags & CLVMD_FLAG_LOCAL) == 0) && if (((inheader->flags & CLVMD_FLAG_LOCAL) == 0) &&
(check_all_clvmds_running(thisfd) == -1)) { (check_all_clvmds_running(thisfd) == -1)) {
@ -1975,6 +1967,9 @@ static int process_work_item(struct lvm_thread_cmd *cmd)
if (cmd->msg == NULL) { if (cmd->msg == NULL) {
DEBUGLOG("process_work_item: free fd %d\n", cmd->client->fd); DEBUGLOG("process_work_item: free fd %d\n", cmd->client->fd);
cmd_client_cleanup(cmd->client); cmd_client_cleanup(cmd->client);
pthread_mutex_destroy(&cmd->client->bits.localsock.reply_mutex);
pthread_mutex_destroy(&cmd->client->bits.localsock.mutex);
pthread_cond_destroy(&cmd->client->bits.localsock.cond);
dm_free(cmd->client); dm_free(cmd->client);
return 0; return 0;
} }