]>
git.proxmox.com Git - mirror_qemu.git/blob - tests/qemu-iotests/tests/image-fleecing
4 # This test covers the basic fleecing workflow, which provides a
5 # point-in-time snapshot of a node that can be queried over NBD.
7 # Copyright (C) 2018 Red Hat, Inc.
10 # This program is free software; you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; either version 2 of the License, or
13 # (at your option) any later version.
15 # This program is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
20 # You should have received a copy of the GNU General Public License
21 # along with this program. If not, see <http://www.gnu.org/licenses/>.
23 # Creator/Owner: John Snow <jsnow@redhat.com>
26 from iotests
import log
, qemu_img
, qemu_io
, qemu_io_silent
28 iotests
.script_initialize(
29 supported_fmts
=['qcow2', 'qcow', 'qed', 'vmdk', 'vhdx', 'raw'],
30 supported_platforms
=['linux'],
33 patterns
= [('0x5d', '0', '64k'),
34 ('0xd5', '1M', '64k'),
35 ('0xdc', '32M', '64k'),
36 ('0xcd', '0x3ff0000', '64k')] # 64M - 64K
38 overwrite
= [('0xab', '0', '64k'), # Full overwrite
39 ('0xad', '0x00f8000', '64k'), # Partial-left (1M-32K)
40 ('0x1d', '0x2008000', '64k'), # Partial-right (32M+32K)
41 ('0xea', '0x3fe0000', '64k')] # Adjacent-left (64M - 128K)
43 zeroes
= [('0', '0x00f8000', '32k'), # Left-end of partial-left (1M-32K)
44 ('0', '0x2010000', '32k'), # Right-end of partial-right (32M+64K)
45 ('0', '0x3fe0000', '64k')] # overwrite[3]
47 remainder
= [('0xd5', '0x108000', '32k'), # Right-end of partial-left [1]
48 ('0xdc', '32M', '32k'), # Left-end of partial-right [2]
49 ('0xcd', '0x3ff0000', '64k')] # patterns[3]
51 def do_test(use_cbw
, base_img_path
, fleece_img_path
, nbd_sock_path
, vm
):
52 log('--- Setting up images ---')
55 assert qemu_img('create', '-f', iotests
.imgfmt
, base_img_path
, '64M') == 0
56 assert qemu_img('create', '-f', 'qcow2', fleece_img_path
, '64M') == 0
59 qemu_io('-f', iotests
.imgfmt
,
60 '-c', 'write -P%s %s %s' % p
, base_img_path
)
65 log('--- Launching VM ---')
70 qom_path
= '/machine/peripheral/sda'
71 vm
.add_blockdev(f
'driver={iotests.imgfmt},file.driver=file,'
72 f
'file.filename={base_img_path},node-name={src_node}')
73 vm
.add_device('virtio-scsi')
74 vm
.add_device(f
'scsi-hd,id=sda,drive={src_node}')
79 log('--- Setting up Fleecing Graph ---')
83 # create tmp_node backed by src_node
84 log(vm
.qmp('blockdev-add', {
86 'node-name': tmp_node
,
89 'filename': fleece_img_path
,
94 # Establish CBW from source to fleecing node
96 log(vm
.qmp('blockdev-add', {
97 'driver': 'copy-before-write',
98 'node-name': 'fl-cbw',
103 log(vm
.qmp('qom-set', path
=qom_path
, property='drive', value
='fl-cbw'))
105 log(vm
.qmp('blockdev-backup',
112 log('--- Setting up NBD Export ---')
115 nbd_uri
= 'nbd+unix:///%s?socket=%s' % (tmp_node
, nbd_sock_path
)
116 log(vm
.qmp('nbd-server-start',
117 {'addr': { 'type': 'unix',
118 'data': { 'path': nbd_sock_path
} } }))
120 log(vm
.qmp('nbd-server-add', device
=tmp_node
))
123 log('--- Sanity Check ---')
126 for p
in patterns
+ zeroes
:
127 cmd
= 'read -P%s %s %s' % p
129 assert qemu_io_silent('-r', '-f', 'raw', '-c', cmd
, nbd_uri
) == 0
132 log('--- Testing COW ---')
136 cmd
= 'write -P%s %s %s' % p
138 log(vm
.hmp_qemu_io(qom_path
, cmd
, qdev
=True))
141 log('--- Verifying Data ---')
144 for p
in patterns
+ zeroes
:
145 cmd
= 'read -P%s %s %s' % p
147 assert qemu_io_silent('-r', '-f', 'raw', '-c', cmd
, nbd_uri
) == 0
150 log('--- Cleanup ---')
154 log(vm
.qmp('qom-set', path
=qom_path
, property='drive', value
=src_node
))
155 log(vm
.qmp('blockdev-del', node_name
='fl-cbw'))
157 log(vm
.qmp('block-job-cancel', device
='fleecing'))
158 e
= vm
.event_wait('BLOCK_JOB_CANCELLED')
160 log(e
, filters
=[iotests
.filter_qmp_event
])
162 log(vm
.qmp('nbd-server-stop'))
163 log(vm
.qmp('blockdev-del', node_name
=tmp_node
))
167 log('--- Confirming writes ---')
170 for p
in overwrite
+ remainder
:
171 cmd
= 'read -P%s %s %s' % p
173 assert qemu_io_silent(base_img_path
, '-c', cmd
) == 0
180 with iotests
.FilePath('base.img') as base_img_path
, \
181 iotests
.FilePath('fleece.img') as fleece_img_path
, \
182 iotests
.FilePath('nbd.sock',
183 base_dir
=iotests
.sock_dir
) as nbd_sock_path
, \
185 do_test(use_cbw
, base_img_path
, fleece_img_path
, nbd_sock_path
, vm
)
188 log('=== Test backup(sync=none) based fleecing ===\n')
191 log('=== Test filter based fleecing ===\n')