root/trunk/contrib/pg_stat_mem/libzonecfg.h

Revision 2, 16.5 kB (checked in by jesus, 7 years ago)

pgsol10 extension to give postgres insight into the memory usage of its backends

Line 
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 2006 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26
27 #ifndef _LIBZONECFG_H
28 #define _LIBZONECFG_H
29
30 #pragma ident   "@(#)libzonecfg.h       1.23    06/09/11 SMI"
31
32 /*
33  * Zone configuration header file.
34  */
35
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39
40 /* sys/socket.h is required by net/if.h, which has a constant needed here */
41 #include <sys/param.h>
42 #include <sys/fstyp.h>
43 #include <sys/mount.h>
44 #include <priv.h>
45 #include <netinet/in.h>
46 #include <sys/socket.h>
47 #include <net/if.h>
48 #include <stdio.h>
49 #include <rctl.h>
50 #include <zone.h>
51 /*
52   This is only available on Solaris 11 for now
53   #include <libbrand.h>
54 */
55 #include <sys/uuid.h>
56
57 #define ZONE_ID_UNDEFINED       -1
58
59 #define Z_OK                    0
60 #define Z_EMPTY_DOCUMENT        1       /* XML doc root element is null */
61 #define Z_WRONG_DOC_TYPE        2       /* top-level XML doc element != zone */
62 #define Z_BAD_PROPERTY          3       /* libxml-level property problem */
63 #define Z_TEMP_FILE             4       /* problem creating temporary file */
64 #define Z_SAVING_FILE           5       /* libxml error saving or validating */
65 #define Z_NO_ENTRY              6       /* no such entry */
66 #define Z_BOGUS_ZONE_NAME       7       /* illegal zone name */
67 #define Z_REQD_RESOURCE_MISSING 8       /* required resource missing */
68 #define Z_REQD_PROPERTY_MISSING 9       /* required property missing */
69 #define Z_BAD_HANDLE            10      /* bad document handle */
70 #define Z_NOMEM                 11      /* out of memory (like ENOMEM) */
71 #define Z_INVAL                 12      /* invalid argument (like EINVAL) */
72 #define Z_ACCES                 13      /* permission denied (like EACCES) */
73 #define Z_TOO_BIG               14      /* string won't fit in char array */
74 #define Z_MISC_FS               15      /* miscellaneous file-system error */
75 #define Z_NO_ZONE               16      /* no such zone */
76 #define Z_NO_RESOURCE_TYPE      17      /* no/wrong resource type */
77 #define Z_NO_RESOURCE_ID        18      /* no/wrong resource id */
78 #define Z_NO_PROPERTY_TYPE      19      /* no/wrong property type */
79 #define Z_NO_PROPERTY_ID        20      /* no/wrong property id */
80 #define Z_BAD_ZONE_STATE        21      /* zone state invalid for given task */
81 #define Z_INVALID_DOCUMENT      22      /* libxml can't validate against DTD */
82 #define Z_NAME_IN_USE           23      /* zone name already in use (rename) */
83 #define Z_NO_SUCH_ID            24      /* delete_index: no old ID */
84 #define Z_UPDATING_INDEX        25      /* add/modify/delete_index problem */
85 #define Z_LOCKING_FILE          26      /* problem locking index file */
86 #define Z_UNLOCKING_FILE        27      /* problem unlocking index file */
87 #define Z_SYSTEM                28      /* consult errno instead */
88 #define Z_INSUFFICIENT_SPEC     29      /* resource insufficiently specified */
89 #define Z_RESOLVED_PATH         34      /* resolved path mismatch */
90 #define Z_IPV6_ADDR_PREFIX_LEN  35      /* IPv6 address prefix length needed */
91 #define Z_BOGUS_ADDRESS         36      /* not IPv[4|6] address or host name */
92 #define Z_PRIV_PROHIBITED       37      /* specified privilege is prohibited */
93 #define Z_PRIV_REQUIRED         38      /* required privilege is missing */
94 #define Z_PRIV_UNKNOWN          39      /* specified privilege is unknown */
95 #define Z_BRAND_ERROR           40      /* brand-specific error */
96
97 /*
98  * Warning: these are shared with the admin/install consolidation.
99  * Do not insert states between any of the currently defined states,
100  * and any new states must be evaluated for impact on range comparisons.
101  */
102 #define ZONE_STATE_CONFIGURED           0
103 #define ZONE_STATE_INCOMPLETE           1
104 #define ZONE_STATE_INSTALLED            2
105 #define ZONE_STATE_READY                3
106 #define ZONE_STATE_RUNNING              4
107 #define ZONE_STATE_SHUTTING_DOWN        5
108 #define ZONE_STATE_DOWN                 6
109 #define ZONE_STATE_MOUNTED              7
110
111 #define ZONE_STATE_MAXSTRLEN    14
112
113 #define LIBZONECFG_PATH         "libzonecfg.so.1"
114
115 #define ZONE_CONFIG_ROOT        "/etc/zones"
116 #define ZONE_INDEX_FILE         ZONE_CONFIG_ROOT "/index"
117
118 /* Owner, group, and mode (defined by packaging) for the config directory */
119 #define ZONE_CONFIG_UID         0               /* root */
120 #define ZONE_CONFIG_GID         3               /* sys */
121 #define ZONE_CONFIG_MODE        0755
122
123 /* Owner, group, and mode (defined by packaging) for the index file */
124 #define ZONE_INDEX_UID          0               /* root */
125 #define ZONE_INDEX_GID          3               /* sys */
126 #define ZONE_INDEX_MODE         0644
127
128 /* The maximum length of the VERSION string in the pkginfo(4) file. */
129 #define ZONE_PKG_VERSMAX        256
130
131 /*
132  * Bit flag definitions for passing into libzonecfg functions.
133  */
134 #define ZONE_DRY_RUN            0x01
135
136 /*
137  * The integer field expresses the current values on a get.
138  * On a put, it represents the new values if >= 0 or "don't change" if < 0.
139  */
140 struct zoneent {
141         char    zone_name[ZONENAME_MAX];        /* name of the zone */
142         int     zone_state;     /* configured | incomplete | installed */
143         char    zone_path[MAXPATHLEN];          /* path to zone storage */
144         uuid_t  zone_uuid;                      /* unique ID for zone */
145         char    zone_newname[ZONENAME_MAX];     /* for doing renames */
146 };
147
148 typedef struct zone_dochandle *zone_dochandle_t;        /* opaque handle */
149
150 typedef uint_t zone_state_t;
151
152 typedef struct zone_fsopt {
153         struct zone_fsopt *zone_fsopt_next;
154         char               zone_fsopt_opt[MAX_MNTOPT_STR];
155 } zone_fsopt_t;
156
157 struct zone_fstab {
158         char            zone_fs_special[MAXPATHLEN];    /* special file */
159         char            zone_fs_dir[MAXPATHLEN];        /* mount point */
160         char            zone_fs_type[FSTYPSZ];          /* e.g. ufs */
161         zone_fsopt_t   *zone_fs_options;                /* mount options */
162         char            zone_fs_raw[MAXPATHLEN];        /* device to fsck */
163 };
164
165 struct zone_nwiftab {
166         char    zone_nwif_address[INET6_ADDRSTRLEN];
167         char    zone_nwif_physical[LIFNAMSIZ];
168 };
169
170 struct zone_devtab {
171         char    zone_dev_match[MAXPATHLEN];
172 };
173
174 struct zone_rctlvaltab {
175         char    zone_rctlval_priv[MAXNAMELEN];
176         char    zone_rctlval_limit[MAXNAMELEN];
177         char    zone_rctlval_action[MAXNAMELEN];
178         struct zone_rctlvaltab *zone_rctlval_next;
179 };
180
181 struct zone_rctltab {
182         char    zone_rctl_name[MAXNAMELEN];
183         struct zone_rctlvaltab *zone_rctl_valptr;
184 };
185
186 struct zone_attrtab {
187         char    zone_attr_name[MAXNAMELEN];
188         char    zone_attr_type[MAXNAMELEN];
189         char    zone_attr_value[2 * BUFSIZ];
190 };
191
192 struct zone_dstab {
193         char    zone_dataset_name[MAXNAMELEN];
194 };
195
196 struct zone_pkgtab {
197         char    zone_pkg_name[MAXNAMELEN];
198         char    zone_pkg_version[ZONE_PKG_VERSMAX];
199 };
200
201 struct zone_patchtab {
202         char    zone_patch_id[MAXNAMELEN];
203 };
204
205 struct zone_devpermtab {
206         char    zone_devperm_name[MAXPATHLEN];
207         uid_t   zone_devperm_uid;
208         gid_t   zone_devperm_gid;
209         mode_t  zone_devperm_mode;
210         char    *zone_devperm_acl;
211 };
212
213 /*
214  * Basic configuration management routines.
215  */
216 extern  zone_dochandle_t        zonecfg_init_handle(void);
217 extern  int     zonecfg_get_handle(const char *, zone_dochandle_t);
218 extern  int     zonecfg_get_snapshot_handle(const char *, zone_dochandle_t);
219 extern  int     zonecfg_get_template_handle(const char *, const char *,
220     zone_dochandle_t);
221 extern  int     zonecfg_get_xml_handle(const char *, zone_dochandle_t);
222 extern  int     zonecfg_check_handle(zone_dochandle_t);
223 extern  void    zonecfg_fini_handle(zone_dochandle_t);
224 extern  int     zonecfg_destroy(const char *, boolean_t);
225 extern  int     zonecfg_destroy_snapshot(const char *);
226 extern  int     zonecfg_save(zone_dochandle_t);
227 extern  int     zonecfg_create_snapshot(const char *);
228 extern  char    *zonecfg_strerror(int);
229 extern  int     zonecfg_access(const char *, int);
230 extern  void    zonecfg_set_root(const char *);
231 extern  const char *zonecfg_get_root(void);
232 extern  boolean_t zonecfg_in_alt_root(void);
233
234 /*
235  * Zone name, path to zone directory, autoboot setting, pool and boot
236  * arguments.
237  */
238 extern  int     zonecfg_validate_zonename(const char *);
239 extern  int     zonecfg_get_name(zone_dochandle_t, char *, size_t);
240 extern  int     zonecfg_set_name(zone_dochandle_t, char *);
241 extern  int     zonecfg_get_zonepath(zone_dochandle_t, char *, size_t);
242 extern  int     zonecfg_set_zonepath(zone_dochandle_t, char *);
243 extern  int     zonecfg_get_autoboot(zone_dochandle_t, boolean_t *);
244 extern  int     zonecfg_set_autoboot(zone_dochandle_t, boolean_t);
245 extern  int     zonecfg_get_pool(zone_dochandle_t, char *, size_t);
246 extern  int     zonecfg_set_pool(zone_dochandle_t, char *);
247 extern  int     zonecfg_get_bootargs(zone_dochandle_t, char *, size_t);
248 extern  int     zonecfg_set_bootargs(zone_dochandle_t, char *);
249
250 /*
251  * Set/retrieve the brand for the zone
252  */
253 extern  int     zonecfg_get_brand(zone_dochandle_t, char *, size_t);
254 extern  int     zonecfg_set_brand(zone_dochandle_t, char *);
255
256 /*
257  * Filesystem configuration.
258  */
259 extern  int     zonecfg_add_filesystem(zone_dochandle_t, struct zone_fstab *);
260 extern  int     zonecfg_delete_filesystem(zone_dochandle_t,
261     struct zone_fstab *);
262 extern  int     zonecfg_modify_filesystem(zone_dochandle_t,
263     struct zone_fstab *, struct zone_fstab *);
264 extern  int     zonecfg_lookup_filesystem(zone_dochandle_t,
265     struct zone_fstab *);
266 extern  int     zonecfg_add_ipd(zone_dochandle_t, struct zone_fstab *);
267 extern  int     zonecfg_delete_ipd(zone_dochandle_t, struct zone_fstab *);
268 extern  int     zonecfg_modify_ipd(zone_dochandle_t,
269     struct zone_fstab *, struct zone_fstab *);
270 extern  int     zonecfg_lookup_ipd(zone_dochandle_t, struct zone_fstab *);
271 extern  int     zonecfg_add_fs_option(struct zone_fstab *, char *);
272 extern  int     zonecfg_remove_fs_option(struct zone_fstab *, char *);
273 extern  void    zonecfg_free_fs_option_list(zone_fsopt_t *);
274 extern  int     zonecfg_find_mounts(char *, int(*)(const char *, void *),
275     void *);
276
277 /*
278  * Network interface configuration.
279  */
280 extern  int     zonecfg_add_nwif(zone_dochandle_t, struct zone_nwiftab *);
281 extern  int     zonecfg_delete_nwif(zone_dochandle_t, struct zone_nwiftab *);
282 extern  int     zonecfg_modify_nwif(zone_dochandle_t, struct zone_nwiftab *,
283     struct zone_nwiftab *);
284 extern  int     zonecfg_lookup_nwif(zone_dochandle_t, struct zone_nwiftab *);
285
286 /*
287  * Device configuration and rule matching.
288  */
289 extern  int     zonecfg_add_dev(zone_dochandle_t, struct zone_devtab *);
290 extern  int     zonecfg_delete_dev(zone_dochandle_t, struct zone_devtab *);
291 extern  int     zonecfg_modify_dev(zone_dochandle_t, struct zone_devtab *,
292     struct zone_devtab *);
293 extern  int     zonecfg_lookup_dev(zone_dochandle_t, struct zone_devtab *);
294
295 /*
296  * Resource control configuration.
297  */
298 extern  int     zonecfg_add_rctl(zone_dochandle_t, struct zone_rctltab *);
299 extern  int     zonecfg_delete_rctl(zone_dochandle_t, struct zone_rctltab *);
300 extern  int     zonecfg_modify_rctl(zone_dochandle_t, struct zone_rctltab *,
301     struct zone_rctltab *);
302 extern  int     zonecfg_lookup_rctl(zone_dochandle_t, struct zone_rctltab *);
303 extern  int     zonecfg_add_rctl_value(struct zone_rctltab *,
304     struct zone_rctlvaltab *);
305 extern  int     zonecfg_remove_rctl_value(struct zone_rctltab *,
306     struct zone_rctlvaltab *);
307 extern  void    zonecfg_free_rctl_value_list(struct zone_rctlvaltab *);
308
309 /*
310  * Generic attribute configuration and type/value extraction.
311  */
312 extern  int     zonecfg_add_attr(zone_dochandle_t, struct zone_attrtab *);
313 extern  int     zonecfg_delete_attr(zone_dochandle_t, struct zone_attrtab *);
314 extern  int     zonecfg_modify_attr(zone_dochandle_t, struct zone_attrtab *,
315     struct zone_attrtab *);
316 extern  int     zonecfg_lookup_attr(zone_dochandle_t, struct zone_attrtab *);
317 extern  int     zonecfg_get_attr_boolean(const struct zone_attrtab *,
318     boolean_t *);
319 extern  int     zonecfg_get_attr_int(const struct zone_attrtab *, int64_t *);
320 extern  int     zonecfg_get_attr_string(const struct zone_attrtab *, char *,
321     size_t);
322 extern  int     zonecfg_get_attr_uint(const struct zone_attrtab *, uint64_t *);
323
324 /*
325  * ZFS configuration.
326  */
327 extern  int     zonecfg_add_ds(zone_dochandle_t, struct zone_dstab *);
328 extern  int     zonecfg_delete_ds(zone_dochandle_t, struct zone_dstab *);
329 extern  int     zonecfg_modify_ds(zone_dochandle_t, struct zone_dstab *,
330     struct zone_dstab *);
331 extern  int     zonecfg_lookup_ds(zone_dochandle_t, struct zone_dstab *);
332
333 /*
334  * attach/detach support.
335  */
336 extern  int     zonecfg_get_attach_handle(const char *, const char *,
337     boolean_t, zone_dochandle_t);
338 extern  int     zonecfg_attach_manifest(int, zone_dochandle_t,
339     zone_dochandle_t);
340 extern  int     zonecfg_detach_save(zone_dochandle_t, uint_t);
341 extern  int     zonecfg_get_detach_info(zone_dochandle_t, boolean_t);
342 extern  boolean_t zonecfg_detached(const char *);
343 extern  void    zonecfg_rm_detached(zone_dochandle_t, boolean_t forced);
344 extern  int     zonecfg_devwalk(zone_dochandle_t handle,
345     int (*cb)(const char *, uid_t, gid_t, mode_t, const char *, void *),
346     void *data);
347 extern  int     zonecfg_devperms_apply(zone_dochandle_t, const char *,
348     uid_t, gid_t, mode_t, const char *);
349
350 /*
351  * External zone verification support.
352  */
353 extern  int     zonecfg_verify_save(zone_dochandle_t, char *);
354
355 /*
356  * '*ent' iterator routines.
357  */
358 extern  int     zonecfg_setfsent(zone_dochandle_t);
359 extern  int     zonecfg_getfsent(zone_dochandle_t, struct zone_fstab *);
360 extern  int     zonecfg_endfsent(zone_dochandle_t);
361 extern  int     zonecfg_setipdent(zone_dochandle_t);
362 extern  int     zonecfg_getipdent(zone_dochandle_t, struct zone_fstab *);
363 extern  int     zonecfg_endipdent(zone_dochandle_t);
364 extern  int     zonecfg_setnwifent(zone_dochandle_t);
365 extern  int     zonecfg_getnwifent(zone_dochandle_t, struct zone_nwiftab *);
366 extern  int     zonecfg_endnwifent(zone_dochandle_t);
367 extern  int     zonecfg_setdevent(zone_dochandle_t);
368 extern  int     zonecfg_getdevent(zone_dochandle_t, struct zone_devtab *);
369 extern  int     zonecfg_enddevent(zone_dochandle_t);
370 extern  int     zonecfg_setattrent(zone_dochandle_t);
371 extern  int     zonecfg_getattrent(zone_dochandle_t, struct zone_attrtab *);
372 extern  int     zonecfg_endattrent(zone_dochandle_t);
373 extern  int     zonecfg_setrctlent(zone_dochandle_t);
374 extern  int     zonecfg_getrctlent(zone_dochandle_t, struct zone_rctltab *);
375 extern  int     zonecfg_endrctlent(zone_dochandle_t);
376 extern  int     zonecfg_setdsent(zone_dochandle_t);
377 extern  int     zonecfg_getdsent(zone_dochandle_t, struct zone_dstab *);
378 extern  int     zonecfg_enddsent(zone_dochandle_t);
379 extern  int     zonecfg_setpkgent(zone_dochandle_t);
380 extern  int     zonecfg_getpkgent(zone_dochandle_t, struct zone_pkgtab *);
381 extern  int     zonecfg_endpkgent(zone_dochandle_t);
382 extern  int     zonecfg_setpatchent(zone_dochandle_t);
383 extern  int     zonecfg_getpatchent(zone_dochandle_t, struct zone_patchtab *);
384 extern  int     zonecfg_endpatchent(zone_dochandle_t);
385 extern  int     zonecfg_setdevperment(zone_dochandle_t);
386 extern  int     zonecfg_getdevperment(zone_dochandle_t,
387     struct zone_devpermtab *);
388 extern  int     zonecfg_enddevperment(zone_dochandle_t);
389
390 /*
391  * Privilege-related functions.
392  */
393 extern  int     zonecfg_default_privset(priv_set_t *);
394 extern  int     zonecfg_get_privset(zone_dochandle_t, priv_set_t *,
395     char **);
396 extern  int     zonecfg_get_limitpriv(zone_dochandle_t, char **);
397 extern  int     zonecfg_set_limitpriv(zone_dochandle_t, char *);
398
399 /*
400  * Higher-level routines.
401  */
402 extern  int     zone_get_brand(char *, char *, size_t);
403 extern  int     zone_get_rootpath(char *, char *, size_t);
404 extern  int     zone_get_devroot(char *, char *, size_t);
405 extern  int     zone_get_zonepath(char *, char *, size_t);
406 extern  int     zone_get_state(char *, zone_state_t *);
407 extern  int     zone_set_state(char *, zone_state_t);
408 extern  char    *zone_state_str(zone_state_t);
409 extern  int     zonecfg_get_name_by_uuid(const uuid_t, char *, size_t);
410 extern  int     zonecfg_get_uuid(const char *, uuid_t);
411
412 /*
413  * Iterator for configured zones.
414  */
415 extern FILE             *setzoneent(void);
416 extern char             *getzoneent(FILE *);
417 extern struct zoneent   *getzoneent_private(FILE *);
418 extern void             endzoneent(FILE *);
419
420 /*
421  * File-system-related convenience functions.
422  */
423 extern boolean_t zonecfg_valid_fs_type(const char *);
424
425 /*
426  * Network-related convenience functions.
427  */
428 extern boolean_t zonecfg_same_net_address(char *, char *);
429 extern int zonecfg_valid_net_address(char *, struct lifreq *);
430
431 /*
432  * Rctl-related common functions.
433  */
434 extern boolean_t zonecfg_is_rctl(const char *);
435 extern boolean_t zonecfg_valid_rctlname(const char *);
436 extern boolean_t zonecfg_valid_rctlblk(const rctlblk_t *);
437 extern boolean_t zonecfg_valid_rctl(const char *, const rctlblk_t *);
438 extern int zonecfg_construct_rctlblk(const struct zone_rctlvaltab *,
439     rctlblk_t *);
440
441 /*
442  * Live Upgrade support functions.  Shared between ON and install gate.
443  */
444 extern FILE *zonecfg_open_scratch(const char *, boolean_t);
445 extern int zonecfg_lock_scratch(FILE *);
446 extern void zonecfg_close_scratch(FILE *);
447 extern int zonecfg_get_scratch(FILE *, char *, size_t, char *, size_t, char *,
448     size_t);
449 extern int zonecfg_find_scratch(FILE *, const char *, const char *, char *,
450     size_t);
451 extern int zonecfg_reverse_scratch(FILE *, const char *, char *, size_t,
452     char *, size_t);
453 extern int zonecfg_add_scratch(FILE *, const char *, const char *,
454     const char *);
455 extern int zonecfg_delete_scratch(FILE *, const char *);
456 extern boolean_t zonecfg_is_scratch(const char *);
457
458 #ifdef __cplusplus
459 }
460 #endif
461
462 #endif  /* _LIBZONECFG_H */
Note: See TracBrowser for help on using the browser.