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:
parent
9395e8fc33
commit
ae42308f5f
@ -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
|
||||||
|
@ -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`.
|
||||||
|
Loading…
Reference in New Issue
Block a user