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