xref: /freebsd/sys/contrib/openzfs/module/nvpair/nvpair_alloc_spl.c (revision 61145dc2b94f12f6a47344fb9aac702321880e43)
1 // SPDX-License-Identifier: CDDL-1.0
2 /*
3  * CDDL HEADER START
4  *
5  * The contents of this file are subject to the terms of the
6  * Common Development and Distribution License, Version 1.0 only
7  * (the "License").  You may not use this file except in compliance
8  * with the License.
9  *
10  * You can obtain a copy of the license at * usr/src/OPENSOLARIS.LICENSE
11  * or https://opensource.org/licenses/CDDL-1.0.
12  * See the License for the specific language governing permissions
13  * and limitations under the License.
14  *
15  * When distributing Covered Code, include this CDDL HEADER in each
16  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
17  * If applicable, add the following below this CDDL HEADER, with the
18  * fields enclosed by brackets "[]" replaced with your own identifying
19  * information: Portions Copyright [yyyy] [name of copyright owner]
20  *
21  * CDDL HEADER END
22  */
23 /*
24  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
25  * Use is subject to license terms.
26  */
27 
28 #include <sys/nvpair.h>
29 #include <sys/kmem.h>
30 #include <sys/vmem.h>
31 
32 static void *
nv_alloc_sleep_spl(nv_alloc_t * nva,size_t size)33 nv_alloc_sleep_spl(nv_alloc_t *nva, size_t size)
34 {
35 	return (vmem_alloc(size, KM_SLEEP));
36 }
37 
38 static void *
nv_alloc_pushpage_spl(nv_alloc_t * nva,size_t size)39 nv_alloc_pushpage_spl(nv_alloc_t *nva, size_t size)
40 {
41 	return (vmem_alloc(size, KM_PUSHPAGE));
42 }
43 
44 static void *
nv_alloc_nosleep_spl(nv_alloc_t * nva,size_t size)45 nv_alloc_nosleep_spl(nv_alloc_t *nva, size_t size)
46 {
47 	return (kmem_alloc(size, KM_NOSLEEP));
48 }
49 
50 static void
nv_free_spl(nv_alloc_t * nva,void * buf,size_t size)51 nv_free_spl(nv_alloc_t *nva, void *buf, size_t size)
52 {
53 	kmem_free(buf, size);
54 }
55 
56 static const nv_alloc_ops_t spl_sleep_ops_def = {
57 	.nv_ao_init = NULL,
58 	.nv_ao_fini = NULL,
59 	.nv_ao_alloc = nv_alloc_sleep_spl,
60 	.nv_ao_free = nv_free_spl,
61 	.nv_ao_reset = NULL
62 };
63 
64 static const nv_alloc_ops_t spl_pushpage_ops_def = {
65 	.nv_ao_init = NULL,
66 	.nv_ao_fini = NULL,
67 	.nv_ao_alloc = nv_alloc_pushpage_spl,
68 	.nv_ao_free = nv_free_spl,
69 	.nv_ao_reset = NULL
70 };
71 
72 static const nv_alloc_ops_t spl_nosleep_ops_def = {
73 	.nv_ao_init = NULL,
74 	.nv_ao_fini = NULL,
75 	.nv_ao_alloc = nv_alloc_nosleep_spl,
76 	.nv_ao_free = nv_free_spl,
77 	.nv_ao_reset = NULL
78 };
79 
80 static nv_alloc_t nv_alloc_sleep_def = {
81 	&spl_sleep_ops_def,
82 	NULL
83 };
84 
85 static nv_alloc_t nv_alloc_pushpage_def = {
86 	&spl_pushpage_ops_def,
87 	NULL
88 };
89 
90 static nv_alloc_t nv_alloc_nosleep_def = {
91 	&spl_nosleep_ops_def,
92 	NULL
93 };
94 
95 nv_alloc_t *const nv_alloc_sleep = &nv_alloc_sleep_def;
96 nv_alloc_t *const nv_alloc_pushpage = &nv_alloc_pushpage_def;
97 nv_alloc_t *const nv_alloc_nosleep = &nv_alloc_nosleep_def;
98