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