/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* bos72V src/bos/kernel/sys/corralid.h 1.41.2.26                         */
/*                                                                        */
/* Licensed Materials - Property of IBM                                   */
/*                                                                        */
/* COPYRIGHT International Business Machines Corp. 2005,2020              */
/* All Rights Reserved                                                    */
/*                                                                        */
/* US Government Users Restricted Rights - Use, duplication or            */
/* disclosure restricted by GSA ADP Schedule Contract with IBM Corp.      */
/*                                                                        */
/* IBM_PROLOG_END_TAG                                                     */
/* @(#)35     1.41.2.26  src/bos/kernel/sys/corralid.h, syscorral, bos72V, v2020_03A2 1/8/20 15:01:30 */

#ifndef _CORRALID_H
#define _CORRALID_H

#include <sys/types.h>

/* This minimal header is standalone and can be used any place in the 
 * kernel where corral identifiers need to be analyzed.  It is also
 * included in corral.h and thus must work in user space as well.
 * Do not add other header dependencies or types that are not solely
 * described here, within this file.
 */

/* Corral key specified from user space.  This is a short 
 * hand persistent identifier for a corral that is recorded in the 
 * corral database.  It is provided during corral_config() and should 
 * be used in the kernel only when a more permanent kernel corral to 
 * identity mapping is needed.   For instance accounting records which 
 * may be formatted long after the corral has been deleted from the 
 * kernel can provide this identifier to user space.  
 *
 * For a more optimally efficient identifier see cid_t
 */
typedef unsigned int ckey_t;

/* Corral identifier.  This is a identifier allocated by the 
 * kernel that changes with every corral instantiation within 
 * the kernel.  It is an efficient lookup mechanism as well as 
 * the primary identifier in all corral system calls and kernel
 * routines.
 */
typedef unsigned short cid_t;

/* Compatibility Runtime Environment indentifier. */ 
typedef unsigned short cre_t;

/* forward declarations */
struct corral; 
struct socket;
struct in_addr;
struct ifnet;
struct wlm_bounds;
struct sockaddr_in;

/* brand() b_flags
 * Note: 
 *	 Processes attempting to enter a Mobile WPAR with open file 
 *       descriptors should either be the init process (B_CORRAL_INIT)
 *       or should declare themselves as ineligible for a checkpoint 
 *       (B_NO_CHECKPOINT, B_RESTART_EXIT, or B_NO_FREEZE).  Otherwise
 *       processes with file descriptors connected to files or devices
 * 	 outside the WPAR will disable any checkpoint possibility.
 * 
 *       One way to ensure you don't have open file descriptors is to call
 *	 kleenup(0,0,0) before brand().
 */
#define B_CORRAL_INIT	0x1   /* process is WPAR init process */

#define B_REPARENT_INIT	0x2   /* process should be reparented to init */

#define B_NO_CHROOT     0x4   /* process should not chroot */

/* brand() b_flags for mobile WPARs */

/* B_NO_CHECKPOINT signifies that process is not to be checkpointed.
 * A process with this flag that is present in the WPAR at the point of 
 * checkpointing is frozen but its presence is ignored and not saved in the
 * checkpoint file.  A process with this flag may not be process group or
 * session leader, nor will its ancestry or progeny be checkpointed.
 */
#define B_NO_CHECKPOINT 0x8

/* B_RESTART_EXIT signifies that a process is to exit immediately on restart.
 * Its complete process state is not saved during checkpoint and a recreation
 * of itself on restart immediately exits with code 0.
 */
#define B_RESTART_EXIT  0x10 

/* #define UNUSED       0x20 */

/* B_IGNORE_WPS signifies that this process should not have its credentials
 * modified when it is branded into the WPAR.  If this flag is not specified
 * then the limiting privilege set of the process will be modified to match
 * the privileges specified in the WPARs configuration file.
 */
#define B_IGNORE_WPS    0x40

/* B_ALLOW_RESTART should be used to brand a process even if the restart
 * phase is in progress.
 * This flag should not be used unless the branded process is part of the
 * restart or is compliant with restart's limitation. This flag is not
 * required if B_CORRAL_INIT is set.
 * WARNING: Using this flag may lead to restart failure.
 */
