Commit Graph

118 Commits

Author SHA1 Message Date
Zhengchao Liu
06b507912f add inode number to NFS trace event
Summary: This adds inode number to NFS trace event so that we can use it in ActivityRecorder to show the filename of the FS request.

Reviewed By: xavierd

Differential Revision: D30849770

fbshipit-source-id: 580faf5fccb1a225399d9aec843e23eae1874e87
2021-09-14 10:44:46 -07:00
Zhengchao Liu
601f99b118 support FS events logging in NFS mounts
Summary: This adds the support for FS events logging for NFS. For context, each type of event is assigned a sampling group that determines its sampling rate. In TraceBus subscription callback, events are sent to `FsEventLogger` to be sampled and logged through `HiveLogger`.

Reviewed By: xavierd

Differential Revision: D30843863

fbshipit-source-id: 65394d31b1197efd69c7fd4c1b24562f5abd5785
2021-09-09 16:29:53 -07:00
Zhengchao Liu
b51e5d07f8 introduce NfsRequsetContext
Summary: As title. `RequsetContext` allows us to track metrics such as latency and count.

Reviewed By: genevievehelsel

Differential Revision: D29835813

fbshipit-source-id: 6b85fc8f11923f530fce6d871fa2253db21bfa98
2021-07-26 16:04:03 -07:00
Zhengchao Liu
d8b2d58e84 categorize NFS handlers by AccessType
Summary: We already have AccessType for FUSE, this adds the same categorization for NFS. This allows us to easily filter events in trace stream and ActivityRecorder.

Reviewed By: chadaustin

Differential Revision: D29771074

fbshipit-source-id: a437f0693f9062fb2df3b6f618a9d8860a05df12
2021-07-19 19:10:48 -07:00
Zhengchao Liu
17ada866bb add edenfsctl trace fs support for nfs
Summary: This diff connects the trace bus with trace fs command.

Reviewed By: chadaustin

Differential Revision: D29367135

fbshipit-source-id: f9217b286c1a21805d70b21282c10d4ad722a391
2021-06-29 17:50:25 -07:00
Zhengchao Liu
d8abf544d2 add handle to publish finish event when exception thrown
Summary: If the handler throws without returning a future, the finish event will not be published. This diff adds the `LiveRequest` to publish finish event in its destructor.

Reviewed By: chadaustin

Differential Revision: D29332452

fbshipit-source-id: 880a4b67ba47b737063a3955c9f4bdbf605f1a43
2021-06-29 17:50:25 -07:00
Zhengchao Liu
d54083bd53 add tracing for nfs
Summary:
This diff adds tracking for nfs, based on the implementation of that of `FuseChannel`.
Also commented below few questions on the implementation before working on integrating to `strace`.

Reviewed By: chadaustin

Differential Revision: D29279126

fbshipit-source-id: de6bb36dfbe2f550a91f2bf254616bbc639c0c3d
2021-06-29 17:50:25 -07:00
Genevieve Helsel
9b4909d022 create util EdenTaskQueue from NfsTaskQueue
Summary: NfsTaskQueue can be made more generic to be shared across the codebase, so this makes it its own target in `eden/fs/utils` w/ the name EdenTaskQueue.

Reviewed By: xavierd

Differential Revision: D29244762

fbshipit-source-id: 78348f2ff8fa66bc801aefe7d6b3905e0da278e8
2021-06-29 09:45:46 -07:00
Katie Mancini
1c31dbb822 allow remount after force unmounting
Summary:
Previously if you `sudo umount -f fbsource-nfs` then try to
`eden mount fbsource-nfs`, the mount will fail because the EdenMount already
exists and is still running.

Let's properly unmount our selfs on a force unmount like we do for fuse.
There are two potential ways to detect a fource unmount: the UMNT call to the
mount deamon or the socket to the nfsd closing. The UMNT call is unreliable
(on Linux we do not get the UNMT call on `umount -l`), so this diff pursues the
socket closing option.

When the nfsd socket is closed we trigger the EdenMount unmounting process if
this has not already started.

Reviewed By: xavierd

Differential Revision: D28329482

