File:  [Power 6/32 Unix Tahoe 4.2BSD] / cci / sys / h / iidr_30.h
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Sun Jul 28 12:29:42 2019 UTC (7 years ago) by root
Branches: bsd, MAIN
CVS tags: v121, HEAD
Power 6/32 Unix version 1.21

/*
**	Copyright (c) 1983 Relational Technology Inc.
**
**	IIDR.H	- structures for the INGRES lock driver
**
**	Description:
**		Defines the constants and the structures used by the lock device.
*/

/*	The request codes to the lock device.		*/

/* These are opcodes used by the lock driver when it is called as
** a minor device.
*/
# define	KN_O_LOCK	1
# define	KN_O_UNLOCK	2
# define	KN_O_CONVERT	3
# define	KN_O_RELEASE	4
# define	KN_O_UNIQ	5
# define	KN_O_DBCONSIST	6

/* These are codes used by the lock driver when it is called as
** a major device.
*/
# define	KN_O_USERSLOT		1
# define	KN_O_PRINT_STRUCTURES	2
# define	KN_O_DEBUGLEVEL		3
# define	KN_O_RESET_LOCKDRIVER	4

/*
** Ioctl's have the command encoded in the lower word,
** and the size of any in or out parameters in the upper
** word.  The high 2 bits of the upper word are used
** to encode the in/out status of the parameter; for now
** we restrict parameters to at most 128 bytes.
**
** For some reason bit 29 is always set.
**
** The high two bits (31 and 30) mean:
**		00	(2)	- Void - no parameters
**		10	(a)	- In parameter
**		01	(6)	- Out parameter
**		11	(e)	- in/out parameter
*/

/* Command qualification for OS, currently unused by INGRES */
# define	KN_QUAL		('i' << 8)

/* bits to shift for parameter type */
# define	KN_P_TSHIFT	28

/* descriptions of parameters */
# define	KN_P_VOID	(0x2 << KN_P_TSHIFT)
# define	KN_P_OUT	(0x6 << KN_P_TSHIFT)
# define	KN_P_IN		(0xa << KN_P_TSHIFT)
# define	KN_P_INOUT	(0xe << KN_P_TSHIFT)

/* bits to shift parameter size */
# define	KN_P_SSHIFT	16

/* size of minor device parameters, in sizoef quantities  */
# define	KN_SZ_LOCK		(sizeof(LOCK_KEY) << KN_P_SSHIFT)
# define	KN_SZ_UNLOCK		(sizeof(short) << KN_P_SSHIFT)
# define	KN_SZ_CONVERT		(sizeof(short) << KN_P_SSHIFT)
# define	KN_SZ_RELEASE		0
# define	KN_SZ_UNIQ		(2 * sizeof(int) << KN_P_SSHIFT)
# define	KN_SZ_DBCONSIST		(sizeof(int) << KN_P_SSHIFT)

/* size of major device parameters, in sizeof() quantities */
# define	KN_SZ_USERSLOT		(sizeof(int) << KN_P_SSHIFT)
# define	KN_SZ_PRINT_STRUCTURES	(sizeof(int) << KN_P_SSHIFT)
# define	KN_SZ_DEBUGLEVEL	(sizeof(int) << KN_P_SSHIFT)
# define	KN_SZ_RESET_LOCKDRIVER	0

# define	KN_R_LOCK		(KN_QUAL | KN_P_IN   | KN_O_LOCK      | KN_SZ_LOCK)
# define	KN_R_UNLOCK		(KN_QUAL | KN_P_IN   | KN_O_UNLOCK    | KN_SZ_UNLOCK)
# define	KN_R_CONVERT		(KN_QUAL | KN_P_IN   | KN_O_CONVERT   | KN_SZ_CONVERT)
# define	KN_R_RELEASE		(KN_QUAL | KN_P_VOID | KN_O_RELEASE   | KN_SZ_RELEASE)
# define	KN_R_UNIQ		(KN_QUAL | KN_P_OUT  | KN_O_UNIQ      | KN_SZ_UNIQ)
# define	KN_R_DBCONSIST		(KN_QUAL | KN_P_IN   | KN_O_DBCONSIST | KN_SZ_DBCONSIST)

/* These are opcodes to be used when connected to the major device */
# define 	KN_R_USERSLOT		(KN_QUAL | KN_P_OUT  | KN_SZ_USERSLOT         | KN_O_USERSLOT)
# define 	KN_R_PRINT_STRUCTURES	(KN_QUAL | KN_P_IN   | KN_SZ_PRINT_STRUCTURES | KN_O_PRINT_STRUCTURES)
# define	KN_R_DEBUGLEVEL		(KN_QUAL | KN_P_IN   | KN_SZ_DEBUGLEVEL       | KN_O_DEBUGLEVEL)
# define	KN_R_RESET_LOCKDRIVER	(KN_QUAL | KN_P_VOID | KN_SZ_RESET_LOCKDRIVER | KN_O_RESET_LOCKDRIVER)