#define B_ALLOW_RESTART 0x80

/* brand() b_flags ends */

/* struct corral c_opts */
#define COPT_DEFAULT                    0x0000
#define COPT_WLM_MANAGED                0x0004
#define COPT_NO_CHROOT                  0x0008
#define COPT_APP_WPAR                   0x0010

/* WPAR has underlying checkpoint restart infrastructure */
#define COPT_MOBILE                     0x0020

/* WPAR's network routes are isolated */
#define COPT_ROUTING                    0x0040

/* NOVIP WPAR */
#define COPT_NOVIPWPAR			0x0080

/* transient: arrival node for upcoming migration is running at a different
 * OS level */
#define COPT_MIG_CROSS_LEVEL            0x0100

/* WPAR has cross-WPAR IPC access */
#define COPT_XWPARIPC                   0x0200

/* Usage of the following checkpoint and restart defines
 * requires the additional use of COPT_MOBILE.  WPAR 
 * configuration and modification routines ensure that 
 * COPT_MOBILE is present.
 */

/* end c_opt options */

/* corral_config() flags */

#define CFLAG_START                     0x00
#define CFLAG_RESTART                   0x01

/* end corral_config() flags */

#define KWNOVIP_SET 0x1
#define KWNOVIP_GET 0x2

/* Definitions related to kwpar_t.kc_state */
/**** KEEP src/bos/usr/lib/corrals/libcor_sh.sh::wpar_init_kcstate_vars IN SYNC ****/

/* Individual bits for kwpar_t.kc_state */
#define KCSBIT_INPROGRESS       0x001
#define KCSBIT_LOAD             0x002
#define KCSBIT_START            0x004
#define KCSBIT_STOP             0x008
#define KCSBIT_CHECKPOINT       0x010
#define KCSBIT_SAVE             0x020
#define KCSBIT_FREEZE           0x040
#define KCSBIT_PAUSE            0x080
#define KCSBIT_RESUME           0x100
#define KCSBIT_RESTORE          0x200
#define KCSBIT_RESTART          0x400
#define KCSBIT_KILL             0x800
#define KCSBIT_MOVE             0x1000
#define KCSBIT_BLOCKFS          0x2000
#define KCSBIT_MAINTENANCE      0x4000
#define KCSBIT_SERVICE          0x8000

/* State indicators/masks for kwpar_t.kc_state */
#define KCS_NONE                0
#define KCS_ALL                 0xFFFF  /* Keep this value accurate */
#define KCS_START_LOAD          (KCSBIT_START|KCSBIT_LOAD)
#define KCS_STARTING            (KCSBIT_START|KCSBIT_INPROGRESS)
#define KCS_STOPPING            (KCSBIT_STOP|KCSBIT_INPROGRESS)
#define KCS_REBOOTING           (KCS_STARTING|KCS_STOPPING) /* From inside */
#define KCS_ACTIVE              (KCSBIT_START) /* && !KCSBIT_INPROGRESS */
#define KCS_CHECKPOINTING       (KCSBIT_CHECKPOINT|KCSBIT_INPROGRESS)
#define KCS_FREEZING            (KCSBIT_START|KCSBIT_FREEZE|KCSBIT_INPROGRESS)
#define KCS_FROZEN              (KCSBIT_FREEZE) /* KCSBIT_INPROGRESS|KCSBIT_CHECKPOINT is allowed; KCSBIT_START is not */
#define KCS_SAVING              (KCSBIT_SAVE|KCSBIT_INPROGRESS)
#define KCS_PAUSED              (KCSBIT_PAUSE)
#define KCS_KILLING             (KCSBIT_KILL|KCSBIT_INPROGRESS)
#define KCS_RESTART_LOAD        (KCSBIT_RESTART|KCSBIT_LOAD)
#define KCS_RESTARTING          (KCSBIT_RESTART|KCSBIT_INPROGRESS)
#define KCS_RESTORING           (KCSBIT_RESTORE|KCSBIT_INPROGRESS)
#define KCS_RESUMING            (KCSBIT_RESUME|KCSBIT_INPROGRESS)
#define KCS_MOVING              (KCSBIT_MOVE|KCSBIT_INPROGRESS)
#define KCS_BLOCKFS             (KCSBIT_BLOCKFS)
#define KCS_MAINTENANCE         (KCSBIT_MAINTENANCE)
#define KCS_SERVICE             (KCSBIT_SERVICE)

