/* @(#)src/common/kernel/base/vx_param.h	3.37.19.5 06/07/99 18:52:08 -  */
/* #ident "@(#)vxfs:src/common/kernel/base/vx_param.h	3.37.19.5" */

/*
 * Copyright (c) 1998 VERITAS Software Corporation.  ALL RIGHTS RESERVED.
 * UNPUBLISHED -- RIGHTS RESERVED UNDER THE COPYRIGHT
 * LAWS OF THE UNITED STATES.  USE OF A COPYRIGHT NOTICE
 * IS PRECAUTIONARY ONLY AND DOES NOT IMPLY PUBLICATION
 * OR DISCLOSURE.
 *
 * THIS SOFTWARE CONTAINS CONFIDENTIAL INFORMATION AND
 * TRADE SECRETS OF VERITAS SOFTWARE.  USE, DISCLOSURE,
 * OR REPRODUCTION IS PROHIBITED WITHOUT THE PRIOR
 * EXPRESS WRITTEN PERMISSION OF VERITAS SOFTWARE.
 *
 * 		RESTRICTED RIGHTS LEGEND
 * USE, DUPLICATION, OR DISCLOSURE BY THE GOVERNMENT IS
 * SUBJECT TO RESTRICTIONS AS SET FORTH IN SUBPARAGRAPH
 * (C) (1) (ii) OF THE RIGHTS IN TECHNICAL DATA AND
 * COMPUTER SOFTWARE CLAUSE AT DFARS 252.227-7013.
 * 		VERITAS SOFTWARE
 * 1600 PLYMOUTH STREET, MOUNTAIN VIEW, CA 94043
 */

#ifndef _FS_VXFS_VX_PARAM_H
#define	_FS_VXFS_VX_PARAM_H

/*
 * Block size info
 */

#define	VX_MINBSIZE	1024	/* smallest block on any vxfs fs */
#define	VX_MINBOFFMASK	0x3ff	/* BOFFMASK for VX_MINBSIZE */
#define	VX_MINBSHIFT	10	/* log 2 (VX_MINBSIZE) */
#define	VX_MAXBSIZE	8192	/* largest block on any vxfs fs */
#define	VX_MAXBOFFMASK	0x1fff	/* BOFFMASK for VX_MAXBSIZE */
#define	VX_MAXBSHIFT	13	/* log 2 (VX_MAXBSIZE) */

#define	IADDREXTSIZE	8192	/* indirect address extent size */
#define	IADDREXTSHIFT	13	/* shift for indirect address extent size */
#define	NINDEXT		2048	/* num of addresses per indirect address ext */
#define	NINDEXTSHIFT	11	/* log 2 (NINDEXT) */

#define	VX_MAXBUFSIZE	65536	/* largest buffer we want to get */

/*
 * Ilist buffer size info
 */

#define VX_ILIST_BSIZE	2048	/* ilist buffer size maximum */

/*
 * The VX_ATOMIC_IOSZ is the unit of I/O which is guaranteed atomic.
 * This should be the smallest sector size of any device a file
 * system might reside on.  The VX_ATOMIC_IOSZ value is used to
 * break up log entries so no entry crosses an atomic I/O boundary.
 */

#define	VX_ATOMIC_IOSZ		512
#define	VX_ATOMIC_IOSHIFT	9

/*
 * The VX_MAXISIZE is the maximum size inode we support.  It must
 * be no larger than VX_ATOMIC_IOSZ.  Also, this must be small enough
 * so the size of a vx_imtran is less than VX_TRANPGSIZE (with space
 * for two inodes included).
 */

#define	VX_MAXISIZE		512

/*
 * Parameters governing extent reorg behavior.
 */

#define	VX_REORG_MAXSTRUCT	32	/* max inodes in structural reorg */
#define	VX_REORG_NEXTENTS	128	/* max extents entered before commit */

/*
 * Parameters governing extent allocation and extent maps.
 */

#define	VX_DEFEXT	2048	/* max extent size for regular files */
#define	VX_MAPSZ	512	/* bytes per map sector */
#define	VX_MAPSHFT	9	/* log2(VX_MAPSZ) */
#define	VX_MAPBLKS	2048	/* blocks mapped by one map sector (bits / 2) */
#define	VX_MAPBLKMASK	0x7ff	/* mask for VX_MAPBLKS */
#define	VX_MAPBLKSHFT	11	/* shift for VX_MAPBLKS */
#define	VX_MAPBYTOBL	2	/* shift for bytes per sector to blocks */

/*
 * Version 3 AU sizes
 */

