Skip to contentSkip to conversation

spice-core: allow setting properties from QMP

RFC In review Kevin Pouget 4 participants 6 messages Jun 19, 2019 – Jun 21, 2019

lore
Share & tools
lore
#0 lore raw

RFC 1/1 spice-core: allow setting properties from QMP

Hello,

we're investigating the possibility to set some spice properties at runtime, through the QMP interface, but we're not sure what's the best way to proceed.
I've prepared the patch below, that adds a new QMP
command, but is there another way like with a QOM object, that could reuse an existing command? I searched but couldn't find an easy/not hacky way to create such objects ...

thanks,

Kevin

---

This patch allows setting spice properties from the QMP interface.

At the moment, only the 'video-codecs' property is supported.

---
 qapi/ui.json    | 19 +++++++++++++++++++
 ui/spice-core.c | 13 +++++++++++++
 2 files changed, 32 insertions(+)
qapi/ui.json +19 -0
index 59e412139a..5483a9c003 100644
@@ -265,6 +265,25 @@
 { 'command': 'query-spice', 'returns': 'SpiceInfo',
   'if': 'defined(CONFIG_SPICE)' }
 
+##
+# @set-spice:
+#
+# Set Spice properties.
+# @property: the SPICE property to modify
+# @value: the new value to affect to this property
+#
+# Since: ...
+#
+# Example:
+#
+# -> { "execute": "set-spice", "arguments": { "property": "video-codecs",
+#                                             "value": "spice:mjpeg;gst:mjpeg;" } }
+# <- { "returns": {} }
+##
+{ 'command': 'set-spice',
+  'data': {'property': 'str', 'value': 'str'},
+  'if': 'defined(CONFIG_SPICE)' }
+
 ##
 # @SPICE_CONNECTED:
 #
ui/spice-core.c +13 -0
index 2ffc3335f0..5408b16684 100644
@@ -503,6 +503,19 @@ static QemuOptsList qemu_spice_opts = {
     },
 };
 
