* added code to catch some more error conditions

* slightly changed the structure of the block device cache
This commit is contained in:
lars 2009-06-11 23:20:23 +00:00
parent df2a8a0db9
commit fe0a062bf6

View file

@ -173,7 +173,7 @@ class Blockdevice:
@param empty_cache: Whether to discard the cached information or not.
"""
if empty_cache:
CACHE.reset(["blockdevice_info", self.name])
CACHE.reset(["blockdevice_info", (self.major, self.minor)])
self.size = self.__get_size()
self.size_human = self.__get_size_human()
self.range = self.__get_device_range()
@ -181,6 +181,14 @@ class Blockdevice:
self.holders = self.__get_dev_related("holders")
self.children = self.__get_children()
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()
self.label = attributes["label"]
self.type_id = attributes["type_id"]
@ -237,7 +245,7 @@ class Blockdevice:
@return: 'True' for a device usable as a storage
"""
## 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)
if not cached is None:
return cached
@ -282,7 +290,7 @@ class Blockdevice:
"""return if the device is a physical volume of a LVM
"""
## 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)
if not cached is None:
return cached
@ -300,7 +308,7 @@ class Blockdevice:
"""return if the device is a logical volume of a LVM
"""
## 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)
if not cached is None:
return cached
@ -325,7 +333,7 @@ class Blockdevice:
"""check if the device is the base of a md raid device
"""
## 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)
if not cached is None:
return cached
@ -352,7 +360,7 @@ class Blockdevice:
"""check if the device is a luks container
"""
## 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)
if not cached is None:
return cached
@ -388,7 +396,7 @@ class Blockdevice:
"""check if the device is marked as 'removable'
"""
## 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)
if not cached is None:
return cached
@ -690,10 +698,10 @@ class BlockdeviceCache:
self.reset()
def reset(self, link=None):
def reset(self, target=None):
"""empty the cache and reset the expire time
"""
if not link:
if target is None:
self.values = {}
try:
self.partitions_save = file(CACHE_MONITOR_FILE).read()
@ -702,9 +710,15 @@ class BlockdeviceCache:
(CACHE_MONITOR_FILE, err_msg))
self.partitions_save = ""
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:
## we do no reset the expire date
self.set(link, {})
LOGGER.log.warn("Invalid argument type for reset: %s" % \
str(type(target)))
def __is_expired(self):
@ -811,7 +825,9 @@ def __get_major_minor(dev):
def get_blockdevice(dev,
sysblock_dir=DEFAULT_SYSBLOCK_DIR,
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
major_minor = (dev.major, dev.minor)
elif type(dev) is types.TupleType: