sapling/eden/fs/inodes/EdenMount.h
Adam Simpkins aaa3332644 simplify EdenMount and Dirstate construction
Summary:
This cleans up construction of the EdenMount and Dirstate objects:

- The EdenMount constructor is now responsible for creating the Overlay and
  Dirstate objects.
- The Dirstate constructor is now responsible for loading the
  DirstatePersistence file.
- The EdenMount now takes ownership of the ClientConfig object, and stores it
  for later use.
- The ClientConfig object now has a method to get the path to the
  DirstatePersistence file.
- I added a ClientConfig::createTestConfig() method, so that the TestMount code
  can now use the same EdenMount constructor as the normal code.

This simplifies the logic in EdenServiceHandler and TestMount, and makes some
of the initialization dependencies a little bit simpler.

This change is necessary in order for me to move some logic from
fusell::MountPoint into EdenMount.  The Dirstate object will need a pointer
back to its EdenMount object, and this diff enables that.

Reviewed By: bolinfest

Differential Revision: D4249393

fbshipit-source-id: 439786accbf48c8696dbc6ca4fe77a4c6bdeab65
2016-12-01 17:52:30 -08:00

130 lines
3.3 KiB
C++

/*
* 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
#include <folly/Synchronized.h>
#include <memory>
#include "eden/fs/journal/JournalDelta.h"
#include "eden/utils/PathFuncs.h"
namespace facebook {
namespace eden {
namespace fusell {
class MountPoint;
}
class BindMount;
class ClientConfig;
class Dirstate;
class ObjectStore;
class Overlay;
class Journal;
class Tree;
/*
* 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.
* - The ObjectStore object used for retreiving/storing object data.
* - The Overlay object used for storing local changes (that have not been
* committed/snapshotted yet).
*/
class EdenMount {
public:
EdenMount(
std::unique_ptr<ClientConfig> config,
std::unique_ptr<ObjectStore> objectStore);
virtual ~EdenMount();
/*
* 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();
}
/*
* Return the path to the mount point.
*/
const AbsolutePath& getPath() const;
/*
* 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;
/*
* 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();
}
const std::shared_ptr<Overlay>& getOverlay() const {
return overlay_;
}
Dirstate* getDirstate() {
return dirstate_.get();
}
folly::Synchronized<Journal>& getJournal() {
return journal_;
}
uint64_t getMountGeneration() const {
return mountGeneration_;
}
const ClientConfig* getConfig() const {
return config_.get();
}
/** Convenience method for getting the Tree for the root of the mount. */
std::unique_ptr<Tree> getRootTree() const;
private:
// Forbidden copy constructor and assignment operator
EdenMount(EdenMount const&) = delete;
EdenMount& operator=(EdenMount const&) = delete;
std::unique_ptr<ClientConfig> config_;
std::unique_ptr<fusell::MountPoint> mountPoint_;
std::unique_ptr<ObjectStore> objectStore_;
std::shared_ptr<Overlay> overlay_;
std::unique_ptr<Dirstate> dirstate_;
/*
* Note that this config will not be updated if the user modifies the
* underlying config files after the ClientConfig was created.
*/
const std::vector<BindMount> bindMounts_;
folly::Synchronized<Journal> journal_;
/*
* 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_;
};
}
}