xref: /illumos-gate/usr/src/lib/varpd/libvarpd/common/libvarpd_impl.h (revision 36589d6bb0cdae89e166b57b0d64ae56d53247d9)
1 /*
2  * This file and its contents are supplied under the terms of the
3  * Common Development and Distribution License ("CDDL"), version 1.0.
4  * You may only use this file in accordance with the terms of version
5  * 1.0 of the CDDL.
6  *
7  * A full copy of the text of the CDDL should have accompanied this
8  * source.  A copy of the CDDL is also available via the Internet at
9  * http://www.illumos.org/license/CDDL.
10  */
11 
12 /*
13  * Copyright 2015 Joyent, Inc.
14  */
15 
16 #ifndef _LIBVARPD_IMPL_H
17 #define	_LIBVARPD_IMPL_H
18 
19 /*
20  * varpd internal interfaces
21  */
22 
23 #include <libvarpd.h>
24 #include <libvarpd_provider.h>
25 #include <sys/avl.h>
26 #include <thread.h>
27 #include <synch.h>
28 #include <limits.h>
29 #include <libidspace.h>
30 #include <umem.h>
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
36 #define	LIBVARPD_ID_MIN	1
37 #define	LIBVARPD_ID_MAX	INT32_MAX
38 
39 typedef struct varpd_plugin {
40 	avl_node_t		vpp_node;
41 	const char		*vpp_name;
42 	overlay_target_mode_t	vpp_mode;
43 	const varpd_plugin_ops_t *vpp_ops;
44 	mutex_t			vpp_lock;
45 	uint_t			vpp_active;
46 } varpd_plugin_t;
47 
48 typedef struct varpd_impl {
49 	mutex_t		vdi_lock;
50 	rwlock_t	vdi_pfdlock;
51 	avl_tree_t	vdi_plugins;	/* vdi_lock */
52 	avl_tree_t	vdi_instances;	/* vdi_lock */
53 	avl_tree_t	vdi_linstances;	/* vdi_lock */
54 	id_space_t	*vdi_idspace;	/* RO */
55 	umem_cache_t	*vdi_qcache;	/* RO */
56 	int		vdi_overlayfd;	/* RO */
57 	int		vdi_doorfd;	/* vdi_lock */
58 	int		vdi_persistfd;	/* vdi_plock */
59 	cond_t		vdi_lthr_cv;	/* vdi_lock */
60 	boolean_t	vdi_lthr_quiesce;	/* vdi_lock */
61 	uint_t		vdi_lthr_count;	/* vdi_lock */
62 } varpd_impl_t;
63 
64 typedef enum varpd_instance_flags {
65 	VARPD_INSTANCE_F_ACTIVATED = 0x01
66 } varpd_instance_flags_t;
67 
68 typedef struct varpd_instance {
69 	avl_node_t	vri_inode;
70 	avl_node_t	vri_lnode;
71 	uint64_t	vri_id;			/* RO */
72 	uint64_t	vri_vnetid;		/* RO */
73 	datalink_id_t	vri_linkid;		/* RO */
74 	overlay_target_mode_t vri_mode;		/* RO */
75 	overlay_plugin_dest_t vri_dest;		/* RO */
76 	varpd_impl_t	*vri_impl;		/* RO */
77 	varpd_plugin_t	*vri_plugin;		/* RO */
78 	void		*vri_private;		/* RO */
79 	mutex_t		vri_lock;
80 	varpd_instance_flags_t vri_flags;	/* vri_lock */
81 } varpd_instance_t;
82 
83 typedef struct varpd_query {
84 	overlay_targ_lookup_t	vq_lookup;
85 	overlay_targ_resp_t	vq_response;
86 	varpd_instance_t	*vq_instance;
87 } varpd_query_t;
88 
89 typedef struct varpd_client_create_arg {
90 	datalink_id_t	vcca_linkid;
91 	uint64_t	vcca_id;
92 	char		vcca_plugin[LIBVARPD_PROP_NAMELEN];
93 } varpd_client_create_arg_t;
94 
95 typedef struct varpd_client_instance_arg {
96 	uint64_t	vcia_id;
97 } varpd_client_instance_arg_t;
98 
99 typedef struct varpd_client_nprops_arg {
100 	uint64_t	vcna_id;
101 	uint_t		vcna_nprops;
102 	uint8_t		vcna_pad[4];
103 } varpd_client_nprops_arg_t;
104 
105 typedef struct varpd_client_propinfo_arg {
106 	uint64_t	vcfa_id;
107 	uint_t		vcfa_propid;
108 	uint_t		vcfa_type;
109 	uint_t		vcfa_prot;
110 	uint32_t	vcfa_defsize;
111 	uint32_t	vcfa_psize;
112 	uint8_t		vcfa_pad[4];
113 	char		vcfa_name[LIBVARPD_PROP_NAMELEN];
114 	uint8_t		vcfa_default[LIBVARPD_PROP_SIZEMAX];
115 	uint8_t		vcfa_poss[LIBVARPD_PROP_SIZEMAX];
116 } varpd_client_propinfo_arg_t;
117 
118 typedef struct varpd_client_prop_arg {
119 	uint64_t	vcpa_id;
120 	uint_t		vcpa_propid;
121 	uint8_t		vcpa_buf[LIBVARPD_PROP_SIZEMAX];
122 	size_t		vcpa_bufsize;
123 } varpd_client_prop_arg_t;
124 
125 typedef struct varpd_client_lookup_arg {
126 	datalink_id_t	vcla_linkid;
127 	uint32_t	vcla_pad;
128 	uint64_t	vcla_id;
129 } varpd_client_lookup_arg_t;
130 
131 typedef struct varpd_client_target_mode_arg {
132 	uint64_t	vtma_id;
133 	uint32_t	vtma_dest;
134 	uint32_t	vtma_mode;
135 } varpd_client_target_mode_arg_t;
136 
137 typedef struct varpd_client_target_cache_arg {
138 	uint64_t	vtca_id;
139 	uint8_t		vtca_key[ETHERADDRL];
140 	uint8_t		vtca_pad[2];
141 	varpd_client_cache_entry_t vtca_entry;
142 } varpd_client_target_cache_arg_t;
143 
144 typedef struct varpd_client_target_walk_arg {
145 	uint64_t	vtcw_id;
146 	uint64_t	vtcw_marker;
147 	uint64_t	vtcw_count;
148 	overlay_targ_cache_entry_t vtcw_ents[];
149 } varpd_client_target_walk_arg_t;
150 
151 typedef enum varpd_client_command {
152 	VARPD_CLIENT_INVALID = 0x0,
153 	VARPD_CLIENT_CREATE,
154 	VARPD_CLIENT_ACTIVATE,
155 	VARPD_CLIENT_DESTROY,
156 	VARPD_CLIENT_NPROPS,
157 	VARPD_CLIENT_PROPINFO,
158 	VARPD_CLIENT_GETPROP,
159 	VARPD_CLIENT_SETPROP,
160 	VARPD_CLIENT_LOOKUP,
161 	VARPD_CLIENT_TARGET_MODE,
162 	VARPD_CLIENT_CACHE_FLUSH,
163 	VARPD_CLIENT_CACHE_DELETE,
164 	VARPD_CLIENT_CACHE_GET,
165 	VARPD_CLIENT_CACHE_SET,
166 	VARPD_CLIENT_CACHE_WALK,
167 	VARPD_CLIENT_MAX
168 } varpd_client_command_t;
169 
170 typedef struct varpd_client_arg {
171 	uint_t	vca_command;
172 	uint_t	vca_errno;
173 	union {
174 		varpd_client_create_arg_t vca_create;
175 		varpd_client_instance_arg_t vca_instance;
176 		varpd_client_nprops_arg_t vca_nprops;
177 		varpd_client_propinfo_arg_t vca_info;
178 		varpd_client_prop_arg_t vca_prop;
179 		varpd_client_lookup_arg_t vca_lookup;
180 		varpd_client_target_mode_arg_t vca_mode;
181 		varpd_client_target_cache_arg_t vca_cache;
182 		varpd_client_target_walk_arg_t vca_walk;
183 	} vca_un;
184 } varpd_client_arg_t;
185 
186 typedef struct varpd_client_eresp {
187 	uint_t vce_command;
188 	uint_t vce_errno;
189 } varpd_client_eresp_t;
190 
191 extern void libvarpd_plugin_init(void);
192 extern void libvarpd_plugin_prefork(void);
193 extern void libvarpd_plugin_postfork(void);
194 extern void libvarpd_plugin_fini(void);
195 extern int libvarpd_plugin_comparator(const void *, const void *);
196 extern varpd_plugin_t *libvarpd_plugin_lookup(varpd_impl_t *, const char *);
197 
198 extern varpd_instance_t *libvarpd_instance_lookup_by_dlid(varpd_impl_t *,
199     datalink_id_t);
200 
201 extern void libvarpd_prop_door_convert(const varpd_prop_handle_t *,
202     varpd_client_propinfo_arg_t *);
203 
204 extern const char *libvarpd_isaext(void);
205 typedef int (*libvarpd_dirwalk_f)(varpd_impl_t *, const char *, void *);
206 extern int libvarpd_dirwalk(varpd_impl_t *, const char *, const char *,
207     libvarpd_dirwalk_f, void *);
208 
209 extern int libvarpd_overlay_init(varpd_impl_t *);
210 extern void libvarpd_overlay_fini(varpd_impl_t *);
211 extern int libvarpd_overlay_info(varpd_impl_t *, datalink_id_t,
212     overlay_plugin_dest_t *, uint64_t *, uint64_t *);
213 extern int libvarpd_overlay_associate(varpd_instance_t *);
214 extern int libvarpd_overlay_disassociate(varpd_instance_t *);
215 extern int libvarpd_overlay_degrade(varpd_instance_t *, const char *);
216 extern int libvarpd_overlay_degrade_datalink(varpd_impl_t *, datalink_id_t,
217     const char *);
218 extern int libvarpd_overlay_restore(varpd_instance_t *);
219 extern int libvarpd_overlay_packet(varpd_impl_t *,
220     const overlay_targ_lookup_t *, void *, size_t *);
221 extern int libvarpd_overlay_inject(varpd_impl_t *,
222     const overlay_targ_lookup_t *, void *, size_t);
223 extern int libvarpd_overlay_instance_inject(varpd_instance_t *, void *, size_t);
224 extern int libvarpd_overlay_resend(varpd_impl_t *,
225     const overlay_targ_lookup_t *, void *, size_t);
226 typedef int (*libvarpd_overlay_iter_f)(varpd_impl_t *, datalink_id_t, void *);
227 extern int libvarpd_overlay_iter(varpd_impl_t *, libvarpd_overlay_iter_f,
228     void *);
229 extern int libvarpd_overlay_cache_flush(varpd_instance_t *);
230 extern int libvarpd_overlay_cache_delete(varpd_instance_t *, const uint8_t *);
231 extern int libvarpd_overlay_cache_delete(varpd_instance_t *, const uint8_t *);
232 extern int libvarpd_overlay_cache_get(varpd_instance_t *, const uint8_t *,
233     varpd_client_cache_entry_t *);
234 extern int libvarpd_overlay_cache_set(varpd_instance_t *, const uint8_t *,
235     const varpd_client_cache_entry_t *);
236 extern int libvarpd_overlay_cache_walk_fill(varpd_instance_t *, uint64_t *,
237     uint64_t *, overlay_targ_cache_entry_t *);
238 
239 extern void libvarpd_persist_init(varpd_impl_t *);
240 extern void libvarpd_persist_fini(varpd_impl_t *);
241 extern int libvarpd_persist_instance(varpd_impl_t *, varpd_instance_t *);
242 extern void libvarpd_torch_instance(varpd_impl_t *,  varpd_instance_t *);
243 
244 #ifdef __cplusplus
245 }
246 #endif
247 
248 #endif /* _LIBVARPD_IMPL_H */
249