Commit Graph

200 Commits

Author SHA1 Message Date
Michael Cuevas
b2ae3f9cc3 eden/{integration, fs, facebook}: switch to platform010
Summary:
We should all be migrating to platform010, for the improved performance of its
generated code and for its improved diagnostics/portability.

Reviewed By: kmancini

Differential Revision: D35851539

fbshipit-source-id: d42b12c77ddeacb4777f2e360fdebd1cbbc1bd6d
2022-04-26 13:22:33 -07:00
Michael Cuevas
91b6afcfd1 Back out "eden/{integration, fs, facebook}: switch to platform010"
Reviewed By: chadaustin

Differential Revision: D35850816

fbshipit-source-id: 282c06fbf7cc249030ae0173779722175c662133
2022-04-22 14:52:01 -07:00
Michael Cuevas
8fb9ea454a eden/{integration, fs, facebook}: switch to platform010
Summary:
We should all be migrating to platform010, for the improved performance of its
generated code and for its improved diagnostics/portability.

Reviewed By: xavierd

Differential Revision: D35573251

fbshipit-source-id: 5339212de0e617df13277ffcb5a67a535263847d
2022-04-21 15:37:37 -07:00
Katie Mancini
9463488e8b fix C++ 20 compile error
Summary:
When we try to switch to platform 10 we get this compile error:

```
eden/fs/nfs/Nfsd3.cpp:1378:26:
error: call to consteval function
'fmt::basic_format_string<char, const unsigned int &>::basic_format_string<const char *, 0>'
is not a constant expression
  return fmt::format(fmtString, std::get<typename T::TrueVariant>(val.v));
```

The problem is that fmtString either needs to be a `basic_format_string` or
needs to be a constexpr so that we can cast it to `basic_format_string` through
various means.

Not totally sure why this worked pre c++ 20, but C++20 introduced some stricter
type checking on the fmt library or constexpr stuff in general i guess.

https://github.com/fmtlib/fmt/issues/2438 outlines the possible fixes

`fmt::runtime` looks like the best way.

Reviewed By: vitaut

Differential Revision: D35756658

fbshipit-source-id: 7b65ccf0719a964ab1f2fc1aed72744e72374d20
2022-04-20 17:37:54 -07:00
Katie Mancini
8f3f873874 fix invalidation on NFS
Summary:
TL;DR: File invalidation after checkout is broken on NFS macOS. This proposes a
fix.

Previously, to invalidate things on NFS we opened and closed all the parent
directories of any files/directories that changed during a checkout operation.

This worked on Linux because all open calls result in some request into the
EdenFS daemon (usually a getattr I think). The returned response from this
would show that the directory had update timestamps. So the open would see the
parent directories in their updated state. This would trigger the NFS client to
clear it's caches for that directory and their recursive children to preserve
CTO. CTO or close-to-open consistency guarantees that if on process observed a
file in state A and closed the file, then another process opened that same file
, it will see the file in state A or a later state.

macOS does not seem to do CTO.

It seems that most of the "read" filesystem calls can basically be served from
cache on NFS. Only writes seem to be guaranteed to make it into eden.

So instead of using a "read" filesystem call to trigger invalidation, we need to
use a write one.

I tried opening things in write mode, but the problem is that we need to
invalidate directories (to ensure the entry information is updated) and
directories can not be opened in write mode.

I tried writing 0 bytes to the files themselves that have changed, but this
empty write is short circuited somewhere in the kernel.

The only filesystem call that can be a noop, and seems to trigger a call into
eden is chmod. We are not really working off any guarantees any more, but
it seems to work on both Linux and macOS in my testing so far and is better
than our current broken state of invalidation.

So now to invalidate we chmod parent directories that have changed with their
current mode. Note that this could get extra tricky if we were mixing updating
directory permissions with invalidating them. We would need to ensure we chmod
with the most up to date mode bits. However, because we do not update
permissions anywhere that we also invalidate (checkout does not know how to
update directory permissions) things are a little simpler.

