summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rettberg2014-12-31 20:44:32 +0100
committerSimon Rettberg2014-12-31 20:44:32 +0100
commit5b322c5d9ba4c0706c66055be980a814de837002 (patch)
treea71282a7896e28bfaeef038cbd04ed32f24ff0a7
parent[SERVER] Create compilation unit for wait/signalling logic (using eventfd) (diff)
downloaddnbd3-5b322c5d9ba4c0706c66055be980a814de837002.tar.gz
dnbd3-5b322c5d9ba4c0706c66055be980a814de837002.tar.xz
dnbd3-5b322c5d9ba4c0706c66055be980a814de837002.zip
[SERVER] Minor tweaks and improvements
-rw-r--r--src/server/integrity.c12
-rw-r--r--src/server/locks.c6
-rw-r--r--src/server/net.c2
-rw-r--r--src/server/server.c4
4 files changed, 15 insertions, 9 deletions
diff --git a/src/server/integrity.c b/src/server/integrity.c
index 16bc9eb..245d394 100644
--- a/src/server/integrity.c
+++ b/src/server/integrity.c
@@ -28,8 +28,8 @@ static pthread_t thread;
static queue_entry checkQueue[CHECK_QUEUE_SIZE];
static pthread_mutex_t integrityQueueLock;
static pthread_cond_t queueSignal;
-static int queueLen = -1;
-static int bRunning = FALSE;
+static volatile int queueLen = -1;
+static volatile int bRunning = FALSE;
static void* integrity_main(void *data);
@@ -103,6 +103,7 @@ static void* integrity_main(void *data)
uint8_t *buffer = NULL;
size_t bufferSize = 0;
setThreadName( "image-check" );
+ blockNoncriticalSignals();
#if defined(linux) || defined(__linux)
// Setting nice of this thread - this is not POSIX conforming, so check if other platforms support this.
// POSIX says that setpriority() should set the nice value of all threads belonging to the current process,
@@ -112,7 +113,11 @@ static void* integrity_main(void *data)
#endif
pthread_mutex_lock( &integrityQueueLock );
while ( !_shutdown ) {
+ if ( queueLen == 0 ) {
+ pthread_cond_wait( &queueSignal, &integrityQueueLock );
+ }
for (i = queueLen - 1; i >= 0; --i) {
+ if ( _shutdown ) break;
if ( checkQueue[i].image == NULL ) continue;
dnbd3_image_t * const image = image_lock( checkQueue[i].image );
checkQueue[i].image = NULL;
@@ -149,9 +154,6 @@ static void* integrity_main(void *data)
// Release :-)
image_release( image );
}
- if ( queueLen == 0 ) {
- pthread_cond_wait( &queueSignal, &integrityQueueLock );
- }
}
pthread_mutex_unlock( &integrityQueueLock );
if ( buffer != NULL ) free( buffer );
diff --git a/src/server/locks.c b/src/server/locks.c
index d93be40..65e3abd 100644
--- a/src/server/locks.c
+++ b/src/server/locks.c
@@ -17,6 +17,7 @@
#include "globals.h"
#include "memlog.h"
#include "helper.h"
+#include "signal.h"
#define MAXLOCKS 2000
#define MAXTHREADS 500
@@ -49,6 +50,7 @@ static int init_done = 0;
static pthread_spinlock_t initdestory;
static volatile int lockId = 0;
static pthread_t watchdog = 0;
+static int watchdogSignal = -1;
static void *debug_thread_watchdog(void *something);
@@ -276,7 +278,7 @@ static void *debug_thread_watchdog(void *something)
}
pthread_spin_unlock( &initdestory );
}
- sleep( 5 );
+ if ( watchdogSignal == -1 || signal_wait( watchdogSignal, 5000 ) == SIGNAL_ERROR ) sleep( 5 );
}
return NULL ;
}
@@ -290,6 +292,7 @@ void debug_locks_start_watchdog()
memlogf( "[ERROR] Could not start debug-lock watchdog." );
return;
}
+ watchdogSignal = signal_new();
#endif
}
@@ -299,6 +302,7 @@ void debug_locks_stop_watchdog()
_shutdown = TRUE;
printf( "Killing debug watchdog...\n" );
pthread_spin_lock( &initdestory );
+ signal_call( watchdogSignal );
pthread_spin_unlock( &initdestory );
thread_join( watchdog, NULL );
#endif
diff --git a/src/server/net.c b/src/server/net.c
index a0362c2..ee621f8 100644
--- a/src/server/net.c
+++ b/src/server/net.c
@@ -307,7 +307,7 @@ void *net_client_handler(void *dnbd3_client)
const ssize_t ret = sendfile( client->sock, image_file, &offset, request.size - done );
if ( ret <= 0 ) {
pthread_mutex_unlock( &client->sendMutex );
- printf( "[ERROR] sendfile failed (image to net. ret=%d, sent %d/%d, errno=%d)\n",
+ printf( "[DEBUG] sendfile failed (image to net. ret=%d, sent %d/%d, errno=%d)\n",
(int)ret, (int)done, (int)request.size, (int)errno );
goto exit_client_cleanup;
}
diff --git a/src/server/server.c b/src/server/server.c
index e502543..3c3fa06 100644
--- a/src/server/server.c
+++ b/src/server/server.c
@@ -446,8 +446,10 @@ void dnbd3_remove_client(dnbd3_client_t *client)
dnbd3_client_t* dnbd3_free_client(dnbd3_client_t *client)
{
spin_lock( &client->lock );
+ pthread_mutex_lock( &client->sendMutex );
if ( client->sock >= 0 ) close( client->sock );
client->sock = -1;
+ pthread_mutex_unlock( &client->sendMutex );
if ( client->image != NULL ) {
spin_lock( &client->image->lock );
if ( client->image->uplink != NULL ) uplink_removeClient( client->image->uplink, client );
@@ -457,8 +459,6 @@ dnbd3_client_t* dnbd3_free_client(dnbd3_client_t *client)
client->image = NULL;
spin_unlock( &client->lock );
spin_destroy( &client->lock );
- pthread_mutex_lock( &client->sendMutex );
- pthread_mutex_unlock( &client->sendMutex );
pthread_mutex_destroy( &client->sendMutex );
free( client );
return NULL ;