Skip to content

Commit 65848f4

Browse files
Zhu Lingshanmstsirkin
authored andcommitted
vDPA: report virtio-block discarding configuration to user space
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.zhu@intel.com> Message-Id: <20240218185606.13509-8-lingshan.zhu@intel.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
1 parent c9d989b commit 65848f4

2 files changed

Lines changed: 29 additions & 0 deletions

File tree

drivers/vdpa/vdpa.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,6 +1041,29 @@ static int vdpa_dev_blk_topology_config_fill(struct sk_buff *msg, u64 features,
10411041
return 0;
10421042
}
10431043

1044+
static int vdpa_dev_blk_discard_config_fill(struct sk_buff *msg, u64 features,
1045+
const struct virtio_blk_config *config)
1046+
{
1047+
u32 val_u32;
1048+
1049+
if ((features & BIT_ULL(VIRTIO_BLK_F_DISCARD)) == 0)
1050+
return 0;
1051+
1052+
val_u32 = __virtio32_to_cpu(true, config->max_discard_sectors);
1053+
if (nla_put_u32(msg, VDPA_ATTR_DEV_BLK_CFG_MAX_DISCARD_SEC, val_u32))
1054+
return -EMSGSIZE;
1055+
1056+
val_u32 = __virtio32_to_cpu(true, config->max_discard_seg);
1057+
if (nla_put_u32(msg, VDPA_ATTR_DEV_BLK_CFG_MAX_DISCARD_SEG, val_u32))
1058+
return -EMSGSIZE;
1059+
1060+
val_u32 = __virtio32_to_cpu(true, config->discard_sector_alignment);
1061+
if (nla_put_u32(msg, VDPA_ATTR_DEV_BLK_CFG_DISCARD_SEC_ALIGN, val_u32))
1062+
return -EMSGSIZE;
1063+
1064+
return 0;
1065+
}
1066+
10441067
static int vdpa_dev_blk_config_fill(struct vdpa_device *vdev,
10451068
struct sk_buff *msg)
10461069
{
@@ -1073,6 +1096,9 @@ static int vdpa_dev_blk_config_fill(struct vdpa_device *vdev,
10731096
if (vdpa_dev_blk_topology_config_fill(msg, features_device, &config))
10741097
return -EMSGSIZE;
10751098

1099+
if (vdpa_dev_blk_discard_config_fill(msg, features_device, &config))
1100+
return -EMSGSIZE;
1101+
10761102
return 0;
10771103
}
10781104

include/uapi/linux/vdpa.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ enum vdpa_attr {
6565
VDPA_ATTR_DEV_BLK_CFG_ALIGN_OFFSET, /* u8 */
6666
VDPA_ATTR_DEV_BLK_CFG_MIN_IO_SIZE, /* u16 */
6767
VDPA_ATTR_DEV_BLK_CFG_OPT_IO_SIZE, /* u32 */
68+
VDPA_ATTR_DEV_BLK_CFG_MAX_DISCARD_SEC, /* u32 */
69+
VDPA_ATTR_DEV_BLK_CFG_MAX_DISCARD_SEG, /* u32 */
70+
VDPA_ATTR_DEV_BLK_CFG_DISCARD_SEC_ALIGN,/* u32 */
6871

6972
/* new attributes must be added above here */
7073
VDPA_ATTR_MAX,

0 commit comments

Comments
 (0)