Skip to content

rust: add support for file system parameters #827

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

Merged
merged 1 commit into from
Jul 19, 2022

Conversation

wedsonaf
Copy link

This allows file system contexts to be further initialised with
parameters from userspace before a fs is mounted or reconfigured.

Signed-off-by: Wedson Almeida Filho [email protected]

// context is valid, `from_pointer` wasn't called yet, so `ptr` is valid. Additionally,
// the callback contract guarantees that callbacks are serialised, so it is ok to
// mutably reference it.
let mut data = unsafe { borrow_mut::<<T::Context as Context<T>>::Data>(ptr) };
Copy link
Member

Choose a reason for hiding this comment

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

To fulfill the safety guarantee, we also need to make sure &data won't be Copy to another thread, right? Because data is Sync, allowing copy &data breaks the safety guarantee:

no other concurrent users of the pointer run at least until the returned ScopeGuard is dropped.

Copy link
Member

Choose a reason for hiding this comment

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

I think it's better if we have a PointerWrapper::borrow_mut

Copy link
Author

Choose a reason for hiding this comment

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

To fulfill the safety guarantee, we also need to make sure &data won't be Copy to another thread, right? Because data is Sync, allowing copy &data breaks the safety guarantee:

no other concurrent users of the pointer run at least until the returned ScopeGuard is dropped.

It's ok to have &data in other threads as long as it is derived from this data (e.g., we call a function that takes a &data as argument and sends it out to other threads but guarantees that they are done before returning). What needs to be avoided is &data or &mut data acquired through other means.

I think it's better if we have a PointerWrapper::borrow_mut

I wanted to avoid having each implementation replicate the same functionality, but thinking about it, we can just provide a default implementation and have everyone use it. Will do.

Copy link
Author

Choose a reason for hiding this comment

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

(BTW, I expanded the comment to include the fact that we can have &data derived from data.)

This allows file system contexts to be further initialised with
parameters from userspace before a fs is mounted or reconfigured.

Signed-off-by: Wedson Almeida Filho <[email protected]>
@@ -44,6 +76,55 @@ impl<T: Type + ?Sized> Tables<T> {
}
}

unsafe extern "C" fn parse_param_callback(

Choose a reason for hiding this comment

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

Doesn't all 'unsafe' comments require a '//SAFETY' comment ( #351 ) ?
Although the following unsafe code it is indeed commented.

Copy link
Member

@ojeda ojeda Jul 17, 2022

Choose a reason for hiding this comment

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

Note that this is an unsafe block, but an unsafe fn. For the former, you indeed need to describe why the operations inside the block are sound with a // SAFETY: comment. For the latter, we use /// # Safety documentation sections to describe the safety preconditions, if public.

It may be a good idea to start requiring documentation for private unsafe functions later on too, though.

Copy link
Author

Choose a reason for hiding this comment

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

As Miguel explained, we normally require /// # Safety blocks for these, which is slightly different: we're telling callers what they need to do to use it safely. I do write these sections even for private functions (see for example unnregister_keys in this very same file), but this case is a callback from C: there are no Rust callers, so no one is going to write a // SAFETY block based on this function.

None of the C callbacks currently have /// # Safety sections because of this.

@wedsonaf wedsonaf merged commit 3d414ec into Rust-for-Linux:rust Jul 19, 2022
@wedsonaf wedsonaf deleted the fs-params branch July 19, 2022 15:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants