block: fix multiwrite_merge() overlapping requests
cover block: fix multiwrite_merge() overlapping requests
This is a fix for https://bugs.launchpad.net/qemu/+bug/1343827.
Patch 1 fixes the bug. Patch 2 adds a qemu-iotests test case to prevent regressions.
Stefan Hajnoczi (2):
block: fix overlapping multiwrite requests
qemu-iotests: add multiwrite test cases
block.c | 6 +++ tests/qemu-iotests/100 | 97 ++++++++++++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/100.out | 54 ++++++++++++++++++++++++++ tests/qemu-iotests/group | 1 + 4 files changed, 158 insertions(+) create mode 100755 tests/qemu-iotests/100 create mode 100644 tests/qemu-iotests/100.out
Signature · 1 line
1.9.3
PATCH 1/2 block: fix overlapping multiwrite requests
When request A is a strict subset of request B:
AAAAAAAA
BBBB
multiwrite_merge() merges them as follows:
AABBBB
The tail of request A should have been included:
AABBBBAA
This patch fixes data loss but this code path is probably rare. Since guests cannot assume ordering between in-flight requests, few applications submit overlapping write requests.
--- block.c | 6 ++++++ 1 file changed, 6 insertions(+)
block.c +6 -0
@@ -4498,6 +4498,12 @@ static int multiwrite_merge(BlockDriverState *bs, BlockRequest *reqs,// Add the second request qemu_iovec_concat (qiov, reqs[i].qiov,0 , reqs[i].qiov->size); +// Add tail of first request, if necessary +if (qiov->size < reqs[outidx].qiov->size) { +qemu_iovec_concat (qiov, reqs[outidx].qiov, qiov->size, + reqs[outidx].qiov->size - qiov->size); + } + reqs[outidx].nb_sectors = qiov->size >>9 ; reqs[outidx].qiov = qiov;
Signature · 1 line
1.9.3
Re: [Qemu-devel] [PATCH 1/2] block: fix overlapping multiwrite requests
Quoted 4 lines · Stefan Hajnoczi
When request A is a strict subset of request B:
AAAAAAAA
BBBB
s/subset/superset/ ?
Fam
Re: [Qemu-devel] [PATCH 1/2] block: fix overlapping multiwrite requests
Quoted 7 lines · Fam Zheng
Quoted 4 lines · Stefan Hajnoczi
When request A is a strict subset of request B:
AAAAAAAA
BBBBs/subset/superset/ ?
Yes :)
PATCH 2/2 qemu-iotests: add multiwrite test cases
In reply to Stefan HajnocziThis test case covers the basic bdrv_aio_multiwrite() scenarios:
1. Single request
2. Sequential requests
3. Overlapping requests
4. Disjoint requests
--- tests/qemu-iotests/100 | 97 ++++++++++++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/100.out | 54 ++++++++++++++++++++++++++ tests/qemu-iotests/group | 1 + 3 files changed, 152 insertions(+) create mode 100755 tests/qemu-iotests/100 create mode 100644 tests/qemu-iotests/100.out
tests/qemu-iotests/100 new file +97 -0
@@ -0,0 +1,97 @@ +#!/bin/bash +# +# Test simple read/write using plain bdrv_read/bdrv_write +# +# Copyright (C) 2014 Red Hat, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# + +# creator [email protected] + +seq=`basename $0` +echo "QA output created by $seq" + +here=`pwd` +tmp=/tmp/$$ +status=1 # failure is the default! + +_cleanup() +{ + _cleanup_test_img +} +trap "_cleanup; exit \$status" 0 1 2 3 15 + +# get standard environment, filters and checks +. ./common.rc +. ./common.filter + +_supported_fmt generic +_supported_proto generic +_supported_os Linux + + +size=128M + +echo +echo "== Single request ==" +_make_test_img $size +$QEMU_IO -c "multiwrite 0 4k" "$TEST_IMG" | _filter_qemu_io + +echo +echo "== verify pattern ==" +$QEMU_IO -c "read -P 0xcd 0 4k" "$TEST_IMG" | _filter_qemu_io +$QEMU_IO -c "read -P 0 4k 4k" "$TEST_IMG" | _filter_qemu_io + +echo +echo "== Sequential requests ==" +_make_test_img $size +$QEMU_IO -c "multiwrite 0 4k ; 4k 4k" "$TEST_IMG" | _filter_qemu_io + +echo +echo "== verify pattern ==" +$QEMU_IO -c "read -P 0xcd 0 4k" "$TEST_IMG" | _filter_qemu_io +$QEMU_IO -c "read -P 0xce 4k 4k" "$TEST_IMG" | _filter_qemu_io +$QEMU_IO -c "read -P 0 8k 4k" "$TEST_IMG" | _filter_qemu_io + +echo +echo "== Overlapping requests ==" +_make_test_img $size +$QEMU_IO -c "multiwrite 0 4k ; 1k 2k" "$TEST_IMG" | _filter_qemu_io + +echo +echo "== verify pattern ==" +# Order of overlapping in-flight requests is not guaranteed so we cannot verify +# [1k, 3k) since it could have either pattern 0xcd or 0xce. +$QEMU_IO -c "read -P 0xcd 0 1k" "$TEST_IMG" | _filter_qemu_io +$QEMU_IO -c "read -P 0xcd 3k 1k" "$TEST_IMG" | _filter_qemu_io +$QEMU_IO -c "read -P 0 4k 4k" "$TEST_IMG" | _filter_qemu_io + +echo +echo "== Disjoint requests ==" +_make_test_img $size +$QEMU_IO -c "multiwrite 0 4k ; 64k 4k" "$TEST_IMG" | _filter_qemu_io + +echo +echo "== verify pattern ==" +$QEMU_IO -c "read -P 0xcd 0 4k" "$TEST_IMG" | _filter_qemu_io +$QEMU_IO -c "read -P 0 4k 60k" "$TEST_IMG" | _filter_qemu_io +$QEMU_IO -c "read -P 0xce 64k 4k" "$TEST_IMG" | _filter_qemu_io +$QEMU_IO -c "read -P 0 68k 4k" "$TEST_IMG" | _filter_qemu_io + +# success, all done +echo "*** done" +rm -f $seq.full +status=0
tests/qemu-iotests/100.out new file +54 -0
54 lines not on this page · raw message
tests/qemu-iotests/group +1 -0
@@ -100,3 +100,4 @@ 091 rw auto quick 092 rw auto quick 095 rw auto quick +100 rw auto quick
Signature · 1 line
1.9.3
Re: [Qemu-devel] [PATCH 2/2] qemu-iotests: add multiwrite test cases
Quoted 9 lines · Stefan Hajnoczi
This test case covers the basic
bdrv_aio_multiwrite()scenarios:
1. Single request
2. Sequential requests
3. Overlapping requests
4. Disjoint requestsSigned-off-by Stefan Hajnoczi <[email protected]>---
tests/qemu-iotests/100 line 73
Quoted 5 lines
tests/qemu-iotests/100 new file +5
-0+echo +echo "== Overlapping requests ==" +_make_test_img $size +$QEMU_IO -c "multiwrite 0 4k ; 1k 2k" "$TEST_IMG" | _filter_qemu_io +
This only tests superset overlap:
AAAA
BB
Wouldn't it be good to also test head overlap, tail overlap, and subset overlap, as in:
AAA
BB
AAA
BB
AA
BBBB
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH 2/2] qemu-iotests: add multiwrite test cases
Quoted 24 lines · Eric Blake
Quoted 9 lines · Stefan Hajnoczi
This test case covers the basic
bdrv_aio_multiwrite()scenarios:
1. Single request
2. Sequential requests
3. Overlapping requests
4. Disjoint requestsSigned-off-by Stefan Hajnoczi <[email protected]>---
tests/qemu-iotests/100 line 73
Quoted 5 lines
tests/qemu-iotests/100 new file +5
-0+echo +echo "== Overlapping requests ==" +_make_test_img $size +$QEMU_IO -c "multiwrite 0 4k ; 1k 2k" "$TEST_IMG" | _filter_qemu_io +This only tests superset overlap:
AAAA
BBWouldn't it be good to also test head overlap, tail overlap, and subset overlap, as in:
Quoted 8 lines
AAA
BBAAA
BBAA
BBBB
Sure, I can add more test cases in v2.
Stefan
Re: [Qemu-devel] [PATCH 2/2] qemu-iotests: add multiwrite test cases
Why are you guys merging requests in qemu at all? Just submit them to the kernel and let the kernel do it.
Quoted 38 lines · Stefan Hajnoczi
Quoted 24 lines · Eric Blake
Quoted 9 lines · Stefan Hajnoczi
This test case covers the basic
bdrv_aio_multiwrite()scenarios:
1. Single request
2. Sequential requests
3. Overlapping requests
4. Disjoint requestsSigned-off-by Stefan Hajnoczi <[email protected]>---
tests/qemu-iotests/100 line 73
Quoted 5 lines
tests/qemu-iotests/100 new file +5
-0+echo +echo "== Overlapping requests ==" +_make_test_img $size +$QEMU_IO -c "multiwrite 0 4k ; 1k 2k" "$TEST_IMG" | _filter_qemu_io +This only tests superset overlap:
AAAA
BBWouldn't it be good to also test head overlap, tail overlap, and subset overlap, as in:
Quoted 8 lines
AAA
BBAAA
BBAA
BBBBSure, I can add more test cases in v2.
Stefan
Re: [Qemu-devel] [PATCH 2/2] qemu-iotests: add multiwrite test cases
Am 31.07.2014 um 20:19 hat Slava Pestov geschrieben:
Quoted 2 lines
Why are you guys merging requests in qemu at all? Just submit them to the kernel and let the kernel do it.
Because the kernel generally isn't the next one seeing the requests. You might be right for the special case of using only raw images with cache=none,aio=native, where we would theoretically have a chance to submit all requests in a batch with a single syscall and then let the kernel merge them. It just isn't what everyone is running.
An important case is requests going to non-raw image format drivers, where many small writes on sparse images are inefficient because they cause a lot of unnecessary COW activity. Another case are backends that don't even send the requests to the kernel, but use e.g. a network protocol as their backend.
Kevin