Blame SOURCES/kvm-iotests-Add-test-for-COR-across-nodes.patch

357786
From d1e2ed07917410e71f10b8dda80ef94a3d333d3c Mon Sep 17 00:00:00 2001
357786
From: Max Reitz <mreitz@redhat.com>
357786
Date: Mon, 18 Jun 2018 16:12:12 +0200
357786
Subject: [PATCH 36/54] iotests: Add test for COR across nodes
357786
357786
RH-Author: Max Reitz <mreitz@redhat.com>
357786
Message-id: <20180618161212.14444-11-mreitz@redhat.com>
357786
Patchwork-id: 80771
357786
O-Subject: [RHV-7.6 qemu-kvm-rhev PATCH 10/10] iotests: Add test for COR across nodes
357786
Bugzilla: 1518738
357786
RH-Acked-by: John Snow <jsnow@redhat.com>
357786
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
357786
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
357786
357786
COR across nodes (that is, you have some filter node between the
357786
actually COR target and the node that performs the COR) cannot reliably
357786
work together with the permission system when there is no explicit COR
357786
node that can request the WRITE_UNCHANGED permission for its child.
357786
This is because COR (currently) sneaks its requests by the usual
357786
permission checks, so it can work without a WRITE* permission; but if
357786
there is a filter node in between, that will re-issue the request, which
357786
then passes through the usual check -- and if nobody has requested a
357786
WRITE_UNCHANGED permission, that check will fail.
357786
357786
There is no real direct fix apart from hoping that there is someone who
357786
has requested that permission; in case of just the qemu-io HMP command
357786
(and no guest device), however, that is not the case.  The real real fix
357786
is to implement the copy-on-read flag through an implicitly added COR
357786
node.  Such a node can request the necessary permissions as shown in
357786
this test.
357786
357786
Signed-off-by: Max Reitz <mreitz@redhat.com>
357786
Message-id: 20180421132929.21610-10-mreitz@redhat.com
357786
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
357786
Signed-off-by: Max Reitz <mreitz@redhat.com>
357786
(cherry picked from commit 3e7a95feb9b5d66cff7fee38b3c423135ed245f6)
357786
Signed-off-by: Max Reitz <mreitz@redhat.com>
357786
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
357786
---
357786
 tests/qemu-iotests/216     | 115 +++++++++++++++++++++++++++++++++++++++++++++
357786
 tests/qemu-iotests/216.out |  28 +++++++++++
357786
 tests/qemu-iotests/group   |   1 +
357786
 3 files changed, 144 insertions(+)
357786
 create mode 100755 tests/qemu-iotests/216
357786
 create mode 100644 tests/qemu-iotests/216.out
