Protect FdEntity::physical_fd with fdent_lock (#2194)

* Protect FdEntity::physical_fd with fdent_lock
Found via ThreadSanitizer.
This commit is contained in:
Andrew Gaul 2023-06-25 16:43:15 +09:00 committed by GitHub
parent 3b6688253f
commit 6448c8f1a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 4 deletions

View File

@ -1410,14 +1410,14 @@ off_t FdEntity::BytesModified()
//
int FdEntity::RowFlush(int fd, const char* tpath, AutoLock::Type type, bool force_sync)
{
AutoLock auto_lock(&fdent_lock, type);
S3FS_PRN_INFO3("[tpath=%s][path=%s][pseudo_fd=%d][physical_fd=%d]", SAFESTRPTR(tpath), path.c_str(), fd, physical_fd);
if(-1 == physical_fd){
return -EBADF;
}
AutoLock auto_lock(&fdent_lock, type);
// check pseudo fd and its flag
fdinfo_map_t::iterator miter = pseudo_fd_map.find(fd);
if(pseudo_fd_map.end() == miter || NULL == miter->second){
@ -2491,10 +2491,11 @@ bool FdEntity::PunchHole(off_t start, size_t size)
{
S3FS_PRN_DBG("[path=%s][physical_fd=%d][offset=%lld][size=%zu]", path.c_str(), physical_fd, static_cast<long long int>(start), size);
AutoLock auto_lock(&fdent_data_lock);
if(-1 == physical_fd){
return false;
}
AutoLock auto_lock(&fdent_data_lock);
// get page list that have no data
fdpage_list_t nodata_pages;
@ -2532,10 +2533,19 @@ bool FdEntity::PunchHole(off_t start, size_t size)
//
void FdEntity::MarkDirtyNewFile()
{
AutoLock auto_lock(&fdent_data_lock);
pagelist.Init(0, false, true);
pending_status = CREATE_FILE_PENDING;
}
bool FdEntity::IsDirtyNewFile() const
{
AutoLock auto_lock(&fdent_data_lock);
return (CREATE_FILE_PENDING == pending_status);
}
bool FdEntity::AddUntreated(off_t start, off_t size)
{
bool result = untreated_list.AddPart(start, size);

View File

@ -149,7 +149,7 @@ class FdEntity
bool PunchHole(off_t start = 0, size_t size = 0);
void MarkDirtyNewFile();
bool IsDirtyNewFile() { return (CREATE_FILE_PENDING == pending_status); }
bool IsDirtyNewFile() const;
bool GetLastUpdateUntreatedPart(off_t& start, off_t& size) const;
bool ReplaceLastUpdateUntreatedPart(off_t front_start, off_t front_size, off_t behind_start, off_t behind_size);