2021-02-09 23:45:00 +03:00
|
|
|
/*
|
2022-01-05 01:58:22 +03:00
|
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
2021-02-09 23:45:00 +03:00
|
|
|
*
|
|
|
|
* This software may be used and distributed according to the terms of the
|
|
|
|
* GNU General Public License version 2.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "eden/fs/nfs/NfsServer.h"
|
2021-06-29 19:44:22 +03:00
|
|
|
|
2021-03-29 19:19:29 +03:00
|
|
|
#include <folly/executors/thread_factory/NamedThreadFactory.h>
|
2021-02-09 23:45:00 +03:00
|
|
|
#include "eden/fs/nfs/Nfsd3.h"
|
2021-06-29 19:44:22 +03:00
|
|
|
#include "eden/fs/utils/EdenTaskQueue.h"
|
2021-02-09 23:45:00 +03:00
|
|
|
|
|
|
|
namespace facebook::eden {
|
|
|
|
|
2021-03-29 19:19:29 +03:00
|
|
|
NfsServer::NfsServer(
|
|
|
|
folly::EventBase* evb,
|
|
|
|
uint64_t numServicingThreads,
|
2022-03-25 01:20:43 +03:00
|
|
|
uint64_t maxInflightRequests,
|
2023-04-19 03:50:02 +03:00
|
|
|
bool shouldRunOurOwnRpcbindServer,
|
2022-03-25 01:20:43 +03:00
|
|
|
const std::shared_ptr<StructuredLogger>& structuredLogger)
|
2021-03-29 19:19:29 +03:00
|
|
|
: evb_(evb),
|
|
|
|
threadPool_(std::make_shared<folly::CPUThreadPoolExecutor>(
|
|
|
|
numServicingThreads,
|
2021-06-29 19:44:22 +03:00
|
|
|
std::make_unique<EdenTaskQueue>(maxInflightRequests),
|
2021-03-29 19:19:29 +03:00
|
|
|
std::make_unique<folly::NamedThreadFactory>("NfsThreadPool"))),
|
2023-04-19 03:50:02 +03:00
|
|
|
rpcbindd_(
|
|
|
|
shouldRunOurOwnRpcbindServer
|
|
|
|
? std::make_shared<Rpcbindd>(evb_, threadPool_, structuredLogger)
|
|
|
|
: nullptr),
|
2022-03-25 01:20:43 +03:00
|
|
|
mountd_(evb_, threadPool_, structuredLogger) {}
|
2021-05-12 23:05:50 +03:00
|
|
|
|
|
|
|
void NfsServer::initialize(
|
|
|
|
folly::SocketAddress addr,
|
|
|
|
bool registerMountdWithRpcbind) {
|
|
|
|
mountd_.initialize(addr, registerMountdWithRpcbind);
|
2023-04-19 03:50:02 +03:00
|
|
|
if (rpcbindd_) {
|
|
|
|
rpcbindd_->initialize();
|
|
|
|
}
|
2023-04-19 03:50:02 +03:00
|
|
|
recordPortNumber(
|
|
|
|
mountd_.getProgramNumber(),
|
|
|
|
mountd_.getProgramVersion(),
|
|
|
|
mountd_.getAddr().getPort());
|
2021-05-12 23:05:50 +03:00
|
|
|
}
|
2021-03-29 19:19:29 +03:00
|
|
|
|
2021-11-18 04:09:58 +03:00
|
|
|
void NfsServer::initialize(folly::File&& socket) {
|
|
|
|
mountd_.initialize(std::move(socket));
|
2023-04-19 03:50:02 +03:00
|
|
|
if (rpcbindd_) {
|
|
|
|
rpcbindd_->initialize();
|
|
|
|
}
|
2023-04-19 03:50:02 +03:00
|
|
|
// TODO: we should register the mountd server on takeover too. but
|
|
|
|
// we only transfer the connected socket not the listening socket.
|
|
|
|
// the listening one is the one we wanna register. So we need to
|
|
|
|
// transfer that socket to be able to register it.
|
2021-11-18 04:09:58 +03:00
|
|
|
}
|
|
|
|
|
2021-02-09 23:45:00 +03:00
|
|
|
NfsServer::NfsMountInfo NfsServer::registerMount(
|
|
|
|
AbsolutePathPiece path,
|
2021-02-09 23:45:00 +03:00
|
|
|
InodeNumber rootIno,
|
2021-02-18 10:29:21 +03:00
|
|
|
std::unique_ptr<NfsDispatcher> dispatcher,
|
2021-02-09 23:45:00 +03:00
|
|
|
const folly::Logger* straceLogger,
|
|
|
|
std::shared_ptr<ProcessNameCache> processNameCache,
|
2021-09-10 02:28:29 +03:00
|
|
|
std::shared_ptr<FsEventLogger> fsEventLogger,
|
2022-03-25 01:20:43 +03:00
|
|
|
const std::shared_ptr<StructuredLogger>& structuredLogger,
|
2021-02-09 23:45:00 +03:00
|
|
|
folly::Duration requestTimeout,
|
2022-03-02 04:52:58 +03:00
|
|
|
std::shared_ptr<Notifier> notifier,
|
2021-04-20 23:07:31 +03:00
|
|
|
CaseSensitivity caseSensitive,
|
2022-11-03 07:02:48 +03:00
|
|
|
uint32_t iosize,
|
|
|
|
size_t traceBusCapacity) {
|
2021-02-09 23:45:00 +03:00
|
|
|
auto nfsd = std::make_unique<Nfsd3>(
|
|
|
|
evb_,
|
2021-03-29 19:19:29 +03:00
|
|
|
threadPool_,
|
2021-02-18 10:29:21 +03:00
|
|
|
std::move(dispatcher),
|
2021-02-09 23:45:00 +03:00
|
|
|
straceLogger,
|
|
|
|
std::move(processNameCache),
|
2021-09-10 02:28:29 +03:00
|
|
|
std::move(fsEventLogger),
|
2022-03-25 01:20:43 +03:00
|
|
|
structuredLogger,
|
2021-02-09 23:45:00 +03:00
|
|
|
requestTimeout,
|
2022-03-02 04:52:58 +03:00
|
|
|
std::move(notifier),
|
2021-04-07 00:16:09 +03:00
|
|
|
caseSensitive,
|
2022-11-03 07:02:48 +03:00
|
|
|
iosize,
|
|
|
|
traceBusCapacity);
|
2021-02-09 23:45:00 +03:00
|
|
|
mountd_.registerMount(path, rootIno);
|
|
|
|
|
2021-05-12 23:05:50 +03:00
|
|
|
return {std::move(nfsd), mountd_.getAddr()};
|
2021-02-09 23:45:00 +03:00
|
|
|
}
|
|
|
|
|
2023-04-19 03:50:02 +03:00
|
|
|
/**
|
|
|
|
* Registers an RPC service running a certain protocol version on port.
|
|
|
|
*/
|
|
|
|
void NfsServer::recordPortNumber(
|
|
|
|
uint32_t protocol,
|
|
|
|
uint32_t version,
|
|
|
|
uint32_t port) {
|
|
|
|
if (rpcbindd_) {
|
|
|
|
rpcbindd_->recordPortNumber(protocol, version, port);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-09 23:45:00 +03:00
|
|
|
void NfsServer::unregisterMount(AbsolutePathPiece path) {
|
|
|
|
mountd_.unregisterMount(path);
|
|
|
|
}
|
|
|
|
|
2021-11-18 04:09:58 +03:00
|
|
|
folly::SemiFuture<folly::File> NfsServer::takeoverStop() {
|
|
|
|
return mountd_.takeoverStop();
|
|
|
|
}
|
|
|
|
|
2021-02-09 23:45:00 +03:00
|
|
|
} // namespace facebook::eden
|