Skip to content

Commit

Permalink
storage: volume.import_volume now expect create()d volume
Browse files Browse the repository at this point in the history
This is much more logical for *import*_volume function.

QubesOS/qubes-issues#2256
  • Loading branch information
marmarek committed Jun 26, 2017
1 parent 28f78ed commit fabd811
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
19 changes: 8 additions & 11 deletions qubes/storage/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,11 @@ def import_data_end(self, success):

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")

Expand Down Expand Up @@ -448,16 +452,9 @@ def clone_volume(self, src_vm, name):
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
Expand Down
1 change: 1 addition & 0 deletions qubes/storage/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ def import_volume(self, src_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

Expand Down
3 changes: 2 additions & 1 deletion qubes/storage/lvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,10 +310,11 @@ def import_volume(self, src_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']
Expand Down

0 comments on commit fabd811

Please sign in to comment.