xref: /illumos-gate/usr/src/uts/common/sys/fs/ufs_log.h (revision e7da395a)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
54f3979a5SWolfgang Schremser  * Common Development and Distribution License (the "License").
64f3979a5SWolfgang Schremser  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22*e7da395aSOwen Roberts  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #ifndef _SYS_FS_UFS_LOG_H
277c478bd9Sstevel@tonic-gate #define	_SYS_FS_UFS_LOG_H
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #include <sys/buf.h>
307c478bd9Sstevel@tonic-gate #include <sys/fs/ufs_trans.h>
317c478bd9Sstevel@tonic-gate #include <sys/fs/ufs_filio.h>
327c478bd9Sstevel@tonic-gate #include <sys/fs/ufs_inode.h>
337c478bd9Sstevel@tonic-gate 
347c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
357c478bd9Sstevel@tonic-gate extern "C" {
367c478bd9Sstevel@tonic-gate #endif
377c478bd9Sstevel@tonic-gate 
387c478bd9Sstevel@tonic-gate typedef struct lufs_save {
397c478bd9Sstevel@tonic-gate 	buf_t		*sv_bp;
407c478bd9Sstevel@tonic-gate 	size_t		sv_nb_left;
417c478bd9Sstevel@tonic-gate 	int		sv_error;
427c478bd9Sstevel@tonic-gate } lufs_save_t;
437c478bd9Sstevel@tonic-gate 
447c478bd9Sstevel@tonic-gate typedef struct lufs_buf {
457c478bd9Sstevel@tonic-gate 	buf_t		lb_buf;
467c478bd9Sstevel@tonic-gate 	void		*lb_ptr;
477c478bd9Sstevel@tonic-gate } lufs_buf_t;
487c478bd9Sstevel@tonic-gate 
497c478bd9Sstevel@tonic-gate /*
507c478bd9Sstevel@tonic-gate  * Log space is stored as extents
517c478bd9Sstevel@tonic-gate  */
527c478bd9Sstevel@tonic-gate #define	LUFS_EXTENTS	(UINT32_C(0))
537c478bd9Sstevel@tonic-gate #define	LS_SECTORS	2
547c478bd9Sstevel@tonic-gate 
557c478bd9Sstevel@tonic-gate typedef struct extent {
567c478bd9Sstevel@tonic-gate 	uint32_t	lbno;	/* Logical block # within the space */
577c478bd9Sstevel@tonic-gate 	uint32_t	pbno;	/* Physical block number of extent. */
587c478bd9Sstevel@tonic-gate 				/* in disk blocks for non-MTB ufs */
597c478bd9Sstevel@tonic-gate 				/* in frags for MTB ufs */
607c478bd9Sstevel@tonic-gate 	uint32_t	nbno;	/* # blocks in this extent */
617c478bd9Sstevel@tonic-gate } extent_t;
627c478bd9Sstevel@tonic-gate 
637c478bd9Sstevel@tonic-gate typedef struct ic_extent {
647c478bd9Sstevel@tonic-gate 	uint32_t	ic_lbno;	/* Logical block # within the space */
657c478bd9Sstevel@tonic-gate 	uint32_t	ic_nbno;	/* # blocks in this extent */
667c478bd9Sstevel@tonic-gate 	daddr_t		ic_pbno;	/* Physical block number of extent. */
677c478bd9Sstevel@tonic-gate 					/* (always in disk blocks) 	*/
687c478bd9Sstevel@tonic-gate } ic_extent_t;
697c478bd9Sstevel@tonic-gate 
707c478bd9Sstevel@tonic-gate typedef struct extent_block {
717c478bd9Sstevel@tonic-gate 	uint32_t	type;		/* Set to LUFS_EXTENTS to identify */
727c478bd9Sstevel@tonic-gate 					/*   structure on disk. */
737c478bd9Sstevel@tonic-gate 	int32_t		chksum;		/* Checksum over entire block. */
747c478bd9Sstevel@tonic-gate 	uint32_t	nextents;	/* Size of extents array. */
757c478bd9Sstevel@tonic-gate 	uint32_t	nbytes;		/* # bytes mapped by extent_block. */
767c478bd9Sstevel@tonic-gate 	uint32_t	nextbno;	/* blkno of next extent_block. */
777c478bd9Sstevel@tonic-gate 	extent_t	extents[1];
787c478bd9Sstevel@tonic-gate } extent_block_t;
797c478bd9Sstevel@tonic-gate 
807c478bd9Sstevel@tonic-gate typedef struct ic_extent_block {
817c478bd9Sstevel@tonic-gate 	uint32_t	ic_nextents;	/* Size of extents array. */
827c478bd9Sstevel@tonic-gate 	uint32_t	ic_nbytes;	/* # bytes mapped by extent_block. */
837c478bd9Sstevel@tonic-gate 	uint32_t	ic_nextbno;	/* blkno of next extent_block. */
847c478bd9Sstevel@tonic-gate 	ic_extent_t	ic_extents[1];
857c478bd9Sstevel@tonic-gate } ic_extent_block_t;
867c478bd9Sstevel@tonic-gate 
877c478bd9Sstevel@tonic-gate /*
887c478bd9Sstevel@tonic-gate  * Don't size the incore buffers too small or too large
897c478bd9Sstevel@tonic-gate  */
907c478bd9Sstevel@tonic-gate #define	LDL_MINTRANSFER		(UINT32_C(32768))	/* 32 k */
917c478bd9Sstevel@tonic-gate #define	LDL_MAXTRANSFER		(UINT32_C(1048576))	/* 1 M */
927c478bd9Sstevel@tonic-gate 
937c478bd9Sstevel@tonic-gate /*
947c478bd9Sstevel@tonic-gate  * LDL_DIVISOR (ldl_divisor) is the number to calculate the log size
957c478bd9Sstevel@tonic-gate  * from the file system size according to the calculation in lufs_enable()
967c478bd9Sstevel@tonic-gate  */
977c478bd9Sstevel@tonic-gate #define	LDL_DIVISOR		1024 /* 1024 gives 1MB per 1GB */
987c478bd9Sstevel@tonic-gate 
99*e7da395aSOwen Roberts /*
100*e7da395aSOwen Roberts  * This gives the maximum size of log for which the 1MB per 1GB rule
101*e7da395aSOwen Roberts  * applies. The size of the log will only be greater than this based
102*e7da395aSOwen Roberts  * on the cylinder group space requirements.
103*e7da395aSOwen Roberts  */
104*e7da395aSOwen Roberts #define	LDL_SOFTLOGCAP		(256 * 1024 * 1024)
105*e7da395aSOwen Roberts 
1067c478bd9Sstevel@tonic-gate /*
1077c478bd9Sstevel@tonic-gate  * But set reasonable min/max units
1087c478bd9Sstevel@tonic-gate  */
1097c478bd9Sstevel@tonic-gate #define	LDL_MINLOGSIZE		(1024 * 1024)
110*e7da395aSOwen Roberts #define	LDL_MAXLOGSIZE		(512 * 1024 * 1024)
111*e7da395aSOwen Roberts 
112*e7da395aSOwen Roberts /*
113*e7da395aSOwen Roberts  * Log space requirement per cylinder group. This needs to accommodate a
114*e7da395aSOwen Roberts  * cg delta (inc. header) and have a factor to cover other deltas involved
115*e7da395aSOwen Roberts  * in a single transaction which could touch all cyl groups in a file system.
116*e7da395aSOwen Roberts  */
117*e7da395aSOwen Roberts #define	LDL_CGSIZEREQ(fs) \
118*e7da395aSOwen Roberts 	((fs)->fs_cgsize + ((fs)->fs_cgsize >> 1))
1197c478bd9Sstevel@tonic-gate 
1207c478bd9Sstevel@tonic-gate #define	LDL_MINBUFSIZE		(32 * 1024)
1217c478bd9Sstevel@tonic-gate #define	LDL_USABLE_BSIZE	(DEV_BSIZE - sizeof (sect_trailer_t))
1227c478bd9Sstevel@tonic-gate #define	NB_LEFT_IN_SECTOR(off) 	(LDL_USABLE_BSIZE - ((off) - dbtob(btodb(off))))
1237c478bd9Sstevel@tonic-gate 
1247c478bd9Sstevel@tonic-gate typedef struct cirbuf {
1257c478bd9Sstevel@tonic-gate 	buf_t		*cb_bp;		/* buf's with space in circular buf */
1267c478bd9Sstevel@tonic-gate 	buf_t		*cb_dirty;	/* filling this buffer for log write */
1277c478bd9Sstevel@tonic-gate 	buf_t		*cb_free;	/* free bufs list */
1287c478bd9Sstevel@tonic-gate 	caddr_t		cb_va;		/* address of circular buffer */
1297c478bd9Sstevel@tonic-gate 	size_t		cb_nb;		/* size of circular buffer */
1307c478bd9Sstevel@tonic-gate 	krwlock_t	cb_rwlock;	/* r/w lock to protect list mgmt. */
1317c478bd9Sstevel@tonic-gate } cirbuf_t;
1327c478bd9Sstevel@tonic-gate 
1337c478bd9Sstevel@tonic-gate #define	LUFS_VERSION		(UINT32_C(1))	/* Version 1 */
1347c478bd9Sstevel@tonic-gate #define	LUFS_VERSION_LATEST	LUFS_VERSION
1357c478bd9Sstevel@tonic-gate 
1367c478bd9Sstevel@tonic-gate /*
1377c478bd9Sstevel@tonic-gate  * The old Disksuite unit structure has been split into two parts -- the
1387c478bd9Sstevel@tonic-gate  * incore part which is created at run time and the ondisk structure.  To
1397c478bd9Sstevel@tonic-gate  * minimize code changes, the incore structure retains the old name,
1407c478bd9Sstevel@tonic-gate  * ml_unit_t and the ondisk structure is called ml_odunit_t.  The ondisk
1417c478bd9Sstevel@tonic-gate  * structure is stored at the beginning of the log.
1427c478bd9Sstevel@tonic-gate  *
1437c478bd9Sstevel@tonic-gate  * This structure must fit into a sector (512b)
1447c478bd9Sstevel@tonic-gate  *
1457c478bd9Sstevel@tonic-gate  */
1467c478bd9Sstevel@tonic-gate typedef struct ml_odunit {
1477c478bd9Sstevel@tonic-gate 	uint32_t	od_version;	/* version number */
1487c478bd9Sstevel@tonic-gate 	uint32_t	od_badlog;	/* is the log okay? */
1497c478bd9Sstevel@tonic-gate 	uint32_t	od_unused1;
1507c478bd9Sstevel@tonic-gate 
1517c478bd9Sstevel@tonic-gate 	/*
1527c478bd9Sstevel@tonic-gate 	 * Important constants
1537c478bd9Sstevel@tonic-gate 	 */
1547c478bd9Sstevel@tonic-gate 	uint32_t	od_maxtransfer;	/* max transfer in bytes */
1557c478bd9Sstevel@tonic-gate 	uint32_t	od_devbsize;	/* device bsize */
1567c478bd9Sstevel@tonic-gate 	int32_t		od_bol_lof;	/* byte offset to begin of log */
1577c478bd9Sstevel@tonic-gate 	int32_t		od_eol_lof;	/* byte offset to end of log */
1587c478bd9Sstevel@tonic-gate 
1597c478bd9Sstevel@tonic-gate 	/*
1607c478bd9Sstevel@tonic-gate 	 * The disk space is split into state and circular log
1617c478bd9Sstevel@tonic-gate 	 */
1627c478bd9Sstevel@tonic-gate 	uint32_t	od_requestsize;	/* size requested by user */
1637c478bd9Sstevel@tonic-gate 	uint32_t	od_statesize;	/* size of state area in bytes */
1647c478bd9Sstevel@tonic-gate 	uint32_t	od_logsize;	/* size of log area in bytes */
1657c478bd9Sstevel@tonic-gate 	int32_t		od_statebno;	/* first block of state area */
1667c478bd9Sstevel@tonic-gate 	int32_t		od_unused2;
1677c478bd9Sstevel@tonic-gate 
1687c478bd9Sstevel@tonic-gate 	/*
1697c478bd9Sstevel@tonic-gate 	 * Head and tail of log
1707c478bd9Sstevel@tonic-gate 	 */
1717c478bd9Sstevel@tonic-gate 	int32_t		od_head_lof;	/* byte offset of head */
1727c478bd9Sstevel@tonic-gate 	uint32_t	od_head_ident;	/* head sector id # */
1737c478bd9Sstevel@tonic-gate 	int32_t		od_tail_lof;	/* byte offset of tail */
1747c478bd9Sstevel@tonic-gate 	uint32_t	od_tail_ident;	/* tail sector id # */
1757c478bd9Sstevel@tonic-gate 	uint32_t	od_chksum;	/* checksum to verify ondisk contents */
1767c478bd9Sstevel@tonic-gate 
1777c478bd9Sstevel@tonic-gate 	/*
1787c478bd9Sstevel@tonic-gate 	 * Used for error recovery
1797c478bd9Sstevel@tonic-gate 	 */
1807c478bd9Sstevel@tonic-gate 	uint32_t	od_head_tid;	/* used for logscan; set at sethead */
1817c478bd9Sstevel@tonic-gate 
1827c478bd9Sstevel@tonic-gate 	/*
1837c478bd9Sstevel@tonic-gate 	 * Debug bits
1847c478bd9Sstevel@tonic-gate 	 */
1857c478bd9Sstevel@tonic-gate 	int32_t		od_debug;
1867c478bd9Sstevel@tonic-gate 
1877c478bd9Sstevel@tonic-gate 	/*
1887c478bd9Sstevel@tonic-gate 	 * Misc
1897c478bd9Sstevel@tonic-gate 	 */
1907c478bd9Sstevel@tonic-gate 	struct timeval	od_timestamp;	/* time of last state change */
1917c478bd9Sstevel@tonic-gate } ml_odunit_t;
1927c478bd9Sstevel@tonic-gate 
1937c478bd9Sstevel@tonic-gate typedef struct ml_unit {
1947c478bd9Sstevel@tonic-gate 	struct ml_unit	*un_next;	/* next incore log */
1957c478bd9Sstevel@tonic-gate 	int		un_flags;	/* Incore state */
1967c478bd9Sstevel@tonic-gate 	buf_t		*un_bp;		/* contains memory for un_ondisk */
1977c478bd9Sstevel@tonic-gate 	struct ufsvfs	*un_ufsvfs;	/* backpointer to ufsvfs */
1987c478bd9Sstevel@tonic-gate 	dev_t		un_dev;		/* for convenience */
1997c478bd9Sstevel@tonic-gate 	ic_extent_block_t *un_ebp;	/* block of extents */
2007c478bd9Sstevel@tonic-gate 	size_t		un_nbeb;	/* # bytes used by *un_ebp */
2017c478bd9Sstevel@tonic-gate 	struct mt_map	*un_deltamap;	/* deltamap */
2027c478bd9Sstevel@tonic-gate 	struct mt_map	*un_logmap;	/* logmap includes moby trans stuff */
2037c478bd9Sstevel@tonic-gate 	struct mt_map	*un_matamap;	/* optional - matamap */
2047c478bd9Sstevel@tonic-gate 
2057c478bd9Sstevel@tonic-gate 	/*
2067c478bd9Sstevel@tonic-gate 	 * Used for managing transactions
2077c478bd9Sstevel@tonic-gate 	 */
2087c478bd9Sstevel@tonic-gate 	uint32_t	un_maxresv;	/* maximum reservable space */
2097c478bd9Sstevel@tonic-gate 	uint32_t	un_resv;	/* reserved byte count for this trans */
2107c478bd9Sstevel@tonic-gate 	uint32_t	un_resv_wantin;	/* reserved byte count for next trans */
2117c478bd9Sstevel@tonic-gate 
2127c478bd9Sstevel@tonic-gate 	/*
2137c478bd9Sstevel@tonic-gate 	 * Used during logscan
2147c478bd9Sstevel@tonic-gate 	 */
2157c478bd9Sstevel@tonic-gate 	uint32_t	un_tid;
2167c478bd9Sstevel@tonic-gate 
2177c478bd9Sstevel@tonic-gate 	/*
2187c478bd9Sstevel@tonic-gate 	 * Read/Write Buffers
2197c478bd9Sstevel@tonic-gate 	 */
2207c478bd9Sstevel@tonic-gate 	cirbuf_t	un_rdbuf;	/* read buffer space */
2217c478bd9Sstevel@tonic-gate 	cirbuf_t	un_wrbuf;	/* write buffer space */
2227c478bd9Sstevel@tonic-gate 
2237c478bd9Sstevel@tonic-gate 	/*
2247c478bd9Sstevel@tonic-gate 	 * Ondisk state
2257c478bd9Sstevel@tonic-gate 	 */
2267c478bd9Sstevel@tonic-gate 	ml_odunit_t	un_ondisk;	/* ondisk log information */
2277c478bd9Sstevel@tonic-gate 
2287c478bd9Sstevel@tonic-gate 	/*
2297c478bd9Sstevel@tonic-gate 	 * locks
2307c478bd9Sstevel@tonic-gate 	 */
2317c478bd9Sstevel@tonic-gate 	kmutex_t	un_log_mutex;	/* allows one log write at a time */
2327c478bd9Sstevel@tonic-gate 	kmutex_t	un_state_mutex;	/* only 1 state update at a time */
2337c478bd9Sstevel@tonic-gate } ml_unit_t;
2347c478bd9Sstevel@tonic-gate 
2357c478bd9Sstevel@tonic-gate /*
2367c478bd9Sstevel@tonic-gate  * Macros to allow access to the ondisk elements via the ml_unit_t incore
2377c478bd9Sstevel@tonic-gate  * structure.
2387c478bd9Sstevel@tonic-gate  */
2397c478bd9Sstevel@tonic-gate 
2407c478bd9Sstevel@tonic-gate #define	un_version	un_ondisk.od_version
2417c478bd9Sstevel@tonic-gate #define	un_badlog	un_ondisk.od_badlog
2427c478bd9Sstevel@tonic-gate #define	un_maxtransfer	un_ondisk.od_maxtransfer
2437c478bd9Sstevel@tonic-gate #define	un_devbsize	un_ondisk.od_devbsize
2447c478bd9Sstevel@tonic-gate #define	un_bol_lof	un_ondisk.od_bol_lof
2457c478bd9Sstevel@tonic-gate #define	un_eol_lof	un_ondisk.od_eol_lof
2467c478bd9Sstevel@tonic-gate #define	un_statesize	un_ondisk.od_statesize
2477c478bd9Sstevel@tonic-gate #define	un_logsize	un_ondisk.od_logsize
2487c478bd9Sstevel@tonic-gate #define	un_statebno	un_ondisk.od_statebno
2497c478bd9Sstevel@tonic-gate #define	un_requestsize	un_ondisk.od_requestsize
2507c478bd9Sstevel@tonic-gate #define	un_head_lof	un_ondisk.od_head_lof
2517c478bd9Sstevel@tonic-gate #define	un_head_ident	un_ondisk.od_head_ident
2527c478bd9Sstevel@tonic-gate #define	un_tail_lof	un_ondisk.od_tail_lof
2537c478bd9Sstevel@tonic-gate #define	un_tail_ident	un_ondisk.od_tail_ident
2547c478bd9Sstevel@tonic-gate #define	un_chksum	un_ondisk.od_chksum
2557c478bd9Sstevel@tonic-gate #define	un_head_tid	un_ondisk.od_head_tid
2567c478bd9Sstevel@tonic-gate #define	un_debug	un_ondisk.od_debug
2577c478bd9Sstevel@tonic-gate #define	un_timestamp	un_ondisk.od_timestamp
2587c478bd9Sstevel@tonic-gate 
2597c478bd9Sstevel@tonic-gate /*
2607c478bd9Sstevel@tonic-gate  *	un_flags
2617c478bd9Sstevel@tonic-gate  */
2627c478bd9Sstevel@tonic-gate #define	LDL_SCAN	0x0001	/* log scan in progress */
2637c478bd9Sstevel@tonic-gate #define	LDL_ERROR	0x0002	/* in error state */
2647c478bd9Sstevel@tonic-gate #define	LDL_NOROLL	0x0004  /* Log Not Yet Rollable */
2657c478bd9Sstevel@tonic-gate 
2667c478bd9Sstevel@tonic-gate typedef struct sect_trailer {
2677c478bd9Sstevel@tonic-gate 	uint32_t	st_tid;		/* transaction id */
2687c478bd9Sstevel@tonic-gate 	uint32_t	st_ident;	/* unique sector id */
2697c478bd9Sstevel@tonic-gate } sect_trailer_t;
2707c478bd9Sstevel@tonic-gate 
2717c478bd9Sstevel@tonic-gate /*
2727c478bd9Sstevel@tonic-gate  * map block
2737c478bd9Sstevel@tonic-gate  */
2747c478bd9Sstevel@tonic-gate #define	MAPBLOCKSIZE	(8192)
2757c478bd9Sstevel@tonic-gate #define	MAPBLOCKSHIFT	(13)
2767c478bd9Sstevel@tonic-gate #define	MAPBLOCKOFF	(MAPBLOCKSIZE-1)
2777c478bd9Sstevel@tonic-gate #define	MAPBLOCKMASK	(~MAPBLOCKOFF)
2787c478bd9Sstevel@tonic-gate #define	DEV_BMASK	(DEV_BSIZE - 1)
2797c478bd9Sstevel@tonic-gate 
2807c478bd9Sstevel@tonic-gate /*
2817c478bd9Sstevel@tonic-gate  * cached roll buffer
2827c478bd9Sstevel@tonic-gate  */
2837c478bd9Sstevel@tonic-gate typedef struct crb {
2847c478bd9Sstevel@tonic-gate 	int64_t		c_mof;		/* master file offset of buffer */
2857c478bd9Sstevel@tonic-gate 	caddr_t		c_buf;		/* pointer to cached roll buffer */
2867c478bd9Sstevel@tonic-gate 	uint32_t	c_nb;		/* size of buffer */
2877c478bd9Sstevel@tonic-gate 	ushort_t	c_refcnt;	/* reference count on crb */
2887c478bd9Sstevel@tonic-gate 	uchar_t		c_invalid;	/* crb should not be used */
2897c478bd9Sstevel@tonic-gate } crb_t;
2907c478bd9Sstevel@tonic-gate 
2917c478bd9Sstevel@tonic-gate #define	CRB_END ((crb_t *)1) /* must be non zero */
2927c478bd9Sstevel@tonic-gate 
2937c478bd9Sstevel@tonic-gate /*
2947c478bd9Sstevel@tonic-gate  * delta header
2957c478bd9Sstevel@tonic-gate  */
2967c478bd9Sstevel@tonic-gate struct delta {
2977c478bd9Sstevel@tonic-gate 	int64_t		d_mof;	/* byte offset on device to start writing */
2987c478bd9Sstevel@tonic-gate 				/*   delta */
2997c478bd9Sstevel@tonic-gate 	int32_t		d_nb;	/* # bytes in the delta */
3007c478bd9Sstevel@tonic-gate 	delta_t 	d_typ;	/* Type of delta.  Defined in ufs_trans.h */
3017c478bd9Sstevel@tonic-gate };
3027c478bd9Sstevel@tonic-gate /*
3037c478bd9Sstevel@tonic-gate  * common map entry
3047c478bd9Sstevel@tonic-gate  */
3057c478bd9Sstevel@tonic-gate typedef struct mapentry	mapentry_t;
3067c478bd9Sstevel@tonic-gate struct mapentry {
3077c478bd9Sstevel@tonic-gate 	/*
3087c478bd9Sstevel@tonic-gate 	 * doubly linked list of all mapentries in map -- MUST BE FIRST
3097c478bd9Sstevel@tonic-gate 	 */
3107c478bd9Sstevel@tonic-gate 	mapentry_t	*me_next;
3117c478bd9Sstevel@tonic-gate 	mapentry_t	*me_prev;
3127c478bd9Sstevel@tonic-gate 
3137c478bd9Sstevel@tonic-gate 	mapentry_t	*me_hash;
3147c478bd9Sstevel@tonic-gate 	mapentry_t	*me_agenext;
3157c478bd9Sstevel@tonic-gate 	mapentry_t	*me_cancel;
3167c478bd9Sstevel@tonic-gate 	crb_t		*me_crb;
3177c478bd9Sstevel@tonic-gate 	int		(*me_func)();
3187c478bd9Sstevel@tonic-gate 	ulong_t		me_arg;
3197c478bd9Sstevel@tonic-gate 	ulong_t		me_age;
3207c478bd9Sstevel@tonic-gate 	struct delta	me_delta;
3217c478bd9Sstevel@tonic-gate 	uint32_t	me_tid;
3227c478bd9Sstevel@tonic-gate 	off_t		me_lof;
3237c478bd9Sstevel@tonic-gate 	ushort_t	me_flags;
3247c478bd9Sstevel@tonic-gate };
3257c478bd9Sstevel@tonic-gate 
3267c478bd9Sstevel@tonic-gate #define	me_mof	me_delta.d_mof
3277c478bd9Sstevel@tonic-gate #define	me_nb	me_delta.d_nb
3287c478bd9Sstevel@tonic-gate #define	me_dt	me_delta.d_typ
3297c478bd9Sstevel@tonic-gate 
3307c478bd9Sstevel@tonic-gate /*
3317c478bd9Sstevel@tonic-gate  * me_flags
3327c478bd9Sstevel@tonic-gate  */
3337c478bd9Sstevel@tonic-gate #define	ME_SCAN		(0x0001)	/* entry from log scan */
3347c478bd9Sstevel@tonic-gate #define	ME_HASH		(0x0002)	/* on hash   list */
3357c478bd9Sstevel@tonic-gate #define	ME_CANCEL	(0x0004)	/* on cancel list */
3367c478bd9Sstevel@tonic-gate #define	ME_AGE		(0x0008)	/* on age    list */
3377c478bd9Sstevel@tonic-gate #define	ME_LIST		(0x0010)	/* on list   list */
3387c478bd9Sstevel@tonic-gate #define	ME_ROLL		(0x0020)	/* on pseudo-roll list */
3397c478bd9Sstevel@tonic-gate #define	ME_USER		(0x0040)	/* User Block DT_CANCEL entry */
3407c478bd9Sstevel@tonic-gate 
3417c478bd9Sstevel@tonic-gate /*
3427c478bd9Sstevel@tonic-gate  * MAP TYPES
3437c478bd9Sstevel@tonic-gate  */
3447c478bd9Sstevel@tonic-gate enum maptypes	{
3457c478bd9Sstevel@tonic-gate 	deltamaptype, logmaptype, matamaptype
3467c478bd9Sstevel@tonic-gate };
3477c478bd9Sstevel@tonic-gate 
3487c478bd9Sstevel@tonic-gate /*
3497c478bd9Sstevel@tonic-gate  * MAP
3507c478bd9Sstevel@tonic-gate  */
3517c478bd9Sstevel@tonic-gate #define	DELTAMAP_NHASH	(512)
3527c478bd9Sstevel@tonic-gate #define	LOGMAP_NHASH	(2048)
3537c478bd9Sstevel@tonic-gate #define	MAP_INDEX(mof, mtm) \
3547c478bd9Sstevel@tonic-gate 	(((mof) >> MAPBLOCKSHIFT) & (mtm->mtm_nhash-1))
3557c478bd9Sstevel@tonic-gate #define	MAP_HASH(mof, mtm) \
3567c478bd9Sstevel@tonic-gate 	((mtm)->mtm_hash + MAP_INDEX((mof), (mtm)))
3577c478bd9Sstevel@tonic-gate 
3587c478bd9Sstevel@tonic-gate typedef struct mt_map {
3597c478bd9Sstevel@tonic-gate 	/*
3607c478bd9Sstevel@tonic-gate 	 * anchor doubly linked list this map's entries -- MUST BE FIRST
3617c478bd9Sstevel@tonic-gate 	 */
3627c478bd9Sstevel@tonic-gate 	mapentry_t	*mtm_next;
3637c478bd9Sstevel@tonic-gate 	mapentry_t	*mtm_prev;
3647c478bd9Sstevel@tonic-gate 
3657c478bd9Sstevel@tonic-gate 	enum maptypes	mtm_type;	/* map type */
3667c478bd9Sstevel@tonic-gate 	int		mtm_flags;	/* generic flags */
3677c478bd9Sstevel@tonic-gate 	int		mtm_ref;	/* PTE like ref bit */
3687c478bd9Sstevel@tonic-gate 	ulong_t		mtm_debug;	/* set at create time */
3697c478bd9Sstevel@tonic-gate 	ulong_t		mtm_age;	/* mono-inc; tags mapentries */
3707c478bd9Sstevel@tonic-gate 	mapentry_t	*mtm_cancel;	/* to be canceled at commit */
3717c478bd9Sstevel@tonic-gate 	ulong_t		mtm_nhash;	/* # of hash anchors */
3727c478bd9Sstevel@tonic-gate 	mapentry_t	**mtm_hash;	/* array of singly linked lists */
3737c478bd9Sstevel@tonic-gate 	struct topstats	*mtm_tops;	/* trans ops - enabled by an ioctl */
3747c478bd9Sstevel@tonic-gate 	long		mtm_nme;	/* # of mapentries */
3757c478bd9Sstevel@tonic-gate 	long		mtm_nmet;	/* # of mapentries this transaction */
3767c478bd9Sstevel@tonic-gate 	long		mtm_cfrags;	/* Canceled frags */
3777c478bd9Sstevel@tonic-gate 	long		mtm_cfragmax;	/* Maximum canceled frags */
3787c478bd9Sstevel@tonic-gate 	/*
3797c478bd9Sstevel@tonic-gate 	 * used after logscan to set the log's tail
3807c478bd9Sstevel@tonic-gate 	 */
3817c478bd9Sstevel@tonic-gate 	off_t		mtm_tail_lof;
3827c478bd9Sstevel@tonic-gate 	size_t		mtm_tail_nb;
3837c478bd9Sstevel@tonic-gate 
3847c478bd9Sstevel@tonic-gate 	/*
3857c478bd9Sstevel@tonic-gate 	 * debug field for Scan test
3867c478bd9Sstevel@tonic-gate 	 */
3877c478bd9Sstevel@tonic-gate 	off_t		mtm_trimlof;	/* log was trimmed to this lof */
3887c478bd9Sstevel@tonic-gate 	off_t		mtm_trimtail;	/* tail lof before trimming */
3897c478bd9Sstevel@tonic-gate 	off_t		mtm_trimalof;	/* lof of last allocation delta */
3907c478bd9Sstevel@tonic-gate 	off_t		mtm_trimclof;	/* lof of last commit delta */
3917c478bd9Sstevel@tonic-gate 	off_t		mtm_trimrlof;	/* lof of last rolled delta */
3927c478bd9Sstevel@tonic-gate 	ml_unit_t	*mtm_ul;	/* log unit for this map */
3937c478bd9Sstevel@tonic-gate 
3947c478bd9Sstevel@tonic-gate 	/*
3957c478bd9Sstevel@tonic-gate 	 * moby trans stuff
3967c478bd9Sstevel@tonic-gate 	 */
3977c478bd9Sstevel@tonic-gate 	uint32_t		mtm_tid;
3987c478bd9Sstevel@tonic-gate 	uint32_t		mtm_committid;
3997c478bd9Sstevel@tonic-gate 	ushort_t		mtm_closed;
4007c478bd9Sstevel@tonic-gate 	ushort_t		mtm_seq;
4017c478bd9Sstevel@tonic-gate 	long			mtm_wantin;
4027c478bd9Sstevel@tonic-gate 	long			mtm_active;
4037c478bd9Sstevel@tonic-gate 	long			mtm_activesync;
4047c478bd9Sstevel@tonic-gate 	ulong_t			mtm_dirty;
4057c478bd9Sstevel@tonic-gate 	kmutex_t		mtm_lock;
4067c478bd9Sstevel@tonic-gate 	kcondvar_t		mtm_cv_commit;
4077c478bd9Sstevel@tonic-gate 	kcondvar_t		mtm_cv_next;
4087c478bd9Sstevel@tonic-gate 	kcondvar_t		mtm_cv_eot;
4097c478bd9Sstevel@tonic-gate 
4107c478bd9Sstevel@tonic-gate 	/*
4117c478bd9Sstevel@tonic-gate 	 * mutex that protects all the fields in mt_map except
4127c478bd9Sstevel@tonic-gate 	 * mtm_mapnext and mtm_refcnt
4137c478bd9Sstevel@tonic-gate 	 */
4147c478bd9Sstevel@tonic-gate 	kmutex_t	mtm_mutex;
4157c478bd9Sstevel@tonic-gate 
4167c478bd9Sstevel@tonic-gate 	/*
4177c478bd9Sstevel@tonic-gate 	 * logmap only condition variables
4187c478bd9Sstevel@tonic-gate 	 */
4197c478bd9Sstevel@tonic-gate 	kcondvar_t	mtm_to_roll_cv; /* roll log or kill roll thread */
4207c478bd9Sstevel@tonic-gate 	kcondvar_t	mtm_from_roll_cv; /* log rolled or thread exiting */
4217c478bd9Sstevel@tonic-gate 
4227c478bd9Sstevel@tonic-gate 	/*
4237c478bd9Sstevel@tonic-gate 	 * rw lock for the agenext mapentry field
4247c478bd9Sstevel@tonic-gate 	 */
4257c478bd9Sstevel@tonic-gate 	krwlock_t	mtm_rwlock;
4267c478bd9Sstevel@tonic-gate 	/*
4277c478bd9Sstevel@tonic-gate 	 * DEBUG: runtestscan
4287c478bd9Sstevel@tonic-gate 	 */
4297c478bd9Sstevel@tonic-gate 	kmutex_t	mtm_scan_mutex;
4307c478bd9Sstevel@tonic-gate 
4317c478bd9Sstevel@tonic-gate 	/*
4327c478bd9Sstevel@tonic-gate 	 * logmap only taskq sync count variable, protected by mtm_lock.
4337c478bd9Sstevel@tonic-gate 	 * keeps track of the number of pending top_issue_sync
4347c478bd9Sstevel@tonic-gate 	 * dispatches.
4357c478bd9Sstevel@tonic-gate 	 */
4367c478bd9Sstevel@tonic-gate 	int		mtm_taskq_sync_count;
4377c478bd9Sstevel@tonic-gate 
4387c478bd9Sstevel@tonic-gate 	/*
4397c478bd9Sstevel@tonic-gate 	 * logmap only condition variable, to synchronize with lufs_unsnarf.
4407c478bd9Sstevel@tonic-gate 	 */
4417c478bd9Sstevel@tonic-gate 	kcondvar_t	mtm_cv;
4427c478bd9Sstevel@tonic-gate } mt_map_t;
4437c478bd9Sstevel@tonic-gate 
4447c478bd9Sstevel@tonic-gate /*
4457c478bd9Sstevel@tonic-gate  * mtm_flags
4467c478bd9Sstevel@tonic-gate  */
4477c478bd9Sstevel@tonic-gate #define	MTM_ROLL_EXIT		0x00000001 /* force roll thread to exit */
4487c478bd9Sstevel@tonic-gate #define	MTM_ROLL_RUNNING	0x00000002 /* roll thread is running */
4497c478bd9Sstevel@tonic-gate #define	MTM_FORCE_ROLL		0x00000004 /* force at least one roll cycle */
4507c478bd9Sstevel@tonic-gate #define	MTM_ROLLING		0x00000008 /* currently rolling the log */
4517c478bd9Sstevel@tonic-gate #define	MTM_CANCELED		0x00000010 /* cancel entries were removed */
4527c478bd9Sstevel@tonic-gate 
4537c478bd9Sstevel@tonic-gate /*
4547c478bd9Sstevel@tonic-gate  * Generic range checking macros
4557c478bd9Sstevel@tonic-gate  */
4567c478bd9Sstevel@tonic-gate #define	OVERLAP(sof, snb, dof, dnb) \
4577c478bd9Sstevel@tonic-gate 	(((sof) >= (dof) && (sof) < ((dof) + (dnb))) || \
4587c478bd9Sstevel@tonic-gate 	((dof) >= (sof) && (dof) < ((sof) + (snb))))
4597c478bd9Sstevel@tonic-gate #define	WITHIN(sof, snb, dof, dnb) \
4607c478bd9Sstevel@tonic-gate 	(((sof) >= (dof)) && (((sof) + (snb)) <= ((dof) + (dnb))))
4617c478bd9Sstevel@tonic-gate #define	DATAoverlapME(mof, hnb, me) \
4627c478bd9Sstevel@tonic-gate 	(OVERLAP((mof), (hnb), (me)->me_mof, (me)->me_nb))
4637c478bd9Sstevel@tonic-gate #define	MEwithinDATA(me, mof, hnb) \
4647c478bd9Sstevel@tonic-gate 	(WITHIN((me)->me_mof, (me)->me_nb, (mof), (hnb)))
4657c478bd9Sstevel@tonic-gate #define	DATAwithinME(mof, hnb, me) \
4667c478bd9Sstevel@tonic-gate 	(WITHIN((mof), (hnb), (me)->me_mof, (me)->me_nb))
4677c478bd9Sstevel@tonic-gate #define	DATAwithinCRB(mof, nb, crb) \
4687c478bd9Sstevel@tonic-gate 	(WITHIN((mof), (nb), (crb)->c_mof, (crb)->c_nb))
4697c478bd9Sstevel@tonic-gate 
4707c478bd9Sstevel@tonic-gate /*
4717c478bd9Sstevel@tonic-gate  * TRANSACTION OPS STATS
4727c478bd9Sstevel@tonic-gate  */
4737c478bd9Sstevel@tonic-gate typedef struct topstats {
4747c478bd9Sstevel@tonic-gate 	uint64_t	mtm_top_num[TOP_MAX];
4757c478bd9Sstevel@tonic-gate 	uint64_t	mtm_top_size_etot[TOP_MAX];
4767c478bd9Sstevel@tonic-gate 	uint64_t	mtm_top_size_rtot[TOP_MAX];
4777c478bd9Sstevel@tonic-gate 	uint64_t	mtm_top_size_max[TOP_MAX];
4787c478bd9Sstevel@tonic-gate 	uint64_t	mtm_top_size_min[TOP_MAX];
4797c478bd9Sstevel@tonic-gate 	uint64_t	mtm_delta_num[DT_MAX];
4807c478bd9Sstevel@tonic-gate } topstats_t;
4817c478bd9Sstevel@tonic-gate 
4827c478bd9Sstevel@tonic-gate /*
4837c478bd9Sstevel@tonic-gate  * fio_lufs_stats_t is used by _FIO_GET_TOP_STATS ioctl for getting topstats
4847c478bd9Sstevel@tonic-gate  */
4857c478bd9Sstevel@tonic-gate typedef struct fio_lufs_stats {
4867c478bd9Sstevel@tonic-gate 	uint32_t	ls_debug;	/* out: un_debug value */
4877c478bd9Sstevel@tonic-gate 	uint32_t	_ls_pad;	/* make size 64-bit aligned on x86 */
4887c478bd9Sstevel@tonic-gate 	topstats_t	ls_topstats;	/* out: transaction stats */
4897c478bd9Sstevel@tonic-gate } fio_lufs_stats_t;
4907c478bd9Sstevel@tonic-gate 
4917c478bd9Sstevel@tonic-gate /*
4927c478bd9Sstevel@tonic-gate  * roll buf structure; one per roll buffer
4937c478bd9Sstevel@tonic-gate  */
4947c478bd9Sstevel@tonic-gate typedef uint16_t rbsecmap_t;
4957c478bd9Sstevel@tonic-gate typedef struct rollbuf {
4967c478bd9Sstevel@tonic-gate 	buf_t rb_bh;		/* roll buffer header */
4977c478bd9Sstevel@tonic-gate 	struct rollbuf *rb_next; /* link for mof ordered roll bufs */
4987c478bd9Sstevel@tonic-gate 	crb_t *rb_crb;		/* cached roll buffer to roll */
4997c478bd9Sstevel@tonic-gate 	mapentry_t *rb_age;	/* age list */
5007c478bd9Sstevel@tonic-gate 	rbsecmap_t rb_secmap;	/* sector map */
5017c478bd9Sstevel@tonic-gate } rollbuf_t;
5027c478bd9Sstevel@tonic-gate 
5037c478bd9Sstevel@tonic-gate /*
5047c478bd9Sstevel@tonic-gate  * un_debug
5057c478bd9Sstevel@tonic-gate  *	MT_TRANSACT		- keep per thread accounting of tranactions
5067c478bd9Sstevel@tonic-gate  *	MT_MATAMAP		- double check deltas and ops against matamap
5077c478bd9Sstevel@tonic-gate  *	MT_WRITE_CHECK		- check master+deltas against metadata write
5087c478bd9Sstevel@tonic-gate  *	MT_LOG_WRITE_CHECK	- read after write for log writes
5097c478bd9Sstevel@tonic-gate  *	MT_CHECK_MAP		- check map after every insert/delete
5107c478bd9Sstevel@tonic-gate  *	MT_TRACE		- trace transactions (used with MT_TRANSACT)
5117c478bd9Sstevel@tonic-gate  *	MT_SIZE			- fail on size errors (used with MT_TRANSACT)
5127c478bd9Sstevel@tonic-gate  *	MT_NOASYNC		- force every op to be sync
5137c478bd9Sstevel@tonic-gate  *	MT_FORCEROLL		- forcibly roll the log after every commit
5147c478bd9Sstevel@tonic-gate  *	MT_SCAN			- running runtestscan; special case as needed
5157c478bd9Sstevel@tonic-gate  */
5167c478bd9Sstevel@tonic-gate #define	MT_NONE			(0x00000000)
5177c478bd9Sstevel@tonic-gate #define	MT_TRANSACT		(0x00000001)
5187c478bd9Sstevel@tonic-gate #define	MT_MATAMAP		(0x00000002)
5197c478bd9Sstevel@tonic-gate #define	MT_WRITE_CHECK		(0x00000004)
5207c478bd9Sstevel@tonic-gate #define	MT_LOG_WRITE_CHECK	(0x00000008)
5217c478bd9Sstevel@tonic-gate #define	MT_CHECK_MAP		(0x00000010)
5227c478bd9Sstevel@tonic-gate #define	MT_TRACE		(0x00000020)
5237c478bd9Sstevel@tonic-gate #define	MT_SIZE			(0x00000040)
5247c478bd9Sstevel@tonic-gate #define	MT_NOASYNC		(0x00000080)
5257c478bd9Sstevel@tonic-gate #define	MT_FORCEROLL		(0x00000100)
5267c478bd9Sstevel@tonic-gate #define	MT_SCAN			(0x00000200)
5277c478bd9Sstevel@tonic-gate 
5287c478bd9Sstevel@tonic-gate struct logstats {
5297c478bd9Sstevel@tonic-gate 	kstat_named_t ls_lreads;	/* master reads */
5307c478bd9Sstevel@tonic-gate 	kstat_named_t ls_lwrites;	/* master writes */
5317c478bd9Sstevel@tonic-gate 	kstat_named_t ls_lreadsinmem;	/* log reads in memory */
5327c478bd9Sstevel@tonic-gate 	kstat_named_t ls_ldlreads;	/* log reads */
5337c478bd9Sstevel@tonic-gate 	kstat_named_t ls_ldlwrites;	/* log writes */
5347c478bd9Sstevel@tonic-gate 	kstat_named_t ls_mreads;	/* log master reads */
5357c478bd9Sstevel@tonic-gate 	kstat_named_t ls_rreads;	/* log roll reads */
5367c478bd9Sstevel@tonic-gate 	kstat_named_t ls_rwrites;	/* log roll writes */
5377c478bd9Sstevel@tonic-gate };
5387c478bd9Sstevel@tonic-gate 
5397c478bd9Sstevel@tonic-gate #ifdef _KERNEL
5407c478bd9Sstevel@tonic-gate 
5417c478bd9Sstevel@tonic-gate typedef struct threadtrans {
5427c478bd9Sstevel@tonic-gate 	ulong_t		deltas_size;	/* size of deltas this transaction */
5437c478bd9Sstevel@tonic-gate 	uint32_t	last_async_tid;	/* last async transaction id */
5447c478bd9Sstevel@tonic-gate 	uchar_t		any_deltas;	/* any deltas done this transaction */
5457c478bd9Sstevel@tonic-gate #ifdef DEBUG
5467c478bd9Sstevel@tonic-gate 	uint_t		topid;		/* transaction type */
5477c478bd9Sstevel@tonic-gate 	ulong_t		esize;		/* estimated trans size */
5487c478bd9Sstevel@tonic-gate 	ulong_t		rsize;		/* real trans size */
5497c478bd9Sstevel@tonic-gate 	dev_t		dev;		/* device */
5507c478bd9Sstevel@tonic-gate #endif /* DEBUG */
5517c478bd9Sstevel@tonic-gate } threadtrans_t;
5527c478bd9Sstevel@tonic-gate 
5537c478bd9Sstevel@tonic-gate /*
5547c478bd9Sstevel@tonic-gate  * Log layer protos -- lufs_log.c
5557c478bd9Sstevel@tonic-gate  */
5567c478bd9Sstevel@tonic-gate extern void		ldl_strategy(ml_unit_t *, buf_t *);
5577c478bd9Sstevel@tonic-gate extern void		ldl_round_commit(ml_unit_t *);
5587c478bd9Sstevel@tonic-gate extern void		ldl_push_commit(ml_unit_t *);
5597c478bd9Sstevel@tonic-gate extern int		ldl_need_commit(ml_unit_t *);
5607c478bd9Sstevel@tonic-gate extern int		ldl_has_space(ml_unit_t *, mapentry_t *);
5617c478bd9Sstevel@tonic-gate extern void		ldl_write(ml_unit_t *, caddr_t, offset_t, mapentry_t *);
5627c478bd9Sstevel@tonic-gate extern void		ldl_waito(ml_unit_t *);
5637c478bd9Sstevel@tonic-gate extern int		ldl_read(ml_unit_t *, caddr_t, offset_t, off_t,
5647c478bd9Sstevel@tonic-gate 					mapentry_t *);
5657c478bd9Sstevel@tonic-gate extern void		ldl_sethead(ml_unit_t *, off_t, uint32_t);
5667c478bd9Sstevel@tonic-gate extern void		ldl_settail(ml_unit_t *, off_t, size_t);
5677c478bd9Sstevel@tonic-gate extern ulong_t		ldl_logscan_nbcommit(off_t);
5687c478bd9Sstevel@tonic-gate extern int		ldl_logscan_read(ml_unit_t *, off_t *, size_t, caddr_t);
5697c478bd9Sstevel@tonic-gate extern void		ldl_logscan_begin(ml_unit_t *);
5707c478bd9Sstevel@tonic-gate extern void		ldl_logscan_end(ml_unit_t *);
5717c478bd9Sstevel@tonic-gate extern int		ldl_need_roll(ml_unit_t *);
5727c478bd9Sstevel@tonic-gate extern void		ldl_seterror(ml_unit_t *, char *);
5737c478bd9Sstevel@tonic-gate extern size_t		ldl_bufsize(ml_unit_t *);
5747c478bd9Sstevel@tonic-gate extern void		ldl_savestate(ml_unit_t *);
5757c478bd9Sstevel@tonic-gate extern void		free_cirbuf(cirbuf_t *);
5767c478bd9Sstevel@tonic-gate extern void		alloc_rdbuf(cirbuf_t *, size_t, size_t);
5777c478bd9Sstevel@tonic-gate extern void		alloc_wrbuf(cirbuf_t *, size_t);
5787c478bd9Sstevel@tonic-gate 
5797c478bd9Sstevel@tonic-gate /*
5807c478bd9Sstevel@tonic-gate  * trans driver layer -- lufs.c
5817c478bd9Sstevel@tonic-gate  */
5827c478bd9Sstevel@tonic-gate extern int		trans_not_wait(struct buf *cb);
5837c478bd9Sstevel@tonic-gate extern int		trans_not_done(struct buf *cb);
5847c478bd9Sstevel@tonic-gate extern int		trans_wait(struct buf *cb);
5857c478bd9Sstevel@tonic-gate extern int		trans_done(struct buf *cb);
5867c478bd9Sstevel@tonic-gate extern void		lufs_strategy(ml_unit_t *, buf_t *);
5877c478bd9Sstevel@tonic-gate extern void		lufs_read_strategy(ml_unit_t *, buf_t *);
5887c478bd9Sstevel@tonic-gate extern void		lufs_write_strategy(ml_unit_t *, buf_t *);
5897c478bd9Sstevel@tonic-gate extern void		lufs_init(void);
5904f3979a5SWolfgang Schremser extern uint32_t		lufs_hd_genid(const ml_unit_t *);
5917c478bd9Sstevel@tonic-gate extern int		lufs_enable(struct vnode *, struct fiolog *, cred_t *);
5927c478bd9Sstevel@tonic-gate extern int		lufs_disable(vnode_t *, struct fiolog *);
5937c478bd9Sstevel@tonic-gate 
5947c478bd9Sstevel@tonic-gate /*
5957c478bd9Sstevel@tonic-gate  * transaction op layer -- lufs_top.c
5967c478bd9Sstevel@tonic-gate  */
5977c478bd9Sstevel@tonic-gate extern void	_init_top(void);
5987c478bd9Sstevel@tonic-gate extern int	top_read_roll(rollbuf_t *, ml_unit_t *);
5997c478bd9Sstevel@tonic-gate 
6007c478bd9Sstevel@tonic-gate 
6017c478bd9Sstevel@tonic-gate /*
6027c478bd9Sstevel@tonic-gate  * map layer -- lufs_map.c
6037c478bd9Sstevel@tonic-gate  */
6047c478bd9Sstevel@tonic-gate extern void		map_free_entries(mt_map_t *);
6057c478bd9Sstevel@tonic-gate extern int		matamap_overlap(mt_map_t *, offset_t, off_t);
6067c478bd9Sstevel@tonic-gate extern int		matamap_within(mt_map_t *, offset_t, off_t);
6077c478bd9Sstevel@tonic-gate extern int		deltamap_need_commit(mt_map_t *);
6087c478bd9Sstevel@tonic-gate extern void		deltamap_add(mt_map_t *, offset_t, off_t, delta_t,
6097c478bd9Sstevel@tonic-gate 				int (*)(), ulong_t, threadtrans_t *tp);
6107c478bd9Sstevel@tonic-gate extern mapentry_t	*deltamap_remove(mt_map_t *, offset_t, off_t);
6117c478bd9Sstevel@tonic-gate extern void		deltamap_del(mt_map_t *, offset_t, off_t);
6127c478bd9Sstevel@tonic-gate extern void		deltamap_push(ml_unit_t *);
6137c478bd9Sstevel@tonic-gate extern void		logmap_cancel_remove(mt_map_t *);
6147c478bd9Sstevel@tonic-gate extern int		logmap_need_commit(mt_map_t *);
6157c478bd9Sstevel@tonic-gate extern int		logmap_need_roll_async(mt_map_t *);
6167c478bd9Sstevel@tonic-gate extern int		logmap_need_roll_sync(mt_map_t *);
6177c478bd9Sstevel@tonic-gate extern void		logmap_start_roll(ml_unit_t *);
6187c478bd9Sstevel@tonic-gate extern void		logmap_kill_roll(ml_unit_t *);
6197c478bd9Sstevel@tonic-gate extern void		logmap_forceroll(mt_map_t *);
6207c478bd9Sstevel@tonic-gate extern void		logmap_forceroll_nowait(mt_map_t *);
6217c478bd9Sstevel@tonic-gate extern int		logmap_overlap(mt_map_t *, offset_t, off_t);
6227c478bd9Sstevel@tonic-gate extern void		logmap_remove_roll(mt_map_t *, offset_t, off_t);
6237c478bd9Sstevel@tonic-gate extern int		logmap_next_roll(mt_map_t *, offset_t *);
6247c478bd9Sstevel@tonic-gate extern int		logmap_list_get(mt_map_t *, offset_t, off_t,
6257c478bd9Sstevel@tonic-gate 				mapentry_t **);
6267c478bd9Sstevel@tonic-gate extern int		logmap_list_get_roll(mt_map_t *, offset_t, rollbuf_t *);
6277c478bd9Sstevel@tonic-gate extern void		logmap_list_put(mt_map_t *, mapentry_t *);
6287c478bd9Sstevel@tonic-gate extern void		logmap_list_put_roll(mt_map_t *, mapentry_t *);
6297c478bd9Sstevel@tonic-gate extern int		logmap_setup_read(mapentry_t *, rollbuf_t *);
6307c478bd9Sstevel@tonic-gate extern void		logmap_make_space(struct mt_map *, ml_unit_t *,
6317c478bd9Sstevel@tonic-gate 				mapentry_t *);
6327c478bd9Sstevel@tonic-gate extern void		logmap_add(ml_unit_t *, char *, offset_t, mapentry_t *);
6337c478bd9Sstevel@tonic-gate extern void		logmap_add_buf(ml_unit_t *, char *, offset_t,
6347c478bd9Sstevel@tonic-gate 				mapentry_t *, caddr_t, uint32_t);
6357c478bd9Sstevel@tonic-gate extern void		logmap_commit(ml_unit_t *, uint32_t);
6367c478bd9Sstevel@tonic-gate extern void		logmap_sethead(mt_map_t *, ml_unit_t *);
6377c478bd9Sstevel@tonic-gate extern void		logmap_settail(mt_map_t *, ml_unit_t *);
6387c478bd9Sstevel@tonic-gate extern void		logmap_roll_dev(ml_unit_t *ul);
6397c478bd9Sstevel@tonic-gate extern void		logmap_cancel(ml_unit_t *, offset_t, off_t, int);
6407c478bd9Sstevel@tonic-gate extern void		logmap_free_cancel(mt_map_t *, mapentry_t **);
6417c478bd9Sstevel@tonic-gate extern int		logmap_iscancel(mt_map_t *, offset_t, off_t);
6427c478bd9Sstevel@tonic-gate extern void		logmap_logscan(ml_unit_t *);
6437c478bd9Sstevel@tonic-gate extern mt_map_t		*map_put(mt_map_t *);
6447c478bd9Sstevel@tonic-gate extern mt_map_t		*map_get(ml_unit_t *, enum maptypes, int);
6457c478bd9Sstevel@tonic-gate extern void		_init_map(void);
6467c478bd9Sstevel@tonic-gate 
6477c478bd9Sstevel@tonic-gate /*
6487c478bd9Sstevel@tonic-gate  * scan and roll threads -- lufs_thread.c
6497c478bd9Sstevel@tonic-gate  */
6507c478bd9Sstevel@tonic-gate extern void	trans_roll(ml_unit_t *);
6517c478bd9Sstevel@tonic-gate 
6527c478bd9Sstevel@tonic-gate /*
6537c478bd9Sstevel@tonic-gate  * DEBUG
6547c478bd9Sstevel@tonic-gate  */
6557c478bd9Sstevel@tonic-gate #ifdef	DEBUG
6567c478bd9Sstevel@tonic-gate extern int	map_put_debug(mt_map_t *);
6577c478bd9Sstevel@tonic-gate extern int	map_get_debug(ml_unit_t *, mt_map_t *);
6587c478bd9Sstevel@tonic-gate extern int	top_write_debug(ml_unit_t *, mapentry_t *, offset_t, off_t);
6597c478bd9Sstevel@tonic-gate extern int	matamap_overlap(mt_map_t *, offset_t, off_t);
6607c478bd9Sstevel@tonic-gate extern int	ldl_sethead_debug(ml_unit_t *);
6617c478bd9Sstevel@tonic-gate extern int	map_check_linkage(mt_map_t *);
6627c478bd9Sstevel@tonic-gate extern int	logmap_logscan_debug(mt_map_t *, mapentry_t *);
6637c478bd9Sstevel@tonic-gate extern int	map_check_ldl_write(ml_unit_t *, caddr_t, offset_t,
6647c478bd9Sstevel@tonic-gate 								mapentry_t *);
6657c478bd9Sstevel@tonic-gate extern int	logmap_logscan_commit_debug(off_t, mt_map_t *);
6667c478bd9Sstevel@tonic-gate extern int	logmap_logscan_add_debug(struct delta *, mt_map_t *);
6677c478bd9Sstevel@tonic-gate extern int	top_delta_debug(ml_unit_t *, offset_t, off_t, delta_t);
6687c478bd9Sstevel@tonic-gate extern int	top_begin_debug(ml_unit_t *, top_t, ulong_t);
6697c478bd9Sstevel@tonic-gate extern int	top_end_debug(ml_unit_t *, mt_map_t *, top_t, ulong_t);
6707c478bd9Sstevel@tonic-gate extern int	top_roll_debug(ml_unit_t *);
6717c478bd9Sstevel@tonic-gate extern int	top_init_debug(void);
6727c478bd9Sstevel@tonic-gate extern int	lufs_initialize_debug(ml_odunit_t *);
6737c478bd9Sstevel@tonic-gate #endif	/* DEBUG */
6747c478bd9Sstevel@tonic-gate 
6757c478bd9Sstevel@tonic-gate extern uint64_t delta_stats[DT_MAX];
6767c478bd9Sstevel@tonic-gate extern uint64_t roll_stats[DT_MAX];
6777c478bd9Sstevel@tonic-gate extern struct logstats logstats;
6787c478bd9Sstevel@tonic-gate extern int ufs_crb_enable;
6797c478bd9Sstevel@tonic-gate 
6807c478bd9Sstevel@tonic-gate extern uint_t topkey;
6817c478bd9Sstevel@tonic-gate extern uint32_t ufs_ncg_log;
6827c478bd9Sstevel@tonic-gate 
6837c478bd9Sstevel@tonic-gate extern uint_t lufs_debug;
6847c478bd9Sstevel@tonic-gate 
6857c478bd9Sstevel@tonic-gate #endif	/* _KERNEL */
6867c478bd9Sstevel@tonic-gate 
6877c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
6887c478bd9Sstevel@tonic-gate }
6897c478bd9Sstevel@tonic-gate #endif
6907c478bd9Sstevel@tonic-gate 
6917c478bd9Sstevel@tonic-gate #endif	/* _SYS_FS_UFS_LOG_H */
692