/*
** These are the parameters to be passed in "addr" on a
** KN_R_PRINT_STRUCTURES call.
*/
# define	KN_P_USERS	1
# define	KN_P_LKB	2
# define	KN_P_HASH	3
# define	KN_P_STAT	4
# define	KN_P_RSB	5

/*	The lock modes that the device supports		 */

# define	KN_M_NL		0
# define	KN_M_CR		1
# define	KN_M_CW		2
# define	KN_M_PR		3
# define	KN_M_PW		4
# define	KN_M_EX		5

/*	Possible extra return values from the lock device	*/

# define	EDEADLOCK	60
# define	ECHILDREN	61
# define	ELOCKID		62
# define	ENOTQUEUED	63
# define	ERESOURCE	64
# define	EBUG		65
# define	ECONSIST	66 /* Couldn't grant lock - data base has gone
				   ** inconsistent
				   */
# define	EFLAG_SAME	67 /* Call to KN_R_CONSIST resulted in state
				   ** remaining the same.
				   */
# define	ELOCKMODE_INVALID	68
# define	EOPCODE_INVALID		69
# define	EWAIT_INTR		70
# define	EPANIC			71	/* lock driver is in a panic
						** state. Rather than crashing
						** the machine, disallow all
						** ioctl requests by minor de-
						** vices.
						*/

/* Types of locks that the lock driver knows about */
# define	LCK_DATABASE	0x4949		/* 'II' */

/*	The structure used by the user to pass lock key information to the lock device.	*/

typedef struct
{
	short		lk_parent;		/*	parentid when setting a lock	*/
	unsigned short	lk_type;		/*	the type of lock		*/
	long		lk_key;			/*	the key when setting a lock	*/
	short		lk_installation;	/*	installation constant	*/
}	LOCK_KEY;

/*	Collect performance numbers about the lock device in this structure.	*/

typedef struct
{
	long	ii_locks;		/*	number of lock requests			*/
	long	ii_unlocks;		/*	number of unlocks requests		*/
	long	ii_converts;		/*	number of conversion requests		*/
	long	ii_lockwaits;		/*	number of lock requests that waited	*/
	long	ii_waitconverts;	/*	number of convert requests that waited	*/
	long	ii_deadconverts;	/*	number of conversion deadlocks		*/
	long	ii_deadsearchs;		/*	number of deadlock searches performed	*/
	long	ii_deadlocks;		/*	number of resource deadlocks found	*/
}	STAT;

/*
** CMD
**
**	This structure really wants to be a bitfield, but this format
**	does not work on different architectures.  On machines with
**	BYTE_SWAP the structure needs to defined differently than on
** 	a VAX.
**
**	Finally on the Pyramid BITFIELDS are not pushed and popped as
**	if they were ints.  Since ioctl expects the cmd argument to be
**	an int we must define CMD as an int and use bit-masking, and
**	shifting to get the values out.
**
**	The format of a request code to the lock device.
**
**	    typedef struct
**	    {
**	    	unsigned cmd_opcode:3;		** function code
**
**	    	unsigned cmd_lock_mode:3;	** lock mode
**
**	    	unsigned cmd_no_queue:1;	**  don't wait modifier
**
**	    	unsigned cmd_ignore_econsist:1;	** modifier tells lock driver
**	    					** to ignore the fact that the
**	    					** data base may be
**	    					** inconsistent
**	    					**
**	    }	CMD;
**
**
**	bits of the command:
**			bits 0-2: opcode.
**			bits 3-5: lock_mode.
**			bit  6  : wait/nowait modifier
**			bit  7  : ignore consistent database modifyer
**			bits 8-15: qualifier to operating system.
**				   this is usually a single character.
**				   we use 'i', which is not used currently
**				   for anything.
**			bits 16-23:size of the parameter being passed through
**				   "addr" the third argument of the ioctl call.
**			bits 24-28: ?
**			bits 29-31: used to encode whether the parameter is
**				    in, out, in/out, or not used. (see above
**				    for description.)
*/
# define CMD_OPCODE(cmd)		(0x00000007 & (cmd))
# define CMD_LOCK_MODE(cmd)		(0x00000007 & ((cmd) >> 3))
# define CMD_NO_QUEUE(cmd)		(0x00000001 & ((cmd) >> 6))
# define CMD_IGNORE_ECONSIST(cmd)	(0x00000001 & ((cmd) >> 7))


# ifndef	QUE_DEF
# define	QUE_DEF	1
typedef struct _QUEUE	QUEUE;

struct	_QUEUE
{
	QUEUE	*q_next;
	QUEUE	*q_prev;
};

# endif		QUE_DEF

QUEUE	*remque_30();
QUEUE	*insque_30();

typedef struct _LKB LKB;
typedef struct _RSB RSB;

/*
**	A Resource Block.
**		An RSB is allocated for each unique key that is locked.
**		It contains information about that states of locks queued against this resource.
*/