#define	VX_AUBLOCKS	32768		   /* size of AU in version 3 fs */
#define	VX_AUSHIFT	15		   /* log of VX_AUBLOCKS */
#define	VX_AUOFFMASK	(VX_AUBLOCKS - 1)  /* mask for VX_AUBLOCKS */

/*
 * Convert au state map entry from bits to bytes
 */

#define	VX_SMAPSIZE	4	/* there are 4 2-bit entries in a byte */
#define	VX_SMAPMASK	0x3	/* mask for VX_SMAPSIZE */
#define	VX_SMAPSHIFT	2	/* shift for VX_SMAPSIZE */

/*
 * The Version 1 on-disk inode size.
 */

#define	OLDINOSIZE	256		/* version 1 inode size */
#define	OLDINODESHIFT	8		/* log base 2 of OLDINOSIZE */

/*
 * The root and lost+found inode numbers.
 */

#define	VX_ROOTINO		((ino_t)2)	/* i number of all roots */
#define	VX_LOSTFOUNDINO		(VX_ROOTINO + 1)
#define	VX_VOLFIRSTINODE	VX_LOSTFOUNDINO

/*
 * vxfs specific errno values
 */

#define	VX_ERETRY	0xf001	/* retry (usually because of memory) */
#define	VX_ENOINODE	0xf002	/* out of inodes */
#define	VX_ENOENT	0xf003	/* ENOENT ret from vx_dirscan or vx_attr_rm */
#define	VX_EAGMOUNT	0xf004	/* aggregate mount was successful */
#define	VX_EMAXTRUNC	0xf005	/* truncation must be retried */
#define	VX_EMAXALLOC	0xf006	/* too many allocations in transaction */
#define	VX_ERWLOCK	0xf007	/* need a RWLOCK in transaction */
#define	VX_EMAXHOLD	0xf008	/* too many held inodes in the transaction */
#define	VX_EQUOTRETRY	0xf009	/* block allocation needed in quota file */
#define	VX_ETRANRES	0xf00a	/* transaction reservation commit retry */
#define	VX_EBMAPCHANGE	0xf00b	/* bmap must be retried */
#define VX_ENOOVERLAY	0xf00c	/* push inode is not overlaid for <off, len> */

/*
 * Various time delays.  The caching policies try to use time as an aid
 * to scalability.  For example, the VX_ICLEAN_TIMELAG is a measure of
 * how long in time we want the inode freelist to be.  If the inodes are
 * being reused in less than VX_ICLEAN_TIMELAG seconds, then we want to
 * increase the size of the inode table.  If the current workload is
 * heavy, the number of inodes used in VX_ICLEAN_TIMELAG seconds may be
 * very large.  If the workload is light, then the number of inodes used
 * will be smaller.
 *
 * VX_SYNC_TIME is the amount of time it takes the flushing threads to
 * sync out the inode table.
 *
 * VX_ICLEAN_TIMELAG is the minimum length of time we want inodes on
 * the freelist before reclaim.  If we are trying to reclaim inodes in
 * less time, then more inodes are allocated.
 *
 * VX_IFREE_TIMELAG is the maximum length of time we want inodes on
 * the freelist.  If inodes are staying on the freelist more than this,
 * then the inode table size is reduced.
 *
 * VX_IINACTIVE_TIMELAG is the length of time we want inodes to sit on
 * the inactive list.
 *
 * VX_IDELXWRI_TIMELAG is the maximum length of time we want delayed
 * extending write files to sit idle before flushing them.
 *
 * VX_DELAYLOG_TIMELAG is the maximum length of time we will let a
 * delayed transaction sit in a log buffer without the log being flushed.
 *
 * VX_MESSAGE_TIMELAG is the length of time between printing nospace
 * or noinode messages.
 *
 * VX_TUNE_TIMELAG is amount of time between tuning intervals
 *
 * VX_FREE_PER_SCAN is the maximum no of inodes to be freed in one scan.
 *
 * VX_RECLAIM_TIMELAG time after which disk space is recovered from an
 * idle inode with VX_IESHORTEN set.
 *
 * VX_THR_DECR_TIMELAG is the amount of quiscent time (in seconds) after which
 * the number of worker threads is decremented.
 *
 * VX_BCFREE_TIMELAG, if non-zero, is the maximum length of time we want
 * idle buffers in the buffer cache.  Buffers older than this value will
 * be freed (Solaris only).
 *
 * VX_BCRECYCLE_TIMELAG is the amount of time buffers can be idle before
 * they are eligible to be recycled to a new identity.
 *
 * VX_FANCYRA_TIMELAG is the amount of time we allow between reads from an inode
 * before turning off fancy read ahead for that inode.
 */

