Re: [RFC 1/2] virtio_blk: add fua write support

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, May 08, 2025 at 01:19:50AM +0100, Alberto Faria wrote:
> Add the proposed VIRTIO_BLK_{F,T}_OUT_FUA uapi definitions and
> corresponding virtio-blk support.
> 
> Signed-off-by: Alberto Faria <afaria@xxxxxxxxxx>
> ---
>  drivers/block/virtio_blk.c      | 10 +++++++---
>  include/uapi/linux/virtio_blk.h |  4 ++++
>  2 files changed, 11 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c
> index 7cffea01d868c..021f05c469c50 100644
> --- a/drivers/block/virtio_blk.c
> +++ b/drivers/block/virtio_blk.c
> @@ -256,7 +256,8 @@ static blk_status_t virtblk_setup_cmd(struct virtio_device *vdev,
>  		sector = blk_rq_pos(req);
>  		break;
>  	case REQ_OP_WRITE:
> -		type = VIRTIO_BLK_T_OUT;
> +		type = req->cmd_flags & REQ_FUA ?
> +			VIRTIO_BLK_T_OUT_FUA : VIRTIO_BLK_T_OUT;
>  		sector = blk_rq_pos(req);
>  		break;
>  	case REQ_OP_FLUSH:
> @@ -1500,6 +1501,9 @@ static int virtblk_probe(struct virtio_device *vdev)
>  	if (virtblk_get_cache_mode(vdev))
>  		lim.features |= BLK_FEAT_WRITE_CACHE;
>  
> +	if (virtio_has_feature(vblk->vdev, VIRTIO_BLK_F_OUT_FUA))
> +		lim.features |= BLK_FEAT_FUA;
> +
>  	vblk->disk = blk_mq_alloc_disk(&vblk->tag_set, &lim, vblk);
>  	if (IS_ERR(vblk->disk)) {
>  		err = PTR_ERR(vblk->disk);
> @@ -1650,7 +1654,7 @@ static unsigned int features_legacy[] = {
>  	VIRTIO_BLK_F_RO, VIRTIO_BLK_F_BLK_SIZE,
>  	VIRTIO_BLK_F_FLUSH, VIRTIO_BLK_F_TOPOLOGY, VIRTIO_BLK_F_CONFIG_WCE,
>  	VIRTIO_BLK_F_MQ, VIRTIO_BLK_F_DISCARD, VIRTIO_BLK_F_WRITE_ZEROES,
> -	VIRTIO_BLK_F_SECURE_ERASE,
> +	VIRTIO_BLK_F_SECURE_ERASE, VIRTIO_BLK_F_OUT_FUA,

This is a new feature. Legacy VIRTIO devices don't support it.
VIRTIO_BLK_F_ZONED was not added to features_legacy[] when it was
introduced either.

>  }
>  ;
>  static unsigned int features[] = {
> @@ -1658,7 +1662,7 @@ static unsigned int features[] = {
>  	VIRTIO_BLK_F_RO, VIRTIO_BLK_F_BLK_SIZE,
>  	VIRTIO_BLK_F_FLUSH, VIRTIO_BLK_F_TOPOLOGY, VIRTIO_BLK_F_CONFIG_WCE,
>  	VIRTIO_BLK_F_MQ, VIRTIO_BLK_F_DISCARD, VIRTIO_BLK_F_WRITE_ZEROES,
> -	VIRTIO_BLK_F_SECURE_ERASE, VIRTIO_BLK_F_ZONED,
> +	VIRTIO_BLK_F_SECURE_ERASE, VIRTIO_BLK_F_ZONED, VIRTIO_BLK_F_OUT_FUA,
>  };
>  
>  static struct virtio_driver virtio_blk = {
> diff --git a/include/uapi/linux/virtio_blk.h b/include/uapi/linux/virtio_blk.h
> index 3744e4da1b2a7..52be7943f6b8d 100644
> --- a/include/uapi/linux/virtio_blk.h
> +++ b/include/uapi/linux/virtio_blk.h
> @@ -42,6 +42,7 @@
>  #define VIRTIO_BLK_F_WRITE_ZEROES	14	/* WRITE ZEROES is supported */
>  #define VIRTIO_BLK_F_SECURE_ERASE	16 /* Secure Erase is supported */
>  #define VIRTIO_BLK_F_ZONED		17	/* Zoned block device */
> +#define VIRTIO_BLK_F_OUT_FUA		18	/* FUA write is supported */
>  
>  /* Legacy feature bits */
>  #ifndef VIRTIO_BLK_NO_LEGACY
> @@ -206,6 +207,9 @@ struct virtio_blk_config {
>  /* Reset All zones command */
>  #define VIRTIO_BLK_T_ZONE_RESET_ALL 26
>  
> +/* FUA write command */
> +#define VIRTIO_BLK_T_OUT_FUA        27
> +
>  #ifndef VIRTIO_BLK_NO_LEGACY
>  /* Barrier before this op. */
>  #define VIRTIO_BLK_T_BARRIER	0x80000000
> -- 
> 2.49.0
> 

Attachment: signature.asc
Description: PGP signature


[Index of Archives]     [Linux RAID]     [Linux SCSI]     [Linux ATA RAID]     [IDE]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Device Mapper]

  Powered by Linux