fbshipit-source-id: 5df8f3eb818a92536095195f1b3a9e412394fbf6
2021-05-27 16:11:50 -07:00
Xavier Deguillard
f7c66f9786 nfs: fix non-UTF8 name handling
Summary:
For non-UTF8 names, the PathComponent constructor would raise an exception, and
since that exception wasn't caught by the handler itself, it would bubble up to
the RPC server and a generic "server IO error" would be sent back to the
client. Since non-UTF8 names aren't a server error, but an invalid argument, we
should instead return a different error.

Unfortunately, EILSEQ isn't an error that an NFS server can return, instead
let's use EINVAL as the argument is clearly invalid.

Reviewed By: chadaustin

Differential Revision: D28482032

fbshipit-source-id: b59044f1a76f7eac79e2df07356a0aeafa22e3c5
2021-05-26 14:05:48 -07:00
Xavier Deguillard
d324a26672 nfs: fix permissions
Summary:
The modeToNfsMode simply didn't consider all the mode bits to be translated to
the proper NFS mode bits. It now does.

Reviewed By: chadaustin

Differential Revision: D28459428

fbshipit-source-id: d879fb1be2085e44110ba552bc47d2770637fc86
2021-05-26 14:05:48 -07:00
Xavier Deguillard
8391057f7d nfs: open files to do invalidation
Summary:
An NFS client caches the attributes of files to avoid having to request these
very frequently. What this means is that a file changed by another client (or
by the server itself) may take some time to be reflected on the client, that
time depends on the attribute caching configuration of the mount point.

For EdenFS, files can changed in 2 ways:
 - Either it is changed by the user via the mount point,
 - Or the user runs an `hg update`

For the first one, the client will simply update its attributes appropriately,
but for the second one, the cached attributes will only be updated when the
user does opens the file, any calls to stat prior will return the old
attributes. Since EdenFS runs on the same host, we can force the attributes
caches to be discarded by simply issuing an open call on the file that changed.

Reviewed By: chadaustin

Differential Revision: D28456482

fbshipit-source-id: 91022d35a33e436c47d94403d0c139992f880cf9
2021-05-26 14:05:48 -07:00
Xavier Deguillard
9621d533f4 nfs: use makeImmediateFutureWith instead of a manual version of it
Summary:
Now that makeImmediateFutureWith exists, we can simply use it instead of
constructing a ImmediateFuture<folly::Unit> and calling thenValue on it.

Reviewed By: chadaustin

Differential Revision: D28518059

fbshipit-source-id: 0041cf863fb32efab274f11c77c76109ca9b454f
2021-05-25 15:16:59 -07:00
Xavier Deguillard
b525114769 nfs: switch RpcServerProcessor::dispatchRpc to ImmediateFuture
Summary:
Now that both implementation are using ImmediateFuture, we can move the
ImmediateFuture one layer up.

Reviewed By: kmancini

Differential Revision: D28302479

fbshipit-source-id: 3c2c164a90ffb42a0e7da8528f976af34fc87315
2021-05-13 16:51:34 -07:00
Xavier Deguillard
65d00fff9f nfs: convert Nfsd3 to ImmediateFuture
Summary:
With the Mountd code being converted to ImmediateFuture, we can now convert
Nfsd3 to use ImmediateFuture too. For now, this isn't expected to perform
better due to the InodeMap still using on folly::Future, which forces the
ImmediateFuture code to store a SemiFuture. A future change will look at
switching the InodeMap to ImmediateFuture to solve this.

Reviewed By: kmancini

Differential Revision: D28297422

fbshipit-source-id: 8b85103657e877b0f102130f2117bbe60598ed52
2021-05-13 16:51:34 -07:00
Xavier Deguillard
472e67081c nfs: convert Mountd to use ImmediateFuture
Summary:
As a first towards converting the code to use ImmediateFuture more broadly,
let's start with a small self contained part of the code.

This is mostly a sed except for the dispatchRpc method that needs to call
.semi().via().

Reviewed By: kmancini

Differential Revision: D28297421

