[master 2/5] Improve format handling for lvm snapshots.
dwlehman
installerbot-noreply at redhat.com
Wed Jun 24 17:44:24 UTC 2015
From: David Lehman <dlehman at redhat.com>
Non-existent lvm snapshots have a copy of the origin's format as their
format. When an origin's format changes, all non-existent snapshots of
that origin must have their formats updated as well.
Related: rhbz#1113207
---
blivet/devices/lvm.py | 43 +++++++++++++++++++++++++++++++------------
1 file changed, 31 insertions(+), 12 deletions(-)
diff --git a/blivet/devices/lvm.py b/blivet/devices/lvm.py
index 3b94a22..87252e2 100644
--- a/blivet/devices/lvm.py
+++ b/blivet/devices/lvm.py
@@ -22,6 +22,7 @@
from decimal import Decimal
from six import add_metaclass
import abc
+import copy
import pprint
import re
import os
@@ -32,7 +33,6 @@
from .. import errors
from .. import util
-from ..formats import getFormat
from ..storage_log import log_method_call
from .. import udev
from ..size import Size, KiB, MiB, ROUND_UP, ROUND_DOWN
@@ -500,6 +500,7 @@ def __init__(self, name, parents=None, size=None, uuid=None,
if not isinstance(container, self._containerClass):
raise ValueError("constructor requires a %s instance" % self._containerClass.__name__)
+ self.snapshots = []
DMDevice.__init__(self, name, size=size, fmt=fmt,
sysfsPath=sysfsPath, parents=parents,
exists=exists)
@@ -509,7 +510,6 @@ def __init__(self, name, parents=None, size=None, uuid=None,
self.logSize = logSize or Size(0)
self.metaDataSize = Size(0)
self.segType = segType or "linear"
- self.snapshots = []
self.req_grow = None
self.req_max_size = Size(0)
@@ -580,6 +580,11 @@ def vgSpaceUsed(self):
return (self.vg.align(self.size, roundup=True) * self.copies
+ self.logSize + self.metaDataSize)
+ def _setFormat(self, fmt):
+ super(LVMLogicalVolumeDevice, self)._setFormat(fmt)
+ for snapshot in (s for s in self.snapshots if not s.exists):
+ snapshot._updateFormatFromOrigin()
+
@property
def vg(self):
""" This Logical Volume's Volume Group. """
@@ -811,8 +816,8 @@ class LVMSnapShotBase(object):
Normal/old snapshots must be removed with their origin, while thin
snapshots can remain after their origin is removed.
- It is also impossible to set the format for a snapshot explicitly as it
- always has the same format as its origin.
+ It is also impossible to set the format for a non-existent snapshot
+ explicitly as it always has the same format as its origin.
"""
_type = "lvmsnapshotbase"
@@ -855,15 +860,29 @@ def _voriginExistenceCheck(self, vorigin, exists):
if vorigin and not exists:
raise ValueError("only existing vorigin snapshots are supported")
- def _setFormat(self, fmt):
- pass
+ def _updateFormatFromOrigin(self):
+ """ Update the snapshot's format to reflect the origin's. """
+ fmt = copy.deepcopy(self.origin.format)
+ fmt.exists = False
+ if hasattr(fmt, "mountpoint"):
+ fmt.mountpoint = ""
+ fmt._chrootedMountpoint = None
+ # pylint: disable=no-member
+ fmt.device = self.path
+
+ super(LVMSnapShotBase, self)._setFormat(fmt)
- def _getFormat(self):
- if self.origin is None:
- fmt = getFormat(None)
+ def _setFormat(self, fmt):
+ # If a snapshot exists it can have a format that is distinct from its
+ # origin's. If it does not exist its format must be a copy of its
+ # origin's.
+ # pylint: disable=no-member
+ if self.exists:
+ super(LVMSnapShotBase, self)._setFormat(fmt)
else:
- fmt = self.origin.format
- return fmt
+ # pylint: disable=no-member
+ log.info("copying %s origin's format", self.name)
+ self._updateFormatFromOrigin()
@abc.abstractmethod
def _create(self):
@@ -1220,7 +1239,7 @@ def __init__(self, name, parents=None, sysfsPath='', origin=None,
LVMSnapShotBase.__init__(self, origin=origin, exists=exists)
LVMThinLogicalVolumeDevice.__init__(self, name, parents=parents,
- sysfsPath=sysfsPath,fmt=None,
+ sysfsPath=sysfsPath,fmt=fmt,
segType=segType,
uuid=uuid, size=size, exists=exists)
--
To view this commit on github, visit https://github.com/rhinstaller/blivet/commit/c50bbeb65c596797514fbce56769385f29c26d31
More information about the anaconda-patches
mailing list