From 40678c15ed2d9adfede581793bcce82a4c340d20 Mon Sep 17 00:00:00 2001 From: Darek Stojaczyk Date: Fri, 15 Mar 2019 14:42:52 +0100 Subject: [PATCH] env: add spdk_realloc() It's a copy of spdk_dma_realloc() matching the new spdk_malloc() naming convention. Change-Id: I8e1b24aa0bae064392fe0f4ebc08c5723d9a5f1a Signed-off-by: Darek Stojaczyk Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/448169 Tested-by: SPDK CI Jenkins Reviewed-by: Jim Harris Reviewed-by: Shuhei Matsumoto --- include/spdk/env.h | 15 +++++++++++++++ lib/env_dpdk/env.c | 6 ++++++ test/common/lib/test_env.c | 9 +++++++++ 3 files changed, 30 insertions(+) diff --git a/include/spdk/env.h b/include/spdk/env.h index 395915a58..d8bca3cf0 100644 --- a/include/spdk/env.h +++ b/include/spdk/env.h @@ -130,6 +130,21 @@ void *spdk_malloc(size_t size, size_t align, uint64_t *phys_addr, int socket_id, */ void *spdk_zmalloc(size_t size, size_t align, uint64_t *phys_addr, int socket_id, uint32_t flags); +/** + * Resize a dma/sharable memory buffer with the given new size and alignment. + * Existing contents are preserved. + * + * \param buf Buffer to resize. + * \param size Size in bytes. + * \param align Alignment value for the allocated memory. If '0', the allocated + * buffer is suitably aligned (in the same manner as malloc()). Otherwise, the + * allocated buffer is aligned to the multiple of align. In this case, it must + * be a power of two. + * + * \return a pointer to the resized memory buffer. + */ +void *spdk_realloc(void *buf, size_t size, size_t align); + /** * Free buffer memory that was previously allocated with spdk_malloc() or spdk_zmalloc(). * diff --git a/lib/env_dpdk/env.c b/lib/env_dpdk/env.c index 28b8862d6..ac9f702c1 100644 --- a/lib/env_dpdk/env.c +++ b/lib/env_dpdk/env.c @@ -89,6 +89,12 @@ spdk_zmalloc(size_t size, size_t align, uint64_t *phys_addr, int socket_id, uint return buf; } +void * +spdk_realloc(void *buf, size_t size, size_t align) +{ + return rte_realloc(buf, size, align); +} + void spdk_free(void *buf) { diff --git a/test/common/lib/test_env.c b/test/common/lib/test_env.c index 0b8cc74b1..44a3cf16a 100644 --- a/test/common/lib/test_env.c +++ b/test/common/lib/test_env.c @@ -114,6 +114,15 @@ spdk_dma_malloc(size_t size, size_t align, uint64_t *phys_addr) return spdk_malloc(size, align, phys_addr, -1, 1); } +DEFINE_RETURN_MOCK(spdk_realloc, void *); +void * +spdk_realloc(void *buf, size_t size, size_t align) +{ + HANDLE_RETURN_MOCK(spdk_realloc); + + return realloc(buf, size); +} + DEFINE_RETURN_MOCK(spdk_dma_zmalloc, void *); void * spdk_dma_zmalloc(size_t size, size_t align, uint64_t *phys_addr)