Print this page
OS-3280 need a way to specify the root of a native system in the lx brand
OS-3279 lx brand should allow delegated datasets
Reviewed by: Jerry Jelinek <jerry.jelinek@joyent.com>
| 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.
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]
|
↓ open down ↓ |
17 lines elided |
↑ open up ↑ |
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 25 */
26 26
27 27 #include "lint.h"
28 +#include "thr_uberdata.h"
28 29 #include <sys/types.h>
29 30 #include <sys/syscall.h>
30 31 #include <sys/zone.h>
31 32 #include <sys/priv.h>
32 33 #include <priv_private.h>
33 34 #include <zone.h>
34 35 #include <sys/tsol/label.h>
35 36 #include <dlfcn.h>
36 37 #include <stdlib.h>
37 38 #include <errno.h>
38 39
39 40 zoneid_t
40 41 zone_create(const char *name, const char *root, const struct priv_set *privs,
41 42 const char *rctls, size_t rctlsz, const char *zfs, size_t zfssz,
42 43 int *extended_error, int match, int doi, const bslabel_t *label, int flags)
43 44 {
44 45 zone_def zd;
45 46 priv_data_t *d;
46 47
47 48 LOADPRIVDATA(d);
48 49
49 50 zd.zone_name = name;
50 51 zd.zone_root = root;
51 52 zd.zone_privs = privs;
52 53 zd.zone_privssz = d->pd_setsize;
53 54 zd.rctlbuf = rctls;
54 55 zd.rctlbufsz = rctlsz;
55 56 zd.zfsbuf = zfs;
56 57 zd.zfsbufsz = zfssz;
57 58 zd.extended_error = extended_error;
58 59 zd.match = match;
59 60 zd.doi = doi;
60 61 zd.label = label;
61 62 zd.flags = flags;
62 63
63 64 return ((zoneid_t)syscall(SYS_zone, ZONE_CREATE, &zd));
64 65 }
65 66
66 67 int
67 68 zone_boot(zoneid_t zoneid)
68 69 {
69 70 return (syscall(SYS_zone, ZONE_BOOT, zoneid));
70 71 }
71 72
72 73 int
73 74 zone_shutdown(zoneid_t zoneid)
74 75 {
75 76 return (syscall(SYS_zone, ZONE_SHUTDOWN, zoneid));
76 77 }
77 78
78 79 int
79 80 zone_destroy(zoneid_t zoneid)
80 81 {
81 82 return (syscall(SYS_zone, ZONE_DESTROY, zoneid));
82 83 }
83 84
84 85 ssize_t
85 86 zone_getattr(zoneid_t zoneid, int attr, void *valp, size_t size)
86 87 {
87 88 sysret_t rval;
88 89 int error;
89 90
90 91 error = __systemcall(&rval, SYS_zone, ZONE_GETATTR, zoneid,
91 92 attr, valp, size);
92 93 if (error)
93 94 (void) __set_errno(error);
94 95 return ((ssize_t)rval.sys_rval1);
95 96 }
96 97
97 98 int
98 99 zone_setattr(zoneid_t zoneid, int attr, void *valp, size_t size)
99 100 {
100 101 return (syscall(SYS_zone, ZONE_SETATTR, zoneid, attr, valp, size));
101 102 }
102 103
103 104 int
104 105 zone_enter(zoneid_t zoneid)
105 106 {
106 107 return (syscall(SYS_zone, ZONE_ENTER, zoneid));
107 108 }
108 109
109 110 /*
110 111 * Get id (if any) for specified zone.
111 112 *
112 113 * Call the real zone_get_id() in libzonecfg.so.1 if it can be found.
113 114 * Otherwise, perform a stripped-down version of the function.
114 115 * Any changes in one version should probably be reflected in the other.
115 116 *
116 117 * This stripped-down version of the function only checks for active
117 118 * (booted) zones, by numeric id or name.
118 119 */
119 120
120 121 typedef int (*zone_get_id_t)(const char *, zoneid_t *);
121 122 static zone_get_id_t real_zone_get_id = NULL;
122 123
123 124 int
124 125 zone_get_id(const char *str, zoneid_t *zip)
125 126 {
126 127 zoneid_t zoneid;
127 128 char *cp;
128 129
129 130 /*
130 131 * The first time we are called, attempt to dlopen() libzonecfg.so.1
131 132 * and get a pointer to the real zone_get_id().
132 133 * If we fail, set our pointer to -1 so we won't try again.
133 134 */
134 135 if (real_zone_get_id == NULL) {
135 136 /*
136 137 * There's no harm in doing this more than once, even
137 138 * concurrently. We will get the same result each time,
138 139 * and the dynamic linker will single-thread the dlopen()
139 140 * with its own internal lock. The worst that can happen
140 141 * is that the handle gets a reference count greater than
141 142 * one, which doesn't matter since we never dlclose()
142 143 * the handle if we successfully find the symbol; the
143 144 * library just stays in the address space until exit().
144 145 */
145 146 void *dlhandle = dlopen("libzonecfg.so.1", RTLD_LAZY);
146 147 void *sym = (void *)(-1);
147 148
148 149 if (dlhandle != NULL &&
149 150 (sym = dlsym(dlhandle, "zone_get_id")) == NULL) {
150 151 sym = (void *)(-1);
151 152 (void) dlclose(dlhandle);
152 153 }
153 154 real_zone_get_id = (zone_get_id_t)sym;
154 155 }
155 156
156 157 /*
157 158 * If we've successfully loaded it, call the real zone_get_id().
158 159 * Otherwise, perform our stripped-down version of the code.
159 160 */
160 161 if (real_zone_get_id != (zone_get_id_t)(-1))
161 162 return (real_zone_get_id(str, zip));
162 163
163 164 /* first try looking for active zone by id */
164 165 errno = 0;
165 166 zoneid = (zoneid_t)strtol(str, &cp, 0);
166 167 if (errno == 0 && cp != str && *cp == '\0' &&
167 168 getzonenamebyid(zoneid, NULL, 0) != -1) {
168 169 *zip = zoneid;
169 170 return (0);
170 171 }
171 172
172 173 /* then look for active zone by name */
173 174 if ((zoneid = getzoneidbyname(str)) != -1) {
174 175 *zip = zoneid;
175 176 return (0);
176 177 }
177 178
178 179 /* not an active zone, return error */
179 180 return (-1);
180 181 }
181 182
182 183 int
183 184 zone_list(zoneid_t *zonelist, uint_t *numzones)
184 185 {
185 186 return (syscall(SYS_zone, ZONE_LIST, zonelist, numzones));
186 187 }
187 188
188 189 /*
189 190 * Underlying implementation for getzoneid and getzoneidbyname.
190 191 */
191 192 static zoneid_t
192 193 zone_lookup(const char *name)
193 194 {
194 195 return ((zoneid_t)syscall(SYS_zone, ZONE_LOOKUP, name));
195 196 }
196 197
197 198 zoneid_t
198 199 getzoneid(void)
199 200 {
200 201 return (zone_lookup(NULL));
201 202 }
202 203
203 204 zoneid_t
204 205 getzoneidbyname(const char *zonename)
205 206 {
206 207 return (zone_lookup(zonename));
207 208 }
208 209
209 210 ssize_t
210 211 getzonenamebyid(zoneid_t zoneid, char *buf, size_t buflen)
211 212 {
212 213 return (zone_getattr(zoneid, ZONE_ATTR_NAME, buf, buflen));
213 214 }
214 215
215 216 int
216 217 zone_version(int *version)
217 218 {
218 219 return (syscall(SYS_zone, ZONE_VERSION, version));
219 220 }
220 221
221 222 int
222 223 zone_add_datalink(zoneid_t zoneid, datalink_id_t linkid)
223 224 {
224 225 return (syscall(SYS_zone, ZONE_ADD_DATALINK, zoneid, linkid));
225 226 }
226 227
227 228 int
228 229 zone_remove_datalink(zoneid_t zoneid, datalink_id_t linkid)
229 230 {
230 231 return (syscall(SYS_zone, ZONE_DEL_DATALINK, zoneid, linkid));
231 232 }
232 233
|
↓ open down ↓ |
195 lines elided |
↑ open up ↑ |
233 234 int
234 235 zone_check_datalink(zoneid_t *zoneidp, datalink_id_t linkid)
235 236 {
236 237 return (syscall(SYS_zone, ZONE_CHECK_DATALINK, zoneidp, linkid));
237 238 }
238 239
239 240 int
240 241 zone_list_datalink(zoneid_t zoneid, int *dlnump, datalink_id_t *linkids)
241 242 {
242 243 return (syscall(SYS_zone, ZONE_LIST_DATALINK, zoneid, dlnump, linkids));
244 +}
245 +
246 +const char *
247 +zone_get_nroot()
248 +{
249 + uberdata_t *udp = curthread->ul_uberdata;
250 + return (udp->ub_broot);
243 251 }
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX