Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 21 additions & 6 deletions drivers/block/rnull/configfs.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,31 @@
// SPDX-License-Identifier: GPL-2.0

use super::{NullBlkDevice, THIS_MODULE};
use super::{
NullBlkDevice,
THIS_MODULE, //
};
use kernel::{
block::mq::gen_disk::{GenDisk, GenDiskBuilder},
configfs::{self, AttributeOperations},
block::mq::gen_disk::{
GenDisk,
GenDiskBuilder, //
},
configfs::{
self,
AttributeOperations, //
},
configfs_attrs,
fmt::{self, Write as _},
fmt::{
self,
Write as _, //
},
new_mutex,
page::PAGE_SIZE,
prelude::*,
str::{kstrtobool_bytes, CString},
sync::Mutex,
str::{
kstrtobool_bytes,
CString, //
},
sync::Mutex, //
};

pub(crate) fn subsystem() -> impl PinInit<kernel::configfs::Subsystem<Config>, Error> {
Expand Down
15 changes: 11 additions & 4 deletions drivers/block/rnull/rnull.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,19 @@ use kernel::{
self,
mq::{
self,
gen_disk::{self, GenDisk},
Operations, TagSet,
},
gen_disk::{
self,
GenDisk, //
},
Operations,
TagSet, //
}, //
},
prelude::*,
sync::{aref::ARef, Arc},
sync::{
aref::ARef,
Arc, //
}, //
};

