diff mbox series

[RFC,3/5] qmp: add QMP command virtio-queue-status

Message ID 20200402100302.833267-4-lvivier@redhat.com (mailing list archive)
State New, archived
Headers show
Series hmp,qmp: Add some commands to introspect virtio devices | expand

Commit Message

Laurent Vivier April 2, 2020, 10:03 a.m. UTC
This new command shows internal status of a VirtQueue.
(vrings and indexes).

Signed-off-by: Laurent Vivier <lvivier@redhat.com>
---
 hw/virtio/virtio-stub.c |  6 +++
 hw/virtio/virtio.c      | 35 +++++++++++++++
 qapi/virtio.json        | 98 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 139 insertions(+)

Comments

Eric Blake April 2, 2020, 2:30 p.m. UTC | #1
On 4/2/20 5:03 AM, Laurent Vivier wrote:
> This new command shows internal status of a VirtQueue.
> (vrings and indexes).
> 
> Signed-off-by: Laurent Vivier <lvivier@redhat.com>
> ---
>   hw/virtio/virtio-stub.c |  6 +++
>   hw/virtio/virtio.c      | 35 +++++++++++++++
>   qapi/virtio.json        | 98 +++++++++++++++++++++++++++++++++++++++++
>   3 files changed, 139 insertions(+)
> 

> +++ b/qapi/virtio.json
> @@ -117,3 +117,101 @@
>     'data': { 'path': 'str' },
>     'returns': 'VirtioStatus'
>   }
> +
> +##
> +# @VirtQueueStatus:
> +#
> +# Status of a VirtQueue
> +#
> +# @queue_index: VirtQueue queue_index

More naming conventions.  queue-index.  I'll quit pointing them out, but 
the whole series should be scrubbed.


> +# Example:
> +#
> +# -> { "execute": "virtio-queue-status",
> +#      "arguments": {
> +#          "path": "/machine/peripheral-anon/device[3]/virtio-backend",
> +#          "queue": 0
> +#      }
> +#   }
> +# <- { "return": {
> +#      "signalled_used": 373,

Of course, if you fix the naming conventions, you'll also need to 
regenerate the examples.

Hmm, it's a bit annoying that our current QMP output is 
non-deterministic.  It doesn't affect correctness, but it would be nice 
if our output was in the same order as our declaration.  Not the fault 
of your patch, nor something you need to worry about.
diff mbox series

Patch

diff --git a/hw/virtio/virtio-stub.c b/hw/virtio/virtio-stub.c
index 8fe2d6cd8892..5b4ed6fd531e 100644
--- a/hw/virtio/virtio-stub.c
+++ b/hw/virtio/virtio-stub.c
@@ -17,3 +17,9 @@  VirtioStatus *qmp_virtio_status(const char* path, Error **errp)
 {
     return qmp_virtio_unsupported(errp);
 }
+
+VirtQueueStatus *qmp_virtio_queue_status(const char *path, uint16_t queue,
+                                         Error **errp)
+{
+    return qmp_virtio_unsupported(errp);
+}
diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
index 7f6e21e4ab2c..271d4ca3417f 100644
--- a/hw/virtio/virtio.c
+++ b/hw/virtio/virtio.c
@@ -3855,6 +3855,41 @@  static VirtIODevice *virtio_device_find(const char *path)
     return NULL;
 }
 