fbshipit-source-id: e706e91fc8f132d4ef742ae98af9bb8304e0bf36
2021-05-13 16:51:34 -07:00
Katie Mancini
85942cfaad use portable version of gtest
Summary:
gtest includes some windows headers that will have conflicts with the
folly portability versions. This caused some issues in my in-memory tree
cache diffs (D27050310 (8a1a529fcc)).

We should probably generally be using the folly portable gtests so we can
avoid such issues in the future.

see here for more details: bd600cd4e8/folly/portability/GTest.h (L19)

I ran this with codemod yes to all

- convert all the includes with quotes:
`codemod -d eden/fs --extensions cpp,h '\#include\ "gtest/gtest\.h"' '#include <folly/portability/GTest.h>'`

- convert all the includes with brackets
`codemod -d eden/fs --extensions cpp,h '\#include\ <gtest/gtest\.h>' '#include <folly/portability/GTest.h>'`

- convert the test template
`codemod -d eden/facebook --extensions template '\#include\ <gtest/gtest\.h>' '#include <folly/portability/GTest.h>'`

then used `arc lint` to clean up all the targets files

Reviewed By: genevievehelsel, xavierd

Differential Revision: D28035146

fbshipit-source-id: c3b88df5d4e7cdf4d1e51d9689987ce039f47fde
2021-05-12 15:58:27 -07:00
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
Xavier Deguillard
42b17dfa1c nfs: add to Executor directly without creating a future
Summary:
folly::via is a Future API, and thus it creates one, which requires allocating
it and then attaching it to the Executore. Since the code to dispatch a request
isn't Future based, we don't need to use folly::via, and we can simply add the
lambda to the Executor directly. This removes expensive memory allocations from
the EventBase.

Reviewed By: kmancini

Differential Revision: D27976674

fbshipit-source-id: 8fa9724a94ba69b071ab894cdbbad0d33733c098
2021-04-28 17:06:23 -07:00
Xavier Deguillard
72b4096a06 nfs: remove multi-fragment O(N^2) complexity
Summary:
Neither macOS, nor Linux are sending multi-fragment requests to the NFS server.
Since supporting these means calling into memmove, which can be expensive for
large requests, let's just remove support for them for now. If somehow macOS
and/or Linux start sending these, the XCHECK(isLast) will catch this and we can
fix the code by then.

Reviewed By: kmancini

Differential Revision: D27976671

fbshipit-source-id: 77c758b2bb36517d22d5b637e6f0ebf84cc19e5b
2021-04-28 17:06:23 -07:00
Xavier Deguillard
32ee50d702 nfs: move some code out of the event base
Summary:
The EventBase is single threaded, and for heavily concurrent client workflows,
it could see a lot activity, thus every cycle saved can be used to drive more
client requests. The construction of the IOBuf doesn't need to be done while in
the EventBase, thus let's build it outside.

Reviewed By: kmancini

Differential Revision: D27976670

fbshipit-source-id: c6c015ef26df1dcb3fc0c5f179e474bafbd71fac
2021-04-28 17:06:23 -07:00
Xavier Deguillard
04ba04fe88 nfs: bump buffer preallocation size
Summary:
Passing 64 to preallocate means that the AsyncSocket code will issue reads of
64 bytes, even though the IOBufQueue has significantly more space available. We
can thus pass a bigger size to preallocate to reduce both the cost of
allocation, and the syscall cost. For heavily concurrent client code, this will
allow us to read more than one request per syscall.

The careful reader may have noticed that for very small requests the code may
reallocate more often that it should as it will always reallocate when falling
under 4KB. This is likely to not be an issue in practice.

Reviewed By: kmancini

Differential Revision: D27976672

fbshipit-source-id: 4c7e3aecc4763ab20854f3c466ce0872332f9b77
2021-04-28 17:06:23 -07:00
Xavier Deguillard
4daf57cab6 nfs: various cleanup of Server.cpp
Summary:
These are various cleanups that should make the code easier to read, there is
no behavior changes.

Reviewed By: kmancini

Differential Revision: D27976673

fbshipit-source-id: 470eb628ca75bf1712a93c6e9aa3a27c3f314d01
2021-04-28 17:06:23 -07:00
Zeyi (Rice) Fan
a3d912f2cd utils: introduce CaseSensitivity
Summary: `CaseSensitivity::Sensitive` is better than a mere `true` out of nowhere.

