13034Sdougm /*
23034Sdougm  * CDDL HEADER START
33034Sdougm  *
43034Sdougm  * The contents of this file are subject to the terms of the
53034Sdougm  * Common Development and Distribution License (the "License").
63034Sdougm  * You may not use this file except in compliance with the License.
73034Sdougm  *
83034Sdougm  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
93034Sdougm  * or http://www.opensolaris.org/os/licensing.
103034Sdougm  * See the License for the specific language governing permissions
113034Sdougm  * and limitations under the License.
123034Sdougm  *
133034Sdougm  * When distributing Covered Code, include this CDDL HEADER in each
143034Sdougm  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
153034Sdougm  * If applicable, add the following below this CDDL HEADER, with the
163034Sdougm  * fields enclosed by brackets "[]" replaced with your own identifying
173034Sdougm  * information: Portions Copyright [yyyy] [name of copyright owner]
183034Sdougm  *
193034Sdougm  * CDDL HEADER END
203034Sdougm  */
213034Sdougm 
223034Sdougm /*
23*3910Sdougm  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
243034Sdougm  * Use is subject to license terms.
253034Sdougm  */
263034Sdougm 
273034Sdougm /*
283034Sdougm  * basic declarations for implementation of the share management
293034Sdougm  * libraries.
303034Sdougm  */
313034Sdougm 
323034Sdougm #ifndef _LIBSHARE_IMPL_H
333034Sdougm #define	_LIBSHARE_IMPL_H
343034Sdougm 
353034Sdougm #pragma ident	"%Z%%M%	%I%	%E% SMI"
363034Sdougm 
373034Sdougm #include <libshare.h>
383034Sdougm #include <libscf.h>
393034Sdougm #include <scfutil.h>
40*3910Sdougm #include <libzfs.h>
413034Sdougm 
423034Sdougm #ifdef	__cplusplus
433034Sdougm extern "C" {
443034Sdougm #endif
453034Sdougm 
463034Sdougm /* directory to find plugin modules in */
473034Sdougm #define	SA_LIB_DIR	"/usr/lib/fs"
483034Sdougm 
493034Sdougm /* default group name for dfstab file */
503034Sdougm #define	SA_DEFAULT_FILE_GRP	"sys"
513034Sdougm 
523034Sdougm typedef void *sa_phandle_t;
533034Sdougm 
543034Sdougm #define	SA_PLUGIN_VERSION	1
553034Sdougm struct sa_plugin_ops {
563034Sdougm 	int	sa_version;
573034Sdougm 	char	*sa_protocol;			/* protocol name */
583034Sdougm 	int	(*sa_init)();
593034Sdougm 	void	(*sa_fini)();
603034Sdougm 	int	(*sa_share)(sa_share_t);	/* start sharing */
613034Sdougm 	int	(*sa_unshare)(char *);	/* stop sharing */
623034Sdougm 	int	(*sa_valid_prop)(sa_property_t, sa_optionset_t);
633034Sdougm 	int	(*sa_valid_space)(char *);	/* is name valid optionspace? */
643034Sdougm 	int	(*sa_security_prop)(char *);	/* property is security */
653034Sdougm 	int	(*sa_legacy_opts)(sa_group_t, char *); /* parse legacy opts */
663034Sdougm 	char   *(*sa_legacy_format)(sa_group_t, int);
673034Sdougm 	int	(*sa_set_proto_prop)(sa_property_t);
683034Sdougm 	sa_protocol_properties_t (*sa_get_proto_set)();
693034Sdougm 	char   *(*sa_get_proto_status)();
703034Sdougm 	char   *(*sa_space_alias)(char *);
713034Sdougm 	int	(*sa_update_legacy)(sa_share_t);
723034Sdougm 	int	(*sa_delete_legacy)(sa_share_t);
733034Sdougm 	int	(*sa_run_command)(int, int, char **); /* proto specific */
743034Sdougm 	int	(*sa_command_help)();
753034Sdougm };
763034Sdougm 
773034Sdougm struct sa_proto_handle {
783034Sdougm 	int			sa_num_proto;
793034Sdougm 	char			**sa_proto;
803034Sdougm 	struct sa_plugin_ops	**sa_ops;
813034Sdougm };
823034Sdougm 
833034Sdougm typedef struct propertylist {
843034Sdougm 	struct propertylist	*pl_next;
853034Sdougm 	int			pl_type;
863034Sdougm 	union propval {
873034Sdougm 	    sa_optionset_t	pl_optionset;
883034Sdougm 	    sa_security_t	pl_security;
893034Sdougm 	    void		*pl_void;
903034Sdougm 	}			pl_value;
913034Sdougm } property_list_t;
923034Sdougm 
933034Sdougm extern int sa_proto_share(char *, sa_share_t);
943034Sdougm extern int sa_proto_unshare(char *, char *);
953034Sdougm extern int sa_proto_valid_prop(char *, sa_property_t, sa_optionset_t);
963034Sdougm extern int sa_proto_security_prop(char *, char *);
973034Sdougm extern int sa_proto_legacy_opts(char *, sa_group_t, char *);
983034Sdougm 
993034Sdougm /* internal utility functions */
1003034Sdougm extern sa_optionset_t sa_get_derived_optionset(sa_group_t, char *, int);
1013034Sdougm extern void sa_free_derived_optionset(sa_optionset_t);
1023034Sdougm extern sa_optionset_t sa_get_all_security_types(void *, char *, int);
1033034Sdougm extern sa_security_t sa_get_derived_security(void *, char *, char *, int);
1043034Sdougm extern void sa_free_derived_security(sa_security_t);
1053034Sdougm extern sa_protocol_properties_t sa_create_protocol_properties(char *);
1063034Sdougm extern int sa_start_transaction(scfutilhandle_t *, char *);
1073034Sdougm extern int sa_end_transaction(scfutilhandle_t *);
1083034Sdougm extern void sa_abort_transaction(scfutilhandle_t *);
1093034Sdougm extern int sa_commit_share(scfutilhandle_t *, sa_group_t, sa_share_t);
1103034Sdougm extern int sa_set_property(scfutilhandle_t *, char *, char *);
1113034Sdougm extern void sa_free_fstype(char *fstyp);
1123034Sdougm extern int sa_delete_share(scfutilhandle_t *, sa_group_t, sa_share_t);
1133034Sdougm extern int sa_delete_instance(scfutilhandle_t *, char *);
1143034Sdougm extern int sa_create_pgroup(scfutilhandle_t *, char *);
1153034Sdougm extern int sa_delete_pgroup(scfutilhandle_t *, char *);
1163034Sdougm 
1173034Sdougm /* ZFS functions */
118*3910Sdougm extern int sa_get_zfs_shares(sa_handle_t, char *);
1193034Sdougm extern int sa_zfs_update(sa_share_t);
1203034Sdougm 
1213034Sdougm /* plugin specific functions */
1223034Sdougm extern int proto_plugin_init();
123*3910Sdougm extern void proto_plugin_fini();
1243034Sdougm extern int sa_proto_set_property(char *, sa_property_t);
1253034Sdougm extern int sa_proto_delete_legacy(char *, sa_share_t);
1263034Sdougm extern int sa_proto_update_legacy(char *, sa_share_t);
1273034Sdougm 
1283034Sdougm #define	PL_TYPE_PROPERTY	0
1293034Sdougm #define	PL_TYPE_SECURITY	1
1303034Sdougm 
1313034Sdougm /* values only used by the internal dfstab/sharetab parser */
1323034Sdougm #define	SA_SHARE_PARSER		0x1000
1333034Sdougm 
1343034Sdougm /* plugin handler only */
1353034Sdougm struct sa_proto_plugin {
1363034Sdougm 	struct sa_proto_plugin	*plugin_next;
1373034Sdougm 	struct sa_plugin_ops	*plugin_ops;
1383034Sdougm 	void			*plugin_handle;
1393034Sdougm };
1403034Sdougm 
141*3910Sdougm /* internal version of sa_handle_t */
142*3910Sdougm typedef struct sa_handle_impl {
143*3910Sdougm 	uint64_t	flags;
144*3910Sdougm 	scfutilhandle_t	*scfhandle;
145*3910Sdougm 	libzfs_handle_t *zfs_libhandle;
146*3910Sdougm 	zfs_handle_t	**zfs_list;
147*3910Sdougm 	size_t		zfs_list_count;
148*3910Sdougm 	xmlNodePtr	tree;
149*3910Sdougm 	xmlDocPtr	doc;
150*3910Sdougm } *sa_handle_impl_t;
151*3910Sdougm 
1523034Sdougm #ifdef	__cplusplus
1533034Sdougm }
1543034Sdougm #endif
1553034Sdougm 
1563034Sdougm #endif /* _LIBSHARE_IMPL_H */
157