diff options
author | Simon Rettberg | 2024-04-24 10:49:55 +0200 |
---|---|---|
committer | Simon Rettberg | 2024-05-13 18:26:42 +0200 |
commit | 03f16dd5d06460eca4ac50ba54e46001b4d34de8 (patch) | |
tree | 2ea390db48a1ef6a64e287da3623f4902d6f046c /src | |
parent | [FUSE] Fix uninitialized speed buffer (diff) | |
download | dnbd3-03f16dd5d06460eca4ac50ba54e46001b4d34de8.tar.gz dnbd3-03f16dd5d06460eca4ac50ba54e46001b4d34de8.tar.xz dnbd3-03f16dd5d06460eca4ac50ba54e46001b4d34de8.zip |
[FUSE] Fix race condition
Diffstat (limited to 'src')
-rw-r--r-- | src/fuse/cowfile.c | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/src/fuse/cowfile.c b/src/fuse/cowfile.c index 90ea568..4e27f56 100644 --- a/src/fuse/cowfile.c +++ b/src/fuse/cowfile.c @@ -1355,12 +1355,15 @@ static bool padBlockForWrite( fuse_req_t req, cow_request_t *cowRequest, sub->dRequest.offset = startOffset & ~DNBD3_BLOCK_MASK; sub->dRequest.fuse_req = req; + atomic_fetch_add( &cowRequest->workCounter, 1 ); + if ( !connection_read( &sub->dRequest ) ) { free( sub ); errno = ENOTSOCK; + // Don't need to go via finishWriteRequest here since the caller will take care of error handling + atomic_fetch_sub( &cowRequest->workCounter, 1 ); return false; } - atomic_fetch_add( &cowRequest->workCounter, 1 ); return true; } @@ -1560,6 +1563,7 @@ fail: if ( cowRequest->errorCode == 0 ) { cowRequest->errorCode = errno != 0 ? errno : EIO; } + // Fallthrough success: finishWriteRequest( req, cowRequest ); } |