diff options
author | Simon Rettberg | 2024-04-24 10:49:55 +0200 |
---|---|---|
committer | Simon Rettberg | 2024-04-24 10:49:55 +0200 |
commit | 90c8e4877f9dd9a07f5fa2c5f8b5af6e14505509 (patch) | |
tree | 5cda79b493ef525967c453fe33fc34502b7a00d7 | |
parent | [FUSE] Fix uninitialized speed buffer (diff) | |
download | dnbd3-90c8e4877f9dd9a07f5fa2c5f8b5af6e14505509.tar.gz dnbd3-90c8e4877f9dd9a07f5fa2c5f8b5af6e14505509.tar.xz dnbd3-90c8e4877f9dd9a07f5fa2c5f8b5af6e14505509.zip |
[FUSE] Fix race condition
-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 ); } |