ut/reduce: move ut_compress/decompress functions
This just moves code to prepare for these functions to be used earlier in the file without adding extra function declarations. Move ut_build_data_buffer as well for similar reasons. Signed-off-by: Jim Harris <james.r.harris@intel.com> Change-Id: Ifd4fb4abbd43aaa01fca3b73bbfd847ffdd4d6f7 Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/449512 Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Reviewed-by: Paul Luse <paul.e.luse@intel.com> Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com> Reviewed-by: Ben Walker <benjamin.walker@intel.com>
This commit is contained in:
parent
fa0d54d431
commit
27631eb571
@ -389,6 +389,84 @@ backing_dev_io_execute(uint32_t count)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
ut_compress(char *outbuf, uint32_t *compressed_len, char *inbuf, uint32_t inbuflen)
|
||||||
|
{
|
||||||
|
uint32_t len = 0;
|
||||||
|
uint8_t count;
|
||||||
|
char last;
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
if (inbuflen == 0) {
|
||||||
|
*compressed_len = len;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (*compressed_len < (len + 2)) {
|
||||||
|
return -ENOSPC;
|
||||||
|
}
|
||||||
|
|
||||||
|
last = *inbuf;
|
||||||
|
count = 1;
|
||||||
|
inbuflen--;
|
||||||
|
inbuf++;
|
||||||
|
|
||||||
|
while (inbuflen > 0 && *inbuf == last && count < UINT8_MAX) {
|
||||||
|
count++;
|
||||||
|
inbuflen--;
|
||||||
|
inbuf++;
|
||||||
|
}
|
||||||
|
|
||||||
|
outbuf[len] = count;
|
||||||
|
outbuf[len + 1] = last;
|
||||||
|
len += 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
ut_decompress(uint8_t *outbuf, uint32_t *compressed_len, uint8_t *inbuf, uint32_t inbuflen)
|
||||||
|
{
|
||||||
|
uint32_t len = 0;
|
||||||
|
|
||||||
|
SPDK_CU_ASSERT_FATAL(inbuflen % 2 == 0);
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
if (inbuflen == 0) {
|
||||||
|
*compressed_len = len;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((len + inbuf[0]) > *compressed_len) {
|
||||||
|
return -ENOSPC;
|
||||||
|
}
|
||||||
|
|
||||||
|
memset(outbuf, inbuf[1], inbuf[0]);
|
||||||
|
outbuf += inbuf[0];
|
||||||
|
len += inbuf[0];
|
||||||
|
inbuflen -= 2;
|
||||||
|
inbuf += 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
ut_build_data_buffer(uint8_t *data, uint32_t data_len, uint8_t init_val, uint32_t repeat)
|
||||||
|
{
|
||||||
|
uint32_t _repeat = repeat;
|
||||||
|
|
||||||
|
SPDK_CU_ASSERT_FATAL(repeat > 0);
|
||||||
|
|
||||||
|
while (data_len > 0) {
|
||||||
|
*data = init_val;
|
||||||
|
data++;
|
||||||
|
data_len--;
|
||||||
|
_repeat--;
|
||||||
|
if (_repeat == 0) {
|
||||||
|
init_val++;
|
||||||
|
_repeat = repeat;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
backing_dev_compress(struct spdk_reduce_backing_dev *backing_dev,
|
backing_dev_compress(struct spdk_reduce_backing_dev *backing_dev,
|
||||||
struct iovec *src_iov, int src_iovcnt,
|
struct iovec *src_iov, int src_iovcnt,
|
||||||
@ -1052,84 +1130,6 @@ overlapped(void)
|
|||||||
backing_dev_destroy(&backing_dev);
|
backing_dev_destroy(&backing_dev);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
|
||||||
ut_compress(char *outbuf, uint32_t *compressed_len, char *inbuf, uint32_t inbuflen)
|
|
||||||
{
|
|
||||||
uint32_t len = 0;
|
|
||||||
uint8_t count;
|
|
||||||
char last;
|
|
||||||
|
|
||||||
while (true) {
|
|
||||||
if (inbuflen == 0) {
|
|
||||||
*compressed_len = len;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (*compressed_len < (len + 2)) {
|
|
||||||
return -ENOSPC;
|
|
||||||
}
|
|
||||||
|
|
||||||
last = *inbuf;
|
|
||||||
count = 1;
|
|
||||||
inbuflen--;
|
|
||||||
inbuf++;
|
|
||||||
|
|
||||||
while (inbuflen > 0 && *inbuf == last && count < UINT8_MAX) {
|
|
||||||
count++;
|
|
||||||
inbuflen--;
|
|
||||||
inbuf++;
|
|
||||||
}
|
|
||||||
|
|
||||||
outbuf[len] = count;
|
|
||||||
outbuf[len + 1] = last;
|
|
||||||
len += 2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
|
||||||
ut_decompress(uint8_t *outbuf, uint32_t *compressed_len, uint8_t *inbuf, uint32_t inbuflen)
|
|
||||||
{
|
|
||||||
uint32_t len = 0;
|
|
||||||
|
|
||||||
SPDK_CU_ASSERT_FATAL(inbuflen % 2 == 0);
|
|
||||||
|
|
||||||
while (true) {
|
|
||||||
if (inbuflen == 0) {
|
|
||||||
*compressed_len = len;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((len + inbuf[0]) > *compressed_len) {
|
|
||||||
return -ENOSPC;
|
|
||||||
}
|
|
||||||
|
|
||||||
memset(outbuf, inbuf[1], inbuf[0]);
|
|
||||||
outbuf += inbuf[0];
|
|
||||||
len += inbuf[0];
|
|
||||||
inbuflen -= 2;
|
|
||||||
inbuf += 2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
ut_build_data_buffer(uint8_t *data, uint32_t data_len, uint8_t init_val, uint32_t repeat)
|
|
||||||
{
|
|
||||||
uint32_t _repeat = repeat;
|
|
||||||
|
|
||||||
SPDK_CU_ASSERT_FATAL(repeat > 0);
|
|
||||||
|
|
||||||
while (data_len > 0) {
|
|
||||||
*data = init_val;
|
|
||||||
data++;
|
|
||||||
data_len--;
|
|
||||||
_repeat--;
|
|
||||||
if (_repeat == 0) {
|
|
||||||
init_val++;
|
|
||||||
_repeat = repeat;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#define BUFSIZE 4096
|
#define BUFSIZE 4096
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
Loading…
Reference in New Issue
Block a user