storage/lvm: use dd for importing volumes

...instead of manual copy in python. DD is much faster and when used
with `conv=sparse` it will correctly preserve sparse image.

QubesOS/qubes-issues#2256
This commit is contained in:
Marek Marczykowski-Górecki 2016-11-03 03:47:28 +01:00
parent 8097da7cab
commit 9197bde76e
No known key found for this signature in database
GPG Key ID: 063938BA42CFA724

View File

@ -141,19 +141,9 @@ class ThinPool(qubes.storage.Pool):
else:
dst_volume = self.create(dst_volume)
cmd = ['sudo', 'qubes-lvm', 'import', dst_volume.vid]
blk_size = 4096
p = subprocess.Popen(cmd, stdin=subprocess.PIPE)
dst = p.stdin
with open(src_path, 'rb') as src:
while True:
tmp = src.read(blk_size)
if not tmp:
break
else:
dst.write(tmp)
p.stdin.close()
p.wait()
cmd = ['sudo', 'dd', 'if=' + src_path, 'of=/dev/' + dst_volume.vid,
'conv=sparse']
subprocess.check_call(cmd)
reset_cache()
return dst_volume