Skip to content

Commit

Permalink
add a safe getMetadata method to InodeBase
Browse files Browse the repository at this point in the history
Summary:
Prior to this diff, to read the inode metadata from an InodeBase, you
had to cast it to a FileInode or TreeInode. Add a public getMetadata
call that acquires the appropriate lock depending on whether it's a
FileInode or TreeInode.

Reviewed By: simpkins

Differential Revision: D9327180

fbshipit-source-id: 66594fb639f1ea72a0e48dcb79234e14d87ec4a2
  • Loading branch information
chadaustin authored and facebook-github-bot committed Aug 23, 2018
1 parent d3f135d commit f87e6bc
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
4 changes: 2 additions & 2 deletions eden/fs/inodes/FileInode.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ struct FileInodeState {
size_t openCount{0};
};

class FileInode : public InodeBaseMetadata<FileInodeState> {
class FileInode final : public InodeBaseMetadata<FileInodeState> {
public:
using Base = InodeBaseMetadata<FileInodeState>;
using FileHandlePtr = std::shared_ptr<EdenFileHandle>;
Expand Down Expand Up @@ -222,7 +222,7 @@ class FileInode : public InodeBaseMetadata<FileInodeState> {
/**
* Returns a copy of this inode's metadata.
*/
InodeMetadata getMetadata() const;
InodeMetadata getMetadata() const override;

/**
* If this file is backed by a source control Blob, return the hash of the
Expand Down
2 changes: 1 addition & 1 deletion eden/fs/inodes/InodeBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ ParentInodeInfo InodeBase::getParentInfo() const {
}
}

InodeMetadata InodeBase::getMetadata() const {
InodeMetadata InodeBase::getMetadataLocked() const {
return getMount()->getInodeMetadataTable()->getOrThrow(getNodeId());
}

Expand Down
12 changes: 9 additions & 3 deletions eden/fs/inodes/InodeBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,11 @@ class InodeBase {
return *loc;
}

/**
* Acquire this inode's contents lock and return its metadata.
*/
virtual InodeMetadata getMetadata() const = 0;

protected:
/**
* Returns current time from EdenMount's clock.
Expand All @@ -375,8 +380,9 @@ class InodeBase {
void updateJournal();

private:
// Private so only InodeBaseMetadata can call them
InodeMetadata getMetadata() const;
// The caller (which is always InodeBaseMetadata) must be holding the inode
// state lock for this type of inode when calling getMetadataLocked().
InodeMetadata getMetadataLocked() const;
void updateAtime();
InodeTimestamps updateMtimeAndCtime(timespec now);

Expand Down Expand Up @@ -570,7 +576,7 @@ class InodeBaseMetadata : public InodeBase {
* Get this inode's metadata. The inode's state lock must be held.
*/
InodeMetadata getMetadataLocked(const InodeState&) const {
return InodeBase::getMetadata();
return InodeBase::getMetadataLocked();
}

/**
Expand Down
4 changes: 2 additions & 2 deletions eden/fs/inodes/TreeInode.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ struct TreeInodeState {
/**
* Represents a directory in the file system.
*/
class TreeInode : public InodeBaseMetadata<DirContents> {
class TreeInode final : public InodeBaseMetadata<DirContents> {
public:
using Base = InodeBaseMetadata<DirContents>;

Expand Down Expand Up @@ -397,7 +397,7 @@ class TreeInode : public InodeBaseMetadata<DirContents> {
/**
* Returns a copy of this inode's metadata.
*/
InodeMetadata getMetadata() const;
InodeMetadata getMetadata() const override;

/**
* Updates the last-access timestamp. Public so TreeInodeDirHandle can call
Expand Down

0 comments on commit f87e6bc

Please sign in to comment.