It's important that the chmod can not complete until it seems an updated view of
the parent directory. So we have to be careful about locking here. (Although
that hasn't really changed since we switched from open to chmod.)

One thing that does change is that since chmod is technically a write, it could
cause extra materialization that would be bad for checkout and status
performance. To prevent these problems I have updated setattr to not materialize
a directory when the attribute change is a noop which it should be in our
invalidation technique unless another client modified the directory in the
meantime in which case the directory should be modified anyways. This would
mean that we could end up wiping out clients changes to permissions in the
working copy during checkout. but this matches non eden checkout behavior. So I
think this is ok.

Reviewed By: xavierd

Differential Revision: D35435764

fbshipit-source-id: 196c4995b130b595f9582204237e726e5212993f
2022-04-19 20:32:54 -07:00
Katie Mancini
ad04eb9bc1 add unit test for access
Summary: This code has enough risk of a copy paste error that it deserves a unit test.

Reviewed By: chadaustin

Differential Revision: D35161787

fbshipit-source-id: 5691d13a74a0f059dfd6a93ea2852dca8399a165
2022-04-18 21:55:15 -07:00
Katie Mancini
3893aa9cf6 log extra connections to NFS server
Summary:
We have seen that sometimes the a client sends us nfsv4 requests with the
nfsv3 version on it.

We fail to parse those.

It's likely the kernel that is sending us that event, but technically any client
could connect to us, so we don't know that for sure.

Let's make sure we log if we see more than one client connected to us. so that
we can confirm if this is the kernel or not.

We should probably also not let non kernel clients connect to us. But I have not
figured out how to do that. tbd

Reviewed By: fanzeyi

Differential Revision: D35448531

fbshipit-source-id: e0810c8961c18b305b80bb874ae4f6aee9583d07
2022-04-07 15:34:08 -07:00
Katie Mancini
63ad96b091 Support access calls
Summary:
In the NFS protocol, the client does not completely resolve permissions based
on the access bits in the mode field of stat.

Clients make a special call into NFS, ACCESS, to check if a certain user has
permissions to perform some operation on a file or directory.

Access was perviously unimplemented for NFS and returned open permissions.

This fully implements the access procedure.

Reviewed By: xavierd

Differential Revision: D34632815

fbshipit-source-id: eda39e02c12c189cd1fc3a32dbe864f00d2c3458
2022-03-29 10:21:05 -07:00
Katie Mancini
7ba3360a97 really weird std::optional + delayed destructor bug
Summary:
my eden-dev on my M1 is always crashing on `eden stop` with this trace:

```
Assertion failed: (dd_->guardCount_ > 0), function ~DestructorGuard, file DelayedDestructionBase.h, line 96.
*** Aborted at 1648171587 (Unix time, try 'date -d 1648171587') ***
*** Signal 6 (SIGABRT) (0x1bb2fd9b8) received by PID 31226 (pthread TID 0x115a58580) (maybe from PID 31226, UID 501) (code: 0), stack trace: ***
I0324 18:26:27.215606 6572327 EdenServer.cpp:1574] mount point "/Users/kmancini/t-fbsource" stopped
V0324 18:26:27.215625 6572327 EdenMount.cpp:800] beginning shutdown for EdenMount /Users/kmancini/t-fbsource
0   edenfs#macosx-arm64                 0x000000010626a968 _ZN5folly10symbolizer17getStackTraceSafeEPmm + 36
1   edenfs#macosx-arm64                 0x000000010611739c _ZN5folly10symbolizer21SafeStackTracePrinter15printStackTraceEb + 108
2   edenfs#macosx-arm64                 0x000000010603e854 _ZN5folly10symbolizer12_GLOBAL__N_118innerSignalHandlerEiP9__siginfoPv + 232
3   edenfs#macosx-arm64                 0x000000010603c9d4 _ZN5folly10symbolizer12_GLOBAL__N_113signalHandlerEiP9__siginfoPv + 108
4   libsystem_platform.dylib            0x00000001bb3484e4 _sigtramp + 56
5   libsystem_pthread.dylib             0x00000001bb330eb0 pthread_kill + 288
6   libsystem_c.dylib                   0x00000001bb26e314 abort + 164
7   libsystem_c.dylib                   0x00000001bb26d72c err + 0
8   edenfs#macosx-arm64                 0x0000000105148ab0 _ZN5folly22DelayedDestructionBase15DestructorGuardD2 (45261a919d)Ev + 180
9   edenfs#macosx-arm64                 0x0000000105143438 _ZN5folly22DelayedDestructionBase15DestructorGuardD1 (19e5072be0)Ev + 28
10  edenfs#macosx-arm64                 0x0000000104df1eb0 _ZNSt3__124__optional_destruct_baseIN5folly22DelayedDestructionBase15DestructorGuardELb0EED2 (45261a919d)Ev + 44
11  edenfs#macosx-arm64                 0x0000000104df1e74 _ZNSt3__123__optional_storage_baseIN5folly22DelayedDestructionBase15DestructorGuardELb0EED2 (45261a919d)Ev + 28
12  edenfs#macosx-arm64                 0x0000000104df1e48 _ZNSt3__120__optional_copy_baseIN5folly22DelayedDestructionBase15DestructorGuardELb0EED2 (45261a919d)Ev + 28
13  edenfs#macosx-arm64                 0x0000000104df1e1c _ZNSt3__120__optional_move_baseIN5folly22DelayedDestructionBase15DestructorGuardELb0EED2 (45261a919d)Ev + 28
14  edenfs#macosx-arm64                 0x0000000104df1df0 _ZNSt3__127__optional_copy_assign_baseIN5folly22DelayedDestructionBase15DestructorGuardELb0EED2 (45261a919d)Ev + 28
15  edenfs#macosx-arm64                 0x0000000104df1dc4 _ZNSt3__127__optional_move_assign_baseIN5folly22DelayedDestructionBase15DestructorGuardELb0EED2 (45261a919d)Ev + 28
16  edenfs#macosx-arm64                 0x0000000104df1d98 _ZNSt3__18optionalIN5folly22DelayedDestructionBase15DestructorGuardEED2 (45261a919d)Ev + 28
17  edenfs#macosx-arm64                 0x0000000104df1bb8 _ZNSt3__18optionalIN5folly22DelayedDestructionBase15DestructorGuardEED1 (19e5072be0)Ev + 28
18  edenfs#macosx-arm64                 0x0000000104df3364 _ZN8facebook4eden9RpcServer17RpcAcceptCallbackD2 (45261a919d)Ev + 60
19  edenfs#macosx-arm64                 0x0000000104df0bd0 _ZN8facebook4eden9RpcServer17RpcAcceptCallbackD1 (19e5072be0)Ev + 28
20  edenfs#macosx-arm64                 0x0000000104df0bfc _ZN8facebook4eden9RpcServer17RpcAcceptCallbackD0Ev + 28
21  edenfs#macosx-arm64                 0x0000000102dfc330 _ZN5folly18DelayedDestruction16onDelayedDestroyEb + 88
22  edenfs#macosx-arm64                 0x0000000105148aec _ZN5folly22DelayedDestructionBase15DestructorGuardD2 (45261a919d)Ev + 240
23  edenfs#macosx-arm64                 0x0000000105143438 _ZN5folly22DelayedDestructionBase15DestructorGuardD1 (19e5072be0)Ev + 28
24  edenfs#macosx-arm64                 0x0000000104dedf3c _ZNSt3__124__optional_destruct_baseIN5folly22DelayedDestructionBase15DestructorGuardELb0EE5resetEv + 40
25  edenfs#macosx-arm64                 0x0000000104dede20 _ZN8facebook4eden9RpcServer17RpcAcceptCallback13acceptStoppedEv + 416
26  edenfs#macosx-arm64                 0x000000010514c260 _ZZN5folly17AsyncServerSocket14RemoteAcceptor4stopEPNS_9EventBaseEPNS0_14AcceptCallbackEENK3$_1clEv + 44
27  edenfs#macosx-arm64                 0x000000010514c228 _ZN5folly6detail8function14FunctionTraitsIFvvEE9callSmallIZNS_17AsyncServerSocket14RemoteAcceptor4stopEPNS_9EventBaseEPNS6_14AcceptCallbackEE3$_1EEvRNS1_4DataE + 32
28  edenfs#macosx-arm64                 0x0000000101fc287c _ZN5folly6detail8function14FunctionTraitsIFvvEEclEv + 40
29  edenfs#macosx-arm64                 0x0000000105d3b40c _ZN5folly9EventBase20FunctionLoopCallback15runLoopCallbackEv + 32
30  edenfs#macosx-arm64                 0x0000000105d3476c _ZN5folly9EventBase16runLoopCallbacksERN5boost9intrusive4listINS0_12LoopCallbackENS2_18constant_time_sizeILb0EEEvvvEE + 120
31  edenfs#macosx-arm64                 0x0000000105d31ef0 _ZN5folly9EventBase16runLoopCallbacksEv + 88
32  edenfs#macosx-arm64                 0x0000000105d336a8 _ZN5folly9EventBase8loopBodyEib + 1396
33  edenfs#macosx-arm64                 0x0000000105d31c10 _ZN5folly9EventBase8loopOnceEi + 44
34  edenfs#macosx-arm64                 0x000000010201a700 _ZN8facebook4eden10EdenServer14performCleanupEv + 2004
35  edenfs#macosx-arm64                 0x0000000101fb8d80 _ZN8facebook4eden11runEdenMainEONS0_8EdenMainEiPPc + 3240
36  edenfs#macosx-arm64                 0x0000000101f5e56c main + 56
37  dyld                                0x00000001159e50f4 start + 520
(safe mode, symbolizer not available)
```

for some reason the destructor is being called twice even though the constructor is only called once.

this makes the delated destructor count double decrement and hit its internal assert.

I think this is because std::optional is directly calling the destructor on the value maybe and so it is being double destructed.

keeping a direct member variable gets rid of the crash.

This probably deserves a follow up to understand why std::optional is doing this.

Reviewed By: xavierd

Differential Revision: D35134797

fbshipit-source-id: 6b9184c878962b7f773f6be55ac70a83dc00fa42
2022-03-25 13:43:16 -07:00
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
Katie Mancini
ee29930b55 log parsing errors more clearly
Summary:
A EdenFS messenger dogfooder on macOS is hitting our check here that file
handles be a certain size.

This likely indicates that we have a big somewhere in parsing that is causing
us to parse something that is not a file handle as a file handle. Its also
possible this request could be malformed.

Eventually we should not trust clients enough to allow them to crash eden with
a malformed request, but the first step to fixing this bug is understanding
wether the request that crashes us is malformed or not.

So first I am adding some extra logging info to this xcheck so that we can
determine the cause. I will follow up with a solution to prevent clients
from crashing EdenFS.

Reviewed By: xavierd

Differential Revision: D34969740

fbshipit-source-id: 783ca1147f6c9d9c86996836d14263a0a79d6b7d
2022-03-21 11:54:16 -07:00
Michael Cuevas
aa4732e433 refactor notifications
Summary:
Refactor the existing notification class so it uses the new Notifier interface. The notifier interface will be used to set up notifications/notification trays on different platforms.

The notifier interface is not fully completed yet. More methods will be added in a future diff.

As of now, we only have 1 Notifier, the command notifier. I hope to remove this notifier once we implement notifiers for all platforms that we support.

Reviewed By: chadaustin

Differential Revision: D34291809

fbshipit-source-id: a2a67af2683f1f88781428e8d88191f49e100e96
2022-03-01 17:52:58 -08:00
Xavier Deguillard
5995517153 inodes: do not call RequestContext::finishRequest in the destructor
Summary:
When ran in the destructor, the class inheriting from RequestContext would have
been destroyed, and thus the vtable for the RequestContext would no longer from
the child class. In practice that meant that the PID of all requests was always
a nullopt, making `eden minitop` and others completely useless.

To solve this, we can simply create a shared_ptr with a custom deleter that
calls finishRequest first before calling the destructor.

Reviewed By: genevievehelsel

Differential Revision: D34160296

fbshipit-source-id: 7f6d9bfa36bc3db256cfe0f61478c22a44028001
2022-02-11 15:57:52 -08:00
Xavier Deguillard
6722ba460d inodes: move RequestContext::finishRequest to the destructor
Summary:
In the case where the shared_ptr holding a RequestContext is copied, some stats
may still be updated after the request completes. Thus it's best to call
finishRequest in the destructor to make sure the stats are properly updated.

Reviewed By: chadaustin

Differential Revision: D33724775

fbshipit-source-id: 5e4b247d44bdbeb322f25316dc98798e551cc43b
2022-01-26 10:24:35 -08:00
Xavier Deguillard
a29d465ee8 fs: fix license header
Summary:
With Facebook having been renamed Meta Platforms, we need to change the license
headers.

Reviewed By: fanzeyi

Differential Revision: D33407812

fbshipit-source-id: b11bfbbf13a48873f0cea75f212cc7b07a68fb2e
2022-01-04 15:00:07 -08:00
Michael Cuevas
e79d41cc77 change entry3 and entryplus3 constructors
Summary: Instead of taking a uint64_t, we'll take in an InodeNumber. This allows us to avoid the conversion from InodeNumber -> uint64_t -> InodeNumber.

Reviewed By: chadaustin, xavierd

Differential Revision: D33135685

fbshipit-source-id: c9e4317b1f5f97ad924dce5da322860c91c64115
2021-12-15 21:13:36 -08:00
Michael Cuevas
d068b2e05a move include inside of windows ifndef
Summary: don't include this header if we're on Windows

Reviewed By: xavierd

Differential Revision: D33111628

fbshipit-source-id: 8bf6c7db4f023f7c348f1e1c439c15856acbf476
2021-12-15 16:08:54 -08:00
Michael Cuevas
670b274424 move statToPostOpAttr() and other functions into a utility file
Summary: In the next diff, we need to use statToPostOpAttr() in another file. We will move these utility functions so we can access them from any file.

Reviewed By: xavierd

Differential Revision: D32771540

fbshipit-source-id: f4d6e2819da3ef66248134337f98eb0a938b6edb
2021-12-15 16:08:54 -08:00
Michael Cuevas
fa60b61477 add getListRef() method to NfsDirList
Summary: This method is needed so that the NfsDispatcher layer can fill in missing stat data for each DirList entry.

Reviewed By: kmancini, xavierd

Differential Revision: D32770593

fbshipit-source-id: 2510adf8b8738259d5e6b8714c6492fd4f75f5d3
2021-12-15 16:08:53 -08:00
Michael Cuevas
0810163d6a add nfs readdirplus implementation to nfsd3 layer
Summary:
We account for args.dircount in this implementation (dircount is the max number of bytes we can use for holding directory information)

We *don't* account for args.maxcount. We should probably do that.

Reviewed By: kmancini, xavierd

Differential Revision: D32767072

fbshipit-source-id: c07d0f3aec5a13ed2bb3fa6960ea65e95438dff3
2021-12-15 16:08:53 -08:00
Michael Cuevas
db86b321b7 add readdirplus support to NfsDispatcher layer
Summary: implement NfsDispatcher layer

Reviewed By: xavierd

Differential Revision: D32765513

fbshipit-source-id: 45af883c94bb078268179d236730e8db51088bc7
2021-12-15 16:08:53 -08:00
Michael Cuevas
64f168baef modify NfsDirList to support entryplus3 entries
Summary:
The current readdir implementation uses NfsDirList to hold readdir results. Our new readdirplus implementation should use the same struct. To do this, we will add the ability to use an entryplus3 XdrList instead of an entry3 XdrList.

We also add a new constructor so we can specify which XdrList to initialize when we create an NfsDirList.

Reviewed By: xavierd

Differential Revision: D32708688

fbshipit-source-id: e2b324dd1dffc8620be89dca471043aba9b167a5
2021-12-15 16:08:53 -08:00
Giuseppe Ottaviano
a384c00413 Remove usages of IOBufQueue::clear()
Summary:
Drop all the remaining instances of `IOBufQueue::clear()`.

(Note: this ignores all push blocking failures!)

Reviewed By: yfeldblum

Differential Revision: D32941992

fbshipit-source-id: c7d983e215a78014ffda74a944b628e1886c35c8
2021-12-10 13:06:29 -08:00
Chad Austin
1781a4b704 display actual size when static_assert sizeof fails
Summary:
static_assert sizeof doesn't show the actual size in clang or gcc, so
implement a CheckSize template.

Reviewed By: xavierd

Differential Revision: D32998926

fbshipit-source-id: 432fbf19eae5b4572e5a4908f9007b7242a3ae69
2021-12-09 14:52:53 -08:00
Katie Mancini
292a694582 turn off some debug logging that was left on
Summary:
I was using this to debug graceful restart locally, and had it at a high debug
level. DBG1 is a bit verbose this should probably be DBG7 with the rest of the
debug logging I added.

Reviewed By: genevievehelsel

Differential Revision: D32902321

fbshipit-source-id: 4b7db7cbe96db8ef5b1035932c06a1de264f8502
2021-12-07 09:46:15 -08:00
Xavier Deguillard
3e70bee42b fschannel: do not report the true used space
Summary:
We've seen several reports of users getting confused by the output of `df` and
thinking that EdenFS was using 100+ GBs of disk space. In reality, EdenFS is
simply reporting the stats from the underlying filesystem, and thus isn't a
true representation of the disk space usage.

To avoid this confusion, let's simply pretend that EdenFS doesn't use any disk
space. This isn't exactly true as the overlay and some internal datastructures
are using space already, but `eden du` is the right way to see these.

Reviewed By: fanzeyi

Differential Revision: D32536715

fbshipit-source-id: ec9b27084340d2e69cc5a14d6aa71def5fb4465d
2021-11-18 12:51:03 -08:00
Jim Meyering
4aa901fe1f eden/fs/nfs/rpc/Server.h: adjust for C++20
Summary:
Provide a no-arg constructor, for C++20

This avoids the following errors:
```
eden/fs/nfs/rpc/Server.h:234:63: error: no matching constructor for initialization of 'facebook::eden::RpcTcpHandler::State'
    explicit StateWrapper(folly::EventBase* evb) : evb_{evb}, state_{} {}
                                                              ^     ~~
eden/fs/nfs/rpc/Server.h:221:5: note: candidate constructor not viable: requires single argument 'state', but no arguments were provided
    State(const State& state) = delete;
    ^
eden/fs/nfs/rpc/Server.h:223:5: note: candidate constructor not viable: requires single argument 'state', but no arguments were provided
    State(State&& state) = delete;
```

Differential Revision: D32521305

fbshipit-source-id: 70d53db2093b41b58d4abc0b20389b0169b7a2e3
2021-11-17 21:50:09 -08:00
Katie Mancini
324071beee takeover for mountd
Summary:
For restart for NFS we now have the pieces to transfer nfs mounts.

The last piece of restart is transferring the mountd socket. This extracts the
socket from the current mountd and provides it to the takeover server, as well
as implements reading the mountd socket from the takeover client and starting
the mountd with this server socket.

Reviewed By: xavierd

Differential Revision: D31802786

fbshipit-source-id: 1727ea0913bfe1dcb02fdbe27c8cc3b9d62a8464
2021-11-17 17:13:12 -08:00
Katie Mancini
5197b8ad71 takeover stop for NFS mounts
Summary:
For restart for NFS we now have the pieces for the nfs channel to
perform takeover and for the takeover code to transfer the data.

This commit plumbs everything through so that we are able to stop and nfs
channel on takeover. this means extracting the connected socket and plubming it
to the takeover server.

Reviewed By: xavierd

Differential Revision: D31357367

fbshipit-source-id: 91973f7c149ae9209e85aa40111f41e7753db63f
2021-11-17 17:13:11 -08:00
Katie Mancini
e30e6b7730 takeover start for NFS mounts
Summary:
For restart for NFS we now have the pieces for the nfs channel to
perform takeover and for the takeover code to transfer the data.

This commit plumbs everything through so that we are able to start and nfs
mount during takeover. This means starting the NFS channel from an existing
connected socket.

Reviewed By: xavierd

Differential Revision: D31802788

fbshipit-source-id: 9034c1cc93e6bb64c09a203d265cf3bdedd1e160
2021-11-17 17:13:11 -08:00
Katie Mancini
2d506a9373 teach RpcServer to do takeover
Summary:
We are working towards supporting graceful restart on NFS so that NFS users will
have this available when we start the migration.

This commit is teaching the Server at the core of the nfsd and mountd to
support takeoverShutdown and takeoverStartup. This means stopping processing
requests when we call takover shutdown and passing the sockets (both server
socket and connected sockets) up the stack.

For now we are only supporting takeover once everything has been initialized
and not during mount or unmount.

This means for the nfsd we will only care about the one connected socket which
is being used to communicate with the kernel. we will pass through the
shutdown promise for the channel. For the mountd we only care about the server
socket which we will return from the takeoverShutdown method itself.

Then we also add being able to initialize itself from a server socket or
a connected socket.

Reviewed By: xavierd

Differential Revision: D31802790

fbshipit-source-id: 06ef4da48cd864bfa20ea0fb98485792255d98cd
2021-11-17 17:13:11 -08:00
Yicheng Wang
9ca84bc057 Adding AcceptInfo into connectionAccepted of AsyncSocket callback
Summary:
AsyncServerSocket works like this:
1) a socket is accepted from the fd
2) the socket is pushed into the socket queue
3) the connectionAccepted() callback is called with the socket is dequeued

Things happening before connectionAccepted() are like black box to us currently. For example the time taken for a socket to sit in the socket queue is completely unknown. Adding this AcceptInfo into the callback could allow us to pass more information to downstream for instrumenting.

This diff only pass timestamp of before the socket is being pushed into the queue.

Reviewed By: yfeldblum

Differential Revision: D31633582

fbshipit-source-id: 66072955318388c2410b48313d3d54078edce478
2021-11-01 18:23:24 -07:00
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
Xavier Deguillard
a579ab83cb nfs: add types for READDIRPLUS
Summary: This is merely adding the type, the implementation will follow.

Reviewed By: kmancini

Differential Revision: D26737271

fbshipit-source-id: 42de7873b271a2bf9499f1274bca50f23dc1016b
2021-03-05 11:11:18 -08:00
Xavier Deguillard
dd831ca0e6 nfs: add XdrList
Summary:
Both READDIR and READDIRPLUS RPC (and other) are using lists as a way to have
an unsized array of values. From a behavior perspective, this is similar to an
array of XdrOptionalValue but without it being prefixed by a size, and with an
additional last element being empty.

To simplify writing these RPC, let's add this XdrList type.

Reviewed By: kmancini

Differential Revision: D26729816

fbshipit-source-id: 8d14bbc6f0513aac51d65625e5751cedc2071a0b
2021-03-05 11:11:18 -08:00
Xavier Deguillard
3371db5c25 nfs: move the XDR macros to Xdr.h
Summary:
These aren't tied to the RPC protocol but more to how XDR works, therefore it
makes more sense to move these to the Xdr.h file. It also enables tests to use
it instead of having to write the serialization by hand.

