Skip to content

Commit

Permalink
Added backup variable for fdcache entity path
Browse files Browse the repository at this point in the history
  • Loading branch information
ggtakec committed Jan 21, 2025
1 parent dd4f139 commit f5dd1f8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/fdcache_entity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,10 @@ void FdEntity::Clear()
pagelist.Init(0, false, false);
path = "";
cachepath = "";

// set backup(read only) variable
const std::lock_guard<std::mutex> ro_lock(ro_path_lock);
ro_path = path;
}

// [NOTE]
Expand Down Expand Up @@ -723,6 +727,10 @@ bool FdEntity::RenamePath(const std::string& newpath, std::string& fentmapkey)
// set new path
path = newpath;

// set backup(read only) variable
const std::lock_guard<std::mutex> ro_lock(ro_path_lock);
ro_path = path;

return true;
}

Expand Down
7 changes: 7 additions & 0 deletions src/fdcache_entity.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ class FdEntity : public std::enable_shared_from_this<FdEntity>
pending_status_t pending_status GUARDED_BY(fdent_data_lock); // status for new file creation and meta update
struct timespec holding_mtime GUARDED_BY(fdent_data_lock); // if mtime is updated while the file is open, it is set time_t value

mutable std::mutex ro_path_lock; // for only the ro_path variable
std::string ro_path GUARDED_BY(ro_path_lock); // holds the same value as "path". this is used as a backup(read-only variable) by special functions only.

private:
static int FillFile(int fd, unsigned char byte, off_t size, off_t start);
static ino_t GetInode(int fd);
Expand Down Expand Up @@ -136,6 +139,10 @@ class FdEntity : public std::enable_shared_from_this<FdEntity>
return FindPseudoFdWithLock(fd);
}
bool FindPseudoFdWithLock(int fd) const REQUIRES(FdEntity::fdent_lock);
std::string GetROPath() const {
const std::lock_guard<std::mutex> ro_lock(ro_path_lock);
return ro_path;
}
int Open(const headers_t* pmeta, off_t size, const struct timespec& ts_mctime, int flags);
bool LoadAll(int fd, off_t* size = nullptr, bool force_load = false);
int Dup(int fd) {
Expand Down

0 comments on commit f5dd1f8

Please sign in to comment.