+void qmp_set_spice(const char *property, const char *value, Error **errp) {
+    if (strcmp(property, "video-codecs") == 0) {
+        int invalid_codecs = spice_server_set_video_codecs(spice_server, value);
+
+        if (invalid_codecs) {
+            error_setg(errp, "Found %d invalic codecs while setting "
+                       "the property %s=%s\n", invalid_codecs, property, value);
+        }
+    } else {
+        error_setg(errp, "Setting an unknown spice property (%s=%s)\n", property, value);
+    }
+}
+
 SpiceInfo *qmp_query_spice(Error **errp)
 {
     QemuOpts *opts = QTAILQ_FIRST(&qemu_spice_opts.head);

--
2.21.0

#1 lore raw
Patchew URL: https://patchew.org/QEMU/[email protected]/

Patchew URL: https://patchew.org/QEMU/[email protected]/

Hi,

This series seems to have some coding style problems. See output below for more information:

Subject: [Qemu-devel] [RFC] spice-core: allow setting properties from QMP
Type: series
Message-id: [email protected]

=== TEST SCRIPT BEGIN ===
#!/bin/bash
git rev-parse base > /dev/null || exit 0
git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram
./scripts/checkpatch.pl --mailback base..
=== TEST SCRIPT END ===

From https://github.com/patchew-project/qemu
* [new tag] patchew/[email protected] -> patchew/[email protected]
Switched to a new branch 'test'
51809fd99d spice-core: allow setting properties from QMP

=== OUTPUT BEGIN ===
ERROR: open brace '{' following function declarations go on the next line #61: FILE: ui/spice-core.c:506:
+void qmp_set_spice(const char *property, const char *value, Error **errp) {

ERROR: Error messages should not contain newlines
#67: FILE: ui/spice-core.c:512:
+ "the property %s=%s\n", invalid_codecs, property, value);

WARNING: line over 80 characters
#70: FILE: ui/spice-core.c:515:
+ error_setg(errp, "Setting an unknown spice property (%s=%s)\n", property, value);

ERROR: Error messages should not contain newlines
#70: FILE: ui/spice-core.c:515:
+ error_setg(errp, "Setting an unknown spice property (%s=%s)\n", property, value);

ERROR: Missing Signed-off-by: line(s)

total: 4 errors, 1 warnings, 44 lines checked

Commit 51809fd99d76 (spice-core: allow setting properties from QMP) has style problems, please review. If any of these errors are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
=== OUTPUT END ===

Test command exited with code: 1

The full log is available at
http://patchew.org/logs/[email protected]/testing.checkpatch/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to [email protected]

#2 lore raw
In reply to Kevin Pouget
Quoted 10 lines · Kevin Pouget

Hello,

we're investigating the possibility to set some spice properties at runtime, through the QMP interface, but we're not sure what's the best way to proceed.
I've prepared the patch below, that adds a new QMP
command, but is there another way like with a QOM object, that could reuse an existing command? I searched but couldn't find an easy/not hacky way to create such objects ...

A new command may be okay, however,

Quoted 8 lines
qapi/ui.json +8 -0
+##
+# @set-spice:
+#
+# Set Spice properties.
+# @property: the SPICE property to modify
+# @value: the new value to affect to this property
+#
+# Since: ...

qapi/ui.json line 285

Quoted 10 lines
qapi/ui.json +10 -0
+#
+# Example:
+#
+# -> { "execute": "set-spice", "arguments": { "property": "video-codecs",
+#                                             "value": "spice:mjpeg;gst:mjpeg;" } }
+# <- { "returns": {} }
+##
+{ 'command': 'set-spice',
+  'data': {'property': 'str', 'value': 'str'},
+  'if': 'defined(CONFIG_SPICE)' }

letting 'property' be an open-coded string feels wrong. If you are only going to accept a specific (limited) set of property names, then 'property' should be typed as an enum:

{ 'enum': 'SpiceProperties', 'data': [ 'video-codecs' ] }

{ 'command': 'set-spice', 'data': { 'property': 'SpiceProperties', 'value': 'str' } }

Quoted 9 lines
qapi/ui.json +1 -0
+
 ##
 # @SPICE_CONNECTED:
 #
ui/spice-core.c +0 -0
index 2ffc3335f0..5408b16684 100644

ui/spice-core.c static QemuOptsList qemu_spice_opts = { · line 511

Quoted 9 lines
ui/spice-core.c +6 -0
@@ -503,6 +503,19 @@ static QemuOptsList qemu_spice_opts = {
     },
 };
 
+void qmp_set_spice(const char *property, const char *value, Error **errp) {
+    if (strcmp(property, "video-codecs") == 0) {
+        int invalid_codecs = spice_server_set_video_codecs(spice_server, value);
+
+        if (invalid_codecs) {
+            error_setg(errp, "Found %d invalic codecs while setting "

invalid

Quoted 14 lines
ui/spice-core.c +7 -1
+                       "the property %s=%s\n", invalid_codecs, property, value);
+        }
+    } else {
+        error_setg(errp, "Setting an unknown spice property (%s=%s)\n", property, value);
+    }
+}
+
 SpiceInfo *qmp_query_spice(Error **errp)
 {
     QemuOpts *opts = QTAILQ_FIRST(&qemu_spice_opts.head);
--

2.21.0

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org
#3 lore raw

Hello Eric,

Quoted 1 line

A new command may be okay, however,

thanks, I've fix the typos and updated the patch to use an Enum, which indeed makes more sense.

I've also updated "spice-query" command to provide the current value of the "video-codec" property,
but it made me wonder if I should improve this QMP interface with a json list, or keep the current string-based list ("enc1:codec1;enc2:codec2").

I CC the spice-devel list to get their point of view

The current behavior is:

--> { "execute": "set-spice", "arguments": { "property":
"video-codecs", "value": "spice:mjpeg;gstreamer:h264" } } <-- {"return":{},"id":"libvirt-23"}

--> { "execute": "query-spice" }
<-- {.... "video-codecs": "spice:mjpeg;gstreamer:h264;" ....}

I put the new version of the RFC patch below

best regards,

Kevin

---

This patch allows setting spice properties from the QMP interface.

At the moment, only the 'video-codecs' property is supported.

---
 qapi/ui.json    | 42 ++++++++++++++++++++++++++++++++++++++++--
 ui/spice-core.c | 21 +++++++++++++++++++++
 2 files changed, 61 insertions(+), 2 deletions(-)
qapi/ui.json +3 -0
index 59e412139a..5f67096bcb 100644
@@ -211,12 +211,16 @@
 #
 # @channels: a list of @SpiceChannel for each active spice channel
 #
+# @video-codecs: The list of encoders:codecs currently allowed for
+#                video streaming (since: ...)
+#
 # Since: 0.14.0
 ##
 { 'struct': 'SpiceInfo',
   'data': {'enabled': 'bool', 'migrated': 'bool', '*host': 'str',

'*port': 'int',

            '*tls-port': 'int', '*auth': 'str', '*compiled-version': 'str',
-           'mouse-mode': 'SpiceQueryMouseMode', '*channels': ['SpiceChannel']},
+           'mouse-mode': 'SpiceQueryMouseMode', '*channels': ['SpiceChannel'],
+           'video-codecs': 'str'},

'if': 'defined(CONFIG_SPICE)' }

##
@@ -257,7 +261,8 @@
# "tls": false
# },
# [ ... more channels follow ... ]

-#          ]
+#          ],
+#          "video-codecs": "spice:mjpeg;gstreamer:h264;"

# }
# }
#
@@ -265,6 +270,39 @@
{ 'command': 'query-spice', 'returns': 'SpiceInfo',
'if': 'defined(CONFIG_SPICE)' }

+##
+# @SpiceProperty:
+#
+# An enumeration of Spice properties that can be set at runtime. +#
+# @video-codecs: the ;-separated list of video-codecs allowed for +# spice-server video streaming.
+#
+# Since: ...
+##
+{ 'enum': 'SpiceProperty',
+ 'data': [ 'video-codecs'],
+ 'if': 'defined(CONFIG_SPICE)' }
+
+##
+# @set-spice:
+#
+# Set Spice properties.
+# @property: the SPICE property to modify
+# @value: the new value to affect to this property
+#
+# Since: ...
+#
+# Example:
+#
+# -> { "execute": "set-spice", "arguments": { "property": "video-codecs",
+# "value": "spice:mjpeg;" } }
+# <- { "returns": {} }
+##
+{ 'command': 'set-spice',
+ 'data': {'property': 'SpiceProperty', 'value': 'str'},
+ 'if': 'defined(CONFIG_SPICE)' }
+
##
# @SPICE_CONNECTED:
#

ui/spice-core.c +10 -0
index 63e8694df8..1660f49f15 100644
@@ -506,6 +506,25 @@ static QemuOptsList qemu_spice_opts = {
     },
 };
 
