From e93c17c021e934bb9028036775c2b541f7fd511b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaroslav=20=C5=A0karvada?= Date: Thu, 30 May 2024 17:23:43 +0200 Subject: [PATCH] hotplug: wait for device initialization MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jaroslav Škarvada --- tuned/consts.py | 5 +++++ tuned/hardware/inventory.py | 8 ++++++++ 2 files changed, 13 insertions(+) diff --git a/tuned/consts.py b/tuned/consts.py index 48c80f0dd..38c85220a 100644 --- a/tuned/consts.py +++ b/tuned/consts.py @@ -215,3 +215,8 @@ "console": LOG_LEVEL_CONSOLE, "none": None, } + +# number of retries when waiting for device initialization +HOTPLUG_WAIT_FOR_DEV_INIT_RETRIES = 100 +# how long to wait for device initialization in seconds during retry +HOTPLUG_WAIT_FOR_DEV_INIT_DELAY = 0.1 diff --git a/tuned/hardware/inventory.py b/tuned/hardware/inventory.py index a08e45609..49aea04fb 100644 --- a/tuned/hardware/inventory.py +++ b/tuned/hardware/inventory.py @@ -54,6 +54,14 @@ def _handle_udev_event(self, event, device): if not device.subsystem in self._subscriptions: return + retry = consts.HOTPLUG_WAIT_FOR_DEV_INIT_RETRIES + while not device.is_initialized and retry > 0: + log.debug("Device '%s' is uninitialized, waiting '%d' seconds for its initialization." % (device, consts.HOTPLUG_WAIT_FOR_DEV_INIT_DELAY)) + time.sleep(consts.HOTPLUG_WAIT_FOR_DEV_INIT_DELAY) + retry =- 1 + if not device.is_initialized: + log.warn("Unsuccessfully waited for device '%s' initialization, continuing with uninitialized device, problems may occur." % device) + for (plugin, callback) in self._subscriptions[device.subsystem]: try: callback(event, device)