diff options
author | Linus Torvalds <torvalds@woody.linux-foundation.org> | 2007-05-08 14:59:33 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@woody.linux-foundation.org> | 2007-05-08 14:59:33 -0400 |
commit | 60c9b2746f589b0b809582b0471cf30ad3ae439f (patch) | |
tree | deb0169acb7f7b5b5ef721650de1e0c6f139823c /fs/xfs/linux-2.6/xfs_lrw.c | |
parent | 4750def52cb2c21732dda9aa1d43a07db37b0186 (diff) | |
parent | f7c66ce3f70d8417de0cfb481ca4e5430382ec5d (diff) |
Merge git://oss.sgi.com:8090/xfs/xfs-2.6
* git://oss.sgi.com:8090/xfs/xfs-2.6:
[XFS] Add lockdep support for XFS
[XFS] Fix race in xfs_write() b/w dmapi callout and direct I/O checks.
[XFS] Get rid of redundant "required" in msg.
[XFS] Export via a function xfs_buftarg_list for use by kdb/xfsidbg.
[XFS] Remove unused ilen variable and references.
[XFS] Fix to prevent the notorious 'NULL files' problem after a crash.
[XFS] Fix race condition in xfs_write().
[XFS] Fix uquota and oquota enforcement problems.
[XFS] propogate return codes from flush routines
[XFS] Fix quotaon syscall failures for group enforcement requests.
[XFS] Invalidate quotacheck when mounting without a quota type.
[XFS] reducing the number of random number functions.
[XFS] remove more misc. unused args
[XFS] the "aendp" arg to xfs_dir2_data_freescan is always NULL, remove it.
[XFS] The last argument "lsn" of xfs_trans_commit() is always called with
Diffstat (limited to 'fs/xfs/linux-2.6/xfs_lrw.c')
-rw-r--r-- | fs/xfs/linux-2.6/xfs_lrw.c | 163 |
1 files changed, 95 insertions, 68 deletions
diff --git a/fs/xfs/linux-2.6/xfs_lrw.c b/fs/xfs/linux-2.6/xfs_lrw.c index 558076dd0752..86fb671a8bcc 100644 --- a/fs/xfs/linux-2.6/xfs_lrw.c +++ b/fs/xfs/linux-2.6/xfs_lrw.c | |||
@@ -191,7 +191,7 @@ xfs_read( | |||
191 | struct file *file = iocb->ki_filp; | 191 | struct file *file = iocb->ki_filp; |
192 | struct inode *inode = file->f_mapping->host; | 192 | struct inode *inode = file->f_mapping->host; |
193 | size_t size = 0; | 193 | size_t size = 0; |
194 | ssize_t ret; | 194 | ssize_t ret = 0; |
195 | xfs_fsize_t n; | 195 | xfs_fsize_t n; |
196 | xfs_inode_t *ip; | 196 | xfs_inode_t *ip; |
197 | xfs_mount_t *mp; | 197 | xfs_mount_t *mp; |
@@ -224,7 +224,7 @@ xfs_read( | |||
224 | mp->m_rtdev_targp : mp->m_ddev_targp; | 224 | mp->m_rtdev_targp : mp->m_ddev_targp; |
225 | if ((*offset & target->bt_smask) || | 225 | if ((*offset & target->bt_smask) || |
226 | (size & target->bt_smask)) { | 226 | (size & target->bt_smask)) { |
227 | if (*offset == ip->i_d.di_size) { | 227 | if (*offset == ip->i_size) { |
228 | return (0); | 228 | return (0); |
229 | } | 229 | } |
230 | return -XFS_ERROR(EINVAL); | 230 | return -XFS_ERROR(EINVAL); |
@@ -263,9 +263,13 @@ xfs_read( | |||
263 | 263 | ||
264 | if (unlikely(ioflags & IO_ISDIRECT)) { | 264 | if (unlikely(ioflags & IO_ISDIRECT)) { |
265 | if (VN_CACHED(vp)) | 265 | if (VN_CACHED(vp)) |
266 | bhv_vop_flushinval_pages(vp, ctooff(offtoct(*offset)), | 266 | ret = bhv_vop_flushinval_pages(vp, ctooff(offtoct(*offset)), |
267 | -1, FI_REMAPF_LOCKED); | 267 | -1, FI_REMAPF_LOCKED); |
268 | mutex_unlock(&inode->i_mutex); | 268 | mutex_unlock(&inode->i_mutex); |
269 | if (ret) { | ||
270 | xfs_iunlock(ip, XFS_IOLOCK_SHARED); | ||
271 | return ret; | ||
272 | } | ||
269 | } | 273 | } |
270 | 274 | ||
271 | xfs_rw_enter_trace(XFS_READ_ENTER, &ip->i_iocore, | 275 | xfs_rw_enter_trace(XFS_READ_ENTER, &ip->i_iocore, |
@@ -383,9 +387,10 @@ xfs_splice_write( | |||
383 | { | 387 | { |
384 | xfs_inode_t *ip = XFS_BHVTOI(bdp); | 388 | xfs_inode_t *ip = XFS_BHVTOI(bdp); |
385 | xfs_mount_t *mp = ip->i_mount; | 389 | xfs_mount_t *mp = ip->i_mount; |
390 | xfs_iocore_t *io = &ip->i_iocore; | ||
386 | ssize_t ret; | 391 | ssize_t ret; |
387 | struct inode *inode = outfilp->f_mapping->host; | 392 | struct inode *inode = outfilp->f_mapping->host; |
388 | xfs_fsize_t isize; | 393 | xfs_fsize_t isize, new_size; |
389 | 394 | ||
390 | XFS_STATS_INC(xs_write_calls); | 395 | XFS_STATS_INC(xs_write_calls); |
391 | if (XFS_FORCED_SHUTDOWN(ip->i_mount)) | 396 | if (XFS_FORCED_SHUTDOWN(ip->i_mount)) |
@@ -406,6 +411,14 @@ xfs_splice_write( | |||
406 | return -error; | 411 | return -error; |
407 | } | 412 | } |
408 | } | 413 | } |
414 | |||
415 | new_size = *ppos + count; | ||
416 | |||
417 | xfs_ilock(ip, XFS_ILOCK_EXCL); | ||
418 | if (new_size > ip->i_size) | ||
419 | io->io_new_size = new_size; | ||
420 | xfs_iunlock(ip, XFS_ILOCK_EXCL); | ||
421 | |||
409 | xfs_rw_enter_trace(XFS_SPLICE_WRITE_ENTER, &ip->i_iocore, | 422 | xfs_rw_enter_trace(XFS_SPLICE_WRITE_ENTER, &ip->i_iocore, |
410 | pipe, count, *ppos, ioflags); | 423 | pipe, count, *ppos, ioflags); |
411 | ret = generic_file_splice_write(pipe, outfilp, ppos, count, flags); | 424 | ret = generic_file_splice_write(pipe, outfilp, ppos, count, flags); |
@@ -416,14 +429,18 @@ xfs_splice_write( | |||
416 | if (unlikely(ret < 0 && ret != -EFAULT && *ppos > isize)) | 429 | if (unlikely(ret < 0 && ret != -EFAULT && *ppos > isize)) |
417 | *ppos = isize; | 430 | *ppos = isize; |
418 | 431 | ||
419 | if (*ppos > ip->i_d.di_size) { | 432 | if (*ppos > ip->i_size) { |
420 | xfs_ilock(ip, XFS_ILOCK_EXCL); | 433 | xfs_ilock(ip, XFS_ILOCK_EXCL); |
421 | if (*ppos > ip->i_d.di_size) { | 434 | if (*ppos > ip->i_size) |
422 | ip->i_d.di_size = *ppos; | 435 | ip->i_size = *ppos; |
423 | i_size_write(inode, *ppos); | 436 | xfs_iunlock(ip, XFS_ILOCK_EXCL); |
424 | ip->i_update_core = 1; | 437 | } |
425 | ip->i_update_size = 1; | 438 | |
426 | } | 439 | if (io->io_new_size) { |
440 | xfs_ilock(ip, XFS_ILOCK_EXCL); | ||
441 | io->io_new_size = 0; | ||
442 | if (ip->i_d.di_size > ip->i_size) | ||
443 | ip->i_d.di_size = ip->i_size; | ||
427 | xfs_iunlock(ip, XFS_ILOCK_EXCL); | 444 | xfs_iunlock(ip, XFS_ILOCK_EXCL); |
428 | } | 445 | } |
429 | xfs_iunlock(ip, XFS_IOLOCK_EXCL); | 446 | xfs_iunlock(ip, XFS_IOLOCK_EXCL); |
@@ -644,7 +661,7 @@ xfs_write( | |||
644 | bhv_vrwlock_t locktype; | 661 | bhv_vrwlock_t locktype; |
645 | size_t ocount = 0, count; | 662 | size_t ocount = 0, count; |
646 | loff_t pos; | 663 | loff_t pos; |
647 | int need_i_mutex = 1, need_flush = 0; | 664 | int need_i_mutex; |
648 | 665 | ||
649 | XFS_STATS_INC(xs_write_calls); | 666 | XFS_STATS_INC(xs_write_calls); |
650 | 667 | ||
@@ -669,39 +686,20 @@ xfs_write( | |||
669 | if (XFS_FORCED_SHUTDOWN(mp)) | 686 | if (XFS_FORCED_SHUTDOWN(mp)) |
670 | return -EIO; | 687 | return -EIO; |
671 | 688 | ||
672 | if (ioflags & IO_ISDIRECT) { | ||
673 | xfs_buftarg_t *target = | ||
674 | (xip->i_d.di_flags & XFS_DIFLAG_REALTIME) ? | ||
675 | mp->m_rtdev_targp : mp->m_ddev_targp; | ||
676 | |||
677 | if ((pos & target->bt_smask) || (count & target->bt_smask)) | ||
678 | return XFS_ERROR(-EINVAL); | ||
679 | |||
680 | if (!VN_CACHED(vp) && pos < i_size_read(inode)) | ||
681 | need_i_mutex = 0; | ||
682 | |||
683 | if (VN_CACHED(vp)) | ||
684 | need_flush = 1; | ||
685 | } | ||
686 | |||
687 | relock: | 689 | relock: |
688 | if (need_i_mutex) { | 690 | if (ioflags & IO_ISDIRECT) { |
691 | iolock = XFS_IOLOCK_SHARED; | ||
692 | locktype = VRWLOCK_WRITE_DIRECT; | ||
693 | need_i_mutex = 0; | ||
694 | } else { | ||
689 | iolock = XFS_IOLOCK_EXCL; | 695 | iolock = XFS_IOLOCK_EXCL; |
690 | locktype = VRWLOCK_WRITE; | 696 | locktype = VRWLOCK_WRITE; |
691 | 697 | need_i_mutex = 1; | |
692 | mutex_lock(&inode->i_mutex); | 698 | mutex_lock(&inode->i_mutex); |
693 | } else { | ||
694 | iolock = XFS_IOLOCK_SHARED; | ||
695 | locktype = VRWLOCK_WRITE_DIRECT; | ||
696 | } | 699 | } |
697 | 700 | ||
698 | xfs_ilock(xip, XFS_ILOCK_EXCL|iolock); | 701 | xfs_ilock(xip, XFS_ILOCK_EXCL|iolock); |
699 | 702 | ||
700 | isize = i_size_read(inode); | ||
701 | |||
702 | if (file->f_flags & O_APPEND) | ||
703 | *offset = isize; | ||
704 | |||
705 | start: | 703 | start: |
706 | error = -generic_write_checks(file, &pos, &count, | 704 | error = -generic_write_checks(file, &pos, &count, |
707 | S_ISBLK(inode->i_mode)); | 705 | S_ISBLK(inode->i_mode)); |
@@ -710,13 +708,8 @@ start: | |||
710 | goto out_unlock_mutex; | 708 | goto out_unlock_mutex; |
711 | } | 709 | } |
712 | 710 | ||
713 | new_size = pos + count; | ||
714 | if (new_size > isize) | ||
715 | io->io_new_size = new_size; | ||
716 | |||
717 | if ((DM_EVENT_ENABLED(vp->v_vfsp, xip, DM_EVENT_WRITE) && | 711 | if ((DM_EVENT_ENABLED(vp->v_vfsp, xip, DM_EVENT_WRITE) && |
718 | !(ioflags & IO_INVIS) && !eventsent)) { | 712 | !(ioflags & IO_INVIS) && !eventsent)) { |
719 | loff_t savedsize = pos; | ||
720 | int dmflags = FILP_DELAY_FLAG(file); | 713 | int dmflags = FILP_DELAY_FLAG(file); |
721 | 714 | ||
722 | if (need_i_mutex) | 715 | if (need_i_mutex) |
@@ -727,8 +720,7 @@ start: | |||
727 | pos, count, | 720 | pos, count, |
728 | dmflags, &locktype); | 721 | dmflags, &locktype); |
729 | if (error) { | 722 | if (error) { |
730 | xfs_iunlock(xip, iolock); | 723 | goto out_unlock_internal; |
731 | goto out_unlock_mutex; | ||
732 | } | 724 | } |
733 | xfs_ilock(xip, XFS_ILOCK_EXCL); | 725 | xfs_ilock(xip, XFS_ILOCK_EXCL); |
734 | eventsent = 1; | 726 | eventsent = 1; |
@@ -740,12 +732,35 @@ start: | |||
740 | * event prevents another call to XFS_SEND_DATA, which is | 732 | * event prevents another call to XFS_SEND_DATA, which is |
741 | * what allows the size to change in the first place. | 733 | * what allows the size to change in the first place. |
742 | */ | 734 | */ |
743 | if ((file->f_flags & O_APPEND) && savedsize != isize) { | 735 | if ((file->f_flags & O_APPEND) && pos != xip->i_size) |
744 | pos = isize = xip->i_d.di_size; | 736 | goto start; |
737 | } | ||
738 | |||
739 | if (ioflags & IO_ISDIRECT) { | ||
740 | xfs_buftarg_t *target = | ||
741 | (xip->i_d.di_flags & XFS_DIFLAG_REALTIME) ? | ||
742 | mp->m_rtdev_targp : mp->m_ddev_targp; | ||
743 | |||
744 | if ((pos & target->bt_smask) || (count & target->bt_smask)) { | ||
745 | xfs_iunlock(xip, XFS_ILOCK_EXCL|iolock); | ||
746 | return XFS_ERROR(-EINVAL); | ||
747 | } | ||
748 | |||
749 | if (!need_i_mutex && (VN_CACHED(vp) || pos > xip->i_size)) { | ||
750 | xfs_iunlock(xip, XFS_ILOCK_EXCL|iolock); | ||
751 | iolock = XFS_IOLOCK_EXCL; | ||
752 | locktype = VRWLOCK_WRITE; | ||
753 | need_i_mutex = 1; | ||
754 | mutex_lock(&inode->i_mutex); | ||
755 | xfs_ilock(xip, XFS_ILOCK_EXCL|iolock); | ||
745 | goto start; | 756 | goto start; |
746 | } | 757 | } |
747 | } | 758 | } |
748 | 759 | ||
760 | new_size = pos + count; | ||
761 | if (new_size > xip->i_size) | ||
762 | io->io_new_size = new_size; | ||
763 | |||
749 | if (likely(!(ioflags & IO_INVIS))) { | 764 | if (likely(!(ioflags & IO_INVIS))) { |
750 | file_update_time(file); | 765 | file_update_time(file); |
751 | xfs_ichgtime_fast(xip, inode, | 766 | xfs_ichgtime_fast(xip, inode, |
@@ -761,11 +776,11 @@ start: | |||
761 | * to zero it out up to the new size. | 776 | * to zero it out up to the new size. |
762 | */ | 777 | */ |
763 | 778 | ||
764 | if (pos > isize) { | 779 | if (pos > xip->i_size) { |
765 | error = xfs_zero_eof(BHV_TO_VNODE(bdp), io, pos, isize); | 780 | error = xfs_zero_eof(BHV_TO_VNODE(bdp), io, pos, xip->i_size); |
766 | if (error) { | 781 | if (error) { |
767 | xfs_iunlock(xip, XFS_ILOCK_EXCL|iolock); | 782 | xfs_iunlock(xip, XFS_ILOCK_EXCL); |
768 | goto out_unlock_mutex; | 783 | goto out_unlock_internal; |
769 | } | 784 | } |
770 | } | 785 | } |
771 | xfs_iunlock(xip, XFS_ILOCK_EXCL); | 786 | xfs_iunlock(xip, XFS_ILOCK_EXCL); |
@@ -785,8 +800,7 @@ start: | |||
785 | if (likely(!error)) | 800 | if (likely(!error)) |
786 | error = -remove_suid(file->f_path.dentry); | 801 | error = -remove_suid(file->f_path.dentry); |
787 | if (unlikely(error)) { | 802 | if (unlikely(error)) { |
788 | xfs_iunlock(xip, iolock); | 803 | goto out_unlock_internal; |
789 | goto out_unlock_mutex; | ||
790 | } | 804 | } |
791 | } | 805 | } |
792 | 806 | ||
@@ -795,11 +809,14 @@ retry: | |||
795 | current->backing_dev_info = mapping->backing_dev_info; | 809 | current->backing_dev_info = mapping->backing_dev_info; |
796 | 810 | ||
797 | if ((ioflags & IO_ISDIRECT)) { | 811 | if ((ioflags & IO_ISDIRECT)) { |
798 | if (need_flush) { | 812 | if (VN_CACHED(vp)) { |
813 | WARN_ON(need_i_mutex == 0); | ||
799 | xfs_inval_cached_trace(io, pos, -1, | 814 | xfs_inval_cached_trace(io, pos, -1, |
800 | ctooff(offtoct(pos)), -1); | 815 | ctooff(offtoct(pos)), -1); |
801 | bhv_vop_flushinval_pages(vp, ctooff(offtoct(pos)), | 816 | error = bhv_vop_flushinval_pages(vp, ctooff(offtoct(pos)), |
802 | -1, FI_REMAPF_LOCKED); | 817 | -1, FI_REMAPF_LOCKED); |
818 | if (error) | ||
819 | goto out_unlock_internal; | ||
803 | } | 820 | } |
804 | 821 | ||
805 | if (need_i_mutex) { | 822 | if (need_i_mutex) { |
@@ -827,7 +844,6 @@ retry: | |||
827 | pos += ret; | 844 | pos += ret; |
828 | count -= ret; | 845 | count -= ret; |
829 | 846 | ||
830 | need_i_mutex = 1; | ||
831 | ioflags &= ~IO_ISDIRECT; | 847 | ioflags &= ~IO_ISDIRECT; |
832 | xfs_iunlock(xip, iolock); | 848 | xfs_iunlock(xip, iolock); |
833 | goto relock; | 849 | goto relock; |
@@ -854,12 +870,12 @@ retry: | |||
854 | error = XFS_SEND_NAMESP(xip->i_mount, DM_EVENT_NOSPACE, vp, | 870 | error = XFS_SEND_NAMESP(xip->i_mount, DM_EVENT_NOSPACE, vp, |
855 | DM_RIGHT_NULL, vp, DM_RIGHT_NULL, NULL, NULL, | 871 | DM_RIGHT_NULL, vp, DM_RIGHT_NULL, NULL, NULL, |
856 | 0, 0, 0); /* Delay flag intentionally unused */ | 872 | 0, 0, 0); /* Delay flag intentionally unused */ |
857 | if (error) | ||
858 | goto out_nounlocks; | ||
859 | if (need_i_mutex) | 873 | if (need_i_mutex) |
860 | mutex_lock(&inode->i_mutex); | 874 | mutex_lock(&inode->i_mutex); |
861 | xfs_rwlock(bdp, locktype); | 875 | xfs_rwlock(bdp, locktype); |
862 | pos = xip->i_d.di_size; | 876 | if (error) |
877 | goto out_unlock_internal; | ||
878 | pos = xip->i_size; | ||
863 | ret = 0; | 879 | ret = 0; |
864 | goto retry; | 880 | goto retry; |
865 | } | 881 | } |
@@ -868,14 +884,10 @@ retry: | |||
868 | if (unlikely(ret < 0 && ret != -EFAULT && *offset > isize)) | 884 | if (unlikely(ret < 0 && ret != -EFAULT && *offset > isize)) |
869 | *offset = isize; | 885 | *offset = isize; |
870 | 886 | ||
871 | if (*offset > xip->i_d.di_size) { | 887 | if (*offset > xip->i_size) { |
872 | xfs_ilock(xip, XFS_ILOCK_EXCL); | 888 | xfs_ilock(xip, XFS_ILOCK_EXCL); |
873 | if (*offset > xip->i_d.di_size) { | 889 | if (*offset > xip->i_size) |
874 | xip->i_d.di_size = *offset; | 890 | xip->i_size = *offset; |
875 | i_size_write(inode, *offset); | ||
876 | xip->i_update_core = 1; | ||
877 | xip->i_update_size = 1; | ||
878 | } | ||
879 | xfs_iunlock(xip, XFS_ILOCK_EXCL); | 891 | xfs_iunlock(xip, XFS_ILOCK_EXCL); |
880 | } | 892 | } |
881 | 893 | ||
@@ -897,16 +909,31 @@ retry: | |||
897 | 909 | ||
898 | error = sync_page_range(inode, mapping, pos, ret); | 910 | error = sync_page_range(inode, mapping, pos, ret); |
899 | if (!error) | 911 | if (!error) |
900 | error = ret; | 912 | error = -ret; |
901 | return error; | 913 | if (need_i_mutex) |
914 | mutex_lock(&inode->i_mutex); | ||
915 | xfs_rwlock(bdp, locktype); | ||
902 | } | 916 | } |
903 | 917 | ||
904 | out_unlock_internal: | 918 | out_unlock_internal: |
919 | if (io->io_new_size) { | ||
920 | xfs_ilock(xip, XFS_ILOCK_EXCL); | ||
921 | io->io_new_size = 0; | ||
922 | /* | ||
923 | * If this was a direct or synchronous I/O that failed (such | ||
924 | * as ENOSPC) then part of the I/O may have been written to | ||
925 | * disk before the error occured. In this case the on-disk | ||
926 | * file size may have been adjusted beyond the in-memory file | ||
927 | * size and now needs to be truncated back. | ||
928 | */ | ||
929 | if (xip->i_d.di_size > xip->i_size) | ||
930 | xip->i_d.di_size = xip->i_size; | ||
931 | xfs_iunlock(xip, XFS_ILOCK_EXCL); | ||
932 | } | ||
905 | xfs_rwunlock(bdp, locktype); | 933 | xfs_rwunlock(bdp, locktype); |
906 | out_unlock_mutex: | 934 | out_unlock_mutex: |
907 | if (need_i_mutex) | 935 | if (need_i_mutex) |
908 | mutex_unlock(&inode->i_mutex); | 936 | mutex_unlock(&inode->i_mutex); |
909 | out_nounlocks: | ||
910 | return -error; | 937 | return -error; |
911 | } | 938 | } |
912 | 939 | ||