kernels.py 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #!/usr/bin/python2
  2. # -*- encoding: utf8 -*-
  3. #
  4. # The Qubes OS Project, http://www.qubes-os.org
  5. #
  6. # Copyright (C) 2010-2015 Joanna Rutkowska <joanna@invisiblethingslab.com>
  7. # Copyright (C) 2015 Wojtek Porczyk <woju@invisiblethingslab.com>
  8. # Copyright (C) 2016 Bahtiar `kalkin-` Gadimov <bahtiar@gadimov.de>
  9. #
  10. # This program is free software; you can redistribute it and/or modify
  11. # it under the terms of the GNU General Public License as published by
  12. # the Free Software Foundation; either version 2 of the License, or
  13. # (at your option) any later version.
  14. #
  15. # This program is distributed in the hope that it will be useful,
  16. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. # GNU General Public License for more details.
  19. #
  20. # You should have received a copy of the GNU General Public License along
  21. # with this program; if not, write to the Free Software Foundation, Inc.,
  22. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  23. #
  24. import os
  25. from qubes.exc import QubesVMError
  26. from qubes.storage import Pool, StoragePoolException, Volume
  27. class LinuxModules(Volume):
  28. rw = False
  29. def __init__(self, target_dir, kernel_version, **kwargs):
  30. super(LinuxModules, self).__init__(**kwargs)
  31. self.kernels_dir = os.path.join(target_dir, kernel_version)
  32. self.path = os.path.join(self.kernels_dir, 'modules.img')
  33. self.vid = self.path
  34. class LinuxKernel(Pool):
  35. driver = 'linux-kernel'
  36. def __init__(self, name=None, dir_path=None):
  37. assert dir_path, 'Missing dir_path'
  38. super(LinuxKernel, self).__init__(name=name)
  39. self.dir_path = dir_path
  40. def init_volume(self, volume_config):
  41. assert 'volume_type' in volume_config, "Volume type missing " \
  42. + str(volume_config)
  43. volume_type = volume_config['volume_type']
  44. if volume_type != 'read-only':
  45. raise StoragePoolException("Unknown volume type " + volume_type)
  46. return LinuxModules(self.dir_path, self.vm.kernel, **volume_config)
  47. def clone(self, source, target):
  48. return target
  49. def create(self, volume, source_volume):
  50. return volume
  51. def commit_template_changes(self, volume):
  52. return volume
  53. @property
  54. def config(self):
  55. return {
  56. 'name': self.name,
  57. 'dir_path': self.dir_path,
  58. 'driver': LinuxKernel.driver,
  59. }
  60. def remove(self, volume):
  61. pass
  62. def rename(self, volume, old_name, new_name):
  63. return volume
  64. def start(self, volume):
  65. path = volume.path
  66. if not os.path.exists(path):
  67. msg = 'VM %s is missing modules: %s' % (self.vm.name, path)
  68. raise QubesVMError(self.vm, msg)
  69. return volume
  70. def stop(self, volume):
  71. pass