From 907ec7268d37451bc56e847606cb5d227510a58f Mon Sep 17 00:00:00 2001 From: paul luse Date: Mon, 22 Jul 2019 13:56:11 -0400 Subject: [PATCH] lib/reduce: conditionally memcpy data to host follow decompression If the decompression code path runs into a chunk that wasn't compressed, the data needs to be copied to the host as the compression engine was not engaged. Signed-off-by: paul luse Change-Id: Ibabd6d6bd2bc5db79953a0a55d7f49d556c08af7 Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/462892 Tested-by: SPDK CI Jenkins Reviewed-by: Jim Harris Reviewed-by: Shuhei Matsumoto --- lib/reduce/reduce.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lib/reduce/reduce.c b/lib/reduce/reduce.c index 912746fbd..be22cfe2a 100644 --- a/lib/reduce/reduce.c +++ b/lib/reduce/reduce.c @@ -1273,6 +1273,9 @@ static void _read_read_done(void *_req, int reduce_errno) { struct spdk_reduce_vol_request *req = _req; + uint64_t chunk_offset; + uint8_t *buf; + int i; if (reduce_errno != 0) { req->reduce_errno = reduce_errno; @@ -1291,6 +1294,17 @@ _read_read_done(void *_req, int reduce_errno) if (req->chunk_is_compressed) { _reduce_vol_decompress_chunk(req, _read_decompress_done); } else { + + /* If the chunk was compressed, the data would have been sent to the + * host buffers by the decompression operation, if not we need to memcpy here. + */ + chunk_offset = req->offset % req->vol->logical_blocks_per_chunk; + buf = req->decomp_buf + chunk_offset * req->vol->params.logical_block_size; + for (i = 0; i < req->iovcnt; i++) { + memcpy(req->iov[i].iov_base, buf, req->iov[i].iov_len); + buf += req->iov[i].iov_len; + } + _read_decompress_done(req, req->chunk->compressed_size); } }