Josef Bacik
2011-Apr-08 15:51 UTC
[PATCH] Btrfs: check for duplicate iov_base''s when doing dio reads
Apparently it is ok to submit a read to an IDE device with the same target page for different offsets. This is what Windows does under qemu. The problem is under DIO we expect them to be different buffers for checksumming reasons, and so this sort of thing will result in checksum errors, when in reality the file is fine. So when reading, check to make sure that all iov bases are different, and if they aren''t fall back to buffered mode, since that will work out right. Thanks, Signed-off-by: Josef Bacik <josef@redhat.com> --- fs/btrfs/inode.c | 17 ++++++++++++++++- 1 files changed, 16 insertions(+), 1 deletions(-) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 032e8fb..c4b914e 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -6205,6 +6205,7 @@ static ssize_t check_direct_IO(struct btrfs_root *root, int rw, struct kiocb *io unsigned long nr_segs) { int seg; + int i; size_t size; unsigned long addr; unsigned blocksize_mask = root->sectorsize - 1; @@ -6219,8 +6220,22 @@ static ssize_t check_direct_IO(struct btrfs_root *root, int rw, struct kiocb *io addr = (unsigned long)iov[seg].iov_base; size = iov[seg].iov_len; end += size; - if ((addr & blocksize_mask) || (size & blocksize_mask)) + if ((addr & blocksize_mask) || (size & blocksize_mask)) goto out; + + /* If this is a write we don''t need to check anymore */ + if (rw & WRITE) + continue; + + /* + * Check to make sure we don''t have duplicate iov_base''s in this + * iovec, if so return EINVAL, otherwise we''ll get csum errors + * when reading back. + */ + for (i = seg + 1; i < nr_segs; i++) { + if (iov[seg].iov_base == iov[i].iov_base) + goto out; + } } retval = 0; out: -- 1.7.2.3 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Reasonably Related Threads
- [RFC][PATCH 2/2] Btrfs: implement unlocked dio write
- [PATCH 1/4] fs: allow short direct-io reads to be completed via buffered IO V2
- [PATCH 2/4] direct-io: add a hook for the fs to provide its own submit_bio function V3
- [PATCH 1/3] fs: allow short direct-io reads to be completed via buffered IO V2
- [RFC][PATCH] direct-io: btrfs: avoid splitting dio requests for non-btrfs filesystems