Corresponded to upload in case of calling release without flush (#2150)

This commit is contained in:
Takeshi Nakatani 2023-04-23 22:59:04 +09:00 committed by GitHub
parent 9b75abfbe6
commit 6d4bb59865
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2911,6 +2911,33 @@ static int s3fs_release(const char* _path, struct fuse_file_info* fi)
WTF8_ENCODE(path) WTF8_ENCODE(path)
S3FS_PRN_INFO("[path=%s][pseudo_fd=%llu]", path, (unsigned long long)(fi->fh)); S3FS_PRN_INFO("[path=%s][pseudo_fd=%llu]", path, (unsigned long long)(fi->fh));
{ // scope for AutoFdEntity
AutoFdEntity autoent;
// [NOTE]
// The pseudo fd stored in fi->fh is attached to AutoFdEntry so that it can be
// destroyed here.
//
FdEntity* ent;
if(NULL == (ent = autoent.Attach(path, static_cast<int>(fi->fh)))){
S3FS_PRN_ERR("could not find pseudo_fd(%llu) for path(%s)", (unsigned long long)(fi->fh), path);
return -EIO;
}
// [NOTE]
// There are cases when s3fs_flush is not called and s3fs_release is called.
// (There have been reported cases where it is not called when exported as NFS.)
// Therefore, Flush() is called here to try to upload the data.
// Flush() will only perform an upload if the file has been updated.
//
int result;
if(ent->IsModified()){
if(0 != (result = ent->Flush(static_cast<int>(fi->fh), AutoLock::NONE, false))){
S3FS_PRN_ERR("failed to upload file contentsfor pseudo_fd(%llu) / path(%s) by result(%d)", (unsigned long long)(fi->fh), path, result);
return result;
}
}
// [NOTE] // [NOTE]
// All opened file's stats is cached with no truncate flag. // All opened file's stats is cached with no truncate flag.
// Thus we unset it here. // Thus we unset it here.
@ -2926,24 +2953,10 @@ static int s3fs_release(const char* _path, struct fuse_file_info* fi)
StatCache::getStatCacheData()->DelStat(path); StatCache::getStatCacheData()->DelStat(path);
} }
{ // scope for AutoFdEntity
AutoFdEntity autoent;
// [NOTE]
// The pseudo fd stored in fi->fh is attached to AutoFdEntry so that it can be
// destroyed here.
//
FdEntity* ent;
if(NULL == (ent = autoent.Attach(path, static_cast<int>(fi->fh)))){
S3FS_PRN_ERR("could not find pseudo_fd(%llu) for path(%s)", (unsigned long long)(fi->fh), path);
return -EIO;
}
bool is_new_file = ent->IsDirtyNewFile(); bool is_new_file = ent->IsDirtyNewFile();
// TODO: correct locks held? // TODO: correct locks held?
int result = ent->UploadPending(static_cast<int>(fi->fh), AutoLock::NONE); if(0 != (result = ent->UploadPending(static_cast<int>(fi->fh), AutoLock::NONE))){
if(0 != result){
S3FS_PRN_ERR("could not upload pending data(meta, etc) for pseudo_fd(%llu) / path(%s)", (unsigned long long)(fi->fh), path); S3FS_PRN_ERR("could not upload pending data(meta, etc) for pseudo_fd(%llu) / path(%s)", (unsigned long long)(fi->fh), path);
return result; return result;
} }
@ -2960,7 +2973,7 @@ static int s3fs_release(const char* _path, struct fuse_file_info* fi)
// check - for debug // check - for debug
if(S3fsLog::IsS3fsLogDbg()){ if(S3fsLog::IsS3fsLogDbg()){
if(FdManager::HasOpenEntityFd(path)){ if(FdManager::HasOpenEntityFd(path)){
S3FS_PRN_WARN("file(%s) is still opened(another pseudo fd is opend).", path); S3FS_PRN_DBG("file(%s) is still opened(another pseudo fd is opend).", path);
} }
} }
S3FS_MALLOCTRIM(0); S3FS_MALLOCTRIM(0);