From 627645acc074eab7a3694a267bc2a643d8b3e57a Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Fri, 5 Feb 2016 15:05:30 +0100 Subject: First steps in make signals more abstract from the underlying mechanism; replace epoll with poll. We now don't assume that a signal equals a single fd (eventfd on Linux). The next step would be to create a version of signal.c that uses a pipe internally, so it can be used on other platforms, like *BSD. This is also the reason epoll was replaced with poll in uplink.c --- src/fuse/connection.c | 16 ++++++++-------- src/fuse/connection.h | 3 ++- src/fuse/main.c | 6 +++--- 3 files changed, 13 insertions(+), 12 deletions(-) (limited to 'src/fuse') diff --git a/src/fuse/connection.c b/src/fuse/connection.c index 170e329..65483a5 100644 --- a/src/fuse/connection.c +++ b/src/fuse/connection.c @@ -46,7 +46,7 @@ static struct { static struct { int sockFd; pthread_mutex_t sendMutex; - int panicSignalFd; + dnbd3_signal_t* panicSignal; dnbd3_host_t currentServer; uint64_t startupTime; } connection; @@ -134,7 +134,7 @@ bool connection_init(const char *hosts, const char *lowerImage, const uint16_t r image.rid = remoteRid; image.size = remoteSize; connection.currentServer = altservers[i].host; - connection.panicSignalFd = signal_new(); + connection.panicSignal = signal_new(); connection.startupTime = nowMilli(); connection.sockFd = sock; requests.head = NULL; @@ -205,7 +205,7 @@ bool connection_read(dnbd3_async_t *request) shutdown( connection.sockFd, SHUT_RDWR ); connection.sockFd = -1; pthread_mutex_unlock( &connection.sendMutex ); - signal_call( connection.panicSignalFd ); + signal_call( connection.panicSignal ); return true; } } @@ -316,7 +316,7 @@ static void* connection_receiveThreadMain(void *sockPtr) // Success, wake up caller request->success = true; request->finished = true; - signal_call( request->signalFd ); + signal_call( request->signal ); } } else if ( reply.cmd == CMD_GET_SERVERS ) { // List of known alt servers @@ -348,7 +348,7 @@ fail:; logadd( LOG_DEBUG1, "RT: Local sock: %d, global: %d", sockFd, connection.sockFd ); if ( connection.sockFd == sockFd ) { connection.sockFd = -1; - signal_call( connection.panicSignalFd ); + signal_call( connection.panicSignal ); } pthread_mutex_unlock( &connection.sendMutex ); // As we're the only reader, it's safe to close the socket now @@ -365,7 +365,7 @@ static void* connection_backgroundThread(void *something UNUSED) const uint64_t now = nowMilli(); if ( now < nextKeepalive && now < nextRttCheck ) { int waitTime = (int)( MIN( nextKeepalive, nextRttCheck ) - now ); - int waitRes = signal_wait( connection.panicSignalFd, waitTime ); + int waitRes = signal_wait( connection.panicSignal, waitTime ); if ( waitRes == SIGNAL_ERROR ) { logadd( LOG_WARNING, "Error waiting on signal in background thread! Errno = %d", errno ); } @@ -585,7 +585,7 @@ static void switchConnection(int sockFd, alt_server_t *srv) if ( ret != 0 ) { close( sockFd ); logadd( LOG_WARNING, "Could not getpeername after connection switch, assuming connection already dead again. (Errno=%d)", errno ); - signal_call( connection.panicSignalFd ); + signal_call( connection.panicSignal ); return; } connection.startupTime = nowMilli(); @@ -604,7 +604,7 @@ static void switchConnection(int sockFd, alt_server_t *srv) logadd( LOG_WARNING, "Resending pending request failed, re-entering panic mode" ); shutdown( connection.sockFd, SHUT_RDWR ); connection.sockFd = -1; - signal_call( connection.panicSignalFd ); + signal_call( connection.panicSignal ); } } pthread_mutex_unlock( &connection.sendMutex ); diff --git a/src/fuse/connection.h b/src/fuse/connection.h index 06db6c4..f01577d 100644 --- a/src/fuse/connection.h +++ b/src/fuse/connection.h @@ -1,6 +1,7 @@ #ifndef _CONNECTION_H_ #define _CONNECTION_H_ +#include "../shared/signal.h" #include #include @@ -11,7 +12,7 @@ typedef struct _dnbd3_async { char* buffer; // Caller-provided buffer to be filled uint64_t offset; uint32_t length; - int signalFd; // Used to signal the caller + dnbd3_signal_t* signal; // Used to signal the caller bool finished; // Will be set to true if the request has been handled bool success; // Will be set to true if the request succeeded } dnbd3_async_t; diff --git a/src/fuse/main.c b/src/fuse/main.c index 22c400e..cf35596 100644 --- a/src/fuse/main.c +++ b/src/fuse/main.c @@ -136,13 +136,13 @@ static int image_read(const char *path, char *buf, size_t size, off_t offset, st request.buffer = buf; request.length = (uint32_t)size; request.offset = offset; - request.signalFd = signal_newBlocking(); + request.signal = signal_newBlocking(); if ( !connection_read( &request ) ) { return -EINVAL; } while ( !request.finished ) { - int ret = signal_wait( request.signalFd, 5000 ); + int ret = signal_wait( request.signal, 5000 ); if ( !keepRunning ) { connection_close(); break; @@ -151,7 +151,7 @@ static int image_read(const char *path, char *buf, size_t size, off_t offset, st debugf( "fuse_read signal wait returned %d", ret ); } } - signal_close( request.signalFd ); + signal_close( request.signal ); if ( request.success ) { return request.length; } else { -- cgit v1.2.3-55-g7522