module! {
Expand Down
24 changes: 18 additions & 6 deletions rust/kernel/block/mq/gen_disk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,26 @@

use crate::{
bindings,
block::mq::{Operations, TagSet},
error::{self, from_err_ptr, Result},
fmt::{self, Write},
block::mq::{
Operations,
TagSet, //
},
error::{
from_err_ptr,
to_result, //
},
fmt::{
self,
Write, //
},
prelude::*,
static_lock_class,
str::NullTerminatedFormatter,
sync::Arc,
types::{ForeignOwnable, ScopeGuard},
types::{
ForeignOwnable,
ScopeGuard, //
}, //
};

/// A builder for [`GenDisk`].
Expand Down Expand Up @@ -54,7 +66,7 @@ impl GenDiskBuilder {
/// and that it is a power of two.
pub fn validate_block_size(size: u32) -> Result {
if !(512..=bindings::PAGE_SIZE as u32).contains(&size) || !size.is_power_of_two() {
Err(error::code::EINVAL)
Err(EINVAL)
} else {
Ok(())
}
Expand Down Expand Up @@ -164,7 +176,7 @@ impl GenDiskBuilder {
// operation, so we will not race.
unsafe { bindings::set_capacity(gendisk, self.capacity_sectors) };

crate::error::to_result(
to_result(
// SAFETY: `gendisk` points to a valid and initialized instance of
// `struct gendisk`.
unsafe {
Expand Down
14 changes: 10 additions & 4 deletions rust/kernel/block/mq/operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,17 @@

use crate::{
bindings,
block::mq::{request::RequestDataWrapper, Request},
error::{from_result, Result},
block::mq::{
request::RequestDataWrapper,
Request, //
},
error::from_result,
prelude::*,
sync::{aref::ARef, Refcount},
types::ForeignOwnable,
sync::{
aref::ARef,
Refcount, //
},
types::ForeignOwnable, //
};
use core::marker::PhantomData;

Expand Down
16 changes: 11 additions & 5 deletions rust/kernel/block/mq/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,21 @@
use crate::{
bindings,
block::mq::Operations,
error::Result,
prelude::*,
sync::{
aref::{ARef, AlwaysRefCounted},
aref::{
ARef,
AlwaysRefCounted, //
},
atomic::Relaxed,
Refcount,
Refcount, //
},
types::Opaque,
types::Opaque, //
};
use core::{
marker::PhantomData,
ptr::NonNull, //
};
use core::{marker::PhantomData, ptr::NonNull};

/// A wrapper around a blk-mq [`struct request`]. This represents an IO request.
///
Expand Down
28 changes: 14 additions & 14 deletions rust/kernel/block/mq/tag_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,21 @@
//!
//! C header: [`include/linux/blk-mq.h`](srctree/include/linux/blk-mq.h)

use core::pin::Pin;

use crate::{
bindings,
block::mq::{operations::OperationsVTable, request::RequestDataWrapper, Operations},
error::{self, Result},
prelude::try_pin_init,
types::Opaque,
block::mq::{
operations::OperationsVTable,
request::RequestDataWrapper,
Operations, //
},
error::to_result,
prelude::*,
types::Opaque, //
};
use core::{
convert::TryInto,
marker::PhantomData, //
};
use core::{convert::TryInto, marker::PhantomData};
use pin_init::{pin_data, pinned_drop, PinInit};

/// A wrapper for the C `struct blk_mq_tag_set`.
///
Expand All @@ -33,11 +37,7 @@ pub struct TagSet<T: Operations> {

impl<T: Operations> TagSet<T> {
/// Try to create a new tag set
pub fn new(
nr_hw_queues: u32,
num_tags: u32,
num_maps: u32,
) -> impl PinInit<Self, error::Error> {
pub fn new(nr_hw_queues: u32, num_tags: u32, num_maps: u32) -> impl PinInit<Self, Error> {
let tag_set: bindings::blk_mq_tag_set = pin_init::zeroed();
let tag_set: Result<_> = core::mem::size_of::<RequestDataWrapper>()
.try_into()
Expand All @@ -63,7 +63,7 @@ impl<T: Operations> TagSet<T> {
// SAFETY: we do not move out of `tag_set`.
let tag_set: &mut Opaque<_> = unsafe { Pin::get_unchecked_mut(tag_set) };
// SAFETY: `tag_set` is a reference to an initialized `blk_mq_tag_set`.
error::to_result( unsafe { bindings::blk_mq_alloc_tag_set(tag_set.get())})
to_result( unsafe { bindings::blk_mq_alloc_tag_set(tag_set.get())})
}),
_p: PhantomData,
})
Expand Down
23 changes: 17 additions & 6 deletions rust/kernel/miscdevice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,27 @@
use crate::{
bindings,
device::Device,
error::{to_result, Error, Result, VTABLE_DEFAULT_ERROR},
ffi::{c_int, c_long, c_uint, c_ulong},
fs::{File, Kiocb},
iov::{IovIterDest, IovIterSource},
error::{
to_result,
VTABLE_DEFAULT_ERROR, //
},
fs::{
File,
Kiocb, //
},
iov::{
IovIterDest,
IovIterSource, //
},
mm::virt::VmaNew,
prelude::*,
seq_file::SeqFile,
types::{ForeignOwnable, Opaque},
types::{
ForeignOwnable,
Opaque, //
},
};
use core::{marker::PhantomData, pin::Pin};
use core::marker::PhantomData;

/// Options for creating a misc device.
#[derive(Copy, Clone)]
Expand Down
34 changes: 28 additions & 6 deletions samples/rust/rust_misc_device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,36 @@

use kernel::{
device::Device,
fs::{File, Kiocb},
ioctl::{_IO, _IOC_SIZE, _IOR, _IOW},
iov::{IovIterDest, IovIterSource},
miscdevice::{MiscDevice, MiscDeviceOptions, MiscDeviceRegistration},
fs::{
File,
Kiocb, //
},
ioctl::{
_IO,
_IOC_SIZE,
_IOR,
_IOW, //
},
iov::{
IovIterDest,
IovIterSource, //
},
miscdevice::{
MiscDevice,
MiscDeviceOptions,
MiscDeviceRegistration, //
},
new_mutex,
prelude::*,
sync::{aref::ARef, Mutex},
uaccess::{UserSlice, UserSliceReader, UserSliceWriter},
sync::{
aref::ARef,
Mutex, //
},
uaccess::{
UserSlice,
UserSliceReader,
UserSliceWriter, //
},
};

const RUST_MISC_DEV_HELLO: u32 = _IO('|' as u32, 0x80);
Expand Down
11 changes: 9 additions & 2 deletions scripts/rustdoc_test_gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,15 @@
use std::{
fs,
fs::File,
io::{BufWriter, Read, Write},
path::{Path, PathBuf},
io::{
BufWriter,
Read,
Write, //
},
path::{
Path,
PathBuf, //
}, //
};

/// Find the real path to the original file based on the `file` portion of the test name.
Expand Down