38 #include <linux/falloc.h>
41 static const struct vm_operations_struct xfs_file_vm_ops;
52 if (type & XFS_IOLOCK_EXCL)
63 if (type & XFS_IOLOCK_EXCL)
73 if (type & XFS_IOLOCK_EXCL)
97 mapping = VFS_I(ip)->i_mapping;
113 zero_user(page, offset, bytes);
139 struct xfs_inode *ip = XFS_I(file->
f_mapping->host);
140 struct xfs_mount *
mp = ip->i_mount;
143 trace_xfs_dir_fsync(ip);
147 lsn = ip->i_itemp->ili_last_lsn;
163 struct xfs_inode *ip = XFS_I(inode);
164 struct xfs_mount *
mp = ip->i_mount;
169 trace_xfs_file_fsync(ip);
175 if (XFS_FORCED_SHUTDOWN(mp))
178 xfs_iflags_clear(ip, XFS_ITRUNCATED);
180 if (mp->m_flags & XFS_MOUNT_BARRIER) {
190 else if (mp->m_logdev_targp != mp->m_ddev_targp)
202 lsn = ip->i_itemp->ili_last_lsn;
216 if ((mp->m_flags & XFS_MOUNT_BARRIER) &&
217 mp->m_logdev_targp == mp->m_ddev_targp &&
228 const struct iovec *iovp,
229 unsigned long nr_segs,
234 struct xfs_inode *ip = XFS_I(inode);
235 struct xfs_mount *
mp = ip->i_mount;
257 mp->m_rtdev_targp : mp->m_ddev_targp;
260 if (iocb->
ki_pos == i_size_read(inode))
266 n = mp->m_super->s_maxbytes - iocb->
ki_pos;
267 if (n <= 0 || size == 0)
273 if (XFS_FORCED_SHUTDOWN(mp))
286 xfs_rw_ilock(ip, XFS_IOLOCK_SHARED);
287 if ((ioflags & IO_ISDIRECT) && inode->
i_mapping->nrpages) {
288 xfs_rw_iunlock(ip, XFS_IOLOCK_SHARED);
289 xfs_rw_ilock(ip, XFS_IOLOCK_EXCL);
296 xfs_rw_iunlock(ip, XFS_IOLOCK_EXCL);
300 xfs_rw_ilock_demote(ip, XFS_IOLOCK_EXCL);
303 trace_xfs_file_read(ip, size, iocb->
ki_pos, ioflags);
309 xfs_rw_iunlock(ip, XFS_IOLOCK_SHARED);
321 struct xfs_inode *ip = XFS_I(infilp->
f_mapping->host);
330 if (XFS_FORCED_SHUTDOWN(ip->i_mount))
333 xfs_rw_ilock(ip, XFS_IOLOCK_SHARED);
335 trace_xfs_file_splice_read(ip, count, *ppos, ioflags);
341 xfs_rw_iunlock(ip, XFS_IOLOCK_SHARED);
356 struct file *outfilp,
362 struct xfs_inode *ip = XFS_I(inode);
371 if (XFS_FORCED_SHUTDOWN(ip->i_mount))
376 trace_xfs_file_splice_write(ip, count, *ppos, ioflags);
394 struct xfs_inode *ip,
398 struct xfs_mount *
mp = ip->i_mount;
421 zero_len = mp->m_sb.sb_blocksize - zero_offset;
422 if (isize + zero_len > offset)
423 zero_len = offset - isize;
440 struct xfs_inode *ip,
444 struct xfs_mount *
mp = ip->i_mount;
455 ASSERT(xfs_isilocked(ip, XFS_IOLOCK_EXCL));
482 if (last_fsb == end_zero_fsb) {
490 ASSERT(start_zero_fsb <= end_zero_fsb);
491 while (start_zero_fsb <= end_zero_fsb) {
493 zero_count_fsb = end_zero_fsb - start_zero_fsb + 1;
507 ASSERT(start_zero_fsb <= (end_zero_fsb + 1));
517 if ((zero_off + zero_len) > offset)
518 zero_len = offset - zero_off;
525 ASSERT(start_zero_fsb <= (end_zero_fsb + 1));
546 struct xfs_inode *ip = XFS_I(inode);
561 if (*pos > i_size_read(inode)) {
562 if (*iolock == XFS_IOLOCK_SHARED) {
563 xfs_rw_iunlock(ip, *iolock);
564 *iolock = XFS_IOLOCK_EXCL;
565 xfs_rw_ilock(ip, *iolock);
621 const struct iovec *iovp,
622 unsigned long nr_segs,
629 struct xfs_inode *ip = XFS_I(inode);
630 struct xfs_mount *
mp = ip->i_mount;
632 size_t count = ocount;
633 int unaligned_io = 0;
636 mp->m_rtdev_targp : mp->m_ddev_targp;
641 if ((pos & mp->m_blockmask) || ((pos + count) & mp->m_blockmask))
651 if (unaligned_io || mapping->
nrpages)
652 iolock = XFS_IOLOCK_EXCL;
654 iolock = XFS_IOLOCK_SHARED;
655 xfs_rw_ilock(ip, iolock);
662 if (mapping->
nrpages && iolock == XFS_IOLOCK_SHARED) {
663 xfs_rw_iunlock(ip, iolock);
664 iolock = XFS_IOLOCK_EXCL;
665 xfs_rw_ilock(ip, iolock);
685 else if (iolock == XFS_IOLOCK_EXCL) {
686 xfs_rw_ilock_demote(ip, XFS_IOLOCK_EXCL);
687 iolock = XFS_IOLOCK_SHARED;
690 trace_xfs_file_direct_write(ip, count, iocb->
ki_pos, 0);
692 &nr_segs, pos, &iocb->
ki_pos, count, ocount);
695 xfs_rw_iunlock(ip, iolock);
698 ASSERT(ret < 0 || ret == count);
705 const struct iovec *iovp,
706 unsigned long nr_segs,
713 struct xfs_inode *ip = XFS_I(inode);
716 int iolock = XFS_IOLOCK_EXCL;
717 size_t count = ocount;
719 xfs_rw_ilock(ip, iolock);
729 trace_xfs_file_buffered_write(ip, count, iocb->
ki_pos, 0);
731 pos, &iocb->
ki_pos, count, ret);
736 if (ret == -
ENOSPC && !enospc) {
745 xfs_rw_iunlock(ip, iolock);
752 const struct iovec *iovp,
753 unsigned long nr_segs,
759 struct xfs_inode *ip = XFS_I(inode);
774 sb_start_write(inode->
i_sb);
776 if (XFS_FORCED_SHUTDOWN(ip->i_mount)) {
799 sb_end_write(inode->
i_sb);
814 xfs_inode_t *ip = XFS_I(inode);
832 offset + len > i_size_read(inode)) {
833 new_size = offset + len;
868 if (XFS_FORCED_SHUTDOWN(
XFS_M(inode->
i_sb)))
878 struct xfs_inode *ip = XFS_I(inode);
891 if (ip->i_d.di_nextents > 0)
912 xfs_inode_t *ip = XFS_I(inode);
928 bufsize = (
size_t)
min_t(loff_t, 32768, ip->i_d.di_size);
931 (xfs_off_t *)&filp->
f_pos, filldir);
942 vma->
vm_ops = &xfs_file_vm_ops;
957 struct vm_fault *vmf)
986 struct buffer_head *bh, *
head;
988 bh = head = page_buffers(page);
999 if (buffer_unwritten(bh) ||
1000 buffer_uptodate(bh)) {
1012 lastoff += bh->b_size;
1013 }
while ((bh = bh->b_this_page) != head);
1038 struct xfs_inode *ip = XFS_I(inode);
1039 struct xfs_mount *
mp = ip->i_mount;
1044 loff_t startoff = *
offset;
1045 loff_t lastoff = startoff;
1048 pagevec_init(&pvec, 0);
1072 if (nr_pages == 0) {
1078 if (lastoff == startoff || lastoff < endoff) {
1090 if (type ==
HOLE_OFF && lastoff == startoff &&
1096 for (i = 0; i < nr_pages; i++) {
1112 if (page->
index > end) {
1113 if (type ==
HOLE_OFF && lastoff < endoff) {
1131 if (!page_has_buffers(page)) {
1143 *offset =
max_t(loff_t, startoff, b_offset);
1163 if (nr_pages < want) {
1171 index = pvec.
pages[i - 1]->index + 1;
1172 pagevec_release(&pvec);
1173 }
while (index <= end);
1176 pagevec_release(&pvec);
1186 struct xfs_inode *ip = XFS_I(inode);
1187 struct xfs_mount *
mp = ip->i_mount;
1197 isize = i_size_read(inode);
1198 if (start >= isize) {
1225 for (i = 0; i < nmap; i++) {
1264 if (start >= isize) {
1288 struct xfs_inode *ip = XFS_I(inode);
1289 struct xfs_mount *
mp = ip->i_mount;
1297 if (XFS_FORCED_SHUTDOWN(mp))
1302 isize = i_size_read(inode);
1303 if (start >= isize) {
1327 for (i = 0; i < nmap; i++) {
1366 if (start >= isize) {
1420 #ifdef CONFIG_COMPAT
1436 #ifdef CONFIG_COMPAT
1442 static const struct vm_operations_struct xfs_file_vm_ops = {