thebeanogamer / rpms / qemu-kvm

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