2 * Copyright (c) 2000-2003 Silicon Graphics, Inc. All Rights Reserved.
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of version 2 of the GNU General Public License as
6 * published by the Free Software Foundation.
8 * This program is distributed in the hope that it would be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 * Further, this software is distributed without any warranty that it is
13 * free of the rightful claim of any third person regarding infringement
14 * or the like. Any license provided herein, whether implied or
15 * otherwise, applies only to this software file. Patent licenses, if
16 * any, provided herein do not apply to combinations of this program with
17 * other software, or any other product whatsoever.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write the Free Software Foundation, Inc., 59
21 * Temple Place - Suite 330, Boston MA 02111-1307, USA.
23 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24 * Mountain View, CA 94043, or:
28 * For further information regarding this notice, see:
30 * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
34 #include "xfs_macros.h"
35 #include "xfs_types.h"
38 #include "xfs_trans.h"
43 #include "xfs_dmapi.h"
44 #include "xfs_mount.h"
45 #include "xfs_alloc_btree.h"
46 #include "xfs_bmap_btree.h"
47 #include "xfs_ialloc_btree.h"
48 #include "xfs_itable.h"
49 #include "xfs_btree.h"
50 #include "xfs_alloc.h"
51 #include "xfs_ialloc.h"
53 #include "xfs_attr_sf.h"
54 #include "xfs_dir_sf.h"
55 #include "xfs_dir2_sf.h"
56 #include "xfs_dinode.h"
57 #include "xfs_inode_item.h"
58 #include "xfs_inode.h"
62 #include "xfs_error.h"
63 #include "xfs_buf_item.h"
67 * This is a subroutine for xfs_write() and other writers (xfs_ioctl)
68 * which clears the setuid and setgid bits when a file is written.
71 xfs_write_clear_setuid(
79 tp = xfs_trans_alloc(mp, XFS_TRANS_WRITEID);
80 if ((error = xfs_trans_reserve(tp, 0,
81 XFS_WRITEID_LOG_RES(mp),
83 xfs_trans_cancel(tp, 0);
86 xfs_ilock(ip, XFS_ILOCK_EXCL);
87 xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL);
88 xfs_trans_ihold(tp, ip);
89 ip->i_d.di_mode &= ~S_ISUID;
92 * Note that we don't have to worry about mandatory
93 * file locking being disabled here because we only
94 * clear the S_ISGID bit if the Group execute bit is
95 * on, but if it was on then mandatory locking wouldn't
98 if (ip->i_d.di_mode & S_IXGRP) {
99 ip->i_d.di_mode &= ~S_ISGID;
101 xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
102 xfs_trans_set_sync(tp);
103 error = xfs_trans_commit(tp, 0, NULL);
104 xfs_iunlock(ip, XFS_ILOCK_EXCL);
109 * Force a shutdown of the filesystem instantly while keeping
110 * the filesystem consistent. We don't do an unmount here; just shutdown
111 * the shop, make sure that absolutely nothing persistent happens to
112 * this filesystem after this point.
116 xfs_do_force_shutdown(
125 mp = XFS_BHVTOM(bdp);
126 logerror = flags & XFS_LOG_IO_ERROR;
128 if (!(flags & XFS_FORCE_UMOUNT)) {
130 "xfs_force_shutdown(%s,0x%x) called from line %d of file %s. Return address = 0x%p",
131 mp->m_fsname,flags,lnnum,fname,__return_address);
134 * No need to duplicate efforts.
136 if (XFS_FORCED_SHUTDOWN(mp) && !logerror)
140 * This flags XFS_MOUNT_FS_SHUTDOWN, makes sure that we don't
141 * queue up anybody new on the log reservations, and wakes up
142 * everybody who's sleeping on log reservations and tells
145 if (xfs_log_force_umount(mp, logerror))
148 if (flags & XFS_CORRUPT_INCORE) {
149 xfs_cmn_err(XFS_PTAG_SHUTDOWN_CORRUPT, CE_ALERT, mp,
150 "Corruption of in-memory data detected. Shutting down filesystem: %s",
152 if (XFS_ERRLEVEL_HIGH <= xfs_error_level) {
155 } else if (!(flags & XFS_FORCE_UMOUNT)) {
157 xfs_cmn_err(XFS_PTAG_SHUTDOWN_LOGERROR, CE_ALERT, mp,
158 "Log I/O Error Detected. Shutting down filesystem: %s",
160 } else if (!(flags & XFS_SHUTDOWN_REMOTE_REQ)) {
161 xfs_cmn_err(XFS_PTAG_SHUTDOWN_IOERROR, CE_ALERT, mp,
162 "I/O Error Detected. Shutting down filesystem: %s",
166 if (!(flags & XFS_FORCE_UMOUNT)) {
168 "Please umount the filesystem, and rectify the problem(s)");
174 * Called when we want to stop a buffer from getting written or read.
175 * We attach the EIO error, muck with its flags, and call biodone
176 * so that the proper iodone callbacks get called.
184 ASSERT(XFS_BUF_ISREAD(bp) || bp->b_iodone);
188 * No need to wait until the buffer is unpinned.
189 * We aren't flushing it.
191 xfs_buftrace("XFS IOERROR", bp);
192 XFS_BUF_ERROR(bp, EIO);
194 * We're calling biodone, so delete B_DONE flag. Either way
195 * we have to call the iodone callback, and calling biodone
196 * probably is the best way since it takes care of
200 XFS_BUF_UNDELAYWRITE(bp);
204 XFS_BUF_CLR_BDSTRAT_FUNC(bp);
211 * Same as xfs_bioerror, except that we are releasing the buffer
212 * here ourselves, and avoiding the biodone call.
213 * This is meant for userdata errors; metadata bufs come with
214 * iodone functions attached, so that we can track down errors.
222 ASSERT(XFS_BUF_IODONE_FUNC(bp) != xfs_buf_iodone_callbacks);
223 ASSERT(XFS_BUF_IODONE_FUNC(bp) != xlog_iodone);
225 xfs_buftrace("XFS IOERRELSE", bp);
226 fl = XFS_BUF_BFLAGS(bp);
228 * No need to wait until the buffer is unpinned.
229 * We aren't flushing it.
231 * chunkhold expects B_DONE to be set, whether
232 * we actually finish the I/O or not. We don't want to
233 * change that interface.
236 XFS_BUF_UNDELAYWRITE(bp);
239 XFS_BUF_CLR_IODONE_FUNC(bp);
240 XFS_BUF_CLR_BDSTRAT_FUNC(bp);
241 if (!(fl & XFS_B_ASYNC)) {
243 * Mark b_error and B_ERROR _both_.
244 * Lot's of chunkcache code assumes that.
245 * There's no reason to mark error for
248 XFS_BUF_ERROR(bp, EIO);
249 XFS_BUF_V_IODONESEMA(bp);
256 * Prints out an ALERT message about I/O error.
261 struct xfs_mount *mp,
266 "I/O error in filesystem (\"%s\") meta-data dev %s block 0x%llx"
267 " (\"%s\") error %d buf count %u",
268 (!mp || !mp->m_fsname) ? "(fs name not set)" : mp->m_fsname,
269 XFS_BUFTARG_NAME(bp->pb_target),
272 XFS_BUF_GETERROR(bp),
277 * This isn't an absolute requirement, but it is
278 * just a good idea to call xfs_read_buf instead of
279 * directly doing a read_buf call. For one, we shouldn't
280 * be doing this disk read if we are in SHUTDOWN state anyway,
281 * so this stops that from happening. Secondly, this does all
282 * the error checking stuff and the brelse if appropriate for
283 * the caller, so the code can be a little leaner.
288 struct xfs_mount *mp,
289 xfs_buftarg_t *target,
299 bp = xfs_buf_read_flags(target, blkno, len, flags);
301 bp = xfs_buf_read(target, blkno, len, flags);
303 return XFS_ERROR(EIO);
304 error = XFS_BUF_GETERROR(bp);
305 if (bp && !error && !XFS_FORCED_SHUTDOWN(mp)) {
310 xfs_ioerror_alert("xfs_read_buf", mp, bp, XFS_BUF_ADDR(bp));
312 error = XFS_ERROR(EIO);
316 XFS_BUF_UNDELAYWRITE(bp);
319 * brelse clears B_ERROR and b_error
328 * Wrapper around bwrite() so that we can trap
329 * write errors, and act accordingly.
333 struct xfs_mount *mp,
339 * XXXsup how does this work for quotas.
341 XFS_BUF_SET_BDSTRAT_FUNC(bp, xfs_bdstrat_cb);
342 XFS_BUF_SET_FSPRIVATE3(bp, mp);
345 if ((error = XFS_bwrite(bp))) {
348 * Cannot put a buftrace here since if the buffer is not
349 * B_HOLD then we will brelse() the buffer before returning
350 * from bwrite and we could be tracing a buffer that has
353 xfs_force_shutdown(mp, XFS_METADATA_IO_ERROR);