+void qmp_set_spice(SpiceProperty property, const char *value, Error **errp)
+{
+    int invalid_codecs;
+
+    switch(property) {
+    case SPICE_PROPERTY_VIDEO_CODECS:
+        invalid_codecs = spice_server_set_video_codecs(spice_server, value);
+
+        if (invalid_codecs) {
+            error_setg(errp, "Found %d invalid video-codecs while

setting spice"
+ " property 'video-codec=%s'", invalid_codecs, value);
+ }
+ break;
+ default:
+ /* only reached in case of version mismatched */
+ error_setg(errp, "Property #%d not supported.", property);
+ }
+}
+
SpiceInfo *qmp_query_spice(Error **errp)

 {
     QemuOpts *opts = QTAILQ_FIRST(&qemu_spice_opts.head);
@@ -555,6 +574,8 @@ SpiceInfo *qmp_query_spice(Error **errp)
                        SPICE_QUERY_MOUSE_MODE_SERVER :
                        SPICE_QUERY_MOUSE_MODE_CLIENT;

+ info->video_codecs = spice_server_get_video_codecs(spice_server);
+

     /* for compatibility with the original command */
     info->has_channels = true;
     info->channels = qmp_query_spice_channels();
Signature · 1 line
2.21.0
#4 lore raw
Quoted 14 lines

Hello Eric,

Quoted 1 line

A new command may be okay, however,

thanks, I've fix the typos and updated the patch to use an Enum, which indeed makes more sense.

I've also updated "spice-query" command to provide the current value of the "video-codec" property,
but it made me wonder if I should improve this QMP interface with a json list, or keep the current string-based list ("enc1:codec1;enc2:codec2").

Quoted 7 lines

I CC the spice-devel list to get their point of view

The current behavior is:

--> { "execute": "set-spice", "arguments": { "property":
"video-codecs", "value": "spice:mjpeg;gstreamer:h264" } } <-- {"return":{},"id":"libvirt-23"}

It looks complicated from the user. Why not just

--> { "execute": "set-spice", "arguments": { "video-codecs": "spice:mjpeg;gstreamer:h264" } }

Quoted 142 lines

--> { "execute": "query-spice" }
<-- {.... "video-codecs": "spice:mjpeg;gstreamer:h264;" ....}

I put the new version of the RFC patch below

best regards,

Kevin

---

This patch allows setting spice properties from the QMP interface.

At the moment, only the 'video-codecs' property is supported.

---
 qapi/ui.json    | 42 ++++++++++++++++++++++++++++++++++++++++--
 ui/spice-core.c | 21 +++++++++++++++++++++
 2 files changed, 61 insertions(+), 2 deletions(-)
qapi/ui.json +5 -1
index 59e412139a..5f67096bcb 100644
@@ -211,12 +211,16 @@
 #
 # @channels: a list of @SpiceChannel for each active spice channel
 #
+# @video-codecs: The list of encoders:codecs currently allowed for
+#                video streaming (since: ...)
+#
 # Since: 0.14.0
 ##
 { 'struct': 'SpiceInfo',
   'data': {'enabled': 'bool', 'migrated': 'bool', '*host': 'str',
 '*port': 'int',
            '*tls-port': 'int', '*auth': 'str', '*compiled-version': 'str',
-           'mouse-mode': 'SpiceQueryMouseMode', '*channels':
 ['SpiceChannel']},
+           'mouse-mode': 'SpiceQueryMouseMode', '*channels':
 ['SpiceChannel'],
+           'video-codecs': 'str'},
   'if': 'defined(CONFIG_SPICE)' }