struct _RSB
{
	QUEUE		rsb_next;			/*	next of hash chain					*/
	QUEUE		rsb_wait_lkb;			/*	queue of waiting locks					*/
	QUEUE		rsb_grant_lkb;			/*	queue of granted locks followed by conversion requests	*/
	RSB		*rsb_parent;			/*	parent resource						*/
	LKB		*rsb_deadlock_next;		/*	used to save next on recursion in deadlock tree		*/
	LKB		*rsb_deadlock_curr;		/*	used to save curr on recursion in deadlock tree		*/
	int		rsb_pad;			/*	for future use						*/
	union
	{
		LOCK_KEY	rsb_lk;			/*	used to save lock from user	*/
		struct
		{
			unsigned char	rsb_xgrant_mode;	/*	granted mode of locked		*/
			unsigned char	rsb_xconvert_mode;	/*	effective convert mode 		*/
			short		rsb_xtype;		/*	first part of the key		*/
			long		rsb_xrkey;		/*	second part of the key		*/
			short		rsb_xrinstallation;	/*	installation key		*/
		}		rsb_actual;
	}		rsb_key;
};

# define	rsb_grant_mode		rsb_key.rsb_actual.rsb_xgrant_mode
# define	rsb_convert_mode	rsb_key.rsb_actual.rsb_xconvert_mode
# define	rsb_depth		rsb_key.rsb_actual.rsb_xdepth
# define	rsb_type		rsb_key.rsb_actual.rsb_xtype
# define	rsb_rkey		rsb_key.rsb_actual.rsb_xrkey
# define	rsb_rinstallation	rsb_key.rsb_actual.rsb_xrinstallation

/*
**	The User structure.
**		Contains information about processes that currently have the lock device open.
**		Used to store information that can't be put in the 'u' struct.
*/

typedef struct
{
	short		usr_minor_dev_number;	/* This will be the minor
						** device number of the driver
						** that the user is connected
						** to.
						** In the case of the major
						** device this number will be
						** 0.  This number will not
						** be unique for users con-
						** nected to the major device.
						** All opcodes implemented for
						** the major device should not
						** need this number to be unique
						** (ie. they should not need
						** context saved between calls).
						*/

	char		usr_state;		/* miscellaneous status info */

	char		usr_visited;		/* noded visited marked for
						** deadlock search
						*/

	char		usr_inconsistent_flag;	/* This is the flag twiddled by
						** the user by using
						** KN_R_CONSIST.  If this flag
						** is set when the user exits
						** then the database is
						** inconsistent.
						*/

	char		usr_db_inconsistent;	/* if this flag is set then the
						** the database is inconsistent
						*/

	char		usr_made_db_inconsistent; /* if this flag is set then
						  ** this user was the one that
						  ** made the db inconsistent.
						  */

	char		usr_not_used;		/* keep structure 16 byte
						** alligned.
						*/

	RSB		*usr_db_resource;	/* This is a pointer to the
						** database lock held by the
						** user.  This is the only case
						** where the lockdriver "knows"
						** about types of locks.
						*/

	LKB		*usr_wait;		/* lock that we are waiting
						** on
						*/

}	USR;

# define	USR_NULLSTATE	00
# define	USR_WAIT	01
# define	USR_VISITED	01
# define	USR_NOTVISITED	00

/* used for usr_made_db_inconsistent */
# define	USR_USR_INCONSISTENT	01

/* used for usr_db_inconsistent */
# define	USR_DB_INCONSISTENT	01

/*
**	The Lock Block.
**		Contains information about a given processes lock request against a resource.
*/

struct	_LKB
{
	QUEUE		lkb_next;			/*	next LBK of the same type	*/
	LKB		*lkb_parent;			/*	parent lock block		*/
	RSB		*lkb_rsb;			/*	associated resource block	*/
	USR		*lkb_usr;			/*	owning process			*/
	unsigned char	lkb_grant_mode;			/*	granted mode			*/
	unsigned char	lkb_request_mode;		/*	requested lock mode		*/
	unsigned char	lkb_state;			/*	current lock state		*/
	unsigned char	lkb_children;			/*	number of child locks		*/
};

# define	LKB_FREE		0
# define	LKB_GRANT		1
# define	LKB_CONVERT		2
# define	LKB_WAIT		3
# define	LKB_E_WAIT_ECONSIST	4	/* lock wait was aborted due to the db going inconsistent */
# define	LKB_E_CONVERT_ECONSIST	5	/* lock wait on a convert was aborted due to the db going
						** inconsistent.
						*/

/* The following macro is used because SV lock drivers set errno by
** setting u.u_error, while 4.2 lock drivers do it by returning a value.
*/
#define	BSD	1		/* Power6/32 is a bsd site	*/
# ifdef	BSD
# define 	SET_ERRNO(a)
# endif	BSD

# ifdef	WECO
# define	SET_ERRNO(a)	set_errno(a)
# endif	WECO

/* UPRINTF
**	On BSD systems uprintf prints to the user's terminal.  This feature
**	is not availiable to SV systems so we use printf instead.
*/
# ifdef	BSD
# define	UPRINTF		uprintf
# endif	BSD

# ifdef	WECO
# define	UPRINTF		printf
# endif WECO

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.