2016-05-20 20:33:42 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2016, Facebook, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This source code is licensed under the BSD-style license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2016-09-19 22:48:11 +03:00
|
|
|
#include <folly/Synchronized.h>
|
2016-05-20 20:33:42 +03:00
|
|
|
#include <memory>
|
2016-09-19 22:48:11 +03:00
|
|
|
#include "eden/fs/journal/JournalDelta.h"
|
2016-05-20 20:33:42 +03:00
|
|
|
#include "eden/utils/PathFuncs.h"
|
|
|
|
|
|
|
|
namespace facebook {
|
|
|
|
namespace eden {
|
|
|
|
namespace fusell {
|
2016-12-02 04:49:40 +03:00
|
|
|
class InodeNameManager;
|
2016-05-20 20:33:42 +03:00
|
|
|
class MountPoint;
|
|
|
|
}
|
|
|
|
|
2016-09-13 04:27:54 +03:00
|
|
|
class BindMount;
|
|
|
|
class ClientConfig;
|
2016-11-26 23:00:16 +03:00
|
|
|
class Dirstate;
|
2016-12-02 04:49:42 +03:00
|
|
|
class EdenDispatcher;
|
2016-12-02 04:49:34 +03:00
|
|
|
class FileInode;
|
2016-12-08 07:03:50 +03:00
|
|
|
class InodeBase;
|
2016-06-09 04:59:51 +03:00
|
|
|
class ObjectStore;
|
2016-05-20 20:33:42 +03:00
|
|
|
class Overlay;
|
2016-09-19 22:48:11 +03:00
|
|
|
class Journal;
|
2016-10-21 23:30:20 +03:00
|
|
|
class Tree;
|
2016-12-02 04:49:34 +03:00
|
|
|
class TreeInode;
|
2016-05-20 20:33:42 +03:00
|
|
|
|
2016-12-13 04:48:45 +03:00
|
|
|
using InodePtr = std::shared_ptr<InodeBase>;
|
|
|
|
using TreeInodePtr = std::shared_ptr<TreeInode>;
|
|
|
|
using FileInodePtr = std::shared_ptr<FileInode>;
|
|
|
|
|
2016-12-02 04:49:34 +03:00
|
|
|
/**
|
2016-05-20 20:33:42 +03:00
|
|
|
* EdenMount contains all of the data about a specific eden mount point.
|
|
|
|
*
|
|
|
|
* This contains:
|
|
|
|
* - The fusell::MountPoint object which manages our FUSE interactions with the
|
|
|
|
* kernel.
|
2016-06-09 04:59:51 +03:00
|
|
|
* - The ObjectStore object used for retreiving/storing object data.
|
2016-05-20 20:33:42 +03:00
|
|
|
* - The Overlay object used for storing local changes (that have not been
|
|
|
|
* committed/snapshotted yet).
|
|
|
|
*/
|
|
|
|
class EdenMount {
|
|
|
|
public:
|
|
|
|
EdenMount(
|
2016-12-02 04:49:30 +03:00
|
|
|
std::unique_ptr<ClientConfig> config,
|
|
|
|
std::unique_ptr<ObjectStore> objectStore);
|
2016-05-20 20:33:42 +03:00
|
|
|
virtual ~EdenMount();
|
|
|
|
|
2016-12-02 04:49:34 +03:00
|
|
|
/**
|
2016-05-20 20:33:42 +03:00
|
|
|
* Get the MountPoint object.
|
|
|
|
*
|
|
|
|
* This returns a raw pointer since the EdenMount owns the mount point.
|
|
|
|
* The caller should generally maintain a reference to the EdenMount object,
|
|
|
|
* and not directly to the MountPoint object itself.
|
|
|
|
*/
|
|
|
|
fusell::MountPoint* getMountPoint() const {
|
|
|
|
return mountPoint_.get();
|
|
|
|
}
|
|
|
|
|
2016-12-02 04:49:34 +03:00
|
|
|
/**
|
2016-05-20 20:33:42 +03:00
|
|
|
* Return the path to the mount point.
|
|
|
|
*/
|
|
|
|
const AbsolutePath& getPath() const;
|
|
|
|
|
2016-09-13 04:27:54 +03:00
|
|
|
/*
|
|
|
|
* Return bind mounts that are applied for this mount. These are based on the
|
|
|
|
* state of the ClientConfig when this EdenMount was created.
|
|
|
|
*/
|
|
|
|
const std::vector<BindMount>& getBindMounts() const;
|
|
|
|
|
2016-12-02 04:49:34 +03:00
|
|
|
/**
|
2016-06-09 04:59:51 +03:00
|
|
|
* Return the ObjectStore used by this mount point.
|
|
|
|
*
|
|
|
|
* The ObjectStore is guaranteed to be valid for the lifetime of the
|
|
|
|
* EdenMount.
|
|
|
|
*/
|
|
|
|
ObjectStore* getObjectStore() const {
|
|
|
|
return objectStore_.get();
|
2016-05-20 20:33:42 +03:00
|
|
|
}
|
|
|
|
|
2016-12-02 04:49:34 +03:00
|
|
|
/**
|
2016-12-02 04:49:42 +03:00
|
|
|
* Return the EdenDispatcher used for this mount.
|
2016-12-02 04:49:34 +03:00
|
|
|
*/
|
2016-12-02 04:49:42 +03:00
|
|
|
EdenDispatcher* getDispatcher() const {
|
|
|
|
return dispatcher_.get();
|
|
|
|
}
|
2016-12-02 04:49:34 +03:00
|
|
|
|
2016-12-02 04:49:40 +03:00
|
|
|
/**
|
|
|
|
* Return the InodeNameManager used for this mount.
|
|
|
|
*/
|
2016-12-02 04:49:42 +03:00
|
|
|
fusell::InodeNameManager* getNameMgr() const {
|
|
|
|
return nameManager_.get();
|
|
|
|
}
|
2016-12-02 04:49:40 +03:00
|
|
|
|
2016-05-20 20:33:42 +03:00
|
|
|
const std::shared_ptr<Overlay>& getOverlay() const {
|
|
|
|
return overlay_;
|
|
|
|
}
|
|
|
|
|
2016-11-26 23:00:16 +03:00
|
|
|
Dirstate* getDirstate() {
|
|
|
|
return dirstate_.get();
|
|
|
|
}
|
|
|
|
|
2016-09-19 22:48:11 +03:00
|
|
|
folly::Synchronized<Journal>& getJournal() {
|
|
|
|
return journal_;
|
|
|
|
}
|
|
|
|
|
2016-09-19 22:48:14 +03:00
|
|
|
uint64_t getMountGeneration() const {
|
|
|
|
return mountGeneration_;
|
|
|
|
}
|
|
|
|
|
2016-12-02 04:49:30 +03:00
|
|
|
const ClientConfig* getConfig() const {
|
|
|
|
return config_.get();
|
|
|
|
}
|
|
|
|
|
2016-12-02 04:49:37 +03:00
|
|
|
/** Get the TreeInode for the root of the mount. */
|
2016-12-13 04:48:45 +03:00
|
|
|
TreeInodePtr getRootInode() const;
|
2016-12-02 04:49:37 +03:00
|
|
|
|
2016-10-21 23:30:20 +03:00
|
|
|
/** Convenience method for getting the Tree for the root of the mount. */
|
|
|
|
std::unique_ptr<Tree> getRootTree() const;
|
|
|
|
|
2016-12-02 04:49:34 +03:00
|
|
|
/**
|
|
|
|
* @return the InodeBase for the specified path or throws a std::system_error
|
|
|
|
* with ENOENT.
|
|
|
|
*/
|
2016-12-13 04:48:45 +03:00
|
|
|
InodePtr getInodeBase(RelativePathPiece path) const;
|
2016-12-02 04:49:34 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return the TreeInode for the specified path or throws a std::system_error
|
|
|
|
* with ENOENT or ENOTDIR, as appropriate.
|
|
|
|
*/
|
2016-12-13 04:48:45 +03:00
|
|
|
TreeInodePtr getTreeInode(RelativePathPiece path) const;
|
2016-12-02 04:49:34 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return the FileInode for the specified path or throws a std::system_error
|
|
|
|
* with ENOENT or EISDIR, as appropriate.
|
|
|
|
*/
|
2016-12-13 04:48:45 +03:00
|
|
|
FileInodePtr getFileInode(RelativePathPiece path) const;
|
2016-12-02 04:49:34 +03:00
|
|
|
|
2016-05-20 20:33:42 +03:00
|
|
|
private:
|
|
|
|
// Forbidden copy constructor and assignment operator
|
|
|
|
EdenMount(EdenMount const&) = delete;
|
|
|
|
EdenMount& operator=(EdenMount const&) = delete;
|
|
|
|
|
2016-12-02 04:49:30 +03:00
|
|
|
std::unique_ptr<ClientConfig> config_;
|
2016-12-02 04:49:42 +03:00
|
|
|
std::unique_ptr<EdenDispatcher> dispatcher_;
|
|
|
|
std::unique_ptr<fusell::InodeNameManager> nameManager_;
|
2016-12-02 04:49:30 +03:00
|
|
|
std::unique_ptr<fusell::MountPoint> mountPoint_;
|
2016-06-09 04:59:51 +03:00
|
|
|
std::unique_ptr<ObjectStore> objectStore_;
|
2016-05-20 20:33:42 +03:00
|
|
|
std::shared_ptr<Overlay> overlay_;
|
2016-11-26 23:00:16 +03:00
|
|
|
std::unique_ptr<Dirstate> dirstate_;
|
2016-09-13 04:27:54 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Note that this config will not be updated if the user modifies the
|
|
|
|
* underlying config files after the ClientConfig was created.
|
|
|
|
*/
|
2016-10-18 22:18:00 +03:00
|
|
|
const std::vector<BindMount> bindMounts_;
|
2016-09-19 22:48:11 +03:00
|
|
|
|
|
|
|
folly::Synchronized<Journal> journal_;
|
2016-09-19 22:48:14 +03:00
|
|
|
|
2016-12-02 04:49:34 +03:00
|
|
|
/**
|
2016-09-19 22:48:14 +03:00
|
|
|
* A number to uniquely identify this particular incarnation of this mount.
|
|
|
|
* We use bits from the process id and the time at which we were mounted.
|
|
|
|
*/
|
|
|
|
const uint64_t mountGeneration_;
|
2016-05-20 20:33:42 +03:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|