xref: /titanic_44/usr/src/lib/libscf/inc/libscf_priv.h (revision 99ebb4ca412cb0a19d77a3899a87c055b9c30fa8)
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  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef	_LIBSCF_PRIV_H
27 #define	_LIBSCF_PRIV_H
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #include <libscf.h>
32 #include <unistd.h>
33 
34 #ifdef	__cplusplus
35 extern "C" {
36 #endif
37 
38 /*
39  * NOTE
40  *
41  * The contents of this file are private to the implementation of Solaris
42  * and are subject to change at any time without notice.
43  */
44 
45 #define	SCF_PG_GENERAL_TYPE		SCF_GROUP_FRAMEWORK
46 #define	SCF_PG_GENERAL_FLAGS		0
47 
48 #define	SCF_PG_GENERAL_OVR_TYPE		SCF_GROUP_FRAMEWORK
49 #define	SCF_PG_GENERAL_OVR_FLAGS	SCF_PG_FLAG_NONPERSISTENT
50 
51 #define	SCF_PG_OPTIONS_TYPE		SCF_GROUP_FRAMEWORK
52 #define	SCF_PG_OPTIONS_FLAGS		0
53 
54 #define	SCF_PG_OPTIONS_OVR_TYPE		SCF_GROUP_FRAMEWORK
55 #define	SCF_PG_OPTIONS_OVR_FLAGS	SCF_PG_FLAG_NONPERSISTENT
56 
57 #define	SCF_PG_RESTARTER_TYPE		SCF_GROUP_FRAMEWORK
58 #define	SCF_PG_RESTARTER_FLAGS		SCF_PG_FLAG_NONPERSISTENT
59 
60 #define	SCF_PG_RESTARTER_ACTIONS_TYPE	SCF_GROUP_FRAMEWORK
61 #define	SCF_PG_RESTARTER_ACTIONS_FLAGS	SCF_PG_FLAG_NONPERSISTENT
62 
63 #define	SCF_PROPERTY_LOGFILE		((const char *)"logfile")
64 #define	SCF_PROPERTY_ALT_LOGFILE	((const char *)"alt_logfile")
65 
66 #define	SCF_LEGACY_SERVICE		((const char *)"smf/legacy_run")
67 
68 #define	SCF_LEGACY_PROPERTY_NAME	((const char *)"name")
69 #define	SCF_LEGACY_PROPERTY_INODE	((const char *)"inode")
70 #define	SCF_LEGACY_PROPERTY_SUFFIX	((const char *)"suffix")
71 
72 #define	SCF_FMRI_TYPE_SVC		0x1
73 #define	SCF_FMRI_TYPE_FILE		0x2
74 
75 typedef struct scf_decoration_info {
76 	const char *sdi_name;
77 	scf_type_t sdi_type;
78 	scf_value_t *sdi_value;		/* can be SCF_DECORATE_CLEAR */
79 } scf_decoration_info_t;
80 
81 typedef int (*scf_decoration_func)(const scf_decoration_info_t *, void *);
82 
83 /*
84  * calls a callback function for each decoration on the handle.  If the
85  * callback returns 0, the iteration stops and returns 0.  If the callback
86  * returns a non-zero value, the iteration continues.  After full completion,
87  * 1 is returned.  On error, -1 is returned.
88  */
89 int _scf_handle_decorations(scf_handle_t *, scf_decoration_func *,
90     scf_value_t *, void *);
91 
92 /*
93  * wait for a change to the propertygroup -- may return early.
94  * For now, only one of these can be outstanding at a time.
95  *
96  * The second argument is how long, in seconds, to wait for a response.
97  *
98  * Returns SCF_COMPLETE on timeout, -1 on error, and SCF_SUCCESS in every
99  * other case.  You must call scf_pg_update() to see if the object has
100  * actually changed.
101  */
102 int _scf_pg_wait(scf_propertygroup_t *, int);
103 
104 /*
105  * set up notifications for changes to a class of property groups (by name
106  * and type)
107  *
108  * Only one thread can be sleeping in _scf_notify_wait() -- others will
109  * fail.  Deletions give an fmri in the output path.
110  *
111  * These do not survive unbind()->bind() -- in fact, that is currently the
112  * only way to clear them.
113  */
114 int _scf_notify_add_pgname(scf_handle_t *, const char *);
115 int _scf_notify_add_pgtype(scf_handle_t *, const char *);
116 int _scf_notify_wait(scf_propertygroup_t *, char *, size_t);
117 
118 /*
119  * Internal interfaces for snapshot creation:
120  *	_scf_snapshot_take_new(), _scf_snapshot_take_new_named(), and
121  *	_scf_snapshot_take_attach() create a set of snaplevels
122  *	containing frozen versions of both the instance's property groups and
123  *	its parent service's property groups. _scf_snapshot_take_new() and
124  *	_scf_snapshot_take_new_named() create a new snapshot to which the
125  *	new snaplevels are attached, while _scf_snapshot_take_attach()
126  *	attaches the new snaplevels to a pre-existing snapshot.
127  *
128  *	_scf_snapshot_take_new_named() records the passed in names into the
129  *	snaplevel instead of the instance and service name.  This creates
130  *	an inconsistency, which should be resolved by using
131  *	_scf_snapshot_attach() to attach the new snaplevels to a snapshot
132  *	underneath the appropriate instance.  The first snapshot can
133  *	then be deleted.
134  *
135  *	_scf_snapshot_attach(snap1, snap2) points snap2 at the snaplevels
136  *	pointed to by snap1.  After a call to either
137  *	_scf_snapshot_take_attach(snap1, snap2) or
138  *	_scf_snapshot_attach(inst, snap), scf_snapshot_update() will be
139  *	required for any open references to snap or snap2 to see the new
140  *	snaplevels.
141  *
142  *	_scf_snapshot_delete() deletes the snapshot object.  While
143  *	snaplevels, being only loosely connected to snapshots, stay
144  *	around until they are no longer referenced, any references *through
145  *	this snapshot object* will be invalidated.
146  *
147  * _scf_snapshot_take_new() can fail with at least _HANDLE_MISMATCH,
148  * _CONNECTION_BROKEN, _INVALID_ARGUMENT, _NO_RESOURCES, _PERMISSION_DENIED,
149  * _NOT_SET, _EXISTS.
150  *
151  * _scf_snapshot_take_new_named() can fail with at least _HANDLE_MISMATCH,
152  * _CONNECTION_BROKEN, _INVALID_ARGUMENT, _NO_RESOURCES, _PERMISSION_DENIED,
153  * _NOT_SET, _EXISTS.
154  *
155  * _scf_snapshot_take_attach() can fail with _CONNECTION_BROKEN, _NOT_SET,
156  * _PERMISSION_DENIED, _NO_RESOURCES, _INVALID_ARGUMENT.
157  *
158  * _scf_snapshot_attach() can fail with _HANDLE_MISMATCH, _CONNECTION_BROKEN,
159  * _NOT_SET, _NO_RESOURCES, _PERMISSION_DENIED.
160  */
161 int _scf_snapshot_take_new(scf_instance_t *, const char *, scf_snapshot_t *);
162 int _scf_snapshot_take_new_named(scf_instance_t *,
163     const char *, const char *, const char *, scf_snapshot_t *);
164 int _scf_snapshot_take_attach(scf_instance_t *, scf_snapshot_t *);
165 int _scf_snapshot_attach(scf_snapshot_t *, scf_snapshot_t *);
166 int _scf_snapshot_delete(scf_snapshot_t *);
167 
168 /*
169  * Destructively portions up the first argument into the different portions
170  * of a svc: fmri, and returns pointers to the applicable portions.  Omitted
171  * portions are set to NULL, except for the scope, which is set to the
172  * default local scope if not specified.
173  *
174  * Parsing is attempted in the order of: svc:, file:. The identified type
175  * of the service is returned in the second argument and may take a value
176  * of: SCF_FMRI_TYPE_SVC or SCF_FMRI_TYPE_FILE.
177  *
178  * Note that some of the returned pointers (in particular the scope) may not
179  * point into the passed buffer.
180  */
181 int scf_parse_fmri(char *, int *, const char **, const char **, const char **,
182     const char **, const char **);
183 
184 int scf_parse_svc_fmri(char *, const char **, const char **, const char **,
185     const char **, const char **);
186 
187 int scf_parse_file_fmri(char *fmri, const char **scope, const char **path);
188 
189 ssize_t scf_canonify_fmri(const char *, char *, size_t);
190 
191 const char *scf_type_to_string(scf_type_t);
192 scf_type_t scf_string_to_type(const char *);
193 
194 int _smf_refresh_instance_i(scf_instance_t *);
195 
196 /*
197  * Walks all the instances matching a given fmri list.  Each fmri in the array
198  * can be one of the following:
199  *
200  * 	- Full instance name
201  * 	- Full service name
202  * 	- Full property group or property name
203  * 	- Partial service or instance name
204  * 	- A globbed pattern
205  *
206  * The matching rules for partial fmris are a slightly more complex.  We allow
207  * for any substring anchored at the end of the instance or service name,
208  * provided it begins with a complete element in the fmri.  For example, given
209  * the fmri "svc:/system/filesystem/local:default", any of the following would
210  * be acceptable matches: 'default', 'local', 'local:default',
211  * 'filesystem/local'.  The following would not be acceptable:
212  * 'system/filesystem', 'filesystem/loc', 'system/local'.  Possible flag values:
213  *
214  * 	SCF_WALK_MULTIPLE	Allow individual arguments to correspond to
215  * 				multiple instances.
216  *
217  * 	SCF_WALK_LEGACY		Walk legacy services (indicated by a non-NULL
218  * 				propery group).
219  *
220  * 	SCF_WALK_SERVICE	If the user specifies a service, pass the
221  * 				service to the callback without iterating over
222  * 				its instances.
223  *
224  * 	SCF_WALK_PROPERTY	Allow FMRIs which match property groups or
225  * 				individual properties.  Incompatible with
226  * 				SCF_WALK_LEGACY.
227  *
228  * 	SCF_WALK_NOINSTANCE	Walk only services.  Must be used in
229  * 				conjunction with SCF_WALK_SERVICE.
230  *
231  * 	SCF_WALK_EXPLICIT	Walk only services if the match is exact
232  *				else return instances. Must be used in
233  *				conjunction with SCF_WALK_SERVICE.
234  *
235  * If no arguments are given, then all instances in the service graph are
236  * walked.
237  *
238  * The second to last parameter is set to UU_EXIT_FATAL if one of the arguments
239  * is an invalid FMRI or matches multiple FMRIs when SCF_WALK_MULTIPLE is not
240  * set.
241  *
242  * The last parameter is a user-supplied error function that is called when
243  * reporting invalid arguments.
244  */
245 
246 #define	SCF_WALK_MULTIPLE	0x01
247 #define	SCF_WALK_LEGACY		0x02
248 #define	SCF_WALK_SERVICE	0x04
249 #define	SCF_WALK_PROPERTY	0x08
250 #define	SCF_WALK_NOINSTANCE	0x10
251 #define	SCF_WALK_EXPLICIT	0x20
252 
253 typedef struct scf_walkinfo {
254 	const char		*fmri;
255 	scf_scope_t		*scope;
256 	scf_service_t		*svc;
257 	scf_instance_t		*inst;
258 	scf_propertygroup_t	*pg;
259 	scf_property_t		*prop;
260 	int			count;	/* svcprop special */
261 } scf_walkinfo_t;
262 
263 typedef int (*scf_walk_callback)(void *, scf_walkinfo_t *);
264 
265 scf_error_t scf_walk_fmri(scf_handle_t *, int, char **, int,
266     scf_walk_callback, void *, int *, void (*)(const char *, ...));
267 
268 /*
269  * Requests a backup of the repository with a particular name, which
270  * can be any alphabetic string.  Only privileged users can do this.
271  *
272  * Can fail with:
273  *	_NOT_BOUND, _CONNECTION_BROKEN, _PERMISSION_DENIED, _INVALID_ARGUMENT,
274  *	_INTERNAL (path too long, or the backup failed for an odd reason),
275  *	_BACKEND_READONLY (filesystem is still read-only)
276  */
277 int _scf_request_backup(scf_handle_t *, const char *);
278 
279 /*
280  * scf_pattern_t
281  */
282 typedef struct scf_pattern {
283 	enum	{
284 		PATTERN_INVALID,	/* Uninitialized state */
285 		PATTERN_EXACT,
286 		PATTERN_GLOB,
287 		PATTERN_PARTIAL
288 	} sp_type;
289 	char			*sp_arg;	/* Original argument */
290 	struct scf_match	*sp_matches;	/* List of matches */
291 	int			sp_matchcount;	/* # of matches */
292 } scf_pattern_t;
293 
294 int scf_cmp_pattern(char *, scf_pattern_t *);
295 
296 #ifdef	__cplusplus
297 }
298 #endif
299 
300 #endif	/* _LIBSCF_PRIV_H */
301