Skip to content

Commit

Permalink
Protect FdEntity::physical_fd with fdent_lock
Browse files Browse the repository at this point in the history
Found via ThreadSanitizer.
  • Loading branch information
gaul committed Jun 24, 2023
1 parent 71ee9d4 commit 260af6c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
12 changes: 11 additions & 1 deletion src/fdcache_entity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/fdcache_entity.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 260af6c

Please sign in to comment.