Blame view

fs/xfs/xfs_rw.c 4.55 KB
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1
  /*
1e69dd0eb   Nathan Scott   [XFS] Push some c...
2
   * Copyright (c) 2000-2006 Silicon Graphics, Inc.
7b7187698   Nathan Scott   [XFS] Update lice...
3
   * All Rights Reserved.
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
4
   *
7b7187698   Nathan Scott   [XFS] Update lice...
5
6
   * This program is free software; you can redistribute it and/or
   * modify it under the terms of the GNU General Public License as
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
7
8
   * published by the Free Software Foundation.
   *
7b7187698   Nathan Scott   [XFS] Update lice...
9
10
11
12
   * This program is distributed in the hope that it would be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   * GNU General Public License for more details.
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
13
   *
7b7187698   Nathan Scott   [XFS] Update lice...
14
15
16
   * You should have received a copy of the GNU General Public License
   * along with this program; if not, write the Free Software Foundation,
   * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
17
   */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
18
  #include "xfs.h"
a844f4510   Nathan Scott   [XFS] Remove xfs_...
19
  #include "xfs_fs.h"
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
20
  #include "xfs_types.h"
a844f4510   Nathan Scott   [XFS] Remove xfs_...
21
  #include "xfs_bit.h"
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
22
  #include "xfs_log.h"
a844f4510   Nathan Scott   [XFS] Remove xfs_...
23
  #include "xfs_inum.h"
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
24
25
26
  #include "xfs_trans.h"
  #include "xfs_sb.h"
  #include "xfs_ag.h"
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
27
  #include "xfs_mount.h"
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
28
  #include "xfs_bmap_btree.h"
a844f4510   Nathan Scott   [XFS] Remove xfs_...
29
30
  #include "xfs_dinode.h"
  #include "xfs_inode.h"
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
31
  #include "xfs_error.h"
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
32
33
34
  #include "xfs_rw.h"
  
  /*
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
35
36
37
38
39
   * Force a shutdown of the filesystem instantly while keeping
   * the filesystem consistent. We don't do an unmount here; just shutdown
   * the shop, make sure that absolutely nothing persistent happens to
   * this filesystem after this point.
   */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
40
41
  void
  xfs_do_force_shutdown(
48c872a9f   Christoph Hellwig   [XFS] decontamina...
42
  	xfs_mount_t	*mp,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
43
44
45
46
47
  	int		flags,
  	char		*fname,
  	int		lnnum)
  {
  	int		logerror;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
48

7d04a335b   Nathan Scott   [XFS] Shutdown th...
49
  	logerror = flags & SHUTDOWN_LOG_IO_ERROR;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
50

7d04a335b   Nathan Scott   [XFS] Shutdown th...
51
  	if (!(flags & SHUTDOWN_FORCE_UMOUNT)) {
0b932cccb   Dave Chinner   xfs: Convert rema...
52
53
54
  		xfs_notice(mp,
  	"%s(0x%x) called from line %d of file %s.  Return address = 0x%p",
  			__func__, flags, lnnum, fname, __return_address);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
55
56
57
58
59
60
61
62
63
64
  	}
  	/*
  	 * No need to duplicate efforts.
  	 */
  	if (XFS_FORCED_SHUTDOWN(mp) && !logerror)
  		return;
  
  	/*
  	 * This flags XFS_MOUNT_FS_SHUTDOWN, makes sure that we don't
  	 * queue up anybody new on the log reservations, and wakes up
7d04a335b   Nathan Scott   [XFS] Shutdown th...
65
66
  	 * everybody who's sleeping on log reservations to tell them
  	 * the bad news.
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
67
68
69
  	 */
  	if (xfs_log_force_umount(mp, logerror))
  		return;
7d04a335b   Nathan Scott   [XFS] Shutdown th...
70
  	if (flags & SHUTDOWN_CORRUPT_INCORE) {
6a19d9393   Dave Chinner   xfs: convert xfs_...
71
72
73
  		xfs_alert_tag(mp, XFS_PTAG_SHUTDOWN_CORRUPT,
      "Corruption of in-memory data detected.  Shutting down filesystem");
  		if (XFS_ERRLEVEL_HIGH <= xfs_error_level)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
74
  			xfs_stack_trace();
7d04a335b   Nathan Scott   [XFS] Shutdown th...
75
  	} else if (!(flags & SHUTDOWN_FORCE_UMOUNT)) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
76
  		if (logerror) {
6a19d9393   Dave Chinner   xfs: convert xfs_...
77
78
  			xfs_alert_tag(mp, XFS_PTAG_SHUTDOWN_LOGERROR,
  		"Log I/O Error Detected.  Shutting down filesystem");
7d04a335b   Nathan Scott   [XFS] Shutdown th...
79
  		} else if (flags & SHUTDOWN_DEVICE_REQ) {
6a19d9393   Dave Chinner   xfs: convert xfs_...
80
81
  			xfs_alert_tag(mp, XFS_PTAG_SHUTDOWN_IOERROR,
  		"All device paths lost.  Shutting down filesystem");
7d04a335b   Nathan Scott   [XFS] Shutdown th...
82
  		} else if (!(flags & SHUTDOWN_REMOTE_REQ)) {
6a19d9393   Dave Chinner   xfs: convert xfs_...
83
84
  			xfs_alert_tag(mp, XFS_PTAG_SHUTDOWN_IOERROR,
  		"I/O Error Detected. Shutting down filesystem");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
85
86
  		}
  	}
