virtualization.lists.linux-foundation.org archive mirror
 help / color / mirror / Atom feed
From: Zhu Lingshan <lingshan.zhu@intel.com>
To: jasowang@redhat.com, mst@redhat.com
Cc: virtualization@lists.linux.dev, Zhu Lingshan <lingshan.zhu@intel.com>
Subject: [PATCH 01/10] vDPA: report virtio-block capacity to user space
Date: Mon, 19 Feb 2024 02:55:57 +0800	[thread overview]
Message-ID: <20240218185606.13509-2-lingshan.zhu@intel.com> (raw)
In-Reply-To: <20240218185606.13509-1-lingshan.zhu@intel.com>

This commit allows userspace to query capacity of
a virtio-block device.

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

diff --git a/drivers/vdpa/vdpa.c b/drivers/vdpa/vdpa.c
index d0695680b282..d5ccb618de2b 100644
--- a/drivers/vdpa/vdpa.c
+++ b/drivers/vdpa/vdpa.c
@@ -944,6 +944,38 @@ static int vdpa_dev_net_config_fill(struct vdpa_device *vdev, struct sk_buff *ms
 	return vdpa_dev_net_mq_config_fill(msg, features_device, &config);
 }
 
+static int
+vdpa_dev_blk_capacity_config_fill(struct sk_buff *msg,
+				  const struct virtio_blk_config *config)
+{
+	u64 val_u64;
+
+	val_u64 = __virtio64_to_cpu(true, config->capacity);
+
+	return nla_put_u64_64bit(msg, VDPA_ATTR_DEV_BLK_CFG_CAPACITY,
+				 val_u64, VDPA_ATTR_PAD);
+}
+
+static int vdpa_dev_blk_config_fill(struct vdpa_device *vdev,
+				    struct sk_buff *msg)
+{
+	struct virtio_blk_config config = {};
+	u64 features_device;
+
+	vdev->config->get_config(vdev, 0, &config, sizeof(config));
+
+	features_device = vdev->config->get_device_features(vdev);
+
+	if (nla_put_u64_64bit(msg, VDPA_ATTR_DEV_FEATURES, features_device,
+			      VDPA_ATTR_PAD))
+		return -EMSGSIZE;
+
+	if (vdpa_dev_blk_capacity_config_fill(msg, &config))
+		return -EMSGSIZE;
+
+	return 0;
+}
+
 static int
 vdpa_dev_config_fill(struct vdpa_device *vdev, struct sk_buff *msg, u32 portid, u32 seq,
 		     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,
 	case VIRTIO_ID_NET:
 		err = vdpa_dev_net_config_fill(vdev, msg);
 		break;
+	case VIRTIO_ID_BLOCK:
+		err = vdpa_dev_blk_config_fill(vdev, msg);
+		break;
 	default:
 		err = -EOPNOTSUPP;
 		break;
diff --git a/include/linux/vdpa.h b/include/linux/vdpa.h
index db15ac07f8a6..a184aa6538cb 100644
--- a/include/linux/vdpa.h
+++ b/include/linux/vdpa.h
@@ -7,6 +7,7 @@
 #include <linux/interrupt.h>
 #include <linux/vhost_iotlb.h>
 #include <linux/virtio_net.h>
+#include <linux/virtio_blk.h>
 #include <linux/if_ether.h>
 
 /**
diff --git a/include/uapi/linux/vdpa.h b/include/uapi/linux/vdpa.h
index 54b649ab0f22..1bf69226cb96 100644
--- a/include/uapi/linux/vdpa.h
+++ b/include/uapi/linux/vdpa.h
@@ -56,6 +56,8 @@ enum vdpa_attr {
 	/* virtio features that are provisioned to the vDPA device */
 	VDPA_ATTR_DEV_FEATURES,                 /* u64 */
 
+	VDPA_ATTR_DEV_BLK_CFG_CAPACITY,		/* u64 */
+
 	/* new attributes must be added above here */
 	VDPA_ATTR_MAX,
 };
-- 
2.39.3


  reply	other threads:[~2024-02-18 10:55 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-18 18:55 [PATCH 00/10] vDPA: allow userspace query virito-block device Zhu Lingshan
2024-02-18 18:55 ` Zhu Lingshan [this message]
2024-03-19 16:43   ` [PATCH 01/10] vDPA: report virtio-block capacity to user space Stefano Garzarella
2024-02-18 18:55 ` [PATCH 02/10] vDPA: report virtio-block max segment size " Zhu Lingshan
2024-03-19 16:04   ` Stefano Garzarella
2024-03-29 14:48     ` Zhu, Lingshan
2024-03-31 20:03       ` Michael S. Tsirkin
2024-02-18 18:55 ` [PATCH 03/10] vDPA: report virtio-block block-size " Zhu Lingshan
2024-03-19 16:43   ` Stefano Garzarella
2024-02-18 18:56 ` [PATCH 04/10] vDPA: report virtio-block max segments in a request " Zhu Lingshan
2024-03-19 16:43   ` Stefano Garzarella
2024-02-18 18:56 ` [PATCH 05/10] vDPA: report virtio-block MQ info " Zhu Lingshan
2024-03-19 16:44   ` Stefano Garzarella
2024-02-18 18:56 ` [PATCH 06/10] vDPA: report virtio-block topology " Zhu Lingshan
2024-03-19 16:44   ` Stefano Garzarella
2024-02-18 18:56 ` [PATCH 07/10] vDPA: report virtio-block discarding configuration " Zhu Lingshan
2024-03-19 16:44   ` Stefano Garzarella
2024-02-18 18:56 ` [PATCH 08/10] vDPA: report virtio-block write zeroes " Zhu Lingshan
2024-03-19 16:36   ` Stefano Garzarella
2024-03-19 17:02     ` Michael S. Tsirkin
2024-03-19 17:08       ` Stefano Garzarella
2024-03-19 17:57         ` Michael S. Tsirkin
2024-02-18 18:56 ` [PATCH 09/10] vDPA: report virtio-block read-only info " Zhu Lingshan
2024-03-19 16:40   ` Stefano Garzarella
2024-04-09  8:37     ` Zhu, Lingshan
2024-05-03 12:18       ` Stefano Garzarella
2024-02-18 18:56 ` [PATCH 10/10] vDPA: report virtio-blk flush " Zhu Lingshan
2024-03-19 16:42   ` Stefano Garzarella
2024-03-19  6:39 ` [PATCH 00/10] vDPA: allow userspace query virito-block device Michael S. Tsirkin
2024-03-20  3:30   ` Jason Wang
2024-03-20  7:00     ` Michael S. Tsirkin
2024-03-19 16:49 ` Stefano Garzarella
2024-03-20 10:31   ` Zhu, Lingshan
2024-03-20 10:53     ` Stefano Garzarella

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240218185606.13509-2-lingshan.zhu@intel.com \
    --to=lingshan.zhu@intel.com \
    --cc=jasowang@redhat.com \
    --cc=mst@redhat.com \
    --cc=virtualization@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).