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