+VirtQueueStatus *qmp_virtio_queue_status(const char *path, uint16_t queue,
+                                         Error **errp)
+{
+    VirtIODevice *vdev;
+    VirtQueueStatus *status;
+
+    vdev = virtio_device_find(path);
+    if (vdev == NULL) {
+        error_setg(errp, "Path %s is not a VirtIO device", path);
+        return NULL;
+    }
+
+    if (queue >= VIRTIO_QUEUE_MAX || !virtio_queue_get_num(vdev, queue)) {
+        error_setg(errp, "Invalid virtqueue number %d", queue);
+        return NULL;
+    }
+
+    status = g_new0(VirtQueueStatus, 1);
+    status->queue_index = vdev->vq[queue].queue_index;
+    status->inuse = vdev->vq[queue].inuse;
+    status->vring_num = vdev->vq[queue].vring.num;
+    status->vring_num_default = vdev->vq[queue].vring.num_default;
+    status->vring_align = vdev->vq[queue].vring.align;
+    status->vring_desc = vdev->vq[queue].vring.desc;
+    status->vring_avail = vdev->vq[queue].vring.avail;
+    status->vring_used = vdev->vq[queue].vring.used;
+    status->last_avail_idx = vdev->vq[queue].last_avail_idx;
+    status->shadow_avail_idx = vdev->vq[queue].shadow_avail_idx;
+    status->used_idx = vdev->vq[queue].used_idx;
+    status->signalled_used = vdev->vq[queue].signalled_used;
+    status->signalled_used_valid = vdev->vq[queue].signalled_used_valid;
+
+    return status;
+}
+
 VirtioStatus *qmp_virtio_status(const char* path, Error **errp)
 {
     VirtIODevice *vdev;
diff --git a/qapi/virtio.json b/qapi/virtio.json
index 2af4d95b9893..ab70500d919b 100644
--- a/qapi/virtio.json
+++ b/qapi/virtio.json
@@ -117,3 +117,101 @@ 
   'data': { 'path': 'str' },
   'returns': 'VirtioStatus'
 }
+
+##
+# @VirtQueueStatus:
+#
+# Status of a VirtQueue
+#
+# @queue_index: VirtQueue queue_index
+#
+# @inuse: VirtQueue inuse
+#
+# @vring_num: VirtQueue vring.num
+#
+# @vring_num_default: VirtQueue vring.num_default
+#
+# @vring_align: VirtQueue vring.align
+#
+# @vring_desc: VirtQueue vring.desc
+#
+# @vring_avail: VirtQueue vring.avail
+#
+# @vring_used: VirtQueue vring.used
+#
+# @last_avail_idx: VirtQueue last_avail_idx
+#
+# @shadow_avail_idx: VirtQueue shadow_avail_idx
+#
+# @used_idx: VirtQueue used_idx
+#
+# @signalled_used: VirtQueue signalled_used
+#
+# @signalled_used_valid: VirtQueue signalled_used_valid
+#
+# Since: 5.1
+#
+##
+
+{ 'struct': 'VirtQueueStatus',
+  'data': {
+    'queue_index': 'uint16',
+    'inuse': 'uint32',
+    'vring_num': 'int',
+    'vring_num_default': 'int',
+    'vring_align': 'int',
+    'vring_desc': 'uint64',
+    'vring_avail': 'uint64',
+    'vring_used': 'uint64',
+    'last_avail_idx': 'uint16',
+    'shadow_avail_idx': 'uint16',
+    'used_idx': 'uint16',
+    'signalled_used': 'uint16',
+    'signalled_used_valid': 'uint16'
+  }
+}
+
+##
+# @virtio-queue-status:
+#
+# Return the status of a given VirtQueue
+#
+# @path: QOBject path of the VirtIODevice
+#
+# @queue: queue number to examine
+#
+# Returns: Status of the VirtQueue
+#
+# Since: 5.1
+#
+# Example:
+#
+# -> { "execute": "virtio-queue-status",
+#      "arguments": {
+#          "path": "/machine/peripheral-anon/device[3]/virtio-backend",
+#          "queue": 0
+#      }
+#   }
+# <- { "return": {
+#      "signalled_used": 373,
+#      "inuse": 0,
+#      "vring_desc": 864411648,
+#      "vring_num_default": 256,
+#      "signalled_used_valid": 1,
+#      "vring_avail": 864415744,
+#      "last_avail_idx": 373,
+#      "queue_index": 0,
+#      "vring_used": 864416320,
+#      "shadow_avail_idx": 619,
+#      "used_idx": 373,
+#      "vring_num": 256,
+#      "vring_align": 4096
+#      }
+#    }
+#
+##
+
+{ 'command': 'virtio-queue-status',
+  'data': { 'path': 'str', 'queue': 'uint16' },
+  'returns': 'VirtQueueStatus'
+}