Re: [PATCH v2 23/83] block: rnull: add discard support
From: Malte Wechter
Date: Wed Jun 10 2026 - 10:00:23 EST
On Tue Jun 9, 2026 at 9:08 PM CEST, Andreas Hindborg wrote:
> Add support for discard operations to the rnull block driver:
> - Add discard module parameter and configfs attribute.
> - Set max_hw_discard_sectors when discard is enabled.
> - Add sector occupancy tracking.
> - Add discard handling that frees sectors and removes empty pages.
> - Discard operations require memory backing to function.
>
> The discard feature uses a bitmap to track which sectors in each page are
> occupied, allowing cleanup of pages when they are empty.
>
> Signed-off-by: Andreas Hindborg <a.hindborg@xxxxxxxxxx>
> ---
> drivers/block/rnull/configfs.rs | 15 +++++
> drivers/block/rnull/rnull.rs | 120 +++++++++++++++++++++++++++++++++++-----
> 2 files changed, 121 insertions(+), 14 deletions(-)
>
> diff --git a/drivers/block/rnull/configfs.rs b/drivers/block/rnull/configfs.rs
> index 2f3fa81ea121..e47399cd45a4 100644
> --- a/drivers/block/rnull/configfs.rs
> +++ b/drivers/block/rnull/configfs.rs
...
> }
> })
> );
> +
> +configfs_attribute!(DeviceConfig, 10,
> + show: |this, page| show_field(this.data.lock().discard, page),
> + store: |this, page| store_with_power_check(this, page, |data, page| {
> + if !data.memory_backed {
> + return Err(EINVAL);
> + }
> + data.discard = kstrtobool_bytes(page)?;
> + Ok(())
> + })
> +);
Should it be ok to set 'discard' to 0 if 'emory_backed' is not set?
In the C null_blk driver, 'discard' defaults to 0 if 'memory_backed' is not set,
it is also ignored (and defaulted to 0) if 'zoned' is enabled.
Best regards,
Malte