/* Macro to decide whether a particular kwpar_t.kc_state value represents a
 * particular state.  Note that any given kwpar_t.kc_state value may represent
 * multiple states.  For example, given:
 *
 * int k = KCSBIT_CHECKPOINT|KCSBIT_INPROGRESS|KCSBIT_PAUSE;
 *
 * ...both of the following are true:
 *
 * HAS_KCS(k, KCS_CHECKPOINTING)
 * HAS_KCS(k, KCS_PAUSED)
 */
#define HAS_KCS(x,y)            (((x & y) == y) && !(                           \
                                 ((y == KCS_ACTIVE) && (x != KCS_ACTIVE))       \
                                 ||                                             \
                                 ((y == KCS_FROZEN) && (x & KCSBIT_START))      \
                                 ||                                             \
                                 ((y == KCS_STOPPING) && (x & KCSBIT_START))    \
                                 ||                                             \
                                 ((y == KCS_STARTING) && (x & KCSBIT_STOP))     \
                                ))

/* end kwpar_t.kc_state definitions */

#define CKEY_INIT	0x0
#define CORRAL_MAX    0xFFFE	/* Maximum cid_t corral identifier */
#define WPARCID_MAX   CORRAL_MAX
#define INVALID_CID   0xFFFF

#define MAXCORRALNAMELEN 25     /* Max SRC subsystem name len (30), 
                                 * minus "cor_", minus the null byte 
			         */
#define UUID_STRMAX 37
/* cordata_config operations */
#define CORDATAOP_ALL             0x1FFF  /* Keep this value accurate */
#define CORDATAOP_UUID            0x0001 
#define CORDATAOP_ARCH            0x0002 
#define CORDATAOP_MIG_VERSIONS	  0x0003

#define MAXWPARNAMELEN MAXCORRALNAMELEN

#define CORRAL_GLOBAL 0    	/* global corral identifier cid_t */
#define WPAR_GLOBAL CORRAL_GLOBAL

/*
 * These are special WPAR which never exists on the system but needed for
 * processing install and emgr TSD.
 * Hence, these CID is created just before  CORRAL_MAX
 */

#define INSTALLP_CID	0xFFFC
#define	EMGR_CID	0xFFFD

/* WPAR clogin tty name. This string is returned by routines that query
 * the TTY name associated with a file descriptor (e.g. ttyname(),
 * pty_ioctl_comm(), etc). The tty name is also kept in WPAR's /etc/utmp
 * and /var/adm/wtmp.
 */
#define WPARTTYNAME  "Global"

/* WPAR resources not managed by WLM seen by both 
   kernel and user space*/
#define WRC_PCT_SEMIDS  0
#define WRC_PCT_MSGIDS  1
#define WRC_PCT_SHMIDS  2
#define WRC_PCT_PINMEM  3

/* WPAR_MAX includes the maximum number of WPARs possible in a system plus one
 * for the "global" WPAR (cid of 0).
 * We need this visible to all */
#define WPAR_MAX 8193

/* Versioned WPAR level identifiers
 * First four bits designate level format identifier.  Only defined format
 * currently is format 0.
 * 
 * Fields should only be non-zero for a level where there is 
 * differentiation between versioned wpar levels.  If all supported
 * technology levels for a release are treated the same, then the
 * TL bits should be 0.
 *
 * Format 0 can continue to be used as long as the following are true:
 *   AIX Version is between 5 and 12.
 *   AIX Release is between 0 and 3.
 *   AIX Technology Level is between 0 and 15.
 *   AIX SysCall Level (kernel interface version) is between 0 and 31.
 * 
 *   VWPAR Level Format 0:
 *   Bit numbers (Read top to bottom)
 * 
 * 11 111 1
 * 54 321 09 8765 43210
 * FF VVV RR TTTT SSSSS
 * FF                                   - format of vwpar level id 
 *    VVV                               - version number - 5 - add 5 to get V
 *        RR                            - release number - 1 - add 1 to get R 
 *           TTTT                       - technology or modification level
 *                SSSSS                 - syscall level (kernel i/f version)
 *
 * FFVV VRRT TTTS SSSS
 * 
 ******************************************/

/* Versioned Workload Partition Environment Levels */
#define CRE_NONE        0               /* Maps to Global Environment */
#define CRE_AIX_52S     1		/* Special initial value */
#define CRE_INVALID_LEVEL 65535		/* Invalid pv_cre value */
#define CRE_ALL_LEVELS  CRE_INVALID_LEVEL	/* Used in kmem handlers */

#define VWPAR_FMT_MASK   0xC000
#define VWPAR_VER_MASK   0x3800
#define VWPAR_REL_MASK    0x600
#define VWPAR_TL_MASK     0x1E0
#define VWPAR_SC_MASK      0x1F

#define VWPAR_FMT_SHIFT      14
#define VWPAR_VER_SHIFT      11
#define VWPAR_REL_SHIFT       9
#define VWPAR_TL_SHIFT        5
#define VWPAR_SC_SHIFT        0

#define VWPAR_MIN_VER         5		/* Minimum Version of AIX in VWPAR */
#define VWPAR_MIN_REL         1		/* Minimum AIX Release Level */

#define CRE_AIX_53        ((3 - VWPAR_MIN_REL) << VWPAR_REL_SHIFT)  /* 0x400 */
#define CRE_AIX_71        (((7 - VWPAR_MIN_VER) << VWPAR_VER_SHIFT) + ((1 - VWPAR_MIN_REL) << VWPAR_REL_SHIFT))  /* 0x1000 */
#define CRE_AIX_71_BTL    (2 << VWPAR_TL_SHIFT)         /* 71 BASE TL = 0x40 */

#define VWPAR_VRT_LVL(x)  ((x) & (VWPAR_VER_MASK|VWPAR_REL_MASK|VWPAR_TL_MASK))
#define VWPAR_VR_LVL(x)   ((x) & (VWPAR_VER_MASK|VWPAR_REL_MASK))
#define VWPAR_V_LVL(x)    ((x) & (VWPAR_VER_MASK))
#define VWPAR_TL_LVL(x)   ((x) & (VWPAR_TL_MASK))

#define V5_VWPAR_LVL(x)     (((x) == CRE_AIX_52S) || \
                           (VWPAR_VR_LVL(x) == CRE_AIX_53))

#define V71_VWPAR_LVL(x)  ((VWPAR_VR_LVL(x) == CRE_AIX_71) && \
                           (VWPAR_TL_LVL(x) >= CRE_AIX_71_BTL))

#define VALID_CRE_LVL(x)  (V5_VWPAR_LVL(x) || V71_VWPAR_LVL(x))
                          

/* Deprecated definition from when levels ids were expected to be sequential */
#define CRE_MAX_LVL     CRE_AIX_52S

/* Architecture Compatibility Environment level identifiers */
#define ACE_NONE	0
#define ACE_POWER4	1
#define ACE_PPC970	2
#define ACE_POWER5	3
#define ACE_POWER6	4
#define ACE_POWER7	5
#define ACE_POWER8	6
#define ACE_POWER9	7
#define ACE_MAX_LVL	ACE_POWER9

/*
 * Max number of sysconfs[] entries required.
 *
 * Currently, CRE_AIX_52S is the only CRE level that requires an entry in
 * sysconfs. As CRE_AIX_52S WARs are not supported on ACE any architecture,
 */
#define CRE_MAX_SC    (ACE_MAX_LVL + CRE_MAX_LVL + 1)

