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 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. 23 */ 24 25 #ifndef _SYS_ZONE_H 26 #define _SYS_ZONE_H 27 28 #include <sys/types.h> 29 #include <sys/mutex.h> 30 #include <sys/param.h> 31 #include <sys/rctl.h> 32 #include <sys/ipc_rctl.h> 33 #include <sys/pset.h> 34 #include <sys/tsol/label.h> 35 #include <sys/cred.h> 36 #include <sys/netstack.h> 37 #include <sys/uadmin.h> 38 #include <sys/ksynch.h> 39 #include <sys/socket_impl.h> 40 #include <netinet/in.h> 41 42 #ifdef __cplusplus 43 extern "C" { 44 #endif 45 46 /* 47 * NOTE 48 * 49 * The contents of this file are private to the implementation of 50 * Solaris and are subject to change at any time without notice. 51 * Applications and drivers using these interfaces may fail to 52 * run on future releases. 53 */ 54 55 /* Available both in kernel and for user space */ 56 57 /* zone id restrictions and special ids */ 58 #define MAX_ZONEID 9999 59 #define MIN_USERZONEID 1 /* lowest user-creatable zone ID */ 60 #define MIN_ZONEID 0 /* minimum zone ID on system */ 61 #define GLOBAL_ZONEID 0 62 #define ZONEID_WIDTH 4 /* for printf */ 63 64 /* 65 * Special zoneid_t token to refer to all zones. 66 */ 67 #define ALL_ZONES (-1) 68 69 /* system call subcodes */ 70 #define ZONE_CREATE 0 71 #define ZONE_DESTROY 1 72 #define ZONE_GETATTR 2 73 #define ZONE_ENTER 3 74 #define ZONE_LIST 4 75 #define ZONE_SHUTDOWN 5 76 #define ZONE_LOOKUP 6 77 #define ZONE_BOOT 7 78 #define ZONE_VERSION 8 79 #define ZONE_SETATTR 9 80 #define ZONE_ADD_DATALINK 10 81 #define ZONE_DEL_DATALINK 11 82 #define ZONE_CHECK_DATALINK 12 83 #define ZONE_LIST_DATALINK 13 84 85 /* zone attributes */ 86 #define ZONE_ATTR_ROOT 1 87 #define ZONE_ATTR_NAME 2 88 #define ZONE_ATTR_STATUS 3 89 #define ZONE_ATTR_PRIVSET 4 90 #define ZONE_ATTR_UNIQID 5 91 #define ZONE_ATTR_POOLID 6 92 #define ZONE_ATTR_INITPID 7 93 #define ZONE_ATTR_SLBL 8 94 #define ZONE_ATTR_INITNAME 9 95 #define ZONE_ATTR_BOOTARGS 10 96 #define ZONE_ATTR_BRAND 11 97 #define ZONE_ATTR_PHYS_MCAP 12 98 #define ZONE_ATTR_SCHED_CLASS 13 99 #define ZONE_ATTR_FLAGS 14 100 #define ZONE_ATTR_HOSTID 15 101 #define ZONE_ATTR_FS_ALLOWED 16 102 #define ZONE_ATTR_NETWORK 17 103 104 /* Start of the brand-specific attribute namespace */ 105 #define ZONE_ATTR_BRAND_ATTRS 32768 106 107 #define ZONE_FS_ALLOWED_MAX 1024 108 109 #define ZONE_EVENT_CHANNEL "com.sun:zones:status" 110 #define ZONE_EVENT_STATUS_CLASS "status" 111 #define ZONE_EVENT_STATUS_SUBCLASS "change" 112 113 #define ZONE_EVENT_UNINITIALIZED "uninitialized" 114 #define ZONE_EVENT_INITIALIZED "initialized" 115 #define ZONE_EVENT_READY "ready" 116 #define ZONE_EVENT_RUNNING "running" 117 #define ZONE_EVENT_SHUTTING_DOWN "shutting_down" 118 119 #define ZONE_CB_NAME "zonename" 120 #define ZONE_CB_NEWSTATE "newstate" 121 #define ZONE_CB_OLDSTATE "oldstate" 122 #define ZONE_CB_TIMESTAMP "when" 123 #define ZONE_CB_ZONEID "zoneid" 124 125 /* 126 * Exit values that may be returned by scripts or programs invoked by various 127 * zone commands. 128 * 129 * These are defined as: 130 * 131 * ZONE_SUBPROC_OK 132 * =============== 133 * The subprocess completed successfully. 134 * 135 * ZONE_SUBPROC_USAGE 136 * ================== 137 * The subprocess failed with a usage message, or a usage message should 138 * be output in its behalf. 139 * 140 * ZONE_SUBPROC_NOTCOMPLETE 141 * ======================== 142 * The subprocess did not complete, but the actions performed by the 143 * subprocess require no recovery actions by the user. 144 * 145 * For example, if the subprocess were called by "zoneadm install," the 146 * installation of the zone did not succeed but the user need not perform 147 * a "zoneadm uninstall" before attempting another install. 148 * 149 * ZONE_SUBPROC_FATAL 150 * ================== 151 * The subprocess failed in a fatal manner, usually one that will require 152 * some type of recovery action by the user. 153 * 154 * For example, if the subprocess were called by "zoneadm install," the 155 * installation of the zone did not succeed and the user will need to 156 * perform a "zoneadm uninstall" before another install attempt is 157 * possible. 158 * 159 * The non-success exit values are large to avoid accidental collision 160 * with values used internally by some commands (e.g. "Z_ERR" and 161 * "Z_USAGE" as used by zoneadm.) 162 */ 163 #define ZONE_SUBPROC_OK 0 164 #define ZONE_SUBPROC_USAGE 253 165 #define ZONE_SUBPROC_NOTCOMPLETE 254 166 #define ZONE_SUBPROC_FATAL 255 167 168 #ifdef _SYSCALL32 169 typedef struct { 170 caddr32_t zone_name; 171 caddr32_t zone_root; 172 caddr32_t zone_privs; 173 size32_t zone_privssz; 174 caddr32_t rctlbuf; 175 size32_t rctlbufsz; 176 caddr32_t extended_error; 177 caddr32_t zfsbuf; 178 size32_t zfsbufsz; 179 int match; /* match level */ 180 uint32_t doi; /* DOI for label */ 181 caddr32_t label; /* label associated with zone */ 182 int flags; 183 } zone_def32; 184 #endif 185 typedef struct { 186 const char *zone_name; 187 const char *zone_root; 188 const struct priv_set *zone_privs; 189 size_t zone_privssz; 190 const char *rctlbuf; 191 size_t rctlbufsz; 192 int *extended_error; 193 const char *zfsbuf; 194 size_t zfsbufsz; 195 int match; /* match level */ 196 uint32_t doi; /* DOI for label */ 197 const bslabel_t *label; /* label associated with zone */ 198 int flags; 199 } zone_def; 200 201 /* extended error information */ 202 #define ZE_UNKNOWN 0 /* No extended error info */ 203 #define ZE_CHROOTED 1 /* tried to zone_create from chroot */ 204 #define ZE_AREMOUNTS 2 /* there are mounts within the zone */ 205 #define ZE_LABELINUSE 3 /* label is already in use by some other zone */ 206 207 /* zone_status */ 208 typedef enum { 209 ZONE_IS_UNINITIALIZED = 0, 210 ZONE_IS_INITIALIZED, 211 ZONE_IS_READY, 212 ZONE_IS_BOOTING, 213 ZONE_IS_RUNNING, 214 ZONE_IS_SHUTTING_DOWN, 215 ZONE_IS_EMPTY, 216 ZONE_IS_DOWN, 217 ZONE_IS_DYING, 218 ZONE_IS_DEAD 219 } zone_status_t; 220 #define ZONE_MIN_STATE ZONE_IS_UNINITIALIZED 221 #define ZONE_MAX_STATE ZONE_IS_DEAD 222 223 /* 224 * Valid commands which may be issued by zoneadm to zoneadmd. The kernel also 225 * communicates with zoneadmd, but only uses Z_REBOOT and Z_HALT. 226 */ 227 typedef enum zone_cmd { 228 Z_READY, Z_BOOT, Z_FORCEBOOT, Z_REBOOT, Z_HALT, Z_NOTE_UNINSTALLING, 229 Z_MOUNT, Z_FORCEMOUNT, Z_UNMOUNT 230 } zone_cmd_t; 231 232 /* 233 * The structure of a request to zoneadmd. 234 */ 235 typedef struct zone_cmd_arg { 236 uint64_t uniqid; /* unique "generation number" */ 237 zone_cmd_t cmd; /* requested action */ 238 uint32_t _pad; /* need consistent 32/64 bit alignmt */ 239 char locale[MAXPATHLEN]; /* locale in which to render messages */ 240 char bootbuf[BOOTARGS_MAX]; /* arguments passed to zone_boot() */ 241 } zone_cmd_arg_t; 242 243 /* 244 * Structure of zoneadmd's response to a request. A NULL return value means 245 * the caller should attempt to restart zoneadmd and retry. 246 */ 247 typedef struct zone_cmd_rval { 248 int rval; /* return value of request */ 249 char errbuf[1]; /* variable-sized buffer containing error messages */ 250 } zone_cmd_rval_t; 251 252 /* 253 * The zone support infrastructure uses the zone name as a component 254 * of unix domain (AF_UNIX) sockets, which are limited to 108 characters 255 * in length, so ZONENAME_MAX is limited by that. 256 */ 257 #define ZONENAME_MAX 64 258 259 #define GLOBAL_ZONENAME "global" 260 261 /* 262 * Extended Regular expression (see regex(5)) which matches all valid zone 263 * names. 264 */ 265 #define ZONENAME_REGEXP "[a-zA-Z0-9][-_.a-zA-Z0-9]{0,62}" 266 267 /* 268 * Where the zones support infrastructure places temporary files. 269 */ 270 #define ZONES_TMPDIR "/var/run/zones" 271 272 /* 273 * The path to the door used by clients to communicate with zoneadmd. 274 */ 275 #define ZONE_DOOR_PATH ZONES_TMPDIR "/%s.zoneadmd_door" 276 277 /* zone_flags */ 278 #define ZF_HASHED_LABEL 0x2 /* zone has a unique label */ 279 #define ZF_IS_SCRATCH 0x4 /* scratch zone */ 280 #define ZF_NET_EXCL 0x8 /* Zone has an exclusive IP stack */ 281 282 /* zone_create flags */ 283 #define ZCF_NET_EXCL 0x1 /* Create a zone with exclusive IP */ 284 285 /* zone network properties */ 286 #define ZONE_NETWORK_ADDRESS 1 287 #define ZONE_NETWORK_DEFROUTER 2 288 289 #define ZONE_NET_ADDRNAME "address" 290 #define ZONE_NET_RTRNAME "route" 291 292 typedef struct zone_net_data { 293 int zn_type; 294 int zn_len; 295 datalink_id_t zn_linkid; 296 uint8_t zn_val[1]; 297 } zone_net_data_t; 298 299 300 #ifdef _KERNEL 301 /* 302 * We need to protect the definition of 'list_t' from userland applications and 303 * libraries which may be defining ther own versions. 304 */ 305 #include <sys/list.h> 306 307 #define GLOBAL_ZONEUNIQID 0 /* uniqid of the global zone */ 308 309 struct pool; 310 struct brand; 311 312 /* 313 * Structure to record list of ZFS datasets exported to a zone. 314 */ 315 typedef struct zone_dataset { 316 char *zd_dataset; 317 list_node_t zd_linkage; 318 } zone_dataset_t; 319 320 /* 321 * structure for zone kstats 322 */ 323 typedef struct zone_kstat { 324 kstat_named_t zk_zonename; 325 kstat_named_t zk_usage; 326 kstat_named_t zk_value; 327 } zone_kstat_t; 328 329 struct cpucap; 330 331 typedef struct zone { 332 /* 333 * zone_name is never modified once set. 334 */ 335 char *zone_name; /* zone's configuration name */ 336 /* 337 * zone_nodename and zone_domain are never freed once allocated. 338 */ 339 char *zone_nodename; /* utsname.nodename equivalent */ 340 char *zone_domain; /* srpc_domain equivalent */ 341 /* 342 * zone_hostid is used for per-zone hostid emulation. 343 * Currently it isn't modified after it's set (so no locks protect 344 * accesses), but that might have to change when we allow 345 * administrators to change running zones' properties. 346 * 347 * The global zone's zone_hostid must always be HW_INVALID_HOSTID so 348 * that zone_get_hostid() will function correctly. 349 */ 350 uint32_t zone_hostid; /* zone's hostid, HW_INVALID_HOSTID */ 351 /* if not emulated */ 352 /* 353 * zone_lock protects the following fields of a zone_t: 354 * zone_ref 355 * zone_cred_ref 356 * zone_ntasks 357 * zone_flags 358 * zone_zsd 359 * zone_pfexecd 360 */ 361 kmutex_t zone_lock; 362 /* 363 * zone_linkage is the zone's linkage into the active or 364 * death-row list. The field is protected by zonehash_lock. 365 */ 366 list_node_t zone_linkage; 367 zoneid_t zone_id; /* ID of zone */ 368 uint_t zone_ref; /* count of zone_hold()s on zone */ 369 uint_t zone_cred_ref; /* count of zone_hold_cred()s on zone */ 370 /* 371 * zone_rootvp and zone_rootpath can never be modified once set. 372 */ 373 struct vnode *zone_rootvp; /* zone's root vnode */ 374 char *zone_rootpath; /* Path to zone's root + '/' */ 375 ushort_t zone_flags; /* misc flags */ 376 zone_status_t zone_status; /* protected by zone_status_lock */ 377 uint_t zone_ntasks; /* number of tasks executing in zone */ 378 kmutex_t zone_nlwps_lock; /* protects zone_nlwps, and *_nlwps */ 379 /* counters in projects and tasks */ 380 /* that are within the zone */ 381 rctl_qty_t zone_nlwps; /* number of lwps in zone */ 382 rctl_qty_t zone_nlwps_ctl; /* protected by zone_rctls->rcs_lock */ 383 rctl_qty_t zone_shmmax; /* System V shared memory usage */ 384 ipc_rqty_t zone_ipc; /* System V IPC id resource usage */ 385 386 uint_t zone_rootpathlen; /* strlen(zone_rootpath) + 1 */ 387 uint32_t zone_shares; /* FSS shares allocated to zone */ 388 rctl_set_t *zone_rctls; /* zone-wide (zone.*) rctls */ 389 kmutex_t zone_mem_lock; /* protects zone_locked_mem and */ 390 /* kpd_locked_mem for all */ 391 /* projects in zone. */ 392 /* Also protects zone_max_swap */ 393 /* grab after p_lock, before rcs_lock */ 394 rctl_qty_t zone_locked_mem; /* bytes of locked memory in */ 395 /* zone */ 396 rctl_qty_t zone_locked_mem_ctl; /* Current locked memory */ 397 /* limit. Protected by */ 398 /* zone_rctls->rcs_lock */ 399 rctl_qty_t zone_max_swap; /* bytes of swap reserved by zone */ 400 rctl_qty_t zone_max_swap_ctl; /* current swap limit. */ 401 /* Protected by */ 402 /* zone_rctls->rcs_lock */ 403 kmutex_t zone_rctl_lock; /* protects zone_max_lofi */ 404 rctl_qty_t zone_max_lofi; /* lofi devs for zone */ 405 rctl_qty_t zone_max_lofi_ctl; /* current lofi limit. */ 406 /* Protected by */ 407 /* zone_rctls->rcs_lock */ 408 list_t zone_zsd; /* list of Zone-Specific Data values */ 409 kcondvar_t zone_cv; /* used to signal state changes */ 410 struct proc *zone_zsched; /* Dummy kernel "zsched" process */ 411 pid_t zone_proc_initpid; /* pid of "init" for this zone */ 412 char *zone_initname; /* fs path to 'init' */ 413 int zone_boot_err; /* for zone_boot() if boot fails */ 414 char *zone_bootargs; /* arguments passed via zone_boot() */ 415 uint64_t zone_phys_mcap; /* physical memory cap */ 416 /* 417 * zone_kthreads is protected by zone_status_lock. 418 */ 419 kthread_t *zone_kthreads; /* kernel threads in zone */ 420 struct priv_set *zone_privset; /* limit set for zone */ 421 /* 422 * zone_vfslist is protected by vfs_list_lock(). 423 */ 424 struct vfs *zone_vfslist; /* list of FS's mounted in zone */ 425 uint64_t zone_uniqid; /* unique zone generation number */ 426 struct cred *zone_kcred; /* kcred-like, zone-limited cred */ 427 /* 428 * zone_pool is protected by pool_lock(). 429 */ 430 struct pool *zone_pool; /* pool the zone is bound to */ 431 hrtime_t zone_pool_mod; /* last pool bind modification time */ 432 /* zone_psetid is protected by cpu_lock */ 433 psetid_t zone_psetid; /* pset the zone is bound to */ 434 /* 435 * The following two can be read without holding any locks. They are 436 * updated under cpu_lock. 437 */ 438 int zone_ncpus; /* zone's idea of ncpus */ 439 int zone_ncpus_online; /* zone's idea of ncpus_online */ 440 /* 441 * List of ZFS datasets exported to this zone. 442 */ 443 list_t zone_datasets; /* list of datasets */ 444 445 ts_label_t *zone_slabel; /* zone sensitivity label */ 446 int zone_match; /* require label match for packets */ 447 tsol_mlp_list_t zone_mlps; /* MLPs on zone-private addresses */ 448 449 boolean_t zone_restart_init; /* Restart init if it dies? */ 450 struct brand *zone_brand; /* zone's brand */ 451 void *zone_brand_data; /* store brand specific data */ 452 id_t zone_defaultcid; /* dflt scheduling class id */ 453 kstat_t *zone_swapresv_kstat; 454 kstat_t *zone_lockedmem_kstat; 455 /* 456 * zone_dl_list is protected by zone_lock 457 */ 458 list_t zone_dl_list; 459 netstack_t *zone_netstack; 460 struct cpucap *zone_cpucap; /* CPU caps data */ 461 /* 462 * Solaris Auditing per-zone audit context 463 */ 464 struct au_kcontext *zone_audit_kctxt; 465 /* 466 * For private use by mntfs. 467 */ 468 struct mntelem *zone_mntfs_db; 469 krwlock_t zone_mntfs_db_lock; 470 471 struct klpd_reg *zone_pfexecd; 472 473 char *zone_fs_allowed; 474 rctl_qty_t zone_nprocs; /* number of processes in the zone */ 475 rctl_qty_t zone_nprocs_ctl; /* current limit protected by */ 476 /* zone_rctls->rcs_lock */ 477 kstat_t *zone_nprocs_kstat; 478 } zone_t; 479 480 /* 481 * Special value of zone_psetid to indicate that pools are disabled. 482 */ 483 #define ZONE_PS_INVAL PS_MYID 484 485 486 extern zone_t zone0; 487 extern zone_t *global_zone; 488 extern uint_t maxzones; 489 extern rctl_hndl_t rc_zone_nlwps; 490 extern rctl_hndl_t rc_zone_nprocs; 491 492 extern long zone(int, void *, void *, void *, void *); 493 extern void zone_zsd_init(void); 494 extern void zone_init(void); 495 extern void zone_hold(zone_t *); 496 extern void zone_rele(zone_t *); 497 extern void zone_cred_hold(zone_t *); 498 extern void zone_cred_rele(zone_t *); 499 extern void zone_task_hold(zone_t *); 500 extern void zone_task_rele(zone_t *); 501 extern zone_t *zone_find_by_id(zoneid_t); 502 extern zone_t *zone_find_by_label(const ts_label_t *); 503 extern zone_t *zone_find_by_name(char *); 504 extern zone_t *zone_find_by_any_path(const char *, boolean_t); 505 extern zone_t *zone_find_by_path(const char *); 506 extern zoneid_t getzoneid(void); 507 extern zone_t *zone_find_by_id_nolock(zoneid_t); 508 extern int zone_datalink_walk(zoneid_t, int (*)(datalink_id_t, void *), void *); 509 extern int zone_check_datalink(zoneid_t *, datalink_id_t); 510 511 /* 512 * Zone-specific data (ZSD) APIs 513 */ 514 /* 515 * The following is what code should be initializing its zone_key_t to if it 516 * calls zone_getspecific() without necessarily knowing that zone_key_create() 517 * has been called on the key. 518 */ 519 #define ZONE_KEY_UNINITIALIZED 0 520 521 typedef uint_t zone_key_t; 522 523 extern void zone_key_create(zone_key_t *, void *(*)(zoneid_t), 524 void (*)(zoneid_t, void *), void (*)(zoneid_t, void *)); 525 extern int zone_key_delete(zone_key_t); 526 extern void *zone_getspecific(zone_key_t, zone_t *); 527 extern int zone_setspecific(zone_key_t, zone_t *, const void *); 528 529 /* 530 * The definition of a zsd_entry is truly private to zone.c and is only 531 * placed here so it can be shared with mdb. 532 * 533 * State maintained for each zone times each registered key, which tracks 534 * the state of the create, shutdown and destroy callbacks. 535 * 536 * zsd_flags is used to keep track of pending actions to avoid holding locks 537 * when calling the create/shutdown/destroy callbacks, since doing so 538 * could lead to deadlocks. 539 */ 540 struct zsd_entry { 541 zone_key_t zsd_key; /* Key used to lookup value */ 542 void *zsd_data; /* Caller-managed value */ 543 /* 544 * Callbacks to be executed when a zone is created, shutdown, and 545 * destroyed, respectively. 546 */ 547 void *(*zsd_create)(zoneid_t); 548 void (*zsd_shutdown)(zoneid_t, void *); 549 void (*zsd_destroy)(zoneid_t, void *); 550 list_node_t zsd_linkage; 551 uint16_t zsd_flags; /* See below */ 552 kcondvar_t zsd_cv; 553 }; 554 555 /* 556 * zsd_flags 557 */ 558 #define ZSD_CREATE_NEEDED 0x0001 559 #define ZSD_CREATE_INPROGRESS 0x0002 560 #define ZSD_CREATE_COMPLETED 0x0004 561 #define ZSD_SHUTDOWN_NEEDED 0x0010 562 #define ZSD_SHUTDOWN_INPROGRESS 0x0020 563 #define ZSD_SHUTDOWN_COMPLETED 0x0040 564 #define ZSD_DESTROY_NEEDED 0x0100 565 #define ZSD_DESTROY_INPROGRESS 0x0200 566 #define ZSD_DESTROY_COMPLETED 0x0400 567 568 #define ZSD_CREATE_ALL \ 569 (ZSD_CREATE_NEEDED|ZSD_CREATE_INPROGRESS|ZSD_CREATE_COMPLETED) 570 #define ZSD_SHUTDOWN_ALL \ 571 (ZSD_SHUTDOWN_NEEDED|ZSD_SHUTDOWN_INPROGRESS|ZSD_SHUTDOWN_COMPLETED) 572 #define ZSD_DESTROY_ALL \ 573 (ZSD_DESTROY_NEEDED|ZSD_DESTROY_INPROGRESS|ZSD_DESTROY_COMPLETED) 574 575 #define ZSD_ALL_INPROGRESS \ 576 (ZSD_CREATE_INPROGRESS|ZSD_SHUTDOWN_INPROGRESS|ZSD_DESTROY_INPROGRESS) 577 578 /* 579 * Macros to help with zone visibility restrictions. 580 */ 581 582 /* 583 * Is process in the global zone? 584 */ 585 #define INGLOBALZONE(p) \ 586 ((p)->p_zone == global_zone) 587 588 /* 589 * Can process view objects in given zone? 590 */ 591 #define HASZONEACCESS(p, zoneid) \ 592 ((p)->p_zone->zone_id == (zoneid) || INGLOBALZONE(p)) 593 594 /* 595 * Convenience macro to see if a resolved path is visible from within a 596 * given zone. 597 * 598 * The basic idea is that the first (zone_rootpathlen - 1) bytes of the 599 * two strings must be equal. Since the rootpathlen has a trailing '/', 600 * we want to skip everything in the path up to (but not including) the 601 * trailing '/'. 602 */ 603 #define ZONE_PATH_VISIBLE(path, zone) \ 604 (strncmp((path), (zone)->zone_rootpath, \ 605 (zone)->zone_rootpathlen - 1) == 0) 606 607 /* 608 * Convenience macro to go from the global view of a path to that seen 609 * from within said zone. It is the responsibility of the caller to 610 * ensure that the path is a resolved one (ie, no '..'s or '.'s), and is 611 * in fact visible from within the zone. 612 */ 613 #define ZONE_PATH_TRANSLATE(path, zone) \ 614 (ASSERT(ZONE_PATH_VISIBLE(path, zone)), \ 615 (path) + (zone)->zone_rootpathlen - 2) 616 617 /* 618 * Special processes visible in all zones. 619 */ 620 #define ZONE_SPECIALPID(x) ((x) == 0 || (x) == 1) 621 622 /* 623 * Zone-safe version of thread_create() to be used when the caller wants to 624 * create a kernel thread to run within the current zone's context. 625 */ 626 extern kthread_t *zthread_create(caddr_t, size_t, void (*)(), void *, size_t, 627 pri_t); 628 extern void zthread_exit(void); 629 630 /* 631 * Functions for an external observer to register interest in a zone's status 632 * change. Observers will be woken up when the zone status equals the status 633 * argument passed in (in the case of zone_status_timedwait, the function may 634 * also return because of a timeout; zone_status_wait_sig may return early due 635 * to a signal being delivered; zone_status_timedwait_sig may return for any of 636 * the above reasons). 637 * 638 * Otherwise these behave identically to cv_timedwait(), cv_wait(), and 639 * cv_wait_sig() respectively. 640 */ 641 extern clock_t zone_status_timedwait(zone_t *, clock_t, zone_status_t); 642 extern clock_t zone_status_timedwait_sig(zone_t *, clock_t, zone_status_t); 643 extern void zone_status_wait(zone_t *, zone_status_t); 644 extern int zone_status_wait_sig(zone_t *, zone_status_t); 645 646 /* 647 * Get the status of the zone (at the time it was called). The state may 648 * have progressed by the time it is returned. 649 */ 650 extern zone_status_t zone_status_get(zone_t *); 651 652 /* 653 * Safely get the hostid of the specified zone (defaults to machine's hostid 654 * if the specified zone doesn't emulate a hostid). Passing NULL retrieves 655 * the global zone's (i.e., physical system's) hostid. 656 */ 657 extern uint32_t zone_get_hostid(zone_t *); 658 659 /* 660 * Get the "kcred" credentials corresponding to the given zone. 661 */ 662 extern struct cred *zone_get_kcred(zoneid_t); 663 664 /* 665 * Get/set the pool the zone is currently bound to. 666 */ 667 extern struct pool *zone_pool_get(zone_t *); 668 extern void zone_pool_set(zone_t *, struct pool *); 669 670 /* 671 * Get/set the pset the zone is currently using. 672 */ 673 extern psetid_t zone_pset_get(zone_t *); 674 extern void zone_pset_set(zone_t *, psetid_t); 675 676 /* 677 * Get the number of cpus/online-cpus visible from the given zone. 678 */ 679 extern int zone_ncpus_get(zone_t *); 680 extern int zone_ncpus_online_get(zone_t *); 681 682 /* 683 * Returns true if the named pool/dataset is visible in the current zone. 684 */ 685 extern int zone_dataset_visible(const char *, int *); 686 687 /* 688 * zone version of kadmin() 689 */ 690 extern int zone_kadmin(int, int, const char *, cred_t *); 691 extern void zone_shutdown_global(void); 692 693 extern void mount_in_progress(void); 694 extern void mount_completed(void); 695 696 extern int zone_walk(int (*)(zone_t *, void *), void *); 697 698 extern rctl_hndl_t rc_zone_locked_mem; 699 extern rctl_hndl_t rc_zone_max_swap; 700 extern rctl_hndl_t rc_zone_max_lofi; 701 702 #endif /* _KERNEL */ 703 704 #ifdef __cplusplus 705 } 706 #endif 707 708 #endif /* _SYS_ZONE_H */ 709