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

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