change the way to get existing fdentity

This commit is contained in:
fangqianan.fqa 2024-12-18 10:37:05 +08:00
parent b83c2852b8
commit d47ad2a057

View File

@ -630,13 +630,28 @@ FdEntity* FdManager::GetExistFdEntity(const char* path, int existfd)
UpdateEntityToTempPath(); UpdateEntityToTempPath();
// search from all entity. // If use_cache is disabled, or the disk space is insufficient when use_cache
for(auto iter = fent.cbegin(); iter != fent.cend(); ++iter){ // is enabled, the corresponding key of the entity in fent is not path.
if(iter->second && iter->second->FindPseudoFd(existfd)){ fdent_map_t::iterator iter = fent.find(std::string(path));
// found existfd in entity if(fent.end() != iter){
return iter->second.get(); if(iter->second && iter->second->FindPseudoFd(existfd)){
return iter->second;
}
} else {
// no matter it's use_cache or not, we search from all entities to
// find entity with the same path. Then we compare the pseudo fd.
for(iter = fent.cbegin(); iter != fent.cend(); ++iter){
// IsOpen() is protected by fd_manager_lock, and so is GetPath().
// Therefore there is no need to hold entity lock here (FindPseudoFd
// holds it inside).
if(iter->second && iter->second->IsOpen() &&
0 == strcmp(iter->second->GetPath(), path) &&
iter->second->FindPseudoFd(existfd)){
return iter->second.get();
} }
}
} }
// not found entity // not found entity
return nullptr; return nullptr;
} }