diff options
Diffstat (limited to 'src/fuse/connection.c')
-rw-r--r-- | src/fuse/connection.c | 51 |
1 files changed, 43 insertions, 8 deletions
diff --git a/src/fuse/connection.c b/src/fuse/connection.c index e760d98..dede680 100644 --- a/src/fuse/connection.c +++ b/src/fuse/connection.c @@ -6,6 +6,8 @@ #include <dnbd3/shared/sockhelper.h> #include <dnbd3/shared/log.h> +#include "main.h" +#include "cowfile.h" #include <stdlib.h> #include <pthread.h> #include <string.h> @@ -108,6 +110,7 @@ static bool hasAltServer( dnbd3_host_t *host ); static void addAltServers( void ); static void sortAltServers(); static void probeAltServers(); +static size_t receiveRequest(const int sock, dnbd3_async_t* request ); static void switchConnection( int sockFd, alt_server_t *srv ); static void requestAltServers( void ); static bool sendAltServerRequest( int sock ); @@ -349,6 +352,17 @@ bool connection_initThreads() return success; } +char * connection_getImageName() +{ + return image.name; +} + +uint16_t connection_getImageRID() +{ + return image.rid; +} + + uint64_t connection_getImageSize() { return image.size; @@ -492,7 +506,7 @@ static void* connection_receiveThreadMain( void *sockPtr ) } } else { // Found a match - const ssize_t ret = sock_recv( sockFd, request->buffer, request->length ); + const ssize_t ret = receiveRequest( sockFd, request ); if ( ret != (ssize_t)request->length ) { logadd( LOG_DEBUG1, "receiving payload for a block reply failed" ); connection_read( request ); @@ -513,8 +527,14 @@ static void* connection_receiveThreadMain( void *sockPtr ) } unlock_rw( &altLock ); } - fuse_reply_buf( request->fuse_req, request->buffer, request->length ); - free( request ); + // TODO: See comment in receiveRequest() + if( useCow ) { + cowfile_handleCallback( request ); + } + else { + fuse_reply_buf( request->fuse_req, container_of( request, dnbd3_async_parent_t, request )->buffer, request->length ); + free( request ); + } } } else if ( reply.cmd == CMD_GET_SERVERS ) { // List of known alt servers @@ -565,8 +585,8 @@ static void* connection_backgroundThread( void *something UNUSED ) while ( keepRunning ) { ticks now; timing_get( &now ); - uint32_t wt1 = timing_diffMs( &now, &nextKeepalive ); - uint32_t wt2 = timing_diffMs( &now, &nextRttCheck ); + uint32_t wt1 = (uint32_t)timing_diffMs( &now, &nextKeepalive ); + uint32_t wt2 = (uint32_t)timing_diffMs( &now, &nextRttCheck ); if ( wt1 > 0 && wt2 > 0 ) { int waitRes = signal_wait( connection.panicSignal, (int)MIN( wt1, wt2 ) + 1 ); if ( !keepRunning ) @@ -812,7 +832,7 @@ static void probeAltServers() } if ( request != NULL && removeRequest( request ) != NULL ) { // Request successfully removed from queue - const ssize_t ret = sock_recv( sock, request->buffer, request->length ); + ssize_t const ret = receiveRequest( sock, request); if ( ret != (ssize_t)request->length ) { logadd( LOG_DEBUG1, "%s probe: receiving payload for a block reply failed", hstr ); // Failure, add to queue again @@ -820,8 +840,13 @@ static void probeAltServers() goto fail; } // Success, reply to fuse - fuse_reply_buf( request->fuse_req, request->buffer, request->length ); - free( request ); + if( useCow ) { + cowfile_handleCallback( request ); + } + else { + fuse_reply_buf( request->fuse_req, container_of( request, dnbd3_async_parent_t, request )->buffer, request->length ); + free( request ); + } logadd( LOG_DEBUG1, "%s probe: Successful direct probe", hstr ); } else { // Wasn't a request that's in our request queue @@ -931,6 +956,16 @@ fail: } } +static size_t receiveRequest(const int sock, dnbd3_async_t* request ) +{ + if( useCow ) { + cow_sub_request_t * cow_request = container_of( request, cow_sub_request_t, dRequest ); + return sock_recv( sock, cow_request->buffer, request->length ); + } else { + return sock_recv( sock, container_of( request, dnbd3_async_parent_t, request )->buffer, request->length ); + } +} + static void switchConnection( int sockFd, alt_server_t *srv ) { struct sockaddr_storage addr; |