Reviewed By: kmancini

Differential Revision: D27867180

fbshipit-source-id: 39d21d3cc3b70c78c6984c3ddbd65b53520770be
2021-04-20 13:08:27 -07:00
Andrii Grynenko
e1dc359365 Move ReleasableDestructor into HeaderClientChannel
Summary: Since HeaderClientChannel now accepts a transport unique_ptr there's no need to have this deleter exposed outside of HeaderClientChannel.

Reviewed By: iahs

Differential Revision: D27729209

fbshipit-source-id: 064b03afdfe567b6df6437348596f0f6f97f6aaf
2021-04-13 23:35:41 -07:00
Xavier Deguillard
f462a76f80 nfs: implement the MKNOD procedure
Summary:
This allows unix sockets to be created in the mount. This will allow Buck to
run properly as it tries to create sockets in the repository.

Reviewed By: kmancini

Differential Revision: D27690406

fbshipit-source-id: 5725d68bdda12f3a5882ce48b6bdd02b14cdece4
2021-04-13 15:17:35 -07:00
Xavier Deguillard
dbc51feb5e nfs: add RPC types for MKNOD
Summary: This merely adds the types for the procedure

Reviewed By: kmancini

Differential Revision: D27690405

fbshipit-source-id: b94fb03658cabaece4166c29135c5fdf9a613d3c
2021-04-13 14:59:58 -07:00
Xavier Deguillard
6836229ab3 nfs: implement RMDIR procedure
Summary:
This is roughly the same logic as the UNLINK one with the only difference being
in the handling of "." and "..".

Reviewed By: kmancini

Differential Revision: D27684716

fbshipit-source-id: 86a95c38e6c783bc3a45c0a8b000d0210b6dd0b8
2021-04-13 14:59:57 -07:00
Xavier Deguillard
dbe993312d nfs: add RPC for RMDIR
Summary:
This merely adds the types needed for the RMDIR procedure. Implementation will
follow.

Reviewed By: genevievehelsel

Differential Revision: D27684736

fbshipit-source-id: 84f5a4f3dc805e7893853b0de1dc19cb01c1319f
2021-04-13 14:59:57 -07:00
Xavier Deguillard
62056fb8ea nfs: fix typo in fsstat
Summary:
To get the size in bytes, we need to multiply the quantity with the block size,
not with itself.

Reviewed By: genevievehelsel

Differential Revision: D27690857

fbshipit-source-id: 7d7ca767881b1118fc24befed230a63f342bc911
2021-04-13 14:59:57 -07:00
Xavier Deguillard
24e3919dea privhelper: allow mounting via NFS on macOS
Summary:
On macOS, the mount syscall for NFS expects the arguments to be XDR encoded.
This set of argument roughly match with its Linux counterpart and appears to
start the mount process. It fails early on when trying to access the .hg
directory but this is probably an issue with the NFS server code, not of the
mounting code.

Reviewed By: kmancini

Differential Revision: D27306769

fbshipit-source-id: 697fadfddc4048ef56c3a23f75dd5bdbcc92af1b
2021-04-06 14:17:00 -07:00
Xavier Deguillard
c0e3d78468 nfs: allow serializing std::optional
Summary:
Non-list optional data can be present in some XDR description, let's special
case it so the intent is clear when declaring XDR datastructures.

Reviewed By: fanzeyi

Differential Revision: D27306768

fbshipit-source-id: 9d4d18bf8deff16f859c6d28a2579341dac8ee6f
2021-03-29 09:20:33 -07:00
Xavier Deguillard
53700635c1 nfs: when receiving a packet iterate over all the fragments
Summary:
After receiving a network packet, it's possible that more than one fragment
were received as part of it. We thus need to service all of them before
returning.

This would typically be seen when running `rg` in the repository, which would
cause hangs due to some requests not being serviced as they would stay in the
iobuf queue until a new packet was received.

Reviewed By: kmancini

Differential Revision: D27194038

