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 <dariusz.stojaczyk@intel.com>
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/448169
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
This commit is contained in:
Darek Stojaczyk 2019-03-15 14:42:52 +01:00
parent 5118004b1d
commit 40678c15ed
3 changed files with 30 additions and 0 deletions

View File

@ -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().
*

View File

@ -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)
{

View File

@ -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)