xref: /illumos-gate/usr/src/lib/libshare/common/libshare_impl.h (revision bea83d026ee1bd1b2a2419e1d0232f107a5d7d9b)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*
28  * basic declarations for implementation of the share management
29  * libraries.
30  */
31 
32 #ifndef _LIBSHARE_IMPL_H
33 #define	_LIBSHARE_IMPL_H
34 
35 #pragma ident	"%Z%%M%	%I%	%E% SMI"
36 
37 #include <libshare.h>
38 #include <libscf.h>
39 #include <scfutil.h>
40 #include <libzfs.h>
41 #include <sharefs/share.h>
42 #include <sharefs/sharetab.h>
43 
44 #ifdef	__cplusplus
45 extern "C" {
46 #endif
47 
48 /* directory to find plugin modules in */
49 #define	SA_LIB_DIR	"/usr/lib/fs"
50 
51 /* default group name for dfstab file */
52 #define	SA_DEFAULT_FILE_GRP	"sys"
53 
54 typedef void *sa_phandle_t;
55 
56 #define	SA_PLUGIN_VERSION	1
57 struct sa_plugin_ops {
58 	int	sa_version;
59 	char	*sa_protocol;			/* protocol name */
60 	int	(*sa_init)();
61 	void	(*sa_fini)();
62 	int	(*sa_share)(sa_share_t);	/* start sharing */
63 	int	(*sa_unshare)(sa_share_t, char *);	/* stop sharing */
64 	int	(*sa_valid_prop)(sa_property_t, sa_optionset_t);
65 	int	(*sa_valid_space)(char *);	/* is name valid optionspace? */
66 	int	(*sa_security_prop)(char *);	/* property is security */
67 	int	(*sa_legacy_opts)(sa_group_t, char *); /* parse legacy opts */
68 	char   *(*sa_legacy_format)(sa_group_t, int);
69 	int	(*sa_set_proto_prop)(sa_property_t);
70 	sa_protocol_properties_t (*sa_get_proto_set)();
71 	char   *(*sa_get_proto_status)();
72 	char   *(*sa_space_alias)(char *);
73 	int	(*sa_update_legacy)(sa_share_t);
74 	int	(*sa_delete_legacy)(sa_share_t);
75 	int	(*sa_change_notify)(sa_share_t);
76 	int	(*sa_enable_resource)(sa_resource_t);
77 	int	(*sa_disable_resource)(sa_resource_t);
78 	uint64_t (*sa_features)(void);
79 	int	(*sa_get_transient_shares)(sa_handle_t); /* add transients */
80 	int	(*sa_notify_resource)(sa_resource_t);
81 	int	(*sa_rename_resource)(sa_handle_t, sa_resource_t, char *);
82 	int	(*sa_run_command)(int, int, char **); /* proto specific */
83 	int	(*sa_command_help)();
84 };
85 
86 struct sa_proto_handle {
87 	int			sa_num_proto;
88 	char			**sa_proto;
89 	struct sa_plugin_ops	**sa_ops;
90 };
91 
92 typedef struct propertylist {
93 	struct propertylist	*pl_next;
94 	int			pl_type;
95 	union propval {
96 	    sa_optionset_t	pl_optionset;
97 	    sa_security_t	pl_security;
98 	    void		*pl_void;
99 	}			pl_value;
100 } property_list_t;
101 
102 /* internal version of sa_handle_t */
103 typedef struct sa_handle_impl {
104 	uint64_t	flags;
105 	scfutilhandle_t	*scfhandle;
106 	libzfs_handle_t *zfs_libhandle;
107 	zfs_handle_t	**zfs_list;
108 	size_t		zfs_list_count;
109 	xmlNodePtr	tree;
110 	xmlDocPtr	doc;
111 	uint64_t	tssharetab;
112 	uint64_t	tstrans;
113 } *sa_handle_impl_t;
114 
115 extern int sa_proto_share(char *, sa_share_t);
116 extern int sa_proto_unshare(sa_share_t, char *, char *);
117 extern int sa_proto_valid_prop(char *, sa_property_t, sa_optionset_t);
118 extern int sa_proto_security_prop(char *, char *);
119 extern int sa_proto_legacy_opts(char *, sa_group_t, char *);
120 extern int sa_proto_share_resource(char *, sa_resource_t);
121 extern int sa_proto_unshare_resource(char *, sa_resource_t);
122 
123 /* internal utility functions */
124 extern sa_optionset_t sa_get_derived_optionset(sa_group_t, char *, int);
125 extern void sa_free_derived_optionset(sa_optionset_t);
126 extern sa_optionset_t sa_get_all_security_types(void *, char *, int);
127 extern sa_security_t sa_get_derived_security(void *, char *, char *, int);
128 extern void sa_free_derived_security(sa_security_t);
129 extern sa_protocol_properties_t sa_create_protocol_properties(char *);
130 extern int sa_start_transaction(scfutilhandle_t *, char *);
131 extern int sa_end_transaction(scfutilhandle_t *, sa_handle_impl_t);
132 extern void sa_abort_transaction(scfutilhandle_t *);
133 extern int sa_commit_share(scfutilhandle_t *, sa_group_t, sa_share_t);
134 extern int sa_set_property(scfutilhandle_t *, char *, char *);
135 extern void sa_free_fstype(char *fstyp);
136 extern int sa_delete_share(scfutilhandle_t *, sa_group_t, sa_share_t);
137 extern int sa_delete_instance(scfutilhandle_t *, char *);
138 extern int sa_create_pgroup(scfutilhandle_t *, char *);
139 extern int sa_delete_pgroup(scfutilhandle_t *, char *);
140 extern void sa_fillshare(sa_share_t share, char *proto, struct share *sh);
141 extern void sa_emptyshare(struct share *sh);
142 
143 /* ZFS functions */
144 extern int sa_get_zfs_shares(sa_handle_t, char *);
145 extern int sa_zfs_update(sa_share_t);
146 extern int sa_share_zfs(sa_share_t, char *, share_t *, void *, zfs_share_op_t);
147 extern int sa_sharetab_fill_zfs(sa_share_t share, struct share *sh,
148     char *proto);
149 
150 /* plugin specific functions */
151 extern int proto_plugin_init();
152 extern void proto_plugin_fini();
153 extern int sa_proto_set_property(char *, sa_property_t);
154 extern int sa_proto_delete_legacy(char *, sa_share_t);
155 extern int sa_proto_update_legacy(char *, sa_share_t);
156 extern int sa_proto_rename_resource(sa_handle_t, char *,
157     sa_resource_t, char *);
158 
159 #define	PL_TYPE_PROPERTY	0
160 #define	PL_TYPE_SECURITY	1
161 
162 /* values only used by the internal dfstab/sharetab parser */
163 #define	SA_SHARE_PARSER		0x1000
164 
165 /* plugin handler only */
166 struct sa_proto_plugin {
167 	struct sa_proto_plugin	*plugin_next;
168 	struct sa_plugin_ops	*plugin_ops;
169 	void			*plugin_handle;
170 };
171 
172 #define	TSTAMP(tm)	(uint64_t)(((uint64_t)tm.tv_sec << 32) | \
173 					(tm.tv_nsec & 0xffffffff))
174 
175 
176 #ifdef	__cplusplus
177 }
178 #endif
179 
180 #endif /* _LIBSHARE_IMPL_H */
181