fbshipit-source-id: 3d81c797b5be7d0466d4acad7208f6a82593b4ca
2021-03-29 09:20:33 -07:00
Xavier Deguillard
2cb1a14b42 nfs: use a cached chain length when building the fragment
Summary:
Computing the length of an iobuf chain can be expensive due to having to walk
its entirety. Thanksfully, IOBufQueue can cache the total length when data is
appended to it, which makes computing the length a constant operation.

Reviewed By: kmancini

Differential Revision: D27194037

fbshipit-source-id: af659c162ada61f2796bf407f419f5f15e918c02
2021-03-29 09:20:33 -07:00
Xavier Deguillard
a598d6ceb4 nfs: move servicing of NFS callback to a threadpool
Summary:
By moving the work to a background threadpool, we can more quickly go back to
servicing incoming NFS requests and thus allow more work to be done
concurrently. This would allow tools like ripgrep to being able to use multiple
cores to search in the code base.

Reviewed By: genevievehelsel

Differential Revision: D27194040

fbshipit-source-id: 7f1775ddaaa7eaf8776a06d05951cb936cd3fbb5
2021-03-29 09:20:33 -07:00
Xavier Deguillard
23ce5849d5 nfs: remove MountdUtil.cpp
Summary:
This used to be very useful in the early stages, as a way to manually test the
code, now that the NFS procotol is pretty well defined and tests are actually
running, this has outlived its usefulness, let's simply remove the code.

Reviewed By: kmancini

Differential Revision: D27194039

fbshipit-source-id: af86edd9f438448209a7d14ba66c9b54d90a9594
2021-03-24 10:17:49 -07:00
Xavier Deguillard
53aee6e28b nfs: remove unecessary moves
Summary:
When I wrote the NFS code, I used `std::move` a bit too much, on datastructure
where moving them is equivalent to copying them. Instead, we can simply use
references, which makes the code shorter, and thus more efficient.

Reviewed By: kmancini

Differential Revision: D27172574

fbshipit-source-id: d9f06bf3f519e3539cf5cd0a0c4e4a49ef8009a8
2021-03-24 10:17:49 -07:00
Xavier Deguillard
022613e90c nfs: add missing DirListTest
Summary:
This should have been added in D27243075 (5a150e125a) but I forgot to run `hg add` and it
was thus not added...

Reviewed By: fanzeyi

Differential Revision: D27279169

fbshipit-source-id: 69807cc05fef33f51b2a491b66c2e8aeb7136deb
2021-03-24 09:45:26 -07:00
Xavier Deguillard
5a150e125a nfs: make XdrTrait<T>::serializedSize non constexpr
Summary:
While clang has no issue compiling this code, gcc appears to choke on it,
failing to compile. This is unfortunate as this means we need to hardcode the
size of the serialized datastructure and validate it with a test.

Reviewed By: fanzeyi

Differential Revision: D27243075

fbshipit-source-id: 5cd59921bbd5d5be4dfb22789942eb022dac5bbe
2021-03-22 19:27:38 -07:00
Xavier Deguillard
9185c5a6c3 nfs: do not initialize the portmap client
Summary:
EdenFS doesn't register itself against the portmap client, and on some system
where it is not started, it appears to not work reliably, crashing EdenFS early
at startup. For now, let's only build it when services need to be registered.

Reviewed By: genevievehelsel

Differential Revision: D27162906

fbshipit-source-id: cc2a8a588a756e54253da31f9bc00fbe4e5312d9
2021-03-18 18:56:30 -07:00
Xavier Deguillard
f888b72efd inodes: a fuse channel may not always be present
Summary:
In a bunch of places, the code assumes that an EdenMount is associated with a
Fuse channel. With NFS, that's no longer the case, thus let's make sure to
check the return value of mount->getFuseChannel(). In the case where it will
make sense to have something for NFS, I've either added an EDEN_BUG, or a TODO,
so we can come back to it later.

Reviewed By: chadaustin

Differential Revision: D26836431

fbshipit-source-id: c061b8f20199e5af3139a5003827f184f6eac8d4
2021-03-18 18:28:57 -07:00
Xavier Deguillard
ec5a6ef1f0 nfs: implement the READDIR RPC
Summary:
The NFS readdir turns out to be pretty similar to the FUSE one, with a couple
of differences. For one, it only populates the directory entry name, it also
puts a limit on the total size of the serialized result, including all the
NFS/XDR overhead.

