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