Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor FUSE #1047

Merged
merged 11 commits into from
Feb 15, 2024
Merged

Refactor FUSE #1047

merged 11 commits into from
Feb 15, 2024

Conversation

cagatay-y
Copy link
Contributor

@cagatay-y cagatay-y commented Feb 3, 2024

This PR aims to use safer standard library functionality for allocation for FUSE, deduplicate what is in common between different operations and specify what is necessarily varying between them in a easier-to-read manner.
Another goal is to set up the module so that in the future we can access the Rsp layout without creating a skeleton Rsp object, in order to eliminate copying. However, that requires changes in virtqueue API and is not a part of this PR.

@cagatay-y
Copy link
Contributor Author

Some of the commits that were automatically rebased do not build. I thought it may make more sense to get feedback first and fix the commits later, incorporating the feedback. I also could not figure out why Clippy thinks that ROOT_ID is not used.

@cagatay-y cagatay-y marked this pull request as ready for review February 5, 2024 16:57
@mkroening mkroening self-assigned this Feb 5, 2024
@mkroening mkroening self-requested a review February 5, 2024 17:02
src/fs/mod.rs Show resolved Hide resolved
Copy link
Member

@mkroening mkroening left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot, @cagatay-y!

This is looking great, though I have a few requests. Please don't hesitate to reach out, if you want to talk about them.

src/lib.rs Outdated Show resolved Hide resolved
src/fs/fuse.rs Outdated Show resolved Hide resolved
src/fs/fuse.rs Outdated Show resolved Hide resolved
src/fs/fuse.rs Outdated Show resolved Hide resolved
Comment on lines 168 to 170
let transfer_tkn = buff_tkn
.write(Some(cmd), None::<&<fuse::Op<CODE> as fuse::OpTrait>::Rsp>)
.unwrap();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you change Some(rsp) to None purposefully?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. As far as I understand, FUSE does not need the memory allocated for the response to be initialized at all. It reads the size of the writable section from the command struct. BufferToken::write copies the the argument when it is Some and since we don't initialize the response, I bypassed the copying.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The part of the request structure that corresponds to our Rsp is referred to as a “[d]evice-writable part” in the file system device section of the Virtio specification and the Virtqueue section specifies that “a device SHOULD NOT read a device-writable buffer (it MAY do so for debugging or diagnostic purposes).”

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is true for Virtqueue's in general, I think we can also remove receive buffer copying from the Virtqueue interface (unless we want to keep it for “debugging or diagnostic purposes,” as mentioned in the specification), though it should probably be a separate PR since it touches parts of the code base outside FUSE.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All right, sounds good! 👍

src/fs/fuse.rs Outdated
pub flags: u32,
pub padding: u32,
impl Op<{ fuse_abi::Opcode::Init as u32 }> {
fn create() -> (Box<<Self as OpTrait>::Cmd>, Box<<Self as OpTrait>::Rsp>) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For Sized return types, we might want to avoid boxing if possible. Though that might be better off as a separate PR, since boxing was the previous behavior too, I think.

@cagatay-y cagatay-y force-pushed the fuse-refactor-2 branch 4 times, most recently from 43de9b3 to fba4e32 Compare February 14, 2024 14:58
Copy link
Member

@mkroening mkroening left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot, this looks great! Could you rebase so CI passes? :)

Moving the ABI definitions to a separate module helps keeping track of
what is our design and what is dictated by the FUSE ABI.
Since the convention removes the module prefix from the identifiers,
qualified names are used at use-sites.
The host does not use the len field of the header of the Rsp (relies on
the size field in the In struct if necessary instead). It is not
necessary to fill it in during creation and copy it during dispatch.
Turning the Cmd/Rsp creation functions into associated functions for the
Op structs allows us to refer to the Op struct in the function signature
and body in a more concise manner.
To specify operations, use structs instead of const generic arguments to
reduce verbosity.
@mkroening mkroening added this pull request to the merge queue Feb 15, 2024
Merged via the queue into hermit-os:main with commit 294fabd Feb 15, 2024
59 checks passed
@mkroening mkroening mentioned this pull request Mar 26, 2024
@cagatay-y cagatay-y deleted the fuse-refactor-2 branch April 4, 2024 10:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants