diff mbox series

[v5,07/12] hmp: add cryptodev info command

Message ID 20230301025124.3605557-8-pizhenwei@bytedance.com (mailing list archive)
State New, archived
Headers show
Series Refactor cryptodev | expand

Commit Message

zhenwei pi March 1, 2023, 2:51 a.m. UTC
Example of this command:
 # virsh qemu-monitor-command vm --hmp info cryptodev
cryptodev1: service=[akcipher|mac|hash|cipher]
    queue 0: type=builtin
cryptodev0: service=[akcipher]
    queue 0: type=lkcf

Signed-off-by: zhenwei pi <pizhenwei@bytedance.com>
---
 backends/cryptodev-hmp-cmds.c | 54 +++++++++++++++++++++++++++++++++++
 backends/meson.build          |  1 +
 hmp-commands-info.hx          | 14 +++++++++
 include/monitor/hmp.h         |  1 +
 4 files changed, 70 insertions(+)
 create mode 100644 backends/cryptodev-hmp-cmds.c

Comments

Daniel P. Berrangé March 1, 2023, 9:38 a.m. UTC | #1
On Wed, Mar 01, 2023 at 10:51:19AM +0800, zhenwei pi wrote:
> Example of this command:
>  # virsh qemu-monitor-command vm --hmp info cryptodev
> cryptodev1: service=[akcipher|mac|hash|cipher]
>     queue 0: type=builtin
> cryptodev0: service=[akcipher]
>     queue 0: type=lkcf
> 
> Signed-off-by: zhenwei pi <pizhenwei@bytedance.com>
> ---
>  backends/cryptodev-hmp-cmds.c | 54 +++++++++++++++++++++++++++++++++++
>  backends/meson.build          |  1 +
>  hmp-commands-info.hx          | 14 +++++++++
>  include/monitor/hmp.h         |  1 +
>  4 files changed, 70 insertions(+)
>  create mode 100644 backends/cryptodev-hmp-cmds.c

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>


With regards,
Daniel
Dr. David Alan Gilbert March 1, 2023, 10:40 a.m. UTC | #2
* zhenwei pi (pizhenwei@bytedance.com) wrote:
> Example of this command:
>  # virsh qemu-monitor-command vm --hmp info cryptodev
> cryptodev1: service=[akcipher|mac|hash|cipher]
>     queue 0: type=builtin
> cryptodev0: service=[akcipher]
>     queue 0: type=lkcf
> 
> Signed-off-by: zhenwei pi <pizhenwei@bytedance.com>

Acked-by: Dr. David Alan Gilbert <dgilbert@redhat.com>

