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)