This commit reports virtio-blk discarding configuration
to user space,includes:
1) the maximum discard sectors
2) maximum number of discard segments for the block driver to use
3) the alignment for splitting a discarding request

Signed-off-by: Zhu Lingshan <lingshan....@intel.com>
---
 drivers/vdpa/vdpa.c       | 26 ++++++++++++++++++++++++++
 include/uapi/linux/vdpa.h |  3 +++
 2 files changed, 29 insertions(+)

diff --git a/drivers/vdpa/vdpa.c b/drivers/vdpa/vdpa.c
index dfd9aa5779dc..bf3fa90908a7 100644
--- a/drivers/vdpa/vdpa.c
+++ b/drivers/vdpa/vdpa.c
@@ -1041,6 +1041,29 @@ static int vdpa_dev_blk_topology_config_fill(struct 
sk_buff *msg, u64 features,
        return 0;
 }
 
+static int vdpa_dev_blk_discard_config_fill(struct sk_buff *msg, u64 features,
+                                      const struct virtio_blk_config *config)
+{
+       u32 val_u32;
+
+       if ((features & BIT_ULL(VIRTIO_BLK_F_DISCARD)) == 0)
+               return 0;
+
+       val_u32 = __virtio32_to_cpu(true, config->max_discard_sectors);
+       if (nla_put_u32(msg, VDPA_ATTR_DEV_BLK_CFG_MAX_DISCARD_SEC, val_u32))
+               return -EMSGSIZE;
+
+       val_u32 = __virtio32_to_cpu(true, config->max_discard_seg);
+       if (nla_put_u32(msg, VDPA_ATTR_DEV_BLK_CFG_MAX_DISCARD_SEG, val_u32))
+               return -EMSGSIZE;
+
+       val_u32 = __virtio32_to_cpu(true, config->discard_sector_alignment);
+       if (nla_put_u32(msg, VDPA_ATTR_DEV_BLK_CFG_DISCARD_SEC_ALIGN, val_u32))
+               return -EMSGSIZE;
+
+       return 0;
+}
+
 static int vdpa_dev_blk_config_fill(struct vdpa_device *vdev,
                                    struct sk_buff *msg)
 {
@@ -1073,6 +1096,9 @@ static int vdpa_dev_blk_config_fill(struct vdpa_device 
*vdev,
        if (vdpa_dev_blk_topology_config_fill(msg, features_device, &config))
                return -EMSGSIZE;
 
+       if (vdpa_dev_blk_discard_config_fill(msg, features_device, &config))
+               return -EMSGSIZE;
+
        return 0;
 }
 
diff --git a/include/uapi/linux/vdpa.h b/include/uapi/linux/vdpa.h
index 5cc70614c97a..30887931a220 100644
--- a/include/uapi/linux/vdpa.h
+++ b/include/uapi/linux/vdpa.h
@@ -65,6 +65,9 @@ enum vdpa_attr {
        VDPA_ATTR_DEV_BLK_CFG_ALIGN_OFFSET,     /* u8 */
        VDPA_ATTR_DEV_BLK_CFG_MIN_IO_SIZE,      /* u16 */
        VDPA_ATTR_DEV_BLK_CFG_OPT_IO_SIZE,      /* u32 */
+       VDPA_ATTR_DEV_BLK_CFG_MAX_DISCARD_SEC,  /* u32 */
+       VDPA_ATTR_DEV_BLK_CFG_MAX_DISCARD_SEG,  /* u32 */
+       VDPA_ATTR_DEV_BLK_CFG_DISCARD_SEC_ALIGN,/* u32 */
 
        /* new attributes must be added above here */
        VDPA_ATTR_MAX,
-- 
2.39.3


Reply via email to