storage: volume.import_volume now expect create()d volume
This is much more logical for *import*_volume function. QubesOS/qubes-issues#2256
This commit is contained in:
parent
28f78ed3b8
commit
fabd8119b4
@ -177,7 +177,11 @@ class Volume(object):
|
||||
|
||||
def import_volume(self, src_volume):
|
||||
''' Imports data from a different volume (possibly in a different
|
||||
pool '''
|
||||
pool.
|
||||
|
||||
The needs to be create()d first.
|
||||
|
||||
This can be implemented as a coroutine. '''
|
||||
# pylint: disable=unused-argument
|
||||
raise self._not_implemented("import_volume")
|
||||
|
||||
@ -448,16 +452,9 @@ class Storage(object):
|
||||
dst_pool = self.vm.app.get_pool(config['pool'])
|
||||
dst = dst_pool.init_volume(self.vm, config)
|
||||
src_volume = src_vm.volumes[name]
|
||||
src_pool = src_volume.pool
|
||||
if dst_pool == src_pool:
|
||||
msg = "Cloning volume {!s} from vm {!s}"
|
||||
self.vm.log.info(msg.format(src_volume.name, src_vm.name))
|
||||
clone_op_ret = dst_pool.clone(src_volume, dst)
|
||||
else:
|
||||
msg = "Importing volume {!s} from vm {!s}"
|
||||
self.vm.log.info(msg.format(src_volume.name, src_vm.name))
|
||||
clone_op_ret = dst_pool.import_volume(
|
||||
dst_pool, dst, src_pool, src_volume)
|
||||
msg = "Importing volume {!s} from vm {!s}"
|
||||
self.vm.log.info(msg.format(src_volume.name, src_vm.name))
|
||||
clone_op_ret = dst.import_volume(src_volume)
|
||||
|
||||
# clone/import functions may be either synchronous or asynchronous
|
||||
# in the later case, we need to wait for them to finish
|
||||
|
@ -261,6 +261,7 @@ class FileVolume(qubes.storage.Volume):
|
||||
msg = msg.format(src_volume, self)
|
||||
assert not src_volume.snap_on_start, msg
|
||||
if self.save_on_stop:
|
||||
_remove_if_exists(self.path)
|
||||
copy_file(src_volume.export(), self.path)
|
||||
return self
|
||||
|
||||
|
@ -310,10 +310,11 @@ class ThinVolume(qubes.storage.Volume):
|
||||
# pylint: disable=line-too-long
|
||||
if isinstance(src_volume.pool, ThinPool) and \
|
||||
src_volume.pool.thin_pool == self.pool.thin_pool: # NOQA
|
||||
cmd = ['remove', self.vid]
|
||||
qubes_lvm(cmd, self.log)
|
||||
cmd = ['clone', str(src_volume), str(self)]
|
||||
qubes_lvm(cmd, self.log)
|
||||
else:
|
||||
self.create()
|
||||
src_path = src_volume.export()
|
||||
cmd = ['sudo', 'dd', 'if=' + src_path, 'of=/dev/' + self.vid,
|
||||
'conv=sparse']
|
||||
|
Loading…
Reference in New Issue
Block a user