Reviewed By: chadaustin

Differential Revision: D26729815

fbshipit-source-id: 227299b94e2f6fa5ecc747a8d5705f0931a7d1f8
2021-03-04 18:15:33 -08:00
Xavier Deguillard
ba37453611 nfs: add RPC types for SETATTR
Summary: This merely adds the types for the SETATTR RPC.

Reviewed By: kmancini

Differential Revision: D26707362

fbshipit-source-id: 89cbf7a501cf4e13878cd84b6c36691d2a08594f
2021-03-04 18:15:33 -08:00
Xavier Deguillard
aed51e9e44 nfs: add argument formatting
Summary:
Now that a large part of the RPC is implemented, being able to see what
arguments are being passed in makes it convenient for debugging.

Reviewed By: kmancini

Differential Revision: D26707363

fbshipit-source-id: 676adef996bf584140b324df1419b139f4600c91
2021-03-04 18:15:33 -08:00
Xavier Deguillard
72972c0ff5 nfs: implement the READ RPC
Summary:
This reads the data from the file. One of the optimization that isn't done in
this diff would be to detect the EOF without having read return a 0-bytes long
buffer. For now this isn't done, but more plumbing in the FileInode would be
required to achieve this.

Reviewed By: kmancini

Differential Revision: D26704138