##

qapi/ui.json +35 -1
@@ -257,7 +261,8 @@
 #                "tls": false
 #             },
 #             [ ... more channels follow ... ]
-#          ]
+#          ],
+#          "video-codecs": "spice:mjpeg;gstreamer:h264;"
 #       }
 #    }
 #
@@ -265,6 +270,39 @@
 { 'command': 'query-spice', 'returns': 'SpiceInfo',
   'if': 'defined(CONFIG_SPICE)' }
 
+##
+# @SpiceProperty:
+#
+# An enumeration of Spice properties that can be set at runtime.
+#
+# @video-codecs: the ;-separated list of video-codecs allowed for
+# spice-server video streaming.
+#
+# Since: ...
+##
+{ 'enum': 'SpiceProperty',
+  'data': [ 'video-codecs'],
+  'if': 'defined(CONFIG_SPICE)' }
+
+##
+# @set-spice:
+#
+# Set Spice properties.
+# @property: the SPICE property to modify
+# @value: the new value to affect to this property
+#
+# Since: ...
+#
+# Example:
+#
+# -> { "execute": "set-spice", "arguments": { "property": "video-codecs",
+#                                             "value": "spice:mjpeg;" } }
+# <- { "returns": {} }
+##
+{ 'command': 'set-spice',
+  'data': {'property': 'SpiceProperty', 'value': 'str'},
+  'if': 'defined(CONFIG_SPICE)' }
+
 ##
 # @SPICE_CONNECTED:
 #
ui/spice-core.c +10 -0
index 63e8694df8..1660f49f15 100644
@@ -506,6 +506,25 @@ static QemuOptsList qemu_spice_opts = {
     },
 };
 
