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 (c) 2018, Joyent, Inc.
14  */
15 
16 #ifndef _SYS_SDEV_PLUGIN_H
17 #define	_SYS_SDEV_PLUGIN_H
18 
19 /*
20  * Kernel sdev plugin interface
21  */
22 
23 #ifdef _KERNEL
24 
25 #include <sys/types.h>
26 #include <sys/stat.h>
27 #include <sys/vnode.h>
28 
29 #endif	/* _KERNEL */
30 
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34 
35 #ifdef _KERNEL
36 
37 typedef uintptr_t sdev_plugin_hdl_t;
38 typedef uintptr_t sdev_ctx_t;
39 
40 /*
41  * Valid return values for sdev_plugin_validate_t.
42  */
43 typedef enum sdev_plugin_validate {
44 	SDEV_VTOR_INVALID = -1,
45 	SDEV_VTOR_SKIP = 0,
46 	SDEV_VTOR_VALID	= 1,
47 	SDEV_VTOR_STALE	= 2
48 } sdev_plugin_validate_t;
49 
50 /*
51  * Valid flags
52  */
53 typedef enum sdev_plugin_flags {
54 	SDEV_PLUGIN_NO_NCACHE = 0x1,
55 	SDEV_PLUGIN_SUBDIR = 0x2
56 } sdev_plugin_flags_t;
57 
58 #define	SDEV_PLUGIN_FLAGS_MASK	0x3
59 
60 /*
61  * Functions a module must implement
62  */
63 typedef sdev_plugin_validate_t (*sp_valid_f)(sdev_ctx_t);
64 typedef int (*sp_filldir_f)(sdev_ctx_t);
65 typedef void (*sp_inactive_f)(sdev_ctx_t);
66 
67 #define	SDEV_PLUGIN_VERSION	1
68 
69 typedef struct sdev_plugin_ops {
70 	int spo_version;
71 	sdev_plugin_flags_t spo_flags;
72 	sp_valid_f spo_validate;
73 	sp_filldir_f spo_filldir;
74 	sp_inactive_f spo_inactive;
75 } sdev_plugin_ops_t;
76 
77 extern sdev_plugin_hdl_t sdev_plugin_register(const char *, sdev_plugin_ops_t *,
78     int *);
79 extern int sdev_plugin_unregister(sdev_plugin_hdl_t);
80 
81 typedef enum sdev_ctx_flags {
82 	SDEV_CTX_GLOBAL = 0x2	/* node belongs to the GZ */
83 } sdev_ctx_flags_t;
84 
85 /*
86  * Context helper functions
87  */
88 extern sdev_ctx_flags_t sdev_ctx_flags(sdev_ctx_t);
89 extern const char *sdev_ctx_name(sdev_ctx_t);
90 extern const char *sdev_ctx_path(sdev_ctx_t);
91 extern int sdev_ctx_minor(sdev_ctx_t, minor_t *);
92 extern enum vtype sdev_ctx_vtype(sdev_ctx_t);
93 
94 /*
95  * Callbacks to manipulate nodes
96  */
97 extern int sdev_plugin_mkdir(sdev_ctx_t, char *);
98 extern int sdev_plugin_mknod(sdev_ctx_t, char *, mode_t, dev_t);
99 
100 #endif	/* _KERNEL */
101 
102 #ifdef __cplusplus
103 }
104 #endif
105 
106 #endif /* _SYS_SDEV_PLUGIN_H */
107