[PATCH v2 2/6] drivers: block: Introduce blk_flush()/blk_dflush()
Simon Glass
sjg at chromium.org
Fri May 29 11:57:06 CEST 2026
uHi Denis,
On 2026-05-29T03:44:35, None <dmukhin at ford.com> wrote:
> drivers: block: Introduce blk_flush()/blk_dflush()
>
> Add generic flush operations for committing dirty data to the storage
> device.
>
> This provides a common block-layer interface for flushing pending
> writes, allowing callers to ensure that data buffered by the block
> device or its backing implementation is written out to the underlying
> storage.
>
> Signed-off-by: Denis Mukhin <dmukhin at ford.com>
>
> disk/disk-uclass.c | 6 ++++++
> drivers/block/blk-uclass.c | 18 ++++++++++++++++++
> include/blk.h | 28 ++++++++++++++++++++++++++++
> include/part.h | 8 ++++++++
> 4 files changed, 60 insertions(+)
> diff --git a/drivers/block/blk-uclass.c b/drivers/block/blk-uclass.c
> @@ -514,6 +514,19 @@ long blk_erase(struct udevice *dev, lbaint_t start, lbaint_t blkcnt)
> +long blk_flush(struct udevice *dev)
> +{
> + struct blk_desc *desc = dev_get_uclass_plat(dev);
> + const struct blk_ops *ops = blk_get_ops(dev);
> +
> + if (!ops->flush)
> + return -ENOSYS;
> +
> + blkcache_invalidate(desc->uclass_id, desc->devnum);
> +
> + return ops->flush(dev);
> +}
Why invalidate the read cache here? Flush pushes dirty data down to
the media; it doesn't change what a subsequent read returns, so the
cached contents are still valid. Erase/write mutate device state, but
flush does not. Please drop the blkcache_invalidate() call (and the
matching one in the non-DM inline below).
> diff --git a/include/blk.h b/include/blk.h
> @@ -99,6 +99,7 @@ struct blk_desc {
> unsigned long (*block_erase)(struct blk_desc *block_dev,
> lbaint_t start,
> lbaint_t blkcnt);
> + unsigned long (*block_flush)(struct blk_desc *block_dev);
This field lives in the !CONFIG_BLK (legacy) branch, but no legacy
driver in the series wires it up. The only consumer (NVMe) is DM-only.
Are you going to need the legacy plumbing?
> diff --git a/include/blk.h b/include/blk.h
> @@ -275,6 +276,14 @@ struct blk_ops {
> + /**
> + * flush() - commit all dirty data to storage
> + *
> + * @dev: Device to flush
> + * @return 0 if OK, -ve on error
> + */
> + unsigned long (*flush)(struct udevice *dev);
> };
Two small things: stray double space after the dash (flush() -
commit), and please place this next to .erase so the
read/write/erase/flush group is together.
> diff --git a/include/part.h b/include/part.h
> @@ -454,6 +454,14 @@ ulong disk_blk_write(struct udevice *dev, lbaint_t start, lbaint_t blkcnt,
> +/**
> + * disk_blk_flush() - commit data to a disk
> + *
> + * @dev: Device to flush
> + * Return: 0 success, or -ve error number (see the IS_ERR_VALUE() macro
> + */
> +ulong disk_blk_flush(struct udevice *dev);
Missing closing parenthesis after IS_ERR_VALUE() macro.
> diff --git a/disk/disk-uclass.c b/disk/disk-uclass.c
> @@ -122,6 +122,11 @@ unsigned long disk_blk_erase(struct udevice *dev, lbaint_t start,
> +unsigned long disk_blk_flush(struct udevice *dev)
> +{
> + return blk_flush(dev_get_parent(dev));
> +}
Please note in the commit message that flushing a partition flushes
the entire underlying device (the API has no start/blkcnt), so callers
don't expect partition-scoped semantics.
Regards,
Simon
More information about the U-Boot
mailing list