> ---
>  backends/cryptodev-hmp-cmds.c | 54 +++++++++++++++++++++++++++++++++++
>  backends/meson.build          |  1 +
>  hmp-commands-info.hx          | 14 +++++++++
>  include/monitor/hmp.h         |  1 +
>  4 files changed, 70 insertions(+)
>  create mode 100644 backends/cryptodev-hmp-cmds.c
> 
> diff --git a/backends/cryptodev-hmp-cmds.c b/backends/cryptodev-hmp-cmds.c
> new file mode 100644
> index 0000000000..4f7220bb13
> --- /dev/null
> +++ b/backends/cryptodev-hmp-cmds.c
> @@ -0,0 +1,54 @@
> +/*
> + * HMP commands related to cryptodev
> + *
> + * Copyright (c) 2023 Bytedance.Inc
> + *
> + * Authors:
> + *    zhenwei pi<pizhenwei@bytedance.com>
> + *
> + * This work is licensed under the terms of the GNU GPL, version 2 or
> + * (at your option) any later version.
> + */
> +
> +#include "qemu/osdep.h"
> +#include "monitor/hmp.h"
> +#include "monitor/monitor.h"
> +#include "qapi/qapi-commands-cryptodev.h"
> +#include "qapi/qmp/qdict.h"
> +
> +
> +void hmp_info_cryptodev(Monitor *mon, const QDict *qdict)
> +{
> +    QCryptodevInfoList *il;
> +    QCryptodevBackendServiceTypeList *sl;
> +    QCryptodevBackendClientList *cl;
> +
> +    for (il = qmp_query_cryptodev(NULL); il; il = il->next) {
> +        g_autofree char *services = NULL;
> +        QCryptodevInfo *info = il->value;
> +        char *tmp_services;
> +
> +        /* build a string like 'service=[akcipher|mac|hash|cipher]' */
> +        for (sl = info->service; sl; sl = sl->next) {
> +            const char *service = QCryptodevBackendServiceType_str(sl->value);
> +
> +            if (!services) {
> +                services = g_strdup(service);
> +            } else {
> +                tmp_services = g_strjoin("|", services, service, NULL);
> +                g_free(services);
> +                services = tmp_services;
> +            }
> +        }
> +        monitor_printf(mon, "%s: service=[%s]\n", info->id, services);
> +
> +        for (cl = info->client; cl; cl = cl->next) {
> +            QCryptodevBackendClient *client = cl->value;
> +            monitor_printf(mon, "    queue %" PRIu32 ": type=%s\n",
> +                           client->queue,
> +                           QCryptodevBackendType_str(client->type));
> +        }
> +    }
> +
> +    qapi_free_QCryptodevInfoList(il);
> +}
> diff --git a/backends/meson.build b/backends/meson.build
> index 954e658b25..b369e0a9d0 100644
> --- a/backends/meson.build
> +++ b/backends/meson.build
> @@ -1,5 +1,6 @@
>  softmmu_ss.add([files(
>    'cryptodev-builtin.c',
> +  'cryptodev-hmp-cmds.c',
>    'cryptodev.c',
>    'hostmem-ram.c',
>    'hostmem.c',
> diff --git a/hmp-commands-info.hx b/hmp-commands-info.hx
> index 754b1e8408..47d63d26db 100644
> --- a/hmp-commands-info.hx
> +++ b/hmp-commands-info.hx
> @@ -993,3 +993,17 @@ SRST
>    ``info virtio-queue-element`` *path* *queue* [*index*]
>      Display element of a given virtio queue
>  ERST
> +
> +    {
> +        .name       = "cryptodev",
> +        .args_type  = "",
> +        .params     = "",
> +        .help       = "show the crypto devices",
> +        .cmd        = hmp_info_cryptodev,
> +        .flags      = "p",
> +    },
> +
> +SRST
> +  ``info cryptodev``
> +    Show the crypto devices.
> +ERST
> diff --git a/include/monitor/hmp.h b/include/monitor/hmp.h
> index 2220f14fc9..e6cf0b7aa7 100644
> --- a/include/monitor/hmp.h
> +++ b/include/monitor/hmp.h
> @@ -178,5 +178,6 @@ void hmp_ioport_read(Monitor *mon, const QDict *qdict);
>  void hmp_ioport_write(Monitor *mon, const QDict *qdict);
>  void hmp_boot_set(Monitor *mon, const QDict *qdict);
>  void hmp_info_mtree(Monitor *mon, const QDict *qdict);
> +void hmp_info_cryptodev(Monitor *mon, const QDict *qdict);
>  
>  #endif
> -- 
> 2.34.1
>
Dr. David Alan Gilbert March 1, 2023, 10:47 a.m. UTC | #3
* zhenwei pi (pizhenwei@bytedance.com) wrote:
> Example of this command:
>  # virsh qemu-monitor-command vm --hmp info cryptodev
> cryptodev1: service=[akcipher|mac|hash|cipher]
>     queue 0: type=builtin
> cryptodev0: service=[akcipher]
>     queue 0: type=lkcf
> 
> Signed-off-by: zhenwei pi <pizhenwei@bytedance.com>

Yes, I think that's fine from HMP; you might want to use some of the
qapi list macros;


Acked-by: Dr. David Alan Gilbert <dgilbert@redhat.com>

> ---
>  backends/cryptodev-hmp-cmds.c | 54 +++++++++++++++++++++++++++++++++++
>  backends/meson.build          |  1 +
>  hmp-commands-info.hx          | 14 +++++++++
>  include/monitor/hmp.h         |  1 +
>  4 files changed, 70 insertions(+)
>  create mode 100644 backends/cryptodev-hmp-cmds.c
> 
> diff --git a/backends/cryptodev-hmp-cmds.c b/backends/cryptodev-hmp-cmds.c
> new file mode 100644
> index 0000000000..4f7220bb13
> --- /dev/null
> +++ b/backends/cryptodev-hmp-cmds.c
> @@ -0,0 +1,54 @@
> +/*
> + * HMP commands related to cryptodev
> + *
> + * Copyright (c) 2023 Bytedance.Inc
> + *
> + * Authors:
> + *    zhenwei pi<pizhenwei@bytedance.com>
> + *
> + * This work is licensed under the terms of the GNU GPL, version 2 or
> + * (at your option) any later version.
> + */
> +
> +#include "qemu/osdep.h"
> +#include "monitor/hmp.h"
> +#include "monitor/monitor.h"
> +#include "qapi/qapi-commands-cryptodev.h"
> +#include "qapi/qmp/qdict.h"
> +
> +
> +void hmp_info_cryptodev(Monitor *mon, const QDict *qdict)
> +{
> +    QCryptodevInfoList *il;
> +    QCryptodevBackendServiceTypeList *sl;
> +    QCryptodevBackendClientList *cl;
> +
> +    for (il = qmp_query_cryptodev(NULL); il; il = il->next) {
> +        g_autofree char *services = NULL;
> +        QCryptodevInfo *info = il->value;
> +        char *tmp_services;
> +
> +        /* build a string like 'service=[akcipher|mac|hash|cipher]' */
> +        for (sl = info->service; sl; sl = sl->next) {
> +            const char *service = QCryptodevBackendServiceType_str(sl->value);
> +
> +            if (!services) {
> +                services = g_strdup(service);
> +            } else {
> +                tmp_services = g_strjoin("|", services, service, NULL);
> +                g_free(services);
> +                services = tmp_services;
> +            }
> +        }
> +        monitor_printf(mon, "%s: service=[%s]\n", info->id, services);
> +
> +        for (cl = info->client; cl; cl = cl->next) {
> +            QCryptodevBackendClient *client = cl->value;
> +            monitor_printf(mon, "    queue %" PRIu32 ": type=%s\n",
> +                           client->queue,
> +                           QCryptodevBackendType_str(client->type));
> +        }
> +    }
> +
> +    qapi_free_QCryptodevInfoList(il);
> +}
> diff --git a/backends/meson.build b/backends/meson.build
> index 954e658b25..b369e0a9d0 100644
> --- a/backends/meson.build
> +++ b/backends/meson.build
> @@ -1,5 +1,6 @@
>  softmmu_ss.add([files(
>    'cryptodev-builtin.c',
> +  'cryptodev-hmp-cmds.c',
>    'cryptodev.c',
>    'hostmem-ram.c',
>    'hostmem.c',
> diff --git a/hmp-commands-info.hx b/hmp-commands-info.hx
> index 754b1e8408..47d63d26db 100644
> --- a/hmp-commands-info.hx
> +++ b/hmp-commands-info.hx
> @@ -993,3 +993,17 @@ SRST
>    ``info virtio-queue-element`` *path* *queue* [*index*]
>      Display element of a given virtio queue
>  ERST
> +
> +    {
> +        .name       = "cryptodev",
> +        .args_type  = "",
> +        .params     = "",
> +        .help       = "show the crypto devices",
> +        .cmd        = hmp_info_cryptodev,
> +        .flags      = "p",
> +    },
> +
> +SRST
> +  ``info cryptodev``
> +    Show the crypto devices.
> +ERST
> diff --git a/include/monitor/hmp.h b/include/monitor/hmp.h
> index 2220f14fc9..e6cf0b7aa7 100644
> --- a/include/monitor/hmp.h
> +++ b/include/monitor/hmp.h
> @@ -178,5 +178,6 @@ void hmp_ioport_read(Monitor *mon, const QDict *qdict);
>  void hmp_ioport_write(Monitor *mon, const QDict *qdict);
>  void hmp_boot_set(Monitor *mon, const QDict *qdict);
>  void hmp_info_mtree(Monitor *mon, const QDict *qdict);
> +void hmp_info_cryptodev(Monitor *mon, const QDict *qdict);
>  
>  #endif
> -- 
> 2.34.1
>
zhenwei pi March 2, 2023, 1:06 a.m. UTC | #4
On 3/1/23 18:47, Dr. David Alan Gilbert wrote:
> * zhenwei pi (pizhenwei@bytedance.com) wrote:
>> Example of this command:
>>   # virsh qemu-monitor-command vm --hmp info cryptodev
>> cryptodev1: service=[akcipher|mac|hash|cipher]
>>      queue 0: type=builtin
>> cryptodev0: service=[akcipher]
>>      queue 0: type=lkcf
>>
>> Signed-off-by: zhenwei pi <pizhenwei@bytedance.com>
> 
> Yes, I think that's fine from HMP; you might want to use some of the
> qapi list macros;
> 
> 
> Acked-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
> 

Sorry, I missed this in the v6 series. I prefer a followup patch to do 
this minor change, or in the next version(if there is any problem in the 
v6 version).

Thanks!

>> ---
>>   backends/cryptodev-hmp-cmds.c | 54 +++++++++++++++++++++++++++++++++++
>>   backends/meson.build          |  1 +
>>   hmp-commands-info.hx          | 14 +++++++++
>>   include/monitor/hmp.h         |  1 +
>>   4 files changed, 70 insertions(+)
>>   create mode 100644 backends/cryptodev-hmp-cmds.c
>>
>> diff --git a/backends/cryptodev-hmp-cmds.c b/backends/cryptodev-hmp-cmds.c
>> new file mode 100644
>> index 0000000000..4f7220bb13
>> --- /dev/null
>> +++ b/backends/cryptodev-hmp-cmds.c
>> @@ -0,0 +1,54 @@
>> +/*
>> + * HMP commands related to cryptodev
>> + *
>> + * Copyright (c) 2023 Bytedance.Inc
>> + *
>> + * Authors:
>> + *    zhenwei pi<pizhenwei@bytedance.com>
>> + *
>> + * This work is licensed under the terms of the GNU GPL, version 2 or
>> + * (at your option) any later version.
>> + */
>> +
>> +#include "qemu/osdep.h"
>> +#include "monitor/hmp.h"
>> +#include "monitor/monitor.h"
>> +#include "qapi/qapi-commands-cryptodev.h"
>> +#include "qapi/qmp/qdict.h"
>> +
>> +
>> +void hmp_info_cryptodev(Monitor *mon, const QDict *qdict)
>> +{
>> +    QCryptodevInfoList *il;
>> +    QCryptodevBackendServiceTypeList *sl;
>> +    QCryptodevBackendClientList *cl;
>> +
>> +    for (il = qmp_query_cryptodev(NULL); il; il = il->next) {
>> +        g_autofree char *services = NULL;
>> +        QCryptodevInfo *info = il->value;
>> +        char *tmp_services;
>> +
>> +        /* build a string like 'service=[akcipher|mac|hash|cipher]' */
>> +        for (sl = info->service; sl; sl = sl->next) {
>> +            const char *service = QCryptodevBackendServiceType_str(sl->value);
>> +
>> +            if (!services) {
>> +                services = g_strdup(service);
>> +            } else {
>> +                tmp_services = g_strjoin("|", services, service, NULL);
>> +                g_free(services);
>> +                services = tmp_services;
>> +            }
>> +        }
>> +        monitor_printf(mon, "%s: service=[%s]\n", info->id, services);
>> +
>> +        for (cl = info->client; cl; cl = cl->next) {
>> +            QCryptodevBackendClient *client = cl->value;
>> +            monitor_printf(mon, "    queue %" PRIu32 ": type=%s\n",
>> +                           client->queue,
>> +                           QCryptodevBackendType_str(client->type));
>> +        }
>> +    }
>> +
>> +    qapi_free_QCryptodevInfoList(il);
>> +}
>> diff --git a/backends/meson.build b/backends/meson.build
>> index 954e658b25..b369e0a9d0 100644
>> --- a/backends/meson.build
>> +++ b/backends/meson.build
>> @@ -1,5 +1,6 @@
>>   softmmu_ss.add([files(
>>     'cryptodev-builtin.c',
>> +  'cryptodev-hmp-cmds.c',
>>     'cryptodev.c',
>>     'hostmem-ram.c',
>>     'hostmem.c',
>> diff --git a/hmp-commands-info.hx b/hmp-commands-info.hx
>> index 754b1e8408..47d63d26db 100644
>> --- a/hmp-commands-info.hx
>> +++ b/hmp-commands-info.hx
>> @@ -993,3 +993,17 @@ SRST
>>     ``info virtio-queue-element`` *path* *queue* [*index*]
>>       Display element of a given virtio queue
>>   ERST
>> +
>> +    {
>> +        .name       = "cryptodev",
>> +        .args_type  = "",
>> +        .params     = "",
>> +        .help       = "show the crypto devices",
>> +        .cmd        = hmp_info_cryptodev,
>> +        .flags      = "p",
>> +    },
>> +
>> +SRST
>> +  ``info cryptodev``
>> +    Show the crypto devices.
>> +ERST
>> diff --git a/include/monitor/hmp.h b/include/monitor/hmp.h
>> index 2220f14fc9..e6cf0b7aa7 100644
>> --- a/include/monitor/hmp.h
>> +++ b/include/monitor/hmp.h
>> @@ -178,5 +178,6 @@ void hmp_ioport_read(Monitor *mon, const QDict *qdict);
>>   void hmp_ioport_write(Monitor *mon, const QDict *qdict);
>>   void hmp_boot_set(Monitor *mon, const QDict *qdict);
>>   void hmp_info_mtree(Monitor *mon, const QDict *qdict);
>> +void hmp_info_cryptodev(Monitor *mon, const QDict *qdict);
>>   
>>   #endif
>> -- 
>> 2.34.1
>>
diff mbox series

Patch

diff --git a/backends/cryptodev-hmp-cmds.c b/backends/cryptodev-hmp-cmds.c
new file mode 100644
index 0000000000..4f7220bb13
--- /dev/null
+++ b/backends/cryptodev-hmp-cmds.c
@@ -0,0 +1,54 @@ 
+/*
+ * HMP commands related to cryptodev
+ *
+ * Copyright (c) 2023 Bytedance.Inc
+ *
+ * Authors:
+ *    zhenwei pi<pizhenwei@bytedance.com>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or
+ * (at your option) any later version.
+ */
+
+#include "qemu/osdep.h"
+#include "monitor/hmp.h"
+#include "monitor/monitor.h"
+#include "qapi/qapi-commands-cryptodev.h"
+#include "qapi/qmp/qdict.h"
+
+
+void hmp_info_cryptodev(Monitor *mon, const QDict *qdict)
+{
+    QCryptodevInfoList *il;
+    QCryptodevBackendServiceTypeList *sl;
+    QCryptodevBackendClientList *cl;
+
+    for (il = qmp_query_cryptodev(NULL); il; il = il->next) {
+        g_autofree char *services = NULL;
+        QCryptodevInfo *info = il->value;
+        char *tmp_services;
+
+        /* build a string like 'service=[akcipher|mac|hash|cipher]' */
+        for (sl = info->service; sl; sl = sl->next) {
+            const char *service = QCryptodevBackendServiceType_str(sl->value);
+
+            if (!services) {
+                services = g_strdup(service);
+            } else {
+                tmp_services = g_strjoin("|", services, service, NULL);
+                g_free(services);
+                services = tmp_services;
+            }
+        }
+        monitor_printf(mon, "%s: service=[%s]\n", info->id, services);
+
+        for (cl = info->client; cl; cl = cl->next) {
+            QCryptodevBackendClient *client = cl->value;
+            monitor_printf(mon, "    queue %" PRIu32 ": type=%s\n",
+                           client->queue,
+                           QCryptodevBackendType_str(client->type));
+        }
+    }
+
+    qapi_free_QCryptodevInfoList(il);
+}
diff --git a/backends/meson.build b/backends/meson.build
index 954e658b25..b369e0a9d0 100644
--- a/backends/meson.build
+++ b/backends/meson.build
@@ -1,5 +1,6 @@ 
 softmmu_ss.add([files(
   'cryptodev-builtin.c',
+  'cryptodev-hmp-cmds.c',
   'cryptodev.c',
   'hostmem-ram.c',
   'hostmem.c',
diff --git a/hmp-commands-info.hx b/hmp-commands-info.hx
index 754b1e8408..47d63d26db 100644
--- a/hmp-commands-info.hx
+++ b/hmp-commands-info.hx
@@ -993,3 +993,17 @@  SRST
   ``info virtio-queue-element`` *path* *queue* [*index*]
     Display element of a given virtio queue
 ERST
+
+    {
+        .name       = "cryptodev",
+        .args_type  = "",
+        .params     = "",
+        .help       = "show the crypto devices",
+        .cmd        = hmp_info_cryptodev,
+        .flags      = "p",
+    },
+
+SRST
+  ``info cryptodev``
+    Show the crypto devices.
+ERST
diff --git a/include/monitor/hmp.h b/include/monitor/hmp.h
index 2220f14fc9..e6cf0b7aa7 100644
--- a/include/monitor/hmp.h
+++ b/include/monitor/hmp.h
@@ -178,5 +178,6 @@  void hmp_ioport_read(Monitor *mon, const QDict *qdict);
 void hmp_ioport_write(Monitor *mon, const QDict *qdict);
 void hmp_boot_set(Monitor *mon, const QDict *qdict);
 void hmp_info_mtree(Monitor *mon, const QDict *qdict);
+void hmp_info_cryptodev(Monitor *mon, const QDict *qdict);
 
 #endif