Lines Matching +full:no +full:- +full:unaligned +full:- +full:direct +full:- +full:access

1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2000-2005 Silicon Graphics, Inc.
33 #include <linux/backing-dev.h>
56 return !((pos | len) & (alloc_unit - 1)); in xfs_is_falloc_aligned()
61 * as there is no file data to flush, and thus also no need for explicit
62 * cache flush operations, and there are no non-transaction metadata updates
72 struct xfs_inode *ip = XFS_I(file->f_mapping->host); in xfs_dir_fsync()
91 * set on the log item until - at least - the journal flush completes. In
104 struct xfs_inode_log_item *iip = ip->i_itemp; in xfs_fsync_flush_log()
107 spin_lock(&iip->ili_lock); in xfs_fsync_flush_log()
109 seq = iip->ili_datasync_seq; in xfs_fsync_flush_log()
111 seq = iip->ili_commit_seq; in xfs_fsync_flush_log()
112 spin_unlock(&iip->ili_lock); in xfs_fsync_flush_log()
117 return xfs_log_force_seq(ip->i_mount, seq, XFS_LOG_SYNC, in xfs_fsync_flush_log()
128 struct xfs_inode *ip = XFS_I(file->f_mapping->host); in xfs_file_fsync()
129 struct xfs_mount *mp = ip->i_mount; in xfs_file_fsync()
140 return -EIO; in xfs_file_fsync()
150 if (XFS_IS_REALTIME_INODE(ip) && mp->m_rtdev_targp != mp->m_ddev_targp) in xfs_file_fsync()
151 error = blkdev_issue_flush(mp->m_rtdev_targp->bt_bdev); in xfs_file_fsync()
152 else if (mp->m_logdev_targp != mp->m_ddev_targp) in xfs_file_fsync()
153 error = blkdev_issue_flush(mp->m_ddev_targp->bt_bdev); in xfs_file_fsync()
159 if (ip->i_itemp) { in xfs_file_fsync()
167 * a no-op we might have to flush the data device cache here. in xfs_file_fsync()
173 mp->m_logdev_targp == mp->m_ddev_targp) { in xfs_file_fsync()
174 err2 = blkdev_issue_flush(mp->m_ddev_targp->bt_bdev); in xfs_file_fsync()
187 struct xfs_inode *ip = XFS_I(file_inode(iocb->ki_filp)); in xfs_ilock_iocb()
189 if (iocb->ki_flags & IOCB_NOWAIT) { in xfs_ilock_iocb()
191 return -EAGAIN; in xfs_ilock_iocb()
205 struct xfs_inode *ip = XFS_I(file_inode(iocb->ki_filp)); in xfs_ilock_iocb_for_write()
230 struct xfs_inode *ip = XFS_I(file_inode(iocb->ki_filp)); in xfs_file_dio_read()
238 file_accessed(iocb->ki_filp); in xfs_file_dio_read()
254 struct xfs_inode *ip = XFS_I(iocb->ki_filp->f_mapping->host); in xfs_file_dax_read()
268 file_accessed(iocb->ki_filp); in xfs_file_dax_read()
277 struct xfs_inode *ip = XFS_I(file_inode(iocb->ki_filp)); in xfs_file_buffered_read()
296 struct inode *inode = file_inode(iocb->ki_filp); in xfs_file_read_iter()
297 struct xfs_mount *mp = XFS_I(inode)->i_mount; in xfs_file_read_iter()
303 return -EIO; in xfs_file_read_iter()
307 else if (iocb->ki_flags & IOCB_DIRECT) in xfs_file_read_iter()
327 struct xfs_mount *mp = ip->i_mount; in xfs_file_splice_read()
333 return -EIO; in xfs_file_splice_read()
346 * Take care of zeroing post-EOF blocks when they might exist.
361 struct xfs_inode *ip = XFS_I(iocb->ki_filp->f_mapping->host); in xfs_file_write_zero_eof()
374 spin_lock(&ip->i_flags_lock); in xfs_file_write_zero_eof()
376 if (iocb->ki_pos <= isize) { in xfs_file_write_zero_eof()
377 spin_unlock(&ip->i_flags_lock); in xfs_file_write_zero_eof()
380 spin_unlock(&ip->i_flags_lock); in xfs_file_write_zero_eof()
382 if (iocb->ki_flags & IOCB_NOWAIT) in xfs_file_write_zero_eof()
383 return -EAGAIN; in xfs_file_write_zero_eof()
401 * wait for all of them to drain. Non-AIO DIO will have drained in xfs_file_write_zero_eof()
403 * cases this wait is a no-op. in xfs_file_write_zero_eof()
410 trace_xfs_zero_eof(ip, isize, iocb->ki_pos - isize); in xfs_file_write_zero_eof()
413 error = xfs_zero_range(ip, isize, iocb->ki_pos - isize, ac, NULL); in xfs_file_write_zero_eof()
420 * Common pre-write limit and setup checks.
424 * if called for a direct write beyond i_size.
433 struct inode *inode = iocb->ki_filp->f_mapping->host; in xfs_file_write_checks()
443 if (iocb->ki_flags & IOCB_NOWAIT) { in xfs_file_write_checks()
445 if (error == -EWOULDBLOCK) in xfs_file_write_checks()
446 error = -EAGAIN; in xfs_file_write_checks()
479 if (iocb->ki_pos > i_size_read(inode)) { in xfs_file_write_checks()
502 if (iocb->ki_flags & IOCB_NOWAIT) in xfs_zoned_write_space_reserve()
506 * Check the rlimit and LFS boundary first so that we don't over-reserve in xfs_zoned_write_space_reserve()
515 error = generic_write_check_limits(iocb->ki_filp, iocb->ki_pos, &count); in xfs_zoned_write_space_reserve()
525 * EOF block and the new start block if they are unaligned. in xfs_zoned_write_space_reserve()
540 struct inode *inode = file_inode(iocb->ki_filp); in xfs_dio_write_end_io()
542 loff_t offset = iocb->ki_pos; in xfs_dio_write_end_io()
550 if (xfs_is_shutdown(ip->i_mount)) in xfs_dio_write_end_io()
551 return -EIO; in xfs_dio_write_end_io()
562 XFS_STATS_ADD(ip->i_mount, xs_write_bytes, size); in xfs_dio_write_end_io()
567 * task-wide nofs context for the following operations. in xfs_dio_write_end_io()
572 if (iocb->ki_flags & IOCB_ATOMIC) in xfs_dio_write_end_io()
581 * Unwritten conversion updates the in-core isize after extent in xfs_dio_write_end_io()
582 * conversion but before updating the on-disk size. Updating isize any in xfs_dio_write_end_io()
592 * We need to update the in-core inode size here so that we don't end up in xfs_dio_write_end_io()
593 * with the on-disk inode size being outside the in-core inode size. We in xfs_dio_write_end_io()
594 * have no other method of updating EOF for AIO, so always do it here in xfs_dio_write_end_io()
612 spin_lock(&ip->i_flags_lock); in xfs_dio_write_end_io()
615 spin_unlock(&ip->i_flags_lock); in xfs_dio_write_end_io()
618 spin_unlock(&ip->i_flags_lock); in xfs_dio_write_end_io()
636 struct xfs_mount *mp = XFS_I(iter->inode)->i_mount; in xfs_dio_zoned_submit_io()
637 struct xfs_zone_alloc_ctx *ac = iter->private; in xfs_dio_zoned_submit_io()
641 count_fsb = XFS_B_TO_FSB(mp, bio->bi_iter.bi_size); in xfs_dio_zoned_submit_io()
642 if (count_fsb > ac->reserved_blocks) { in xfs_dio_zoned_submit_io()
645 count_fsb, ac->reserved_blocks); in xfs_dio_zoned_submit_io()
650 ac->reserved_blocks -= count_fsb; in xfs_dio_zoned_submit_io()
652 bio->bi_end_io = xfs_end_bio; in xfs_dio_zoned_submit_io()
653 ioend = iomap_init_ioend(iter->inode, bio, file_offset, in xfs_dio_zoned_submit_io()
655 xfs_zone_alloc_and_submit(ioend, &ac->open_zone); in xfs_dio_zoned_submit_io()
665 * Handle block aligned direct I/O writes.
703 * Handle block aligned direct I/O writes to zoned devices.
714 ret = xfs_zoned_write_space_reserve(ip->i_mount, iocb, from, 0, &ac); in xfs_file_dio_write_zoned()
720 xfs_zoned_space_unreserve(ip->i_mount, &ac); in xfs_file_dio_write_zoned()
728 * - REQ_ATOMIC-based, which would typically use some form of HW offload in the
730 * - COW-based, which uses a COW fork as a staging extent for data updates
748 if (ocount > xfs_inode_buftarg(ip)->bt_awu_max) in xfs_file_dio_write_atomic()
773 * The retry mechanism is based on the ->iomap_begin method returning in xfs_file_dio_write_atomic()
774 * -ENOPROTOOPT, which would be when the REQ_ATOMIC-based write is not in xfs_file_dio_write_atomic()
775 * possible. The REQ_ATOMIC-based method typically not be possible if in xfs_file_dio_write_atomic()
778 if (ret == -ENOPROTOOPT && dops == &xfs_direct_write_iomap_ops) { in xfs_file_dio_write_atomic()
791 * Handle block unaligned direct I/O writes
793 * In most cases direct I/O writes will be done holding IOLOCK_SHARED, allowing
794 * them to be done in parallel with reads and other direct I/O writes. However,
795 * if the I/O is not aligned to filesystem blocks, the direct I/O layer may need
796 * to do sub-block zeroing and that requires serialisation against other direct
798 * the unaligned I/O so that we don't get racing block zeroing in the dio layer.
799 * In the case where sub-block zeroing is not required, we can do concurrent
800 * sub-block dios to the same block successfully.
803 * IOMAP_DIO_OVERWRITE_ONLY flag to tell the lower layers to return -EAGAIN
820 * Extending writes need exclusivity because of the sub-block zeroing in xfs_file_dio_write_unaligned()
824 if (iocb->ki_pos > isize || iocb->ki_pos + count >= isize) { in xfs_file_dio_write_unaligned()
825 if (iocb->ki_flags & IOCB_NOWAIT) in xfs_file_dio_write_unaligned()
826 return -EAGAIN; in xfs_file_dio_write_unaligned()
837 * We can't properly handle unaligned direct I/O to reflink files yet, in xfs_file_dio_write_unaligned()
842 ret = -ENOTBLK; in xfs_file_dio_write_unaligned()
851 * If we are doing exclusive unaligned I/O, this must be the only I/O in xfs_file_dio_write_unaligned()
852 * in-flight. Otherwise we risk data corruption due to unwritten extent in xfs_file_dio_write_unaligned()
864 * Retry unaligned I/O with exclusive blocking semantics if the DIO in xfs_file_dio_write_unaligned()
868 if (ret == -EAGAIN && !(iocb->ki_flags & IOCB_NOWAIT)) { in xfs_file_dio_write_unaligned()
885 struct xfs_inode *ip = XFS_I(file_inode(iocb->ki_filp)); in xfs_file_dio_write()
889 /* direct I/O must be aligned to device logical sector size */ in xfs_file_dio_write()
890 if ((iocb->ki_pos | count) & target->bt_logical_sectormask) in xfs_file_dio_write()
891 return -EINVAL; in xfs_file_dio_write()
899 if (((iocb->ki_pos | count) & ip->i_mount->m_blockmask) || in xfs_file_dio_write()
901 (iov_iter_alignment(from) & ip->i_mount->m_blockmask))) in xfs_file_dio_write()
905 if (iocb->ki_flags & IOCB_ATOMIC) in xfs_file_dio_write()
916 struct inode *inode = iocb->ki_filp->f_mapping->host; in xfs_file_dax_write()
929 pos = iocb->ki_pos; in xfs_file_dax_write()
933 if (ret > 0 && iocb->ki_pos > i_size_read(inode)) { in xfs_file_dax_write()
934 i_size_write(inode, iocb->ki_pos); in xfs_file_dax_write()
944 XFS_STATS_ADD(ip->i_mount, xs_write_bytes, ret); in xfs_file_dax_write()
946 /* Handle various SYNC-type writes */ in xfs_file_dax_write()
957 struct inode *inode = iocb->ki_filp->f_mapping->host; in xfs_file_buffered_write()
988 if (ret == -EDQUOT && !cleared_space) { in xfs_file_buffered_write()
993 } else if (ret == -ENOSPC && !cleared_space) { in xfs_file_buffered_write()
997 xfs_flush_inodes(ip->i_mount); in xfs_file_buffered_write()
1001 xfs_blockgc_free_space(ip->i_mount, &icw); in xfs_file_buffered_write()
1010 XFS_STATS_ADD(ip->i_mount, xs_write_bytes, ret); in xfs_file_buffered_write()
1011 /* Handle various SYNC-type writes */ in xfs_file_buffered_write()
1022 struct xfs_inode *ip = XFS_I(iocb->ki_filp->f_mapping->host); in xfs_file_buffered_write_zoned()
1023 struct xfs_mount *mp = ip->i_mount; in xfs_file_buffered_write_zoned()
1048 XFS_FSB_TO_B(mp, ac.reserved_blocks) - in xfs_file_buffered_write_zoned()
1049 (iocb->ki_pos & mp->m_blockmask)); in xfs_file_buffered_write_zoned()
1058 if (ret == -ENOSPC && !cleared_space) { in xfs_file_buffered_write_zoned()
1071 xfs_zoned_space_unreserve(ip->i_mount, &ac); in xfs_file_buffered_write_zoned()
1084 struct inode *inode = iocb->ki_filp->f_mapping->host; in xfs_file_write_iter()
1089 XFS_STATS_INC(ip->i_mount, xs_write_calls); in xfs_file_write_iter()
1094 if (xfs_is_shutdown(ip->i_mount)) in xfs_file_write_iter()
1095 return -EIO; in xfs_file_write_iter()
1097 if (iocb->ki_flags & IOCB_ATOMIC) { in xfs_file_write_iter()
1099 return -EINVAL; in xfs_file_write_iter()
1102 return -EINVAL; in xfs_file_write_iter()
1112 if (iocb->ki_flags & IOCB_DIRECT) { in xfs_file_write_iter()
1120 if (ret != -ENOTBLK) in xfs_file_write_iter()
1134 if (xfs_has_wsync(ip->i_mount)) in xfs_file_sync_writes()
1136 if (filp->f_flags & (__O_SYNC | O_DSYNC)) in xfs_file_sync_writes()
1184 loff_t new_size = i_size_read(inode) - len; in xfs_falloc_collapse_range()
1188 return -EINVAL; in xfs_falloc_collapse_range()
1191 * There is no need to overlap collapse range with EOF, in which case it in xfs_falloc_collapse_range()
1195 return -EINVAL; in xfs_falloc_collapse_range()
1214 return -EINVAL; in xfs_falloc_insert_range()
1217 * New inode size must not exceed ->s_maxbytes, accounting for in xfs_falloc_insert_range()
1220 if (inode->i_sb->s_maxbytes - isize < len) in xfs_falloc_insert_range()
1221 return -EFBIG; in xfs_falloc_insert_range()
1225 return -EINVAL; in xfs_falloc_insert_range()
1234 * past EOF and hence losing access to the data that is contained within in xfs_falloc_insert_range()
1245 * 2.) If prealloc returns ENOSPC, the file range is still zero-valued by
1271 len = round_up(offset + len, blksize) - round_down(offset, blksize); in xfs_falloc_zero_range()
1320 return -EOPNOTSUPP; in xfs_falloc_allocate_range()
1361 * require the in-memory size to be fully up-to-date. in __xfs_file_fallocate()
1389 error = -EOPNOTSUPP; in __xfs_file_fallocate()
1412 error = xfs_zoned_space_reserve(ip->i_mount, 2, XFS_ZR_RESERVED, &ac); in xfs_file_zoned_fallocate()
1416 xfs_zoned_space_unreserve(ip->i_mount, &ac); in xfs_file_zoned_fallocate()
1429 if (!S_ISREG(inode->i_mode)) in xfs_file_fallocate()
1430 return -EINVAL; in xfs_file_fallocate()
1432 return -EOPNOTSUPP; in xfs_file_fallocate()
1487 struct xfs_mount *mp = src->i_mount; in xfs_file_remap_range()
1493 return -EINVAL; in xfs_file_remap_range()
1496 return -EOPNOTSUPP; in xfs_file_remap_range()
1499 return -EIO; in xfs_file_remap_range()
1521 (src->i_diflags2 & XFS_DIFLAG2_COWEXTSIZE) && in xfs_file_remap_range()
1523 !(dest->i_diflags2 & XFS_DIFLAG2_COWEXTSIZE)) in xfs_file_remap_range()
1524 cowextsize = src->i_cowextsize; in xfs_file_remap_range()
1539 * handle partial results -- either the whole remap succeeds, or we in xfs_file_remap_range()
1553 if (xfs_is_shutdown(XFS_M(inode->i_sb))) in xfs_file_open()
1554 return -EIO; in xfs_file_open()
1555 file->f_mode |= FMODE_NOWAIT | FMODE_CAN_ODIRECT; in xfs_file_open()
1557 file->f_mode |= FMODE_CAN_ATOMIC_WRITE; in xfs_file_open()
1570 if (xfs_is_shutdown(ip->i_mount)) in xfs_dir_open()
1571 return -EIO; in xfs_dir_open()
1577 * If there are any blocks, read-ahead block 0 as we're almost in xfs_dir_open()
1581 if (ip->i_df.if_nextents > 0) in xfs_dir_open()
1597 struct xfs_mount *mp = ip->i_mount; in xfs_file_release()
1600 * If this is a read-only mount or the file system has been shut down, in xfs_file_release()
1610 * is particularly noticeable from a truncate down, buffered (re-)write in xfs_file_release()
1617 if (ip->i_delayed_blks > 0) in xfs_file_release()
1618 filemap_flush(inode->i_mapping); in xfs_file_release()
1622 * XFS aggressively preallocates post-EOF space to generate contiguous in xfs_file_release()
1632 * This heuristic is skipped for inodes with the append-only flag as in xfs_file_release()
1635 * There is no point in freeing blocks here for open but unlinked files in xfs_file_release()
1638 * When releasing a read-only context, don't flush data or trim post-EOF in xfs_file_release()
1645 if (!inode->i_nlink || in xfs_file_release()
1646 !(file->f_mode & FMODE_WRITE) || in xfs_file_release()
1647 (ip->i_diflags & XFS_DIFLAG_APPEND) || in xfs_file_release()
1686 * point we can change the ->readdir prototype to include the in xfs_file_readdir()
1689 bufsize = (size_t)min_t(loff_t, XFS_READDIR_BUFSIZE, ip->i_disk_size); in xfs_file_readdir()
1700 struct inode *inode = file->f_mapping->host; in xfs_file_llseek()
1702 if (xfs_is_shutdown(XFS_I(inode)->i_mount)) in xfs_file_llseek()
1703 return -EIO; in xfs_file_llseek()
1718 return vfs_setpos(file, offset, inode->i_sb->s_maxbytes); in xfs_file_llseek()
1735 (write_fault && !vmf->cow_page) ? in xfs_dax_fault_locked()
1748 struct xfs_inode *ip = XFS_I(file_inode(vmf->vma->vm_file)); in xfs_dax_read_fault()
1766 * invalidate_lock (vfs/XFS_MMAPLOCK - truncate serialisation)
1768 * i_lock (XFS - extent map serialisation)
1776 struct inode *inode = file_inode(vmf->vma->vm_file); in __xfs_write_fault()
1783 sb_start_pagefault(inode->i_sb); in __xfs_write_fault()
1784 file_update_time(vmf->vma->vm_file); in __xfs_write_fault()
1805 sb_end_pagefault(inode->i_sb); in __xfs_write_fault()
1814 struct xfs_inode *ip = XFS_I(file_inode(vmf->vma->vm_file)); in xfs_write_fault_zoned()
1815 unsigned int len = folio_size(page_folio(vmf->page)); in xfs_write_fault_zoned()
1821 * This could over-allocate as it doesn't check for truncation. in xfs_write_fault_zoned()
1826 error = xfs_zoned_space_reserve(ip->i_mount, in xfs_write_fault_zoned()
1827 XFS_B_TO_FSB(ip->i_mount, len), 0, &ac); in xfs_write_fault_zoned()
1831 xfs_zoned_space_unreserve(ip->i_mount, &ac); in xfs_write_fault_zoned()
1840 if (xfs_is_zoned_inode(XFS_I(file_inode(vmf->vma->vm_file)))) in xfs_write_fault()
1849 return (vmf->flags & FAULT_FLAG_WRITE) && in xfs_is_write_fault()
1850 (vmf->vma->vm_flags & VM_SHARED); in xfs_is_write_fault()
1857 struct inode *inode = file_inode(vmf->vma->vm_file); in xfs_filemap_fault()
1875 if (!IS_DAX(file_inode(vmf->vma->vm_file))) in xfs_filemap_huge_fault()
1915 struct file *file = desc->file; in xfs_file_mmap_prepare()
1920 * We don't support synchronous mappings for non-DAX files and in xfs_file_mmap_prepare()
1923 if (!daxdev_mapping_supported(desc->vm_flags, file_inode(file), in xfs_file_mmap_prepare()
1924 target->bt_daxdev)) in xfs_file_mmap_prepare()
1925 return -EOPNOTSUPP; in xfs_file_mmap_prepare()
1928 desc->vm_ops = &xfs_file_vm_ops; in xfs_file_mmap_prepare()
1930 desc->vm_flags |= VM_HUGEPAGE; in xfs_file_mmap_prepare()