You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2024/10/06 00:38:05 UTC

(nuttx) 05/16: virtio-blk: add VIRTIO_BLK_F_FLUSH features

This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit 7ec167392c61e422e6bd7ef3e9c87b0f5776fece
Author: wangyongrong <wa...@xiaomi.com>
AuthorDate: Mon Jun 3 14:06:56 2024 +0800

    virtio-blk: add VIRTIO_BLK_F_FLUSH features
    
    Should support the flush command only when virtio device support
    feature VIRTIO_BLK_F_FLUSH
    
    Signed-off-by: wangyongrong <wa...@xiaomi.com>
---
 drivers/virtio/virtio-blk.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/drivers/virtio/virtio-blk.c b/drivers/virtio/virtio-blk.c
index e25564fe8d..38965ce5f2 100644
--- a/drivers/virtio/virtio-blk.c
+++ b/drivers/virtio/virtio-blk.c
@@ -41,6 +41,10 @@
 #define VIRTIO_BLK_REQ_HEADER_SIZE  sizeof(struct virtio_blk_req_s)
 #define VIRTIO_BLK_RESP_HEADER_SIZE sizeof(struct virtio_blk_resp_s)
 
+/* Block feature bits */
+
+#define VIRTIO_BLK_F_FLUSH          9  /* Cache flush command support */
+
 /* Block request type */
 
 #define VIRTIO_BLK_T_IN             0  /* READ */
@@ -458,7 +462,10 @@ static int virtio_blk_ioctl(FAR struct inode *inode, int cmd,
   switch (cmd)
     {
       case BIOC_FLUSH:
-        ret = virtio_blk_flush(priv);
+        if (virtio_has_feature(priv->vdev, VIRTIO_BLK_F_FLUSH))
+          {
+            ret = virtio_blk_flush(priv);
+          }
         break;
     }
 
@@ -514,7 +521,7 @@ static int virtio_blk_init(FAR struct virtio_blk_priv_s *priv,
   /* Initialize the virtio device */
 
   virtio_set_status(vdev, VIRTIO_CONFIG_STATUS_DRIVER);
-  virtio_set_features(vdev, 0);
+  virtio_negotiate_features(vdev, 1UL << VIRTIO_BLK_F_FLUSH);
   virtio_set_status(vdev, VIRTIO_CONFIG_FEATURES_OK);
 
   vqname[0]   = "virtio_blk_vq";