Commit Graph

92 Commits

Author SHA1 Message Date
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
Xavier Deguillard
b46a7b2a11 nfs: implement the CREATE RPC
Summary:
The CREATE RPC is intended to create regular files on the server. It supports 3
ways of creating them: unchecked, guarded and exclusive. The exclusive mode
allows for a client to being able to re-transmit the creation and for it to not
fail when that happens. The way this is implemented requires the server to
store a cookie passed in by the client and on retransmission to compare it in
order to not fail the file creation. This complexity may not be warranted and
needed in the case of EdenFS, and the spec allows for a server to not support
this operation, thus EdenFS claims to not support it.

The 2 other modes are more traditional, guarded will simply fail if the file
already exist, while unchecked succeed in that same situation. It's not
entirely clear in the RFC what the behavior is supposed to be in the unchecked
case, and whether the attributes needs to be applied. For now, the error is
just ignored, a warning message is logged and a success is returned in this
case. In the future, setting the file attribute (in particular the mode and
size) may be necessary.

Reviewed By: kmancini

Differential Revision: D26654766

fbshipit-source-id: c2e8142b8a4ff756a868e5859fdda4b07e53bddf
2021-03-04 09:59:45 -08:00
Xavier Deguillard
effa6a2a22 nfs: add RPC types for CREATE
Summary: This simply adds the types to implement the CREATE RPC call.

Reviewed By: kmancini

Differential Revision: D26654767

fbshipit-source-id: 5972102aebb3b06c6838a28f3a191304efc7c945
2021-02-26 15:42:43 -08:00
Xavier Deguillard
a2efac262b nfs: implement MKDIR RPC
Summary:
The MKDIR RPC is the first RPC that modifies the working copy. It is only
partially implemented due to the parent directory attributes not being
collected just yet. Implementing these will be essential for good caching on
the client side. For simplicity reason, this isn't done just yet.

Reviewed By: kmancini

Differential Revision: D26644056

fbshipit-source-id: f99add63a2ce5789a9aa81cefe4d04c2f4a741ed
2021-02-26 15:42:43 -08:00
Xavier Deguillard
8e9b69d1a5 nfs: add RPC types for MKDIR
Summary: This adds all the types necessaryt to implement the MKDIR RPC.

Reviewed By: kmancini

Differential Revision: D26644057

fbshipit-source-id: cfbcf3f0a7212433eba67f2266d5f7bcc2906a88
2021-02-26 15:42:42 -08:00
Xavier Deguillard
40c223ed76 nfs: add XdrOptionalVariant
Summary:
This is a fairly common pattern in the NFS code, and we can reduce code
duplication by automatically implementing the XdrTrait.

Reviewed By: kmancini

Differential Revision: D26639683

fbshipit-source-id: 6e9cb14ce1538834224017b8ef88955e563d6723
2021-02-26 15:42:42 -08:00
Xavier Deguillard
9f1662031c nfs: de-dup XdrVariant<nfsstat3, ...> code
Summary:
The NFS RPC description is filled with variant over nfsstat3 with only 2 cases:
NFS3_OK, and the default one. I was feeling bad having to write the same code
again and again for the deserialize part of the XdrTrait, and thus came up with
a template solution that enables us to remove all of the boilerplate code.

The only drawback is that this moves the variant one additional layer down, and
that means an extra layer of brace when initializing it. From what I know,
this is caused by the -Wmissing-braces warning, maybe we could remove that
warning?

Reviewed By: kmancini

Differential Revision: D26627163

fbshipit-source-id: ab56dee42273f180b2edf4f529221a15154ac2fb
2021-02-26 08:01:25 -08:00
Xavier Deguillard
0c3c258ce2 nfs: add missing RPC args struct
Summary:
Previously, when an argument was just a plan filehandle, I just bypassed adding
the structure and just read the handle directly from the stream. kmancini
correctly pointed out that this is a bit confusing, thus let's add the arg
struct everywhere to cut that confusion.

Reviewed By: kmancini

Differential Revision: D26649568

fbshipit-source-id: bc4d6e519450f228d151a3de7acdfc1002c43b38
2021-02-25 18:51:27 -08:00
Xavier Deguillard
917575d591 nfs: implement READLINK RPC
Summary:
This is merely a forward to the readlink FileInode method. This allows the
.eden directory and its symlinks to be read properly.

Reviewed By: kmancini

Differential Revision: D26619947

fbshipit-source-id: d5f8ef81ce3000c0f0a2f47007affe2c0292ef31
2021-02-25 18:51:27 -08:00