fbshipit-source-id: 82e6d4994dd5dc46372778c10d9f68f7ca1e3a87
2021-03-04 17:51:51 -08:00
Xavier Deguillard
6629d7fd9b nfs: add RPC types for READ
Summary: This merely adds the types for the READ RPC.

Reviewed By: kmancini

Differential Revision: D26704137

fbshipit-source-id: a803fc9082cbec6ce0c6b9db2bfede55bf478df1
2021-03-04 17:51:51 -08:00
Xavier Deguillard
7238290100 nfs: implement the REMOVE RPC
Summary:
While creating the .hg directory, Mercurial seems to want to remove some files
too, thus let's thread this to the inode layer to allow Mercurial to continue.

Reviewed By: kmancini

Differential Revision: D26699272

fbshipit-source-id: e6d283b92e18962698c0df3c6361adfbd0c50223
2021-03-04 17:51:51 -08:00
Xavier Deguillard
9a7c51ef9c nfs: add RPC types for REMOVE procedure
Summary: This is merely adding the types needed to implement the REMOVE procedure.

Reviewed By: kmancini

Differential Revision: D26694441

fbshipit-source-id: 736d06ed7bfae40f827fbec6017e069fe11d7464
2021-03-04 09:59:48 -08:00
Xavier Deguillard
6daea7e4e0 nfs: implement the LINK RPC
Summary:
Since EdenFS doesn't support hardlinks, this is merely collecting the attribute
of the file before always failing.