7d04a335b   Nathan Scott   [XFS] Shutdown th...
87
  	if (!(flags & SHUTDOWN_FORCE_UMOUNT)) {
0b932cccb   Dave Chinner   xfs: Convert rema...
88
89
  		xfs_alert(mp,
  	"Please umount the filesystem and rectify the problem(s)");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
90
91
  	}
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
92
93
94
95
96
97
98
99
100
101
  /*
   * Prints out an ALERT message about I/O error.
   */
  void
  xfs_ioerror_alert(
  	char			*func,
  	struct xfs_mount	*mp,
  	xfs_buf_t		*bp,
  	xfs_daddr_t		blkno)
  {
0b932cccb   Dave Chinner   xfs: Convert rema...
102
103
104
  	xfs_alert(mp,
  		 "I/O error occurred: meta-data dev %s block 0x%llx"
  		 "       (\"%s\") error %d buf count %zd",
ce8e922c0   Nathan Scott   [XFS] Complete th...
105
106
107
  		XFS_BUFTARG_NAME(XFS_BUF_TARGET(bp)),
  		(__uint64_t)blkno, func,
  		XFS_BUF_GETERROR(bp), XFS_BUF_COUNT(bp));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
  }
  
  /*
   * This isn't an absolute requirement, but it is
   * just a good idea to call xfs_read_buf instead of
   * directly doing a read_buf call. For one, we shouldn't
   * be doing this disk read if we are in SHUTDOWN state anyway,
   * so this stops that from happening. Secondly, this does all
   * the error checking stuff and the brelse if appropriate for
   * the caller, so the code can be a little leaner.
   */
  
  int
  xfs_read_buf(
  	struct xfs_mount *mp,
  	xfs_buftarg_t	 *target,
  	xfs_daddr_t	 blkno,
  	int              len,
  	uint             flags,
  	xfs_buf_t	 **bpp)
  {
  	xfs_buf_t	 *bp;
  	int		 error;
6ad112bfb   Christoph Hellwig   xfs: simplify xfs...
131
132
133
134
  	if (!flags)
  		flags = XBF_LOCK | XBF_MAPPED;
  
  	bp = xfs_buf_read(target, blkno, len, flags);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
  	if (!bp)
  		return XFS_ERROR(EIO);
  	error = XFS_BUF_GETERROR(bp);
  	if (bp && !error && !XFS_FORCED_SHUTDOWN(mp)) {
  		*bpp = bp;
  	} else {
  		*bpp = NULL;
  		if (error) {
  			xfs_ioerror_alert("xfs_read_buf", mp, bp, XFS_BUF_ADDR(bp));
  		} else {
  			error = XFS_ERROR(EIO);
  		}
  		if (bp) {
  			XFS_BUF_UNDONE(bp);
  			XFS_BUF_UNDELAYWRITE(bp);
  			XFS_BUF_STALE(bp);
  			/*
  			 * brelse clears B_ERROR and b_error
  			 */
  			xfs_buf_relse(bp);
  		}
  	}
  	return (error);
  }
  
  /*
5683f53e3   Christoph Hellwig   xfs: uninline xfs...
161
162
163
164
165
166
   * helper function to extract extent size hint from inode
   */
  xfs_extlen_t
  xfs_get_extsz_hint(
  	struct xfs_inode	*ip)
  {
0d8b30ad1   Christoph Hellwig   xfs: fix xfs_get_...
167
168
169
170
171
  	if ((ip->i_d.di_flags & XFS_DIFLAG_EXTSIZE) && ip->i_d.di_extsize)
  		return ip->i_d.di_extsize;
  	if (XFS_IS_REALTIME_INODE(ip))
  		return ip->i_mount->m_sb.sb_rextsize;
  	return 0;
5683f53e3   Christoph Hellwig   xfs: uninline xfs...
172
  }