libnv: Allow use in non-sleepable contexts

44c125c4ce switched the nvlist allocations
to be M_WAITOK, but this precludes the use in non-sleepable contexts.
(E.g. with a nonsleepable lock held).

All callers for these allocation functions already cope with memory
alloation failures, so there's no reason to allow sleeping during
allocations.

Reviewed by:	melifaro, oshogbo
MFC after:	1 week
Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D29556
This commit is contained in:
Kristof Provost 2021-03-25 13:59:14 +01:00
parent 5a5623397c
commit ab8d25880e

View File

@ -52,13 +52,13 @@ typedef struct nvpair nvpair_t;
#define NV_FLAG_IN_ARRAY 0x100
#ifdef _KERNEL
#define nv_malloc(size) malloc((size), M_NVLIST, M_WAITOK)
#define nv_malloc(size) malloc((size), M_NVLIST, M_NOWAIT)
#define nv_calloc(n, size) mallocarray((n), (size), M_NVLIST, \
M_WAITOK | M_ZERO)
M_NOWAIT | M_ZERO)
#define nv_realloc(buf, size) realloc((buf), (size), M_NVLIST, \
M_WAITOK)
M_NOWAIT)
#define nv_free(buf) free((buf), M_NVLIST)
#define nv_strdup(buf) strdup((buf), M_NVLIST)
#define nv_strdup(buf) strdup_flags((buf), M_NVLIST, M_NOWAIT)
#define nv_vasprintf(ptr, ...) vasprintf(ptr, M_NVLIST, __VA_ARGS__)
#define ERRNO_SET(var) do { } while (0)