Add support for relabeling of the swap format (#1818508)
This commit is contained in:
parent
d9a621d013
commit
d3096aaa6a
118
0002-Add-support-for-relabeling-of-the-swap-format.patch
Normal file
118
0002-Add-support-for-relabeling-of-the-swap-format.patch
Normal file
@ -0,0 +1,118 @@
|
|||||||
|
From a45b33839a88572a9776deec61234917fb66fb4f Mon Sep 17 00:00:00 2001
|
||||||
|
From: Vojtech Trefny <vtrefny@redhat.com>
|
||||||
|
Date: Tue, 31 Dec 2019 15:37:32 +0100
|
||||||
|
Subject: [PATCH 1/2] Define the 'relabels' method for all formats
|
||||||
|
|
||||||
|
---
|
||||||
|
blivet/formats/__init__.py | 4 ++++
|
||||||
|
1 file changed, 4 insertions(+)
|
||||||
|
|
||||||
|
diff --git a/blivet/formats/__init__.py b/blivet/formats/__init__.py
|
||||||
|
index 84657e01..0dbbae93 100644
|
||||||
|
--- a/blivet/formats/__init__.py
|
||||||
|
+++ b/blivet/formats/__init__.py
|
||||||
|
@@ -250,6 +250,10 @@ def labeling(self):
|
||||||
|
"""Returns False by default since most formats are non-labeling."""
|
||||||
|
return False
|
||||||
|
|
||||||
|
+ def relabels(self):
|
||||||
|
+ """Returns False by default since most formats are non-labeling."""
|
||||||
|
+ return False
|
||||||
|
+
|
||||||
|
def label_format_ok(self, label):
|
||||||
|
"""Checks whether the format of the label is OK for whatever
|
||||||
|
application is used by blivet to write a label for this format.
|
||||||
|
|
||||||
|
From 2e5e1b5f07be00a0b594742007bcadc2abdf2912 Mon Sep 17 00:00:00 2001
|
||||||
|
From: Vojtech Trefny <vtrefny@redhat.com>
|
||||||
|
Date: Tue, 31 Dec 2019 16:32:07 +0100
|
||||||
|
Subject: [PATCH 2/2] Add support for relabeling of the swap format
|
||||||
|
|
||||||
|
---
|
||||||
|
blivet/formats/swap.py | 39 ++++++++++++++++++++++++++++-
|
||||||
|
tests/formats_test/labeling_test.py | 6 +++++
|
||||||
|
2 files changed, 44 insertions(+), 1 deletion(-)
|
||||||
|
|
||||||
|
diff --git a/blivet/formats/swap.py b/blivet/formats/swap.py
|
||||||
|
index 36b50cb6..4b8a7edf 100644
|
||||||
|
--- a/blivet/formats/swap.py
|
||||||
|
+++ b/blivet/formats/swap.py
|
||||||
|
@@ -20,8 +20,10 @@
|
||||||
|
# Red Hat Author(s): Dave Lehman <dlehman@redhat.com>
|
||||||
|
#
|
||||||
|
|
||||||
|
+import os
|
||||||
|
+
|
||||||
|
from parted import PARTITION_SWAP, fileSystemType
|
||||||
|
-from ..errors import FSWriteUUIDError
|
||||||
|
+from ..errors import FSWriteUUIDError, SwapSpaceError
|
||||||
|
from ..storage_log import log_method_call
|
||||||
|
from ..tasks import availability
|
||||||
|
from ..tasks import fsuuid
|
||||||
|
@@ -53,6 +55,8 @@ class SwapSpace(DeviceFormat):
|
||||||
|
# see rhbz#744129 for details
|
||||||
|
_max_size = Size("128 GiB")
|
||||||
|
|
||||||
|
+ config_actions_map = {"label": "write_label"}
|
||||||
|
+
|
||||||
|
def __init__(self, **kwargs):
|
||||||
|
"""
|
||||||
|
:keyword device: path to the block device node
|
||||||
|
@@ -105,10 +109,43 @@ def labeling(self):
|
||||||
|
"""Returns True as mkswap can write a label to the swap space."""
|
||||||
|
return True
|
||||||
|
|
||||||
|
+ def relabels(self):
|
||||||
|
+ """Returns True as mkswap can write a label to the swap space."""
|
||||||
|
+ return True and self._plugin.available
|
||||||
|
+
|
||||||
|
def label_format_ok(self, label):
|
||||||
|
"""Returns True since no known restrictions on the label."""
|
||||||
|
return True
|
||||||
|
|
||||||
|
+ def write_label(self, dry_run=False):
|
||||||
|
+ """ Create a label for this format.
|
||||||
|
+
|
||||||
|
+ :raises: SwapSpaceError
|
||||||
|
+
|
||||||
|
+ If self.label is None, this means accept the default, so raise
|
||||||
|
+ an SwapSpaceError in this case.
|
||||||
|
+
|
||||||
|
+ Raises a SwapSpaceError if the label can not be set.
|
||||||
|
+ """
|
||||||
|
+
|
||||||
|
+ if not self._plugin.available:
|
||||||
|
+ raise SwapSpaceError("application to set label on swap format is not available")
|
||||||
|
+
|
||||||
|
+ if not dry_run:
|
||||||
|
+ if not self.exists:
|
||||||
|
+ raise SwapSpaceError("swap has not been created")
|
||||||
|
+
|
||||||
|
+ if not os.path.exists(self.device):
|
||||||
|
+ raise SwapSpaceError("device does not exist")
|
||||||
|
+
|
||||||
|
+ if self.label is None:
|
||||||
|
+ raise SwapSpaceError("makes no sense to write a label when accepting default label")
|
||||||
|
+
|
||||||
|
+ if not self.label_format_ok(self.label):
|
||||||
|
+ raise SwapSpaceError("bad label format")
|
||||||
|
+
|
||||||
|
+ blockdev.swap.mkswap(self.device, self.label)
|
||||||
|
+
|
||||||
|
label = property(lambda s: s._get_label(), lambda s, l: s._set_label(l),
|
||||||
|
doc="the label for this swap space")
|
||||||
|
|
||||||
|
diff --git a/tests/formats_test/labeling_test.py b/tests/formats_test/labeling_test.py
|
||||||
|
index e2569201..e26cb7df 100644
|
||||||
|
--- a/tests/formats_test/labeling_test.py
|
||||||
|
+++ b/tests/formats_test/labeling_test.py
|
||||||
|
@@ -113,3 +113,9 @@ def test_creating_swap_space_none(self):
|
||||||
|
def test_creating_swap_space_empty(self):
|
||||||
|
swp = swap.SwapSpace(device=self.loop_devices[0], label="")
|
||||||
|
self.assertIsNone(swp.create())
|
||||||
|
+
|
||||||
|
+ def test_relabel(self):
|
||||||
|
+ swp = swap.SwapSpace(device=self.loop_devices[0])
|
||||||
|
+ self.assertIsNone(swp.create())
|
||||||
|
+ swp.label = "label"
|
||||||
|
+ swp.write_label()
|
@ -23,7 +23,7 @@ Version: 3.1.7
|
|||||||
|
|
||||||
#%%global prerelease .b2
|
#%%global prerelease .b2
|
||||||
# prerelease, if defined, should be something like .a1, .b1, .b2.dev1, or .c2
|
# prerelease, if defined, should be something like .a1, .b1, .b2.dev1, or .c2
|
||||||
Release: 1%{?prerelease}%{?dist}
|
Release: 2%{?prerelease}%{?dist}
|
||||||
Epoch: 1
|
Epoch: 1
|
||||||
License: LGPLv2+
|
License: LGPLv2+
|
||||||
%global realname blivet
|
%global realname blivet
|
||||||
@ -31,6 +31,7 @@ License: LGPLv2+
|
|||||||
Source0: http://github.com/storaged-project/blivet/archive/%{realname}-%{realversion}.tar.gz
|
Source0: http://github.com/storaged-project/blivet/archive/%{realname}-%{realversion}.tar.gz
|
||||||
Source1: http://github.com/storaged-project/blivet/archive/%{realname}-%{realversion}-tests.tar.gz
|
Source1: http://github.com/storaged-project/blivet/archive/%{realname}-%{realversion}-tests.tar.gz
|
||||||
Patch0: 0001-initial-PowerNV-class-support.patch
|
Patch0: 0001-initial-PowerNV-class-support.patch
|
||||||
|
Patch1: 0002-Add-support-for-relabeling-of-the-swap-format.patch
|
||||||
|
|
||||||
# Versions of required components (done so we make sure the buildrequires
|
# Versions of required components (done so we make sure the buildrequires
|
||||||
# match the requires versions of things).
|
# match the requires versions of things).
|
||||||
@ -192,6 +193,9 @@ configuration.
|
|||||||
%endif
|
%endif
|
||||||
|
|
||||||
%changelog
|
%changelog
|
||||||
|
* Mon Mar 30 2020 Vojtech Trefny <vtrefny@redhat.com> - 3.1.7-2
|
||||||
|
- Add support for relabeling of the swap format
|
||||||
|
|
||||||
* Wed Jan 29 2020 Vojtech Trefny <vtrefny@redhat.com> - 3.1.7-1
|
* Wed Jan 29 2020 Vojtech Trefny <vtrefny@redhat.com> - 3.1.7-1
|
||||||
- Use SHA256 instead of MD5 for /proc/mounts hash calculation (vtrefny)
|
- Use SHA256 instead of MD5 for /proc/mounts hash calculation (vtrefny)
|
||||||
- Fix udev test names so they actually get run. (dlehman)
|
- Fix udev test names so they actually get run. (dlehman)
|
||||||
|
Loading…
Reference in New Issue
Block a user