sapling/eden/fs/inodes/ServerState.h
Xavier Deguillard fdbedc4818 nfs: allow mountd and nfsd sockets to be non-inet on macOS
Summary:
macOS supports NFS servers that can be reached via a unix socket as a way to
improve performance by reducing the TCP cost. To support this, let's first
allow the socket to bind to to be passed to the RpcServer, and then pass it
through to the privhelper code.

Reviewed By: kmancini

Differential Revision: D28261423

fbshipit-source-id: 78c60aac26353d1da76a67897429b964332df8b3
2021-05-12 13:06:57 -07:00

177 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& {
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 &notifications_;
}
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