2 * Copyright (c) 2000-2006 Silicon Graphics, Inc.
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
7 * published by the Free Software Foundation.
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.
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
20 #include "xfs_types.h"
24 #include "xfs_trans.h"
28 #include "xfs_dmapi.h"
29 #include "xfs_mount.h"
30 #include "xfs_bmap_btree.h"
31 #include "xfs_alloc_btree.h"
32 #include "xfs_ialloc_btree.h"
33 #include "xfs_dir2_sf.h"
34 #include "xfs_attr_sf.h"
35 #include "xfs_dinode.h"
36 #include "xfs_inode.h"
37 #include "xfs_inode_item.h"
38 #include "xfs_itable.h"
39 #include "xfs_btree.h"
40 #include "xfs_alloc.h"
41 #include "xfs_ialloc.h"
44 #include "xfs_error.h"
45 #include "xfs_buf_item.h"
47 #include "xfs_trace.h"
50 * Force a shutdown of the filesystem instantly while keeping
51 * the filesystem consistent. We don't do an unmount here; just shutdown
52 * the shop, make sure that absolutely nothing persistent happens to
53 * this filesystem after this point.
56 xfs_do_force_shutdown(
64 logerror
= flags
& SHUTDOWN_LOG_IO_ERROR
;
66 if (!(flags
& SHUTDOWN_FORCE_UMOUNT
)) {
67 cmn_err(CE_NOTE
, "xfs_force_shutdown(%s,0x%x) called from "
68 "line %d of file %s. Return address = 0x%p",
69 mp
->m_fsname
, flags
, lnnum
, fname
, __return_address
);
72 * No need to duplicate efforts.
74 if (XFS_FORCED_SHUTDOWN(mp
) && !logerror
)
78 * This flags XFS_MOUNT_FS_SHUTDOWN, makes sure that we don't
79 * queue up anybody new on the log reservations, and wakes up
80 * everybody who's sleeping on log reservations to tell them
83 if (xfs_log_force_umount(mp
, logerror
))
86 if (flags
& SHUTDOWN_CORRUPT_INCORE
) {
87 xfs_cmn_err(XFS_PTAG_SHUTDOWN_CORRUPT
, CE_ALERT
, mp
,
88 "Corruption of in-memory data detected. Shutting down filesystem: %s",
90 if (XFS_ERRLEVEL_HIGH
<= xfs_error_level
) {
93 } else if (!(flags
& SHUTDOWN_FORCE_UMOUNT
)) {
95 xfs_cmn_err(XFS_PTAG_SHUTDOWN_LOGERROR
, CE_ALERT
, mp
,
96 "Log I/O Error Detected. Shutting down filesystem: %s",
98 } else if (flags
& SHUTDOWN_DEVICE_REQ
) {
99 xfs_cmn_err(XFS_PTAG_SHUTDOWN_IOERROR
, CE_ALERT
, mp
,
100 "All device paths lost. Shutting down filesystem: %s",
102 } else if (!(flags
& SHUTDOWN_REMOTE_REQ
)) {
103 xfs_cmn_err(XFS_PTAG_SHUTDOWN_IOERROR
, CE_ALERT
, mp
,
104 "I/O Error Detected. Shutting down filesystem: %s",
108 if (!(flags
& SHUTDOWN_FORCE_UMOUNT
)) {
109 cmn_err(CE_ALERT
, "Please umount the filesystem, "
110 "and rectify the problem(s)");
115 * Prints out an ALERT message about I/O error.
120 struct xfs_mount
*mp
,
125 "I/O error in filesystem (\"%s\") meta-data dev %s block 0x%llx"
126 " (\"%s\") error %d buf count %zd",
127 (!mp
|| !mp
->m_fsname
) ? "(fs name not set)" : mp
->m_fsname
,
128 XFS_BUFTARG_NAME(XFS_BUF_TARGET(bp
)),
129 (__uint64_t
)blkno
, func
,
130 XFS_BUF_GETERROR(bp
), XFS_BUF_COUNT(bp
));
134 * This isn't an absolute requirement, but it is
135 * just a good idea to call xfs_read_buf instead of
136 * directly doing a read_buf call. For one, we shouldn't
137 * be doing this disk read if we are in SHUTDOWN state anyway,
138 * so this stops that from happening. Secondly, this does all
139 * the error checking stuff and the brelse if appropriate for
140 * the caller, so the code can be a little leaner.
145 struct xfs_mount
*mp
,
146 xfs_buftarg_t
*target
,
156 flags
= XBF_LOCK
| XBF_MAPPED
;
158 bp
= xfs_buf_read(target
, blkno
, len
, flags
);
160 return XFS_ERROR(EIO
);
161 error
= XFS_BUF_GETERROR(bp
);
162 if (bp
&& !error
&& !XFS_FORCED_SHUTDOWN(mp
)) {
167 xfs_ioerror_alert("xfs_read_buf", mp
, bp
, XFS_BUF_ADDR(bp
));
169 error
= XFS_ERROR(EIO
);
173 XFS_BUF_UNDELAYWRITE(bp
);
176 * brelse clears B_ERROR and b_error
185 * helper function to extract extent size hint from inode
189 struct xfs_inode
*ip
)
193 if (unlikely(XFS_IS_REALTIME_INODE(ip
))) {
194 extsz
= (ip
->i_d
.di_flags
& XFS_DIFLAG_EXTSIZE
)
196 : ip
->i_mount
->m_sb
.sb_rextsize
;
199 extsz
= (ip
->i_d
.di_flags
& XFS_DIFLAG_EXTSIZE
)
200 ? ip
->i_d
.di_extsize
: 0;