Unify descriptor managment into LiteBox core#722
Open
jaybosamiya-ms wants to merge 13 commits intomainfrom
Open
Unify descriptor managment into LiteBox core#722jaybosamiya-ms wants to merge 13 commits intomainfrom
jaybosamiya-ms wants to merge 13 commits intomainfrom
Conversation
These were intended to eventually be public, but were locked down in the past. Now that things are a bit more stable, we can actually make these public.
This was a non-trivial change since it required migrating a bunch of code up to actually use raw FDs everywhere, but this should make the next commit (hopefully) simpler to read.
This gets rid of the `__Unused`, but introduces some clippy things to be cleaned up, but I wanted to keep this particular commit quite "obvious" on its own to see in the diff.
c87e164 to
c454122
Compare
|
🤖 SemverChecks 🤖 No breaking API changes detected Note: this does not mean API is unchanged, or even that there are no breaking changes; simply, none of the detections triggered. |
wdcui
reviewed
Mar 14, 2026
| } | ||
| // Close whatever is at newfd before duping into it | ||
| let newfd_usize = usize::try_from(newfd).or(Err(Errno::EBADF))?; | ||
| let _ = self.do_close(newfd_usize); |
Member
There was a problem hiding this comment.
Do we need to check if the oldfd is valid before closing the newfd?
| @@ -1895,30 +2017,19 @@ impl<FS: ShimFS> Task<FS> { | |||
| Ok(oldfd) | |||
Member
There was a problem hiding this comment.
Do we need to check oldfd is valid?
| .fd_into_raw_integer(socket), | ||
| ) | ||
| let Ok(raw_fd) = files.insert_raw_fd(socket) else { | ||
| unimplemented!() |
Member
There was a problem hiding this comment.
Should we return EMFILE instead of panic?
| peer_addr, | ||
| )) | ||
| let Ok(raw_fd) = files.insert_raw_fd(accepted_file) else { | ||
| unimplemented!() |
| } | ||
| Ok(target) | ||
| } else { | ||
| Ok(rds.fd_into_raw_integer(fd)) |
Member
There was a problem hiding this comment.
This call may return a fd that's less than the min_fd checked in fcntl?
| .raw_descriptor_store | ||
| .read() | ||
| .fd_from_raw_integer::<crate::syscalls::unix::UnixSocketSubsystem<FS>>(raw_fd) | ||
| .map_err(|_| Errno::ENOTSOCK)?; |
Member
There was a problem hiding this comment.
What if the socket doesn't exist? Should we return EBADF instead of ENOTSOCK?
| let raw_fd = sockfd as usize; | ||
| let inet_fd = { | ||
| let rds = self.raw_descriptor_store.read(); | ||
| rds.fd_from_raw_integer(raw_fd).ok() |
Member
There was a problem hiding this comment.
Do we need to handle the error path here?
| let max_fd = self.max_fd.load(Ordering::Relaxed); | ||
| if raw_fd > max_fd { | ||
| let orig = rds.fd_consume_raw_integer::<Subsystem>(raw_fd).unwrap(); | ||
| return Err(alloc::sync::Arc::into_inner(orig).unwrap()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR fully eliminates the descriptor table indirection we had in the shim, now relying entirely on the LiteBox core to manage file descriptors both for raw FDs as well as the typed FDs.
To do this, I've made the following changes at the core litebox crate:
liteboxcrates to defineFdEnabledSubsystems, as a stabilized interfaceEntryHandleinterface, that allows entry-specific locking outsideliteboxwithout maintaining a full descriptor table lockAt the shim, roughly it boils down to "remove
Descriptors+Descriptor" and deal with the consequences. The changes are quite extensive but are not particularly insightful in any major way. I did clean up a few bugs along the way where (say) rlimits might not have been adhered to, or if two descriptors are made and the second one hit an rlimit issue, then there could have been a leak, etc.Despite removing a chunk of code, some other code did get a tiny bit more bloated, but the level of indirection is smaller. I think we can further clean this up by removing some of the redundancy, but I think merging this in sooner than that is probably the better move, thus I've opened the PR in the current state.
Related: #31