qubes-storage.rst 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. :py:mod:`qubes.storage` -- Qubes data storage
  2. =============================================
  3. Qubes provide extensible API for domains data storage. Each domain have
  4. multiple storage volumes, for different purposes. Each volume is provided by
  5. some storage pool. Qubes support different storage pool drivers, and it's
  6. possible to register additional 3rd-party drivers.
  7. Domain's storage volumes:
  8. - `root` - this is where operating system is installed. The volume is
  9. available read-write to :py:class:`~qubes.vm.templatevm.TemplateVM` and
  10. :py:class:`~qubes.vm.standalonevm.StandaloneVM`, and read-only to others
  11. (:py:class:`~qubes.vm.appvm.AppVM` and :py:class:`~qubes.vm.dispvm.DispVM`).
  12. - `private` - this is where domain's data live. The volume is available
  13. read-write to all domain classes (including :py:class:`~qubes.vm.dispvm.DispVM`,
  14. but data written there is discarded on domain shutdown).
  15. - `volatile` - this is used for any data that do not to persist. This include
  16. swap, copy-on-write layer for `root` volume etc.
  17. - `kernel` - domain boot files - operating system kernel, initial ramdisk,
  18. kernel modules etc. This volume is provided read-only and should be provided by
  19. a storage pool respecting :py:attr:`qubes.vm.qubesvm.QubesVM.kernel` property.
  20. Storage pool concept
  21. --------------------
  22. Storage pool is responsible for managing its volumes. Qubes have defined
  23. storage pool driver API, allowing to put domains storage in various places. By
  24. default two drivers are provided: :py:class:`qubes.storage.file.FilePool`
  25. (named `file`) and :py:class:`qubes.storage.lvm.ThinPool` (named `lvm_thin`).
  26. But the API allow to implement variety of other drivers (like additionally
  27. encrypted storage, external disk, drivers using special features of some
  28. filesystems like btrfs, etc).
  29. Most of storage API focus on storage volumes. Each volume have at least those
  30. properties:
  31. - :py:attr:`~qubes.storage.Volume.rw` - should the volume be available
  32. read-only or read-write to the domain
  33. - :py:attr:`~qubes.storage.Volume.snap_on_start` - should the domain start
  34. with its own state of the volume, or rather a snapshot of its template volume
  35. (pointed by a :py:attr:`~qubes.storage.Volume.source` property). This can be
  36. set to `True` only if a domain do have `template` property (AppVM and DispVM).
  37. If the domain's template is running already, the snapshot should be made out of
  38. the template's before its startup.
  39. - :py:attr:`~qubes.storage.Volume.save_on_stop` - should the volume state be
  40. saved or discarded on domain
  41. stop. In either case, while the domain is running, volume's current state
  42. should not be committed immediately. This is to allow creating snapshots of the
  43. volume's state from before domain start (see
  44. :py:attr:`~qubes.storage.Volume.snap_on_start`).
  45. - :py:attr:`~qubes.storage.Volume.revisions_to_keep` - number of volume
  46. revisions to keep. If greater than zero, at each domain stop (and if
  47. :py:attr:`~qubes.storage.Volume.save_on_stop` is `True`) new revision is saved
  48. and old ones exceeding :py:attr:`~qubes.storage.Volume.revisions_to_keep` limit
  49. are removed.
  50. - :py:attr:`~qubes.storage.Volume.source` - source volume for
  51. :py:attr:`~qubes.storage.Volume.snap_on_start` volumes
  52. - :py:attr:`~qubes.storage.Volume.vid` - pool specific volume identifier, must
  53. be unique inside given pool
  54. - :py:attr:`~qubes.storage.Volume.pool` - storage pool object owning this volume
  55. - :py:attr:`~qubes.storage.Volume.name` - name of the volume inside owning
  56. domain (like `root`, or `private`)
  57. - :py:attr:`~qubes.storage.Volume.size` - size of the volume, in bytes
  58. Storage pool driver may define additional properties.
  59. Storage pool driver API
  60. -----------------------
  61. Storage pool driver need to implement two classes:
  62. - pool class - inheriting from :py:class:`qubes.storage.Pool`
  63. - volume class - inheriting from :py:class:`qubes.storage.Volume`
  64. Pool class should be registered with `qubes.storage` entry_point, under the
  65. name of storage pool driver. Volume class instances should be returned by
  66. :py:meth:`qubes.storage.Pool.init_volume` method of pool class instance.
  67. Methods required to be implemented by the pool class:
  68. - :py:meth:`~qubes.storage.Pool.init_volume` - return instance of appropriate
  69. volume class; this method should not alter any persistent disk state, it is
  70. used to instantiate both existing volumes and create new ones
  71. - :py:meth:`~qubes.storage.Pool.setup` - setup new storage pool
  72. - :py:meth:`~qubes.storage.Pool.destroy` - destroy storage pool
  73. Methods and properties required to be implemented by the volume class:
  74. - :py:meth:`~qubes.storage.Volume.create` - create volume on disk
  75. - :py:meth:`~qubes.storage.Volume.remove` - remove volume from disk
  76. - :py:meth:`~qubes.storage.Volume.start` - prepare the volume for domain start;
  77. this include making a snapshot if
  78. :py:attr:`~qubes.storage.Volume.snap_on_start` is `True`
  79. - :py:meth:`~qubes.storage.Volume.stop` - cleanup after domain shutdown; this
  80. include committing changes to the volume if
  81. :py:attr:`~qubes.storage.Volume.save_on_stop` is `True`
  82. - :py:meth:`~qubes.storage.Volume.export` - return a path to be read to extract
  83. volume data; for complex formats, this can be a pipe (connected to some
  84. data-extracting process)
  85. - :py:meth:`~qubes.storage.Volume.import_data` - return a path the data should
  86. be written to, to import volume data; for complex formats, this can be pipe
  87. (connected to some data-importing process)
  88. - :py:meth:`~qubes.storage.Volume.import_data_end` - finish data import
  89. operation (cleanup temporary files etc); this methods is called always after
  90. :py:meth:`~qubes.storage.Volume.import_data` regardless if operation was
  91. successful or not
  92. - :py:meth:`~qubes.storage.Volume.import_volume` - import data from another volume
  93. - :py:meth:`~qubes.storage.Volume.resize` - resize volume
  94. - :py:meth:`~qubes.storage.Volume.revert` - revert volume state to a given revision
  95. - :py:attr:`~qubes.storage.Volume.revisions` - collection of volume revisions (to use
  96. with :py:meth:`qubes.storage.Volume.revert`)
  97. - :py:meth:`~qubes.storage.Volume.is_dirty` - is volume properly committed
  98. after domain shutdown? Applies only to volumes with
  99. :py:attr:`~qubes.storage.Volume.save_on_stop` set to `True`
  100. - :py:meth:`~qubes.storage.Volume.is_outdated` - have the source volume started
  101. since domain startup? applies only to volumes with
  102. :py:attr:`~qubes.storage.Volume.snap_on_start` set to `True`
  103. - :py:attr:`~qubes.storage.Volume.config` - volume configuration, this should
  104. be enough to later reinstantiate the same volume object
  105. - :py:meth:`~qubes.storage.Volume.block_device` - return
  106. :py:class:`qubes.storage.BlockDevice` instance required to configure volume in
  107. libvirt
  108. Some storage pool drivers can provide limited functionality only - for example
  109. support only `volatile` volumes (those with
  110. :py:attr:`~qubes.storage.Volume.snap_on_start` is `False`,
  111. :py:attr:`~qubes.storage.Volume.save_on_stop` is `False`, and
  112. :py:attr:`~qubes.storage.Volume.rw` is `True`). In that case, it should raise
  113. :py:exc:`NotImplementedError` in :py:meth:`qubes.storage.Pool.init_volume` when
  114. trying to instantiate unsupported volume.
  115. Note that pool driver should be prepared to recover from power loss before
  116. stopping a domain - so, if volume have
  117. :py:attr:`~qubes.storage.Volume.save_on_stop` is `True`, and
  118. :py:meth:`qubes.storage.Volume.stop` wasn't called, next
  119. :py:meth:`~qubes.storage.Volume.start` should pick up previous (not committed)
  120. state.
  121. See specific methods documentation for details.
  122. Module contents
  123. ---------------
  124. .. automodule:: qubes.storage
  125. :members:
  126. :show-inheritance:
  127. .. vim: ts=3 sw=3 et