rust: Move unfit code out of `rust/kernel/types.rs`
Subsystems (5)
cover rust: Move unfit code out of `rust/kernel/types.rs`
Hello all,
These are the patches for a good first issue that Benno Lossin oppened on https://github.com/Rust-for-Linux/linux/issues/1117
According to the issue description, the file rust/kernel/types.rs is a rather non-descriptive, general file that contains code that might be better suited elsewhere:
- ARef<T> and AlwaysRefCounted should be in rust/kernel/sync/aref.rs
- The FromBytes and AsBytes traits and implementations should be in rust/kernel/transmute.rs
Aliet Exposito Garcia (2):
rust: Move FromBytes and AsBytes traits to a new transmute
module
rust: Move ARef<T> and AlwaysRefCounted to new sync::aref module
drivers/block/rnull.rs | 3 +- rust/kernel/block/mq.rs | 6 +- rust/kernel/block/mq/operations.rs | 2 +- rust/kernel/block/mq/request.rs | 3 +- rust/kernel/device.rs | 8 +- rust/kernel/lib.rs | 1 + rust/kernel/sync.rs | 1 + rust/kernel/sync/aref.rs | 152 ++++++++++++++++++++ rust/kernel/task.rs | 4 +- rust/kernel/transmute.rs | 67 +++++++++ rust/kernel/types.rs | 216 +---------------------------- rust/kernel/uaccess.rs | 2 +- 12 files changed, 236 insertions(+), 229 deletions(-) create mode 100644 rust/kernel/sync/aref.rs create mode 100644 rust/kernel/transmute.rs
base-commit: a2f11547052001bd448ccec81dd1e68409078fbb
Signature · 1 line
2.46.0
PATCH 1/2 rust: Move `FromBytes` and `AsBytes` traits to a new `transmute` module
This patch refactors the FromBytes and AsBytes traits from types.rs into a new transmute.rs module.
The traits and their implementations remain unchanged.
- Adds rust/kernel/transmute.rs with the definitions of FromBytes and AsBytes
- Removes the same trait definitions from rust/kernel/types.rs
- Updates rust/kernel/uaccess.rs to import AsBytes and FromBytes from transmute.rs
--- rust/kernel/lib.rs | 1 + rust/kernel/transmute.rs | 67 ++++++++++++++++++++++++++++++++++++++++ rust/kernel/types.rs | 64 -------------------------------------- rust/kernel/uaccess.rs | 2 +- 4 files changed, 69 insertions(+), 65 deletions(-) create mode 100644 rust/kernel/transmute.rs
rust/kernel/lib.rs +1 -0
@@ -52,6 +52,7 @@pub mod sync;pub mod task;pub mod time; +pub mod transmute;pub mod types;pub mod uaccess;pub mod workqueue;
rust/kernel/transmute.rs new file +67 -0
67 lines not on this page · raw message
rust/kernel/types.rs +0 -64
67 lines not on this page · raw message
rust/kernel/uaccess.rs +1 -1
@@ -9,7 +9,7 @@ bindings, error::Result, prelude::*, - types::{AsBytes, FromBytes}, + transmute::{AsBytes, FromBytes}, };use alloc::vec::Vec ;use core::ffi::{c_ulong, c_void};
Signature · 1 line
2.46.0
Re: [PATCH 1/2] rust: Move `FromBytes` and `AsBytes` traits to a new `transmute` module
Quoted 13 lines · Aliet Exposito Garcia
This patch refactors the
FromBytesandAsBytestraits fromtypes.rsinto a newtransmute.rsmodule.
The traits and their implementations remain unchanged.
- Addsrust/kernel/transmute.rswith the definitions ofFromBytesandAsBytes
- Removes the same trait definitions fromrust/kernel/types.rs
- Updatesrust/kernel/uaccess.rsto importAsBytesandFromBytesfromtransmute.rsSuggested-by Benno Lossin <[email protected]>
Quoted 7 lines
--- rust/kernel/lib.rs | 1 + rust/kernel/transmute.rs | 67 ++++++++++++++++++++++++++++++++++++++++ rust/kernel/types.rs | 64 -------------------------------------- rust/kernel/uaccess.rs | 2 +- 4 files changed, 69 insertions(+), 65 deletions(-) create mode 100644 rust/kernel/transmute.rs
Thanks for the patch!
---
Cheers,
Benno
Re: [PATCH 1/2] rust: Move `FromBytes` and `AsBytes` traits to a new `transmute` module
In reply to Aliet Exposito GarciaQuoted 9 lines · Aliet Exposito Garcia
This patch refactors the
FromBytesandAsBytestraits fromtypes.rsinto a newtransmute.rsmodule.
The traits and their implementations remain unchanged.
- Addsrust/kernel/transmute.rswith the definitions ofFromBytesandAsBytes
- Removes the same trait definitions fromrust/kernel/types.rs
- Updatesrust/kernel/uaccess.rsto importAsBytesandFromBytesfromtransmute.rs
Quoted 4 lines
Suggested-by Benno Lossin <[email protected]>
PATCH 2/2 rust: Move `ARef<T>` and `AlwaysRefCounted` to new `sync::aref` module
In reply to Aliet Exposito GarciaThis patch refactors the ARef type and AlwaysRefCounted trait from types.rs into a new sync/aref.rs module.
The type and trait definitions remain unchanged.
- Adds rust/kernel/sync/aref.rs with the definitions of ARef and AlwaysRefCounted
- Removes the same type and trait definitions from rust/kernel/types.rs
- Updates relevant files to import ARef and AlwaysRefCounted from
`sync/aref.rs`
--- drivers/block/rnull.rs | 3 +- rust/kernel/block/mq.rs | 6 +- rust/kernel/block/mq/operations.rs | 2 +- rust/kernel/block/mq/request.rs | 3 +- rust/kernel/device.rs | 8 +- rust/kernel/sync.rs | 1 + rust/kernel/sync/aref.rs | 152 +++++++++++++++++++++++++++++ rust/kernel/task.rs | 4 +- rust/kernel/types.rs | 152 +---------------------------- 9 files changed, 167 insertions(+), 164 deletions(-) create mode 100644 rust/kernel/sync/aref.rs
drivers/block/rnull.rs +1 -2
@@ -20,8 +20,7 @@ error::Result, new_mutex, pr_info, prelude::*, - sync::{Arc, Mutex}, - types::ARef, + sync::{aref::ARef, Arc, Mutex}, };module! {
rust/kernel/block/mq.rs +3 -3
@@ -20,7 +20,7 @@//! The kernel will interface with the block device driver by calling the method //! implementations of the `Operations` trait. //! -//! IO requests are passed to the driver as [`kernel::types::ARef<Request>`] +//! IO requests are passed to the driver as [`kernel::sync::aref::ARef<Request>`] //! instances. The `Request` type is a wrapper around the C `struct request`. //! The driver must mark end of processing by calling one of the //! `Request::end`, methods. Failure to do so can lead to deadlock or timeout
@@ -61,8 +61,8 @@//! block::mq::*, //! new_mutex, //! prelude::*, -//! sync::{Arc, Mutex}, -//! types::{ARef, ForeignOwnable}, +//! sync::{Arc, Mutex, aref::{ARef, AlwaysRefCounted}}, +//! types::ForeignOwnable, //! }; //! //! struct MyBlkDevice;
rust/kernel/block/mq/operations.rs +1 -1
@@ -9,7 +9,7 @@ block::mq::request::RequestDataWrapper, block::mq::Request, error::{from_result, Result}, - types::ARef, + sync::aref::ARef, };use core::{marker::PhantomData , sync::atomic::AtomicU64 , sync::atomic::Ordering };
rust/kernel/block/mq/request.rs +2 -1
@@ -8,7 +8,8 @@ bindings, block::mq::Operations, error::Result, - types::{ARef, AlwaysRefCounted, Opaque}, + sync::aref::{ARef, AlwaysRefCounted}, + types::Opaque, };use core::{ marker::PhantomData ,
rust/kernel/device.rs +3 -5
@@ -4,10 +4,8 @@//! //! C header: [`include/linux/device.h`](srctree/include/linux/device.h) -use crate ::{ - bindings, - types::{ARef ,Opaque }, -}; +use crate ::{bindings, sync::aref::ARef , types::Opaque }; +use core::ptr;/// A reference-counted device.
@@ -85,7 +83,7 @@ pub unsafe fn as_ref<'a>(ptr: *mut bindings::device) -> &'a Self { }// SAFETY: Instances of `Device` are always reference-counted. -unsafe impl crate ::types::AlwaysRefCounted for Device { +unsafe impl crate ::sync::aref::AlwaysRefCounted for Device {fn inc_ref (&self) {// SAFETY: The existence of a shared reference guarantees that the refcount is non-zero. unsafe { bindings::get_device (self.as_raw ()) };
rust/kernel/sync.rs +1 -0
@@ -8,6 +8,7 @@use crate ::types::Opaque ;mod arc; +pub mod aref;mod condvar;pub mod lock;mod locked_by;
rust/kernel/sync/aref.rs new file +152 -0
152 lines not on this page · raw message
rust/kernel/task.rs +2 -2
@@ -61,7 +61,7 @@ macro_rules! current {/// incremented when creating `State` and decremented when it is dropped: /// /// ``` -/// use kernel::{task::Task, types::ARef}; +/// use kernel::{task::Task, sync::aref::ARef}; /// /// struct State { /// creator: ARef<Task>,
@@ -164,7 +164,7 @@ pub fn wake_up(&self) { }// SAFETY: The type invariants guarantee that `Task` is always refcounted. -unsafe impl crate ::types::AlwaysRefCounted for Task { +unsafe impl crate ::sync::aref::AlwaysRefCounted for Task {fn inc_ref (&self) {// SAFETY: The existence of a shared reference means that the refcount is nonzero. unsafe { bindings::get_task_struct (self.0 .get ()) };
rust/kernel/types.rs +2 -150
166 lines not on this page · raw message
Signature · 1 line
2.46.0
Re: [PATCH 2/2] rust: Move `ARef<T>` and `AlwaysRefCounted` to new `sync::aref` module
Quoted 13 lines · Aliet Exposito Garcia
This patch refactors the
AReftype andAlwaysRefCountedtrait fromtypes.rsinto a newsync/aref.rsmodule.
The type and trait definitions remain unchanged.
- Addsrust/kernel/sync/aref.rswith the definitions ofARefandAlwaysRefCounted
- Removes the same type and trait definitions fromrust/kernel/types.rs
- Updates relevant files to importARefandAlwaysRefCountedfrom`sync/aref.rs`Suggested-by Benno Lossin <[email protected]>
Quoted 12 lines
--- drivers/block/rnull.rs | 3 +- rust/kernel/block/mq.rs | 6 +- rust/kernel/block/mq/operations.rs | 2 +- rust/kernel/block/mq/request.rs | 3 +- rust/kernel/device.rs | 8 +- rust/kernel/sync.rs | 1 + rust/kernel/sync/aref.rs | 152 +++++++++++++++++++++++++++++ rust/kernel/task.rs | 4 +- rust/kernel/types.rs | 152 +---------------------------- 9 files changed, 167 insertions(+), 164 deletions(-) create mode 100644 rust/kernel/sync/aref.rs
---
Cheers,
Benno
Re: [PATCH 2/2] rust: Move `ARef<T>` and `AlwaysRefCounted` to new `sync::aref` module
In reply to Aliet Exposito GarciaQuoted 7 lines · Aliet Exposito Garcia
This patch refactors the
AReftype andAlwaysRefCountedtrait fromtypes.rsinto a newsync/aref.rsmodule.
The type and trait definitions remain unchanged.
- Addsrust/kernel/sync/aref.rswith the definitions ofARefandAlwaysRefCounted
- Removes the same type and trait definitions fromrust/kernel/types.rs
- Updates relevant files to importARefandAlwaysRefCountedfrom
Quoted 6 lines
`sync/aref.rs`Suggested-by Benno Lossin <[email protected]>
Thanks,
Fiona
Miguel Ojeda
AppliedQuoted 10 lines · Aliet Exposito Garcia
Hello all,
These are the patches for a good first issue that Benno Lossin oppened on https://github.com/Rust-for-Linux/linux/issues/1117
According to the issue description, the filerust/kernel/types.rsis a rather non-descriptive, general file that contains code that might be better suited elsewhere:
-ARef<T>andAlwaysRefCountedshould be inrust/kernel/sync/aref.rs
- TheFromBytesandAsBytestraits and implementations should be inrust/kernel/transmute.rs
Applied to rust-next -- thanks everyone!
[ Rebased on top of the lints series and slightly reworded. - Miguel ]
[ Rebased on top of the lints series, slightly reworded and removed
unneeded use AlwaysRefCounted in example. - Miguel ]
Aliet: please double-check that you are happy with the rebase.
Cheers,
Miguel
Quoted 11 lines · Miguel Ojeda
Quoted 9 lines · Aliet Exposito Garcia
Hello all,
These are the patches for a good first issue that Benno Lossin oppened on https://github.com/Rust-for-Linux/linux/issues/1117
According to the issue description, the filerust/kernel/types.rsis a rather non-descriptive, general file that contains code that might be better suited elsewhere:
-ARef<T>andAlwaysRefCountedshould be inrust/kernel/sync/aref.rs
- TheFromBytesandAsBytestraits and implementations should be inrust/kernel/transmute.rs
Quoted 8 lines
Applied to
rust-next-- thanks everyone![ Rebased on top of the lints series and slightly reworded. - Miguel ]
[ Rebased on top of the lints series, slightly reworded and removed
unneededuse AlwaysRefCountedin example. - Miguel ]Aliet: please double-check that you are happy with the rebase.
Hello Miguel, yes, I have double-checked and I am happy with the rebase.
Quoted 2 lines
Cheers,
Miguel
I want to continue studying Rust so that little by little I can help in the Rust-for-Linux subsystem.
Thank you very much to everyone; you have an excellent community, very welcoming to beginners.
Best regards,
Aliet
Quoted 8 lines · Aliet Expósito
Hello Miguel, yes, I have double-checked and I am happy with the rebase.
I want to continue studying Rust so that little by little I can help in the Rust-for-Linux subsystem.
Thank you very much to everyone; you have an excellent community, very welcoming to beginners.
Thanks for double-checking and the kind words -- messages like this may make others decide to contribute! :)
Cheers,
Miguel
Quoted 7 lines · Miguel Ojeda
Applied to
rust-next-- thanks everyone![ Rebased on top of the lints series and slightly reworded. - Miguel ]
[ Rebased on top of the lints series, slightly reworded and removed
unneededuse AlwaysRefCountedin example. - Miguel ]
The other day I dropped temporarily the second patch to keep linux-next building and to simplify merging the VFS series. I will put it back later on.
Cheers,
Miguel