/* [k]wpar_checkpoint_status() commands */
#define WPAR_CHECKPOINT_TRY             0x1
#define WPAR_CHECKPOINT_DENY            0x2
#define WPAR_CHECKPOINT_ALLOW           0x3
#define WPAR_CHECKPOINT_CLEAR           0x4
#define WPAR_RESTART_CLEAR              0x5
#define WPAR_CHECKPOINT_QUERY           0x6
#define WPAR_CHECKPOINT_DENY_ALL        0x7
#define WPAR_CHECKPOINT_CROSS_LEVEL_MIG 0x8
#define WPAR_CHECKPOINT_SAME_LEVEL_MIG  0x9

/* Notification events */
#define WPARSTART		1
#define WPARSTOP		2
#define MOB_CHECKPOINT_START	3
#define MOB_CHECKPOINT_END	4
#define MOB_CHECKPOINT_FAILED	5
#define MOB_RESTART_START	6
#define MOB_RESTART_END		7
#define MOB_RESTART_FAILED	8

#ifdef _KERNEL

/*
 * _KERNSYS should be defined only for kernel
 * not for kernel extensions. 
 */

#ifdef _KERNSYS

/* Not intended to be used by kernel extensions or 
 * user applications.
 */

extern cre_t wpar_lookup_cre(struct pvproc *);

#endif

/* if we're in the global corral (cid == 0) or the kcorral cids 
 * are equivalent then the object associated with OKCID is viewable
 */
#define KCID_VIEWABLE(MYKCID,OKCID) \
	((MYKCID) == CORRAL_GLOBAL || (MYKCID) == (OKCID))

/* Special type of viewable macro used for processes.  This one conforms
 * to KCID_VIEWABLE() but also allows process 0 (swapper) to show thru.
 * We allow swapper process to show since we don't run a unique swapper for 
 * the corral yet several system utilities decide we're not on a valid
 * AIX system if they don't see it.
 */
#define KCID_PV_VIEWABLE(MYKCID, PV) \
	((MYKCID) == CORRAL_GLOBAL ||  \
         (MYKCID) == (PV)->pv_kcid || \
	 (PV)->pv_pid == 0)

#define KCID_CORRALED(KCID)	 ((KCID) != CORRAL_GLOBAL)
#define KCID_CURPROC() 		 (curpvproc->pv_kcid)
#define KCID_INIT(KCID)		 ((KCID) = 0)
#define KCID_EQUAL(KCID1,KCID2)  ((KCID1) == (KCID2))

/* Returns true if this an application WPAR */
#define KCID_APP_WPAR(KCID)  	 kwpar_option_enabled(KCID,COPT_APP_WPAR)
 
/* FLAGS */
#define C_FREE 		0x00000000
#define C_CONFIG 	0x00000001
/* #define OBSOLETE	0x00000002  */
/* #define OBSOLETE	0x00000004  */

/* kwpar_getset_netisolation() commands (cmd parameter) */
#define KWNIOPT_SET 0x1
#define KWNIOPT_GET 0x2

/* kwpar_delroutes() flags */
#define KWR_EXPLICIT 0x1        /* Delete only explicit routes */

