xref: /freebsd/sys/contrib/openzfs/lib/libnvpair/nvpair_alloc_system.c (revision 22649d4dba730d46244fd2dff4fd174903c8379f)
1 // SPDX-License-Identifier: CDDL-1.0
2 /*
3  * This file and its contents are supplied under the terms of the
4  * Common Development and Distribution License ("CDDL"), version 1.0.
5  * You may only use this file in accordance with the terms of version
6  * 1.0 of the CDDL.
7  *
8  * A full copy of the text of the CDDL should have accompanied this
9  * source.  A copy of the CDDL is also available via the Internet at
10  * https://opensource.org/license/CDDL-1.0.
11  */
12 /*
13  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
14  * Use is subject to license terms.
15  */
16 
17 
18 
19 #include <rpc/types.h>
20 #include <sys/kmem.h>
21 #include <sys/nvpair.h>
22 
23 static void *
nv_alloc_sys(nv_alloc_t * nva,size_t size)24 nv_alloc_sys(nv_alloc_t *nva, size_t size)
25 {
26 	return (kmem_alloc(size, (int)(uintptr_t)nva->nva_arg));
27 }
28 
29 static void
nv_free_sys(nv_alloc_t * nva,void * buf,size_t size)30 nv_free_sys(nv_alloc_t *nva, void *buf, size_t size)
31 {
32 	(void) nva;
33 	kmem_free(buf, size);
34 }
35 
36 static const nv_alloc_ops_t system_ops = {
37 	NULL,			/* nv_ao_init() */
38 	NULL,			/* nv_ao_fini() */
39 	nv_alloc_sys,		/* nv_ao_alloc() */
40 	nv_free_sys,		/* nv_ao_free() */
41 	NULL			/* nv_ao_reset() */
42 };
43 
44 static nv_alloc_t nv_alloc_sleep_def = {
45 	&system_ops,
46 	(void *)KM_SLEEP
47 };
48 
49 static nv_alloc_t nv_alloc_nosleep_def = {
50 	&system_ops,
51 	(void *)KM_NOSLEEP
52 };
53 
54 nv_alloc_t *const nv_alloc_sleep = &nv_alloc_sleep_def;
55 nv_alloc_t *const nv_alloc_nosleep = &nv_alloc_nosleep_def;
56