Browse Source

prolong lifetime of blockdevice cache to 120 seconds

fix blockdevice size calculation
respect "empty_cache" setting during blockdevice reset
master
lars 14 years ago
parent
commit
9bf82f30dc
  1. 10
      src/cryptobox/core/blockdevice.py

10
src/cryptobox/core/blockdevice.py

@ -51,7 +51,7 @@ MAJOR_DEVNUM_MD_RAID = 9
## cache settings
CACHE_ENABLED = True
CACHE_EXPIRE_SECONDS = 60
CACHE_EXPIRE_SECONDS = 120
CACHE_MONITOR_FILE = '/proc/partitions'
## useful for manual profiling
@ -139,7 +139,8 @@ class Blockdevice:
@type empty_cache: boolean
@param empty_cache: Whether to discard the cached information or not.
"""
CACHE.reset(["blockdevice_info", self.name])
if empty_cache:
CACHE.reset(["blockdevice_info", self.name])
self.devnum = self.__get_major_minor()
self.size = self.__get_size()
self.size_human = self.__get_size_human()
@ -387,8 +388,9 @@ class Blockdevice:
"""
default = 0
try:
size_kb = int(file(os.path.join(self.devdir, 'size')).read())
return int(size_kb/1024)
size_blocks = int(file(os.path.join(self.devdir, 'size')).read())
## size is defined as the number of blocks (512 byte)
return int(size_blocks/512)
except OSError:
return default
except ValueError:

Loading…
Cancel
Save