From aa7c0b71a730ba14a83b02414d7b7fa5f30e9898 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Sun, 17 Mar 2019 20:43:43 +0100 Subject: [PATCH] storage/lvm: refresh size cache if it's older than 30sec Disk usage may change dynamically not only at VM start/stop. Refresh the size cache before checking usage property, but no more than once every 30sec (refresh interval of disk space widget) Fixes QubesOS/qubes-issues#4888 --- qubes/storage/lvm.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/qubes/storage/lvm.py b/qubes/storage/lvm.py index b9eb4ef9..b26109cd 100644 --- a/qubes/storage/lvm.py +++ b/qubes/storage/lvm.py @@ -188,6 +188,7 @@ class ThinPool(qubes.storage.Pool): @property def usage(self): + refresh_cache() try: return qubes.storage.lvm.size_cache[ self.volume_group + '/' + self.thin_pool]['usage'] @@ -253,6 +254,7 @@ def init_cache_coro(log=logging.getLogger('qubes.storage.lvm')): return _parse_lvm_cache(out) +size_cache_time = 0 size_cache = init_cache() @@ -720,6 +722,7 @@ class ThinVolume(qubes.storage.Volume): @property def usage(self): # lvm thin usage always returns at least the same usage as # the parent + refresh_cache() try: return qubes.storage.lvm.size_cache[self._vid_current]['usage'] except KeyError: @@ -816,7 +819,14 @@ def qubes_lvm_coro(cmd, log=logging.getLogger('qubes.storage.lvm')): def reset_cache(): qubes.storage.lvm.size_cache = init_cache() + qubes.storage.lvm.size_cache_time = time.monotonic() @asyncio.coroutine def reset_cache_coro(): qubes.storage.lvm.size_cache = yield from init_cache_coro() + qubes.storage.lvm.size_cache_time = time.monotonic() + +def refresh_cache(): + '''Reset size cache, if it's older than 30sec ''' + if size_cache_time+30 < time.monotonic(): + reset_cache()