Re: [RFC PATCH v1 3/5] rust: file: add `FileDescriptorReservation`

From: Martin Rodriguez Reboredo
Date: Wed Aug 09 2023 - 00:34:57 EST


On 7/20/23 12:28, Alice Ryhl wrote:
From: Wedson Almeida Filho <walmeida@xxxxxxxxxxxxx>

This allows the creation of a file descriptor in two steps: first, we
reserve a slot for it, then we commit or drop the reservation. The first
step may fail (e.g., the current process ran out of available slots),
but commit and drop never fail (and are mutually exclusive).

Co-Developed-by: Alice Ryhl <aliceryhl@xxxxxxxxxx>
Signed-off-by: Wedson Almeida Filho <walmeida@xxxxxxxxxxxxx>
Signed-off-by: Alice Ryhl <aliceryhl@xxxxxxxxxx>
---
[...]
+/// A file descriptor reservation.
+///
+/// This allows the creation of a file descriptor in two steps: first, we reserve a slot for it,
+/// then we commit or drop the reservation. The first step may fail (e.g., the current process ran
+/// out of available slots), but commit and drop never fail (and are mutually exclusive).

This "drop" suggests to me that there was a method that it does said
action, and indeed it is `Drop::drop`. But if I look at the doc comment
of `commit` then it doesn't look that these two are mutex.

/// Commits the reservation.
///
/// The previously reserved file descriptor is bound to `file`.

I'd put a mention that `FileDescriptorReservation` gets forgotten when
`commit` is called so then it clears up that it's mutex with drop.

+///
+/// # Invariants
+///
+/// The fd stored in this struct must correspond to a reserved file descriptor of the current task.
+pub struct FileDescriptorReservation {
[...]
+}
[...]