Re: [PATCH 28/79] block: rnull: add partial I/O support for bad blocks

Alice Ryhl
2026-03-16T12:14:15Z

On Mon, Feb 16, 2026 at 12:35:15AM +0100, Andreas Hindborg wrote:
> Add bad_blocks_partial_io configuration option that allows partial I/O
> completion when encountering bad blocks, rather than failing the entire
> request.
>
> When enabled, requests are truncated to stop before the first bad block
> range, allowing the valid portion to be processed successfully. This
> improves compatibility with applications that can handle partial
> reads/writes.
>
> Signed-off-by: Andreas Hindborg <a.hindborg@kernel.org>

> -#[vtable]
> -impl configfs::AttributeOperations<13> for DeviceConfig {
> - type Data = DeviceConfig;
> -
> - fn show(this: &DeviceConfig, page: &mut [u8; PAGE_SIZE]) -> Result<usize> {
> - let mut writer = kernel::str::Formatter::new(page);
> -
> - if this.data.lock().bad_blocks_once {
> - writer.write_str("1\n")?;
> - } else {
> - writer.write_str("0\n")?;
> - }
> -
> - Ok(writer.bytes_written())
> - }
> -
> - fn store(this: &DeviceConfig, page: &[u8]) -> Result {
> - if this.data.lock().powered {
> - return Err(EBUSY);
> - }
> -
> - this.data.lock().bad_blocks_once = kstrtobool_bytes(page)?;
> -
> - Ok(())
> - }
> -}
> +configfs_simple_bool_field!(DeviceConfig, 13, bad_blocks_once);

Squash this into previous patch.

> +fn is_power_of_two<T>(value: T) -> bool
> +where
> + T: core::ops::Sub<T, Output = T>,
> + T: core::ops::BitAnd ,
> + T: core::cmp::PartialOrd<T>,
> + T: Copy,
> + T: From<u8>,
> +{
> + (value > 0u8.into()) && (value & (value - 1u8.into())) == 0u8.into()
> +}

This is in the standard library.

> +fn align_down<T>(value: T, to: T) -> T
> +where
> + T: core::ops::Sub<T, Output = T>,
> + T: core::ops::Not ,
> + T: core::ops::BitAnd ,
> + T: core::cmp::PartialOrd<T>,
> + T: Copy,
> + T: From<u8>,
> +{
> + debug_assert!(is_power_of_two(to));
> + value & !(to - 1u8.into())
> +}

Overlap with:
https://lore.kernel.org/rust-for-linux/20260221020952.412352-22-jhubbard@nvidia.com/

Alice