357786
357786
diff --git a/tests/qemu-iotests/216 b/tests/qemu-iotests/216
357786
new file mode 100755
357786
index 0000000..ca9b47a
357786
--- /dev/null
357786
+++ b/tests/qemu-iotests/216
357786
@@ -0,0 +1,115 @@
357786
+#!/usr/bin/env python
357786
+#
357786
+# Copy-on-read tests using a COR filter node
357786
+#
357786
+# Copyright (C) 2018 Red Hat, Inc.
357786
+#
357786
+# This program is free software; you can redistribute it and/or modify
357786
+# it under the terms of the GNU General Public License as published by
357786
+# the Free Software Foundation; either version 2 of the License, or
357786
+# (at your option) any later version.
357786
+#
357786
+# This program is distributed in the hope that it will be useful,
357786
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
357786
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
357786
+# GNU General Public License for more details.
357786
+#
357786
+# You should have received a copy of the GNU General Public License
357786
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
357786
+#
357786
+# Creator/Owner: Max Reitz <mreitz@redhat.com>
357786
+
357786
+import iotests
357786
+from iotests import log, qemu_img_pipe, qemu_io, filter_qemu_io
357786
+
357786
+# Need backing file support
357786
+iotests.verify_image_format(supported_fmts=['qcow2', 'qcow', 'qed', 'vmdk'])
357786
+iotests.verify_platform(['linux'])
357786
+
357786
+log('')
357786
+log('=== Copy-on-read across nodes ===')
357786
+log('')
357786
+
357786
+# The old copy-on-read mechanism without a filter node cannot request
357786
+# WRITE_UNCHANGED permissions for its child.  Therefore it just tries
357786
+# to sneak its write by the usual permission system and holds its
357786
+# fingers crossed.  However, that sneaking does not work so well when
357786
+# there is a filter node in the way: That will receive the write
357786
+# request and re-issue a new one to its child, which this time is a
357786
+# proper write request that will make the permission system cough --
357786
+# unless there is someone at the top (like a guest device) that has
357786
+# requested write permissions.
357786
+#
357786
+# A COR filter node, however, can request the proper permissions for
357786
+# its child and therefore is not hit by this issue.
357786
+
357786
+with iotests.FilePath('base.img') as base_img_path, \
357786
+     iotests.FilePath('top.img') as top_img_path, \
357786
+     iotests.VM() as vm:
357786
+
357786
+    log('--- Setting up images ---')
357786
+    log('')
357786
+
357786
+    qemu_img_pipe('create', '-f', iotests.imgfmt, base_img_path, '64M')
357786
+
357786
+    log(filter_qemu_io(qemu_io(base_img_path, '-c', 'write -P 1 0M 1M')))
357786
+
357786
+    qemu_img_pipe('create', '-f', iotests.imgfmt, '-b', base_img_path,
357786
+                  top_img_path)
357786
+
357786
+    log(filter_qemu_io(qemu_io(top_img_path,  '-c', 'write -P 2 1M 1M')))
357786
+
357786
+    log('')
357786
+    log('--- Doing COR ---')
357786
+    log('')
357786
+
357786
+    # Compare with e.g. the following:
357786
+    #   vm.add_drive_raw('if=none,node-name=node0,copy-on-read=on,driver=raw,' \
357786
+    #                    'file.driver=%s,file.file.filename=%s' %
357786
+    #                       (iotests.imgfmt, top_img_path))
357786
+    # (Remove the blockdev-add instead.)
357786
+    # ((Not tested here because it hits an assertion in the permission
357786
+    #   system.))
357786
+
357786
+    vm.launch()
357786
+
357786
+    log(vm.qmp('blockdev-add',
357786
+                    node_name='node0',
357786
+                    driver='copy-on-read',
357786
+                    file={
357786
+                        'driver': 'raw',
357786
+                        'file': {
357786
+                            'driver': 'copy-on-read',
357786
+                            'file': {
357786
+                                'driver': 'raw',
357786
+                                'file': {
357786
+                                    'driver': iotests.imgfmt,
357786
+                                    'file': {
357786
+                                        'driver': 'file',
357786
+                                        'filename': top_img_path
357786
+                                    },
357786
+                                    'backing': {
357786
+                                        'driver': iotests.imgfmt,
357786
+                                        'file': {
357786
+                                            'driver': 'file',
357786
+                                            'filename': base_img_path
357786
+                                        }
357786
+                                    }
357786
+                                }
357786
+                            }
357786
+                        }
357786
+                    }))
357786
+
357786
+    # Trigger COR
357786
+    log(vm.qmp('human-monitor-command',
357786
+               command_line='qemu-io node0 "read 0 64M"'))
357786
+
357786
+    vm.shutdown()
357786
+
357786
+    log('')
357786
+    log('--- Checking COR result ---')
357786
+    log('')
357786
+
357786
+    log(filter_qemu_io(qemu_io(base_img_path, '-c', 'discard 0 64M')))
357786
+    log(filter_qemu_io(qemu_io(top_img_path,  '-c', 'read -P 1 0M 1M')))
357786
+    log(filter_qemu_io(qemu_io(top_img_path,  '-c', 'read -P 2 1M 1M')))
357786
diff --git a/tests/qemu-iotests/216.out b/tests/qemu-iotests/216.out
357786
new file mode 100644
357786
index 0000000..d3fc590
357786
--- /dev/null
357786
+++ b/tests/qemu-iotests/216.out
357786
@@ -0,0 +1,28 @@
357786
+
357786
+=== Copy-on-read across nodes ===
357786
+
357786
+--- Setting up images ---
357786
+
357786
+wrote 1048576/1048576 bytes at offset 0
357786
+1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
357786
+
357786
+wrote 1048576/1048576 bytes at offset 1048576
357786
+1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
357786
+
357786
+
357786
+--- Doing COR ---
357786
+
357786
+{u'return': {}}
357786
+{u'return': u''}
357786
+
357786
+--- Checking COR result ---
357786
+
357786
+discard 67108864/67108864 bytes at offset 0
357786
+64 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
357786
+
357786
+read 1048576/1048576 bytes at offset 0
357786
+1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
357786
+
357786
+read 1048576/1048576 bytes at offset 1048576
357786
+1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
357786
+
357786
diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group
357786
index cd5d26c..d228008 100644
357786
--- a/tests/qemu-iotests/group
357786
+++ b/tests/qemu-iotests/group
357786
@@ -214,4 +214,5 @@
357786
 213 rw auto quick
357786
 214 rw auto
357786
 215 rw auto quick
357786
+216 rw auto quick
357786
 218 rw auto quick
357786
-- 
357786
1.8.3.1
357786