- prof_list = self.get_refs('profile')
- for prof_uuid in prof_list:
- prof_db = self.lookup(prof_uuid)
- if not prof_db:
- panic("profile:", profile, "not found.")
- for ref_class, ref_uuid in prof_db.get_all_refs():
- if ref_class in ('osd', 'mdsdev'):
- devdb = self.lookup(ref_uuid)
- uuid = devdb.get_first_ref('target')
- if tgtuuid == uuid:
- return ref_uuid
- return None
+ if self.caching_enabled and self.lookup_tgtdev_cache.has_key(tgtuuid):
+ res = self.lookup_tgtdev_cache[tgtuuid]
+ else:
+ prof_list = self.get_refs('profile')
+ res = None
+ for prof_uuid in prof_list:
+ prof_db = self.lookup(prof_uuid)
+ if not prof_db:
+ panic("profile:", profile, "not found.")
+ for ref_class, ref_uuid in prof_db.get_all_refs():
+ if ref_class in ('osd', 'mdsdev'):
+ devdb = self.lookup(ref_uuid)
+ uuid = devdb.get_first_ref('target')
+ if tgtuuid == uuid:
+ res = ref_uuid
+ break
+ if not res is None:
+ break
+ if self.caching_enabled:
+ self.lookup_tgtdev_cache[tgtuuid] = res
+ return res