From dae3375e720fe67870fe92e0aecd9638726c4d43 Mon Sep 17 00:00:00 2001 From: Vojtech Trefny Date: Wed, 9 Sep 2020 15:26:39 +0200 Subject: [PATCH 1/2] Try to not use udev.resolve_devspec when querying MountsCache udev.resolve_devspec is slow and uses udev.settle, we should avoid using it if possible when getting system mountpoints. --- blivet/mounts.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/blivet/mounts.py b/blivet/mounts.py index 7ce41d77..ef2def89 100644 --- a/blivet/mounts.py +++ b/blivet/mounts.py @@ -27,6 +27,8 @@ import logging log = logging.getLogger("blivet") +import os + class _MountinfoCache(object): @@ -113,6 +115,12 @@ def get_mountpoints(self, devspec, subvolspec=None): # devspec == None means "get 'nodev' mount points" if devspec not in (None, "tmpfs"): + if devspec.startswith("/dev"): + # try to avoid using resolve_devspec if possible + name = os.path.realpath(devspec).split("/")[-1] + if (name, subvolspec) in self.mountpoints.keys(): + return self.mountpoints[(name, subvolspec)] + # use the canonical device path (if available) canon_devspec = resolve_devspec(devspec, sysname=True) if canon_devspec is not None: From ae32d008e7425610d437c72bb284664ace7ce5b7 Mon Sep 17 00:00:00 2001 From: Vojtech Trefny Date: Wed, 9 Sep 2020 15:27:57 +0200 Subject: [PATCH 2/2] Do not run udev.settle in StorageDevice._pre_teardown We currently run udev.settle for every _pre_teardown call even if there is no change or format teardown. This commit moves the udev.settle call to format classes so it is called only when format.teardown calls in _pre_teardown change the format. --- blivet/devices/storage.py | 1 - blivet/formats/fs.py | 2 ++ blivet/formats/luks.py | 5 +++++ blivet/formats/swap.py | 3 +++ tests/devices_test/device_methods_test.py | 2 -- 5 files changed, 10 insertions(+), 3 deletions(-) diff --git a/blivet/devices/storage.py b/blivet/devices/storage.py index d47affca..bde0b7d6 100644 --- a/blivet/devices/storage.py +++ b/blivet/devices/storage.py @@ -425,7 +425,6 @@ def _pre_teardown(self, recursive=None): self.original_format.teardown() if self.format.exists: self.format.teardown() - udev.settle() return True def _teardown(self, recursive=None): diff --git a/blivet/formats/fs.py b/blivet/formats/fs.py index 9c14649e..d351dee1 100644 --- a/blivet/formats/fs.py +++ b/blivet/formats/fs.py @@ -614,6 +614,8 @@ def _teardown(self, **kwargs): if mountpoint == self._chrooted_mountpoint: self._chrooted_mountpoint = None + udev.settle() + def read_label(self): """Read this filesystem's label. diff --git a/blivet/formats/luks.py b/blivet/formats/luks.py index de9f1d32..0d036588 100644 --- a/blivet/formats/luks.py +++ b/blivet/formats/luks.py @@ -36,6 +36,7 @@ from ..tasks import availability, lukstasks from ..size import Size, KiB from ..static_data import luks_data +from .. import udev import logging log = logging.getLogger("blivet") @@ -275,6 +276,8 @@ def _teardown(self, **kwargs): log.debug("unmapping %s", self.map_name) blockdev.crypto.luks_close(self.map_name) + udev.settle() + def _pre_resize(self): if self.luks_version == "luks2" and not self.has_key: raise LUKSError("Passphrase or key needs to be set before resizing LUKS2 format.") @@ -442,5 +445,7 @@ def _teardown(self, **kwargs): # for all devices supported by cryptsetup blockdev.crypto.luks_close(self.map_name) + udev.settle() + register_device_format(Integrity) diff --git a/blivet/formats/swap.py b/blivet/formats/swap.py index 3cc59138..2e4b07df 100644 --- a/blivet/formats/swap.py +++ b/blivet/formats/swap.py @@ -29,6 +29,7 @@ from ..tasks import fsuuid from . import DeviceFormat, register_device_format from ..size import Size +from .. import udev import gi gi.require_version("BlockDev", "2.0") @@ -206,6 +207,8 @@ def _teardown(self, **kwargs): type=self.type, status=self.status) blockdev.swap.swapoff(self.device) + udev.settle() + def _create(self, **kwargs): log_method_call(self, device=self.device, type=self.type, status=self.status) diff --git a/tests/devices_test/device_methods_test.py b/tests/devices_test/device_methods_test.py index e6718121..f00509be 100644 --- a/tests/devices_test/device_methods_test.py +++ b/tests/devices_test/device_methods_test.py @@ -161,7 +161,6 @@ def _destroy(): self.assertFalse(self.device.exists) self.assertEqual(self.device.update_sysfs_path.called, self.destroy_updates_sysfs_path) - self.assertEqual(self.patches["udev"].settle.called, self.destroy_calls_udev_settle) self.patches["udev"].reset_mock() self.device.update_sysfs_path.reset_mock() @@ -228,7 +227,6 @@ def test_teardown(self): self.device.teardown() self.assertTrue(self.teardown_method_mock.called) - self.assertEqual(self.patches["udev"].settle.called, self.teardown_calls_udev_settle) self.assertEqual(self.device.update_sysfs_path.called, self.teardown_updates_sysfs_path) self.patches["udev"].reset_mock() self.device.update_sysfs_path.reset_mock()