#define	VX_SYNC_TIME			60
#define	VX_ICLEAN_TIMELAG		180
#define	VX_IFREE_TIMELAG		600
#define	VX_IINACTIVE_TIMELAG		10
#define	VX_IDELXWRI_TIMELAG		15
#define	VX_DELAYLOG_TIMELAG		3
#define	VX_MESSAGE_TIMELAG		5
#define	VX_TUNE_TIMELAG			60
#define VX_FREE_PER_SCAN		50
#define	VX_RECLAIM_TIMELAG		600
#define VX_THR_DECR_TIMELAG		300
#define VX_BCFREE_TIMELAG		0
#define	VX_BCRECYCLE_TIMELAG		3600
#define VX_FANCYRA_TIMELAG		60

/*
 * The number of threads we kick off for an individual task.
 */

#define	VX_THREAD_START			15

/*
 * When the total number of transactions gets too large, we start flushing
 * file systems with more than VX_FLUSH_TRAN transactions outstanding.
 */

#define	VX_FLUSH_TRAN		300

/*
 * When the number of mlinks on the fset's done mlink queue exceeds this
 * value, see if any of them can be marked complete.  This is checked in
 * the done routine of the VX_CUTTRAN subfunction.
 */

#define	VX_FSET_MLINKS		50

/*
 * To balance file system usage, when the file system free space falls
 * below VX_MINFREE we will stop allocating very large extents.  If the
 * file system is very large, the maximum value (in kilobytes) for
 * fs_minfree is VX_MAX_MINFREE.
 *
 * When an allocation unit falls below VX_AUFREE[i] blocks free we will start
 * allocating inodes into other allocation units with VX_AUFREE[i+1] blocks.
 */

#define	VX_MINFREE	10	/* minimum pct of fs that we want free */
#define	VX_MAX_MINFREE	(512 * 1024)	/* max kbytes for fs_minfree */
#define	VX_AUFREE1	5
#define	VX_AUFREE2	10
#define	VX_AUFREE3	20
#define	VX_AUFREE4	30

/*
 * This controls the maximum number of inodes that may cluster as a
 * side inode update in vx_iupdat().
 */

#define	VX_MAXICLUSTER	32

/*
 * This value is used to increment the CUT entry version number.
 */

#define	VX_CUTINCR	20000

/*
 * Default values of I/O parameters.  See the vx_fs_ioinit() routine
 * for comments describing the use of each value.
 */

#define	VX_DEF_MAXIO		(64 * 1024)
#define	VX_DEF_INITRA		(16 * 1024)
#define	VX_DEF_DIRECTSZ		(256 * 1024)
#define	VX_DEF_BMAPCLUSTER	64
#define	VX_DEF_IOTRACK		(64 * 1024)
#define	VX_DEF_IOCYLINDER	(4 * 64 * 1024)
#define	VX_DEF_MAXTRANSFER	VX_MACH_DEF_MAXTRANSFER
#define	VX_MIN_MAXIOLOCK	(1024 * 1024)
#define	VX_MAX_MAXRA		(1024 * 1024)
#define	VX_DEF_STRATCLUSTER	8
#define	VX_DEF_BIGFILESIZE	(8 * 1024 * 1024)
#define	VX_FAST_READ_LIMIT	(128 * 1024)

/*
 * When getpage is called, this is the maximum number of pages it will
 * obtain in one call.
 */

#define	VX_MAXGETPAGES		8

/*
 * Maximum length of buffer chains built by flushing routines
 * (and maximum buffers examined per iteration).
 */

#define	VX_MAX_BUFCHAIN		128

/*
 * vxfs message structure
 */

struct vx_msg {
	vx_u32_t	msg_type;	/* message priority */
	caddr_t		msg_string;	/* message text */
};

/*
 * snapshot bitmap buffer parameters
 */

#define	VX_SNAPBITBUF_SHIFT	(13)
#define	VX_SNAPBITBUF_SZ	(1 << VX_SNAPBITBUF_SHIFT)
#define	VX_SNAPBITSPBUF_SHIFT	(VX_SNAPBITBUF_SHIFT + 3)
#define	VX_SNAPBITSPBUF		(1 << VX_SNAPBITSPBUF_SHIFT)

/*
 * vxfs message codes
 */

