diff options
author | Dave Chinner <david@fromorbit.com> | 2008-11-27 22:23:33 -0500 |
---|---|---|
committer | Niv Sardi <xaiki@sgi.com> | 2008-11-30 19:11:10 -0500 |
commit | 2e6560929d8ab4b650fecc3a87013852b34f0922 (patch) | |
tree | 59da3284d66e3a5bdf86780a009bf2ce941fbfd4 /fs/xfs | |
parent | 65795910c1b798f8a47181b48cf6eb163a15e778 (diff) |
[XFS] fix error inversion problems with data flushing
XFS gets the sign of the error wrong in several places when
gathering the error from generic linux functions. These functions
return negative error values, while the core XFS code returns
positive error values. Hence when XFS inverts the error to be
returned to the VFS, it can incorrectly invert a negative
error and this error will be ignored by the syscall return.
Fix all the problems related to calling filemap_* functions.
Problem initially identified by Nick Piggin in xfs_fsync().
Signed-off-by: Dave Chinner <david@fromorbit.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Niv Sardi <xaiki@sgi.com>
Diffstat (limited to 'fs/xfs')
-rw-r--r-- | fs/xfs/linux-2.6/xfs_fs_subr.c | 23 | ||||
-rw-r--r-- | fs/xfs/linux-2.6/xfs_lrw.c | 2 | ||||
-rw-r--r-- | fs/xfs/linux-2.6/xfs_super.c | 13 | ||||
-rw-r--r-- | fs/xfs/xfs_vnodeops.c | 2 | ||||
-rw-r--r-- | fs/xfs/xfs_vnodeops.h | 1 |
5 files changed, 32 insertions, 9 deletions
diff --git a/fs/xfs/linux-2.6/xfs_fs_subr.c b/fs/xfs/linux-2.6/xfs_fs_subr.c index 36caa6d957df..5aeb77776961 100644 --- a/fs/xfs/linux-2.6/xfs_fs_subr.c +++ b/fs/xfs/linux-2.6/xfs_fs_subr.c | |||
@@ -24,6 +24,10 @@ int fs_noerr(void) { return 0; } | |||
24 | int fs_nosys(void) { return ENOSYS; } | 24 | int fs_nosys(void) { return ENOSYS; } |
25 | void fs_noval(void) { return; } | 25 | void fs_noval(void) { return; } |
26 | 26 | ||
27 | /* | ||
28 | * note: all filemap functions return negative error codes. These | ||
29 | * need to be inverted before returning to the xfs core functions. | ||
30 | */ | ||
27 | void | 31 | void |
28 | xfs_tosspages( | 32 | xfs_tosspages( |
29 | xfs_inode_t *ip, | 33 | xfs_inode_t *ip, |
@@ -53,7 +57,7 @@ xfs_flushinval_pages( | |||
53 | if (!ret) | 57 | if (!ret) |
54 | truncate_inode_pages(mapping, first); | 58 | truncate_inode_pages(mapping, first); |
55 | } | 59 | } |
56 | return ret; | 60 | return -ret; |
57 | } | 61 | } |
58 | 62 | ||
59 | int | 63 | int |
@@ -72,10 +76,23 @@ xfs_flush_pages( | |||
72 | xfs_iflags_clear(ip, XFS_ITRUNCATED); | 76 | xfs_iflags_clear(ip, XFS_ITRUNCATED); |
73 | ret = filemap_fdatawrite(mapping); | 77 | ret = filemap_fdatawrite(mapping); |
74 | if (flags & XFS_B_ASYNC) | 78 | if (flags & XFS_B_ASYNC) |
75 | return ret; | 79 | return -ret; |
76 | ret2 = filemap_fdatawait(mapping); | 80 | ret2 = filemap_fdatawait(mapping); |
77 | if (!ret) | 81 | if (!ret) |
78 | ret = ret2; | 82 | ret = ret2; |
79 | } | 83 | } |
80 | return ret; | 84 | return -ret; |
85 | } | ||
86 | |||
87 | int | ||
88 | xfs_wait_on_pages( | ||
89 | xfs_inode_t *ip, | ||
90 | xfs_off_t first, | ||
91 | xfs_off_t last) | ||
92 | { | ||
93 | struct address_space *mapping = VFS_I(ip)->i_mapping; | ||
94 | |||
95 | if (mapping_tagged(mapping, PAGECACHE_TAG_WRITEBACK)) | ||
96 | return -filemap_fdatawait(mapping); | ||
97 | return 0; | ||
81 | } | 98 | } |
diff --git a/fs/xfs/linux-2.6/xfs_lrw.c b/fs/xfs/linux-2.6/xfs_lrw.c index 1957e5357d04..4959c8744997 100644 --- a/fs/xfs/linux-2.6/xfs_lrw.c +++ b/fs/xfs/linux-2.6/xfs_lrw.c | |||
@@ -243,7 +243,7 @@ xfs_read( | |||
243 | 243 | ||
244 | if (unlikely(ioflags & IO_ISDIRECT)) { | 244 | if (unlikely(ioflags & IO_ISDIRECT)) { |
245 | if (inode->i_mapping->nrpages) | 245 | if (inode->i_mapping->nrpages) |
246 | ret = xfs_flushinval_pages(ip, (*offset & PAGE_CACHE_MASK), | 246 | ret = -xfs_flushinval_pages(ip, (*offset & PAGE_CACHE_MASK), |
247 | -1, FI_REMAPF_LOCKED); | 247 | -1, FI_REMAPF_LOCKED); |
248 | mutex_unlock(&inode->i_mutex); | 248 | mutex_unlock(&inode->i_mutex); |
249 | if (ret) { | 249 | if (ret) { |
diff --git a/fs/xfs/linux-2.6/xfs_super.c b/fs/xfs/linux-2.6/xfs_super.c index cc5e07e3e7a1..ae92290e3c14 100644 --- a/fs/xfs/linux-2.6/xfs_super.c +++ b/fs/xfs/linux-2.6/xfs_super.c | |||
@@ -990,21 +990,26 @@ xfs_fs_write_inode( | |||
990 | struct inode *inode, | 990 | struct inode *inode, |
991 | int sync) | 991 | int sync) |
992 | { | 992 | { |
993 | struct xfs_inode *ip = XFS_I(inode); | ||
993 | int error = 0; | 994 | int error = 0; |
994 | int flags = 0; | 995 | int flags = 0; |
995 | 996 | ||
996 | xfs_itrace_entry(XFS_I(inode)); | 997 | xfs_itrace_entry(ip); |
997 | if (sync) { | 998 | if (sync) { |
998 | filemap_fdatawait(inode->i_mapping); | 999 | error = xfs_wait_on_pages(ip, 0, -1); |
1000 | if (error) | ||
1001 | goto out_error; | ||
999 | flags |= FLUSH_SYNC; | 1002 | flags |= FLUSH_SYNC; |
1000 | } | 1003 | } |
1001 | error = xfs_inode_flush(XFS_I(inode), flags); | 1004 | error = xfs_inode_flush(ip, flags); |
1005 | |||
1006 | out_error: | ||
1002 | /* | 1007 | /* |
1003 | * if we failed to write out the inode then mark | 1008 | * if we failed to write out the inode then mark |
1004 | * it dirty again so we'll try again later. | 1009 | * it dirty again so we'll try again later. |
1005 | */ | 1010 | */ |
1006 | if (error) | 1011 | if (error) |
1007 | xfs_mark_inode_dirty_sync(XFS_I(inode)); | 1012 | xfs_mark_inode_dirty_sync(ip); |
1008 | 1013 | ||
1009 | return -error; | 1014 | return -error; |
1010 | } | 1015 | } |
diff --git a/fs/xfs/xfs_vnodeops.c b/fs/xfs/xfs_vnodeops.c index c055bdb11cb7..f26b038004a7 100644 --- a/fs/xfs/xfs_vnodeops.c +++ b/fs/xfs/xfs_vnodeops.c | |||
@@ -681,7 +681,7 @@ xfs_fsync( | |||
681 | return XFS_ERROR(EIO); | 681 | return XFS_ERROR(EIO); |
682 | 682 | ||
683 | /* capture size updates in I/O completion before writing the inode. */ | 683 | /* capture size updates in I/O completion before writing the inode. */ |
684 | error = filemap_fdatawait(VFS_I(ip)->i_mapping); | 684 | error = xfs_wait_on_pages(ip, 0, -1); |
685 | if (error) | 685 | if (error) |
686 | return XFS_ERROR(error); | 686 | return XFS_ERROR(error); |
687 | 687 | ||
diff --git a/fs/xfs/xfs_vnodeops.h b/fs/xfs/xfs_vnodeops.h index a559400aeae0..2a45b00ad32e 100644 --- a/fs/xfs/xfs_vnodeops.h +++ b/fs/xfs/xfs_vnodeops.h | |||
@@ -75,5 +75,6 @@ int xfs_flushinval_pages(struct xfs_inode *ip, xfs_off_t first, | |||
75 | xfs_off_t last, int fiopt); | 75 | xfs_off_t last, int fiopt); |
76 | int xfs_flush_pages(struct xfs_inode *ip, xfs_off_t first, | 76 | int xfs_flush_pages(struct xfs_inode *ip, xfs_off_t first, |
77 | xfs_off_t last, uint64_t flags, int fiopt); | 77 | xfs_off_t last, uint64_t flags, int fiopt); |
78 | int xfs_wait_on_pages(struct xfs_inode *ip, xfs_off_t first, xfs_off_t last); | ||
78 | 79 | ||
79 | #endif /* _XFS_VNODEOPS_H */ | 80 | #endif /* _XFS_VNODEOPS_H */ |