Reviewed By: kmancini

Differential Revision: D26682014

fbshipit-source-id: 8c39170147023a03e87ed7a0fae66f9184b4f690
2021-03-04 09:59:47 -08:00
Xavier Deguillard
466b3144b8 nfs: add RPC types for LINK
Summary: During clone, Mercurial calls this, despite EdenFS not advertising hardlinks.

Reviewed By: kmancini

Differential Revision: D26682013

fbshipit-source-id: b43affeb7577354991308165113d5d5070bf8605
2021-03-04 09:59:47 -08:00
Xavier Deguillard
b5ad70b619 nfs: implement the FSSTAT RPC
Summary:
The RPC simply queries various filesystem attributes, we merely forward what
statfs on the overlayfs gives us.

Reviewed By: kmancini

Differential Revision: D26681613

fbshipit-source-id: 5b94d05cafff8d77390fe60a3b5cf1dc3e022f42
2021-03-04 09:59:47 -08:00
Xavier Deguillard
f7050ae2ea nfs: add RPC types for FSSTAT
Summary: This merely adds the types for the RPC.

Reviewed By: kmancini

Differential Revision: D26681615

fbshipit-source-id: d092cf0b6b5bb7435702d125b5c6ea7ee68356dc
2021-03-04 09:59:47 -08:00
Xavier Deguillard
e87ea9c085 nfs: implement the WRITE RPC
Summary:
This simply writes the data passed in to the inode. Note that the current
implementation has a protocol violation since it doesn't sync the data written
to disk but advertise to the client that it did. This is completely wrong from
a data consistency guarantee, but is probably fine for now. Once the code
becomes closer to being production ready, this will be changed to honor the
client asks.