+void qmp_set_spice(SpiceProperty property, const char *value, Error **errp)
+{
+    int invalid_codecs;
+
+    switch(property) {
+    case SPICE_PROPERTY_VIDEO_CODECS:
+        invalid_codecs = spice_server_set_video_codecs(spice_server, value);
+
+        if (invalid_codecs) {
+            error_setg(errp, "Found %d invalid video-codecs while

setting spice"

ui/spice-core.c +11 -1
+                       " property 'video-codec=%s'", invalid_codecs, value);
+        }
+        break;
+    default:
+        /* only reached in case of version mismatched */
+        error_setg(errp, "Property #%d not supported.", property);
+    }
+}
+
 SpiceInfo *qmp_query_spice(Error **errp)
 {
     QemuOpts *opts = QTAILQ_FIRST(&qemu_spice_opts.head);
@@ -555,6 +574,8 @@ SpiceInfo *qmp_query_spice(Error **errp)
                        SPICE_QUERY_MOUSE_MODE_SERVER :
                        SPICE_QUERY_MOUSE_MODE_CLIENT;
 
+    info->video_codecs = spice_server_get_video_codecs(spice_server);
+
     /* for compatibility with the original command */
     info->has_channels = true;
     info->channels = qmp_query_spice_channels();
--

2.21.0

#5 lore raw
Quoted 19 lines · Frediano Ziglio
Quoted 19 lines

Hello Eric,

Quoted 1 line

A new command may be okay, however,

thanks, I've fix the typos and updated the patch to use an Enum, which indeed makes more sense.

I've also updated "spice-query" command to provide the current value of the "video-codec" property,
but it made me wonder if I should improve this QMP interface with a json list, or keep the current string-based list ("enc1:codec1;enc2:codec2").

I CC the spice-devel list to get their point of view

The current behavior is:

Quoted 7 lines
Quoted 3 lines

--> { "execute": "set-spice", "arguments": { "property":
"video-codecs", "value": "spice:mjpeg;gstreamer:h264" } } <-- {"return":{},"id":"libvirt-23"}

It looks complicated from the user. Why not just

--> { "execute": "set-spice", "arguments": { "video-codecs": "spice:mjpeg;gstreamer:h264" } }

it makes sense indeed, I've updated the code:

# -> { "execute": "set-spice", "arguments": { "video-codecs": "spice:mjpeg;" } # <- { "returns": {} }

+{ 'command': 'set-spice',
+ 'data': {'*video-codecs': 'str'},
+ 'if': 'defined(CONFIG_SPICE)' }

---
 qapi/ui.json    | 27 +++++++++++++++++++++++++--
 ui/spice-core.c | 17 +++++++++++++++++
 2 files changed, 42 insertions(+), 2 deletions(-)
qapi/ui.json +3 -0
index 59e412139a..cdbe04bda0 100644
@@ -211,12 +211,16 @@
 #
 # @channels: a list of @SpiceChannel for each active spice channel
 #
+# @video-codecs: The list of encoders:codecs currently allowed for
+#                video streaming (since: ...)
+#
 # Since: 0.14.0
 ##
 { 'struct': 'SpiceInfo',
   'data': {'enabled': 'bool', 'migrated': 'bool', '*host': 'str',

'*port': 'int',

            '*tls-port': 'int', '*auth': 'str', '*compiled-version': 'str',
-           'mouse-mode': 'SpiceQueryMouseMode', '*channels': ['SpiceChannel']},
+           'mouse-mode': 'SpiceQueryMouseMode', '*channels': ['SpiceChannel'],
+           'video-codecs': 'str'},

'if': 'defined(CONFIG_SPICE)' }

##
@@ -257,7 +261,8 @@
# "tls": false
# },
# [ ... more channels follow ... ]

-#          ]
+#          ],
+#          "video-codecs": "spice:mjpeg;gstreamer:h264;"

# }
# }
#
@@ -265,6 +270,24 @@
{ 'command': 'query-spice', 'returns': 'SpiceInfo',
'if': 'defined(CONFIG_SPICE)' }

+##
+# @set-spice:
+#
+# Set Spice properties.
+# @video-codecs: the ;-separated list of video-codecs allowed for
+# spice-server video streaming.
+#
+# Since: ...
+#
+# Example:
+#
+# -> { "execute": "set-spice", "arguments": { "video-codecs": "spice:mjpeg;" } +# <- { "returns": {} }
+##
+{ 'command': 'set-spice',
+ 'data': {'*video-codecs': 'str'},
+ 'if': 'defined(CONFIG_SPICE)' }
+
##
# @SPICE_CONNECTED:
#

ui/spice-core.c +17 -0
index 63e8694df8..a4b265b663 100644
@@ -506,6 +506,21 @@ static QemuOptsList qemu_spice_opts = {
     },
 };
 
+void qmp_set_spice(bool has_video_codecs, const char *video_codecs,
+                   Error **errp)
+{
+    if (has_video_codecs) {
+        int invalid_codecs = spice_server_set_video_codecs(spice_server,
+                                                           video_codecs);
+
+        if (invalid_codecs) {
+            error_setg(errp, "Found %d invalid video-codecs while setting"
+                       " spice property 'video-codec=%s'", invalid_codecs,
+                       video_codecs);
+        }
+    }
+}
+
 SpiceInfo *qmp_query_spice(Error **errp)
 {
     QemuOpts *opts = QTAILQ_FIRST(&qemu_spice_opts.head);
@@ -555,6 +570,8 @@ SpiceInfo *qmp_query_spice(Error **errp)
                        SPICE_QUERY_MOUSE_MODE_SERVER :
                        SPICE_QUERY_MOUSE_MODE_CLIENT;
 
+    info->video_codecs = spice_server_get_video_codecs(spice_server);
+
     /* for compatibility with the original command */
     info->has_channels = true;
     info->channels = qmp_query_spice_channels();
Signature · 1 line
2.21.0