/* kernel services */
void kwpar_init(void);
int kwpar_option_enabled(cid_t, unsigned int);
int kwpar_sethostname(cid_t, char *, size_t);
int kwpar_setdomainname(cid_t, char *, size_t);
int kwpar_gethostname(cid_t, char *, size_t, int);
int kwpar_getname(cid_t, char *, size_t, int);
int kwpar_getdomainname(cid_t, char *, size_t, int);
int kwpar_sethostid(cid_t, int);
int kwpar_gethostid(cid_t, int *);
int kwpar_getrootpath(cid_t, size_t *, char *);
int kwpar_getinitpid(cid_t, pid_t *);
int kwpar_resetinitpid(cid_t);
int kwpar_getckey(cid_t, ckey_t *);
int kwpar_getclassindex(cid_t);
int kwpar_inuse(cid_t, int);
int kwpar_setstate(cid_t, uint, uint);
int kwpar_getstate(cid_t, uint*);
int kwpar_getstate_nolock(cid_t, uint*);
int kwpar_wait_for_state_change(cid_t, uint*, uint);
int kwpar_checkpoint_status(cid_t, int, void *);
int kwpar_getwlmlimits(cid_t, int, struct wlm_bounds *);
int kwpar_getrset(cid_t, char *);
int kwpar_getset_netisolation(cid_t kcid, int cmd, boolean_t *value);
int kwpar_getset_novipwpar(cid_t kcid, int cmd, boolean_t *value);
int kwpar_delroutes(cid_t kcid, uint flags);
int kwpar_isappwpar(cid_t kcid);
int kwpar_pn_isappwpar(cid_t kcid);
int kwpar_pn_xwparaccess(cid_t kcid);
int kwpar_mount_begin_check(cid_t kcid, int cmd, cid_t vfs_kcid);
int kwpar_mount_end_check(cid_t kcid, int cmd, int rc);
int kwpar_mnt_hold (cid_t kcid);
int kwpar_mnt_rele (cid_t kcid);
int kwpar_get_params(cid_t kcid, int *cross_oslevel, cre_t *wpar_cre);
int kwpar_getbitmaps(cid_t kcid, void **bitmap32, void **bitmap64);
void kwpar_savemrc(tid_t, sigset_t *, uint);
uint kwpar_getmrc(sigset_t *);
void kwpar_rmmrclist(tid_t);

pid_t kwpar_r2vmap_pid(cid_t *kcidp, pid_t rpid);
pid_t kwpar_v2rmap_pid(cid_t  kcid,  pid_t vpid);
tid_t kwpar_r2vmap_tid(cid_t *kcidp, tid_t rtid);
tid_t kwpar_v2rmap_tid(cid_t  kcid,  tid_t vtid);
pid_t kwpar_v2rmap_vpid(cid_t,  pid_t);


/* WPAR device mapping services */
int kwpar_v2rmap_devno(cid_t kcid, dev_t vdevno, dev_t *rdevno);
int kwpar_r2vmap_devno(cid_t kcid, dev_t rdevno, dev_t *vdevno);
int kwpar_regdevno(cid_t kcid, dev_t vdevno, dev_t *rdevno);
int kwpar_unregdevno(cid_t kcid, dev_t rdevno);
int kwpar_devV2Rname(char *vname, char *rname);
int kwpar_devV2Rname_CID(cid_t kcid, char *vname, char *rname);

/* WPAR exported kernel extension list services */
int kwpar_chk_kext(int cmd, char * name, char * path, mid_t kmid, uint * local, uint * hndl);

/* Operation for kwpar_chk_kext */
#define WPAR_EXT_CHK_LOAD	0x01	/* Check load permission   */
#define WPAR_EXT_CHK_UNLOAD	0x02	/* Check unload permission */
#define WPAR_EXT_REG_KMID   	0x04	/* Register a kmid to a loaded KE */

/* Operations for kwpar_getdd() */
typedef enum
{
   WPAR_DD_NONE,    /* 0x00 - no action / blank action              */
   WPAR_DD_OPTS,    /* 0x01 - retrieve d_open dd options            */
   WPAR_DD_OPEN,    /* 0x02 - retrieve d_open dd entry point        */
   WPAR_DD_CLOSE,   /* 0x03 - retrieve d_close dd entry point       */
   WPAR_DD_READ,    /* 0x04 - retrieve d_read dd entry point        */
   WPAR_DD_WRITE,   /* 0x05 - retrieve d_write dd entry point       */
   WPAR_DD_IOCTL,   /* 0x06 - retrieve d_ioctl dd entry point       */
   WPAR_DD_SELECT,  /* 0x07 - retrieve d_select dd entry point      */
   WPAR_DD_MPX,     /* 0x08 - retrieve d_mpx dd entry point         */
   WPAR_DD_CLONE,   /* 0x09 - retrieve clone d_open dd entry point  */
   WPAR_DD_STRAT,   /* 0x0A - retrieve d_strategy entry point       */
   WPAR_DD_DUMP,    /* 0x0B - retrieve d_dump entry point           */
   WPAR_DD_REVOKE,  /* 0x0C - retrieve d_revoke entry point         */
   WPAR_DD_QRY,     /* 0x0D - retrieve devqry entry point           */
   WPAR_DD_CFG,     /* 0x0F - retrieve d_config entry point         */
   WPAR_DD_CFGINIT  /* 0x10 - retrieve initial d_config entry point */
}  kwparddop_t;

