kernels.py 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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.storage import Pool, StoragePoolException, Volume
  26. class LinuxModules(Volume):
  27. rw = False
  28. def __init__(self, target_dir, kernel_version, **kwargs):
  29. super(LinuxModules, self).__init__(**kwargs)
  30. self.kernels_dir = os.path.join(target_dir, kernel_version)
  31. self.path = os.path.join(self.kernels_dir, 'modules.img')
  32. self.vid = self.path
  33. self.vmlinuz = os.path.join(self.kernels_dir, 'vmlinuz')
  34. self.initramfs = os.path.join(self.kernels_dir, 'initramfs')
  35. class LinuxKernel(Pool):
  36. driver = 'linux-kernel'
  37. def __init__(self, name=None, dir_path=None):
  38. assert dir_path, 'Missing dir_path'
  39. super(LinuxKernel, self).__init__(name=name)
  40. self.dir_path = dir_path
  41. def init_volume(self, vm, volume_config):
  42. assert 'volume_type' in volume_config, "Volume type missing " \
  43. + str(volume_config)
  44. volume_type = volume_config['volume_type']
  45. if volume_type != 'read-only':
  46. raise StoragePoolException("Unknown volume type " + volume_type)
  47. volume = LinuxModules(self.dir_path, vm.kernel, **volume_config)
  48. _check_path(volume.path)
  49. _check_path(volume.vmlinuz)
  50. _check_path(volume.initramfs)
  51. return volume
  52. def clone(self, source, target):
  53. return target
  54. def create(self, volume, source_volume):
  55. return volume
  56. def commit_template_changes(self, volume):
  57. return volume
  58. @property
  59. def config(self):
  60. return {
  61. 'name': self.name,
  62. 'dir_path': self.dir_path,
  63. 'driver': LinuxKernel.driver,
  64. }
  65. def destroy(self):
  66. pass
  67. def remove(self, volume):
  68. pass
  69. def rename(self, volume, old_name, new_name):
  70. return volume
  71. def setup(self):
  72. pass
  73. def start(self, volume):
  74. path = volume.path
  75. if not os.path.exists(path):
  76. raise StoragePoolException('Missing kernel modules: %s' % path)
  77. return volume
  78. def stop(self, volume):
  79. pass
  80. def _check_path(path):
  81. ''' Raise an :py:class:`qubes.storage.StoragePoolException` if ``path`` does
  82. not exist.
  83. '''
  84. if not os.path.exists(path):
  85. raise StoragePoolException('Missing file: %s' % path)