sapling/eden/fs/prjfs/PrjfsDispatcher.h
Xavier Deguillard 62076b545e inodes: move dispatchers around
Summary:
Instead of having one "Dispatcher" type that the various backend overload,
let's simply have a per-mount type dispatcher type. The previous model worked
fine when EdenFS supported only one way of mounting a repository, but with NFS
coming, unix platform will support both FUSE and NFS, making the Dispatcher
overload nonsensical.

As a behavioral change, the dispatcher lifetime and ownership is changed a bit.
It used to live for the duration of the EdenMount object, but is now tied to
the channel lifetime, as it is now owned by it.

Reviewed By: kmancini

Differential Revision: D26329477

fbshipit-source-id: 3959b90a4909e3ab0898caa308f54686f59a943c
2021-02-10 11:52:06 -08:00

152 lines
3.6 KiB
C++

/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This software may be used and distributed according to the terms of the
* GNU General Public License version 2.
*/
#pragma once
#include "folly/portability/Windows.h"
#include <ProjectedFSLib.h> // @manual
#include "eden/fs/prjfs/Enumerator.h"
#include "eden/fs/utils/Guid.h"
#include "eden/fs/utils/PathFuncs.h"
namespace folly {
template <class T>
class Future;
} // namespace folly
namespace facebook::eden {
class ObjectFetchContext;
class EdenStats;
struct InodeMetadata {
// To ensure that the OS has a record of the canonical file name, and not
// just whatever case was used to lookup the file, we capture the
// relative path here.
RelativePath path;
size_t size;
bool isDir;
};
struct LookupResult {
InodeMetadata meta;
std::function<void()> incFsRefcount;
};
class PrjfsDispatcher {
public:
virtual ~PrjfsDispatcher();
explicit PrjfsDispatcher(EdenStats* stats);
EdenStats* getStats() const;
/**
* Open a directory
*/
virtual folly::Future<std::vector<FileMetadata>> opendir(
RelativePathPiece path,
ObjectFetchContext& context) = 0;
/**
* Lookup the specified file and get its attributes.
*/
virtual folly::Future<std::optional<LookupResult>> lookup(
RelativePath path,
ObjectFetchContext& context) = 0;
/**
* Test if a file with the given name exist
*/
virtual folly::Future<bool> access(
RelativePath path,
ObjectFetchContext& context) = 0;
/**
* Read the file with the given name
*
* Returns the entire content of the file at path.
*
* In the future, this will return only what's in between offset and
* offset+length.
*/
virtual folly::Future<std::string> read(
RelativePath path,
ObjectFetchContext& context) = 0;
/**
* Notification sent when a file was created
*/
virtual folly::Future<folly::Unit> newFileCreated(
RelativePath relPath,
RelativePath destPath,
bool isDirectory,
ObjectFetchContext& context) = 0;
/**
* Notification sent when a file was ovewritten
*/
virtual folly::Future<folly::Unit> fileOverwritten(
RelativePath relPath,
RelativePath destPath,
bool isDirectory,
ObjectFetchContext& context) = 0;
/**
* Notification sent when a file is closed after being modified
*/
virtual folly::Future<folly::Unit> fileHandleClosedFileModified(
RelativePath relPath,
RelativePath destPath,
bool isDirectory,
ObjectFetchContext& context) = 0;
/**
* Notification sent when a file is renamed
*/
virtual folly::Future<folly::Unit> fileRenamed(
RelativePath oldPath,
RelativePath newPath,
bool isDirectory,
ObjectFetchContext& context) = 0;
/**
* Notification sent prior to renaming a file
*
* A failure will block the rename operation
*/
virtual folly::Future<folly::Unit> preRename(
RelativePath oldPath,
RelativePath newPath,
bool isDirectory,
ObjectFetchContext& context) = 0;
/**
* Notification sent when a file is being removed
*/
virtual folly::Future<folly::Unit> fileHandleClosedFileDeleted(
RelativePath relPath,
RelativePath destPath,
bool isDirectory,
ObjectFetchContext& context) = 0;
/**
* Notification sent prior to creating a hardlink
*
* A failure will block the hardlink operation
*/
virtual folly::Future<folly::Unit> preSetHardlink(
RelativePath oldPath,
RelativePath newPath,
bool isDirectory,
ObjectFetchContext& context) = 0;
private:
EdenStats* stats_{nullptr};
};
} // namespace facebook::eden