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.
31 #include <linux/backing-dev.h>
54 return !((pos | len) & (alloc_unit - 1)); in xfs_is_falloc_aligned()
59 * as there is no file data to flush, and thus also no need for explicit
60 * cache flush operations, and there are no non-transaction metadata updates
70 struct xfs_inode *ip = XFS_I(file->f_mapping->host); in xfs_dir_fsync()
83 if (datasync && !(ip->i_itemp->ili_fsync_fields & ~XFS_ILOG_TIMESTAMP)) in xfs_fsync_seq()
85 return ip->i_itemp->ili_commit_seq; in xfs_fsync_seq()
113 error = xfs_log_force_seq(ip->i_mount, seq, XFS_LOG_SYNC, in xfs_fsync_flush_log()
116 spin_lock(&ip->i_itemp->ili_lock); in xfs_fsync_flush_log()
117 ip->i_itemp->ili_fsync_fields = 0; in xfs_fsync_flush_log()
118 spin_unlock(&ip->i_itemp->ili_lock); in xfs_fsync_flush_log()
131 struct xfs_inode *ip = XFS_I(file->f_mapping->host); in xfs_file_fsync()
132 struct xfs_mount *mp = ip->i_mount; in xfs_file_fsync()
143 return -EIO; in xfs_file_fsync()
154 error = blkdev_issue_flush(mp->m_rtdev_targp->bt_bdev); in xfs_file_fsync()
155 else if (mp->m_logdev_targp != mp->m_ddev_targp) in xfs_file_fsync()
156 error = blkdev_issue_flush(mp->m_ddev_targp->bt_bdev); in xfs_file_fsync()
172 * a no-op we might have to flush the data device cache here. in xfs_file_fsync()
178 mp->m_logdev_targp == mp->m_ddev_targp) { in xfs_file_fsync()
179 err2 = blkdev_issue_flush(mp->m_ddev_targp->bt_bdev); in xfs_file_fsync()
192 struct xfs_inode *ip = XFS_I(file_inode(iocb->ki_filp)); in xfs_ilock_iocb()
194 if (iocb->ki_flags & IOCB_NOWAIT) { in xfs_ilock_iocb()
196 return -EAGAIN; in xfs_ilock_iocb()
210 struct xfs_inode *ip = XFS_I(file_inode(iocb->ki_filp)); in xfs_ilock_iocb_for_write()
235 struct xfs_inode *ip = XFS_I(file_inode(iocb->ki_filp)); in xfs_file_dio_read()
243 file_accessed(iocb->ki_filp); in xfs_file_dio_read()
259 struct xfs_inode *ip = XFS_I(iocb->ki_filp->f_mapping->host); in xfs_file_dax_read()
273 file_accessed(iocb->ki_filp); in xfs_file_dax_read()
282 struct xfs_inode *ip = XFS_I(file_inode(iocb->ki_filp)); in xfs_file_buffered_read()
301 struct inode *inode = file_inode(iocb->ki_filp); in xfs_file_read_iter()
302 struct xfs_mount *mp = XFS_I(inode)->i_mount; in xfs_file_read_iter()
308 return -EIO; in xfs_file_read_iter()
312 else if (iocb->ki_flags & IOCB_DIRECT) in xfs_file_read_iter()
332 struct xfs_mount *mp = ip->i_mount; in xfs_file_splice_read()
338 return -EIO; in xfs_file_splice_read()
351 * Take care of zeroing post-EOF blocks when they might exist.
365 struct xfs_inode *ip = XFS_I(iocb->ki_filp->f_mapping->host); in xfs_file_write_zero_eof()
378 spin_lock(&ip->i_flags_lock); in xfs_file_write_zero_eof()
380 if (iocb->ki_pos <= isize) { in xfs_file_write_zero_eof()
381 spin_unlock(&ip->i_flags_lock); in xfs_file_write_zero_eof()
384 spin_unlock(&ip->i_flags_lock); in xfs_file_write_zero_eof()
386 if (iocb->ki_flags & IOCB_NOWAIT) in xfs_file_write_zero_eof()
387 return -EAGAIN; in xfs_file_write_zero_eof()
405 * wait for all of them to drain. Non-AIO DIO will have drained in xfs_file_write_zero_eof()
407 * cases this wait is a no-op. in xfs_file_write_zero_eof()
414 trace_xfs_zero_eof(ip, isize, iocb->ki_pos - isize); in xfs_file_write_zero_eof()
417 error = xfs_zero_range(ip, isize, iocb->ki_pos - isize, NULL); in xfs_file_write_zero_eof()
424 * Common pre-write limit and setup checks.
428 * if called for a direct write beyond i_size.
436 struct inode *inode = iocb->ki_filp->f_mapping->host; in xfs_file_write_checks()
446 if (iocb->ki_flags & IOCB_NOWAIT) { in xfs_file_write_checks()
448 if (error == -EWOULDBLOCK) in xfs_file_write_checks()
449 error = -EAGAIN; in xfs_file_write_checks()
482 if (iocb->ki_pos > i_size_read(inode)) { in xfs_file_write_checks()
501 struct inode *inode = file_inode(iocb->ki_filp); in xfs_dio_write_end_io()
503 loff_t offset = iocb->ki_pos; in xfs_dio_write_end_io()
508 if (xfs_is_shutdown(ip->i_mount)) in xfs_dio_write_end_io()
509 return -EIO; in xfs_dio_write_end_io()
520 XFS_STATS_ADD(ip->i_mount, xs_write_bytes, size); in xfs_dio_write_end_io()
525 * task-wide nofs context for the following operations. in xfs_dio_write_end_io()
536 * Unwritten conversion updates the in-core isize after extent in xfs_dio_write_end_io()
537 * conversion but before updating the on-disk size. Updating isize any in xfs_dio_write_end_io()
547 * We need to update the in-core inode size here so that we don't end up in xfs_dio_write_end_io()
548 * with the on-disk inode size being outside the in-core inode size. We in xfs_dio_write_end_io()
549 * have no other method of updating EOF for AIO, so always do it here in xfs_dio_write_end_io()
567 spin_lock(&ip->i_flags_lock); in xfs_dio_write_end_io()
570 spin_unlock(&ip->i_flags_lock); in xfs_dio_write_end_io()
573 spin_unlock(&ip->i_flags_lock); in xfs_dio_write_end_io()
586 * Handle block aligned direct I/O writes
623 * Handle block unaligned direct I/O writes
625 * In most cases direct I/O writes will be done holding IOLOCK_SHARED, allowing
626 * them to be done in parallel with reads and other direct I/O writes. However,
627 * if the I/O is not aligned to filesystem blocks, the direct I/O layer may need
628 * to do sub-block zeroing and that requires serialisation against other direct
630 * the unaligned I/O so that we don't get racing block zeroing in the dio layer.
631 * In the case where sub-block zeroing is not required, we can do concurrent
632 * sub-block dios to the same block successfully.
635 * IOMAP_DIO_OVERWRITE_ONLY flag to tell the lower layers to return -EAGAIN
652 * Extending writes need exclusivity because of the sub-block zeroing in xfs_file_dio_write_unaligned()
656 if (iocb->ki_pos > isize || iocb->ki_pos + count >= isize) { in xfs_file_dio_write_unaligned()
657 if (iocb->ki_flags & IOCB_NOWAIT) in xfs_file_dio_write_unaligned()
658 return -EAGAIN; in xfs_file_dio_write_unaligned()
669 * We can't properly handle unaligned direct I/O to reflink files yet, in xfs_file_dio_write_unaligned()
674 ret = -ENOTBLK; in xfs_file_dio_write_unaligned()
683 * If we are doing exclusive unaligned I/O, this must be the only I/O in xfs_file_dio_write_unaligned()
684 * in-flight. Otherwise we risk data corruption due to unwritten extent in xfs_file_dio_write_unaligned()
696 * Retry unaligned I/O with exclusive blocking semantics if the DIO in xfs_file_dio_write_unaligned()
700 if (ret == -EAGAIN && !(iocb->ki_flags & IOCB_NOWAIT)) { in xfs_file_dio_write_unaligned()
717 struct xfs_inode *ip = XFS_I(file_inode(iocb->ki_filp)); in xfs_file_dio_write()
721 /* direct I/O must be aligned to device logical sector size */ in xfs_file_dio_write()
722 if ((iocb->ki_pos | count) & target->bt_logical_sectormask) in xfs_file_dio_write()
723 return -EINVAL; in xfs_file_dio_write()
724 if ((iocb->ki_pos | count) & ip->i_mount->m_blockmask) in xfs_file_dio_write()
734 struct inode *inode = iocb->ki_filp->f_mapping->host; in xfs_file_dax_write()
747 pos = iocb->ki_pos; in xfs_file_dax_write()
751 if (ret > 0 && iocb->ki_pos > i_size_read(inode)) { in xfs_file_dax_write()
752 i_size_write(inode, iocb->ki_pos); in xfs_file_dax_write()
762 XFS_STATS_ADD(ip->i_mount, xs_write_bytes, ret); in xfs_file_dax_write()
764 /* Handle various SYNC-type writes */ in xfs_file_dax_write()
775 struct inode *inode = iocb->ki_filp->f_mapping->host; in xfs_file_buffered_write()
805 if (ret == -EDQUOT && !cleared_space) { in xfs_file_buffered_write()
810 } else if (ret == -ENOSPC && !cleared_space) { in xfs_file_buffered_write()
814 xfs_flush_inodes(ip->i_mount); in xfs_file_buffered_write()
818 xfs_blockgc_free_space(ip->i_mount, &icw); in xfs_file_buffered_write()
827 XFS_STATS_ADD(ip->i_mount, xs_write_bytes, ret); in xfs_file_buffered_write()
828 /* Handle various SYNC-type writes */ in xfs_file_buffered_write()
839 struct inode *inode = iocb->ki_filp->f_mapping->host; in xfs_file_write_iter()
844 XFS_STATS_INC(ip->i_mount, xs_write_calls); in xfs_file_write_iter()
849 if (xfs_is_shutdown(ip->i_mount)) in xfs_file_write_iter()
850 return -EIO; in xfs_file_write_iter()
855 if (iocb->ki_flags & IOCB_ATOMIC) { in xfs_file_write_iter()
859 * a FS block, but there is no requirement to support this. in xfs_file_write_iter()
862 if (ocount != ip->i_mount->m_sb.sb_blocksize) in xfs_file_write_iter()
863 return -EINVAL; in xfs_file_write_iter()
869 if (iocb->ki_flags & IOCB_DIRECT) { in xfs_file_write_iter()
877 if (ret != -ENOTBLK) in xfs_file_write_iter()
889 if (xfs_has_wsync(ip->i_mount)) in xfs_file_sync_writes()
891 if (filp->f_flags & (__O_SYNC | O_DSYNC)) in xfs_file_sync_writes()
938 loff_t new_size = i_size_read(inode) - len; in xfs_falloc_collapse_range()
942 return -EINVAL; in xfs_falloc_collapse_range()
945 * There is no need to overlap collapse range with EOF, in which case it in xfs_falloc_collapse_range()
949 return -EINVAL; in xfs_falloc_collapse_range()
968 return -EINVAL; in xfs_falloc_insert_range()
971 * New inode size must not exceed ->s_maxbytes, accounting for in xfs_falloc_insert_range()
974 if (inode->i_sb->s_maxbytes - isize < len) in xfs_falloc_insert_range()
975 return -EFBIG; in xfs_falloc_insert_range()
979 return -EINVAL; in xfs_falloc_insert_range()
988 * past EOF and hence losing access to the data that is contained within in xfs_falloc_insert_range()
999 * 2.) If prealloc returns ENOSPC, the file range is still zero-valued by
1024 len = round_up(offset + len, blksize) - round_down(offset, blksize); in xfs_falloc_zero_range()
1073 return -EOPNOTSUPP; in xfs_falloc_allocate_range()
1102 if (!S_ISREG(inode->i_mode)) in xfs_file_fallocate()
1103 return -EINVAL; in xfs_file_fallocate()
1105 return -EOPNOTSUPP; in xfs_file_fallocate()
1117 * require the in-memory size to be fully up-to-date. in xfs_file_fallocate()
1145 error = -EOPNOTSUPP; in xfs_file_fallocate()
1195 struct xfs_mount *mp = src->i_mount; in xfs_file_remap_range()
1201 return -EINVAL; in xfs_file_remap_range()
1204 return -EOPNOTSUPP; in xfs_file_remap_range()
1207 return -EIO; in xfs_file_remap_range()
1229 (src->i_diflags2 & XFS_DIFLAG2_COWEXTSIZE) && in xfs_file_remap_range()
1231 !(dest->i_diflags2 & XFS_DIFLAG2_COWEXTSIZE)) in xfs_file_remap_range()
1232 cowextsize = src->i_cowextsize; in xfs_file_remap_range()
1247 * handle partial results -- either the whole remap succeeds, or we in xfs_file_remap_range()
1261 if (xfs_is_shutdown(XFS_M(inode->i_sb))) in xfs_file_open()
1262 return -EIO; in xfs_file_open()
1263 file->f_mode |= FMODE_NOWAIT | FMODE_CAN_ODIRECT; in xfs_file_open()
1265 file->f_mode |= FMODE_CAN_ATOMIC_WRITE; in xfs_file_open()
1278 if (xfs_is_shutdown(ip->i_mount)) in xfs_dir_open()
1279 return -EIO; in xfs_dir_open()
1285 * If there are any blocks, read-ahead block 0 as we're almost in xfs_dir_open()
1289 if (ip->i_df.if_nextents > 0) in xfs_dir_open()
1305 struct xfs_mount *mp = ip->i_mount; in xfs_file_release()
1308 * If this is a read-only mount or the file system has been shut down, in xfs_file_release()
1318 * is particularly noticeable from a truncate down, buffered (re-)write in xfs_file_release()
1325 if (ip->i_delayed_blks > 0) in xfs_file_release()
1326 filemap_flush(inode->i_mapping); in xfs_file_release()
1330 * XFS aggressively preallocates post-EOF space to generate contiguous in xfs_file_release()
1340 * This heuristic is skipped for inodes with the append-only flag as in xfs_file_release()
1343 * There is no point in freeing blocks here for open but unlinked files in xfs_file_release()
1346 * When releasing a read-only context, don't flush data or trim post-EOF in xfs_file_release()
1355 if (inode->i_nlink && in xfs_file_release()
1356 (file->f_mode & FMODE_WRITE) && in xfs_file_release()
1357 !(ip->i_diflags & XFS_DIFLAG_APPEND) && in xfs_file_release()
1387 * point we can change the ->readdir prototype to include the in xfs_file_readdir()
1390 bufsize = (size_t)min_t(loff_t, XFS_READDIR_BUFSIZE, ip->i_disk_size); in xfs_file_readdir()
1401 struct inode *inode = file->f_mapping->host; in xfs_file_llseek()
1403 if (xfs_is_shutdown(XFS_I(inode)->i_mount)) in xfs_file_llseek()
1404 return -EIO; in xfs_file_llseek()
1419 return vfs_setpos(file, offset, inode->i_sb->s_maxbytes); in xfs_file_llseek()
1436 (write_fault && !vmf->cow_page) ? in xfs_dax_fault_locked()
1449 struct xfs_inode *ip = XFS_I(file_inode(vmf->vma->vm_file)); in xfs_dax_read_fault()
1467 * invalidate_lock (vfs/XFS_MMAPLOCK - truncate serialisation)
1469 * i_lock (XFS - extent map serialisation)
1476 struct inode *inode = file_inode(vmf->vma->vm_file); in xfs_write_fault()
1483 sb_start_pagefault(inode->i_sb); in xfs_write_fault()
1484 file_update_time(vmf->vma->vm_file); in xfs_write_fault()
1504 sb_end_pagefault(inode->i_sb); in xfs_write_fault()
1512 return (vmf->flags & FAULT_FLAG_WRITE) && in xfs_is_write_fault()
1513 (vmf->vma->vm_flags & VM_SHARED); in xfs_is_write_fault()
1520 struct inode *inode = file_inode(vmf->vma->vm_file); in xfs_filemap_fault()
1538 if (!IS_DAX(file_inode(vmf->vma->vm_file))) in xfs_filemap_huge_fault()
1583 * We don't support synchronous mappings for non-DAX files and in xfs_file_mmap()
1586 if (!daxdev_mapping_supported(vma, target->bt_daxdev)) in xfs_file_mmap()
1587 return -EOPNOTSUPP; in xfs_file_mmap()
1590 vma->vm_ops = &xfs_file_vm_ops; in xfs_file_mmap()