zone.h revision b0f673c4626e4cb1db7785287eaeed2731dfefe8
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2014 Nexenta Systems, Inc. All rights reserved.
*/
#ifndef _SYS_ZONE_H
#define _SYS_ZONE_H
#include <sys/ipc_rctl.h>
#include <sys/netstack.h>
#include <sys/socket_impl.h>
#ifdef __cplusplus
extern "C" {
#endif
/*
* NOTE
*
* The contents of this file are private to the implementation of
* Solaris and are subject to change at any time without notice.
* Applications and drivers using these interfaces may fail to
* run on future releases.
*/
/* Available both in kernel and for user space */
/* zone id restrictions and special ids */
#define MAX_ZONEID 9999
#define MIN_ZONEID 0 /* minimum zone ID on system */
#define GLOBAL_ZONEID 0
/*
* Special zoneid_t token to refer to all zones.
*/
#define ALL_ZONES (-1)
/* system call subcodes */
#define ZONE_CREATE 0
#define ZONE_DESTROY 1
#define ZONE_GETATTR 2
#define ZONE_ENTER 3
#define ZONE_LIST 4
#define ZONE_SHUTDOWN 5
#define ZONE_LOOKUP 6
#define ZONE_BOOT 7
#define ZONE_VERSION 8
#define ZONE_SETATTR 9
#define ZONE_ADD_DATALINK 10
#define ZONE_DEL_DATALINK 11
#define ZONE_CHECK_DATALINK 12
#define ZONE_LIST_DATALINK 13
/* zone attributes */
#define ZONE_ATTR_ROOT 1
#define ZONE_ATTR_NAME 2
#define ZONE_ATTR_STATUS 3
#define ZONE_ATTR_PRIVSET 4
#define ZONE_ATTR_UNIQID 5
#define ZONE_ATTR_POOLID 6
#define ZONE_ATTR_INITPID 7
#define ZONE_ATTR_SLBL 8
#define ZONE_ATTR_INITNAME 9
#define ZONE_ATTR_BOOTARGS 10
#define ZONE_ATTR_BRAND 11
#define ZONE_ATTR_PHYS_MCAP 12
#define ZONE_ATTR_SCHED_CLASS 13
#define ZONE_ATTR_FLAGS 14
#define ZONE_ATTR_HOSTID 15
#define ZONE_ATTR_FS_ALLOWED 16
#define ZONE_ATTR_NETWORK 17
/* Start of the brand-specific attribute namespace */
#define ZONE_ATTR_BRAND_ATTRS 32768
#define ZONE_FS_ALLOWED_MAX 1024
#define ZONE_EVENT_CHANNEL "com.sun:zones:status"
#define ZONE_EVENT_STATUS_CLASS "status"
#define ZONE_EVENT_STATUS_SUBCLASS "change"
#define ZONE_EVENT_UNINITIALIZED "uninitialized"
#define ZONE_EVENT_INITIALIZED "initialized"
#define ZONE_EVENT_READY "ready"
#define ZONE_EVENT_RUNNING "running"
#define ZONE_EVENT_SHUTTING_DOWN "shutting_down"
#define ZONE_CB_NAME "zonename"
#define ZONE_CB_NEWSTATE "newstate"
#define ZONE_CB_OLDSTATE "oldstate"
#define ZONE_CB_TIMESTAMP "when"
#define ZONE_CB_ZONEID "zoneid"
/*
* Exit values that may be returned by scripts or programs invoked by various
* zone commands.
*
* These are defined as:
*
* ZONE_SUBPROC_OK
* ===============
* The subprocess completed successfully.
*
* ZONE_SUBPROC_USAGE
* ==================
* The subprocess failed with a usage message, or a usage message should
* be output in its behalf.
*
* ZONE_SUBPROC_NOTCOMPLETE
* ========================
* The subprocess did not complete, but the actions performed by the
* subprocess require no recovery actions by the user.
*
* For example, if the subprocess were called by "zoneadm install," the
* installation of the zone did not succeed but the user need not perform
* a "zoneadm uninstall" before attempting another install.
*
* ZONE_SUBPROC_FATAL
* ==================
* The subprocess failed in a fatal manner, usually one that will require
* some type of recovery action by the user.
*
* For example, if the subprocess were called by "zoneadm install," the
* installation of the zone did not succeed and the user will need to
* perform a "zoneadm uninstall" before another install attempt is
* possible.
*
* The non-success exit values are large to avoid accidental collision
* with values used internally by some commands (e.g. "Z_ERR" and
* "Z_USAGE" as used by zoneadm.)
*/
#define ZONE_SUBPROC_OK 0
#define ZONE_SUBPROC_USAGE 253
#define ZONE_SUBPROC_NOTCOMPLETE 254
#define ZONE_SUBPROC_FATAL 255
#ifdef _SYSCALL32
typedef struct {
int match; /* match level */
int flags;
} zone_def32;
#endif
typedef struct {
const char *zone_name;
const char *zone_root;
const struct priv_set *zone_privs;
const char *rctlbuf;
int *extended_error;
const char *zfsbuf;
int match; /* match level */
int flags;
} zone_def;
/* extended error information */
#define ZE_UNKNOWN 0 /* No extended error info */
/*
* zone_status values
*
* You must modify zone_status_names in mdb(1M)'s genunix module
*/
typedef enum {
#define ZONE_MIN_STATE ZONE_IS_UNINITIALIZED
#define ZONE_MAX_STATE ZONE_IS_DEAD
/*
* Valid commands which may be issued by zoneadm to zoneadmd. The kernel also
* communicates with zoneadmd, but only uses Z_REBOOT and Z_HALT.
*/
typedef enum zone_cmd {
} zone_cmd_t;
/*
* The structure of a request to zoneadmd.
*/
typedef struct zone_cmd_arg {
/*
* Structure of zoneadmd's response to a request. A NULL return value means
* the caller should attempt to restart zoneadmd and retry.
*/
typedef struct zone_cmd_rval {
int rval; /* return value of request */
/*
* The zone support infrastructure uses the zone name as a component
* of unix domain (AF_UNIX) sockets, which are limited to 108 characters
* in length, so ZONENAME_MAX is limited by that.
*/
#define ZONENAME_MAX 64
#define GLOBAL_ZONENAME "global"
/*
* Extended Regular expression (see regex(5)) which matches all valid zone
* names.
*/
#define ZONENAME_REGEXP "[a-zA-Z0-9][-_.a-zA-Z0-9]{0,62}"
/*
* Where the zones support infrastructure places temporary files.
*/
#define ZONES_TMPDIR "/var/run/zones"
/*
* The path to the door used by clients to communicate with zoneadmd.
*/
/* zone_flags */
/*
* Threads that read or write the following flag must hold zone_lock.
*/
/*
* The following threads are set when the zone is created and never changed.
* Threads that test for these flags don't have to hold zone_lock.
*/
/* zone_create flags */
/* zone network properties */
#define ZONE_NETWORK_ADDRESS 1
#define ZONE_NETWORK_DEFROUTER 2
#define ZONE_NET_ADDRNAME "address"
#define ZONE_NET_RTRNAME "route"
typedef struct zone_net_data {
int zn_type;
int zn_len;
#ifdef _KERNEL
/*
* We need to protect the definition of 'list_t' from userland applications and
* libraries which may be defining ther own versions.
*/
#define GLOBAL_ZONEUNIQID 0 /* uniqid of the global zone */
struct pool;
struct brand;
/*
* Each of these constants identifies a kernel subsystem that acquires and
* releases zone references. Each subsystem that invokes
* zone_hold_ref() and zone_rele_ref() should specify the
* zone_ref_subsys_t constant associated with the subsystem. Tracked holds
* help users and developers quickly identify subsystems that stall zone
* shutdowns indefinitely.
*
* when you modify this enumeration.
*/
typedef enum zone_ref_subsys {
ZONE_REF_NFS, /* NFS */
ZONE_REF_NFSV4, /* NFSv4 */
ZONE_REF_SMBFS, /* SMBFS */
ZONE_REF_MNTFS, /* MNTFS */
ZONE_REF_LOFI, /* LOFI devices */
ZONE_REF_VFS, /* VFS infrastructure */
ZONE_REF_IPC, /* IPC infrastructure */
ZONE_REF_NUM_SUBSYS /* This must be the last entry. */
/*
* zone_ref represents a general-purpose references to a zone. Each zone's
* references are linked into the zone's zone_t::zone_ref_list. This allows
* debuggers to walk zones' references.
*/
typedef struct zone_ref {
} zone_ref_t;
/*
* Structure to record list of ZFS datasets exported to a zone.
*/
typedef struct zone_dataset {
char *zd_dataset;
/*
* structure for zone kstats
*/
typedef struct zone_kstat {
} zone_kstat_t;
struct cpucap;
typedef struct zone {
/*
* zone_name is never modified once set.
*/
char *zone_name; /* zone's configuration name */
/*
* zone_nodename and zone_domain are never freed once allocated.
*/
char *zone_nodename; /* utsname.nodename equivalent */
char *zone_domain; /* srpc_domain equivalent */
/*
* zone_hostid is used for per-zone hostid emulation.
* Currently it isn't modified after it's set (so no locks protect
* accesses), but that might have to change when we allow
* administrators to change running zones' properties.
*
* The global zone's zone_hostid must always be HW_INVALID_HOSTID so
* that zone_get_hostid() will function correctly.
*/
/* if not emulated */
/*
* zone_lock protects the following fields of a zone_t:
* zone_ref
* zone_cred_ref
* zone_subsys_ref
* zone_ref_list
* zone_ntasks
* zone_flags
* zone_zsd
* zone_pfexecd
*/
/*
* zone_linkage is the zone's linkage into the active or
* death-row list. The field is protected by zonehash_lock.
*/
/*
* Fixed-sized array of subsystem-specific reference counts
* The sum of all of the counts must be less than or equal to zone_ref.
* The array is indexed by the counts' subsystems' zone_ref_subsys_t
* constants.
*/
/*
* zone_rootvp and zone_rootpath can never be modified once set.
*/
char *zone_rootpath; /* Path to zone's root + '/' */
/* counters in projects and tasks */
/* that are within the zone */
/* kpd_locked_mem for all */
/* projects in zone. */
/* Also protects zone_max_swap */
/* grab after p_lock, before rcs_lock */
/* zone */
/* limit. Protected by */
/* zone_rctls->rcs_lock */
/* Protected by */
/* zone_rctls->rcs_lock */
/* Protected by */
/* zone_rctls->rcs_lock */
char *zone_initname; /* fs path to 'init' */
int zone_boot_err; /* for zone_boot() if boot fails */
char *zone_bootargs; /* arguments passed via zone_boot() */
/*
* zone_kthreads is protected by zone_status_lock.
*/
/*
* zone_vfslist is protected by vfs_list_lock().
*/
/*
* zone_pool is protected by pool_lock().
*/
/* zone_psetid is protected by cpu_lock */
/*
* The following two can be read without holding any locks. They are
* updated under cpu_lock.
*/
int zone_ncpus; /* zone's idea of ncpus */
int zone_ncpus_online; /* zone's idea of ncpus_online */
/*
* List of ZFS datasets exported to this zone.
*/
int zone_match; /* require label match for packets */
void *zone_brand_data; /* store brand specific data */
/*
* zone_dl_list is protected by zone_lock
*/
/*
* Solaris Auditing per-zone audit context
*/
struct au_kcontext *zone_audit_kctxt;
/*
* For private use by mntfs.
*/
struct mntelem *zone_mntfs_db;
struct klpd_reg *zone_pfexecd;
char *zone_fs_allowed;
/* zone_rctls->rcs_lock */
/*
* DTrace-private per-zone state
*/
int zone_dtrace_getf; /* # of unprivileged getf()s */
} zone_t;
/*
* Special value of zone_psetid to indicate that pools are disabled.
*/
#define ZONE_PS_INVAL PS_MYID
extern zone_t *global_zone;
extern rctl_hndl_t rc_zone_nlwps;
extern rctl_hndl_t rc_zone_nprocs;
extern long zone(int, void *, void *, void *, void *);
extern void zone_zsd_init(void);
extern void zone_init(void);
extern void zone_init_ref(zone_ref_t *);
extern void zone_cred_hold(zone_t *);
extern void zone_cred_rele(zone_t *);
extern void zone_task_hold(zone_t *);
extern void zone_task_rele(zone_t *);
extern zone_t *zone_find_by_name(char *);
extern zone_t *zone_find_by_path(const char *);
/*
* Zone-specific data (ZSD) APIs
*/
/*
* The following is what code should be initializing its zone_key_t to if it
* calls zone_getspecific() without necessarily knowing that zone_key_create()
* has been called on the key.
*/
#define ZONE_KEY_UNINITIALIZED 0
typedef uint_t zone_key_t;
extern int zone_key_delete(zone_key_t);
/*
* The definition of a zsd_entry is truly private to zone.c and is only
* placed here so it can be shared with mdb.
*
* State maintained for each zone times each registered key, which tracks
* the state of the create, shutdown and destroy callbacks.
*
* zsd_flags is used to keep track of pending actions to avoid holding locks
* could lead to deadlocks.
*/
struct zsd_entry {
void *zsd_data; /* Caller-managed value */
/*
* Callbacks to be executed when a zone is created, shutdown, and
* destroyed, respectively.
*/
void *(*zsd_create)(zoneid_t);
void (*zsd_shutdown)(zoneid_t, void *);
void (*zsd_destroy)(zoneid_t, void *);
};
/*
* zsd_flags
*/
#define ZSD_CREATE_NEEDED 0x0001
#define ZSD_CREATE_INPROGRESS 0x0002
#define ZSD_CREATE_COMPLETED 0x0004
#define ZSD_SHUTDOWN_NEEDED 0x0010
#define ZSD_SHUTDOWN_INPROGRESS 0x0020
#define ZSD_SHUTDOWN_COMPLETED 0x0040
#define ZSD_DESTROY_NEEDED 0x0100
#define ZSD_DESTROY_INPROGRESS 0x0200
#define ZSD_DESTROY_COMPLETED 0x0400
#define ZSD_CREATE_ALL \
#define ZSD_SHUTDOWN_ALL \
#define ZSD_DESTROY_ALL \
#define ZSD_ALL_INPROGRESS \
/*
* Macros to help with zone visibility restrictions.
*/
/*
* Is process in the global zone?
*/
#define INGLOBALZONE(p) \
((p)->p_zone == global_zone)
/*
* Can process view objects in given zone?
*/
#define HASZONEACCESS(p, zoneid) \
/*
* Convenience macro to see if a resolved path is visible from within a
* given zone.
*
* The basic idea is that the first (zone_rootpathlen - 1) bytes of the
* two strings must be equal. Since the rootpathlen has a trailing '/',
* we want to skip everything in the path up to (but not including) the
* trailing '/'.
*/
/*
* Convenience macro to go from the global view of a path to that seen
* from within said zone. It is the responsibility of the caller to
* ensure that the path is a resolved one (ie, no '..'s or '.'s), and is
* in fact visible from within the zone.
*/
/*
* Special processes visible in all zones.
*/
#define ZONE_SPECIALPID(x) ((x) == 0 || (x) == 1)
/*
* Zone-safe version of thread_create() to be used when the caller wants to
* create a kernel thread to run within the current zone's context.
*/
pri_t);
extern void zthread_exit(void);
/*
* Functions for an external observer to register interest in a zone's status
* change. Observers will be woken up when the zone status equals the status
* argument passed in (in the case of zone_status_timedwait, the function may
* also return because of a timeout; zone_status_wait_sig may return early due
* to a signal being delivered; zone_status_timedwait_sig may return for any of
* the above reasons).
*
* Otherwise these behave identically to cv_timedwait(), cv_wait(), and
* cv_wait_sig() respectively.
*/
/*
* Get the status of the zone (at the time it was called). The state may
* have progressed by the time it is returned.
*/
/*
* Safely get the hostid of the specified zone (defaults to machine's hostid
* if the specified zone doesn't emulate a hostid). Passing NULL retrieves
* the global zone's (i.e., physical system's) hostid.
*/
/*
* Get the "kcred" credentials corresponding to the given zone.
*/
/*
*/
/*
*/
/*
* Get the number of cpus/online-cpus visible from the given zone.
*/
extern int zone_ncpus_get(zone_t *);
extern int zone_ncpus_online_get(zone_t *);
/*
*/
extern int zone_dataset_visible(const char *, int *);
/*
* zone version of kadmin()
*/
extern int zone_kadmin(int, int, const char *, cred_t *);
extern void zone_shutdown_global(void);
extern void mount_in_progress(void);
extern void mount_completed(void);
extern rctl_hndl_t rc_zone_locked_mem;
extern rctl_hndl_t rc_zone_max_swap;
extern rctl_hndl_t rc_zone_max_lofi;
#endif /* _KERNEL */
#ifdef __cplusplus
}
#endif
#endif /* _SYS_ZONE_H */