/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* bos72Q src/bos/usr/ccs/lib/libcorcfg/wparlock.h 1.10.1.2               */
/*                                                                        */
/* Licensed Materials - Property of IBM                                   */
/*                                                                        */
/* Restricted Materials of IBM                                            */
/*                                                                        */
/* COPYRIGHT International Business Machines Corp. 2005,2019              */
/* 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                                                     */
/* @(#)84       1.10.1.2  src/bos/usr/ccs/lib/libcorcfg/wparlock.h, libcor, bos72Q, q2019_13A4 2/4/19 06:28:50 */

#ifndef _H_CORLOCK
#define _H_CORLOCK

#ifdef __cplusplus
extern "C" {
#endif

typedef uint  corflag_t;
typedef char  cname_t[MAXCORRALNAMELEN + 1];

/* Operations Types */
/* NOTE: If making changes to operation types,
 * make corresponding changes to all perl and 
 * ksh consumers.
 */
#define COROPMAX   21
typedef enum
{
   COROPNONE,       /* 0 blank operation */
   COROPDBG,        /* 1 internal/debug use */ 
   COROPLS,         /* 2 list operation */
   COROPCH,         /* 3 change operation */
   COROPRM,         /* 4 remove operation */
   COROPSTART,      /* 5 start operation */
   COROPSTOP,       /* 6 stop operation */
   COROPSYNC,       /* 7 sync operation */
   COROPMK,         /* 8 make operation */
   COROPRUN,        /* 9 run operation */
   COROPWEXEC,	    /*10 exec operation */
   COROPREBOOT,	    /*11 reboot opertation */
   COROPRC,	    /*12 rc.wpars */
   COROPCKPT,	    /*13 checkpoint operation */
   COROPRSTART,	    /*14 restart operation */
   COROPKILL,	    /*15 kill operation */
   COROPRESUME,     /*16 resume operation */
   COROPRESOURCE,   /*17 non-wpar resource operation */
   COROPVINIT,      /*18 vinit (app wpar monitor) */
   COROPSAVE,        /*19 save operation (backup) */
   COROPMOVE,       /*20 move operation (async. mobility) */
   COROPMIG         /*21 mig operation */
}  corop_t;

/* Corresponding command name strings */
static char *COROP_MAP[COROPMAX+1] = {
   "none",
   "debug",
   "lswpar",
   "chwpar",
   "rmwpar",
   "startwpar",
   "stopwpar",
   "syncwpar",
   "mkwpar",
   "runwpar",
   "wparexec",
   "rebootwpar",
   "rc.wpars",
   "chkptwpar",
   "restartwpar",
   "killwpar",
   "resumewpar",
   "resource",
   "vinit",
   "savewpar",
   "movewpar",
   "migwpar"
};

/* Lock action types */
typedef enum
{
   CORNONE,        /* 0 no action / blank action */
   CORLOCK,        /* 1 lock the corral   */
   CORUNLOCK,      /* 2 unlock the corral */
   CORSTAT         /* 3 get lock file information, call to corlockstat() */
}  lockact_t;


/* Response status types */
typedef enum
{
   CLS_OK,         /* 0  no status, blank status, ok status */
   CLS_ENOLOCK,    /* 1  no current lock on corral */
   CLS_ELOCKED,    /* 2  corral is locked */
   CLS_ESTALE,     /* 3  corral is locked by non-existent process */
   CLS_ELFBUSY,    /* 4  unable to get record lock on lock file */
   CLS_ECORRAL,    /* 5  can't locate corral by given name */
   CLS_EOPEN,      /* 6  error opening lock file */
   CLS_EFSTAT,     /* 7  error stating lock file */
   CLS_EGETPROC,   /* 8  getprocs64() call failed */
   CLS_EWRITE,     /* 9  error writing lock file */
   CLS_EPARMS,     /* 10 one or more invalid parameters */
   CLS_ERM,        /* 11 error removing lock file */
   CLS_ELFPATH,    /* 12 error processing lock file path */
   CLS_EKQUERY,    /* 13 error querying the kernel */
   CLS_EKSTATE     /* 14 kernel state of the wpar forbids acquiring lock */
}  corlockstat_t;


/* Lock request sructure */
typedef struct corlockrq
{
   cname_t        cname;          /* name of corral to lock */
   pid_t          r_pid;          /* pid requesting the lock action */
   corop_t        r_operation;    /* The operation requesting that lock action */
   corflag_t      flags;          /* Bitwise "or"ed options */
}  corlockreq_t;


/* Lock response sructure */
typedef struct corlockresp
{
   pid_t          h_pid;          /* pid that is holding the lock */
   time64_t       h_pid_start;    /* start time of h_pid */
   corop_t        h_operation;    /* operation associated with h_pid */
   corflag_t      h_flags;        /* Bitwise "or"ed options (inheritance) */
   corlockstat_t  lockstat;       /* status of the action */
}  corlockresp_t;


/* Lock action flags (corflag_t) */
#define BIT(n)            (1<<n)      /* bit setter for the chronically lazy */
#define CLF_SKIPNAME      BIT(0)      /* skip corral name existence check */
#define CLF_STALEBAD      BIT(1)      /* error if lock holder is stale */
#define CLF_FORCE         BIT(2)      /* force lock/unlock (shortest route) */
#define CLF_NO_INHERIT    BIT(3)      /* lock cannot be inherited by subprocs */
#define CLF_TRANSFER      BIT(4)      /* lock is completely reassigned to subproc */
#define CLF_INHERIT       BIT(5)      /* lock is inherited read-only by subprocs */
#define INHERITANCE_BITS (CLF_NO_INHERIT | CLF_TRANSFER | CLF_INHERIT) /* convenience */


/**************************************************************************
 Subroutine: corlockctl()
 Function: Locks or unlocks the corral with given lockfile.
 Input Parameters:  lockact_t lockact, corlockreq_t structure
 Output Parameters: corlockresp_t structure
 Returns: void 
***************************************************************************/
extern void corlockctl(lockact_t, corlockreq_t, corlockresp_t *);

/**************************************************************************
 Subroutine: corlockstat()
 Function: Gets information on existing lock file.
 Input Parameters: cname = corral name
 Output Parameters: corlockresp_t structure

 Note:  The corlockstat() subroutine returns 
        the following via resp->lstatus: 
        CLS_ENOLOCK = no valid lock exists
        CLS_ELOCKED = a valid lock exists
        CLS_ESTALE  = a stale lock exists
        CLS_<OTHER> = some sort of error getting 
                      the lock status 

 Returns: void 
***************************************************************************/
extern void corlockstat(cname_t, corlockresp_t *);

/**************************************************************************
 Subroutine: is_ancestor()   (NOT EXPORTED)
 Function: Determines whether the process described by apid is a direct ancestor
        of the process described by dpid.  Returns TRUE if so; FALSE otherwise.
        Note: tests for STRICT ancestry - i.e. returns false if apid == dpid.
 Input Parameters: PID of the proposed *ancestor*, PID of the proposed
        *descendant*
 Output Parameters: None
 Returns: TRUE/FALSE
***************************************************************************/
extern boolean_t is_ancestor(pid_t, pid_t);

#ifdef __cplusplus
}
#endif
  
#endif /* _H_CORLOCK */
