qapi: add conditions to REPLICATION type/commands on the schema

Add #if defined(CONFIG_REPLICATION) in generated code, and adjust the
code accordingly.

Made conditional:

* xen-set-replication, query-xen-replication-status,
  xen-colo-do-checkpoint

  Before the patch, we first register the commands unconditionally in
  generated code (requires a stub), then conditionally unregister in
  qmp_unregister_commands_hack().

  Afterwards, we register only when CONFIG_REPLICATION.  The command
  fails exactly the same, with CommandNotFound.

  Improvement, because now query-qmp-schema is accurate, and we're one
  step closer to killing qmp_unregister_commands_hack().

* enum BlockdevDriver value "replication" in command blockdev-add

* BlockdevOptions variant @replication

and related structures.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <20181213123724.4866-23-marcandre.lureau@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
This commit is contained in:
Marc-André Lureau 2018-12-13 16:37:24 +04:00 committed by Markus Armbruster
parent fd9dda3b70
commit 335d10cd8e
4 changed files with 21 additions and 25 deletions

View File

@ -24,7 +24,9 @@
#include "trace.h" #include "trace.h"
#include "qemu/error-report.h" #include "qemu/error-report.h"
#include "migration/failover.h" #include "migration/failover.h"
#ifdef CONFIG_REPLICATION
#include "replication.h" #include "replication.h"
#endif
#include "net/colo-compare.h" #include "net/colo-compare.h"
#include "net/colo.h" #include "net/colo.h"
#include "block/block.h" #include "block/block.h"
@ -201,11 +203,11 @@ void colo_do_failover(MigrationState *s)
} }
} }
#ifdef CONFIG_REPLICATION
void qmp_xen_set_replication(bool enable, bool primary, void qmp_xen_set_replication(bool enable, bool primary,
bool has_failover, bool failover, bool has_failover, bool failover,
Error **errp) Error **errp)
{ {
#ifdef CONFIG_REPLICATION
ReplicationMode mode = primary ? ReplicationMode mode = primary ?
REPLICATION_MODE_PRIMARY : REPLICATION_MODE_PRIMARY :
REPLICATION_MODE_SECONDARY; REPLICATION_MODE_SECONDARY;
@ -224,14 +226,10 @@ void qmp_xen_set_replication(bool enable, bool primary,
} }
replication_stop_all(failover, failover ? NULL : errp); replication_stop_all(failover, failover ? NULL : errp);
} }
#else
abort();
#endif
} }
ReplicationStatus *qmp_query_xen_replication_status(Error **errp) ReplicationStatus *qmp_query_xen_replication_status(Error **errp)
{ {
#ifdef CONFIG_REPLICATION
Error *err = NULL; Error *err = NULL;
ReplicationStatus *s = g_new0(ReplicationStatus, 1); ReplicationStatus *s = g_new0(ReplicationStatus, 1);
@ -246,19 +244,13 @@ ReplicationStatus *qmp_query_xen_replication_status(Error **errp)
error_free(err); error_free(err);
return s; return s;
#else
abort();
#endif
} }
void qmp_xen_colo_do_checkpoint(Error **errp) void qmp_xen_colo_do_checkpoint(Error **errp)
{ {
#ifdef CONFIG_REPLICATION
replication_do_checkpoint_all(errp); replication_do_checkpoint_all(errp);
#else
abort();
#endif
} }
#endif
COLOStatus *qmp_query_colo_status(Error **errp) COLOStatus *qmp_query_colo_status(Error **errp)
{ {

View File

@ -1147,11 +1147,6 @@ static void qmp_query_qmp_schema(QDict *qdict, QObject **ret_data,
*/ */
static void qmp_unregister_commands_hack(void) static void qmp_unregister_commands_hack(void)
{ {
#ifndef CONFIG_REPLICATION
qmp_unregister_command(&qmp_commands, "xen-set-replication");
qmp_unregister_command(&qmp_commands, "query-xen-replication-status");
qmp_unregister_command(&qmp_commands, "xen-colo-do-checkpoint");
#endif
#ifndef TARGET_I386 #ifndef TARGET_I386
qmp_unregister_command(&qmp_commands, "rtc-reset-reinjection"); qmp_unregister_command(&qmp_commands, "rtc-reset-reinjection");
qmp_unregister_command(&qmp_commands, "query-sev"); qmp_unregister_command(&qmp_commands, "query-sev");

View File

@ -2623,7 +2623,9 @@
'copy-on-read', 'dmg', 'file', 'ftp', 'ftps', 'gluster', 'copy-on-read', 'dmg', 'file', 'ftp', 'ftps', 'gluster',
'host_cdrom', 'host_device', 'http', 'https', 'iscsi', 'luks', 'host_cdrom', 'host_device', 'http', 'https', 'iscsi', 'luks',
'nbd', 'nfs', 'null-aio', 'null-co', 'nvme', 'parallels', 'qcow', 'nbd', 'nfs', 'null-aio', 'null-co', 'nvme', 'parallels', 'qcow',
'qcow2', 'qed', 'quorum', 'raw', 'rbd', 'replication', 'sheepdog', 'qcow2', 'qed', 'quorum', 'raw', 'rbd',
{ 'name': 'replication', 'if': 'defined(CONFIG_REPLICATION)' },
'sheepdog',
'ssh', 'throttle', 'vdi', 'vhdx', 'vmdk', 'vpc', 'vvfat', 'vxhs' ] } 'ssh', 'throttle', 'vdi', 'vhdx', 'vmdk', 'vpc', 'vvfat', 'vxhs' ] }
## ##
@ -3380,7 +3382,8 @@
# #
# Since: 2.9 # Since: 2.9
## ##
{ 'enum' : 'ReplicationMode', 'data' : [ 'primary', 'secondary' ] } { 'enum' : 'ReplicationMode', 'data' : [ 'primary', 'secondary' ],
'if': 'defined(CONFIG_REPLICATION)' }
## ##
# @BlockdevOptionsReplication: # @BlockdevOptionsReplication:
@ -3398,7 +3401,8 @@
{ 'struct': 'BlockdevOptionsReplication', { 'struct': 'BlockdevOptionsReplication',
'base': 'BlockdevOptionsGenericFormat', 'base': 'BlockdevOptionsGenericFormat',
'data': { 'mode': 'ReplicationMode', 'data': { 'mode': 'ReplicationMode',
'*top-id': 'str' } } '*top-id': 'str' },
'if': 'defined(CONFIG_REPLICATION)' }
## ##
# @NFSTransport: # @NFSTransport:
@ -3714,7 +3718,8 @@
'quorum': 'BlockdevOptionsQuorum', 'quorum': 'BlockdevOptionsQuorum',
'raw': 'BlockdevOptionsRaw', 'raw': 'BlockdevOptionsRaw',
'rbd': 'BlockdevOptionsRbd', 'rbd': 'BlockdevOptionsRbd',
'replication':'BlockdevOptionsReplication', 'replication': { 'type': 'BlockdevOptionsReplication',
'if': 'defined(CONFIG_REPLICATION)' },
'sheepdog': 'BlockdevOptionsSheepdog', 'sheepdog': 'BlockdevOptionsSheepdog',
'ssh': 'BlockdevOptionsSsh', 'ssh': 'BlockdevOptionsSsh',
'throttle': 'BlockdevOptionsThrottle', 'throttle': 'BlockdevOptionsThrottle',

View File

@ -1257,7 +1257,8 @@
# Since: 2.9 # Since: 2.9
## ##
{ 'command': 'xen-set-replication', { 'command': 'xen-set-replication',
'data': { 'enable': 'bool', 'primary': 'bool', '*failover' : 'bool' } } 'data': { 'enable': 'bool', 'primary': 'bool', '*failover' : 'bool' },
'if': 'defined(CONFIG_REPLICATION)' }
## ##
# @ReplicationStatus: # @ReplicationStatus:
@ -1272,7 +1273,8 @@
# Since: 2.9 # Since: 2.9
## ##
{ 'struct': 'ReplicationStatus', { 'struct': 'ReplicationStatus',
'data': { 'error': 'bool', '*desc': 'str' } } 'data': { 'error': 'bool', '*desc': 'str' },
'if': 'defined(CONFIG_REPLICATION)' }
## ##
# @query-xen-replication-status: # @query-xen-replication-status:
@ -1289,7 +1291,8 @@
# Since: 2.9 # Since: 2.9
## ##
{ 'command': 'query-xen-replication-status', { 'command': 'query-xen-replication-status',
'returns': 'ReplicationStatus' } 'returns': 'ReplicationStatus',
'if': 'defined(CONFIG_REPLICATION)' }
## ##
# @xen-colo-do-checkpoint: # @xen-colo-do-checkpoint:
@ -1305,7 +1308,8 @@
# #
# Since: 2.9 # Since: 2.9
## ##
{ 'command': 'xen-colo-do-checkpoint' } { 'command': 'xen-colo-do-checkpoint',
'if': 'defined(CONFIG_REPLICATION)' }
## ##
# @COLOStatus: # @COLOStatus: