mirror of
https://github.com/s3fs-fuse/s3fs-fuse.git
synced 2024-12-22 16:58:55 +00:00
Separate serialization and deserialization code (#2566)
This is clearer than a bool parameter.
This commit is contained in:
parent
a8af6cb3b4
commit
31061416bc
@ -981,7 +981,7 @@ bool FdManager::RawCheckAllCache(FILE* fp, const char* cache_stat_top_dir, const
|
||||
// open cache stat file and load page info.
|
||||
PageList pagelist;
|
||||
CacheFileStat cfstat(object_file_path.c_str());
|
||||
if(!cfstat.ReadOnlyOpen() || !pagelist.Serialize(cfstat, false, cache_file_inode)){
|
||||
if(!cfstat.ReadOnlyOpen() || !pagelist.Deserialize(cfstat, cache_file_inode)){
|
||||
++err_file_cnt;
|
||||
S3FS_PRN_CACHE(fp, CACHEDBG_FMT_FILE_PROB, object_file_path.c_str(), strOpenedWarn.c_str());
|
||||
S3FS_PRN_CACHE(fp, CACHEDBG_FMT_CRIT_HEAD, "Could not load cache file stats information");
|
||||
|
@ -137,7 +137,7 @@ void FdEntity::Clear()
|
||||
ino_t cur_inode = GetInode();
|
||||
if(0 != cur_inode && cur_inode == inode){
|
||||
CacheFileStat cfstat(path.c_str());
|
||||
if(!pagelist.Serialize(cfstat, true, inode)){
|
||||
if(!pagelist.Serialize(cfstat, inode)){
|
||||
S3FS_PRN_WARN("failed to save cache stat file(%s).", path.c_str());
|
||||
}
|
||||
}
|
||||
@ -204,7 +204,7 @@ void FdEntity::Close(int fd)
|
||||
ino_t cur_inode = GetInode();
|
||||
if(0 != cur_inode && cur_inode == inode){
|
||||
CacheFileStat cfstat(path.c_str());
|
||||
if(!pagelist.Serialize(cfstat, true, inode)){
|
||||
if(!pagelist.Serialize(cfstat, inode)){
|
||||
S3FS_PRN_WARN("failed to save cache stat file(%s).", path.c_str());
|
||||
}
|
||||
}
|
||||
@ -449,7 +449,7 @@ int FdEntity::Open(const headers_t* pmeta, off_t size, const struct timespec& ts
|
||||
// try to open cache file
|
||||
if( -1 != (physical_fd = open(cachepath.c_str(), O_RDWR)) &&
|
||||
0 != (inode = FdEntity::GetInode(physical_fd)) &&
|
||||
pagelist.Serialize(*pcfstat, false, inode) )
|
||||
pagelist.Deserialize(*pcfstat, inode))
|
||||
{
|
||||
// succeed to open cache file and to load stats data
|
||||
st = {};
|
||||
@ -581,7 +581,7 @@ int FdEntity::Open(const headers_t* pmeta, off_t size, const struct timespec& ts
|
||||
|
||||
// reset cache stat file
|
||||
if(need_save_csf && pcfstat.get()){
|
||||
if(!pagelist.Serialize(*pcfstat, true, inode)){
|
||||
if(!pagelist.Serialize(*pcfstat, inode)){
|
||||
S3FS_PRN_WARN("failed to save cache stat file(%s), but continue...", path.c_str());
|
||||
}
|
||||
}
|
||||
|
@ -819,12 +819,12 @@ bool PageList::ClearAllModified()
|
||||
return Compress();
|
||||
}
|
||||
|
||||
bool PageList::Serialize(CacheFileStat& file, bool is_output, ino_t inode)
|
||||
bool PageList::Serialize(CacheFileStat& file, ino_t inode)
|
||||
{
|
||||
if(!file.Open()){
|
||||
return false;
|
||||
}
|
||||
if(is_output){
|
||||
|
||||
//
|
||||
// put to file
|
||||
//
|
||||
@ -845,7 +845,15 @@ bool PageList::Serialize(CacheFileStat& file, bool is_output, ino_t inode)
|
||||
return false;
|
||||
}
|
||||
|
||||
}else{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PageList::Deserialize(CacheFileStat& file, ino_t inode)
|
||||
{
|
||||
if(!file.Open()){
|
||||
return false;
|
||||
}
|
||||
|
||||
//
|
||||
// loading from file
|
||||
//
|
||||
@ -966,7 +974,7 @@ bool PageList::Serialize(CacheFileStat& file, bool is_output, ino_t inode)
|
||||
Clear();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -94,6 +94,7 @@ class PageList
|
||||
|
||||
void Clear();
|
||||
bool Parse(off_t new_pos);
|
||||
bool Serialize(CacheFileStat& file, ino_t inode);
|
||||
|
||||
public:
|
||||
static void FreeList(fdpage_list_t& list);
|
||||
@ -122,7 +123,7 @@ class PageList
|
||||
bool ClearAllModified();
|
||||
|
||||
bool Compress();
|
||||
bool Serialize(CacheFileStat& file, bool is_output, ino_t inode);
|
||||
bool Deserialize(CacheFileStat& file, ino_t inode);
|
||||
void Dump() const;
|
||||
bool CompareSparseFile(int fd, size_t file_size, fdpage_list_t& err_area_list, fdpage_list_t& warn_area_list);
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user