xref: /titanic_50/usr/src/cmd/zoneadmd/zoneadmd.h (revision e07b36b5f925802c7a364a9b5dcbd2a8d184e2c6)
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 2009 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
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.
45  *
46  * Since 0, 1 and 2 are generally used for success, general error, and usage,
47  * we start with 3.
48  */
49 #define	ZEXIT_FORK		3
50 #define	ZEXIT_EXEC		4
51 #define	ZEXIT_ZONE_ENTER	5
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 /* 0755 is the default directory mode. */
63 #define	DEFAULT_DIR_MODE \
64 	(S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)
65 #define	DEFAULT_DIR_USER -1	/* user ID for chown: -1 means don't change */
66 #define	DEFAULT_DIR_GROUP -1	/* grp ID for chown: -1 means don't change */
67 
68 
69 typedef struct zlog {
70 	FILE *logfile;	/* file to log to */
71 
72 	/*
73 	 * The following are used if logging to a buffer.
74 	 */
75 	char *log;	/* remaining log */
76 	size_t loglen;	/* size of remaining log */
77 	char *buf;	/* underlying storage */
78 	size_t buflen;	/* total len of 'buf' */
79 	char *locale;	/* locale to use for gettext() */
80 } zlog_t;
81 
82 extern zlog_t logsys;
83 
84 extern mutex_t lock;
85 extern mutex_t msglock;
86 extern boolean_t in_death_throes;
87 extern boolean_t bringup_failure_recovery;
88 extern char *zone_name;
89 extern char boot_args[BOOTARGS_MAX];
90 extern char bad_boot_arg[BOOTARGS_MAX];
91 extern boolean_t zone_isnative;
92 extern boolean_t zone_iscluster;
93 extern dladm_handle_t dld_handle;
94 
95 extern void zerror(zlog_t *, boolean_t, const char *, ...);
96 extern char *localize_msg(char *locale, const char *msg);
97 
98 /*
99  * Eventstream interfaces.
100  */
101 typedef enum {
102 	Z_EVT_NULL = 0,
103 	Z_EVT_ZONE_BOOTING,
104 	Z_EVT_ZONE_REBOOTING,
105 	Z_EVT_ZONE_HALTED,
106 	Z_EVT_ZONE_READIED,
107 	Z_EVT_ZONE_UNINSTALLING,
108 	Z_EVT_ZONE_BOOTFAILED,
109 	Z_EVT_ZONE_BADARGS
110 } zone_evt_t;
111 
112 extern int eventstream_init();
113 extern void eventstream_write(zone_evt_t evt);
114 
115 /*
116  * Zone mount styles.  Boot is the standard mount we do when booting the zone,
117  * scratch is the standard scratch zone mount for upgrade and update is a
118  * variation on the scratch zone where we don't lofs mount the zone's /etc
119  * and /var back into the scratch zone so that we can then do an
120  * 'update on attach' within the scratch zone.
121  */
122 typedef enum {
123 	Z_MNT_BOOT = 0,
124 	Z_MNT_SCRATCH,
125 	Z_MNT_UPDATE
126 } zone_mnt_t;
127 
128 /*
129  * Virtual platform interfaces.
130  */
131 extern zoneid_t vplat_create(zlog_t *, zone_mnt_t);
132 extern int vplat_bringup(zlog_t *, zone_mnt_t, zoneid_t);
133 extern int vplat_teardown(zlog_t *, boolean_t, boolean_t);
134 extern int vplat_get_iptype(zlog_t *, zone_iptype_t *);
135 
136 /*
137  * Filesystem mounting interfaces.
138  */
139 extern int valid_mount_path(zlog_t *, const char *, const char *,
140     const char *, const char *);
141 extern int make_one_dir(zlog_t *, const char *, const char *,
142     mode_t, uid_t, gid_t);
143 extern void resolve_lofs(zlog_t *zlogp, char *path, size_t pathlen);
144 
145 /*
146  * Console subsystem routines.
147  */
148 extern int init_console(zlog_t *);
149 extern void serve_console(zlog_t *);
150 
151 /*
152  * Contract handling.
153  */
154 extern int init_template(void);
155 
156 /*
157  * Routine to manage child processes.
158  */
159 extern int do_subproc(zlog_t *, char *, char **);
160 
161 #ifdef __cplusplus
162 }
163 #endif
164 
165 #endif /* _ZONEADMD_H */
166