Reviewed By: kmancini

Differential Revision: D26681614

fbshipit-source-id: 82ad7a141be3bbe365363b1f6692ae62f253423f
2021-03-04 09:59:46 -08:00
Xavier Deguillard
3d377e2df3 nfs: replace folly::io::Appender with folly::io::QueueAppender
Summary:
The Appender API doesn't allow us to simply append an IOBuf chain to it forcing
the entire chain to be copied to it. For the most part, this isn't an issue,
but to reduce the overhead of the READ NFS procedure, this will be a nice
benefit.

For the most part, this diff is a codemod, with a couple of places that needed
to be manually fixed. These were in the rpc/Server.{cpp,h} and
rpc/StreamClient.{cpp,h}.

Reviewed By: genevievehelsel

Differential Revision: D26675988

fbshipit-source-id: 04feef8623fcddd02ff7aea0b68a17598ab1d0f8
2021-03-04 09:59:46 -08:00
Xavier Deguillard
8125e2e115 nfs: de-duplicate some common test functions
Summary:
The ser, de and roundtrip are duplicated 3 times in the various tests, let's
move them into a common library.

Reviewed By: chadaustin

Differential Revision: D26675989

fbshipit-source-id: 1da0bc33429795a889b72c76fa18e5fa3cb7df6f
2021-03-04 09:59:46 -08:00
Xavier Deguillard
3bea128aeb nfs: add types for WRITE RPC
Summary: This merely adds the various types for the WRITE RPC.

Reviewed By: chadaustin

Differential Revision: D26671895

fbshipit-source-id: 8409c8a1f90e97478aed7c9f19b881c46234b539
2021-03-04 09:59:46 -08:00
Xavier Deguillard
0841d553fd nfs: allow serializing/deserializing IOBuf
Summary:
For the READ/WRITE RPC calls, copying data in and out of an IOBuf chain can be
fairly expensive, to avoid this overhead, we can simply clone the data out of
the IOBuf chain directly, saving on the cost of copy.

Since the code uses a folly::io::Appender that doesn't support adding an IOBuf
to it, we still pay the cost of copying data to it, switching to
folly::io::QueueAppender may solve this.

Reviewed By: chadaustin

Differential Revision: D26671896

fbshipit-source-id: 0161f04cb820bf27ef66fdef6b4a1ce4eb778b96
2021-03-04 09:59:45 -08:00