Browse Source

storage/lvm: misc fixes

- add missing lvm remove call when commiting changes
- delay creating volatile image until domain startup (it will be created
  then anyway)
- reset cache only when really changed anything
- attach VM to the volume (snapshot) created for its runtime - to not
  expose changes (for example in root volume) to child VMs until
  shutdown

QubesOS/qubes-issues#2412
QubesOS/qubes-issues#2256
Marek Marczykowski-Górecki 7 years ago
parent
commit
400e92b25a
1 changed files with 15 additions and 3 deletions
  1. 15 3
      qubes/storage/lvm.py

+ 15 - 3
qubes/storage/lvm.py

@@ -69,6 +69,7 @@ class ThinPool(qubes.storage.Pool):
         cmd = ['clone', volume._vid_snap, volume.vid]
         qubes_lvm(cmd, self.log)
         cmd = ['remove', volume._vid_snap]
+        qubes_lvm(cmd, self.log)
 
     @property
     def config(self):
@@ -83,8 +84,9 @@ class ThinPool(qubes.storage.Pool):
         assert volume.vid
         assert volume.size
         if volume.source:
-            return self.clone(volume.source, volume)
-        else:
+            # will clone in start()
+            return volume
+        elif not volume._is_volatile:
             cmd = [
                 'create',
                 self._pool_id,
@@ -92,7 +94,7 @@ class ThinPool(qubes.storage.Pool):
                 str(volume.size)
             ]
             qubes_lvm(cmd, self.log)
-        reset_cache()
+            reset_cache()
         return volume
 
     def destroy(self):
@@ -398,6 +400,16 @@ class ThinVolume(qubes.storage.Volume):
         raise qubes.storage.StoragePoolException(
             "You shouldn't use lvm size setter")
 
+    def block_device(self):
+        ''' Return :py:class:`qubes.devices.BlockDevice` for serialization in
+            the libvirt XML template as <disk>.
+        '''
+        if not self._is_volatile:
+            return qubes.devices.BlockDevice(
+                '/dev/' + self._vid_snap, self.name, self.script,
+                self.rw, self.domain, self.devtype)
+        else:
+            return super(ThinVolume, self).block_device()
 
     @property
     def usage(self):  # lvm thin usage always returns at least the same usage as