xref: /titanic_51/usr/src/cmd/zoneadmd/zoneadmd.h (revision 613b28719c10e84c1202c1045df44d77767de21d)
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 2008 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 /*
35  * Multi-threaded programs should avoid MT-unsafe library calls (i.e., any-
36  * thing which could try to acquire a user-level lock unprotected by an atfork
37  * handler) between fork(2) and exec(2).  See the pthread_atfork(3THR) man
38  * page for details.  In particular, we want to avoid calls to zerror() in
39  * such situations, as it calls setlocale(3c) which is susceptible to such
40  * problems.  So instead we have the child use one of the special exit codes
41  * below when needed, and the parent look out for such possibilities and call
42  * zerror() there.
43  *
44  * Since 0, 1 and 2 are generally used for success, general error, and usage,
45  * we start with 3.
46  */
47 #define	ZEXIT_FORK		3
48 #define	ZEXIT_EXEC		4
49 #define	ZEXIT_ZONE_ENTER	5
50 
51 #define	DEVFSADM	"devfsadm"
52 #define	DEVFSADM_PATH	"/usr/sbin/devfsadm"
53 
54 #define	EXEC_PREFIX	"exec "
55 #define	EXEC_LEN	(strlen(EXEC_PREFIX))
56 
57 #define	CLUSTER_BRAND_NAME	"cluster"
58 
59 /* 0755 is the default directory mode. */
60 #define	DEFAULT_DIR_MODE \
61 	(S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)
62 #define	DEFAULT_DIR_USER -1	/* user ID for chown: -1 means don't change */
63 #define	DEFAULT_DIR_GROUP -1	/* grp ID for chown: -1 means don't change */
64 
65 
66 typedef struct zlog {
67 	FILE *logfile;	/* file to log to */
68 
69 	/*
70 	 * The following are used if logging to a buffer.
71 	 */
72 	char *log;	/* remaining log */
73 	size_t loglen;	/* size of remaining log */
74 	char *buf;	/* underlying storage */
75 	size_t buflen;	/* total len of 'buf' */
76 	char *locale;	/* locale to use for gettext() */
77 } zlog_t;
78 
79 extern zlog_t logsys;
80 
81 extern mutex_t lock;
82 extern mutex_t msglock;
83 extern boolean_t in_death_throes;
84 extern boolean_t bringup_failure_recovery;
85 extern char *zone_name;
86 extern char boot_args[BOOTARGS_MAX];
87 extern char bad_boot_arg[BOOTARGS_MAX];
88 extern boolean_t zone_isnative;
89 extern boolean_t zone_iscluster;
90 
91 extern void zerror(zlog_t *, boolean_t, const char *, ...);
92 extern char *localize_msg(char *locale, const char *msg);
93 
94 /*
95  * Eventstream interfaces.
96  */
97 typedef enum {
98 	Z_EVT_NULL = 0,
99 	Z_EVT_ZONE_BOOTING,
100 	Z_EVT_ZONE_REBOOTING,
101 	Z_EVT_ZONE_HALTED,
102 	Z_EVT_ZONE_READIED,
103 	Z_EVT_ZONE_UNINSTALLING,
104 	Z_EVT_ZONE_BOOTFAILED,
105 	Z_EVT_ZONE_BADARGS
106 } zone_evt_t;
107 
108 extern int eventstream_init();
109 extern void eventstream_write(zone_evt_t evt);
110 
111 /*
112  * Zone mount styles.  Boot is the standard mount we do when booting the zone,
113  * scratch is the standard scratch zone mount for upgrade and update is a
114  * variation on the scratch zone where we don't lofs mount the zone's /etc
115  * and /var back into the scratch zone so that we can then do an
116  * 'update on attach' within the scratch zone.
117  */
118 typedef enum {
119 	Z_MNT_BOOT = 0,
120 	Z_MNT_SCRATCH,
121 	Z_MNT_UPDATE
122 } zone_mnt_t;
123 
124 /*
125  * Virtual platform interfaces.
126  */
127 extern zoneid_t vplat_create(zlog_t *, zone_mnt_t);
128 extern int vplat_bringup(zlog_t *, zone_mnt_t, zoneid_t);
129 extern int vplat_teardown(zlog_t *, boolean_t, boolean_t);
130 
131 /*
132  * Filesystem mounting interfaces.
133  */
134 extern int valid_mount_path(zlog_t *, const char *, const char *,
135     const char *, const char *);
136 extern int make_one_dir(zlog_t *, const char *, const char *,
137     mode_t, uid_t, gid_t);
138 extern void resolve_lofs(zlog_t *zlogp, char *path, size_t pathlen);
139 
140 /*
141  * Console subsystem routines.
142  */
143 extern int init_console_slave(zlog_t *);
144 extern void destroy_console_slave(void);
145 extern void reset_slave_terminal(zlog_t *);
146 extern int init_console(zlog_t *);
147 extern void serve_console(zlog_t *);
148 
149 /*
150  * Contract handling.
151  */
152 extern int init_template(void);
153 
154 /*
155  * Routine to manage child processes.
156  */
157 extern int do_subproc(zlog_t *, char *, char **);
158 
159 #ifdef __cplusplus
160 }
161 #endif
162 
163 #endif /* _ZONEADMD_H */
164