From: Vojtech Trefny vtrefny@redhat.com
--- blivet/tasks/lukstasks.py | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-)
diff --git a/blivet/tasks/lukstasks.py b/blivet/tasks/lukstasks.py index 0fa59d7..f3556cb 100644 --- a/blivet/tasks/lukstasks.py +++ b/blivet/tasks/lukstasks.py @@ -28,13 +28,43 @@
from ..devicelibs import crypto from ..errors import LUKSError -from ..size import Size
from . import availability from . import task from . import dfresize
+class LUKSSize(task.BasicApplication): + """ Obtain information about the size of a LUKS format. """ + + ext = availability.BLOCKDEV_CRYPTO_PLUGIN + + description = "size of a luks device" + + def __init__(self, a_luks): + """ Initializer. + + :param :class:`~.formats.luks.LUKS` a_luks: a LUKS format object + """ + self.luks = a_luks + + def do_task(self): + """ Returns the size of the luks format. + + :returns: the size of the luks format + :rtype: :class:`~.size.Size` + :raises :class:`~.errors.LUKSError`: if size cannot be obtained + """ + + try: + dm_dev = blockdev.dm.node_from_name(self.luks.map_name) + blocks = int(util.get_sysfs_attr("/sys/block/%s" % dm_dev, "size") or "0") + except blockdev.CryptoError as e: + raise LUKSError(e) + + return blocks * crypto.SECTOR_SIZE + + class LUKSResize(task.BasicApplication, dfresize.DFResizeTask): """ Handle resize of LUKS device. """