Skip to content

Commit c2475a9

Browse files
Zhu Lingshanmstsirkin
authored andcommitted
vDPA: report virtio-block capacity to user space
This commit allows userspace to query capacity of a virtio-block device. Signed-off-by: Zhu Lingshan <lingshan.zhu@intel.com> Message-Id: <20240218185606.13509-2-lingshan.zhu@intel.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
1 parent 2b666ee commit c2475a9

3 files changed

Lines changed: 38 additions & 0 deletions

File tree

drivers/vdpa/vdpa.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -944,6 +944,38 @@ static int vdpa_dev_net_config_fill(struct vdpa_device *vdev, struct sk_buff *ms
944944
return vdpa_dev_net_mq_config_fill(msg, features_device, &config);
945945
}
946946

947+
static int
948+
vdpa_dev_blk_capacity_config_fill(struct sk_buff *msg,
949+
const struct virtio_blk_config *config)
950+
{
951+
u64 val_u64;
952+
953+
val_u64 = __virtio64_to_cpu(true, config->capacity);
954+
955+
return nla_put_u64_64bit(msg, VDPA_ATTR_DEV_BLK_CFG_CAPACITY,
956+
val_u64, VDPA_ATTR_PAD);
957+
}
958+
959+
static int vdpa_dev_blk_config_fill(struct vdpa_device *vdev,
960+
struct sk_buff *msg)
961+
{
962+
struct virtio_blk_config config = {};
963+
u64 features_device;
964+
965+
vdev->config->get_config(vdev, 0, &config, sizeof(config));
966+
967+
features_device = vdev->config->get_device_features(vdev);
968+
969+
if (nla_put_u64_64bit(msg, VDPA_ATTR_DEV_FEATURES, features_device,
970+
VDPA_ATTR_PAD))
971+
return -EMSGSIZE;
972+
973+
if (vdpa_dev_blk_capacity_config_fill(msg, &config))
974+
return -EMSGSIZE;
975+
976+
return 0;
977+
}
978+
947979
static int
948980
vdpa_dev_config_fill(struct vdpa_device *vdev, struct sk_buff *msg, u32 portid, u32 seq,
949981
int flags, struct netlink_ext_ack *extack)
@@ -988,6 +1020,9 @@ vdpa_dev_config_fill(struct vdpa_device *vdev, struct sk_buff *msg, u32 portid,
9881020
case VIRTIO_ID_NET:
9891021
err = vdpa_dev_net_config_fill(vdev, msg);
9901022
break;
1023+
case VIRTIO_ID_BLOCK:
1024+
err = vdpa_dev_blk_config_fill(vdev, msg);
1025+
break;
9911026
default:
9921027
err = -EOPNOTSUPP;
9931028
break;

include/linux/vdpa.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <linux/interrupt.h>
88
#include <linux/vhost_iotlb.h>
99
#include <linux/virtio_net.h>
10+
#include <linux/virtio_blk.h>
1011
#include <linux/if_ether.h>
1112

1213
/**

include/uapi/linux/vdpa.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ enum vdpa_attr {
5656
/* virtio features that are provisioned to the vDPA device */
5757
VDPA_ATTR_DEV_FEATURES, /* u64 */
5858

59+
VDPA_ATTR_DEV_BLK_CFG_CAPACITY, /* u64 */
60+
5961
/* new attributes must be added above here */
6062
VDPA_ATTR_MAX,
6163
};

0 commit comments

Comments
 (0)