xref: /freebsd/sys/contrib/openzfs/include/sys/nvpair_impl.h (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 /*
29  * Copyright (c) 2017 by Delphix. All rights reserved.
30  */
31 
32 #ifndef	_NVPAIR_IMPL_H
33 #define	_NVPAIR_IMPL_H
34 
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
38 
39 #include <sys/nvpair.h>
40 
41 /*
42  * The structures here provided for information and debugging purposes only
43  * may be changed in the future.
44  */
45 
46 /*
47  * implementation linked list for pre-packed data
48  */
49 typedef struct i_nvp i_nvp_t;
50 
51 struct i_nvp {
52 	union {
53 		/* ensure alignment */
54 		uint64_t	_nvi_align;
55 
56 		struct {
57 			/* pointer to next nvpair */
58 			i_nvp_t	*_nvi_next;
59 
60 			/* pointer to prev nvpair */
61 			i_nvp_t	*_nvi_prev;
62 
63 			/* next pair in table bucket */
64 			i_nvp_t	*_nvi_hashtable_next;
65 		} _nvi;
66 	} _nvi_un;
67 
68 	/* nvpair */
69 	nvpair_t nvi_nvp;
70 };
71 #define	nvi_next	_nvi_un._nvi._nvi_next
72 #define	nvi_prev	_nvi_un._nvi._nvi_prev
73 #define	nvi_hashtable_next	_nvi_un._nvi._nvi_hashtable_next
74 
75 typedef struct {
76 	i_nvp_t		*nvp_list;	/* linked list of nvpairs */
77 	i_nvp_t		*nvp_last;	/* last nvpair */
78 	const i_nvp_t	*nvp_curr;	/* current walker nvpair */
79 	nv_alloc_t	*nvp_nva;	/* pluggable allocator */
80 	uint32_t	nvp_stat;	/* internal state */
81 
82 	i_nvp_t		**nvp_hashtable; /* table of entries used for lookup */
83 	uint32_t	nvp_nbuckets;	/* # of buckets in hash table */
84 	uint32_t	nvp_nentries;	/* # of entries in hash table */
85 } nvpriv_t;
86 
87 #ifdef	__cplusplus
88 }
89 #endif
90 
91 #endif	/* _NVPAIR_IMPL_H */
92