Print this page
| Split |
Close |
| Expand all |
| Collapse all |
--- old/usr/src/lib/libc/port/sys/zone.c
+++ new/usr/src/lib/libc/port/sys/zone.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
|
↓ open down ↓ |
14 lines elided |
↑ open up ↑ |
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21
22 22 /*
23 23 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
24 24 * Use is subject to license terms.
25 - * Copyright 2011 Joyent Inc. All rights reserved.
26 25 */
27 26
28 27 #include "lint.h"
29 28 #include "thr_uberdata.h"
30 29 #include <sys/types.h>
31 30 #include <sys/syscall.h>
32 31 #include <sys/zone.h>
33 32 #include <sys/priv.h>
34 33 #include <priv_private.h>
35 34 #include <zone.h>
36 35 #include <sys/tsol/label.h>
37 36 #include <dlfcn.h>
38 37 #include <stdlib.h>
39 38 #include <errno.h>
40 39
41 40 zoneid_t
42 41 zone_create(const char *name, const char *root, const struct priv_set *privs,
43 42 const char *rctls, size_t rctlsz, const char *zfs, size_t zfssz,
44 - int *extended_error, int match, int doi, const bslabel_t *label, int flags,
45 - zoneid_t req_zoneid)
43 + int *extended_error, int match, int doi, const bslabel_t *label, int flags)
46 44 {
47 45 zone_def zd;
48 46 priv_data_t *d;
49 47
50 48 LOADPRIVDATA(d);
51 49
52 50 zd.zone_name = name;
53 51 zd.zone_root = root;
54 52 zd.zone_privs = privs;
55 53 zd.zone_privssz = d->pd_setsize;
56 54 zd.rctlbuf = rctls;
57 55 zd.rctlbufsz = rctlsz;
58 56 zd.zfsbuf = zfs;
59 57 zd.zfsbufsz = zfssz;
60 58 zd.extended_error = extended_error;
61 59 zd.match = match;
62 60 zd.doi = doi;
63 61 zd.label = label;
64 62 zd.flags = flags;
65 - zd.zoneid = req_zoneid;
66 63
67 64 return ((zoneid_t)syscall(SYS_zone, ZONE_CREATE, &zd));
68 65 }
69 66
70 67 int
71 68 zone_boot(zoneid_t zoneid)
72 69 {
73 70 return (syscall(SYS_zone, ZONE_BOOT, zoneid));
74 71 }
75 72
76 73 int
77 74 zone_shutdown(zoneid_t zoneid)
78 75 {
79 76 return (syscall(SYS_zone, ZONE_SHUTDOWN, zoneid));
80 77 }
81 78
82 79 int
83 80 zone_destroy(zoneid_t zoneid)
84 81 {
85 82 return (syscall(SYS_zone, ZONE_DESTROY, zoneid));
86 83 }
87 84
88 85 ssize_t
89 86 zone_getattr(zoneid_t zoneid, int attr, void *valp, size_t size)
90 87 {
91 88 sysret_t rval;
92 89 int error;
93 90
94 91 error = __systemcall(&rval, SYS_zone, ZONE_GETATTR, zoneid,
95 92 attr, valp, size);
96 93 if (error)
97 94 (void) __set_errno(error);
98 95 return ((ssize_t)rval.sys_rval1);
99 96 }
100 97
101 98 int
102 99 zone_setattr(zoneid_t zoneid, int attr, void *valp, size_t size)
103 100 {
104 101 return (syscall(SYS_zone, ZONE_SETATTR, zoneid, attr, valp, size));
105 102 }
106 103
107 104 int
108 105 zone_enter(zoneid_t zoneid)
109 106 {
110 107 return (syscall(SYS_zone, ZONE_ENTER, zoneid));
111 108 }
112 109
113 110 /*
114 111 * Get id (if any) for specified zone.
115 112 *
116 113 * Call the real zone_get_id() in libzonecfg.so.1 if it can be found.
117 114 * Otherwise, perform a stripped-down version of the function.
118 115 * Any changes in one version should probably be reflected in the other.
119 116 *
120 117 * This stripped-down version of the function only checks for active
121 118 * (booted) zones, by numeric id or name.
122 119 */
123 120
124 121 typedef int (*zone_get_id_t)(const char *, zoneid_t *);
125 122 static zone_get_id_t real_zone_get_id = NULL;
126 123
127 124 int
128 125 zone_get_id(const char *str, zoneid_t *zip)
129 126 {
130 127 zoneid_t zoneid;
131 128 char *cp;
132 129
133 130 /*
134 131 * The first time we are called, attempt to dlopen() libzonecfg.so.1
135 132 * and get a pointer to the real zone_get_id().
136 133 * If we fail, set our pointer to -1 so we won't try again.
137 134 */
138 135 if (real_zone_get_id == NULL) {
139 136 /*
140 137 * There's no harm in doing this more than once, even
141 138 * concurrently. We will get the same result each time,
142 139 * and the dynamic linker will single-thread the dlopen()
143 140 * with its own internal lock. The worst that can happen
144 141 * is that the handle gets a reference count greater than
145 142 * one, which doesn't matter since we never dlclose()
146 143 * the handle if we successfully find the symbol; the
147 144 * library just stays in the address space until exit().
148 145 */
149 146 void *dlhandle = dlopen("libzonecfg.so.1", RTLD_LAZY);
150 147 void *sym = (void *)(-1);
151 148
152 149 if (dlhandle != NULL &&
153 150 (sym = dlsym(dlhandle, "zone_get_id")) == NULL) {
154 151 sym = (void *)(-1);
155 152 (void) dlclose(dlhandle);
156 153 }
157 154 real_zone_get_id = (zone_get_id_t)sym;
158 155 }
159 156
160 157 /*
161 158 * If we've successfully loaded it, call the real zone_get_id().
162 159 * Otherwise, perform our stripped-down version of the code.
163 160 */
164 161 if (real_zone_get_id != (zone_get_id_t)(-1))
165 162 return (real_zone_get_id(str, zip));
166 163
167 164 /* first try looking for active zone by id */
168 165 errno = 0;
169 166 zoneid = (zoneid_t)strtol(str, &cp, 0);
170 167 if (errno == 0 && cp != str && *cp == '\0' &&
171 168 getzonenamebyid(zoneid, NULL, 0) != -1) {
172 169 *zip = zoneid;
173 170 return (0);
174 171 }
175 172
176 173 /* then look for active zone by name */
177 174 if ((zoneid = getzoneidbyname(str)) != -1) {
178 175 *zip = zoneid;
179 176 return (0);
180 177 }
181 178
182 179 /* not an active zone, return error */
183 180 return (-1);
184 181 }
185 182
186 183 int
187 184 zone_list(zoneid_t *zonelist, uint_t *numzones)
188 185 {
189 186 return (syscall(SYS_zone, ZONE_LIST, zonelist, numzones));
190 187 }
191 188
192 189 /*
193 190 * Underlying implementation for getzoneid and getzoneidbyname.
194 191 */
195 192 static zoneid_t
196 193 zone_lookup(const char *name)
197 194 {
198 195 return ((zoneid_t)syscall(SYS_zone, ZONE_LOOKUP, name));
199 196 }
200 197
201 198 zoneid_t
202 199 getzoneid(void)
203 200 {
204 201 return (zone_lookup(NULL));
205 202 }
206 203
207 204 zoneid_t
208 205 getzoneidbyname(const char *zonename)
209 206 {
210 207 return (zone_lookup(zonename));
211 208 }
212 209
213 210 ssize_t
214 211 getzonenamebyid(zoneid_t zoneid, char *buf, size_t buflen)
215 212 {
216 213 return (zone_getattr(zoneid, ZONE_ATTR_NAME, buf, buflen));
217 214 }
218 215
219 216 int
220 217 zone_version(int *version)
221 218 {
222 219 return (syscall(SYS_zone, ZONE_VERSION, version));
223 220 }
224 221
225 222 int
226 223 zone_add_datalink(zoneid_t zoneid, datalink_id_t linkid)
227 224 {
228 225 return (syscall(SYS_zone, ZONE_ADD_DATALINK, zoneid, linkid));
229 226 }
230 227
231 228 int
232 229 zone_remove_datalink(zoneid_t zoneid, datalink_id_t linkid)
233 230 {
234 231 return (syscall(SYS_zone, ZONE_DEL_DATALINK, zoneid, linkid));
235 232 }
236 233
237 234 int
238 235 zone_check_datalink(zoneid_t *zoneidp, datalink_id_t linkid)
239 236 {
240 237 return (syscall(SYS_zone, ZONE_CHECK_DATALINK, zoneidp, linkid));
241 238 }
242 239
243 240 int
244 241 zone_list_datalink(zoneid_t zoneid, int *dlnump, datalink_id_t *linkids)
245 242 {
246 243 return (syscall(SYS_zone, ZONE_LIST_DATALINK, zoneid, dlnump, linkids));
247 244 }
248 245
249 246 const char *
250 247 zone_get_nroot()
251 248 {
252 249 uberdata_t *udp = curthread->ul_uberdata;
253 250 return (udp->ub_broot);
254 251 }
|
↓ open down ↓ |
179 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX