diff options
author | Simon Rettberg | 2020-07-24 14:24:38 +0200 |
---|---|---|
committer | Simon Rettberg | 2020-07-24 14:24:38 +0200 |
commit | fa9c5cb8c07f98511e98572c379c63a2f9afc425 (patch) | |
tree | 7dc1191345b1710020def6c30f4d31afa319211e /src/fuse | |
parent | [FUSE] Cleanup (diff) | |
download | dnbd3-fa9c5cb8c07f98511e98572c379c63a2f9afc425.tar.gz dnbd3-fa9c5cb8c07f98511e98572c379c63a2f9afc425.tar.xz dnbd3-fa9c5cb8c07f98511e98572c379c63a2f9afc425.zip |
[FUSE] Fix returning pending request on RTT measurement
Diffstat (limited to 'src/fuse')
-rw-r--r-- | src/fuse/connection.c | 16 | ||||
-rw-r--r-- | src/fuse/connection.h | 2 | ||||
-rw-r--r-- | src/fuse/main.c | 5 |
3 files changed, 8 insertions, 15 deletions
diff --git a/src/fuse/connection.c b/src/fuse/connection.c index 2fa7c57..7bd8018 100644 --- a/src/fuse/connection.c +++ b/src/fuse/connection.c @@ -385,13 +385,10 @@ static void* connection_receiveThreadMain( void *sockPtr ) } } else { // Found a match - request->buffer = malloc( request->length ); // char* const ssize_t ret = sock_recv( sockFd, request->buffer, request->length ); if ( ret != (ssize_t)request->length ) { logadd( LOG_DEBUG1, "receiving payload for a block reply failed" ); connection_read( request ); - free( request->buffer ); - request->buffer = NULL; goto fail; } // Check RTT @@ -409,15 +406,8 @@ static void* connection_receiveThreadMain( void *sockPtr ) } unlock_rw( &altLock ); } - int fuse_reply = fuse_reply_buf( request->fuse_req, request->buffer, request->length ); - if ( fuse_reply != 0 ) { - printf( "ERROR ON FUSE REPLY %i \n", fuse_reply ); - fuse_reply_err( request->fuse_req, fuse_reply ); - } - free( request->buffer ); - request->buffer = NULL; + fuse_reply_buf( request->fuse_req, request->buffer, request->length ); free( request ); - request = NULL; } } else if ( reply.cmd == CMD_GET_SERVERS ) { // List of known alt servers @@ -715,7 +705,9 @@ static void probeAltServers() connection_read( request ); goto fail; } - // Success, wake up caller + // Success, reply to fuse + fuse_reply_buf( request->fuse_req, 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 diff --git a/src/fuse/connection.h b/src/fuse/connection.h index 58017dd..be0115e 100644 --- a/src/fuse/connection.h +++ b/src/fuse/connection.h @@ -16,11 +16,11 @@ struct _dnbd3_async; typedef struct _dnbd3_async { struct _dnbd3_async *next; // Next in this linked list (provate field, not set by caller) - char* buffer; // Caller-provided buffer to be filled ticks time; // When request was put on wire, 0 if not measuring uint64_t offset; uint32_t length; fuse_req_t fuse_req; + char buffer[]; // Must be last member! } dnbd3_async_t; bool connection_init( const char *hosts, const char *image, const uint16_t rid, const bool learnNewServers ); diff --git a/src/fuse/main.c b/src/fuse/main.c index 736dfc8..df30602 100644 --- a/src/fuse/main.c +++ b/src/fuse/main.c @@ -207,7 +207,7 @@ static void image_ll_read( fuse_req_t req, fuse_ino_t ino, size_t size, off_t of if ( offset + size > imageSize ) { size = imageSize - offset; } - if ( size == 0 ) { + if ( size == 0 || size > UINT32_MAX ) { fuse_reply_err( req, 0 ); return; } @@ -221,13 +221,14 @@ static void image_ll_read( fuse_req_t req, fuse_ino_t ino, size_t size, off_t of ++logInfo.blockRequestCount[startBlock]; } } - dnbd3_async_t *request = malloc( sizeof(dnbd3_async_t) ); + dnbd3_async_t *request = malloc( sizeof(dnbd3_async_t) + size ); request->length = (uint32_t)size; request->offset = offset; request->fuse_req = req; if ( !connection_read( request ) ) { fuse_reply_err( req, EIO ); + free( request ); } } |