mirror of
https://github.com/mii443/qemu.git
synced 2025-08-22 23:25:48 +00:00
simplebench/bench-backup: add --compressed option
Allow bench compressed backup. Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
This commit is contained in:
@ -21,6 +21,7 @@
|
||||
|
||||
import sys
|
||||
import os
|
||||
import subprocess
|
||||
import socket
|
||||
import json
|
||||
|
||||
@ -77,11 +78,29 @@ def bench_block_job(cmd, cmd_args, qemu_args):
|
||||
return {'seconds': (end_ms - start_ms) / 1000000.0}
|
||||
|
||||
|
||||
def get_image_size(path):
|
||||
out = subprocess.run(['qemu-img', 'info', '--out=json', path],
|
||||
stdout=subprocess.PIPE, check=True).stdout
|
||||
return json.loads(out)['virtual-size']
|
||||
|
||||
|
||||
# Bench backup or mirror
|
||||
def bench_block_copy(qemu_binary, cmd, cmd_options, source, target):
|
||||
"""Helper to run bench_block_job() for mirror or backup"""
|
||||
assert cmd in ('blockdev-backup', 'blockdev-mirror')
|
||||
|
||||
if target['driver'] == 'qcow2':
|
||||
try:
|
||||
os.remove(target['file']['filename'])
|
||||
except OSError:
|
||||
pass
|
||||
|
||||
subprocess.run(['qemu-img', 'create', '-f', 'qcow2',
|
||||
target['file']['filename'],
|
||||
str(get_image_size(source['filename']))],
|
||||
stdout=subprocess.DEVNULL,
|
||||
stderr=subprocess.DEVNULL, check=True)
|
||||
|
||||
source['node-name'] = 'source'
|
||||
target['node-name'] = 'target'
|
||||
|
||||
@ -106,6 +125,10 @@ def drv_nbd(host, port):
|
||||
'server': {'type': 'inet', 'host': host, 'port': port}}
|
||||
|
||||
|
||||
def drv_qcow2(file):
|
||||
return {'driver': 'qcow2', 'file': file}
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
import sys
|
||||
|
||||
|
Reference in New Issue
Block a user