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