xref: /titanic_50/usr/src/uts/common/sys/fs/ufs_panic.h (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate #ifndef	_SYS_FS_UFS_PANIC_H
28*7c478bd9Sstevel@tonic-gate #define	_SYS_FS_UFS_PANIC_H
29*7c478bd9Sstevel@tonic-gate 
30*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
31*7c478bd9Sstevel@tonic-gate 
32*7c478bd9Sstevel@tonic-gate #include <sys/types.h>
33*7c478bd9Sstevel@tonic-gate #include <sys/vfs.h>
34*7c478bd9Sstevel@tonic-gate #include <sys/fs/ufs_inode.h>
35*7c478bd9Sstevel@tonic-gate #include <sys/fs/ufs_fs.h>
36*7c478bd9Sstevel@tonic-gate 
37*7c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
38*7c478bd9Sstevel@tonic-gate extern "C" {
39*7c478bd9Sstevel@tonic-gate #endif
40*7c478bd9Sstevel@tonic-gate 
41*7c478bd9Sstevel@tonic-gate #if defined(_KERNEL)
42*7c478bd9Sstevel@tonic-gate 
43*7c478bd9Sstevel@tonic-gate /*
44*7c478bd9Sstevel@tonic-gate  * failures have an associated state
45*7c478bd9Sstevel@tonic-gate  *  making them bit values simplifies state transition validity checking
46*7c478bd9Sstevel@tonic-gate  */
47*7c478bd9Sstevel@tonic-gate 
48*7c478bd9Sstevel@tonic-gate typedef enum ufs_failure_states {
49*7c478bd9Sstevel@tonic-gate 	/* initial states, set mostly by thread encountering failure */
50*7c478bd9Sstevel@tonic-gate 	UF_UNDEF	= 0x0000,	/* freshly-allocated memory */
51*7c478bd9Sstevel@tonic-gate 	UF_INIT		= 0x0001,	/* being created */
52*7c478bd9Sstevel@tonic-gate 	UF_QUEUE	= 0x0002,	/* queued for fix thread */
53*7c478bd9Sstevel@tonic-gate 
54*7c478bd9Sstevel@tonic-gate 	/* transitional states, set mostly by fix failure thread */
55*7c478bd9Sstevel@tonic-gate 	UF_TRYLCK	= 0x0010,	/* attempting to be locked */
56*7c478bd9Sstevel@tonic-gate 	UF_LOCKED	= 0x0020,	/* error lock set */
57*7c478bd9Sstevel@tonic-gate 	UF_UMOUNT	= 0x0040,	/* attempting to be unmounted */
58*7c478bd9Sstevel@tonic-gate 	UF_FIXING	= 0x0080,	/* fsck started; attempting unlock */
59*7c478bd9Sstevel@tonic-gate 
60*7c478bd9Sstevel@tonic-gate 	/* terminal states, once in this state, fix failure thread is done */
61*7c478bd9Sstevel@tonic-gate 	UF_FIXED	= 0x0100,	/* no problemo, man */
62*7c478bd9Sstevel@tonic-gate 	UF_NOTFIX	= 0x0200,	/* can't fix; shouldn't panic */
63*7c478bd9Sstevel@tonic-gate 	UF_REPLICA	= 0x0400,	/* replica panic; fix original only */
64*7c478bd9Sstevel@tonic-gate 	UF_PANIC	= 0x0800,	/* gave up/exceeded limits/can't fix */
65*7c478bd9Sstevel@tonic-gate 					/* not strictly a terminal state, */
66*7c478bd9Sstevel@tonic-gate 					/* because we will do some actions */
67*7c478bd9Sstevel@tonic-gate 					/* if we find a failure in this state */
68*7c478bd9Sstevel@tonic-gate 					/* but those actions will be terminal */
69*7c478bd9Sstevel@tonic-gate 
70*7c478bd9Sstevel@tonic-gate 	/* handy, but used only as terminators and placeholders */
71*7c478bd9Sstevel@tonic-gate 	UF_ILLEGAL	= 0xffff,	/* invalid state */
72*7c478bd9Sstevel@tonic-gate 	UF_ALLSTATES	= 0x0ff3	/* all possible state */
73*7c478bd9Sstevel@tonic-gate } ufs_failure_states_t;
74*7c478bd9Sstevel@tonic-gate 
75*7c478bd9Sstevel@tonic-gate /*
76*7c478bd9Sstevel@tonic-gate  * each manifestation of a fault (ie. "panic") is
77*7c478bd9Sstevel@tonic-gate  * associated with a distinct ufs_failure event
78*7c478bd9Sstevel@tonic-gate  */
79*7c478bd9Sstevel@tonic-gate 
80*7c478bd9Sstevel@tonic-gate typedef struct ufs_failure
81*7c478bd9Sstevel@tonic-gate {
82*7c478bd9Sstevel@tonic-gate 	struct ufs_failure	*uf_chain[2];	/* protected by ufs_elock mux */
83*7c478bd9Sstevel@tonic-gate 	struct ufs_failure	*uf_orig;	/* if duplicate event, */
84*7c478bd9Sstevel@tonic-gate 						/* here's the original */
85*7c478bd9Sstevel@tonic-gate 	struct ufs_failure	*uf_master;	/* if sharing a logged device */
86*7c478bd9Sstevel@tonic-gate 						/* here's the master failure */
87*7c478bd9Sstevel@tonic-gate 	struct buf		*uf_bp;		/* ptr to buf containing sb */
88*7c478bd9Sstevel@tonic-gate 	kmutex_t		*uf_vfs_lockp;	/* ptr to vfs_lock */
89*7c478bd9Sstevel@tonic-gate 	struct vfs_ufsfx	*uf_vfs_ufsfxp;	/* ptr to fix-on-panic per fs */
90*7c478bd9Sstevel@tonic-gate 	struct vfs		*uf_vfsp;	/* ptr to vfs */
91*7c478bd9Sstevel@tonic-gate 	struct ufsvfs		*uf_ufsvfsp;	/* to match if unmounted */
92*7c478bd9Sstevel@tonic-gate 	dev_t			 uf_dev;	/* device id */
93*7c478bd9Sstevel@tonic-gate 	ufs_failure_states_t	 uf_s;		/* current failure state */
94*7c478bd9Sstevel@tonic-gate 	int			 uf_flags;	/* internal flags */
95*7c478bd9Sstevel@tonic-gate 	time_t			 uf_begin_tm;	/* when did panic begin? */
96*7c478bd9Sstevel@tonic-gate 	time_t			 uf_end_tm;	/* ... end? */
97*7c478bd9Sstevel@tonic-gate 	time_t			 uf_entered_tm;	/* ... was state entered? */
98*7c478bd9Sstevel@tonic-gate 	struct lockfs		 uf_lf;		/* needed to set lockfs lock */
99*7c478bd9Sstevel@tonic-gate 	int			 uf_lf_err;	/* errno if lockfs fails  */
100*7c478bd9Sstevel@tonic-gate 	long			 uf_retry;	/* seconds */
101*7c478bd9Sstevel@tonic-gate 	unsigned		 uf_counter;	/* of state-specific actions */
102*7c478bd9Sstevel@tonic-gate 	kmutex_t		 uf_mutex;	/* protects struct body */
103*7c478bd9Sstevel@tonic-gate 	char		uf_fsname[MAXMNTLEN];	/* for post-unmount errors */
104*7c478bd9Sstevel@tonic-gate 						/* after ufsvfsp is free'd */
105*7c478bd9Sstevel@tonic-gate 	char uf_panic_str[LOCKFS_MAXCOMMENTLEN]; /* original panic message */
106*7c478bd9Sstevel@tonic-gate 						/* XXX could be smaller */
107*7c478bd9Sstevel@tonic-gate } ufs_failure_t;
108*7c478bd9Sstevel@tonic-gate 
109*7c478bd9Sstevel@tonic-gate #define	uf_next	uf_chain[0]
110*7c478bd9Sstevel@tonic-gate #define	uf_prev	uf_chain[1]
111*7c478bd9Sstevel@tonic-gate #define	uf_fs	uf_bp->b_un.b_fs
112*7c478bd9Sstevel@tonic-gate 
113*7c478bd9Sstevel@tonic-gate /*
114*7c478bd9Sstevel@tonic-gate  * per-filesystem panic event state
115*7c478bd9Sstevel@tonic-gate  */
116*7c478bd9Sstevel@tonic-gate typedef struct vfs_ufsfx {
117*7c478bd9Sstevel@tonic-gate 	long		 fx_flags;		/* see ufs_panic.h for the */
118*7c478bd9Sstevel@tonic-gate 	ufs_failure_t	*fx_current;		/* currently being fixed */
119*7c478bd9Sstevel@tonic-gate } vfs_ufsfx_t;
120*7c478bd9Sstevel@tonic-gate 
121*7c478bd9Sstevel@tonic-gate /*
122*7c478bd9Sstevel@tonic-gate  * External entry points
123*7c478bd9Sstevel@tonic-gate  *
124*7c478bd9Sstevel@tonic-gate  *  ufs_fault(vnode_t *, char *fmt, ...)
125*7c478bd9Sstevel@tonic-gate  *	replaces calls to cmn_err(CE_PANIC, char *fmt, ...)
126*7c478bd9Sstevel@tonic-gate  *  	The vnode is any vnode in the filesystem.
127*7c478bd9Sstevel@tonic-gate  *	ufs_fault returns an errno to bubble up.
128*7c478bd9Sstevel@tonic-gate  *  ufsfx_init()
129*7c478bd9Sstevel@tonic-gate  *	is called at modload time to set global values etc.
130*7c478bd9Sstevel@tonic-gate  *  ufsfx_mount()
131*7c478bd9Sstevel@tonic-gate  *	is called at mount time to do per-fs initialization
132*7c478bd9Sstevel@tonic-gate  *	returns 0 (ok) or errno
133*7c478bd9Sstevel@tonic-gate  *  ufsfx_unmount()
134*7c478bd9Sstevel@tonic-gate  *	is called at unmount time to prevent spinning on work
135*7c478bd9Sstevel@tonic-gate  *	to fix an unmounted fs
136*7c478bd9Sstevel@tonic-gate  *  ufsfx_lockfs()
137*7c478bd9Sstevel@tonic-gate  *  ufsfx_unlockfs()
138*7c478bd9Sstevel@tonic-gate  *      are called at upon (un)locking of a fs for coordination
139*7c478bd9Sstevel@tonic-gate  *  ufsfx_get_failure_qlen()
140*7c478bd9Sstevel@tonic-gate  *	is called by the hlock thread to coordinate with the fix
141*7c478bd9Sstevel@tonic-gate  *	failure thread
142*7c478bd9Sstevel@tonic-gate  */
143*7c478bd9Sstevel@tonic-gate 
144*7c478bd9Sstevel@tonic-gate /*PRINTFLIKE2*/
145*7c478bd9Sstevel@tonic-gate int	ufs_fault(vnode_t *, char *fmt, ...) __KPRINTFLIKE(2);
146*7c478bd9Sstevel@tonic-gate void	ufsfx_init(void);
147*7c478bd9Sstevel@tonic-gate int	ufsfx_mount(struct ufsvfs *, int);
148*7c478bd9Sstevel@tonic-gate void	ufsfx_unmount(struct ufsvfs *);
149*7c478bd9Sstevel@tonic-gate void	ufsfx_lockfs(struct ufsvfs *);
150*7c478bd9Sstevel@tonic-gate void	ufsfx_unlockfs(struct ufsvfs *);
151*7c478bd9Sstevel@tonic-gate int	ufsfx_get_failure_qlen(void);
152*7c478bd9Sstevel@tonic-gate 
153*7c478bd9Sstevel@tonic-gate extern struct ufs_q ufs_fix;
154*7c478bd9Sstevel@tonic-gate 
155*7c478bd9Sstevel@tonic-gate #endif /* _KERNEL */
156*7c478bd9Sstevel@tonic-gate 
157*7c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
158*7c478bd9Sstevel@tonic-gate }
159*7c478bd9Sstevel@tonic-gate #endif
160*7c478bd9Sstevel@tonic-gate 
161*7c478bd9Sstevel@tonic-gate #endif	/* _SYS_FS_UFS_PANIC_H */
162