mirror of
https://github.com/facebook/sapling.git
synced 2024-10-09 16:31:02 +03:00
91336a090e
Summary: This will be the main entry point for everything related to the various NFS programs. For now, it simply starts an nfsd program when registering a new mount point and returns the ports that mount(2) should use to connect to it. Reviewed By: kmancini Differential Revision: D26204060 fbshipit-source-id: 115d2d206109499d5b49c529ebf1f739fc364c23
178 lines
4.5 KiB
C++
178 lines
4.5 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/ThreadLocal.h>
|
|
#include <chrono>
|
|
#include <memory>
|
|
|
|
#include "eden/fs/config/CachedParsedFileMonitor.h"
|
|
#include "eden/fs/config/ReloadableConfig.h"
|
|
#include "eden/fs/fuse/privhelper/PrivHelper.h"
|
|
#include "eden/fs/model/git/GitIgnoreFileParser.h"
|
|
#include "eden/fs/notifications/Notifications.h"
|
|
#include "eden/fs/telemetry/EdenStats.h"
|
|
#include "eden/fs/utils/PathFuncs.h"
|
|
#include "eden/fs/utils/UserInfo.h"
|
|
|
|
namespace facebook {
|
|
namespace eden {
|
|
|
|
class Clock;
|
|
class EdenConfig;
|
|
class FaultInjector;
|
|
class ProcessNameCache;
|
|
class StructuredLogger;
|
|
class TopLevelIgnores;
|
|
class UnboundedQueueExecutor;
|
|
class NfsServer;
|
|
|
|
/**
|
|
* ServerState contains state shared across multiple mounts.
|
|
*
|
|
* This is normally owned by the main EdenServer object. However unit tests
|
|
* also create ServerState objects without an EdenServer.
|
|
*/
|
|
class ServerState {
|
|
public:
|
|
ServerState(
|
|
UserInfo userInfo,
|
|
std::shared_ptr<PrivHelper> privHelper,
|
|
std::shared_ptr<UnboundedQueueExecutor> threadPool,
|
|
std::shared_ptr<Clock> clock,
|
|
std::shared_ptr<ProcessNameCache> processNameCache,
|
|
std::shared_ptr<StructuredLogger> structuredLogger,
|
|
std::shared_ptr<const EdenConfig> edenConfig,
|
|
std::shared_ptr<NfsServer> nfs,
|
|
bool enableFaultInjection = false);
|
|
~ServerState();
|
|
|
|
/**
|
|
* Set the path to the server's thrift socket.
|
|
*
|
|
* This is called by EdenServer once it has initialized the thrift server.
|
|
*/
|
|
void setSocketPath(AbsolutePathPiece path) {
|
|
socketPath_ = path.copy();
|
|
}
|
|
|
|
/**
|
|
* Get the path to the server's thrift socket.
|
|
*
|
|
* This is used by the EdenMount to populate the `.eden/socket` special file.
|
|
*/
|
|
const AbsolutePath& getSocketPath() const {
|
|
return socketPath_;
|
|
}
|
|
|
|
/**
|
|
* Get the EdenStats object that tracks process-wide (rather than per-mount)
|
|
* statistics.
|
|
*/
|
|
EdenStats& getStats() {
|
|
return edenStats_;
|
|
}
|
|
|
|
ReloadableConfig& getReloadableConfig() {
|
|
return config_;
|
|
}
|
|
const ReloadableConfig& getReloadableConfig() const {
|
|
return config_;
|
|
}
|
|
|
|
/**
|
|
* Get the EdenConfig data.
|
|
*
|
|
* The config data may be reloaded from disk depending on the value of the
|
|
* reload parameter.
|
|
*/
|
|
std::shared_ptr<const EdenConfig> getEdenConfig(
|
|
ConfigReloadBehavior reload = ConfigReloadBehavior::AutoReload) {
|
|
return config_.getEdenConfig(reload);
|
|
}
|
|
|
|
/**
|
|
* Get the TopLevelIgnores. It is based on the system and user git ignore
|
|
* files.
|
|
*/
|
|
std::unique_ptr<TopLevelIgnores> getTopLevelIgnores();
|
|
|
|
/**
|
|
* Get the UserInfo object describing the user running this edenfs process.
|
|
*/
|
|
const UserInfo& getUserInfo() const {
|
|
return userInfo_;
|
|
}
|
|
|
|
/**
|
|
* Get the PrivHelper object used to perform operations that require
|
|
* elevated privileges.
|
|
*/
|
|
PrivHelper* getPrivHelper() {
|
|
return privHelper_.get();
|
|
}
|
|
|
|
/**
|
|
* Get the thread pool.
|
|
*
|
|
* Adding new tasks to this thread pool executor will never block.
|
|
*/
|
|
const std::shared_ptr<UnboundedQueueExecutor>& getThreadPool() const {
|
|
return threadPool_;
|
|
}
|
|
|
|
/**
|
|
* Get the Clock.
|
|
*/
|
|
const std::shared_ptr<Clock>& getClock() const {
|
|
return clock_;
|
|
}
|
|
|
|
const std::shared_ptr<NfsServer>& getNfsServer() const& {
|
|
XDCHECK(nfs_);
|
|
return nfs_;
|
|
}
|
|
|
|
const std::shared_ptr<ProcessNameCache>& getProcessNameCache() const {
|
|
return processNameCache_;
|
|
}
|
|
|
|
const std::shared_ptr<StructuredLogger>& getStructuredLogger() const {
|
|
return structuredLogger_;
|
|
}
|
|
|
|
FaultInjector& getFaultInjector() {
|
|
return *faultInjector_;
|
|
}
|
|
|
|
Notifications* getNotifications() {
|
|
return ¬ifications_;
|
|
}
|
|
|
|
private:
|
|
AbsolutePath socketPath_;
|
|
UserInfo userInfo_;
|
|
EdenStats edenStats_;
|
|
std::shared_ptr<PrivHelper> privHelper_;
|
|
std::shared_ptr<UnboundedQueueExecutor> threadPool_;
|
|
std::shared_ptr<Clock> clock_;
|
|
std::shared_ptr<ProcessNameCache> processNameCache_;
|
|
std::shared_ptr<StructuredLogger> structuredLogger_;
|
|
std::unique_ptr<FaultInjector> const faultInjector_;
|
|
std::shared_ptr<NfsServer> nfs_;
|
|
|
|
ReloadableConfig config_;
|
|
folly::Synchronized<CachedParsedFileMonitor<GitIgnoreFileParser>>
|
|
userIgnoreFileMonitor_;
|
|
folly::Synchronized<CachedParsedFileMonitor<GitIgnoreFileParser>>
|
|
systemIgnoreFileMonitor_;
|
|
Notifications notifications_;
|
|
};
|
|
} // namespace eden
|
|
} // namespace facebook
|