Linux Device Mapper development
 help / color / mirror / Atom feed
From: Christophe Varoqui <christophe.varoqui@gmail.com>
To: Hannes Reinecke <hare@suse.de>
Cc: dm-devel@redhat.com
Subject: Re: [PATCH 25/42] Make log_pthread more robust
Date: Wed, 09 Jan 2013 01:16:12 +0100	[thread overview]
Message-ID: <1357690572.12137.17.camel@lapoo.opensvc.com> (raw)
In-Reply-To: <1357653259-62650-26-git-send-email-hare@suse.de>

On mar., 2013-01-08 at 14:54 +0100, Hannes Reinecke wrote:
> We don't need to allocate memory for mutexes, we can just
> be using static variables. And valgrind complained about
> logqueue flush from shutdown, so don't do this.
> The normal shutdown process should be flushing the log
> queue anyway.
> 
It seems the log_thread_flush() function is missing from the patchset.
Care to send the incremental patch ?

Regards,
Christophe Varoqui
www.opensvc.com

> Signed-off-by: Hannes Reinecke <hare@suse.de>
> ---
>  libmultipath/log_pthread.c |  101 +++++++++++++++++++++++++++++--------------
>  libmultipath/log_pthread.h |   10 +++--
>  2 files changed, 74 insertions(+), 37 deletions(-)
> 
> diff --git a/libmultipath/log_pthread.c b/libmultipath/log_pthread.c
> index d701ba1..9e92a70 100644
> --- a/libmultipath/log_pthread.c
> +++ b/libmultipath/log_pthread.c
> @@ -13,20 +13,41 @@
>  #include "log.h"
>  #include "lock.h"
>  
> +pthread_t log_thr;
> +
> +pthread_mutex_t logq_lock;
> +pthread_mutex_t logev_lock;
> +pthread_cond_t logev_cond;
> +
> +int logq_running;
> +
> +static void
> +sigusr1 (int sig)
> +{
> +	pthread_mutex_lock(&logq_lock);
> +	log_reset("multipathd");
> +	pthread_mutex_unlock(&logq_lock);
> +}
> +
>  void log_safe (int prio, const char * fmt, va_list ap)
>  {
>  	sigset_t old;
>  
> +	if (log_thr == (pthread_t)0) {
> +		syslog(prio, fmt, ap);
> +		return;
> +	}
> +
>  	block_signal(SIGUSR1, &old);
>  	block_signal(SIGHUP, NULL);
>  
> -	pthread_mutex_lock(logq_lock);
> +	pthread_mutex_lock(&logq_lock);
>  	log_enqueue(prio, fmt, ap);
> -	pthread_mutex_unlock(logq_lock);
> +	pthread_mutex_unlock(&logq_lock);
>  
> -	pthread_mutex_lock(logev_lock);
> -	pthread_cond_signal(logev_cond);
> -	pthread_mutex_unlock(logev_lock);
> +	pthread_mutex_lock(&logev_lock);
> +	pthread_cond_signal(&logev_cond);
> +	pthread_mutex_unlock(&logev_lock);
>  
>  	pthread_sigmask(SIG_SETMASK, &old, NULL);
>  }
> @@ -36,9 +57,9 @@ static void flush_logqueue (void)
>  	int empty;
>  
>  	do {
> -		pthread_mutex_lock(logq_lock);
> +		pthread_mutex_lock(&logq_lock);
>  		empty = log_dequeue(la->buff);
> -		pthread_mutex_unlock(logq_lock);
> +		pthread_mutex_unlock(&logq_lock);
>  		if (!empty)
>  			log_syslog(la->buff);
>  	} while (empty == 0);
> @@ -46,15 +67,30 @@ static void flush_logqueue (void)
>  
>  static void * log_thread (void * et)
>  {
> +	struct sigaction sig;
> +	int running;
> +
> +	sig.sa_handler = sigusr1;
> +	sigemptyset(&sig.sa_mask);
> +	sig.sa_flags = 0;
> +	if (sigaction(SIGUSR1, &sig, NULL) < 0)
> +		logdbg(stderr, "Cannot set signal handler");
> +
> +	pthread_mutex_lock(&logev_lock);
> +	logq_running = 1;
> +	pthread_mutex_unlock(&logev_lock);
> +
>  	mlockall(MCL_CURRENT | MCL_FUTURE);
>  	logdbg(stderr,"enter log_thread\n");
>  
>  	while (1) {
> -		pthread_mutex_lock(logev_lock);
> -		pthread_cond_wait(logev_cond, logev_lock);
> -		pthread_mutex_unlock(logev_lock);
> -
> -		flush_logqueue();
> +		pthread_mutex_lock(&logev_lock);
> +		pthread_cond_wait(&logev_cond, &logev_lock);
> +		running = logq_running;
> +		pthread_mutex_unlock(&logev_lock);
> +		if (!running)
> +			break;
> +		log_thread_flush();
>  	}
>  	return NULL;
>  }
> @@ -63,19 +99,18 @@ void log_thread_start (pthread_attr_t *attr)
>  {
>  	logdbg(stderr,"enter log_thread_start\n");
>  
> -	logq_lock = (pthread_mutex_t *) malloc(sizeof(pthread_mutex_t));
> -	logev_lock = (pthread_mutex_t *) malloc(sizeof(pthread_mutex_t));
> -	logev_cond = (pthread_cond_t *) malloc(sizeof(pthread_cond_t));
> -
> -	pthread_mutex_init(logq_lock, NULL);
> -	pthread_mutex_init(logev_lock, NULL);
> -	pthread_cond_init(logev_cond, NULL);
> +	pthread_mutex_init(&logq_lock, NULL);
> +	pthread_mutex_init(&logev_lock, NULL);
> +	pthread_cond_init(&logev_cond, NULL);
>  
>  	if (log_init("multipathd", 0)) {
>  		fprintf(stderr,"can't initialize log buffer\n");
>  		exit(1);
>  	}
> -	pthread_create(&log_thr, attr, log_thread, NULL);
> +	if (pthread_create(&log_thr, attr, log_thread, NULL)) {
> +		fprintf(stderr,"can't start log thread\n");
> +		exit(1);
> +	}
>  
>  	return;
>  }
> @@ -84,22 +119,22 @@ void log_thread_stop (void)
>  {
>  	logdbg(stderr,"enter log_thread_stop\n");
>  
> -	pthread_mutex_lock(logq_lock);
> +	pthread_mutex_lock(&logev_lock);
> +	logq_running = 0;
> +	pthread_cond_signal(&logev_cond);
> +	pthread_mutex_unlock(&logev_lock);
> +
> +	pthread_mutex_lock(&logq_lock);
>  	pthread_cancel(log_thr);
> -	pthread_mutex_unlock(logq_lock);
> +	pthread_mutex_unlock(&logq_lock);
>  	pthread_join(log_thr, NULL);
> +	log_thr = (pthread_t)0;
>  
>  	flush_logqueue();
>  
> -	pthread_mutex_destroy(logq_lock);
> -	pthread_mutex_destroy(logev_lock);
> -	pthread_cond_destroy(logev_cond);
> -
> -	free(logq_lock);
> -	logq_lock = NULL;
> -	free(logev_lock);
> -	logev_lock = NULL;
> -	free(logev_cond);
> -	logev_cond = NULL;
> -	free_logarea();
> +	pthread_mutex_destroy(&logq_lock);
> +	pthread_mutex_destroy(&logev_lock);
> +	pthread_cond_destroy(&logev_cond);
> +
> +	log_close();
>  }
> diff --git a/libmultipath/log_pthread.h b/libmultipath/log_pthread.h
> index 77780d8..f3b70ea 100644
> --- a/libmultipath/log_pthread.h
> +++ b/libmultipath/log_pthread.h
> @@ -3,11 +3,13 @@
>  
>  #include <pthread.h>
>  
> -pthread_t log_thr;
> +extern pthread_t log_thr;
>  
> -pthread_mutex_t *logq_lock;
> -pthread_mutex_t *logev_lock;
> -pthread_cond_t *logev_cond;
> +extern pthread_mutex_t logq_lock;
> +extern pthread_mutex_t logev_lock;
> +extern pthread_cond_t logev_cond;
> +
> +extern int logq_running;
>  
>  void log_safe(int prio, const char * fmt, va_list ap);
>  void log_thread_start(pthread_attr_t *attr);

  reply	other threads:[~2013-01-09  0:16 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-01-08 13:53 [PATCH 00/42] SLES resync Hannes Reinecke
2013-01-08 13:53 ` [PATCH 01/42] libmultipath: Invalid check for mpp->wwid in dm_addmap() Hannes Reinecke
2013-01-08 13:53 ` [PATCH 02/42] Remove newline from condlog() Hannes Reinecke
2013-01-08 13:53 ` [PATCH 03/42] Fixup pathgroup allocation in disassemble_map() Hannes Reinecke
2013-01-08 13:53 ` [PATCH 04/42] libmultipath: resource leak in read_value_block() Hannes Reinecke
2013-01-08 13:53 ` [PATCH 05/42] prio: fix merging of prioritizers with different args Hannes Reinecke
2013-01-08 13:53 ` [PATCH 06/42] Accept several whitespaces in bindings file Hannes Reinecke
2013-01-08 13:53 ` [PATCH 07/42] Add TAGS makefile target Hannes Reinecke
2013-01-08 13:53 ` [PATCH 08/42] libmultipath: Fix typo in mp_prio_handler() Hannes Reinecke
2013-01-08 13:53 ` [PATCH 09/42] Do not trigger a map reload on priority updates Hannes Reinecke
2013-01-08 13:53 ` [PATCH 10/42] Introduce MP_FAST_IO_FAIL_UNSET Hannes Reinecke
2013-01-08 13:53 ` [PATCH 11/42] Checker name is not displayed on failure Hannes Reinecke
2013-01-08 13:53 ` [PATCH 12/42] Valgrind fixes for prioritizer Hannes Reinecke
2013-01-08 13:53 ` [PATCH 13/42] Incorrect inquiry vendor length in hds prioritizer Hannes Reinecke
2013-01-08 13:53 ` [PATCH 14/42] Print out multipath alias for flush_on_last_del messages Hannes Reinecke
2013-01-08 13:53 ` [PATCH 15/42] Clarify setting origin in propsel.c Hannes Reinecke
2013-01-08 13:53 ` [PATCH 16/42] libmultipath: error checking in remove_features() Hannes Reinecke
2013-01-08 13:53 ` [PATCH 17/42] Increase parameter buffer Hannes Reinecke
2013-01-08 13:53 ` [PATCH 18/42] Check return code from pathinfo() Hannes Reinecke
2013-01-08 13:53 ` [PATCH 19/42] Inconsistent string quoting Hannes Reinecke
2013-01-08 13:53 ` [PATCH 20/42] Switch off 'queue_if_no_path' before removing maps Hannes Reinecke
2013-01-08 13:53 ` [PATCH 21/42] Double free in disassemble_map() Hannes Reinecke
2013-01-08 13:54 ` [PATCH 22/42] libmultipath: prio keyword ignored for multipath config Hannes Reinecke
2013-01-08 13:54 ` [PATCH 23/42] Path checker should return PATH_DOWN when no path is found Hannes Reinecke
2013-01-08 13:54 ` [PATCH 24/42] Do not call sysfs_get_timeout for non-SCSI devices Hannes Reinecke
2013-01-08 13:54 ` [PATCH 25/42] Make log_pthread more robust Hannes Reinecke
2013-01-09  0:16   ` Christophe Varoqui [this message]
2013-01-09 19:15     ` Xose Vazquez Perez
2013-01-08 13:54 ` [PATCH 26/42] Print log messages when updating tables failed Hannes Reinecke
2013-01-08 13:54 ` [PATCH 27/42] Update 'no_path_retry' correctly for failed paths Hannes Reinecke
2013-01-08 13:54 ` [PATCH 28/42] Clean up uevent queue on shutdown Hannes Reinecke
2013-01-08 13:54 ` [PATCH 29/42] libmultipath: Print out uevent sequence number Hannes Reinecke
2013-01-08 13:54 ` [PATCH 30/42] Fix race condition in stop_waiter_thread() Hannes Reinecke
2013-01-08 13:54 ` [PATCH 31/42] Use VECTOR_SIZE() defines Hannes Reinecke
2013-01-08 13:54 ` [PATCH 32/42] Make 'allocated' an integer in vector.h Hannes Reinecke
2013-01-08 13:54 ` [PATCH 33/42] Syntax error in /etc/init.d/boot.multipath Hannes Reinecke
2013-01-08 13:54 ` [PATCH 34/42] multipath.init.suse: Update usage message Hannes Reinecke
2013-01-08 13:54 ` [PATCH 35/42] multipath.conf.5: Clarify dev_loss_tmo settings Hannes Reinecke
2013-01-08 13:54 ` [PATCH 36/42] Clarify dev_loss_tmo capping in multipath.conf.5 Hannes Reinecke
2013-01-08 13:54 ` [PATCH 38/42] multipathd: Ignore errors when creating pidfile Hannes Reinecke
2013-01-08 13:54 ` [PATCH 39/42] multipathd deadlocks during restart Hannes Reinecke
2013-01-08 13:54 ` [PATCH 40/42] multipathd: sighandlers might use uninitialized gvecs Hannes Reinecke
2013-01-08 13:54 ` [PATCH 41/42] multipathd: crash in reconfigure CLI command Hannes Reinecke
2013-01-08 13:54 ` [PATCH 42/42] multipathd: lock vectors during initial configuration Hannes Reinecke
2013-01-08 23:37   ` Christophe Varoqui
2013-01-09  7:01     ` Hannes Reinecke
2013-01-08 23:53 ` [PATCH 00/42] SLES resync Christophe Varoqui
2013-01-10  5:36   ` Benjamin Marzinski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1357690572.12137.17.camel@lapoo.opensvc.com \
    --to=christophe.varoqui@gmail.com \
    --cc=christophe.varoqui@opensvc.com \
    --cc=dm-devel@redhat.com \
    --cc=hare@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox