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