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/
33 * fs/xfs/linux/xfs_lrw.c (Linux Read Write stuff)
42 #include "xfs_trans.h"
47 #include "xfs_alloc.h"
48 #include "xfs_dmapi.h"
49 #include "xfs_quota.h"
50 #include "xfs_mount.h"
51 #include "xfs_alloc_btree.h"
52 #include "xfs_bmap_btree.h"
53 #include "xfs_ialloc_btree.h"
54 #include "xfs_btree.h"
55 #include "xfs_ialloc.h"
56 #include "xfs_attr_sf.h"
57 #include "xfs_dir_sf.h"
58 #include "xfs_dir2_sf.h"
59 #include "xfs_dinode.h"
60 #include "xfs_inode.h"
63 #include "xfs_rtalloc.h"
64 #include "xfs_error.h"
65 #include "xfs_itable.h"
67 #include "xfs_refcache.h"
72 #include "xfs_inode_item.h"
73 #include "xfs_buf_item.h"
74 #include "xfs_utils.h"
75 #include "xfs_iomap.h"
77 #if defined(XFS_RW_TRACE)
87 xfs_inode_t *ip = XFS_IO_INODE(io);
89 if (ip->i_rwtrace == NULL)
91 ktrace_enter(ip->i_rwtrace,
92 (void *)(unsigned long)tag,
94 (void *)((unsigned long)((ip->i_d.di_size >> 32) & 0xffffffff)),
95 (void *)((unsigned long)(ip->i_d.di_size & 0xffffffff)),
96 (void *)(__psint_t)buf,
97 (void *)((unsigned long)size),
98 (void *)((unsigned long)((offset >> 32) & 0xffffffff)),
99 (void *)((unsigned long)(offset & 0xffffffff)),
100 (void *)((unsigned long)ioflags),
101 (void *)((unsigned long)((io->io_new_size >> 32) & 0xffffffff)),
102 (void *)((unsigned long)(io->io_new_size & 0xffffffff)),
111 xfs_inval_cached_trace(
118 xfs_inode_t *ip = XFS_IO_INODE(io);
120 if (ip->i_rwtrace == NULL)
122 ktrace_enter(ip->i_rwtrace,
123 (void *)(__psint_t)XFS_INVAL_CACHED,
125 (void *)((unsigned long)((offset >> 32) & 0xffffffff)),
126 (void *)((unsigned long)(offset & 0xffffffff)),
127 (void *)((unsigned long)((len >> 32) & 0xffffffff)),
128 (void *)((unsigned long)(len & 0xffffffff)),
129 (void *)((unsigned long)((first >> 32) & 0xffffffff)),
130 (void *)((unsigned long)(first & 0xffffffff)),
131 (void *)((unsigned long)((last >> 32) & 0xffffffff)),
132 (void *)((unsigned long)(last & 0xffffffff)),
145 * xfs_iozero clears the specified range of buffer supplied,
146 * and marks all the affected blocks as valid and modified. If
147 * an affected block is not allocated, it will be allocated. If
148 * an affected block is not completely overwritten, and is not
149 * valid before the operation, it will be read from disk before
150 * being partially zeroed.
154 xfs_vnode_t *vp, /* vnode */
155 loff_t pos, /* offset in file */
156 size_t count, /* size of data to zero */
157 loff_t end_size) /* max file size to set */
162 struct address_space *mapping;
166 mapping = ip->i_mapping;
168 unsigned long index, offset;
170 offset = (pos & (PAGE_CACHE_SIZE -1)); /* Within page */
171 index = pos >> PAGE_CACHE_SHIFT;
172 bytes = PAGE_CACHE_SIZE - offset;
177 page = grab_cache_page(mapping, index);
182 status = mapping->a_ops->prepare_write(NULL, page, offset,
188 memset((void *) (kaddr + offset), 0, bytes);
189 flush_dcache_page(page);
190 status = mapping->a_ops->commit_write(NULL, page, offset,
195 if (pos > i_size_read(ip))
196 i_size_write(ip, pos < end_size ? pos : end_size);
202 page_cache_release(page);
213 * xfs_inval_cached_pages
215 * This routine is responsible for keeping direct I/O and buffered I/O
216 * somewhat coherent. From here we make sure that we're at least
217 * temporarily holding the inode I/O lock exclusively and then call
218 * the page cache to flush and invalidate any cached pages. If there
219 * are no cached pages this routine will be very quick.
222 xfs_inval_cached_pages(
231 if (!VN_CACHED(vp)) {
238 * We need to get the I/O lock exclusively in order
239 * to safely invalidate pages and mappings.
242 XFS_IUNLOCK(mp, io, XFS_IOLOCK_SHARED);
243 XFS_ILOCK(mp, io, XFS_IOLOCK_EXCL);
246 /* Writing beyond EOF creates a hole that must be zeroed */
247 if (write && (offset > XFS_SIZE(mp, io))) {
250 XFS_ILOCK(mp, io, XFS_ILOCK_EXCL|XFS_EXTSIZE_RD);
251 isize = XFS_SIZE(mp, io);
252 if (offset > isize) {
253 xfs_zero_eof(vp, io, offset, isize, offset);
255 XFS_IUNLOCK(mp, io, XFS_ILOCK_EXCL|XFS_EXTSIZE_RD);
258 xfs_inval_cached_trace(io, offset, -1, ctooff(offtoct(offset)), -1);
259 XVOP_FLUSHINVAL_PAGES(vp, ctooff(offtoct(offset)), -1, FI_REMAPF_LOCKED);
261 XFS_ILOCK_DEMOTE(mp, io, XFS_IOLOCK_EXCL);
266 xfs_read_file(xfs_mount_t *mp, xfs_inode_t *ip, struct uio *uio, int ioflag);
268 ssize_t /* bytes read, or (-) error */
280 ip = XFS_BHVTOI(bdp);
283 XFS_STATS_INC(xs_read_calls);
285 if (unlikely(ioflags & IO_ISDIRECT)) {
286 if (((__psint_t)buf & BBMASK) ||
287 (uio->uio_offset & mp->m_blockmask) ||
288 (uio->uio_resid & mp->m_blockmask)) {
289 if (uio->uio_offset >= ip->i_d.di_size) {
296 if (uio->uio_resid == 0)
298 n = XFS_MAXIOFFSET(mp) - uio->uio_offset;
302 size = (n < uio->uio_resid)? n : uio->uio_resid;
304 if (XFS_FORCED_SHUTDOWN(mp)) {
308 if (!(ioflags & IO_ISLOCKED))
309 xfs_ilock(ip, XFS_IOLOCK_SHARED);
311 if (DM_EVENT_ENABLED(BHV_TO_VNODE(bdp)->v_vfsp, ip, DM_EVENT_READ) &&
312 !(ioflags & IO_INVIS)) {
314 vrwlock_t locktype = VRWLOCK_READ;
315 int dmflags = FILP_DELAY_FLAG(file) | DM_SEM_FLAG_RD(ioflags);
317 error = XFS_SEND_DATA(mp, DM_EVENT_READ, BHV_TO_VNODE(bdp),
318 uio->uio_offset, size, dmflags, &locktype);
320 if (!(ioflags & IO_ISLOCKED))
321 xfs_iunlock(ip, XFS_IOLOCK_SHARED);
326 if (unlikely(ioflags & IO_ISDIRECT)) {
327 xfs_rw_enter_trace(XFS_DIORD_ENTER, &ip->i_iocore,
328 buf, size, *offset, ioflags);
329 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,22)
330 xfs_off_t pos = uio->uio_offset;
332 ret = generic_file_direct_IO(READ, file, buf, size, pos);
334 uio->uio_offset = pos + ret;
336 UPDATE_ATIME(file->f_dentry->d_inode);
338 ret = generic_file_read(file, buf, size, offset);
341 xfs_rw_enter_trace(XFS_READ_ENTER, &ip->i_iocore,
342 buf, size, *offset, ioflags);
343 ret = generic_file_read(file, buf, size, offset);
346 ret = xfs_read_file(mp, ip, uio, ioflags);
349 if (!(ioflags & IO_ISLOCKED))
350 xfs_iunlock(ip, XFS_IOLOCK_SHARED);
352 XFS_STATS_ADD(xs_read_bytes, ret);
354 if (likely((ioflags & IO_INVIS) == 0)) {
355 xfs_ichgtime(ip, XFS_ICHGTIME_ACC);
362 * This routine is called to handle zeroing any space in the last
363 * block of the file that is beyond the EOF. We do this since the
364 * size is being increased without writing anything to that block
365 * and we don't want anyone to read the garbage on the disk.
367 STATIC int /* error (positive) */
373 xfs_fsize_t end_size)
375 xfs_fileoff_t last_fsb;
380 int isize_fsb_offset;
382 xfs_bmbt_irec_t imap;
386 ASSERT(ismrlocked(io->io_lock, MR_UPDATE) != 0);
387 ASSERT(offset > isize);
391 isize_fsb_offset = XFS_B_FSB_OFFSET(mp, isize);
392 if (isize_fsb_offset == 0) {
394 * There are no extra bytes in the last block on disk to
400 last_fsb = XFS_B_TO_FSBT(mp, isize);
402 error = XFS_BMAPI(mp, NULL, io, last_fsb, 1, 0, NULL, 0, &imap,
409 * If the block underlying isize is just a hole, then there
410 * is nothing to zero.
412 if (imap.br_startblock == HOLESTARTBLOCK) {
416 * Zero the part of the last block beyond the EOF, and write it
417 * out sync. We need to drop the ilock while we do this so we
418 * don't deadlock when the buffer cache calls back to us.
420 XFS_IUNLOCK(mp, io, XFS_ILOCK_EXCL| XFS_EXTSIZE_RD);
421 loff = XFS_FSB_TO_B(mp, last_fsb);
422 lsize = XFS_FSB_TO_B(mp, 1);
424 zero_offset = isize_fsb_offset;
425 zero_len = mp->m_sb.sb_blocksize - isize_fsb_offset;
427 error = xfs_iozero(vp, loff + zero_offset, zero_len, end_size);
429 XFS_ILOCK(mp, io, XFS_ILOCK_EXCL|XFS_EXTSIZE_RD);
435 * Zero any on disk space between the current EOF and the new,
436 * larger EOF. This handles the normal case of zeroing the remainder
437 * of the last block in the file and the unusual case of zeroing blocks
438 * out beyond the size of the file. This second case only happens
439 * with fixed size extents and when the system crashes before the inode
440 * size was updated but after blocks were allocated. If fill is set,
441 * then any holes in the range are filled and zeroed. If not, the holes
442 * are left alone as holes.
445 int /* error (positive) */
449 xfs_off_t offset, /* starting I/O offset */
450 xfs_fsize_t isize, /* current inode size */
451 xfs_fsize_t end_size) /* terminal inode size */
453 xfs_fileoff_t start_zero_fsb;
454 xfs_fileoff_t end_zero_fsb;
455 xfs_fileoff_t prev_zero_fsb;
456 xfs_fileoff_t zero_count_fsb;
457 xfs_fileoff_t last_fsb;
458 xfs_extlen_t buf_len_fsb;
459 xfs_extlen_t prev_zero_count;
463 xfs_bmbt_irec_t imap;
467 ASSERT(ismrlocked(io->io_lock, MR_UPDATE));
468 ASSERT(ismrlocked(io->io_iolock, MR_UPDATE));
473 * First handle zeroing the block on which isize resides.
474 * We only zero a part of that block so it is handled specially.
476 error = xfs_zero_last_block(vp, io, offset, isize, end_size);
478 ASSERT(ismrlocked(io->io_lock, MR_UPDATE));
479 ASSERT(ismrlocked(io->io_iolock, MR_UPDATE));
484 * Calculate the range between the new size and the old
485 * where blocks needing to be zeroed may exist. To get the
486 * block where the last byte in the file currently resides,
487 * we need to subtract one from the size and truncate back
488 * to a block boundary. We subtract 1 in case the size is
489 * exactly on a block boundary.
491 last_fsb = isize ? XFS_B_TO_FSBT(mp, isize - 1) : (xfs_fileoff_t)-1;
492 start_zero_fsb = XFS_B_TO_FSB(mp, (xfs_ufsize_t)isize);
493 end_zero_fsb = XFS_B_TO_FSBT(mp, offset - 1);
494 ASSERT((xfs_sfiloff_t)last_fsb < (xfs_sfiloff_t)start_zero_fsb);
495 if (last_fsb == end_zero_fsb) {
497 * The size was only incremented on its last block.
498 * We took care of that above, so just return.
503 ASSERT(start_zero_fsb <= end_zero_fsb);
504 prev_zero_fsb = NULLFILEOFF;
506 while (start_zero_fsb <= end_zero_fsb) {
508 zero_count_fsb = end_zero_fsb - start_zero_fsb + 1;
509 error = XFS_BMAPI(mp, NULL, io, start_zero_fsb, zero_count_fsb,
510 0, NULL, 0, &imap, &nimaps, NULL);
512 ASSERT(ismrlocked(io->io_lock, MR_UPDATE));
513 ASSERT(ismrlocked(io->io_iolock, MR_UPDATE));
518 if (imap.br_state == XFS_EXT_UNWRITTEN ||
519 imap.br_startblock == HOLESTARTBLOCK) {
521 * This loop handles initializing pages that were
522 * partially initialized by the code below this
523 * loop. It basically zeroes the part of the page
524 * that sits on a hole and sets the page as P_HOLE
525 * and calls remapf if it is a mapped file.
527 prev_zero_fsb = NULLFILEOFF;
529 start_zero_fsb = imap.br_startoff +
531 ASSERT(start_zero_fsb <= (end_zero_fsb + 1));
536 * There are blocks in the range requested.
537 * Zero them a single write at a time. We actually
538 * don't zero the entire range returned if it is
539 * too big and simply loop around to get the rest.
540 * That is not the most efficient thing to do, but it
541 * is simple and this path should not be exercised often.
543 buf_len_fsb = XFS_FILBLKS_MIN(imap.br_blockcount,
544 mp->m_writeio_blocks << 8);
546 * Drop the inode lock while we're doing the I/O.
547 * We'll still have the iolock to protect us.
549 XFS_IUNLOCK(mp, io, XFS_ILOCK_EXCL|XFS_EXTSIZE_RD);
551 loff = XFS_FSB_TO_B(mp, start_zero_fsb);
552 lsize = XFS_FSB_TO_B(mp, buf_len_fsb);
554 error = xfs_iozero(vp, loff, lsize, end_size);
560 prev_zero_fsb = start_zero_fsb;
561 prev_zero_count = buf_len_fsb;
562 start_zero_fsb = imap.br_startoff + buf_len_fsb;
563 ASSERT(start_zero_fsb <= (end_zero_fsb + 1));
565 XFS_ILOCK(mp, io, XFS_ILOCK_EXCL|XFS_EXTSIZE_RD);
572 XFS_ILOCK(mp, io, XFS_ILOCK_EXCL|XFS_EXTSIZE_RD);
577 ssize_t /* bytes written, or (-) error */
589 xfs_fsize_t isize, new_size;
590 xfs_fsize_t n, limit;
597 XFS_STATS_INC(xs_write_calls);
599 vp = BHV_TO_VNODE(bdp);
600 xip = XFS_BHVTOI(bdp);
608 xfs_check_frozen(mp, bdp, XFS_FREEZE_WRITE);
610 if (XFS_FORCED_SHUTDOWN(xip->i_mount)) {
614 if (unlikely(ioflags & IO_ISDIRECT)) {
615 if (((__psint_t)buf & BBMASK) ||
616 (*offset & mp->m_blockmask) ||
617 (size & mp->m_blockmask)) {
620 iolock = XFS_IOLOCK_SHARED;
621 locktype = VRWLOCK_WRITE_DIRECT;
623 if (io->io_flags & XFS_IOCORE_RT)
625 iolock = XFS_IOLOCK_EXCL;
626 locktype = VRWLOCK_WRITE;
629 if (ioflags & IO_ISLOCKED)
632 xfs_ilock(xip, XFS_ILOCK_EXCL|iolock);
634 isize = xip->i_d.di_size;
635 limit = XFS_MAXIOFFSET(mp);
637 if (file->f_flags & O_APPEND)
643 xfs_iunlock(xip, XFS_ILOCK_EXCL|iolock);
649 new_size = *offset + size;
650 if (new_size > isize) {
651 io->io_new_size = new_size;
654 if ((DM_EVENT_ENABLED(vp->v_vfsp, xip, DM_EVENT_WRITE) &&
655 !(ioflags & IO_INVIS) && !eventsent)) {
656 loff_t savedsize = *offset;
657 int dmflags = FILP_DELAY_FLAG(file) | DM_SEM_FLAG_RD(ioflags);
659 xfs_iunlock(xip, XFS_ILOCK_EXCL);
660 error = XFS_SEND_DATA(xip->i_mount, DM_EVENT_WRITE, vp,
664 if (iolock) xfs_iunlock(xip, iolock);
667 xfs_ilock(xip, XFS_ILOCK_EXCL);
671 * The iolock was dropped and reaquired in XFS_SEND_DATA
672 * so we have to recheck the size when appending.
673 * We will only "goto start;" once, since having sent the
674 * event prevents another call to XFS_SEND_DATA, which is
675 * what allows the size to change in the first place.
677 if ((file->f_flags & O_APPEND) &&
678 savedsize != xip->i_d.di_size) {
679 *offset = isize = xip->i_d.di_size;
685 * If the offset is beyond the size of the file, we have a couple
686 * of things to do. First, if there is already space allocated
687 * we need to either create holes or zero the disk or ...
689 * If there is a page where the previous size lands, we need
690 * to zero it out up to the new size.
693 if (!(ioflags & IO_ISDIRECT) && (*offset > isize && isize)) {
694 error = xfs_zero_eof(BHV_TO_VNODE(bdp), io, *offset,
695 isize, *offset + size);
697 xfs_iunlock(xip, XFS_ILOCK_EXCL|iolock);
701 xfs_iunlock(xip, XFS_ILOCK_EXCL);
704 * If we're writing the file then make sure to clear the
705 * setuid and setgid bits if the process is not being run
706 * by root. This keeps people from modifying setuid and
710 if (((xip->i_d.di_mode & S_ISUID) ||
711 ((xip->i_d.di_mode & (S_ISGID | S_IXGRP)) ==
712 (S_ISGID | S_IXGRP))) &&
713 !capable(CAP_FSETID)) {
714 error = xfs_write_clear_setuid(xip);
716 xfs_iunlock(xip, iolock);
722 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,22)
723 if ((ssize_t) size < 0) {
728 if (!access_ok(VERIFY_READ, buf, size)) {
733 #define do_generic_direct_write(file, buf, size, offset) \
734 generic_file_write_nolock(file, buf, size, offset)
735 #define do_generic_file_write(file, buf, size, offset) \
736 generic_file_write_nolock(file, buf, size, offset)
740 if (unlikely(ioflags & IO_ISDIRECT)) {
741 loff_t pos = *offset;
742 struct address_space *mapping = file->f_dentry->d_inode->i_mapping;
743 struct inode *inode = mapping->host;
745 ret = precheck_file_write(file, inode, &size, &pos);
746 if (ret || size == 0)
749 xfs_inval_cached_pages(vp, io, pos, 1, 1);
750 inode->i_ctime = inode->i_mtime = CURRENT_TIME;
751 /* mark_inode_dirty_sync(inode); - we do this later */
753 xfs_rw_enter_trace(XFS_DIOWR_ENTER, io, buf, size, pos, ioflags);
754 ret = generic_file_direct_IO(WRITE, file, (char *)buf, size, pos);
758 xfs_rw_enter_trace(XFS_WRITE_ENTER, io, buf, size, *offset, ioflags);
759 ret = do_generic_file_write(file, buf, size, offset);
762 if (unlikely(ioflags & IO_INVIS)) {
763 /* generic_file_write updates the mtime/ctime but we need
764 * to undo that because this I/O was supposed to be
767 struct inode *inode = LINVFS_GET_IP(vp);
768 inode->i_mtime = xip->i_d.di_mtime.t_sec;
769 inode->i_ctime = xip->i_d.di_ctime.t_sec;
771 xfs_ichgtime(xip, XFS_ICHGTIME_MOD | XFS_ICHGTIME_CHG);
774 if ((ret == -ENOSPC) &&
775 DM_EVENT_ENABLED(vp->v_vfsp, xip, DM_EVENT_NOSPACE) &&
776 !(ioflags & IO_INVIS)) {
778 xfs_rwunlock(bdp, locktype);
779 error = XFS_SEND_NAMESP(xip->i_mount, DM_EVENT_NOSPACE, vp,
780 DM_RIGHT_NULL, vp, DM_RIGHT_NULL, NULL, NULL,
781 0, 0, 0); /* Delay flag intentionally unused */
784 xfs_rwlock(bdp, locktype);
785 *offset = xip->i_d.di_size;
789 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,22)
794 xfs_rwunlock(bdp, locktype);
798 XFS_STATS_ADD(xs_write_bytes, ret);
800 if (*offset > xip->i_d.di_size) {
801 xfs_ilock(xip, XFS_ILOCK_EXCL);
802 if (*offset > xip->i_d.di_size) {
803 struct inode *inode = LINVFS_GET_IP(vp);
805 xip->i_d.di_size = *offset;
806 i_size_write(inode, *offset);
807 xip->i_update_core = 1;
808 xip->i_update_size = 1;
809 mark_inode_dirty_sync(inode);
811 xfs_iunlock(xip, XFS_ILOCK_EXCL);
814 /* Handle various SYNC-type writes */
815 if ((file->f_flags & O_SYNC) || IS_SYNC(file->f_dentry->d_inode)) {
818 * If we're treating this as O_DSYNC and we have not updated the
819 * size, force the log.
822 if (!(mp->m_flags & XFS_MOUNT_OSYNCISOSYNC)
823 && !(xip->i_update_size)) {
825 * If an allocation transaction occurred
826 * without extending the size, then we have to force
827 * the log up the proper point to ensure that the
828 * allocation is permanent. We can't count on
829 * the fact that buffered writes lock out direct I/O
830 * writes - the direct I/O write could have extended
831 * the size nontransactionally, then finished before
832 * we started. xfs_write_file will think that the file
833 * didn't grow but the update isn't safe unless the
834 * size change is logged.
836 * Force the log if we've committed a transaction
837 * against the inode or if someone else has and
838 * the commit record hasn't gone to disk (e.g.
839 * the inode is pinned). This guarantees that
840 * all changes affecting the inode are permanent
844 xfs_inode_log_item_t *iip;
848 if (iip && iip->ili_last_lsn) {
849 lsn = iip->ili_last_lsn;
850 xfs_log_force(mp, lsn,
851 XFS_LOG_FORCE | XFS_LOG_SYNC);
852 } else if (xfs_ipincount(xip) > 0) {
853 xfs_log_force(mp, (xfs_lsn_t)0,
854 XFS_LOG_FORCE | XFS_LOG_SYNC);
861 * O_SYNC or O_DSYNC _with_ a size update are handled
864 * If the write was synchronous then we need to make
865 * sure that the inode modification time is permanent.
866 * We'll have updated the timestamp above, so here
867 * we use a synchronous transaction to log the inode.
868 * It's not fast, but it's necessary.
870 * If this a dsync write and the size got changed
871 * non-transactionally, then we need to ensure that
872 * the size change gets logged in a synchronous
876 tp = xfs_trans_alloc(mp, XFS_TRANS_WRITE_SYNC);
877 if ((error = xfs_trans_reserve(tp, 0,
878 XFS_SWRITE_LOG_RES(mp),
880 /* Transaction reserve failed */
881 xfs_trans_cancel(tp, 0);
883 /* Transaction reserve successful */
884 xfs_ilock(xip, XFS_ILOCK_EXCL);
885 xfs_trans_ijoin(tp, xip, XFS_ILOCK_EXCL);
886 xfs_trans_ihold(tp, xip);
887 xfs_trans_log_inode(tp, xip, XFS_ILOG_CORE);
888 xfs_trans_set_sync(tp);
889 error = xfs_trans_commit(tp, 0, (xfs_lsn_t)0);
890 xfs_iunlock(xip, XFS_ILOCK_EXCL);
893 } /* (ioflags & O_SYNC) */
896 * If we are coming from an nfsd thread then insert into the
900 if (!strcmp(current->comm, "nfsd"))
901 xfs_refcache_insert(xip);
903 /* Drop lock this way - the old refcache release is in here */
905 xfs_rwunlock(bdp, locktype);
913 * Initiate IO on given buffer.
916 xfs_buf_iorequest(struct xfs_buf *bp)
918 bp->b_flags &= ~(B_INVAL|B_DONE);
919 bp->b_ioflags &= ~BIO_ERROR;
921 if (bp->b_flags & B_ASYNC)
924 if (bp->b_vp == NULL) {
925 if (bp->b_iocmd == BIO_WRITE) {
926 bp->b_flags &= ~(B_DELWRI | B_DEFERRED);
927 bufobj_wref(bp->b_bufobj);
930 bp->b_iooffset = (bp->b_blkno << BBSHIFT);
933 if (bp->b_iocmd == BIO_WRITE) {
934 /* Mark the buffer clean */
936 bufobj_wref(bp->b_bufobj);
937 vfs_busy_pages(bp, 1);
938 } else if (bp->b_iocmd == BIO_READ) {
939 vfs_busy_pages(bp, 0);
941 bp->b_iooffset = dbtob(bp->b_blkno);
948 * All xfs metadata buffers except log state machine buffers
949 * get this attached as their b_bdstrat callback function.
950 * This is so that we can catch a buffer
951 * after prematurely unpinning it to forcibly shutdown the filesystem.
954 xfs_bdstrat_cb(struct xfs_buf *bp)
958 mp = XFS_BUF_FSPRIVATE3(bp, xfs_mount_t *);
959 if (!XFS_FORCED_SHUTDOWN(mp)) {
960 xfs_buf_iorequest(bp);
963 xfs_buftrace("XFS__BDSTRAT IOERROR", bp);
965 * Metadata write that didn't get logged but
966 * written delayed anyway. These aren't associated
967 * with a transaction, and can be ignored.
969 if (XFS_BUF_IODONE_FUNC(bp) == NULL &&
970 (XFS_BUF_ISREAD(bp)) == 0)
971 return (xfs_bioerror_relse(bp));
973 return (xfs_bioerror(bp));
979 xfs_bmap(bhv_desc_t *bdp,
986 xfs_inode_t *ip = XFS_BHVTOI(bdp);
987 xfs_iocore_t *io = &ip->i_iocore;
989 ASSERT((ip->i_d.di_mode & S_IFMT) == S_IFREG);
990 ASSERT(((ip->i_d.di_flags & XFS_DIFLAG_REALTIME) != 0) ==
991 ((ip->i_iocore.io_flags & XFS_IOCORE_RT) != 0));
993 return xfs_iomap(io, offset, count, flags, iomapp, niomaps);
997 * Wrapper around bdstrat so that we can stop data
998 * from going to disk in case we are shutting down the filesystem.
999 * Typically user data goes thru this path; one of the exceptions
1000 * is the superblock.
1004 struct xfs_mount *mp,
1008 if (!XFS_FORCED_SHUTDOWN(mp)) {
1009 /* Grio redirection would go here
1010 * if (XFS_BUF_IS_GRIO(bp)) {
1013 return xfs_buf_iorequest(bp);
1017 xfs_buftrace("XFSBDSTRAT IOERROR", bp);
1018 return (xfs_bioerror_relse(bp));
1022 * If the underlying (data/log/rt) device is readonly, there are some
1023 * operations that cannot proceed.
1026 xfs_dev_is_read_only(
1030 if (xfs_readonly_buftarg(mp->m_ddev_targp) ||
1031 xfs_readonly_buftarg(mp->m_logdev_targp) ||
1032 (mp->m_rtdev_targp && xfs_readonly_buftarg(mp->m_rtdev_targp))) {
1034 "XFS: %s required on read-only device.", message);
1036 "XFS: write access unavailable, cannot proceed.");