浏览代码

qga: conditionalize schema for commands requiring utmpx

Rather than creating stubs for every command that just return
QERR_UNSUPPORTED, use 'if' conditions in the QAPI schema to
fully exclude generation of the get-users command on POSIX
platforms lacking required APIs.

The command will be rejected at QMP dispatch time instead,
avoiding reimplementing rejection by blocking the stub commands.
This changes the error message for affected commands from

    {"class": "CommandNotFound", "desc": "Command FOO has been disabled"}

to

    {"class": "CommandNotFound", "desc": "The command FOO has not been found"}

This has the additional benefit that the QGA protocol reference
now documents what conditions enable use of the command.

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Konstantin Kostiuk <kkostiuk@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
Reviewed-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
Message-ID: <20240712132459.3974109-17-berrange@redhat.com>
Signed-off-by: Konstantin Kostiuk <kkostiuk@redhat.com>
Daniel P. Berrangé 1 年之前
父节点
当前提交
2799f434a4
共有 2 个文件被更改,包括 5 次插入11 次删除
  1. 1 9
      qga/commands-posix.c
  2. 4 2
      qga/qapi-schema.json

+ 1 - 9
qga/commands-posix.c

@@ -1212,15 +1212,7 @@ GuestUserList *qmp_guest_get_users(Error **errp)
     return head;
     return head;
 }
 }
 
 
-#else
-
-GuestUserList *qmp_guest_get_users(Error **errp)
-{
-    error_setg(errp, QERR_UNSUPPORTED);
-    return NULL;
-}
-
-#endif
+#endif /* HAVE_UTMPX */
 
 
 /* Replace escaped special characters with their real values. The replacement
 /* Replace escaped special characters with their real values. The replacement
  * is done in place -- returned value is in the original string.
  * is done in place -- returned value is in the original string.

+ 4 - 2
qga/qapi-schema.json

@@ -1414,7 +1414,8 @@
 # Since: 2.10
 # Since: 2.10
 ##
 ##
 { 'struct': 'GuestUser',
 { 'struct': 'GuestUser',
-  'data': { 'user': 'str', 'login-time': 'number', '*domain': 'str' } }
+  'data': { 'user': 'str', 'login-time': 'number', '*domain': 'str' },
+  'if': { 'any': ['CONFIG_WIN32', 'HAVE_UTMPX' ] } }
 
 
 ##
 ##
 # @guest-get-users:
 # @guest-get-users:
@@ -1426,7 +1427,8 @@
 # Since: 2.10
 # Since: 2.10
 ##
 ##
 { 'command': 'guest-get-users',
 { 'command': 'guest-get-users',
-  'returns': ['GuestUser'] }
+  'returns': ['GuestUser'],
+  'if': { 'any': ['CONFIG_WIN32', 'HAVE_UTMPX' ] } }
 
 
 ##
 ##
 # @GuestTimezone:
 # @GuestTimezone: