Commit a7634cff authored by Andrew Morton's avatar Andrew Morton Committed by Russell King

[PATCH] O_DIRECT invalidation fix

If the alignment checks in generic_direct_IO() fail, we end up not
forcing writeback of dirty pagecache pages, but we still run
invalidate_inode_pages2().  The net result is that dirty pagecache gets
incorrectly removed.  I guess this will expose unwritten disk blocks.

So move the sync up into generic_file_direct_IO(), where we perform the
invalidation.  So we know that pagecache and disk are in sync before we
do anything else.
parent 911ceab5
...@@ -620,13 +620,11 @@ generic_direct_IO(int rw, struct inode *inode, const struct iovec *iov, ...@@ -620,13 +620,11 @@ generic_direct_IO(int rw, struct inode *inode, const struct iovec *iov,
int seg; int seg;
size_t size; size_t size;
unsigned long addr; unsigned long addr;
struct address_space *mapping = inode->i_mapping;
unsigned blocksize_mask = (1 << inode->i_blkbits) - 1; unsigned blocksize_mask = (1 << inode->i_blkbits) - 1;
ssize_t retval = -EINVAL; ssize_t retval = -EINVAL;
if (offset & blocksize_mask) { if (offset & blocksize_mask)
goto out; goto out;
}
/* Check the memory alignment. Blocks cannot straddle pages */ /* Check the memory alignment. Blocks cannot straddle pages */
for (seg = 0; seg < nr_segs; seg++) { for (seg = 0; seg < nr_segs; seg++) {
...@@ -636,14 +634,6 @@ generic_direct_IO(int rw, struct inode *inode, const struct iovec *iov, ...@@ -636,14 +634,6 @@ generic_direct_IO(int rw, struct inode *inode, const struct iovec *iov,
goto out; goto out;
} }
if (mapping->nrpages) {
retval = filemap_fdatawrite(mapping);
if (retval == 0)
retval = filemap_fdatawait(mapping);
if (retval)
goto out;
}
retval = direct_io_worker(rw, inode, iov, offset, nr_segs, get_blocks); retval = direct_io_worker(rw, inode, iov, offset, nr_segs, get_blocks);
out: out:
return retval; return retval;
...@@ -656,8 +646,17 @@ generic_file_direct_IO(int rw, struct inode *inode, const struct iovec *iov, ...@@ -656,8 +646,17 @@ generic_file_direct_IO(int rw, struct inode *inode, const struct iovec *iov,
struct address_space *mapping = inode->i_mapping; struct address_space *mapping = inode->i_mapping;
ssize_t retval; ssize_t retval;
if (mapping->nrpages) {
retval = filemap_fdatawrite(mapping);
if (retval == 0)
retval = filemap_fdatawait(mapping);
if (retval)
goto out;
}
retval = mapping->a_ops->direct_IO(rw, inode, iov, offset, nr_segs); retval = mapping->a_ops->direct_IO(rw, inode, iov, offset, nr_segs);
if (inode->i_mapping->nrpages) if (inode->i_mapping->nrpages)
invalidate_inode_pages2(inode->i_mapping); invalidate_inode_pages2(inode->i_mapping);
out:
return retval; return retval;
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment