sapling/eden/fs/nfs/Mountd.h
Katie Mancini 84057e7171 make parsing errors non fatal and log them
Summary:
If an NFS client sends us an improperly formatted request, EdenFS crashes.
This is dangerous because any process on the machine could send us an NFS
request and this could crash eden.

Eden should be resilient to badly formatted requests/requests it fails to
parse.

This will make debugging failed requests harder as errors will be less
obvious to the user, but it will also allow users to keep using their mount
after a failed request.

Reviewed By: xavierd

Differential Revision: D34981438

fbshipit-source-id: 107de2324b1dc145bd426398614ee76b72c5c446
2022-03-24 15:20:43 -07:00

91 lines
2.5 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.
*/
#pragma once
#ifndef _WIN32
// Implementation of the mount protocol as described in:
// https://tools.ietf.org/html/rfc1813#page-106
#include "eden/fs/inodes/InodeNumber.h"
#include "eden/fs/nfs/rpc/Server.h"
#include "eden/fs/utils/PathFuncs.h"
namespace folly {
class Executor;
}
namespace facebook::eden {
class MountdServerProcessor;
class Mountd {
public:
/**
* Create a new RPC mountd program.
*
* All the socket processing will be run on the EventBase passed in. This
* also must be called on that EventBase thread.
*
* Note: at mount time, EdenFS will manually call mount.nfs with -o mountport
* to manually specify the port on which this server is bound, so registering
* is not necessary for a properly behaving EdenFS.
*/
Mountd(
folly::EventBase* evb,
std::shared_ptr<folly::Executor> threadPool,
const std::shared_ptr<StructuredLogger>& structuredLogger);
/**
* Bind the RPC mountd program to the passed in address.
*
* If registerWithRpcbind is set, this mountd program will advertise itself
* against the rpcbind daemon allowing it to be visible system wide. Be aware
* that for a given transport (tcp/udp) only one mountd program can be
* registered with rpcbind, and thus if a real NFS server is running on this
* host, EdenFS won't be able to register itself.
*/
void initialize(folly::SocketAddress addr, bool registerWithRpcbind);
void initialize(folly::File&& socket);
/**
* Register a path as the root of a mount point.
*
* Once registered, the mount RPC request for that specific path will answer
* positively with the passed in InodeNumber.
*/
void registerMount(AbsolutePathPiece path, InodeNumber rootIno);
/**
* Unregister the mount point matching the path.
*/
void unregisterMount(AbsolutePathPiece path);
/**
* Obtain the address that this mountd program is listening on.
*/
folly::SocketAddress getAddr() const {
return server_->getAddr();
}
folly::SemiFuture<folly::File> takeoverStop();
Mountd(const Mountd&) = delete;
Mountd(Mountd&&) = delete;
Mountd& operator=(const Mountd&) = delete;
Mountd& operator=(Mountd&&) = delete;
private:
std::shared_ptr<MountdServerProcessor> proc_;
std::shared_ptr<RpcServer> server_;
};
} // namespace facebook::eden
#endif