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 (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Copyright 2014 Nexenta Systems, Inc. All rights reserved.
25 */
26
27 #ifndef _ZONEADMD_H
28 #define _ZONEADMD_H
29
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33
34 #include <libdladm.h>
35
36 /*
37 * Multi-threaded programs should avoid MT-unsafe library calls (i.e., any-
38 * thing which could try to acquire a user-level lock unprotected by an atfork
39 * handler) between fork(2) and exec(2). See the pthread_atfork(3THR) man
40 * page for details. In particular, we want to avoid calls to zerror() in
41 * such situations, as it calls setlocale(3c) which is susceptible to such
42 * problems. So instead we have the child use one of the special exit codes
43 * below when needed, and the parent look out for such possibilities and call
44 * zerror() there.
52
53 #define DEVFSADM "devfsadm"
54 #define DEVFSADM_PATH "/usr/sbin/devfsadm"
55
56 #define EXEC_PREFIX "exec "
57 #define EXEC_LEN (strlen(EXEC_PREFIX))
58
59 #define CLUSTER_BRAND_NAME "cluster"
60 #define LABELED_BRAND_NAME "labeled"
61
62 #define SHUTDOWN_WAIT 60
63 #define SHUTDOWN_DEFAULT "/sbin/init 0"
64 #define SHUTDOWN_FMRI "svc:/system/zones:default"
65
66 /* 0755 is the default directory mode. */
67 #define DEFAULT_DIR_MODE \
68 (S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)
69 #define DEFAULT_DIR_USER -1 /* user ID for chown: -1 means don't change */
70 #define DEFAULT_DIR_GROUP -1 /* grp ID for chown: -1 means don't change */
71
72
73 typedef struct zlog {
74 FILE *logfile; /* file to log to */
75
76 /*
77 * The following are used if logging to a buffer.
78 */
79 char *log; /* remaining log */
80 size_t loglen; /* size of remaining log */
81 char *buf; /* underlying storage */
82 size_t buflen; /* total len of 'buf' */
83 char *locale; /* locale to use for gettext() */
84 } zlog_t;
85
86 extern zlog_t logsys;
87
88 extern mutex_t lock;
89 extern mutex_t msglock;
90 extern boolean_t in_death_throes;
91 extern boolean_t bringup_failure_recovery;
92 extern char *zone_name;
93 extern char pool_name[MAXNAMELEN];
94 extern char brand_name[MAXNAMELEN];
95 extern char default_brand[MAXNAMELEN];
96 extern char boot_args[BOOTARGS_MAX];
97 extern char bad_boot_arg[BOOTARGS_MAX];
98 extern boolean_t zone_isnative;
99 extern boolean_t zone_iscluster;
100 extern dladm_handle_t dld_handle;
101
102 extern void zerror(zlog_t *, boolean_t, const char *, ...);
103 extern char *localize_msg(char *locale, const char *msg);
104
105 /*
106 * Eventstream interfaces.
107 */
108 typedef enum {
109 Z_EVT_NULL = 0,
110 Z_EVT_ZONE_BOOTING,
111 Z_EVT_ZONE_REBOOTING,
112 Z_EVT_ZONE_HALTED,
113 Z_EVT_ZONE_READIED,
114 Z_EVT_ZONE_UNINSTALLING,
115 Z_EVT_ZONE_BOOTFAILED,
116 Z_EVT_ZONE_BADARGS
117 } zone_evt_t;
118
119 extern int eventstream_init();
120 extern void eventstream_write(zone_evt_t evt);
121
122 /*
123 * Zone mount styles. Boot is the standard mount we do when booting the zone,
124 * scratch is the standard scratch zone mount for upgrade and update is a
125 * variation on the scratch zone where we don't lofs mount the zone's /etc
126 * and /var back into the scratch zone so that we can then do an
127 * 'update on attach' within the scratch zone.
128 */
129 typedef enum {
130 Z_MNT_BOOT = 0,
131 Z_MNT_SCRATCH,
132 Z_MNT_UPDATE
133 } zone_mnt_t;
134
135 /*
136 * Virtual platform interfaces.
137 */
138 extern zoneid_t vplat_create(zlog_t *, zone_mnt_t);
139 extern int vplat_bringup(zlog_t *, zone_mnt_t, zoneid_t);
140 extern int vplat_teardown(zlog_t *, boolean_t, boolean_t);
141 extern int vplat_get_iptype(zlog_t *, zone_iptype_t *);
142
143 /*
144 * Filesystem mounting interfaces.
145 */
146 extern int valid_mount_path(zlog_t *, const char *, const char *,
147 const char *, const char *);
148 extern int make_one_dir(zlog_t *, const char *, const char *,
149 mode_t, uid_t, gid_t);
150 extern void resolve_lofs(zlog_t *zlogp, char *path, size_t pathlen);
151
152 /*
153 * Console subsystem routines.
154 */
155 extern int init_console(zlog_t *);
156 extern void serve_console(zlog_t *);
157
158 /*
159 * Contract handling.
160 */
161 extern int init_template(void);
162
163 /*
164 * Routine to manage child processes.
165 */
166 extern int do_subproc(zlog_t *, char *, char **);
167
168 #ifdef __cplusplus
169 }
170 #endif
171
172 #endif /* _ZONEADMD_H */
|
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 (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Copyright 2014 Nexenta Systems, Inc. All rights reserved.
25 * Copyright 2016 Joyent, Inc.
26 */
27
28 #ifndef _ZONEADMD_H
29 #define _ZONEADMD_H
30
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34
35 #include <libdladm.h>
36
37 /*
38 * Multi-threaded programs should avoid MT-unsafe library calls (i.e., any-
39 * thing which could try to acquire a user-level lock unprotected by an atfork
40 * handler) between fork(2) and exec(2). See the pthread_atfork(3THR) man
41 * page for details. In particular, we want to avoid calls to zerror() in
42 * such situations, as it calls setlocale(3c) which is susceptible to such
43 * problems. So instead we have the child use one of the special exit codes
44 * below when needed, and the parent look out for such possibilities and call
45 * zerror() there.
53
54 #define DEVFSADM "devfsadm"
55 #define DEVFSADM_PATH "/usr/sbin/devfsadm"
56
57 #define EXEC_PREFIX "exec "
58 #define EXEC_LEN (strlen(EXEC_PREFIX))
59
60 #define CLUSTER_BRAND_NAME "cluster"
61 #define LABELED_BRAND_NAME "labeled"
62
63 #define SHUTDOWN_WAIT 60
64 #define SHUTDOWN_DEFAULT "/sbin/init 0"
65 #define SHUTDOWN_FMRI "svc:/system/zones:default"
66
67 /* 0755 is the default directory mode. */
68 #define DEFAULT_DIR_MODE \
69 (S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)
70 #define DEFAULT_DIR_USER -1 /* user ID for chown: -1 means don't change */
71 #define DEFAULT_DIR_GROUP -1 /* grp ID for chown: -1 means don't change */
72
73 #define ALT_MOUNT(mount_cmd) ((mount_cmd) != Z_MNT_BOOT)
74
75 typedef struct zlog {
76 FILE *logfile; /* file to log to */
77
78 /*
79 * The following are used if logging to a buffer.
80 */
81 char *log; /* remaining log */
82 size_t loglen; /* size of remaining log */
83 char *buf; /* underlying storage */
84 size_t buflen; /* total len of 'buf' */
85 char *locale; /* locale to use for gettext() */
86 } zlog_t;
87
88 extern zlog_t logsys;
89
90 extern mutex_t lock;
91 extern mutex_t msglock;
92 extern boolean_t in_death_throes;
93 extern boolean_t bringup_failure_recovery;
94 extern char *zone_name;
95 extern char zonepath[MAXNAMELEN];
96 extern zone_dochandle_t snap_hndl;
97 extern char pool_name[MAXNAMELEN];
98 extern char brand_name[MAXNAMELEN];
99 extern char default_brand[MAXNAMELEN];
100 extern char boot_args[BOOTARGS_MAX];
101 extern boolean_t zone_isnative;
102 extern boolean_t zone_iscluster;
103 extern dladm_handle_t dld_handle;
104
105 extern void zerror(zlog_t *, boolean_t, const char *, ...);
106 extern char *localize_msg(char *locale, const char *msg);
107
108 /*
109 * Eventstream interfaces.
110 */
111 typedef enum {
112 Z_EVT_NULL = 0,
113 Z_EVT_ZONE_BOOTING,
114 Z_EVT_ZONE_REBOOTING,
115 Z_EVT_ZONE_HALTED,
116 Z_EVT_ZONE_READIED,
117 Z_EVT_ZONE_UNINSTALLING,
118 Z_EVT_ZONE_BOOTFAILED
119 } zone_evt_t;
120
121 extern int eventstream_init();
122 extern void eventstream_write(zone_evt_t evt);
123
124 /*
125 * Zone mount styles. Boot is the standard mount we do when booting the zone,
126 * scratch is the standard scratch zone mount for upgrade and update is a
127 * variation on the scratch zone where we don't lofs mount the zone's /etc
128 * and /var back into the scratch zone so that we can then do an
129 * 'update on attach' within the scratch zone.
130 */
131 typedef enum {
132 Z_MNT_BOOT = 0,
133 Z_MNT_SCRATCH,
134 Z_MNT_UPDATE
135 } zone_mnt_t;
136
137 /*
138 * Virtual platform interfaces.
139 */
140 extern zoneid_t vplat_create(zlog_t *, zone_mnt_t);
141 extern int vplat_bringup(zlog_t *, zone_mnt_t, zoneid_t);
142 extern int vplat_teardown(zlog_t *, boolean_t, boolean_t);
143 extern int vplat_get_iptype(zlog_t *, zone_iptype_t *);
144
145 /*
146 * Filesystem mounting interfaces.
147 */
148 extern int valid_mount_path(zlog_t *, const char *, const char *,
149 const char *, const char *);
150 extern int make_one_dir(zlog_t *, const char *, const char *,
151 mode_t, uid_t, gid_t);
152 extern void resolve_lofs(zlog_t *zlogp, char *path, size_t pathlen);
153
154 /*
155 * Console subsystem routines.
156 */
157 extern int init_console(zlog_t *);
158 extern void serve_console(zlog_t *);
159 extern void zcons_statechanged();
160
161 /*
162 * Memory capping thread creation.
163 */
164 extern void create_mcap_thread(zlog_t *, zoneid_t);
165 extern void destroy_mcap_thread();
166
167 /*
168 * Zone FD log thread creation.
169 */
170 extern void create_log_thread(zlog_t *, zoneid_t);
171 extern void destroy_log_thread();
172
173 /*
174 * Contract handling.
175 */
176 extern int init_template(void);
177
178 /*
179 * Routine to manage child processes.
180 */
181 extern int do_subproc(zlog_t *, char *, char **);
182
183 #ifdef __cplusplus
184 }
185 #endif
186
187 #endif /* _ZONEADMD_H */
|