2016-04-01 15:10:44 +02:00
|
|
|
#
|
|
|
|
# The Qubes OS Project, http://www.qubes-os.org
|
|
|
|
#
|
|
|
|
# Copyright (C) 2010-2015 Joanna Rutkowska <joanna@invisiblethingslab.com>
|
|
|
|
# Copyright (C) 2015 Wojtek Porczyk <woju@invisiblethingslab.com>
|
|
|
|
# Copyright (C) 2016 Bahtiar `kalkin-` Gadimov <bahtiar@gadimov.de>
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License along
|
|
|
|
# with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
#
|
2017-01-18 22:16:46 +01:00
|
|
|
|
2016-04-27 22:39:11 +02:00
|
|
|
''' This module contains pool implementations for different OS kernels. '''
|
2017-01-18 22:16:46 +01:00
|
|
|
|
2016-04-01 15:10:44 +02:00
|
|
|
import os
|
|
|
|
|
|
|
|
from qubes.storage import Pool, StoragePoolException, Volume
|
|
|
|
|
|
|
|
|
|
|
|
class LinuxModules(Volume):
|
2016-04-27 22:39:11 +02:00
|
|
|
''' A volume representing a ro linux kernel '''
|
2016-04-01 15:10:44 +02:00
|
|
|
rw = False
|
|
|
|
|
|
|
|
def __init__(self, target_dir, kernel_version, **kwargs):
|
2017-05-17 01:37:59 +02:00
|
|
|
kwargs['vid'] = ''
|
2016-04-01 15:10:44 +02:00
|
|
|
super(LinuxModules, self).__init__(**kwargs)
|
2017-05-17 01:37:59 +02:00
|
|
|
self._kernel_version = kernel_version
|
|
|
|
self.target_dir = target_dir
|
|
|
|
|
|
|
|
@property
|
|
|
|
def vid(self):
|
|
|
|
if callable(self._kernel_version):
|
|
|
|
return self._kernel_version()
|
|
|
|
return self._kernel_version
|
|
|
|
|
|
|
|
@vid.setter
|
|
|
|
def vid(self, value):
|
|
|
|
# ignore
|
|
|
|
pass
|
|
|
|
|
|
|
|
@property
|
|
|
|
def kernels_dir(self):
|
|
|
|
kernel_version = self.vid
|
2017-06-02 15:43:43 +02:00
|
|
|
if not kernel_version:
|
2017-05-17 01:37:59 +02:00
|
|
|
return None
|
|
|
|
return os.path.join(self.target_dir, kernel_version)
|
|
|
|
|
|
|
|
@property
|
|
|
|
def path(self):
|
|
|
|
kernels_dir = self.kernels_dir
|
2017-06-02 15:43:43 +02:00
|
|
|
if not kernels_dir:
|
2017-05-17 01:37:59 +02:00
|
|
|
return None
|
|
|
|
return os.path.join(kernels_dir, 'modules.img')
|
|
|
|
|
|
|
|
@property
|
|
|
|
def vmlinuz(self):
|
|
|
|
kernels_dir = self.kernels_dir
|
2017-06-02 15:43:43 +02:00
|
|
|
if not kernels_dir:
|
2017-05-17 01:37:59 +02:00
|
|
|
return None
|
|
|
|
return os.path.join(kernels_dir, 'vmlinuz')
|
|
|
|
|
|
|
|
@property
|
|
|
|
def initramfs(self):
|
|
|
|
kernels_dir = self.kernels_dir
|
2017-06-02 15:43:43 +02:00
|
|
|
if not kernels_dir:
|
2017-05-17 01:37:59 +02:00
|
|
|
return None
|
|
|
|
return os.path.join(kernels_dir, 'initramfs')
|
2016-04-01 15:10:44 +02:00
|
|
|
|
2016-07-12 18:16:15 +02:00
|
|
|
@property
|
|
|
|
def revisions(self):
|
|
|
|
return {}
|
2016-04-01 15:10:44 +02:00
|
|
|
|
2017-06-09 04:46:46 +02:00
|
|
|
def is_dirty(self):
|
|
|
|
return False
|
|
|
|
|
|
|
|
def clone(self, source):
|
|
|
|
if isinstance(source, LinuxModules):
|
|
|
|
# do nothing
|
|
|
|
return self
|
|
|
|
raise StoragePoolException('clone of LinuxModules volume from '
|
|
|
|
'different volume type is not supported')
|
|
|
|
|
|
|
|
def create(self):
|
|
|
|
return self
|
|
|
|
|
|
|
|
def commit(self):
|
|
|
|
return self
|
|
|
|
|
|
|
|
def export(self):
|
|
|
|
return self.path
|
|
|
|
|
|
|
|
def is_outdated(self):
|
|
|
|
return False
|
|
|
|
|
|
|
|
def start(self):
|
|
|
|
path = self.path
|
|
|
|
if path and not os.path.exists(path):
|
|
|
|
raise StoragePoolException('Missing kernel modules: %s' % path)
|
|
|
|
|
|
|
|
return self
|
|
|
|
|
|
|
|
def stop(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def verify(self):
|
|
|
|
if self.vid:
|
|
|
|
_check_path(self.path)
|
|
|
|
_check_path(self.vmlinuz)
|
|
|
|
_check_path(self.initramfs)
|
|
|
|
|
2017-05-17 01:37:59 +02:00
|
|
|
def block_device(self):
|
2017-06-02 15:43:43 +02:00
|
|
|
if self.vid:
|
2017-05-17 01:37:59 +02:00
|
|
|
return super().block_device()
|
|
|
|
|
|
|
|
|
2016-04-01 15:10:44 +02:00
|
|
|
class LinuxKernel(Pool):
|
2016-04-27 22:39:11 +02:00
|
|
|
''' Provides linux kernels '''
|
2016-04-01 15:10:44 +02:00
|
|
|
driver = 'linux-kernel'
|
|
|
|
|
|
|
|
def __init__(self, name=None, dir_path=None):
|
|
|
|
assert dir_path, 'Missing dir_path'
|
|
|
|
super(LinuxKernel, self).__init__(name=name)
|
|
|
|
self.dir_path = dir_path
|
|
|
|
|
2016-04-01 17:30:11 +02:00
|
|
|
def init_volume(self, vm, volume_config):
|
2016-07-12 18:16:15 +02:00
|
|
|
assert not volume_config['rw']
|
2016-04-01 15:10:44 +02:00
|
|
|
|
2017-06-09 04:46:46 +02:00
|
|
|
volume_config['pool'] = self
|
2017-05-17 01:37:59 +02:00
|
|
|
volume = LinuxModules(self.dir_path, lambda: vm.kernel, **volume_config)
|
2016-04-01 17:30:11 +02:00
|
|
|
|
|
|
|
return volume
|
2016-04-01 15:10:44 +02:00
|
|
|
|
|
|
|
@property
|
|
|
|
def config(self):
|
|
|
|
return {
|
|
|
|
'name': self.name,
|
|
|
|
'dir_path': self.dir_path,
|
|
|
|
'driver': LinuxKernel.driver,
|
|
|
|
}
|
|
|
|
|
2016-04-15 20:33:04 +02:00
|
|
|
def destroy(self):
|
|
|
|
pass
|
|
|
|
|
2016-07-12 18:16:15 +02:00
|
|
|
def import_volume(self, dst_pool, dst_volume, src_pool, src_volume):
|
|
|
|
pass
|
|
|
|
|
2016-04-01 15:10:44 +02:00
|
|
|
def remove(self, volume):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def rename(self, volume, old_name, new_name):
|
|
|
|
return volume
|
|
|
|
|
2016-04-15 20:33:04 +02:00
|
|
|
def setup(self):
|
|
|
|
pass
|
|
|
|
|
2016-04-27 22:39:11 +02:00
|
|
|
@property
|
|
|
|
def volumes(self):
|
|
|
|
''' Return all known kernel volumes '''
|
|
|
|
return [LinuxModules(self.dir_path,
|
|
|
|
kernel_version,
|
2017-06-09 04:46:46 +02:00
|
|
|
pool=self,
|
2016-04-27 22:39:11 +02:00
|
|
|
name=kernel_version,
|
2016-04-27 17:16:34 +02:00
|
|
|
internal=True,
|
2016-07-12 18:16:15 +02:00
|
|
|
rw=False
|
|
|
|
)
|
2016-04-27 22:39:11 +02:00
|
|
|
for kernel_version in os.listdir(self.dir_path)]
|
|
|
|
|
2016-04-01 17:30:11 +02:00
|
|
|
|
|
|
|
def _check_path(path):
|
|
|
|
''' Raise an :py:class:`qubes.storage.StoragePoolException` if ``path`` does
|
|
|
|
not exist.
|
|
|
|
'''
|
|
|
|
if not os.path.exists(path):
|
|
|
|
raise StoragePoolException('Missing file: %s' % path)
|