* added code to catch some more error conditions
* slightly changed the structure of the block device cache
This commit is contained in:
parent
df2a8a0db9
commit
fe0a062bf6
1 changed files with 28 additions and 12 deletions
|
@ -173,7 +173,7 @@ class Blockdevice:
|
||||||
@param empty_cache: Whether to discard the cached information or not.
|
@param empty_cache: Whether to discard the cached information or not.
|
||||||
"""
|
"""
|
||||||
if empty_cache:
|
if empty_cache:
|
||||||
CACHE.reset(["blockdevice_info", self.name])
|
CACHE.reset(["blockdevice_info", (self.major, self.minor)])
|
||||||
self.size = self.__get_size()
|
self.size = self.__get_size()
|
||||||
self.size_human = self.__get_size_human()
|
self.size_human = self.__get_size_human()
|
||||||
self.range = self.__get_device_range()
|
self.range = self.__get_device_range()
|
||||||
|
@ -181,6 +181,14 @@ class Blockdevice:
|
||||||
self.holders = self.__get_dev_related("holders")
|
self.holders = self.__get_dev_related("holders")
|
||||||
self.children = self.__get_children()
|
self.children = self.__get_children()
|
||||||
self.devnodes = self.__get_device_nodes()
|
self.devnodes = self.__get_device_nodes()
|
||||||
|
if self.get_device() is None:
|
||||||
|
CACHE.reset(["blockdevice_nodes"])
|
||||||
|
self.devnodes = self.__get_device_nodes()
|
||||||
|
if self.get_device() is None:
|
||||||
|
LOGGER.warning("No suitable device nodes found for: %s" % \
|
||||||
|
self.devdir)
|
||||||
|
# the following code would fail without device node -> skip it
|
||||||
|
return
|
||||||
attributes = self.__get_blkid_attributes()
|
attributes = self.__get_blkid_attributes()
|
||||||
self.label = attributes["label"]
|
self.label = attributes["label"]
|
||||||
self.type_id = attributes["type_id"]
|
self.type_id = attributes["type_id"]
|
||||||
|
@ -237,7 +245,7 @@ class Blockdevice:
|
||||||
@return: 'True' for a device usable as a storage
|
@return: 'True' for a device usable as a storage
|
||||||
"""
|
"""
|
||||||
## check the cache first
|
## check the cache first
|
||||||
cache_link = ["blockdevice_info", self.name, "is_storage"]
|
cache_link = ["blockdevice_info", (self.major, self.minor), "is_storage"]
|
||||||
cached = CACHE.get(cache_link)
|
cached = CACHE.get(cache_link)
|
||||||
if not cached is None:
|
if not cached is None:
|
||||||
return cached
|
return cached
|
||||||
|
@ -282,7 +290,7 @@ class Blockdevice:
|
||||||
"""return if the device is a physical volume of a LVM
|
"""return if the device is a physical volume of a LVM
|
||||||
"""
|
"""
|
||||||
## check the cache first
|
## check the cache first
|
||||||
cache_link = ["blockdevice_info", self.name, "is_lvm_pv"]
|
cache_link = ["blockdevice_info", (self.major, self.minor), "is_lvm_pv"]
|
||||||
cached = CACHE.get(cache_link)
|
cached = CACHE.get(cache_link)
|
||||||
if not cached is None:
|
if not cached is None:
|
||||||
return cached
|
return cached
|
||||||
|
@ -300,7 +308,7 @@ class Blockdevice:
|
||||||
"""return if the device is a logical volume of a LVM
|
"""return if the device is a logical volume of a LVM
|
||||||
"""
|
"""
|
||||||
## check the cache first
|
## check the cache first
|
||||||
cache_link = ["blockdevice_info", self.name, "is_lvm_lv"]
|
cache_link = ["blockdevice_info", (self.major, self.minor), "is_lvm_lv"]
|
||||||
cached = CACHE.get(cache_link)
|
cached = CACHE.get(cache_link)
|
||||||
if not cached is None:
|
if not cached is None:
|
||||||
return cached
|
return cached
|
||||||
|
@ -325,7 +333,7 @@ class Blockdevice:
|
||||||
"""check if the device is the base of a md raid device
|
"""check if the device is the base of a md raid device
|
||||||
"""
|
"""
|
||||||
## check the cache first
|
## check the cache first
|
||||||
cache_link = ["blockdevice_info", self.name, "is_md_raid"]
|
cache_link = ["blockdevice_info", (self.major, self.minor), "is_md_raid"]
|
||||||
cached = CACHE.get(cache_link)
|
cached = CACHE.get(cache_link)
|
||||||
if not cached is None:
|
if not cached is None:
|
||||||
return cached
|
return cached
|
||||||
|
@ -352,7 +360,7 @@ class Blockdevice:
|
||||||
"""check if the device is a luks container
|
"""check if the device is a luks container
|
||||||
"""
|
"""
|
||||||
## check the cache first
|
## check the cache first
|
||||||
cache_link = ["blockdevice_info", self.name, "is_luks"]
|
cache_link = ["blockdevice_info", (self.major, self.minor), "is_luks"]
|
||||||
cached = CACHE.get(cache_link)
|
cached = CACHE.get(cache_link)
|
||||||
if not cached is None:
|
if not cached is None:
|
||||||
return cached
|
return cached
|
||||||
|
@ -388,7 +396,7 @@ class Blockdevice:
|
||||||
"""check if the device is marked as 'removable'
|
"""check if the device is marked as 'removable'
|
||||||
"""
|
"""
|
||||||
## check the cache first
|
## check the cache first
|
||||||
cache_link = ["blockdevice_info", self.name, "is_removable"]
|
cache_link = ["blockdevice_info", (self.major, self.minor), "is_removable"]
|
||||||
cached = CACHE.get(cache_link)
|
cached = CACHE.get(cache_link)
|
||||||
if not cached is None:
|
if not cached is None:
|
||||||
return cached
|
return cached
|
||||||
|
@ -690,10 +698,10 @@ class BlockdeviceCache:
|
||||||
self.reset()
|
self.reset()
|
||||||
|
|
||||||
|
|
||||||
def reset(self, link=None):
|
def reset(self, target=None):
|
||||||
"""empty the cache and reset the expire time
|
"""empty the cache and reset the expire time
|
||||||
"""
|
"""
|
||||||
if not link:
|
if target is None:
|
||||||
self.values = {}
|
self.values = {}
|
||||||
try:
|
try:
|
||||||
self.partitions_save = file(CACHE_MONITOR_FILE).read()
|
self.partitions_save = file(CACHE_MONITOR_FILE).read()
|
||||||
|
@ -702,9 +710,15 @@ class BlockdeviceCache:
|
||||||
(CACHE_MONITOR_FILE, err_msg))
|
(CACHE_MONITOR_FILE, err_msg))
|
||||||
self.partitions_save = ""
|
self.partitions_save = ""
|
||||||
self.expires = int(time.time()) + CACHE_EXPIRE_SECONDS
|
self.expires = int(time.time()) + CACHE_EXPIRE_SECONDS
|
||||||
|
elif type(target) == types.ListType:
|
||||||
|
# we do not reset the expire date
|
||||||
|
self.set(target, {})
|
||||||
|
elif isinstance(target, Blockdevice):
|
||||||
|
# we do not reset the expire date
|
||||||
|
self.set(["blockdevice_info", (target.major, target.minor)], {})
|
||||||
else:
|
else:
|
||||||
## we do no reset the expire date
|
LOGGER.log.warn("Invalid argument type for reset: %s" % \
|
||||||
self.set(link, {})
|
str(type(target)))
|
||||||
|
|
||||||
|
|
||||||
def __is_expired(self):
|
def __is_expired(self):
|
||||||
|
@ -811,7 +825,9 @@ def __get_major_minor(dev):
|
||||||
def get_blockdevice(dev,
|
def get_blockdevice(dev,
|
||||||
sysblock_dir=DEFAULT_SYSBLOCK_DIR,
|
sysblock_dir=DEFAULT_SYSBLOCK_DIR,
|
||||||
devnode_dir=DEFAULT_DEVNODE_DIR, retry_once=True):
|
devnode_dir=DEFAULT_DEVNODE_DIR, retry_once=True):
|
||||||
if isinstance(dev, Blockdevice):
|
if dev is None:
|
||||||
|
return None
|
||||||
|
elif isinstance(dev, Blockdevice):
|
||||||
# it is already a blockdevice
|
# it is already a blockdevice
|
||||||
major_minor = (dev.major, dev.minor)
|
major_minor = (dev.major, dev.minor)
|
||||||
elif type(dev) is types.TupleType:
|
elif type(dev) is types.TupleType:
|
||||||
|
|
Loading…
Reference in a new issue