sapling/eden/fs/nfs/NfsServer.cpp
Katie Mancini d9737647bc register rpc servers with port mapper
Summary:
Now that we have the plumbing we can start registering our NFS RPC servers (
mountd and nfsd) with the portmapper/rpcbind.

I am taing a short cut for prototyping. I am skipping general purpose
rpc registration (i.e. making these rpc calls to register a service). This is
because (1) I am trying to prototype quickly, so I don't want to implement the
portmapper endpoints that allow registering/ unregistering a server and (2)
there are maybe security considerations, and I don't want to think about those
rn.

Reviewed By: chadaustin

Differential Revision: D44987884

fbshipit-source-id: 4b849d1dd060d2e033ab48df883e228015906a7d
2023-04-18 17:50:02 -07:00

109 lines
3.1 KiB
C++

/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* 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"
#include <folly/executors/thread_factory/NamedThreadFactory.h>
#include "eden/fs/nfs/Nfsd3.h"
#include "eden/fs/utils/EdenTaskQueue.h"
namespace facebook::eden {
NfsServer::NfsServer(
folly::EventBase* evb,
uint64_t numServicingThreads,
uint64_t maxInflightRequests,
bool shouldRunOurOwnRpcbindServer,
const std::shared_ptr<StructuredLogger>& structuredLogger)
: evb_(evb),
threadPool_(std::make_shared<folly::CPUThreadPoolExecutor>(
numServicingThreads,
std::make_unique<EdenTaskQueue>(maxInflightRequests),
std::make_unique<folly::NamedThreadFactory>("NfsThreadPool"))),
rpcbindd_(
shouldRunOurOwnRpcbindServer
? std::make_shared<Rpcbindd>(evb_, threadPool_, structuredLogger)
: nullptr),
mountd_(evb_, threadPool_, structuredLogger) {}
void NfsServer::initialize(
folly::SocketAddress addr,
bool registerMountdWithRpcbind) {
mountd_.initialize(addr, registerMountdWithRpcbind);
if (rpcbindd_) {
rpcbindd_->initialize();
}
recordPortNumber(
mountd_.getProgramNumber(),
mountd_.getProgramVersion(),
mountd_.getAddr().getPort());
}
void NfsServer::initialize(folly::File&& socket) {
mountd_.initialize(std::move(socket));
if (rpcbindd_) {
rpcbindd_->initialize();
}
// 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.
}
NfsServer::NfsMountInfo NfsServer::registerMount(
AbsolutePathPiece path,
InodeNumber rootIno,
std::unique_ptr<NfsDispatcher> dispatcher,
const folly::Logger* straceLogger,
std::shared_ptr<ProcessNameCache> processNameCache,
std::shared_ptr<FsEventLogger> fsEventLogger,
const std::shared_ptr<StructuredLogger>& structuredLogger,
folly::Duration requestTimeout,
std::shared_ptr<Notifier> notifier,
CaseSensitivity caseSensitive,
uint32_t iosize,
size_t traceBusCapacity) {
auto nfsd = std::make_unique<Nfsd3>(
evb_,
threadPool_,
std::move(dispatcher),
straceLogger,
std::move(processNameCache),
std::move(fsEventLogger),
structuredLogger,
requestTimeout,
std::move(notifier),
caseSensitive,
iosize,
traceBusCapacity);
mountd_.registerMount(path, rootIno);
return {std::move(nfsd), mountd_.getAddr()};
}
/**
* 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);
}
}
void NfsServer::unregisterMount(AbsolutePathPiece path) {
mountd_.unregisterMount(path);
}
folly::SemiFuture<folly::File> NfsServer::takeoverStop() {
return mountd_.takeoverStop();
}
} // namespace facebook::eden