[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 05/73] cryptodev: Introduce 'query-cryptodev' QMP command
From: |
Michael S. Tsirkin |
Subject: |
[PULL 05/73] cryptodev: Introduce 'query-cryptodev' QMP command |
Date: |
Tue, 7 Mar 2023 20:11:04 -0500 |
From: zhenwei pi <pizhenwei@bytedance.com>
Now we have a QMP command to query crypto devices:
virsh qemu-monitor-command vm '{"execute": "query-cryptodev"}' | jq
{
"return": [
{
"service": [
"akcipher",
"mac",
"hash",
"cipher"
],
"id": "cryptodev1",
"client": [
{
"queue": 0,
"type": "builtin"
}
]
},
{
"service": [
"akcipher"
],
"id": "cryptodev0",
"client": [
{
"queue": 0,
"type": "lkcf"
}
]
}
],
"id": "libvirt-417"
}
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: zhenwei pi <pizhenwei@bytedance.com>
Message-Id: <20230301105847.253084-6-pizhenwei@bytedance.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
qapi/cryptodev.json | 44 +++++++++++++++++++++++++++++++++++++++++++
backends/cryptodev.c | 45 ++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 89 insertions(+)
diff --git a/qapi/cryptodev.json b/qapi/cryptodev.json
index 8732a30524..f33f96a692 100644
--- a/qapi/cryptodev.json
+++ b/qapi/cryptodev.json
@@ -43,3 +43,47 @@
{ 'enum': 'QCryptodevBackendType',
'prefix': 'QCRYPTODEV_BACKEND_TYPE',
'data': ['builtin', 'vhost-user', 'lkcf']}
+
+##
+# @QCryptodevBackendClient:
+#
+# Information about a queue of crypto device.
+#
+# @queue: the queue index of the crypto device
+#
+# @type: the type of the crypto device
+#
+# Since: 8.0
+##
+{ 'struct': 'QCryptodevBackendClient',
+ 'data': { 'queue': 'uint32',
+ 'type': 'QCryptodevBackendType' } }
+
+##
+# @QCryptodevInfo:
+#
+# Information about a crypto device.
+#
+# @id: the id of the crypto device
+#
+# @service: supported service types of a crypto device
+#
+# @client: the additional infomation of the crypto device
+#
+# Since: 8.0
+##
+{ 'struct': 'QCryptodevInfo',
+ 'data': { 'id': 'str',
+ 'service': ['QCryptodevBackendServiceType'],
+ 'client': ['QCryptodevBackendClient'] } }
+
+##
+# @query-cryptodev:
+#
+# Returns information about current crypto devices.
+#
+# Returns: a list of @QCryptodevInfo
+#
+# Since: 8.0
+##
+{ 'command': 'query-cryptodev', 'returns': ['QCryptodevInfo']}
diff --git a/backends/cryptodev.c b/backends/cryptodev.c
index c2a053db0e..3a45d19823 100644
--- a/backends/cryptodev.c
+++ b/backends/cryptodev.c
@@ -24,6 +24,7 @@
#include "qemu/osdep.h"
#include "sysemu/cryptodev.h"
#include "qapi/error.h"
+#include "qapi/qapi-commands-cryptodev.h"
#include "qapi/visitor.h"
#include "qemu/config-file.h"
#include "qemu/error-report.h"
@@ -33,6 +34,50 @@
static QTAILQ_HEAD(, CryptoDevBackendClient) crypto_clients;
+static int qmp_query_cryptodev_foreach(Object *obj, void *data)
+{
+ CryptoDevBackend *backend;
+ QCryptodevInfoList **infolist = data;
+ uint32_t services, i;
+
+ if (!object_dynamic_cast(obj, TYPE_CRYPTODEV_BACKEND)) {
+ return 0;
+ }
+
+ QCryptodevInfo *info = g_new0(QCryptodevInfo, 1);
+ info->id = g_strdup(object_get_canonical_path_component(obj));
+
+ backend = CRYPTODEV_BACKEND(obj);
+ services = backend->conf.crypto_services;
+ for (i = 0; i < QCRYPTODEV_BACKEND_SERVICE__MAX; i++) {
+ if (services & (1 << i)) {
+ QAPI_LIST_PREPEND(info->service, i);
+ }
+ }
+
+ for (i = 0; i < backend->conf.peers.queues; i++) {
+ CryptoDevBackendClient *cc = backend->conf.peers.ccs[i];
+ QCryptodevBackendClient *client = g_new0(QCryptodevBackendClient, 1);
+
+ client->queue = cc->queue_index;
+ client->type = cc->type;
+ QAPI_LIST_PREPEND(info->client, client);
+ }
+
+ QAPI_LIST_PREPEND(*infolist, info);
+
+ return 0;
+}
+
+QCryptodevInfoList *qmp_query_cryptodev(Error **errp)
+{
+ QCryptodevInfoList *list = NULL;
+ Object *objs = container_get(object_get_root(), "/objects");
+
+ object_child_foreach(objs, qmp_query_cryptodev_foreach, &list);
+
+ return list;
+}
CryptoDevBackendClient *cryptodev_backend_new_client(void)
{
--
MST
- [PULL 00/73] virtio,pc,pci: features, fixes, Michael S. Tsirkin, 2023/03/07
- [PULL 01/73] cryptodev: Introduce cryptodev.json, Michael S. Tsirkin, 2023/03/07
- [PULL 02/73] cryptodev: Remove 'name' & 'model' fields, Michael S. Tsirkin, 2023/03/07
- [PULL 03/73] cryptodev: Introduce cryptodev alg type in QAPI, Michael S. Tsirkin, 2023/03/07
- [PULL 04/73] cryptodev: Introduce server type in QAPI, Michael S. Tsirkin, 2023/03/07
- [PULL 05/73] cryptodev: Introduce 'query-cryptodev' QMP command,
Michael S. Tsirkin <=
- [PULL 06/73] cryptodev-builtin: Detect akcipher capability, Michael S. Tsirkin, 2023/03/07
- [PULL 07/73] hmp: add cryptodev info command, Michael S. Tsirkin, 2023/03/07
- [PULL 08/73] cryptodev: Use CryptoDevBackendOpInfo for operation, Michael S. Tsirkin, 2023/03/07
- [PULL 09/73] cryptodev: Account statistics, Michael S. Tsirkin, 2023/03/07
- [PULL 10/73] cryptodev: support QoS, Michael S. Tsirkin, 2023/03/07
- [PULL 11/73] cryptodev: Support query-stats QMP command, Michael S. Tsirkin, 2023/03/07
- [PULL 12/73] MAINTAINERS: add myself as the maintainer for cryptodev, Michael S. Tsirkin, 2023/03/07
- [PULL 13/73] vdpa net: move iova tree creation from init to start, Michael S. Tsirkin, 2023/03/07
- [PULL 14/73] vdpa: Remember last call fd set, Michael S. Tsirkin, 2023/03/07
- [PULL 15/73] vdpa: Negotiate _F_SUSPEND feature, Michael S. Tsirkin, 2023/03/07