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.
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.
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]
23 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
28 #include <sys/types.h>
29 #include <sys/syscall.h>
32 #include <priv_private.h>
39 zone_create(const char *name
, const char *root
, const struct priv_set
*privs
,
40 const char *rctls
, size_t rctlsz
, const char *zfs
, size_t zfssz
,
41 int *extended_error
, int flags
)
50 zd
.zone_privs
= privs
;
51 zd
.zone_privssz
= d
->pd_setsize
;
53 zd
.rctlbufsz
= rctlsz
;
56 zd
.extended_error
= extended_error
;
59 return ((zoneid_t
)syscall(SYS_zone
, ZONE_CREATE
, &zd
));
63 zone_boot(zoneid_t zoneid
)
65 return (syscall(SYS_zone
, ZONE_BOOT
, zoneid
));
69 zone_shutdown(zoneid_t zoneid
)
71 return (syscall(SYS_zone
, ZONE_SHUTDOWN
, zoneid
));
75 zone_destroy(zoneid_t zoneid
)
77 return (syscall(SYS_zone
, ZONE_DESTROY
, zoneid
));
81 zone_getattr(zoneid_t zoneid
, int attr
, void *valp
, size_t size
)
86 error
= __systemcall(&rval
, SYS_zone
, ZONE_GETATTR
, zoneid
,
89 (void) __set_errno(error
);
90 return ((ssize_t
)rval
.sys_rval1
);
94 zone_setattr(zoneid_t zoneid
, int attr
, void *valp
, size_t size
)
96 return (syscall(SYS_zone
, ZONE_SETATTR
, zoneid
, attr
, valp
, size
));
100 zone_enter(zoneid_t zoneid
)
102 return (syscall(SYS_zone
, ZONE_ENTER
, zoneid
));
106 * Get id (if any) for specified zone.
108 * Call the real zone_get_id() in libzonecfg.so.1 if it can be found.
109 * Otherwise, perform a stripped-down version of the function.
110 * Any changes in one version should probably be reflected in the other.
112 * This stripped-down version of the function only checks for active
113 * (booted) zones, by numeric id or name.
116 typedef int (*zone_get_id_t
)(const char *, zoneid_t
*);
117 static zone_get_id_t real_zone_get_id
= NULL
;
120 zone_get_id(const char *str
, zoneid_t
*zip
)
126 * The first time we are called, attempt to dlopen() libzonecfg.so.1
127 * and get a pointer to the real zone_get_id().
128 * If we fail, set our pointer to -1 so we won't try again.
130 if (real_zone_get_id
== NULL
) {
132 * There's no harm in doing this more than once, even
133 * concurrently. We will get the same result each time,
134 * and the dynamic linker will single-thread the dlopen()
135 * with its own internal lock. The worst that can happen
136 * is that the handle gets a reference count greater than
137 * one, which doesn't matter since we never dlclose()
138 * the handle if we successfully find the symbol; the
139 * library just stays in the address space until exit().
141 void *dlhandle
= dlopen("libzonecfg.so.1", RTLD_LAZY
);
142 void *sym
= (void *)(-1);
144 if (dlhandle
!= NULL
&&
145 (sym
= dlsym(dlhandle
, "zone_get_id")) == NULL
) {
147 (void) dlclose(dlhandle
);
149 real_zone_get_id
= (zone_get_id_t
)sym
;
153 * If we've successfully loaded it, call the real zone_get_id().
154 * Otherwise, perform our stripped-down version of the code.
156 if (real_zone_get_id
!= (zone_get_id_t
)(-1))
157 return (real_zone_get_id(str
, zip
));
159 /* first try looking for active zone by id */
161 zoneid
= (zoneid_t
)strtol(str
, &cp
, 0);
162 if (errno
== 0 && cp
!= str
&& *cp
== '\0' &&
163 getzonenamebyid(zoneid
, NULL
, 0) != -1) {
168 /* then look for active zone by name */
169 if ((zoneid
= getzoneidbyname(str
)) != -1) {
174 /* not an active zone, return error */
179 zone_list(zoneid_t
*zonelist
, uint_t
*numzones
)
181 return (syscall(SYS_zone
, ZONE_LIST
, zonelist
, numzones
));
185 * Underlying implementation for getzoneid and getzoneidbyname.
188 zone_lookup(const char *name
)
190 return ((zoneid_t
)syscall(SYS_zone
, ZONE_LOOKUP
, name
));
196 return (zone_lookup(NULL
));
200 getzoneidbyname(const char *zonename
)
202 return (zone_lookup(zonename
));
206 getzonenamebyid(zoneid_t zoneid
, char *buf
, size_t buflen
)
208 return (zone_getattr(zoneid
, ZONE_ATTR_NAME
, buf
, buflen
));
212 zone_version(int *version
)
214 return (syscall(SYS_zone
, ZONE_VERSION
, version
));
218 zone_add_datalink(zoneid_t zoneid
, datalink_id_t linkid
)
220 return (syscall(SYS_zone
, ZONE_ADD_DATALINK
, zoneid
, linkid
));
224 zone_remove_datalink(zoneid_t zoneid
, datalink_id_t linkid
)
226 return (syscall(SYS_zone
, ZONE_DEL_DATALINK
, zoneid
, linkid
));
230 zone_check_datalink(zoneid_t
*zoneidp
, datalink_id_t linkid
)
232 return (syscall(SYS_zone
, ZONE_CHECK_DATALINK
, zoneidp
, linkid
));
236 zone_list_datalink(zoneid_t zoneid
, int *dlnump
, datalink_id_t
*linkids
)
238 return (syscall(SYS_zone
, ZONE_LIST_DATALINK
, zoneid
, dlnump
, linkids
));