34b321
From 31ce74359a069be69af0f6ba2f7867ed2083317a Mon Sep 17 00:00:00 2001
34b321
From: John Snow <jsnow@redhat.com>
34b321
Date: Tue, 8 Dec 2015 20:30:59 +0100
34b321
Subject: [PATCH 21/27] ide-test: fix failure for test_flush
34b321
34b321
RH-Author: John Snow <jsnow@redhat.com>
34b321
Message-id: <1449606659-23710-1-git-send-email-jsnow@redhat.com>
34b321
Patchwork-id: 68521
34b321
O-Subject: [RHEL-7.3 qemu-kvm PATCH v3 21/21] ide-test: fix failure for test_flush
34b321
Bugzilla: 1272523
34b321
RH-Acked-by: Thomas Huth <thuth@redhat.com>
34b321
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
34b321
RH-Acked-by: Max Reitz <mreitz@redhat.com>
34b321
34b321
This patch is a combination of two patches:
34b321
34b321
(1) Revert "qtest/ide-test: disable flush-test"
34b321
(2) ide-test: fix failure for test_flush
34b321
34b321
First, the downstream-only revert:
34b321
This reverts commit 228e49fabffa644ab7a6a03e98205f293115dc89.
34b321
34b321
Second, the backported fix:
34b321
34b321
bd07684aacfb61668ae2c25b7dd00b64f3d7c7f3 added a test to ensure BSY
34b321
flag is set when a flush request is in flight. It does this by setting
34b321
a blkdebug breakpoint on flush_to_os before issuing a CMD_FLUSH_CACHE.
34b321
It then resumes CMD_FLUSH_CACHE operation and checks that BSY is unset.
34b321
34b321
The actual unsetting of BSY does not occur until ide_flush_cb gets
34b321
called in a bh, however, so in some cases this check will race with
34b321
the actual completion.
34b321
34b321
Fix this by polling the ide status register until BSY flag gets unset
34b321
before we do our final sanity checks. According to
34b321
f68ec8379e88502b4841a110c070e9b118d3151c this is in line with how a guest
34b321
would determine whether or not the device is still busy.
34b321
34b321
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
34b321
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
34b321
(cherry picked from commit 22bfa16ed3d4c9d534dcfe6f2381a654f32296b9)
34b321
Signed-off-by: John Snow <jsnow@redhat.com>
34b321
---
34b321
 tests/ide-test.c | 41 +++++++++++++++++++++++++++++++++++++++++
34b321
 1 file changed, 41 insertions(+)
34b321
34b321
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
34b321
---
34b321
 tests/ide-test.c | 41 +++++++++++++++++++++++++++++++++++++++++
34b321
 1 file changed, 41 insertions(+)
34b321
34b321
diff --git a/tests/ide-test.c b/tests/ide-test.c
34b321
index 43b7fd6..92dd0e5 100644
34b321
--- a/tests/ide-test.c
34b321
+++ b/tests/ide-test.c
34b321
@@ -425,6 +425,46 @@ static void test_identify(void)
34b321
     ide_test_quit();
34b321
 }
34b321
 
34b321
+static void test_flush(void)
34b321
+{
34b321
+    uint8_t data;
34b321
+
34b321
+    ide_test_start(
34b321
+        "-vnc none "
34b321
+        "-drive file=blkdebug::%s,if=ide,cache=writeback",
34b321
+        tmp_path);
34b321
+
34b321
+    /* Delay the completion of the flush request until we explicitly do it */
34b321
+    qmp("{'execute':'human-monitor-command', 'arguments': { "
34b321
+        "'command-line': 'qemu-io ide0-hd0 \"break flush_to_os A\"'} }");
34b321
+
34b321
+    /* FLUSH CACHE command on device 0*/
34b321
+    outb(IDE_BASE + reg_device, 0);
34b321
+    outb(IDE_BASE + reg_command, CMD_FLUSH_CACHE);
34b321
+
34b321
+    /* Check status while request is in flight*/
34b321
+    data = inb(IDE_BASE + reg_status);
34b321
+    assert_bit_set(data, BSY | DRDY);
34b321
+    assert_bit_clear(data, DF | ERR | DRQ);
34b321
+
34b321
+    /* Complete the command */
34b321
+    qmp("{'execute':'human-monitor-command', 'arguments': { "
34b321
+        "'command-line': 'qemu-io ide0-hd0 \"resume A\"'} }");
34b321
+
34b321
+    /* Check registers */
34b321
+    data = inb(IDE_BASE + reg_device);
34b321
+    g_assert_cmpint(data & DEV, ==, 0);
34b321
+
34b321
+    do {
34b321
+        data = inb(IDE_BASE + reg_status);
34b321
+    } while (data & BSY);
34b321
+
34b321
+    assert_bit_set(data, DRDY);
34b321
+    assert_bit_clear(data, BSY | DF | ERR | DRQ);
34b321
+
34b321
+    ide_test_quit();
34b321
+}
34b321
+
34b321
 static void test_flush_nodev(void)
34b321
 {
34b321
     ide_test_start("");
34b321
@@ -468,6 +508,7 @@ int main(int argc, char **argv)
34b321
     qtest_add_func("/ide/bmdma/long_prdt", test_bmdma_long_prdt);
34b321
     qtest_add_func("/ide/bmdma/teardown", test_bmdma_teardown);
34b321
 
34b321
+    qtest_add_func("/ide/flush", test_flush);
34b321
     qtest_add_func("/ide/flush_nodev", test_flush_nodev);
34b321
 
34b321
     ret = g_test_run();
34b321
-- 
34b321
1.8.3.1
34b321