#define	VX_MSG_NOMSG		0
#define	VX_MSG_NOSPACE		1
#define	VX_MSG_WROFS		2
#define	VX_MSG_BADEMAP		3
#define	VX_MSG_BADIMAP		4
#define	VX_MSG_BADIEMAP		5
#define	VX_MSG_BADSUMMARY	6
#define	VX_MSG_BADISUMMARY	7
#define	VX_MSG_DIRERR		8
#define	VX_MSG_IDIRERR		9
#define	VX_MSG_INOTFREE		10
#define	VX_MSG_NOINODES		11
#define	VX_MSG_BADINUM		12
#define	VX_MSG_BADIEXT		13
#define	VX_MSG_ENFILE		14
#define	VX_MSG_IBADFAIL		15
#define	VX_MSG_IREADERR		16
#define	VX_MSG_MARKIBAD		17
#define	VX_MSG_LOGOVERFLOW	19
#define	VX_MSG_LOGBAD		20
#define	VX_MSG_MOUNTSETUP	21
#define	VX_MSG_ROOTREMOUNT	22
#define	VX_MSG_UNMOUNTROOT	23
#define	VX_MSG_CUTFAIL		24
#define	VX_MSG_BADSUPER		25
#define	VX_MSG_SNAPREAD		26
#define	VX_MSG_SNAPWRITE	27
#define	VX_MSG_SNAPNOSPACE	28
#define	VX_MSG_SNAPMAPWERR	29
#define	VX_MSG_SNAPMAPRERR	30
#define	VX_MSG_DISABLE		31
#define	VX_MSG_SNAPDISABLE	32
#define	VX_MSG_BADBLOCK		33
#define	VX_MSG_RESETLOG		34
#define	VX_MSG_INACTIVE		35
#define	VX_MSG_BADLCT		36
#define	VX_MSG_METAIOERR	37
#define	VX_MSG_DATAIOERR	38
#define	VX_MSG_BADSUPER2	39
#define	VX_MSG_BADDQ		40
#define	VX_MSG_NOQUOTA		41
#define	VX_MSG_BHARDQUOTA	42
#define	VX_MSG_BSOFTQUOTA	43
#define	VX_MSG_BSOFTOVER	44
#define	VX_MSG_IHARDQUOTA	45
#define	VX_MSG_ISOFTQUOTA	46
#define	VX_MSG_ISOFTOVER	47
#define	VX_MSG_EQUOTAREAD	48
#define	VX_MSG_EQUOTAWRITE	49
#define	VX_MSG_LDLOG_WRITE	50
#define	VX_MSG_LDLOG_START	51
#define	VX_MSG_LDLOG_STOP	52
#define	VX_MSG_LDLOG_SUSPEND	53
#define	VX_MSG_LDLOG_RESUME	54
#define	VX_MSG_FORCEUNMOUNT	55
#define	VX_MSG_BADSMAP		56
#define	VX_MSG_BADESUM		57
#define	VX_MSG_BADISUM		58
#define	VX_MSG_SNAPBITMAPWERR	59
#define	VX_MSG_SNAPBITMAPRERR	60
#define	VX_MSG_RESIZE_REMOUNT	61
#define	VX_MSG_CREATOP_INVAL	62
#define	VX_MSG_BADFSET		63
#define	VX_MSG_INOVERSION	64
#define	VX_MSG_MODNOTREGISTERED	65
#define	VX_MSG_DMAPI_MOUNT	66
#define	VX_MSG_DMAPI_MOUNT_FAIL	67
#define	VX_MSG_NINODE_NCSIZE	68
#define	VX_MSG_NINODE_BUFHWM	69
#define	VX_MSG_CLONE_REMOVED	70
#define	VX_MSG_DATAIO_CLEARED	71

/*
 * Maximum message number index.  Minimum is always zero.
 * Set to last VX_MSG_* from above!
 */

#define VX_MSG_MAX		VX_MSG_DATAIO_CLEARED

/*
 * Maximum number of iovectors handled by the logged write code
 */

#define	VX_MAXIOVEC		4

/*
 * VM/FS defines
 */

#define	VX_MAX_DIRECT_IOSZ	(65535 * DEV_BSIZE)
#define VX_MIN_MAXDISKQ		(1024 * 1024)

/*
 * When we're removing a clone, we call vx_emptyfset() to truncate all
 * the inodes and convert them to pass through inodes. For every
 * VX_NITRUNC inodes that we truncate, we write the inode number in
 * the fileset header file. If we crash, when we perform extended op
 * op completion on the next mount, we can start off from where we left off.
 *
 * Similarly, when we convert a data-full clone to a no-data clone,
 * we iterate through the ilist, pushing or freeing extents and converting
 * what was there to a hole to represent the changed blocks. For each
 * VX_NCONVNODATA inodes processed, we update the values of fsh_eopdata
 * and fsh_attr_eopdata with the appropriate inode numbers.
 */

#define VX_NITRUNC	256
#define VX_NCONVNODATA	256

#endif	/* _FS_VXFS_VX_PARAM_H */
