Commit | Line | Data |
---|---|---|
1da177e4 | 1 | /* |
1e69dd0e | 2 | * Copyright (c) 2000-2006 Silicon Graphics, Inc. |
7b718769 | 3 | * All Rights Reserved. |
1da177e4 | 4 | * |
7b718769 NS |
5 | * This program is free software; you can redistribute it and/or |
6 | * modify it under the terms of the GNU General Public License as | |
1da177e4 LT |
7 | * published by the Free Software Foundation. |
8 | * | |
7b718769 NS |
9 | * This program is distributed in the hope that it would be useful, |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | * GNU General Public License for more details. | |
1da177e4 | 13 | * |
7b718769 NS |
14 | * You should have received a copy of the GNU General Public License |
15 | * along with this program; if not, write the Free Software Foundation, | |
16 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
1da177e4 | 17 | */ |
1da177e4 | 18 | #include "xfs.h" |
a844f451 | 19 | #include "xfs_fs.h" |
1da177e4 | 20 | #include "xfs_types.h" |
a844f451 | 21 | #include "xfs_bit.h" |
1da177e4 | 22 | #include "xfs_log.h" |
a844f451 | 23 | #include "xfs_inum.h" |
1da177e4 LT |
24 | #include "xfs_trans.h" |
25 | #include "xfs_sb.h" | |
26 | #include "xfs_ag.h" | |
1da177e4 | 27 | #include "xfs_mount.h" |
1da177e4 | 28 | #include "xfs_bmap_btree.h" |
a844f451 NS |
29 | #include "xfs_dinode.h" |
30 | #include "xfs_inode.h" | |
1da177e4 | 31 | #include "xfs_error.h" |
1da177e4 LT |
32 | #include "xfs_rw.h" |
33 | ||
1da177e4 LT |
34 | /* |
35 | * Force a shutdown of the filesystem instantly while keeping | |
36 | * the filesystem consistent. We don't do an unmount here; just shutdown | |
37 | * the shop, make sure that absolutely nothing persistent happens to | |
38 | * this filesystem after this point. | |
39 | */ | |
1da177e4 LT |
40 | void |
41 | xfs_do_force_shutdown( | |
48c872a9 | 42 | xfs_mount_t *mp, |
1da177e4 LT |
43 | int flags, |
44 | char *fname, | |
45 | int lnnum) | |
46 | { | |
47 | int logerror; | |
1da177e4 | 48 | |
7d04a335 | 49 | logerror = flags & SHUTDOWN_LOG_IO_ERROR; |
1da177e4 | 50 | |
7d04a335 NS |
51 | if (!(flags & SHUTDOWN_FORCE_UMOUNT)) { |
52 | cmn_err(CE_NOTE, "xfs_force_shutdown(%s,0x%x) called from " | |
53 | "line %d of file %s. Return address = 0x%p", | |
54 | mp->m_fsname, flags, lnnum, fname, __return_address); | |
1da177e4 LT |
55 | } |
56 | /* | |
57 | * No need to duplicate efforts. | |
58 | */ | |
59 | if (XFS_FORCED_SHUTDOWN(mp) && !logerror) | |
60 | return; | |
61 | ||
62 | /* | |
63 | * This flags XFS_MOUNT_FS_SHUTDOWN, makes sure that we don't | |
64 | * queue up anybody new on the log reservations, and wakes up | |
7d04a335 NS |
65 | * everybody who's sleeping on log reservations to tell them |
66 | * the bad news. | |
1da177e4 LT |
67 | */ |
68 | if (xfs_log_force_umount(mp, logerror)) | |
69 | return; | |
70 | ||
7d04a335 | 71 | if (flags & SHUTDOWN_CORRUPT_INCORE) { |
6a19d939 DC |
72 | xfs_alert_tag(mp, XFS_PTAG_SHUTDOWN_CORRUPT, |
73 | "Corruption of in-memory data detected. Shutting down filesystem"); | |
74 | if (XFS_ERRLEVEL_HIGH <= xfs_error_level) | |
1da177e4 | 75 | xfs_stack_trace(); |
7d04a335 | 76 | } else if (!(flags & SHUTDOWN_FORCE_UMOUNT)) { |
1da177e4 | 77 | if (logerror) { |
6a19d939 DC |
78 | xfs_alert_tag(mp, XFS_PTAG_SHUTDOWN_LOGERROR, |
79 | "Log I/O Error Detected. Shutting down filesystem"); | |
7d04a335 | 80 | } else if (flags & SHUTDOWN_DEVICE_REQ) { |
6a19d939 DC |
81 | xfs_alert_tag(mp, XFS_PTAG_SHUTDOWN_IOERROR, |
82 | "All device paths lost. Shutting down filesystem"); | |
7d04a335 | 83 | } else if (!(flags & SHUTDOWN_REMOTE_REQ)) { |
6a19d939 DC |
84 | xfs_alert_tag(mp, XFS_PTAG_SHUTDOWN_IOERROR, |
85 | "I/O Error Detected. Shutting down filesystem"); | |
1da177e4 LT |
86 | } |
87 | } | |
7d04a335 NS |
88 | if (!(flags & SHUTDOWN_FORCE_UMOUNT)) { |
89 | cmn_err(CE_ALERT, "Please umount the filesystem, " | |
90 | "and rectify the problem(s)"); | |
1da177e4 LT |
91 | } |
92 | } | |
93 | ||
1da177e4 LT |
94 | /* |
95 | * Prints out an ALERT message about I/O error. | |
96 | */ | |
97 | void | |
98 | xfs_ioerror_alert( | |
99 | char *func, | |
100 | struct xfs_mount *mp, | |
101 | xfs_buf_t *bp, | |
102 | xfs_daddr_t blkno) | |
103 | { | |
104 | cmn_err(CE_ALERT, | |
105 | "I/O error in filesystem (\"%s\") meta-data dev %s block 0x%llx" | |
da1650a5 | 106 | " (\"%s\") error %d buf count %zd", |
1da177e4 | 107 | (!mp || !mp->m_fsname) ? "(fs name not set)" : mp->m_fsname, |
ce8e922c NS |
108 | XFS_BUFTARG_NAME(XFS_BUF_TARGET(bp)), |
109 | (__uint64_t)blkno, func, | |
110 | XFS_BUF_GETERROR(bp), XFS_BUF_COUNT(bp)); | |
1da177e4 LT |
111 | } |
112 | ||
113 | /* | |
114 | * This isn't an absolute requirement, but it is | |
115 | * just a good idea to call xfs_read_buf instead of | |
116 | * directly doing a read_buf call. For one, we shouldn't | |
117 | * be doing this disk read if we are in SHUTDOWN state anyway, | |
118 | * so this stops that from happening. Secondly, this does all | |
119 | * the error checking stuff and the brelse if appropriate for | |
120 | * the caller, so the code can be a little leaner. | |
121 | */ | |
122 | ||
123 | int | |
124 | xfs_read_buf( | |
125 | struct xfs_mount *mp, | |
126 | xfs_buftarg_t *target, | |
127 | xfs_daddr_t blkno, | |
128 | int len, | |
129 | uint flags, | |
130 | xfs_buf_t **bpp) | |
131 | { | |
132 | xfs_buf_t *bp; | |
133 | int error; | |
134 | ||
6ad112bf CH |
135 | if (!flags) |
136 | flags = XBF_LOCK | XBF_MAPPED; | |
137 | ||
138 | bp = xfs_buf_read(target, blkno, len, flags); | |
1da177e4 LT |
139 | if (!bp) |
140 | return XFS_ERROR(EIO); | |
141 | error = XFS_BUF_GETERROR(bp); | |
142 | if (bp && !error && !XFS_FORCED_SHUTDOWN(mp)) { | |
143 | *bpp = bp; | |
144 | } else { | |
145 | *bpp = NULL; | |
146 | if (error) { | |
147 | xfs_ioerror_alert("xfs_read_buf", mp, bp, XFS_BUF_ADDR(bp)); | |
148 | } else { | |
149 | error = XFS_ERROR(EIO); | |
150 | } | |
151 | if (bp) { | |
152 | XFS_BUF_UNDONE(bp); | |
153 | XFS_BUF_UNDELAYWRITE(bp); | |
154 | XFS_BUF_STALE(bp); | |
155 | /* | |
156 | * brelse clears B_ERROR and b_error | |
157 | */ | |
158 | xfs_buf_relse(bp); | |
159 | } | |
160 | } | |
161 | return (error); | |
162 | } | |
163 | ||
5683f53e CH |
164 | /* |
165 | * helper function to extract extent size hint from inode | |
166 | */ | |
167 | xfs_extlen_t | |
168 | xfs_get_extsz_hint( | |
169 | struct xfs_inode *ip) | |
170 | { | |
0d8b30ad CH |
171 | if ((ip->i_d.di_flags & XFS_DIFLAG_EXTSIZE) && ip->i_d.di_extsize) |
172 | return ip->i_d.di_extsize; | |
173 | if (XFS_IS_REALTIME_INODE(ip)) | |
174 | return ip->i_mount->m_sb.sb_rextsize; | |
175 | return 0; | |
5683f53e | 176 | } |