It is not specified if the . and .. entries need to be returned, but since the
NFS spec is usually pretty explicit about these and makes it clear that this is
for the most part a client burden, I didn't add these. I may have to revisit
this later when I get to manually browse a repository.

Since the READDIR RPC doesn't populate any filehandle, the client will have to
issue a LOOKUP RPC for each entries, potentially leading to some
inefficiencies. A future diff will implement the READDIRPLUS to fix these.

Reviewed By: chadaustin

Differential Revision: D26802310

fbshipit-source-id: b821b57021d0c2dca33427975b1acd665173bc5c
2021-03-18 10:08:50 -07:00
Xavier Deguillard
a7a8778dcf nfs: add a serializedSize to XdrTrait
Summary:
This simplifies a handful of tests and will make writing the READDIR RPC a bit
less magic when computing the amount of memory needed per entry.

Reviewed By: chadaustin

Differential Revision: D26802312

fbshipit-source-id: fc66cb68f721ed34c8f9879cdda2cd8db6ed8daa
2021-03-18 10:08:50 -07:00
Xavier Deguillard
35ecddf6c0 nfs: add RPC types for READDIR
Summary: This merely adds the types for the READDIR RPC.

Reviewed By: chadaustin

Differential Revision: D26802313

fbshipit-source-id: 634ff9b3f97dc4dba56d225c1fb9eae0a94c02d5
2021-03-18 10:08:50 -07:00
Xavier Deguillard
9ad3320272 nfs: implement the SYMLINK RPC
Summary:
When creating the .hg directory, Mercurial issues a SYMLINK RPC, thus let's
support it.

Reviewed By: kmancini

Differential Revision: D26785005

fbshipit-source-id: a760d55e6117cc3725444c604e3e4036f4a317b2
2021-03-17 21:30:06 -07:00
Xavier Deguillard
2c1bde2907 nfs: implement the RENAME RPC
Summary:
As it's name implies, this RPC is used to rename files. It's not clear whether
all the error cases that the spec specifies are properly covered, but future
tests can uncover this.

Reviewed By: kmancini

Differential Revision: D26771235

fbshipit-source-id: cad1065a5277e2ab169dd34c7d485d6a4cdd4b76
2021-03-11 08:31:08 -08:00
Xavier Deguillard
9452af6c8c nfs: factor out building the wcc_data
Summary:
This is pattern that is repeated in several functions, let's only have one
function to make the code easier to read.

Reviewed By: kmancini

Differential Revision: D26771236

fbshipit-source-id: 64a68e90eafcea85f850374751ae7bf34f98f118
2021-03-11 08:31:08 -08:00
Xavier Deguillard
6c338a68c6 nfs: add RPC types for RENAME
Summary: This merely adds the types needed for the RENAME RPC.

Reviewed By: kmancini

Differential Revision: D26771238

fbshipit-source-id: 7b9db7b46ffba2d7a906d0e2b60e24df0b5b055d
2021-03-11 08:31:07 -08:00
Xavier Deguillard
30bbc06336 nfs: implement SETATTR RPC
Summary:
The SETATTR RPC allows for changing various attributes of the file, like it's
mode, uid, gid, etc. The one piece of the NFS RFC that isn't implemented is
that NFS allows for a client to pass a ctime to the server that it needs to
check prior to setting the attributes. This is done to avoid concurrent
operations on the file conflicting with each other. This is not implemented for
now as Mercurial appears to not be using it.

Reviewed By: kmancini

Differential Revision: D26760073

fbshipit-source-id: 3474665fcf1b089ef6f7de4a6c45a26ef324240e
2021-03-11 08:31:07 -08:00
Xavier Deguillard
8a270adec1 nfs: add SYMLINK RPC types
Summary:
This merely adds the types needed for the SYMLINK RPC, the implementation will
follow.

Reviewed By: kmancini

Differential Revision: D26737273

fbshipit-source-id: 4ed3029304fe64892e88bc05a64b4b3b19fd5460
2021-03-05 11:11:18 -08:00