/* Device entry point prototypes */
int kwar_getdd(dev_t, kwparddop_t, void**);

/* Virtual device name macros */
#define STRDISK "hdisk"
#define STRDISK_LEN 5 
#define STRTAPE "rmt"
#define STRTAPE_LEN 3

#define WDEV_IS_VNAME_DISK(n) \
   ((n) && (strncmp((n), STRDISK, STRDISK_LEN) == 0))

#define WDEV_IS_VNAME_TAPE(n) \
   ((n) && (strncmp((n), STRTAPE, STRTAPE_LEN) == 0))

#define WDEV_IS_VNAME(n) \
   (WDEV_IS_VNAME_DISK((n)) || WDEV_IS_VNAME_TAPE((n)))

/* Declarations to prevent including of extra header files */
struct socket;
struct file;
struct timespec;

/* Subsystems may register for corral callback notification.
 * Notification callback routine is made on new corral
 * configuration or on corral deletion.
 */
typedef int regkey_t;

typedef int (*wpar_config_func_t)(int flags, cid_t cid, 
                                  struct corral *, void *unused);
typedef int (*wpar_brand_addr_t)(struct sockaddr_in *, cid_t);
typedef int (*wpar_net_info_t)(int, caddr_t , int *, uint64_t, int *, cid_t);
typedef int (*wpar_net_oper_t)(int cmd, cid_t cid, caddr_t bufp, int size);
typedef int (*wpar_inet_cr_t)(int cmd, struct socket *, struct file *, void *);
typedef struct wpar_config_hook
{
    uint		current_hiwater;
    wpar_config_func_t	configp;
} wpar_config_hook_t;

#define WPAR_NET_HOOK_VERSION 2

struct wpar_net_hook
{
    int               version;
    wpar_brand_addr_t addrp;
    wpar_net_info_t   infop;
    wpar_net_oper_t   operp;
    wpar_inet_cr_t    inetcrp;
    void **           wpars_netstatp;
};
typedef struct wpar_net_hook wpar_net_hook_t;

#define WPAR_AIO_HOOK_VERSION		1

/* hooks for AIO */

typedef int (*wpar_aio_suspend_io_t)(struct timespec *timeoutp);
typedef int (*wpar_aio_resume_io_t)(void);
typedef int (*wpar_aio_io_t)(pid_t, int, struct file *, struct file *,
	void *, size_t *);

struct wpar_aio_hook
{
	int			version;
	wpar_aio_suspend_io_t	suspendp;
	wpar_aio_resume_io_t	resumep;
	wpar_aio_io_t		getiop;
	wpar_aio_io_t		putiop;
};

typedef struct wpar_aio_hook wpar_aio_hook_t;

#define WPAR_PSE_HOOK_VERSION 1

typedef int (*wpar_pse_crstr_t)(int, void *);

struct wpar_pse_hook
{
    int               version;
    wpar_pse_crstr_t  crstrp;
};
typedef struct wpar_pse_hook wpar_pse_hook_t;

/* Checkpointing structures for trace kernel extension devices */
#define WPAR_TRC_HOOK_VERSION 1
typedef int (*wpar_trc_crstr_t)(int,void*);
struct wpar_trc_hook
{
    int               version;
    wpar_trc_crstr_t  crtrcp;
};
typedef struct wpar_trc_hook wpar_trc_hook_t;

#define WPAR_BPF_HOOK_VERSION 1

typedef int (*wpar_bpf_crstr_t)(int, void *);

struct wpar_bpf_hook
{
    int               version;
    wpar_bpf_crstr_t  crbpfp;
};
typedef struct wpar_bpf_hook wpar_bpf_hook_t;

#define WPAR_NFS_HOOK_VERSION	1

#define NFS_OPER_NETBLOCK	1
#define NFS_OPER_NETUNBLOCK	2

typedef int (*wpar_nfs_oper_t)(int cmd, cid_t cid, caddr_t bufp, int size);

