2 * Copyright (c) 2000-2003,2005 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
23 #include "xfs_trans.h"
27 #include "xfs_alloc.h"
28 #include "xfs_dmapi.h"
29 #include "xfs_quota.h"
30 #include "xfs_mount.h"
31 #include "xfs_bmap_btree.h"
32 #include "xfs_alloc_btree.h"
33 #include "xfs_ialloc_btree.h"
34 #include "xfs_dir2_sf.h"
35 #include "xfs_attr_sf.h"
36 #include "xfs_dinode.h"
37 #include "xfs_inode.h"
39 #include "xfs_btree.h"
40 #include "xfs_ialloc.h"
41 #include "xfs_rtalloc.h"
42 #include "xfs_error.h"
43 #include "xfs_itable.h"
47 #include "xfs_inode_item.h"
48 #include "xfs_buf_item.h"
49 #include "xfs_utils.h"
50 #include "xfs_iomap.h"
51 #include "xfs_vnodeops.h"
53 #include <linux/capability.h>
54 #include <linux/writeback.h>
57 #if defined(XFS_RW_TRACE)
67 xfs_inode_t *ip = XFS_IO_INODE(io);
69 if (ip->i_rwtrace == NULL)
71 ktrace_enter(ip->i_rwtrace,
72 (void *)(unsigned long)tag,
74 (void *)((unsigned long)((ip->i_d.di_size >> 32) & 0xffffffff)),
75 (void *)((unsigned long)(ip->i_d.di_size & 0xffffffff)),
77 (void *)((unsigned long)segs),
78 (void *)((unsigned long)((offset >> 32) & 0xffffffff)),
79 (void *)((unsigned long)(offset & 0xffffffff)),
80 (void *)((unsigned long)ioflags),
81 (void *)((unsigned long)((io->io_new_size >> 32) & 0xffffffff)),
82 (void *)((unsigned long)(io->io_new_size & 0xffffffff)),
83 (void *)((unsigned long)current_pid()),
91 xfs_inval_cached_trace(
98 xfs_inode_t *ip = XFS_IO_INODE(io);
100 if (ip->i_rwtrace == NULL)
102 ktrace_enter(ip->i_rwtrace,
103 (void *)(__psint_t)XFS_INVAL_CACHED,
105 (void *)((unsigned long)((offset >> 32) & 0xffffffff)),
106 (void *)((unsigned long)(offset & 0xffffffff)),
107 (void *)((unsigned long)((len >> 32) & 0xffffffff)),
108 (void *)((unsigned long)(len & 0xffffffff)),
109 (void *)((unsigned long)((first >> 32) & 0xffffffff)),
110 (void *)((unsigned long)(first & 0xffffffff)),
111 (void *)((unsigned long)((last >> 32) & 0xffffffff)),
112 (void *)((unsigned long)(last & 0xffffffff)),
113 (void *)((unsigned long)current_pid()),
125 * xfs_iozero clears the specified range of buffer supplied,
126 * and marks all the affected blocks as valid and modified. If
127 * an affected block is not allocated, it will be allocated. If
128 * an affected block is not completely overwritten, and is not
129 * valid before the operation, it will be read from disk before
130 * being partially zeroed.
134 struct inode *ip, /* inode */
135 loff_t pos, /* offset in file */
136 size_t count) /* size of data to zero */
139 struct address_space *mapping;
142 mapping = ip->i_mapping;
144 unsigned offset, bytes;
147 offset = (pos & (PAGE_CACHE_SIZE -1)); /* Within page */
148 bytes = PAGE_CACHE_SIZE - offset;
152 status = pagecache_write_begin(NULL, mapping, pos, bytes,
153 AOP_FLAG_UNINTERRUPTIBLE,
158 zero_user_page(page, offset, bytes, KM_USER0);
160 status = pagecache_write_end(NULL, mapping, pos, bytes, bytes,
162 WARN_ON(status <= 0); /* can't return less than zero! */
171 ssize_t /* bytes read, or (-) error */
175 const struct iovec *iovp,
180 struct file *file = iocb->ki_filp;
181 struct inode *inode = file->f_mapping->host;
182 bhv_vnode_t *vp = XFS_ITOV(ip);
183 xfs_mount_t *mp = ip->i_mount;
190 XFS_STATS_INC(xs_read_calls);
192 /* START copy & waste from filemap.c */
193 for (seg = 0; seg < segs; seg++) {
194 const struct iovec *iv = &iovp[seg];
197 * If any segment has a negative length, or the cumulative
198 * length ever wraps negative then return -EINVAL.
201 if (unlikely((ssize_t)(size|iv->iov_len) < 0))
202 return XFS_ERROR(-EINVAL);
204 /* END copy & waste from filemap.c */
206 if (unlikely(ioflags & IO_ISDIRECT)) {
207 xfs_buftarg_t *target =
208 (ip->i_d.di_flags & XFS_DIFLAG_REALTIME) ?
209 mp->m_rtdev_targp : mp->m_ddev_targp;
210 if ((*offset & target->bt_smask) ||
211 (size & target->bt_smask)) {
212 if (*offset == ip->i_size) {
215 return -XFS_ERROR(EINVAL);
219 n = XFS_MAXIOFFSET(mp) - *offset;
220 if ((n <= 0) || (size == 0))
226 if (XFS_FORCED_SHUTDOWN(mp))
229 if (unlikely(ioflags & IO_ISDIRECT))
230 mutex_lock(&inode->i_mutex);
231 xfs_ilock(ip, XFS_IOLOCK_SHARED);
233 if (DM_EVENT_ENABLED(ip, DM_EVENT_READ) && !(ioflags & IO_INVIS)) {
234 bhv_vrwlock_t locktype = VRWLOCK_READ;
235 int dmflags = FILP_DELAY_FLAG(file) | DM_SEM_FLAG_RD(ioflags);
237 ret = -XFS_SEND_DATA(mp, DM_EVENT_READ, vp, *offset, size,
240 xfs_iunlock(ip, XFS_IOLOCK_SHARED);
241 if (unlikely(ioflags & IO_ISDIRECT))
242 mutex_unlock(&inode->i_mutex);
247 if (unlikely(ioflags & IO_ISDIRECT)) {
249 ret = xfs_flushinval_pages(ip,
250 ctooff(offtoct(*offset)),
251 -1, FI_REMAPF_LOCKED);
252 mutex_unlock(&inode->i_mutex);
254 xfs_iunlock(ip, XFS_IOLOCK_SHARED);
259 xfs_rw_enter_trace(XFS_READ_ENTER, &ip->i_iocore,
260 (void *)iovp, segs, *offset, ioflags);
262 iocb->ki_pos = *offset;
263 ret = generic_file_aio_read(iocb, iovp, segs, *offset);
264 if (ret == -EIOCBQUEUED && !(ioflags & IO_ISAIO))
265 ret = wait_on_sync_kiocb(iocb);
267 XFS_STATS_ADD(xs_read_bytes, ret);
269 xfs_iunlock(ip, XFS_IOLOCK_SHARED);
278 struct pipe_inode_info *pipe,
283 bhv_vnode_t *vp = XFS_ITOV(ip);
284 xfs_mount_t *mp = ip->i_mount;
287 XFS_STATS_INC(xs_read_calls);
288 if (XFS_FORCED_SHUTDOWN(ip->i_mount))
291 xfs_ilock(ip, XFS_IOLOCK_SHARED);
293 if (DM_EVENT_ENABLED(ip, DM_EVENT_READ) && !(ioflags & IO_INVIS)) {
294 bhv_vrwlock_t locktype = VRWLOCK_READ;
297 error = XFS_SEND_DATA(mp, DM_EVENT_READ, vp, *ppos, count,
298 FILP_DELAY_FLAG(infilp), &locktype);
300 xfs_iunlock(ip, XFS_IOLOCK_SHARED);
304 xfs_rw_enter_trace(XFS_SPLICE_READ_ENTER, &ip->i_iocore,
305 pipe, count, *ppos, ioflags);
306 ret = generic_file_splice_read(infilp, ppos, pipe, count, flags);
308 XFS_STATS_ADD(xs_read_bytes, ret);
310 xfs_iunlock(ip, XFS_IOLOCK_SHARED);
317 struct pipe_inode_info *pipe,
318 struct file *outfilp,
324 bhv_vnode_t *vp = XFS_ITOV(ip);
325 xfs_mount_t *mp = ip->i_mount;
326 xfs_iocore_t *io = &ip->i_iocore;
328 struct inode *inode = outfilp->f_mapping->host;
329 xfs_fsize_t isize, new_size;
331 XFS_STATS_INC(xs_write_calls);
332 if (XFS_FORCED_SHUTDOWN(ip->i_mount))
335 xfs_ilock(ip, XFS_IOLOCK_EXCL);
337 if (DM_EVENT_ENABLED(ip, DM_EVENT_WRITE) && !(ioflags & IO_INVIS)) {
338 bhv_vrwlock_t locktype = VRWLOCK_WRITE;
341 error = XFS_SEND_DATA(mp, DM_EVENT_WRITE, vp, *ppos, count,
342 FILP_DELAY_FLAG(outfilp), &locktype);
344 xfs_iunlock(ip, XFS_IOLOCK_EXCL);
349 new_size = *ppos + count;
351 xfs_ilock(ip, XFS_ILOCK_EXCL);
352 if (new_size > ip->i_size)
353 io->io_new_size = new_size;
354 xfs_iunlock(ip, XFS_ILOCK_EXCL);
356 xfs_rw_enter_trace(XFS_SPLICE_WRITE_ENTER, &ip->i_iocore,
357 pipe, count, *ppos, ioflags);
358 ret = generic_file_splice_write(pipe, outfilp, ppos, count, flags);
360 XFS_STATS_ADD(xs_write_bytes, ret);
362 isize = i_size_read(inode);
363 if (unlikely(ret < 0 && ret != -EFAULT && *ppos > isize))
366 if (*ppos > ip->i_size) {
367 xfs_ilock(ip, XFS_ILOCK_EXCL);
368 if (*ppos > ip->i_size)
370 xfs_iunlock(ip, XFS_ILOCK_EXCL);
373 if (io->io_new_size) {
374 xfs_ilock(ip, XFS_ILOCK_EXCL);
376 if (ip->i_d.di_size > ip->i_size)
377 ip->i_d.di_size = ip->i_size;
378 xfs_iunlock(ip, XFS_ILOCK_EXCL);
380 xfs_iunlock(ip, XFS_IOLOCK_EXCL);
385 * This routine is called to handle zeroing any space in the last
386 * block of the file that is beyond the EOF. We do this since the
387 * size is being increased without writing anything to that block
388 * and we don't want anyone to read the garbage on the disk.
390 STATIC int /* error (positive) */
397 xfs_fileoff_t last_fsb;
398 xfs_mount_t *mp = io->io_mount;
403 xfs_bmbt_irec_t imap;
405 ASSERT(ismrlocked(io->io_lock, MR_UPDATE) != 0);
407 zero_offset = XFS_B_FSB_OFFSET(mp, isize);
408 if (zero_offset == 0) {
410 * There are no extra bytes in the last block on disk to
416 last_fsb = XFS_B_TO_FSBT(mp, isize);
418 error = XFS_BMAPI(mp, NULL, io, last_fsb, 1, 0, NULL, 0, &imap,
419 &nimaps, NULL, NULL);
425 * If the block underlying isize is just a hole, then there
426 * is nothing to zero.
428 if (imap.br_startblock == HOLESTARTBLOCK) {
432 * Zero the part of the last block beyond the EOF, and write it
433 * out sync. We need to drop the ilock while we do this so we
434 * don't deadlock when the buffer cache calls back to us.
436 XFS_IUNLOCK(mp, io, XFS_ILOCK_EXCL| XFS_EXTSIZE_RD);
438 zero_len = mp->m_sb.sb_blocksize - zero_offset;
439 if (isize + zero_len > offset)
440 zero_len = offset - isize;
441 error = xfs_iozero(ip, isize, zero_len);
443 XFS_ILOCK(mp, io, XFS_ILOCK_EXCL|XFS_EXTSIZE_RD);
449 * Zero any on disk space between the current EOF and the new,
450 * larger EOF. This handles the normal case of zeroing the remainder
451 * of the last block in the file and the unusual case of zeroing blocks
452 * out beyond the size of the file. This second case only happens
453 * with fixed size extents and when the system crashes before the inode
454 * size was updated but after blocks were allocated. If fill is set,
455 * then any holes in the range are filled and zeroed. If not, the holes
456 * are left alone as holes.
459 int /* error (positive) */
463 xfs_off_t offset, /* starting I/O offset */
464 xfs_fsize_t isize) /* current inode size */
466 struct inode *ip = vn_to_inode(vp);
467 xfs_fileoff_t start_zero_fsb;
468 xfs_fileoff_t end_zero_fsb;
469 xfs_fileoff_t zero_count_fsb;
470 xfs_fileoff_t last_fsb;
471 xfs_fileoff_t zero_off;
472 xfs_fsize_t zero_len;
473 xfs_mount_t *mp = io->io_mount;
476 xfs_bmbt_irec_t imap;
478 ASSERT(ismrlocked(io->io_lock, MR_UPDATE));
479 ASSERT(ismrlocked(io->io_iolock, MR_UPDATE));
480 ASSERT(offset > isize);
483 * First handle zeroing the block on which isize resides.
484 * We only zero a part of that block so it is handled specially.
486 error = xfs_zero_last_block(ip, io, offset, isize);
488 ASSERT(ismrlocked(io->io_lock, MR_UPDATE));
489 ASSERT(ismrlocked(io->io_iolock, MR_UPDATE));
494 * Calculate the range between the new size and the old
495 * where blocks needing to be zeroed may exist. To get the
496 * block where the last byte in the file currently resides,
497 * we need to subtract one from the size and truncate back
498 * to a block boundary. We subtract 1 in case the size is
499 * exactly on a block boundary.
501 last_fsb = isize ? XFS_B_TO_FSBT(mp, isize - 1) : (xfs_fileoff_t)-1;
502 start_zero_fsb = XFS_B_TO_FSB(mp, (xfs_ufsize_t)isize);
503 end_zero_fsb = XFS_B_TO_FSBT(mp, offset - 1);
504 ASSERT((xfs_sfiloff_t)last_fsb < (xfs_sfiloff_t)start_zero_fsb);
505 if (last_fsb == end_zero_fsb) {
507 * The size was only incremented on its last block.
508 * We took care of that above, so just return.
513 ASSERT(start_zero_fsb <= end_zero_fsb);
514 while (start_zero_fsb <= end_zero_fsb) {
516 zero_count_fsb = end_zero_fsb - start_zero_fsb + 1;
517 error = XFS_BMAPI(mp, NULL, io, start_zero_fsb, zero_count_fsb,
518 0, NULL, 0, &imap, &nimaps, NULL, NULL);
520 ASSERT(ismrlocked(io->io_lock, MR_UPDATE));
521 ASSERT(ismrlocked(io->io_iolock, MR_UPDATE));
526 if (imap.br_state == XFS_EXT_UNWRITTEN ||
527 imap.br_startblock == HOLESTARTBLOCK) {
529 * This loop handles initializing pages that were
530 * partially initialized by the code below this
531 * loop. It basically zeroes the part of the page
532 * that sits on a hole and sets the page as P_HOLE
533 * and calls remapf if it is a mapped file.
535 start_zero_fsb = imap.br_startoff + imap.br_blockcount;
536 ASSERT(start_zero_fsb <= (end_zero_fsb + 1));
541 * There are blocks we need to zero.
542 * Drop the inode lock while we're doing the I/O.
543 * We'll still have the iolock to protect us.
545 XFS_IUNLOCK(mp, io, XFS_ILOCK_EXCL|XFS_EXTSIZE_RD);
547 zero_off = XFS_FSB_TO_B(mp, start_zero_fsb);
548 zero_len = XFS_FSB_TO_B(mp, imap.br_blockcount);
550 if ((zero_off + zero_len) > offset)
551 zero_len = offset - zero_off;
553 error = xfs_iozero(ip, zero_off, zero_len);
558 start_zero_fsb = imap.br_startoff + imap.br_blockcount;
559 ASSERT(start_zero_fsb <= (end_zero_fsb + 1));
561 XFS_ILOCK(mp, io, XFS_ILOCK_EXCL|XFS_EXTSIZE_RD);
568 XFS_ILOCK(mp, io, XFS_ILOCK_EXCL|XFS_EXTSIZE_RD);
573 ssize_t /* bytes written, or (-) error */
575 struct xfs_inode *xip,
577 const struct iovec *iovp,
582 struct file *file = iocb->ki_filp;
583 struct address_space *mapping = file->f_mapping;
584 struct inode *inode = mapping->host;
585 bhv_vnode_t *vp = XFS_ITOV(xip);
586 unsigned long segs = nsegs;
588 ssize_t ret = 0, error = 0;
589 xfs_fsize_t isize, new_size;
593 bhv_vrwlock_t locktype;
594 size_t ocount = 0, count;
598 XFS_STATS_INC(xs_write_calls);
600 error = generic_segment_checks(iovp, &segs, &ocount, VERIFY_READ);
613 xfs_wait_for_freeze(mp, SB_FREEZE_WRITE);
615 if (XFS_FORCED_SHUTDOWN(mp))
619 if (ioflags & IO_ISDIRECT) {
620 iolock = XFS_IOLOCK_SHARED;
621 locktype = VRWLOCK_WRITE_DIRECT;
624 iolock = XFS_IOLOCK_EXCL;
625 locktype = VRWLOCK_WRITE;
627 mutex_lock(&inode->i_mutex);
630 xfs_ilock(xip, XFS_ILOCK_EXCL|iolock);
633 error = -generic_write_checks(file, &pos, &count,
634 S_ISBLK(inode->i_mode));
636 xfs_iunlock(xip, XFS_ILOCK_EXCL|iolock);
637 goto out_unlock_mutex;
640 if ((DM_EVENT_ENABLED(xip, DM_EVENT_WRITE) &&
641 !(ioflags & IO_INVIS) && !eventsent)) {
642 int dmflags = FILP_DELAY_FLAG(file);
645 dmflags |= DM_FLAGS_IMUX;
647 xfs_iunlock(xip, XFS_ILOCK_EXCL);
648 error = XFS_SEND_DATA(xip->i_mount, DM_EVENT_WRITE, vp,
652 goto out_unlock_internal;
654 xfs_ilock(xip, XFS_ILOCK_EXCL);
658 * The iolock was dropped and reacquired in XFS_SEND_DATA
659 * so we have to recheck the size when appending.
660 * We will only "goto start;" once, since having sent the
661 * event prevents another call to XFS_SEND_DATA, which is
662 * what allows the size to change in the first place.
664 if ((file->f_flags & O_APPEND) && pos != xip->i_size)
668 if (ioflags & IO_ISDIRECT) {
669 xfs_buftarg_t *target =
670 (xip->i_d.di_flags & XFS_DIFLAG_REALTIME) ?
671 mp->m_rtdev_targp : mp->m_ddev_targp;
673 if ((pos & target->bt_smask) || (count & target->bt_smask)) {
674 xfs_iunlock(xip, XFS_ILOCK_EXCL|iolock);
675 return XFS_ERROR(-EINVAL);
678 if (!need_i_mutex && (VN_CACHED(vp) || pos > xip->i_size)) {
679 xfs_iunlock(xip, XFS_ILOCK_EXCL|iolock);
680 iolock = XFS_IOLOCK_EXCL;
681 locktype = VRWLOCK_WRITE;
683 mutex_lock(&inode->i_mutex);
684 xfs_ilock(xip, XFS_ILOCK_EXCL|iolock);
689 new_size = pos + count;
690 if (new_size > xip->i_size)
691 io->io_new_size = new_size;
693 if (likely(!(ioflags & IO_INVIS))) {
694 file_update_time(file);
695 xfs_ichgtime_fast(xip, inode,
696 XFS_ICHGTIME_MOD | XFS_ICHGTIME_CHG);
700 * If the offset is beyond the size of the file, we have a couple
701 * of things to do. First, if there is already space allocated
702 * we need to either create holes or zero the disk or ...
704 * If there is a page where the previous size lands, we need
705 * to zero it out up to the new size.
708 if (pos > xip->i_size) {
709 error = xfs_zero_eof(vp, io, pos, xip->i_size);
711 xfs_iunlock(xip, XFS_ILOCK_EXCL);
712 goto out_unlock_internal;
715 xfs_iunlock(xip, XFS_ILOCK_EXCL);
718 * If we're writing the file then make sure to clear the
719 * setuid and setgid bits if the process is not being run
720 * by root. This keeps people from modifying setuid and
724 if (((xip->i_d.di_mode & S_ISUID) ||
725 ((xip->i_d.di_mode & (S_ISGID | S_IXGRP)) ==
726 (S_ISGID | S_IXGRP))) &&
727 !capable(CAP_FSETID)) {
728 error = xfs_write_clear_setuid(xip);
730 error = -remove_suid(file->f_path.dentry);
731 if (unlikely(error)) {
732 goto out_unlock_internal;
737 /* We can write back this queue in page reclaim */
738 current->backing_dev_info = mapping->backing_dev_info;
740 if ((ioflags & IO_ISDIRECT)) {
742 WARN_ON(need_i_mutex == 0);
743 xfs_inval_cached_trace(io, pos, -1,
744 ctooff(offtoct(pos)), -1);
745 error = xfs_flushinval_pages(xip,
746 ctooff(offtoct(pos)),
747 -1, FI_REMAPF_LOCKED);
749 goto out_unlock_internal;
753 /* demote the lock now the cached pages are gone */
754 XFS_ILOCK_DEMOTE(mp, io, XFS_IOLOCK_EXCL);
755 mutex_unlock(&inode->i_mutex);
757 iolock = XFS_IOLOCK_SHARED;
758 locktype = VRWLOCK_WRITE_DIRECT;
762 xfs_rw_enter_trace(XFS_DIOWR_ENTER, io, (void *)iovp, segs,
764 ret = generic_file_direct_write(iocb, iovp,
765 &segs, pos, offset, count, ocount);
768 * direct-io write to a hole: fall through to buffered I/O
769 * for completing the rest of the request.
771 if (ret >= 0 && ret != count) {
772 XFS_STATS_ADD(xs_write_bytes, ret);
777 ioflags &= ~IO_ISDIRECT;
778 xfs_iunlock(xip, iolock);
782 xfs_rw_enter_trace(XFS_WRITE_ENTER, io, (void *)iovp, segs,
784 ret = generic_file_buffered_write(iocb, iovp, segs,
785 pos, offset, count, ret);
788 current->backing_dev_info = NULL;
790 if (ret == -EIOCBQUEUED && !(ioflags & IO_ISAIO))
791 ret = wait_on_sync_kiocb(iocb);
793 if (ret == -ENOSPC &&
794 DM_EVENT_ENABLED(xip, DM_EVENT_NOSPACE) && !(ioflags & IO_INVIS)) {
795 xfs_rwunlock(xip, locktype);
797 mutex_unlock(&inode->i_mutex);
798 error = XFS_SEND_NAMESP(xip->i_mount, DM_EVENT_NOSPACE, vp,
799 DM_RIGHT_NULL, vp, DM_RIGHT_NULL, NULL, NULL,
800 0, 0, 0); /* Delay flag intentionally unused */
802 mutex_lock(&inode->i_mutex);
803 xfs_rwlock(xip, locktype);
805 goto out_unlock_internal;
811 isize = i_size_read(inode);
812 if (unlikely(ret < 0 && ret != -EFAULT && *offset > isize))
815 if (*offset > xip->i_size) {
816 xfs_ilock(xip, XFS_ILOCK_EXCL);
817 if (*offset > xip->i_size)
818 xip->i_size = *offset;
819 xfs_iunlock(xip, XFS_ILOCK_EXCL);
824 goto out_unlock_internal;
826 XFS_STATS_ADD(xs_write_bytes, ret);
828 /* Handle various SYNC-type writes */
829 if ((file->f_flags & O_SYNC) || IS_SYNC(inode)) {
831 xfs_rwunlock(xip, locktype);
833 mutex_unlock(&inode->i_mutex);
834 error2 = sync_page_range(inode, mapping, pos, ret);
838 mutex_lock(&inode->i_mutex);
839 xfs_rwlock(xip, locktype);
840 error2 = xfs_write_sync_logforce(mp, xip);
846 if (io->io_new_size) {
847 xfs_ilock(xip, XFS_ILOCK_EXCL);
850 * If this was a direct or synchronous I/O that failed (such
851 * as ENOSPC) then part of the I/O may have been written to
852 * disk before the error occured. In this case the on-disk
853 * file size may have been adjusted beyond the in-memory file
854 * size and now needs to be truncated back.
856 if (xip->i_d.di_size > xip->i_size)
857 xip->i_d.di_size = xip->i_size;
858 xfs_iunlock(xip, XFS_ILOCK_EXCL);
860 xfs_rwunlock(xip, locktype);
863 mutex_unlock(&inode->i_mutex);
868 * All xfs metadata buffers except log state machine buffers
869 * get this attached as their b_bdstrat callback function.
870 * This is so that we can catch a buffer
871 * after prematurely unpinning it to forcibly shutdown the filesystem.
874 xfs_bdstrat_cb(struct xfs_buf *bp)
878 mp = XFS_BUF_FSPRIVATE3(bp, xfs_mount_t *);
879 if (!XFS_FORCED_SHUTDOWN(mp)) {
880 xfs_buf_iorequest(bp);
883 xfs_buftrace("XFS__BDSTRAT IOERROR", bp);
885 * Metadata write that didn't get logged but
886 * written delayed anyway. These aren't associated
887 * with a transaction, and can be ignored.
889 if (XFS_BUF_IODONE_FUNC(bp) == NULL &&
890 (XFS_BUF_ISREAD(bp)) == 0)
891 return (xfs_bioerror_relse(bp));
893 return (xfs_bioerror(bp));
907 xfs_iocore_t *io = &ip->i_iocore;
909 ASSERT((ip->i_d.di_mode & S_IFMT) == S_IFREG);
910 ASSERT(((ip->i_d.di_flags & XFS_DIFLAG_REALTIME) != 0) ==
911 ((ip->i_iocore.io_flags & XFS_IOCORE_RT) != 0));
913 return xfs_iomap(io, offset, count, flags, iomapp, niomaps);
917 * Wrapper around bdstrat so that we can stop data
918 * from going to disk in case we are shutting down the filesystem.
919 * Typically user data goes thru this path; one of the exceptions
924 struct xfs_mount *mp,
928 if (!XFS_FORCED_SHUTDOWN(mp)) {
929 /* Grio redirection would go here
930 * if (XFS_BUF_IS_GRIO(bp)) {
933 xfs_buf_iorequest(bp);
937 xfs_buftrace("XFSBDSTRAT IOERROR", bp);
938 return (xfs_bioerror_relse(bp));
942 * If the underlying (data/log/rt) device is readonly, there are some
943 * operations that cannot proceed.
946 xfs_dev_is_read_only(
950 if (xfs_readonly_buftarg(mp->m_ddev_targp) ||
951 xfs_readonly_buftarg(mp->m_logdev_targp) ||
952 (mp->m_rtdev_targp && xfs_readonly_buftarg(mp->m_rtdev_targp))) {
954 "XFS: %s required on read-only device.", message);
956 "XFS: write access unavailable, cannot proceed.");