From: Laurent Vivier <lvivier@redhat.com>
This new command shows the status of a VirtIODevice
(features, endianness and number of virtqueues)
Next patch will improve output by decoding feature bits.
Signed-off-by: Laurent Vivier <lvivier@redhat.com>
Signed-off-by: Jonah Palmer <jonah.palmer@oracle.com>
---
hw/virtio/virtio-stub.c | 5 ++++
hw/virtio/virtio.c | 50 ++++++++++++++++++++++++++++++++
qapi/virtio.json | 76 +++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 131 insertions(+)
diff --git a/hw/virtio/virtio-stub.c b/hw/virtio/virtio-stub.c
index d4a88f5..ddb592f 100644
--- a/hw/virtio/virtio-stub.c
+++ b/hw/virtio/virtio-stub.c
@@ -12,3 +12,8 @@ VirtioInfoList *qmp_x_debug_query_virtio(Error **errp)
{
return qmp_virtio_unsupported(errp);
}
+
+VirtioStatus *qmp_x_debug_virtio_status(const char* path, Error **errp)
+{
+ return qmp_virtio_unsupported(errp);
+}
diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
index f3fc1bb..222330a 100644
--- a/hw/virtio/virtio.c
+++ b/hw/virtio/virtio.c
@@ -3896,6 +3896,56 @@ VirtioInfoList *qmp_x_debug_query_virtio(Error **errp)
return list;
}
+static VirtIODevice *virtio_device_find(const char *path)
+{
+ VirtIODevice *vdev;
+
+ QTAILQ_FOREACH(vdev, &virtio_list, next) {
+ DeviceState *dev = DEVICE(vdev);
+
+ if (strcmp(dev->canonical_path, path) != 0) {
+ continue;
+ }
+ return vdev;
+ }
+
+ return NULL;
+}
+
+VirtioStatus *qmp_x_debug_virtio_status(const char* path, Error **errp)
+{
+ VirtIODevice *vdev;
+ VirtioStatus *status;
+
+ vdev = virtio_device_find(path);
+ if (vdev == NULL) {
+ error_setg(errp, "Path %s is not a VirtIO device", path);
+ return NULL;
+ }
+
+ status = g_new0(VirtioStatus, 1);
+ status->guest_features = vdev->guest_features;
+ status->host_features = vdev->host_features;
+ status->backend_features = vdev->backend_features;
+ status->device_id = vdev->device_id;
+
+ switch (vdev->device_endian) {
+ case VIRTIO_DEVICE_ENDIAN_LITTLE:
+ status->device_endian = VIRTIO_STATUS_ENDIANNESS_LITTLE;
+ break;
+ case VIRTIO_DEVICE_ENDIAN_BIG:
+ status->device_endian = VIRTIO_STATUS_ENDIANNESS_BIG;
+ break;
+ default:
+ status->device_endian = VIRTIO_STATUS_ENDIANNESS_UNKNOWN;
+ break;
+ }
+
+ status->num_vqs = virtio_get_num_queues(vdev);
+
+ return status;
+}
+
static const TypeInfo virtio_device_info = {
.name = TYPE_VIRTIO_DEVICE,
.parent = TYPE_DEVICE,
diff --git a/qapi/virtio.json b/qapi/virtio.json
index 804adbe..4bd09c9 100644
--- a/qapi/virtio.json
+++ b/qapi/virtio.json
@@ -70,3 +70,79 @@
##
{ 'command': 'x-debug-query-virtio', 'returns': ['VirtioInfo'] }
+
+##
+# @VirtioStatusEndianness:
+#
+# Enumeration of endianness for VirtioDevice
+#
+# Since: 6.1
+##
+{ 'enum': 'VirtioStatusEndianness',
+ 'data': [ 'unknown', 'little', 'big' ]
+}
+
+##
+# @VirtioStatus:
+#
+# @device-id: VirtIODevice status
+#
+# @device-endian: VirtIODevice device_endian
+#
+# @guest-features: VirtIODevice guest_features
+#
+# @host-features: VirtIODevice host_features
+#
+# @backend-features: VirtIODevice backend_features
+#
+# @num-vqs: number of VirtIODevice queues
+#
+# Since: 6.1
+#
+##
+
+{ 'struct': 'VirtioStatus',
+ 'data': {
+ 'device-id': 'int',
+ 'device-endian': 'VirtioStatusEndianness',
+ 'guest-features': 'uint64',
+ 'host-features': 'uint64',
+ 'backend-features': 'uint64',
+ 'num-vqs': 'uint16'
+ }
+}
+
+##
+# @x-debug-virtio-status:
+#
+# Return the status of virtio device
+#
+# @path: QOBject path of the VirtIODevice
+#
+# Returns: status of the VirtIODevice
+#
+# Since: 6.1
+#
+# Example:
+#
+# -> { "execute": "x-debug-virtio-status",
+# "arguments": {
+# "path": "/machine/peripheral-anon/device[3]/virtio-backend"
+# }
+# }
+# <- { "return": {
+# "backend-features": 0,
+# "guest-features": 5111807911,
+# "num-vqs": 3,
+# "host-features": 6337593319,
+# "device-endian": "little",
+# "device-id": 1
+# }
+# }
+#
+##
+
+{ 'command': 'x-debug-virtio-status',
+ 'data': { 'path': 'str' },
+ 'returns': 'VirtioStatus'
+}
--
1.8.3.1
Jonah Palmer <jonah.palmer@oracle.com> writes:
> From: Laurent Vivier <lvivier@redhat.com>
>
> This new command shows the status of a VirtIODevice
> (features, endianness and number of virtqueues)
>
> Next patch will improve output by decoding feature bits.
>
> Signed-off-by: Laurent Vivier <lvivier@redhat.com>
> Signed-off-by: Jonah Palmer <jonah.palmer@oracle.com>
[...]
> diff --git a/qapi/virtio.json b/qapi/virtio.json
> index 804adbe..4bd09c9 100644
> --- a/qapi/virtio.json
> +++ b/qapi/virtio.json
> @@ -70,3 +70,79 @@
> ##
>
> { 'command': 'x-debug-query-virtio', 'returns': ['VirtioInfo'] }
> +
> +##
> +# @VirtioStatusEndianness:
> +#
> +# Enumeration of endianness for VirtioDevice
> +#
> +# Since: 6.1
6.2 now, here, below, and in the remainder of this series.
> +##
> +{ 'enum': 'VirtioStatusEndianness',
> + 'data': [ 'unknown', 'little', 'big' ]
> +}
> +
> +##
> +# @VirtioStatus:
> +#
> +# @device-id: VirtIODevice status
"status"? Really?
> +#
> +# @device-endian: VirtIODevice device_endian
> +#
> +# @guest-features: VirtIODevice guest_features
> +#
> +# @host-features: VirtIODevice host_features
> +#
> +# @backend-features: VirtIODevice backend_features
> +#
> +# @num-vqs: number of VirtIODevice queues
> +#
> +# Since: 6.1
> +#
> +##
> +
> +{ 'struct': 'VirtioStatus',
> + 'data': {
> + 'device-id': 'int',
VirtIODevice member @device_id is uint64_t. Should this be 'uint16'?
> + 'device-endian': 'VirtioStatusEndianness',
> + 'guest-features': 'uint64',
> + 'host-features': 'uint64',
> + 'backend-features': 'uint64',
> + 'num-vqs': 'uint16'
virtio_get_num_queues() returns int. Sure 'uint16' is the right type?
> + }
> +}
> +
> +##
> +# @x-debug-virtio-status:
> +#
> +# Return the status of virtio device
"of a virtio device"
> +#
> +# @path: QOBject path of the VirtIODevice
"QOM path", please.
> +#
> +# Returns: status of the VirtIODevice
> +#
> +# Since: 6.1
> +#
> +# Example:
> +#
> +# -> { "execute": "x-debug-virtio-status",
> +# "arguments": {
> +# "path": "/machine/peripheral-anon/device[3]/virtio-backend"
> +# }
> +# }
> +# <- { "return": {
> +# "backend-features": 0,
> +# "guest-features": 5111807911,
> +# "num-vqs": 3,
> +# "host-features": 6337593319,
> +# "device-endian": "little",
> +# "device-id": 1
> +# }
> +# }
> +#
> +##
> +
> +{ 'command': 'x-debug-virtio-status',
> + 'data': { 'path': 'str' },
> + 'returns': 'VirtioStatus'
> +}
On 8/7/21 8:42 AM, Markus Armbruster wrote:
> Jonah Palmer <jonah.palmer@oracle.com> writes:
>
>> From: Laurent Vivier <lvivier@redhat.com>
>>
>> This new command shows the status of a VirtIODevice
>> (features, endianness and number of virtqueues)
>>
>> Next patch will improve output by decoding feature bits.
>>
>> Signed-off-by: Laurent Vivier <lvivier@redhat.com>
>> Signed-off-by: Jonah Palmer <jonah.palmer@oracle.com>
> [...]
>
>> diff --git a/qapi/virtio.json b/qapi/virtio.json
>> index 804adbe..4bd09c9 100644
>> --- a/qapi/virtio.json
>> +++ b/qapi/virtio.json
>> @@ -70,3 +70,79 @@
>> ##
>>
>> { 'command': 'x-debug-query-virtio', 'returns': ['VirtioInfo'] }
>> +
>> +##
>> +# @VirtioStatusEndianness:
>> +#
>> +# Enumeration of endianness for VirtioDevice
>> +#
>> +# Since: 6.1
> 6.2 now, here, below, and in the remainder of this series.
>
>> +##
>> +{ 'enum': 'VirtioStatusEndianness',
>> + 'data': [ 'unknown', 'little', 'big' ]
>> +}
>> +
>> +##
>> +# @VirtioStatus:
>> +#
>> +# @device-id: VirtIODevice status
> "status"? Really?
I'll change it to 'VirtIODevice ID' instead
>
>> +#
>> +# @device-endian: VirtIODevice device_endian
>> +#
>> +# @guest-features: VirtIODevice guest_features
>> +#
>> +# @host-features: VirtIODevice host_features
>> +#
>> +# @backend-features: VirtIODevice backend_features
>> +#
>> +# @num-vqs: number of VirtIODevice queues
>> +#
>> +# Since: 6.1
>> +#
>> +##
>> +
>> +{ 'struct': 'VirtioStatus',
>> + 'data': {
>> + 'device-id': 'int',
> VirtIODevice member @device_id is uint64_t. Should this be 'uint16'?
Ah, yes this should be uint16. I'll update this.
>
>> + 'device-endian': 'VirtioStatusEndianness',
>> + 'guest-features': 'uint64',
>> + 'host-features': 'uint64',
>> + 'backend-features': 'uint64',
>> + 'num-vqs': 'uint16'
> virtio_get_num_queues() returns int. Sure 'uint16' is the right type?
Yes, you're right, it should be an 'int' instead. I'll also update this.
>
>> + }
>> +}
>> +
>> +##
>> +# @x-debug-virtio-status:
>> +#
>> +# Return the status of virtio device
> "of a virtio device"
Oops! Forgot the article, thank you.
>
>> +#
>> +# @path: QOBject path of the VirtIODevice
> "QOM path", please.
>
>> +#
>> +# Returns: status of the VirtIODevice
>> +#
>> +# Since: 6.1
>> +#
>> +# Example:
>> +#
>> +# -> { "execute": "x-debug-virtio-status",
>> +# "arguments": {
>> +# "path": "/machine/peripheral-anon/device[3]/virtio-backend"
>> +# }
>> +# }
>> +# <- { "return": {
>> +# "backend-features": 0,
>> +# "guest-features": 5111807911,
>> +# "num-vqs": 3,
>> +# "host-features": 6337593319,
>> +# "device-endian": "little",
>> +# "device-id": 1
>> +# }
>> +# }
>> +#
>> +##
>> +
>> +{ 'command': 'x-debug-virtio-status',
>> + 'data': { 'path': 'str' },
>> + 'returns': 'VirtioStatus'
>> +}
On Mon, Jul 12, 2021 at 06:35:33AM -0400, Jonah Palmer wrote:
> From: Laurent Vivier <lvivier@redhat.com>
>
> This new command shows the status of a VirtIODevice
> (features, endianness and number of virtqueues)
>
> Next patch will improve output by decoding feature bits.
>
> Signed-off-by: Laurent Vivier <lvivier@redhat.com>
> Signed-off-by: Jonah Palmer <jonah.palmer@oracle.com>
Do we want to also decode the device status?
E.g. does it have driver, need reset, etc etc?
Also, the internal broken flag?
> ---
> hw/virtio/virtio-stub.c | 5 ++++
> hw/virtio/virtio.c | 50 ++++++++++++++++++++++++++++++++
> qapi/virtio.json | 76 +++++++++++++++++++++++++++++++++++++++++++++++++
> 3 files changed, 131 insertions(+)
>
> diff --git a/hw/virtio/virtio-stub.c b/hw/virtio/virtio-stub.c
> index d4a88f5..ddb592f 100644
> --- a/hw/virtio/virtio-stub.c
> +++ b/hw/virtio/virtio-stub.c
> @@ -12,3 +12,8 @@ VirtioInfoList *qmp_x_debug_query_virtio(Error **errp)
> {
> return qmp_virtio_unsupported(errp);
> }
> +
> +VirtioStatus *qmp_x_debug_virtio_status(const char* path, Error **errp)
> +{
> + return qmp_virtio_unsupported(errp);
> +}
> diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
> index f3fc1bb..222330a 100644
> --- a/hw/virtio/virtio.c
> +++ b/hw/virtio/virtio.c
> @@ -3896,6 +3896,56 @@ VirtioInfoList *qmp_x_debug_query_virtio(Error **errp)
> return list;
> }
>
> +static VirtIODevice *virtio_device_find(const char *path)
> +{
> + VirtIODevice *vdev;
> +
> + QTAILQ_FOREACH(vdev, &virtio_list, next) {
> + DeviceState *dev = DEVICE(vdev);
> +
> + if (strcmp(dev->canonical_path, path) != 0) {
> + continue;
> + }
> + return vdev;
> + }
> +
> + return NULL;
> +}
> +
> +VirtioStatus *qmp_x_debug_virtio_status(const char* path, Error **errp)
> +{
> + VirtIODevice *vdev;
> + VirtioStatus *status;
> +
> + vdev = virtio_device_find(path);
> + if (vdev == NULL) {
> + error_setg(errp, "Path %s is not a VirtIO device", path);
> + return NULL;
> + }
> +
> + status = g_new0(VirtioStatus, 1);
> + status->guest_features = vdev->guest_features;
> + status->host_features = vdev->host_features;
> + status->backend_features = vdev->backend_features;
> + status->device_id = vdev->device_id;
> +
> + switch (vdev->device_endian) {
> + case VIRTIO_DEVICE_ENDIAN_LITTLE:
> + status->device_endian = VIRTIO_STATUS_ENDIANNESS_LITTLE;
> + break;
> + case VIRTIO_DEVICE_ENDIAN_BIG:
> + status->device_endian = VIRTIO_STATUS_ENDIANNESS_BIG;
> + break;
> + default:
> + status->device_endian = VIRTIO_STATUS_ENDIANNESS_UNKNOWN;
> + break;
> + }
> +
> + status->num_vqs = virtio_get_num_queues(vdev);
> +
> + return status;
> +}
> +
> static const TypeInfo virtio_device_info = {
> .name = TYPE_VIRTIO_DEVICE,
> .parent = TYPE_DEVICE,
> diff --git a/qapi/virtio.json b/qapi/virtio.json
> index 804adbe..4bd09c9 100644
> --- a/qapi/virtio.json
> +++ b/qapi/virtio.json
> @@ -70,3 +70,79 @@
> ##
>
> { 'command': 'x-debug-query-virtio', 'returns': ['VirtioInfo'] }
> +
> +##
> +# @VirtioStatusEndianness:
> +#
> +# Enumeration of endianness for VirtioDevice
> +#
> +# Since: 6.1
> +##
> +{ 'enum': 'VirtioStatusEndianness',
> + 'data': [ 'unknown', 'little', 'big' ]
> +}
> +
> +##
> +# @VirtioStatus:
> +#
> +# @device-id: VirtIODevice status
> +#
> +# @device-endian: VirtIODevice device_endian
> +#
> +# @guest-features: VirtIODevice guest_features
> +#
> +# @host-features: VirtIODevice host_features
> +#
> +# @backend-features: VirtIODevice backend_features
> +#
> +# @num-vqs: number of VirtIODevice queues
> +#
> +# Since: 6.1
> +#
> +##
> +
> +{ 'struct': 'VirtioStatus',
> + 'data': {
> + 'device-id': 'int',
> + 'device-endian': 'VirtioStatusEndianness',
> + 'guest-features': 'uint64',
> + 'host-features': 'uint64',
> + 'backend-features': 'uint64',
> + 'num-vqs': 'uint16'
> + }
> +}
> +
> +##
> +# @x-debug-virtio-status:
> +#
> +# Return the status of virtio device
> +#
> +# @path: QOBject path of the VirtIODevice
> +#
> +# Returns: status of the VirtIODevice
> +#
> +# Since: 6.1
> +#
> +# Example:
> +#
> +# -> { "execute": "x-debug-virtio-status",
> +# "arguments": {
> +# "path": "/machine/peripheral-anon/device[3]/virtio-backend"
> +# }
> +# }
> +# <- { "return": {
> +# "backend-features": 0,
> +# "guest-features": 5111807911,
> +# "num-vqs": 3,
> +# "host-features": 6337593319,
> +# "device-endian": "little",
> +# "device-id": 1
> +# }
> +# }
> +#
> +##
> +
> +{ 'command': 'x-debug-virtio-status',
> + 'data': { 'path': 'str' },
> + 'returns': 'VirtioStatus'
> +}
> --
> 1.8.3.1
© 2016 - 2025 Red Hat, Inc.