From: mulhern amulhern@redhat.com
Signed-off-by: mulhern amulhern@redhat.com --- blivet/devicelibs/crypto.py | 1 + blivet/tasks/lukstasks.py | 56 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 blivet/tasks/lukstasks.py
diff --git a/blivet/devicelibs/crypto.py b/blivet/devicelibs/crypto.py index 7d3bc15..fbef943 100644 --- a/blivet/devicelibs/crypto.py +++ b/blivet/devicelibs/crypto.py @@ -25,5 +25,6 @@
LUKS_METADATA_SIZE = Size("2 MiB") MIN_CREATE_ENTROPY = 256 # bits +SECTOR_SIZE = Size("512 B")
EXTERNAL_DEPENDENCIES = [availability.BLOCKDEV_CRYPTO_PLUGIN] diff --git a/blivet/tasks/lukstasks.py b/blivet/tasks/lukstasks.py new file mode 100644 index 0000000..27920c1 --- /dev/null +++ b/blivet/tasks/lukstasks.py @@ -0,0 +1,56 @@ +# lukstasks.py +# Tasks for a LUKS format. +# +# Copyright (C) 2015 Red Hat, Inc. +# +# This copyrighted material is made available to anyone wishing to use, +# modify, copy, or redistribute it subject to the terms and conditions of +# the GNU General Public License v.2, or (at your option) any later version. +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY expressed or implied, including the implied warranties of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General +# Public License for more details. You should have received a copy of the +# GNU General Public License along with this program; if not, write to the +# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +# 02110-1301, USA. Any Red Hat trademarks that are incorporated in the +# source code or documentation are not subject to the GNU General Public +# License and may only be used or replicated with the express permission of +# Red Hat, Inc. +# +# Red Hat Author(s): Anne Mulhern amulhern@redhat.com + +from gi.repository import BlockDev as blockdev + +from .. import util + +from ..devicelibs import crypto +from ..errors import LUKSError +from ..size import Size + +from . import availability +from . import task +from . import dfresize + +class LUKSResize(task.BasicApplication, dfresize.DFResizeTask): + """ Handle resize of LUKS device. """ + + description = "resize luks device" + + ext = availability.BLOCKDEV_CRYPTO_PLUGIN + + # units for specifying new size + unit = crypto.SECTOR_SIZE + + def __init__(self, a_luks): + """ Initializer. + + :param :class:`~.formats.luks.LUKS` a_luks: a LUKS format object + """ + self.luks = a_luks + + def doTask(self): + """ Resizes the LUKS format. """ + try: + blockdev.crypto.luks_resize(self.luks.mapName, self.luks.targetSize.convertTo(self.unit)) + except blockdev.CryptoError as e: + raise LUKSError(e)