xfs: drop dmapi hooks
[sfrench/cifs-2.6.git] / fs / xfs / xfs_rw.c
1 /*
2  * Copyright (c) 2000-2006 Silicon Graphics, Inc.
3  * All Rights Reserved.
4  *
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.
8  *
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.
13  *
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
17  */
18 #include "xfs.h"
19 #include "xfs_fs.h"
20 #include "xfs_types.h"
21 #include "xfs_bit.h"
22 #include "xfs_log.h"
23 #include "xfs_inum.h"
24 #include "xfs_trans.h"
25 #include "xfs_sb.h"
26 #include "xfs_ag.h"
27 #include "xfs_dir2.h"
28 #include "xfs_mount.h"
29 #include "xfs_bmap_btree.h"
30 #include "xfs_alloc_btree.h"
31 #include "xfs_ialloc_btree.h"
32 #include "xfs_dir2_sf.h"
33 #include "xfs_attr_sf.h"
34 #include "xfs_dinode.h"
35 #include "xfs_inode.h"
36 #include "xfs_inode_item.h"
37 #include "xfs_itable.h"
38 #include "xfs_btree.h"
39 #include "xfs_alloc.h"
40 #include "xfs_ialloc.h"
41 #include "xfs_attr.h"
42 #include "xfs_bmap.h"
43 #include "xfs_error.h"
44 #include "xfs_buf_item.h"
45 #include "xfs_rw.h"
46 #include "xfs_trace.h"
47
48 /*
49  * Force a shutdown of the filesystem instantly while keeping
50  * the filesystem consistent. We don't do an unmount here; just shutdown
51  * the shop, make sure that absolutely nothing persistent happens to
52  * this filesystem after this point.
53  */
54 void
55 xfs_do_force_shutdown(
56         xfs_mount_t     *mp,
57         int             flags,
58         char            *fname,
59         int             lnnum)
60 {
61         int             logerror;
62
63         logerror = flags & SHUTDOWN_LOG_IO_ERROR;
64
65         if (!(flags & SHUTDOWN_FORCE_UMOUNT)) {
66                 cmn_err(CE_NOTE, "xfs_force_shutdown(%s,0x%x) called from "
67                                  "line %d of file %s.  Return address = 0x%p",
68                         mp->m_fsname, flags, lnnum, fname, __return_address);
69         }
70         /*
71          * No need to duplicate efforts.
72          */
73         if (XFS_FORCED_SHUTDOWN(mp) && !logerror)
74                 return;
75
76         /*
77          * This flags XFS_MOUNT_FS_SHUTDOWN, makes sure that we don't
78          * queue up anybody new on the log reservations, and wakes up
79          * everybody who's sleeping on log reservations to tell them
80          * the bad news.
81          */
82         if (xfs_log_force_umount(mp, logerror))
83                 return;
84
85         if (flags & SHUTDOWN_CORRUPT_INCORE) {
86                 xfs_cmn_err(XFS_PTAG_SHUTDOWN_CORRUPT, CE_ALERT, mp,
87     "Corruption of in-memory data detected.  Shutting down filesystem: %s",
88                         mp->m_fsname);
89                 if (XFS_ERRLEVEL_HIGH <= xfs_error_level) {
90                         xfs_stack_trace();
91                 }
92         } else if (!(flags & SHUTDOWN_FORCE_UMOUNT)) {
93                 if (logerror) {
94                         xfs_cmn_err(XFS_PTAG_SHUTDOWN_LOGERROR, CE_ALERT, mp,
95                 "Log I/O Error Detected.  Shutting down filesystem: %s",
96                                 mp->m_fsname);
97                 } else if (flags & SHUTDOWN_DEVICE_REQ) {
98                         xfs_cmn_err(XFS_PTAG_SHUTDOWN_IOERROR, CE_ALERT, mp,
99                 "All device paths lost.  Shutting down filesystem: %s",
100                                 mp->m_fsname);
101                 } else if (!(flags & SHUTDOWN_REMOTE_REQ)) {
102                         xfs_cmn_err(XFS_PTAG_SHUTDOWN_IOERROR, CE_ALERT, mp,
103                 "I/O Error Detected.  Shutting down filesystem: %s",
104                                 mp->m_fsname);
105                 }
106         }
107         if (!(flags & SHUTDOWN_FORCE_UMOUNT)) {
108                 cmn_err(CE_ALERT, "Please umount the filesystem, "
109                                   "and rectify the problem(s)");
110         }
111 }
112
113 /*
114  * Prints out an ALERT message about I/O error.
115  */
116 void
117 xfs_ioerror_alert(
118         char                    *func,
119         struct xfs_mount        *mp,
120         xfs_buf_t               *bp,
121         xfs_daddr_t             blkno)
122 {
123         cmn_err(CE_ALERT,
124  "I/O error in filesystem (\"%s\") meta-data dev %s block 0x%llx"
125  "       (\"%s\") error %d buf count %zd",
126                 (!mp || !mp->m_fsname) ? "(fs name not set)" : mp->m_fsname,
127                 XFS_BUFTARG_NAME(XFS_BUF_TARGET(bp)),
128                 (__uint64_t)blkno, func,
129                 XFS_BUF_GETERROR(bp), XFS_BUF_COUNT(bp));
130 }
131
132 /*
133  * This isn't an absolute requirement, but it is
134  * just a good idea to call xfs_read_buf instead of
135  * directly doing a read_buf call. For one, we shouldn't
136  * be doing this disk read if we are in SHUTDOWN state anyway,
137  * so this stops that from happening. Secondly, this does all
138  * the error checking stuff and the brelse if appropriate for
139  * the caller, so the code can be a little leaner.
140  */
141
142 int
143 xfs_read_buf(
144         struct xfs_mount *mp,
145         xfs_buftarg_t    *target,
146         xfs_daddr_t      blkno,
147         int              len,
148         uint             flags,
149         xfs_buf_t        **bpp)
150 {
151         xfs_buf_t        *bp;
152         int              error;
153
154         if (!flags)
155                 flags = XBF_LOCK | XBF_MAPPED;
156
157         bp = xfs_buf_read(target, blkno, len, flags);
158         if (!bp)
159                 return XFS_ERROR(EIO);
160         error = XFS_BUF_GETERROR(bp);
161         if (bp && !error && !XFS_FORCED_SHUTDOWN(mp)) {
162                 *bpp = bp;
163         } else {
164                 *bpp = NULL;
165                 if (error) {
166                         xfs_ioerror_alert("xfs_read_buf", mp, bp, XFS_BUF_ADDR(bp));
167                 } else {
168                         error = XFS_ERROR(EIO);
169                 }
170                 if (bp) {
171                         XFS_BUF_UNDONE(bp);
172                         XFS_BUF_UNDELAYWRITE(bp);
173                         XFS_BUF_STALE(bp);
174                         /*
175                          * brelse clears B_ERROR and b_error
176                          */
177                         xfs_buf_relse(bp);
178                 }
179         }
180         return (error);
181 }
182
183 /*
184  * helper function to extract extent size hint from inode
185  */
186 xfs_extlen_t
187 xfs_get_extsz_hint(
188         struct xfs_inode        *ip)
189 {
190         xfs_extlen_t            extsz;
191
192         if (unlikely(XFS_IS_REALTIME_INODE(ip))) {
193                 extsz = (ip->i_d.di_flags & XFS_DIFLAG_EXTSIZE)
194                                 ? ip->i_d.di_extsize
195                                 : ip->i_mount->m_sb.sb_rextsize;
196                 ASSERT(extsz);
197         } else {
198                 extsz = (ip->i_d.di_flags & XFS_DIFLAG_EXTSIZE)
199                                 ? ip->i_d.di_extsize : 0;
200         }
201
202         return extsz;
203 }