diff --git a/qubes/storage/kernels.py b/qubes/storage/kernels.py new file mode 100644 index 00000000..d7441b29 --- /dev/null +++ b/qubes/storage/kernels.py @@ -0,0 +1,88 @@ +#!/usr/bin/python2 +# -*- encoding: utf8 -*- +# +# The Qubes OS Project, http://www.qubes-os.org +# +# Copyright (C) 2010-2015 Joanna Rutkowska +# Copyright (C) 2015 Wojtek Porczyk +# Copyright (C) 2016 Bahtiar `kalkin-` Gadimov +# +# 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. +# +import os + +from qubes.exc import QubesVMError +from qubes.storage import Pool, StoragePoolException, Volume + + +class LinuxModules(Volume): + rw = False + + def __init__(self, target_dir, kernel_version, **kwargs): + super(LinuxModules, self).__init__(**kwargs) + self.kernels_dir = os.path.join(target_dir, kernel_version) + self.path = os.path.join(self.kernels_dir, 'modules.img') + self.vid = self.path + + +class LinuxKernel(Pool): + 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 + + def init_volume(self, volume_config): + assert 'volume_type' in volume_config, "Volume type missing " \ + + str(volume_config) + volume_type = volume_config['volume_type'] + if volume_type != 'read-only': + raise StoragePoolException("Unknown volume type " + volume_type) + + return LinuxModules(self.dir_path, self.vm.kernel, **volume_config) + + def clone(self, source, target): + return target + + def create(self, volume, source_volume): + return volume + + def commit_template_changes(self, volume): + return volume + + @property + def config(self): + return { + 'name': self.name, + 'dir_path': self.dir_path, + 'driver': LinuxKernel.driver, + } + + def remove(self, volume): + pass + + def rename(self, volume, old_name, new_name): + return volume + + def start(self, volume): + path = volume.path + if not os.path.exists(path): + msg = 'VM %s is missing modules: %s' % (self.vm.name, path) + raise QubesVMError(self.vm, msg) + return volume + + def stop(self, volume): + pass diff --git a/rpm_spec/core-dom0.spec b/rpm_spec/core-dom0.spec index d1832259..7f0b7b48 100644 --- a/rpm_spec/core-dom0.spec +++ b/rpm_spec/core-dom0.spec @@ -233,6 +233,7 @@ fi %dir %{python_sitelib}/qubes/storage %{python_sitelib}/qubes/storage/__init__.py* %{python_sitelib}/qubes/storage/xen.py* +%{python_sitelib}/qubes/storage/kernels.py* %dir %{python_sitelib}/qubes/tools %{python_sitelib}/qubes/tools/__init__.py* diff --git a/setup.py b/setup.py index 533981f1..ad3a0f90 100644 --- a/setup.py +++ b/setup.py @@ -45,5 +45,6 @@ if __name__ == '__main__': ], 'qubes.storage': [ 'xen = qubes.storage.xen:XenPool', + 'linux-kernel = qubes.storage.kernels:LinuxKernel', ] })