mirror of
https://github.com/facebook/sapling.git
synced 2024-10-05 14:28:17 +03:00
move InodeBase from eden/fuse to eden/fs/inodes
Summary: Move the InodeBase class from the lower-level fusell code up to the eden/fs/inodes layer, now that everything else that uses it is in eden/fs/inodes. I plan to start changing the ownership model of inode objects a bit, and this will allow the InodeBase class to interact with EdenDispatcher and other classes in eden/fs/inodes. Reviewed By: bolinfest Differential Revision: D4283392 fbshipit-source-id: 9e1d6fb81dc223f905847cbe8d165a40ad0aca4d
This commit is contained in:
parent
d478ee151b
commit
da04640287
@ -687,7 +687,7 @@ void Dirstate::remove(RelativePathPiece path, bool force) {
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<fusell::InodeBase> inode;
|
||||
std::shared_ptr<InodeBase> inode;
|
||||
if (parent != nullptr) {
|
||||
try {
|
||||
inode = parent->getChildByName(path.basename()).get();
|
||||
|
@ -196,14 +196,14 @@ std::shared_ptr<TreeInode> EdenDispatcher::getRootInode() const {
|
||||
return root_;
|
||||
}
|
||||
|
||||
void EdenDispatcher::recordInode(std::shared_ptr<fusell::InodeBase> inode) {
|
||||
void EdenDispatcher::recordInode(std::shared_ptr<InodeBase> inode) {
|
||||
auto ino = inode->getNodeId();
|
||||
std::unique_lock<SharedMutex> g(lock_);
|
||||
auto ret = inodes_.emplace(ino, std::move(inode));
|
||||
DCHECK(ret.second);
|
||||
}
|
||||
|
||||
std::shared_ptr<fusell::InodeBase> EdenDispatcher::getInode(
|
||||
std::shared_ptr<InodeBase> EdenDispatcher::getInode(
|
||||
fuse_ino_t ino,
|
||||
bool mustExist) const {
|
||||
std::shared_lock<SharedMutex> g(lock_);
|
||||
@ -217,8 +217,7 @@ std::shared_ptr<fusell::InodeBase> EdenDispatcher::getInode(
|
||||
return it->second;
|
||||
}
|
||||
|
||||
std::shared_ptr<fusell::InodeBase> EdenDispatcher::lookupInode(
|
||||
fuse_ino_t ino) const {
|
||||
std::shared_ptr<InodeBase> EdenDispatcher::lookupInode(fuse_ino_t ino) const {
|
||||
std::shared_lock<SharedMutex> g(lock_);
|
||||
const auto& it = inodes_.find(ino);
|
||||
if (it == inodes_.end()) {
|
||||
@ -276,8 +275,7 @@ folly::Future<fuse_entry_param> EdenDispatcher::lookup(
|
||||
});
|
||||
}
|
||||
|
||||
folly::Future<std::shared_ptr<fusell::InodeBase>>
|
||||
EdenDispatcher::lookupInodeBase(
|
||||
folly::Future<std::shared_ptr<InodeBase>> EdenDispatcher::lookupInodeBase(
|
||||
fuse_ino_t parent,
|
||||
PathComponentPiece namepiece) {
|
||||
auto dir = getTreeInode(parent);
|
||||
@ -285,7 +283,7 @@ EdenDispatcher::lookupInodeBase(
|
||||
// First, see if we already have the Inode loaded
|
||||
auto mgr = mount_->getNameMgr();
|
||||
auto node = mgr->getNodeByName(parent, namepiece, false);
|
||||
std::shared_ptr<fusell::InodeBase> existing_inode;
|
||||
std::shared_ptr<InodeBase> existing_inode;
|
||||
|
||||
if (node) {
|
||||
existing_inode = lookupInode(node->getNodeId());
|
||||
@ -293,7 +291,7 @@ EdenDispatcher::lookupInodeBase(
|
||||
|
||||
return (existing_inode ? makeFuture(existing_inode)
|
||||
: dir->getChildByName(namepiece))
|
||||
.then([=](std::shared_ptr<fusell::InodeBase> inode) mutable {
|
||||
.then([=](std::shared_ptr<InodeBase> inode) mutable {
|
||||
if (!inode) {
|
||||
throwSystemErrorExplicit(ENOENT);
|
||||
}
|
||||
|
@ -16,12 +16,12 @@ namespace facebook {
|
||||
namespace eden {
|
||||
|
||||
namespace fusell {
|
||||
class InodeBase;
|
||||
class InodeNameManager;
|
||||
}
|
||||
|
||||
class EdenMount;
|
||||
class FileInode;
|
||||
class InodeBase;
|
||||
class TreeInode;
|
||||
|
||||
/**
|
||||
@ -29,7 +29,7 @@ class TreeInode;
|
||||
*/
|
||||
class EdenDispatcher : public fusell::Dispatcher {
|
||||
std::shared_ptr<TreeInode> root_;
|
||||
std::unordered_map<fuse_ino_t, std::shared_ptr<fusell::InodeBase>> inodes_;
|
||||
std::unordered_map<fuse_ino_t, std::shared_ptr<InodeBase>> inodes_;
|
||||
mutable folly::SharedMutex lock_;
|
||||
|
||||
// The EdenMount that owns this EdenDispatcher.
|
||||
@ -49,9 +49,8 @@ class EdenDispatcher : public fusell::Dispatcher {
|
||||
EdenMount* mount,
|
||||
std::shared_ptr<TreeInode> rootInode);
|
||||
|
||||
std::shared_ptr<fusell::InodeBase> getInode(fuse_ino_t, bool mustExist = true)
|
||||
const;
|
||||
std::shared_ptr<fusell::InodeBase> lookupInode(fuse_ino_t) const;
|
||||
std::shared_ptr<InodeBase> getInode(fuse_ino_t, bool mustExist = true) const;
|
||||
std::shared_ptr<InodeBase> lookupInode(fuse_ino_t) const;
|
||||
std::shared_ptr<TreeInode> getTreeInode(fuse_ino_t, bool mustExist = true)
|
||||
const;
|
||||
std::shared_ptr<FileInode> getFileInode(fuse_ino_t, bool mustExist = true)
|
||||
@ -69,7 +68,7 @@ class EdenDispatcher : public fusell::Dispatcher {
|
||||
/** Throws if setRootInode() has not been invoked yet. */
|
||||
std::shared_ptr<TreeInode> getRootInode() const;
|
||||
|
||||
void recordInode(std::shared_ptr<fusell::InodeBase> inode);
|
||||
void recordInode(std::shared_ptr<InodeBase> inode);
|
||||
|
||||
void initConnection(fuse_conn_info& conn) override;
|
||||
folly::Future<Attr> getattr(fuse_ino_t ino) override;
|
||||
@ -86,7 +85,7 @@ class EdenDispatcher : public fusell::Dispatcher {
|
||||
/**
|
||||
* Similar to lookup(), except this does not require an active FUSE request.
|
||||
*/
|
||||
folly::Future<std::shared_ptr<fusell::InodeBase>> lookupInodeBase(
|
||||
folly::Future<std::shared_ptr<InodeBase>> lookupInodeBase(
|
||||
fuse_ino_t parent,
|
||||
PathComponentPiece name);
|
||||
folly::Future<folly::Unit> forget(fuse_ino_t ino,
|
||||
|
@ -113,8 +113,7 @@ std::unique_ptr<Tree> EdenMount::getRootTree() const {
|
||||
}
|
||||
}
|
||||
|
||||
shared_ptr<fusell::InodeBase> EdenMount::getInodeBase(
|
||||
RelativePathPiece path) const {
|
||||
shared_ptr<InodeBase> EdenMount::getInodeBase(RelativePathPiece path) const {
|
||||
auto inodeBase = dispatcher_->getInode(FUSE_ROOT_ID);
|
||||
auto relativePath = RelativePathPiece{path};
|
||||
|
||||
|
@ -17,7 +17,6 @@
|
||||
namespace facebook {
|
||||
namespace eden {
|
||||
namespace fusell {
|
||||
class InodeBase;
|
||||
class InodeNameManager;
|
||||
class MountPoint;
|
||||
}
|
||||
@ -27,6 +26,7 @@ class ClientConfig;
|
||||
class Dirstate;
|
||||
class EdenDispatcher;
|
||||
class FileInode;
|
||||
class InodeBase;
|
||||
class ObjectStore;
|
||||
class Overlay;
|
||||
class Journal;
|
||||
@ -126,7 +126,7 @@ class EdenMount {
|
||||
* @return the InodeBase for the specified path or throws a std::system_error
|
||||
* with ENOENT.
|
||||
*/
|
||||
std::shared_ptr<fusell::InodeBase> getInodeBase(RelativePathPiece path) const;
|
||||
std::shared_ptr<InodeBase> getInodeBase(RelativePathPiece path) const;
|
||||
|
||||
/**
|
||||
* @return the TreeInode for the specified path or throws a std::system_error
|
||||
|
@ -31,7 +31,7 @@ FileInode::FileInode(
|
||||
fuse_ino_t ino,
|
||||
std::shared_ptr<TreeInode> parentInode,
|
||||
TreeInode::Entry* entry)
|
||||
: fusell::InodeBase(ino),
|
||||
: InodeBase(ino),
|
||||
parentInode_(parentInode),
|
||||
entry_(entry),
|
||||
data_(
|
||||
@ -43,7 +43,7 @@ FileInode::FileInode(
|
||||
std::shared_ptr<TreeInode> parentInode,
|
||||
TreeInode::Entry* entry,
|
||||
folly::File&& file)
|
||||
: fusell::InodeBase(ino),
|
||||
: InodeBase(ino),
|
||||
parentInode_(parentInode),
|
||||
entry_(entry),
|
||||
data_(std::make_shared<FileData>(
|
||||
|
@ -9,9 +9,9 @@
|
||||
*/
|
||||
#pragma once
|
||||
#include <folly/File.h>
|
||||
#include "InodeBase.h"
|
||||
#include "TreeInode.h"
|
||||
#include "eden/fs/model/Tree.h"
|
||||
#include "eden/fuse/InodeBase.h"
|
||||
|
||||
namespace facebook {
|
||||
namespace eden {
|
||||
@ -20,7 +20,7 @@ class FileHandle;
|
||||
class FileData;
|
||||
class Hash;
|
||||
|
||||
class FileInode : public fusell::InodeBase {
|
||||
class FileInode : public InodeBase {
|
||||
public:
|
||||
/** Construct an inode using an overlay entry */
|
||||
FileInode(
|
||||
|
@ -13,7 +13,6 @@ using namespace folly;
|
||||
|
||||
namespace facebook {
|
||||
namespace eden {
|
||||
namespace fusell {
|
||||
|
||||
InodeBase::~InodeBase() {}
|
||||
|
||||
@ -24,13 +23,14 @@ InodeBase::InodeBase(fuse_ino_t ino) : ino_(ino) {
|
||||
}
|
||||
|
||||
// See Dispatcher::getattr
|
||||
folly::Future<Dispatcher::Attr> InodeBase::getattr() {
|
||||
folly::Future<fusell::Dispatcher::Attr> InodeBase::getattr() {
|
||||
FUSELL_NOT_IMPL();
|
||||
}
|
||||
|
||||
// See Dispatcher::setattr
|
||||
folly::Future<Dispatcher::Attr> InodeBase::setattr(const struct stat& attr,
|
||||
int to_set) {
|
||||
folly::Future<fusell::Dispatcher::Attr> InodeBase::setattr(
|
||||
const struct stat& /* attr */,
|
||||
int /* to_set */) {
|
||||
FUSELL_NOT_IMPL();
|
||||
}
|
||||
|
||||
@ -57,4 +57,3 @@ bool InodeBase::canForget() {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -10,12 +10,11 @@
|
||||
#pragma once
|
||||
#include <folly/futures/Future.h>
|
||||
#include <atomic>
|
||||
#include "Dispatcher.h"
|
||||
#include "fuse_headers.h"
|
||||
#include "eden/fuse/Dispatcher.h"
|
||||
#include "eden/fuse/fuse_headers.h"
|
||||
|
||||
namespace facebook {
|
||||
namespace eden {
|
||||
namespace fusell {
|
||||
|
||||
class InodeBase : public std::enable_shared_from_this<InodeBase> {
|
||||
fuse_ino_t ino_;
|
||||
@ -40,11 +39,12 @@ class InodeBase : public std::enable_shared_from_this<InodeBase> {
|
||||
}
|
||||
|
||||
// See Dispatcher::getattr
|
||||
virtual folly::Future<Dispatcher::Attr> getattr();
|
||||
virtual folly::Future<fusell::Dispatcher::Attr> getattr();
|
||||
|
||||
// See Dispatcher::setattr
|
||||
virtual folly::Future<Dispatcher::Attr> setattr(const struct stat& attr,
|
||||
int to_set);
|
||||
virtual folly::Future<fusell::Dispatcher::Attr> setattr(
|
||||
const struct stat& attr,
|
||||
int to_set);
|
||||
|
||||
virtual folly::Future<folly::Unit> setxattr(folly::StringPiece name,
|
||||
folly::StringPiece value,
|
||||
@ -60,4 +60,3 @@ class InodeBase : public std::enable_shared_from_this<InodeBase> {
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
@ -34,7 +34,7 @@ TreeInode::TreeInode(
|
||||
TreeInode::Entry* entry,
|
||||
fuse_ino_t parent,
|
||||
fuse_ino_t ino)
|
||||
: fusell::InodeBase(ino),
|
||||
: InodeBase(ino),
|
||||
mount_(mount),
|
||||
contents_(buildDirFromTree(tree.get())),
|
||||
entry_(entry),
|
||||
@ -49,7 +49,7 @@ TreeInode::TreeInode(
|
||||
TreeInode::Entry* entry,
|
||||
fuse_ino_t parent,
|
||||
fuse_ino_t ino)
|
||||
: fusell::InodeBase(ino),
|
||||
: InodeBase(ino),
|
||||
mount_(mount),
|
||||
contents_(std::move(dir)),
|
||||
entry_(entry),
|
||||
@ -77,7 +77,7 @@ fusell::Dispatcher::Attr TreeInode::getAttrLocked(const Dir* contents) {
|
||||
return attr;
|
||||
}
|
||||
|
||||
std::shared_ptr<fusell::InodeBase> TreeInode::getChildByNameLocked(
|
||||
std::shared_ptr<InodeBase> TreeInode::getChildByNameLocked(
|
||||
const Dir* contents,
|
||||
PathComponentPiece name) {
|
||||
auto iter = contents->entries.find(name);
|
||||
@ -114,7 +114,7 @@ std::shared_ptr<fusell::InodeBase> TreeInode::getChildByNameLocked(
|
||||
entry);
|
||||
}
|
||||
|
||||
folly::Future<std::shared_ptr<fusell::InodeBase>> TreeInode::getChildByName(
|
||||
folly::Future<std::shared_ptr<InodeBase>> TreeInode::getChildByName(
|
||||
PathComponentPiece namepiece) {
|
||||
auto contents = contents_.rlock();
|
||||
return getChildByNameLocked(&*contents, namepiece);
|
||||
@ -293,7 +293,7 @@ bool TreeInode::canForget() {
|
||||
}
|
||||
|
||||
folly::Future<fuse_entry_param> link(
|
||||
std::shared_ptr<fusell::InodeBase> /* node */,
|
||||
std::shared_ptr<InodeBase> /* node */,
|
||||
PathComponentPiece /* newname */) {
|
||||
// We intentionally do not support hard links.
|
||||
// These generally cannot be tracked in source control (git or mercurial)
|
||||
@ -411,7 +411,7 @@ folly::Future<folly::Unit> TreeInode::unlink(PathComponentPiece name) {
|
||||
return folly::Unit{};
|
||||
}
|
||||
|
||||
std::shared_ptr<fusell::InodeBase> TreeInode::lookupChildByNameLocked(
|
||||
std::shared_ptr<InodeBase> TreeInode::lookupChildByNameLocked(
|
||||
const Dir* contents,
|
||||
PathComponentPiece name) {
|
||||
auto dispatcher = getMount()->getDispatcher();
|
||||
|
@ -9,8 +9,8 @@
|
||||
*/
|
||||
#pragma once
|
||||
#include <folly/Optional.h>
|
||||
#include "eden/fs/inodes/InodeBase.h"
|
||||
#include "eden/fs/model/Hash.h"
|
||||
#include "eden/fuse/InodeBase.h"
|
||||
#include "eden/fuse/InodeNameManager.h"
|
||||
#include "eden/utils/PathMap.h"
|
||||
|
||||
@ -24,7 +24,7 @@ class Tree;
|
||||
class Overlay;
|
||||
|
||||
// Represents a Tree instance in a form that FUSE can consume
|
||||
class TreeInode : public fusell::InodeBase {
|
||||
class TreeInode : public InodeBase {
|
||||
public:
|
||||
/** Represents a directory entry.
|
||||
* A directory entry holds the combined Tree and Overlay data;
|
||||
@ -65,7 +65,7 @@ class TreeInode : public fusell::InodeBase {
|
||||
/// file attributes and cache ttls.
|
||||
fusell::Dispatcher::Attr attr;
|
||||
/// The newly created inode instance.
|
||||
std::shared_ptr<fusell::InodeBase> inode;
|
||||
std::shared_ptr<InodeBase> inode;
|
||||
/// The newly opened file handle.
|
||||
std::shared_ptr<FileHandle> file;
|
||||
/// The newly created node record from the name manager.
|
||||
@ -96,7 +96,7 @@ class TreeInode : public fusell::InodeBase {
|
||||
|
||||
/** Implements the InodeBase method used by the Dispatcher
|
||||
* to create the Inode instance for a given name */
|
||||
folly::Future<std::shared_ptr<fusell::InodeBase>> getChildByName(
|
||||
folly::Future<std::shared_ptr<InodeBase>> getChildByName(
|
||||
PathComponentPiece namepiece);
|
||||
|
||||
folly::Future<std::shared_ptr<fusell::DirHandle>> opendir(
|
||||
@ -170,7 +170,7 @@ class TreeInode : public fusell::InodeBase {
|
||||
* on the Dir object. This is needed because the equivalent lookupInodeBase
|
||||
* functionality in the dispatcher will call in to getChildByName and
|
||||
* attempt to acquire the lock */
|
||||
std::shared_ptr<fusell::InodeBase> lookupChildByNameLocked(
|
||||
std::shared_ptr<InodeBase> lookupChildByNameLocked(
|
||||
const Dir* contents,
|
||||
PathComponentPiece name);
|
||||
|
||||
@ -180,11 +180,10 @@ class TreeInode : public fusell::InodeBase {
|
||||
Dir buildDirFromTree(const Tree* tree);
|
||||
|
||||
/** Helper used to implement getChildByName and lookupChildByNameLocked */
|
||||
std::shared_ptr<fusell::InodeBase> getChildByNameLocked(
|
||||
std::shared_ptr<InodeBase> getChildByNameLocked(
|
||||
const Dir* contents,
|
||||
PathComponentPiece name);
|
||||
|
||||
|
||||
// The EdenMount object that this inode belongs to.
|
||||
// We store this as a raw pointer since the TreeInode is part of the mount
|
||||
// point. The EdenMount should always exist longer than any inodes it
|
||||
|
@ -210,8 +210,7 @@ SHA1Result EdenServiceHandler::getSHA1ForPath(
|
||||
|
||||
auto it = relativePath.paths().begin();
|
||||
while (true) {
|
||||
shared_ptr<fusell::InodeBase> inodeBase;
|
||||
inodeBase =
|
||||
shared_ptr<InodeBase> inodeBase =
|
||||
dispatcher->lookupInodeBase(parent->getNodeId(), it.piece().basename())
|
||||
.get();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user