struct wpar_nfs_hook
{
    int               version;
    wpar_nfs_oper_t   operp;
};
typedef struct wpar_nfs_hook wpar_nfs_hook_t;

#define LU_NFS_HOOK_VERSION	1

#define LU_NFS_OPER_CHECKPOINT	0
#define LU_NFS_OPER_NETUNBLOCK	1

typedef int (*lu_nfs_oper_t)(int cmd, caddr_t bufp, int size);

struct lu_nfs_hook
{
    int               version;
    lu_nfs_oper_t     operp;
};
typedef struct lu_nfs_hook lu_nfs_hook_t;

/* Hooks for IOCP */

#define	WPAR_IOCP_HOOK_VERSION	1

struct fdinfo_io_iocp;		/* need this for forward reference below */

typedef	int (*wpar_get_iocp_fds_t)(struct fdinfo_io_iocp *);
typedef	int (*wpar_get_iocp_pkts_t)(struct fdinfo_io_iocp *);
typedef	int (*wpar_put_iocp_pkts_t)(struct fdinfo_io_iocp *);

typedef	struct wpar_iocp_hook
{
	int			version;
	wpar_get_iocp_fds_t	getfdsp;
	wpar_get_iocp_pkts_t	getpktsp;
	wpar_put_iocp_pkts_t	putpktsp;
} wpar_iocp_hook_t;


/* Invalid registration key.  Returned if no registration possible */
#define BADREGKEY  -1

/* These defines are for identifying the hook type 
 * that is being supplied to kwpar_reghook().  The 
 * hookp input type depends on the hooktype specified.
 */
#define WPAR_NOTIFY_HOOK    1 /* hookp is a wpar_config_func_t */
#define WPAR_NET_HOOK       2 /* hookp is a wpar_net_hook_t */
#define WPAR_MCR_HOOK       3 /* hookp is a wpar_mcr_hook_t */
#define WPAR_AIO_HOOK       4 /* hook for legacy AIO */
#define WPAR_POSIX_AIO_HOOK 5 /* hook for POSIX AIO */
#define WPAR_PSE_HOOK       6 /* hookp is a wpar_pse_hook_t */
#define WPAR_NFS_HOOK       7 /* hookp is a wpar_nfs_hook_t */
#define WPAR_IOCP_HOOK      8 /* hookp is a wpar_iocp_hook_t */
#define LU_MCR_HOOK         9 /* hookp is a lu_mcr_hook_t */
#define WPAR_TRACE_HOOK    10 /* hookp is a wpar_trc_hook_t */
#define WPAR_BPF_HOOK      11 /* hookp is a wpar_bpf_hook_t */
#define LU_NFS_HOOK        12 /* hookp is a lu_nfs_hook_t */

struct vnode * kwpar_holdrootvnode(cid_t);
#define kwpar_relerootvnode(VN)	if (VN)	VNOP_RELE(VN)

int wlm_start_corral(void);
int wlm_stop_corral(void);

/* Exported kernel extension calls */
cid_t kcid_curproc(void);
int curproc_kproc(void);

regkey_t kwpar_reghook(int hooktype, void *hookp);
int kwpar_unreghook(regkey_t); /* unregister kwpar_reghook */

/* wpar resource control functions*/
extern int wpar_limits_checkupdt (int resource, long  count);
extern void  wpar_usage_decrement (cid_t kcid, int resource, long count);
int wpar_dr_resetlimits (void *event, void *arg, int phase, void *info);

/*IPC usage tracking variables*/
extern long	msqid_inuse;
extern long semid_inuse;
extern long shmid_inuse;
extern char novip_wpar[];
#define GET_NOVIP_WPAR(kcid,value) \
        ((value) =  ((novip_wpar[(kcid)/8] & (1<< (7 - ((kcid) % 8)))) ? 1 : 0))

/* For use by kwpar_mount_begin_check and kwpar_mount_end_check */
#define WPAR_MOUNT_CHECK     1
#define WPAR_UMOUNT_CHECK    2

#endif /* _KERNEL */
#endif /* _CORRALID_H */