storage: improve handling volume export

1. Add a helper function on vm.storage. This is equivalent of:

    vm.storage.get_pool(vm.volumes[name]).export(vm.volumes[name])

2. Make sure the path returned by `export` on LVM volume is accessible.
This commit is contained in:
Marek Marczykowski-Górecki 2016-09-26 00:53:10 +02:00
parent 9395e8fc33
commit ae42308f5f
No known key found for this signature in database
GPG Key ID: 063938BA42CFA724
2 changed files with 15 additions and 1 deletions

View File

@ -463,6 +463,15 @@ class Storage(object):
for target in parsed_xml.xpath( for target in parsed_xml.xpath(
"//domain/devices/disk/target")]) "//domain/devices/disk/target")])
def export(self, volume):
''' Helper function to export volume (pool.export(volume))'''
assert isinstance(volume, (Volume, basestring)), \
"You need to pass a Volume or pool name as str"
if isinstance(volume, Volume):
return self.pools[volume.name].export(volume)
else:
return self.pools[volume].export(self.vm.volumes[volume])
class Pool(object): class Pool(object):
''' A Pool is used to manage different kind of volumes (File ''' A Pool is used to manage different kind of volumes (File

View File

@ -100,7 +100,12 @@ class ThinPool(qubes.storage.Pool):
def export(self, volume): def export(self, volume):
''' Returns an object that can be `open()`. ''' ''' Returns an object that can be `open()`. '''
return '/dev/' + volume.vid devpath = '/dev/' + volume.vid
if not os.access(devpath, os.R_OK):
# FIXME: convert to udev rules, and drop after introducing qubesd
subprocess.check_call(['sudo', 'chgrp', 'qubes', devpath])
subprocess.check_call(['sudo', 'chmod', 'g+rw', devpath])
return devpath
def init_volume(self, vm, volume_config): def init_volume(self, vm, volume_config):
''' Initialize a :py:class:`qubes.storage.Volume` from `volume_config`. ''' Initialize a :py:class:`qubes.storage.Volume` from `volume_config`.