Migration Pull request (20231011 edition)

Hi
 
 In this pull request:
 
 - Markus RDMA cleanup series
 - recover fixes from peter
 - migration capability from fabiano
 - negative migration test from fabiano.
 
 Please, pull.
 
 Thanks, Juan.
 -----BEGIN PGP SIGNATURE-----
 
 iQIzBAABCAAdFiEEGJn/jt6/WMzuA0uC9IfvGFhy1yMFAmUmaQ8ACgkQ9IfvGFhy
 1yN9fA//SBnea3Wl2158J673l5aaI8Vp/1PjfzvNdcr/6EQbXZBgug+haQ3n5Hhf
 USNRhemrCkpZAGCUf07g9pfF4R/Jsq1OkOrWF4e6gAaZPNU4V5F7VKBk8pmFMLtr
 Kk2XgnH2ZPaFEvts0qBrOfvDHH8gOzzjpF2HGrioM8Zr3p1JHz9OqJoSyawLF0U7
 YFTq2jJSgaOQ6ax1+L8hLLuXlmNccBaTWT8Cv0rbPEgcwrJOM/wMfmd6O39ps929
 yS5NnxqqkrprTDjmeGOgOQd0Cy/flinnzmu+BVMO6/ns9Hu6q1TGG6D+DOBdgmHH
 jq7Ej5VILtXWOoZtXLHqA1Xt73ciVlmditVupoC+5vtIJou2JseClutOp98qxxzV
 llMF7ldHbRTWnu7qIrwv2OINarowR0pIZfkJqBc6dNHHScwMCnX5L9YAvNePEo2V
 1oJpbqW7mmgwdlFAiKFD+AE6qUWxcnzOvPf+fzWrJMi507Kv5nmxQWTHw9dsFs7k
 neWnK21t0s2t77+vVBtLlr06JESG+WndzvQsXKZu8Pd0+ASnzpX8pRVzxEPk5EiH
 fT9bhXOCvxTTHulznjkOApODE5NF+KlHAFXU87cSIkdi/6JfzcvTe6KeeIPC248Q
 jk3nVlhds1xajTcPAK7HF5Ta6R8rNdTZ6q/kFNhLaTGqv9agxDU=
 =hekO
 -----END PGP SIGNATURE-----

Merge tag 'migration-20231011-pull-request' of https://gitlab.com/juan.quintela/qemu into staging

Migration Pull request (20231011 edition)

Hi

In this pull request:

- Markus RDMA cleanup series
- recover fixes from peter
- migration capability from fabiano
- negative migration test from fabiano.

Please, pull.

Thanks, Juan.

# -----BEGIN PGP SIGNATURE-----
#
# iQIzBAABCAAdFiEEGJn/jt6/WMzuA0uC9IfvGFhy1yMFAmUmaQ8ACgkQ9IfvGFhy
# 1yN9fA//SBnea3Wl2158J673l5aaI8Vp/1PjfzvNdcr/6EQbXZBgug+haQ3n5Hhf
# USNRhemrCkpZAGCUf07g9pfF4R/Jsq1OkOrWF4e6gAaZPNU4V5F7VKBk8pmFMLtr
# Kk2XgnH2ZPaFEvts0qBrOfvDHH8gOzzjpF2HGrioM8Zr3p1JHz9OqJoSyawLF0U7
# YFTq2jJSgaOQ6ax1+L8hLLuXlmNccBaTWT8Cv0rbPEgcwrJOM/wMfmd6O39ps929
# yS5NnxqqkrprTDjmeGOgOQd0Cy/flinnzmu+BVMO6/ns9Hu6q1TGG6D+DOBdgmHH
# jq7Ej5VILtXWOoZtXLHqA1Xt73ciVlmditVupoC+5vtIJou2JseClutOp98qxxzV
# llMF7ldHbRTWnu7qIrwv2OINarowR0pIZfkJqBc6dNHHScwMCnX5L9YAvNePEo2V
# 1oJpbqW7mmgwdlFAiKFD+AE6qUWxcnzOvPf+fzWrJMi507Kv5nmxQWTHw9dsFs7k
# neWnK21t0s2t77+vVBtLlr06JESG+WndzvQsXKZu8Pd0+ASnzpX8pRVzxEPk5EiH
# fT9bhXOCvxTTHulznjkOApODE5NF+KlHAFXU87cSIkdi/6JfzcvTe6KeeIPC248Q
# jk3nVlhds1xajTcPAK7HF5Ta6R8rNdTZ6q/kFNhLaTGqv9agxDU=
# =hekO
# -----END PGP SIGNATURE-----
# gpg: Signature made Wed 11 Oct 2023 05:21:19 EDT
# gpg:                using RSA key 1899FF8EDEBF58CCEE034B82F487EF185872D723
# gpg: Good signature from "Juan Quintela <quintela@redhat.com>" [full]
# gpg:                 aka "Juan Quintela <quintela@trasno.org>" [full]
# Primary key fingerprint: 1899 FF8E DEBF 58CC EE03  4B82 F487 EF18 5872 D723

* tag 'migration-20231011-pull-request' of https://gitlab.com/juan.quintela/qemu: (65 commits)
  migration: Add migration_rp_wait|kick()
  migration: Remember num of ramblocks to sync during recovery
  qemufile: Always return a verbose error
  migration: Introduce migrate_has_error()
  migration: Display error in query-migrate irrelevant of status
  migration/rdma: Replace flawed device detail dump by tracing
  migration/rdma: Use error_report() & friends instead of stderr
  migration/rdma: Downgrade qemu_rdma_cleanup() errors to warnings
  migration/rdma: Silence qemu_rdma_register_and_get_keys()
  migration/rdma: Silence qemu_rdma_block_for_wrid()
  migration/rdma: Don't report received completion events as error
  migration/rdma: Silence qemu_rdma_reg_control()
  migration/rdma: Silence qemu_rdma_connect()
  migration/rdma: Silence qemu_rdma_resolve_host()
  migration/rdma: Convert qemu_rdma_alloc_pd_cq() to Error
  migration/rdma: Convert qemu_rdma_post_recv_control() to Error
  migration/rdma: Convert qemu_rdma_post_send_control() to Error
  migration/rdma: Convert qemu_rdma_write() to Error
  migration/rdma: Convert qemu_rdma_write_one() to Error
  migration/rdma: Convert qemu_rdma_write_flush() to Error
  ...

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
This commit is contained in:
Stefan Hajnoczi 2023-10-11 09:42:39 -04:00
commit 48747938d1
16 changed files with 758 additions and 642 deletions

View File

@ -431,13 +431,16 @@ void migrate_add_address(SocketAddress *address)
static void qemu_start_incoming_migration(const char *uri, Error **errp)
{
const char *p = NULL;
MigrationIncomingState *mis = migration_incoming_get_current();
/* URI is not suitable for migration? */
if (!migration_channels_and_uri_compatible(uri, errp)) {
return;
}
qapi_event_send_migration(MIGRATION_STATUS_SETUP);
migrate_set_state(&mis->state, MIGRATION_STATUS_NONE,
MIGRATION_STATUS_SETUP);
if (strstart(uri, "tcp:", &p) ||
strstart(uri, "unix:", NULL) ||
strstart(uri, "vsock:", NULL)) {
@ -531,7 +534,7 @@ process_incoming_migration_co(void *opaque)
mis->largest_page_size = qemu_ram_pagesize_largest();
postcopy_state_set(POSTCOPY_INCOMING_NONE);
migrate_set_state(&mis->state, MIGRATION_STATUS_NONE,
migrate_set_state(&mis->state, MIGRATION_STATUS_SETUP,
MIGRATION_STATUS_ACTIVE);
mis->loadvm_co = qemu_coroutine_self();
@ -1057,9 +1060,6 @@ static void fill_source_migration_info(MigrationInfo *info)
break;
case MIGRATION_STATUS_FAILED:
info->has_status = true;
if (s->error) {
info->error_desc = g_strdup(error_get_pretty(s->error));
}
break;
case MIGRATION_STATUS_CANCELLED:
info->has_status = true;
@ -1069,6 +1069,11 @@ static void fill_source_migration_info(MigrationInfo *info)
break;
}
info->status = state;
QEMU_LOCK_GUARD(&s->error_mutex);
if (s->error) {
info->error_desc = g_strdup(error_get_pretty(s->error));
}
}
static void fill_destination_migration_info(MigrationInfo *info)
@ -1229,6 +1234,13 @@ void migrate_set_error(MigrationState *s, const Error *error)
}
}
bool migrate_has_error(MigrationState *s)
{
/* The lock is not helpful here, but still follow the rule */
QEMU_LOCK_GUARD(&s->error_mutex);
return qatomic_read(&s->error);
}
static void migrate_error_free(MigrationState *s)
{
QEMU_LOCK_GUARD(&s->error_mutex);
@ -1751,6 +1763,16 @@ static void mark_source_rp_bad(MigrationState *s)
s->rp_state.error = true;
}
void migration_rp_wait(MigrationState *s)
{
qemu_sem_wait(&s->rp_state.rp_sem);
}
void migration_rp_kick(MigrationState *s)
{
qemu_sem_post(&s->rp_state.rp_sem);
}
static struct rp_cmd_args {
ssize_t len; /* -1 = variable */
const char *name;
@ -1823,7 +1845,7 @@ static int migrate_handle_rp_resume_ack(MigrationState *s, uint32_t value)
MIGRATION_STATUS_POSTCOPY_ACTIVE);
/* Notify send thread that time to continue send pages */
qemu_sem_post(&s->rp_state.rp_sem);
migration_rp_kick(s);
return 0;
}
@ -2452,7 +2474,7 @@ static int postcopy_resume_handshake(MigrationState *s)
qemu_savevm_send_postcopy_resume(s->to_dst_file);
while (s->state == MIGRATION_STATUS_POSTCOPY_RECOVER) {
qemu_sem_wait(&s->rp_state.rp_sem);
migration_rp_wait(s);
}
if (s->state == MIGRATION_STATUS_POSTCOPY_ACTIVE) {

View File

@ -316,6 +316,12 @@ struct MigrationState {
* be cleared in the rp_thread!
*/
bool rp_thread_created;
/*
* Used to synchronize between migration main thread and return
* path thread. The migration thread can wait() on this sem, while
* other threads (e.g., return path thread) can kick it using a
* post().
*/
QemuSemaphore rp_sem;
/*
* We post to this when we got one PONG from dest. So far it's an
@ -476,6 +482,7 @@ bool migration_has_all_channels(void);
uint64_t migrate_max_downtime(void);
void migrate_set_error(MigrationState *s, const Error *error);
bool migrate_has_error(MigrationState *s);
void migrate_fd_connect(MigrationState *s, Error *error_in);
@ -526,4 +533,13 @@ void migration_populate_vfio_info(MigrationInfo *info);
void migration_reset_vfio_bytes_transferred(void);
void postcopy_temp_page_reset(PostcopyTmpPage *tmp_page);
/* Migration thread waiting for return path thread. */
void migration_rp_wait(MigrationState *s);
/*
* Kick the migration thread waiting for return path messages. NOTE: the
* name can be slightly confusing (when read as "kick the rp thread"), just
* to remember the target is always the migration thread.
*/
void migration_rp_kick(MigrationState *s);
#endif

View File

@ -1408,20 +1408,25 @@ void qmp_migrate_set_parameters(MigrateSetParameters *params, Error **errp)
{
MigrationParameters tmp;
/* TODO Rewrite "" to null instead */
/* TODO Rewrite "" to null instead for all three tls_* parameters */
if (params->tls_creds
&& params->tls_creds->type == QTYPE_QNULL) {
qobject_unref(params->tls_creds->u.n);
params->tls_creds->type = QTYPE_QSTRING;
params->tls_creds->u.s = strdup("");
}
/* TODO Rewrite "" to null instead */
if (params->tls_hostname
&& params->tls_hostname->type == QTYPE_QNULL) {
qobject_unref(params->tls_hostname->u.n);
params->tls_hostname->type = QTYPE_QSTRING;
params->tls_hostname->u.s = strdup("");
}
if (params->tls_authz
&& params->tls_authz->type == QTYPE_QNULL) {
qobject_unref(params->tls_authz->u.n);
params->tls_authz->type = QTYPE_QSTRING;
params->tls_authz->u.s = strdup("");
}
migrate_params_test_apply(params, &tmp);

View File

@ -142,15 +142,24 @@ void qemu_file_set_hooks(QEMUFile *f, const QEMUFileHooks *hooks)
*
* Return negative error value if there has been an error on previous
* operations, return 0 if no error happened.
* Optional, it returns Error* in errp, but it may be NULL even if return value
* is not 0.
*
* If errp is specified, a verbose error message will be copied over.
*/
static int qemu_file_get_error_obj(QEMUFile *f, Error **errp)
{
if (errp) {
*errp = f->last_error_obj ? error_copy(f->last_error_obj) : NULL;
if (!f->last_error) {
return 0;
}
/* There is an error */
if (errp) {
if (f->last_error_obj) {
*errp = error_copy(f->last_error_obj);
} else {
error_setg_errno(errp, -f->last_error, "Channel error");
}
}
return f->last_error;
}

View File

@ -394,6 +394,14 @@ struct RAMState {
/* Queue of outstanding page requests from the destination */
QemuMutex src_page_req_mutex;
QSIMPLEQ_HEAD(, RAMSrcPageRequest) src_page_requests;
/*
* This is only used when postcopy is in recovery phase, to communicate
* between the migration thread and the return path thread on dirty
* bitmap synchronizations. This field is unused in other stages of
* RAM migration.
*/
unsigned int postcopy_bmap_sync_requested;
};
typedef struct RAMState RAMState;
@ -4119,21 +4127,21 @@ static int ram_dirty_bitmap_sync_all(MigrationState *s, RAMState *rs)
{
RAMBlock *block;
QEMUFile *file = s->to_dst_file;
int ramblock_count = 0;
trace_ram_dirty_bitmap_sync_start();
qatomic_set(&rs->postcopy_bmap_sync_requested, 0);
RAMBLOCK_FOREACH_NOT_IGNORED(block) {
qemu_savevm_send_recv_bitmap(file, block->idstr);
trace_ram_dirty_bitmap_request(block->idstr);
ramblock_count++;
qatomic_inc(&rs->postcopy_bmap_sync_requested);
}
trace_ram_dirty_bitmap_sync_wait();
/* Wait until all the ramblocks' dirty bitmap synced */
while (ramblock_count--) {
qemu_sem_wait(&s->rp_state.rp_sem);
while (qatomic_read(&rs->postcopy_bmap_sync_requested)) {
migration_rp_wait(s);
}
trace_ram_dirty_bitmap_sync_complete();
@ -4141,11 +4149,6 @@ static int ram_dirty_bitmap_sync_all(MigrationState *s, RAMState *rs)
return 0;
}
static void ram_dirty_bitmap_reload_notify(MigrationState *s)
{
qemu_sem_post(&s->rp_state.rp_sem);
}
/*
* Read the received bitmap, revert it as the initial dirty bitmap.
* This is only used when the postcopy migration is paused but wants
@ -4159,6 +4162,7 @@ int ram_dirty_bitmap_reload(MigrationState *s, RAMBlock *block)
unsigned long *le_bitmap, nbits = block->used_length >> TARGET_PAGE_BITS;
uint64_t local_size = DIV_ROUND_UP(nbits, 8);
uint64_t size, end_mark;
RAMState *rs = ram_state;
trace_ram_dirty_bitmap_reload_begin(block->idstr);
@ -4225,11 +4229,16 @@ int ram_dirty_bitmap_reload(MigrationState *s, RAMBlock *block)
/* We'll recalculate migration_dirty_pages in ram_state_resume_prepare(). */
trace_ram_dirty_bitmap_reload_complete(block->idstr);
qatomic_dec(&rs->postcopy_bmap_sync_requested);
/*
* We succeeded to sync bitmap for current ramblock. If this is
* the last one to sync, we need to notify the main send thread.
* We succeeded to sync bitmap for current ramblock. Always kick the
* migration thread to check whether all requested bitmaps are
* reloaded. NOTE: it's racy to only kick when requested==0, because
* we don't know whether the migration thread may still be increasing
* it.
*/
ram_dirty_bitmap_reload_notify(s);
migration_rp_kick(s);
ret = 0;
out:

File diff suppressed because it is too large Load Diff

View File

@ -2734,7 +2734,8 @@ static bool postcopy_pause_incoming(MigrationIncomingState *mis)
qemu_mutex_unlock(&mis->postcopy_prio_thread_mutex);
}
migrate_set_state(&mis->state, MIGRATION_STATUS_POSTCOPY_ACTIVE,
/* Current state can be either ACTIVE or RECOVER */
migrate_set_state(&mis->state, mis->state,
MIGRATION_STATUS_POSTCOPY_PAUSED);
/* Notify the fault thread for the invalidated file handle */

View File

@ -208,12 +208,14 @@ qemu_rdma_accept_incoming_migration(void) ""
qemu_rdma_accept_incoming_migration_accepted(void) ""
qemu_rdma_accept_pin_state(bool pin) "%d"
qemu_rdma_accept_pin_verbsc(void *verbs) "Verbs context after listen: %p"
qemu_rdma_block_for_wrid_miss(const char *wcompstr, int wcomp, const char *gcompstr, uint64_t req) "A Wanted wrid %s (%d) but got %s (%" PRIu64 ")"
qemu_rdma_block_for_wrid_miss(uint64_t wcomp, uint64_t req) "A Wanted wrid %" PRIu64 " but got %" PRIu64
qemu_rdma_cleanup_disconnect(void) ""
qemu_rdma_close(void) ""
qemu_rdma_connect_pin_all_requested(void) ""
qemu_rdma_connect_pin_all_outcome(bool pin) "%d"
qemu_rdma_dest_init_trying(const char *host, const char *ip) "%s => %s"
qemu_rdma_dump_id_failed(const char *who) "%s RDMA Device opened, but can't query port information"
qemu_rdma_dump_id(const char *who, const char *name, const char *dev_name, const char *dev_path, const char *ibdev_path, int transport, const char *transport_name) "%s RDMA Device opened: kernel name %s uverbs device name %s, infiniband_verbs class device path %s, infiniband class device path %s, transport: (%d) %s"
qemu_rdma_dump_gid(const char *who, const char *src, const char *dst) "%s Source GID: %s, Dest GID: %s"
qemu_rdma_exchange_get_response_start(const char *desc) "CONTROL: %s receiving..."
qemu_rdma_exchange_get_response_none(const char *desc, int type) "Surprise: got %s (%d)"
@ -222,9 +224,9 @@ qemu_rdma_exchange_send_waiting(const char *desc) "Waiting for response %s"
qemu_rdma_exchange_send_received(const char *desc) "Response %s received."
qemu_rdma_fill(size_t control_len, size_t size) "RDMA %zd of %zd bytes already in buffer"
qemu_rdma_init_ram_blocks(int blocks) "Allocated %d local ram block structures"
qemu_rdma_poll_recv(const char *compstr, int64_t comp, int64_t id, int sent) "completion %s #%" PRId64 " received (%" PRId64 ") left %d"
qemu_rdma_poll_write(const char *compstr, int64_t comp, int left, uint64_t block, uint64_t chunk, void *local, void *remote) "completions %s (%" PRId64 ") left %d, block %" PRIu64 ", chunk: %" PRIu64 " %p %p"
qemu_rdma_poll_other(const char *compstr, int64_t comp, int left) "other completion %s (%" PRId64 ") received left %d"
qemu_rdma_poll_recv(uint64_t comp, int64_t id, int sent) "completion %" PRIu64 " received (%" PRId64 ") left %d"
qemu_rdma_poll_write(uint64_t comp, int left, uint64_t block, uint64_t chunk, void *local, void *remote) "completions %" PRIu64 " left %d, block %" PRIu64 ", chunk: %" PRIu64 " %p %p"
qemu_rdma_poll_other(uint64_t comp, int left) "other completion %" PRIu64 " received left %d"
qemu_rdma_post_send_control(const char *desc) "CONTROL: sending %s.."
qemu_rdma_register_and_get_keys(uint64_t len, void *start) "Registering %" PRIu64 " bytes @ %p"
qemu_rdma_register_odp_mr(const char *name) "Try to register On-Demand Paging memory region: %s"

View File

@ -230,9 +230,8 @@
# throttled during auto-converge. This is only present when
# auto-converge has started throttling guest cpus. (Since 2.7)
#
# @error-desc: the human readable error description string, when
# @status is 'failed'. Clients should not attempt to parse the
# error strings. (Since 2.7)
# @error-desc: the human readable error description string. Clients
# should not attempt to parse the error strings. (Since 2.7)
#
# @postcopy-blocktime: total time when all vCPU were blocked during
# postcopy live migration. This is only present when the

View File

@ -1259,6 +1259,28 @@ void qtest_memset(QTestState *s, uint64_t addr, uint8_t pattern, size_t size)
qtest_rsp(s);
}
QDict *qtest_vqmp_assert_failure_ref(QTestState *qts,
const char *fmt, va_list args)
{
QDict *response;
QDict *ret;
response = qtest_vqmp(qts, fmt, args);
g_assert(response);
if (!qdict_haskey(response, "error")) {
g_autoptr(GString) s = qobject_to_json_pretty(QOBJECT(response), true);
g_test_message("%s", s->str);
}
g_assert(qdict_haskey(response, "error"));
g_assert(!qdict_haskey(response, "return"));
ret = qdict_get_qdict(response, "error");
qobject_ref(ret);
qobject_unref(response);
return ret;
}
QDict *qtest_vqmp_assert_success_ref(QTestState *qts,
const char *fmt, va_list args)
{
@ -1321,6 +1343,17 @@ void qtest_vqmp_fds_assert_success(QTestState *qts, int *fds, size_t nfds,
}
#endif /* !_WIN32 */
QDict *qtest_qmp_assert_failure_ref(QTestState *qts, const char *fmt, ...)
{
QDict *response;
va_list ap;
va_start(ap, fmt);
response = qtest_vqmp_assert_failure_ref(qts, fmt, ap);
va_end(ap);
return response;
}
QDict *qtest_qmp_assert_success_ref(QTestState *qts, const char *fmt, ...)
{
QDict *response;

View File

@ -810,6 +810,34 @@ void qtest_vqmp_fds_assert_success(QTestState *qts, int *fds, size_t nfds,
G_GNUC_PRINTF(4, 0);
#endif /* !_WIN32 */
/**
* qtest_qmp_assert_failure_ref:
* @qts: QTestState instance to operate on
* @fmt: QMP message to send to qemu, formatted like
* qobject_from_jsonf_nofail(). See parse_interpolation() for what's
* supported after '%'.
*
* Sends a QMP message to QEMU, asserts that an 'error' key is present in
* the response, and returns the response.
*/
QDict *qtest_qmp_assert_failure_ref(QTestState *qts, const char *fmt, ...)
G_GNUC_PRINTF(2, 3);
/**
* qtest_vqmp_assert_failure_ref:
* @qts: QTestState instance to operate on
* @fmt: QMP message to send to qemu, formatted like
* qobject_from_jsonf_nofail(). See parse_interpolation() for what's
* supported after '%'.
* @args: variable arguments for @fmt
*
* Sends a QMP message to QEMU, asserts that an 'error' key is present in
* the response, and returns the response.
*/
QDict *qtest_vqmp_assert_failure_ref(QTestState *qts,
const char *fmt, va_list args)
G_GNUC_PRINTF(2, 0);
/**
* qtest_qmp_assert_success_ref:
* @qts: QTestState instance to operate on

View File

@ -317,6 +317,7 @@ qtests = {
'tpm-tis-i2c-test': [io, tpmemu_files, 'qtest_aspeed.c'],
'tpm-tis-device-swtpm-test': [io, tpmemu_files, 'tpm-tis-util.c'],
'tpm-tis-device-test': [io, tpmemu_files, 'tpm-tis-util.c'],
'virtio-net-failover': files('migration-helpers.c'),
'vmgenid-test': files('boot-sector.c', 'acpi-utils.c'),
'netdev-socket': files('netdev-socket.c', '../unit/socket-helpers.c'),
}

View File

@ -49,6 +49,26 @@ bool migrate_watch_for_resume(QTestState *who, const char *name,
return false;
}
void migrate_qmp_fail(QTestState *who, const char *uri, const char *fmt, ...)
{
va_list ap;
QDict *args, *err;
va_start(ap, fmt);
args = qdict_from_vjsonf_nofail(fmt, ap);
va_end(ap);
g_assert(!qdict_haskey(args, "uri"));
qdict_put_str(args, "uri", uri);
err = qtest_qmp_assert_failure_ref(
who, "{ 'execute': 'migrate', 'arguments': %p}", args);
g_assert(qdict_haskey(err, "desc"));
qobject_unref(err);
}
/*
* Send QMP command "migrate".
* Arguments are built from @fmt... (formatted like
@ -70,6 +90,46 @@ void migrate_qmp(QTestState *who, const char *uri, const char *fmt, ...)
"{ 'execute': 'migrate', 'arguments': %p}", args);
}
void migrate_set_capability(QTestState *who, const char *capability,
bool value)
{
qtest_qmp_assert_success(who,
"{ 'execute': 'migrate-set-capabilities',"
"'arguments': { "
"'capabilities': [ { "
"'capability': %s, 'state': %i } ] } }",
capability, value);
}
void migrate_incoming_qmp(QTestState *to, const char *uri, const char *fmt, ...)
{
va_list ap;
QDict *args, *rsp, *data;
va_start(ap, fmt);
args = qdict_from_vjsonf_nofail(fmt, ap);
va_end(ap);
g_assert(!qdict_haskey(args, "uri"));
qdict_put_str(args, "uri", uri);
migrate_set_capability(to, "events", true);
rsp = qtest_qmp(to, "{ 'execute': 'migrate-incoming', 'arguments': %p}",
args);
g_assert(qdict_haskey(rsp, "return"));
qobject_unref(rsp);
rsp = qtest_qmp_eventwait_ref(to, "MIGRATION");
g_assert(qdict_haskey(rsp, "data"));
data = qdict_get_qdict(rsp, "data");
g_assert(qdict_haskey(data, "status"));
g_assert_cmpstr(qdict_get_str(data, "status"), ==, "setup");
qobject_unref(rsp);
}
/*
* Note: caller is responsible to free the returned object via
* qobject_unref() after use

View File

@ -23,6 +23,16 @@ bool migrate_watch_for_resume(QTestState *who, const char *name,
G_GNUC_PRINTF(3, 4)
void migrate_qmp(QTestState *who, const char *uri, const char *fmt, ...);
G_GNUC_PRINTF(3, 4)
void migrate_incoming_qmp(QTestState *who, const char *uri,
const char *fmt, ...);
G_GNUC_PRINTF(3, 4)
void migrate_qmp_fail(QTestState *who, const char *uri, const char *fmt, ...);
void migrate_set_capability(QTestState *who, const char *capability,
bool value);
QDict *migrate_query(QTestState *who);
QDict *migrate_query_not_failed(QTestState *who);

View File

@ -605,17 +605,6 @@ static void migrate_cancel(QTestState *who)
qtest_qmp_assert_success(who, "{ 'execute': 'migrate_cancel' }");
}
static void migrate_set_capability(QTestState *who, const char *capability,
bool value)
{
qtest_qmp_assert_success(who,
"{ 'execute': 'migrate-set-capabilities',"
"'arguments': { "
"'capabilities': [ { "
"'capability': %s, 'state': %i } ] } }",
capability, value);
}
static void migrate_postcopy_start(QTestState *from, QTestState *to)
{
qtest_qmp_assert_success(from, "{ 'execute': 'migrate-start-postcopy' }");
@ -708,6 +697,8 @@ typedef struct {
MIG_TEST_FAIL,
/* This test should fail, dest qemu should fail with abnormal status */
MIG_TEST_FAIL_DEST_QUIT_ERR,
/* The QMP command for this migration should fail with an error */
MIG_TEST_QMP_ERROR,
} result;
/*
@ -1514,6 +1505,7 @@ static void test_precopy_common(MigrateCommon *args)
{
QTestState *from, *to;
void *data_hook = NULL;
g_autofree char *connect_uri = NULL;
if (test_migrate_start(&from, &to, args->listen_uri, &args->start)) {
return;
@ -1548,13 +1540,17 @@ static void test_precopy_common(MigrateCommon *args)
}
if (!args->connect_uri) {
g_autofree char *local_connect_uri =
migrate_get_socket_address(to, "socket-address");
migrate_qmp(from, local_connect_uri, "{}");
connect_uri = migrate_get_socket_address(to, "socket-address");
} else {
migrate_qmp(from, args->connect_uri, "{}");
connect_uri = g_strdup(args->connect_uri);
}
if (args->result == MIG_TEST_QMP_ERROR) {
migrate_qmp_fail(from, connect_uri, "{}");
goto finish;
}
migrate_qmp(from, connect_uri, "{}");
if (args->result != MIG_TEST_SUCCEED) {
bool allow_active = args->result == MIG_TEST_FAIL;
@ -1606,6 +1602,7 @@ static void test_precopy_common(MigrateCommon *args)
wait_for_serial("dest_serial");
}
finish:
if (args->finish_hook) {
args->finish_hook(from, to, data_hook);
}
@ -1981,8 +1978,7 @@ static void *test_migrate_fd_start_hook(QTestState *from,
close(pair[0]);
/* Start incoming migration from the 1st socket */
qtest_qmp_assert_success(to, "{ 'execute': 'migrate-incoming',"
" 'arguments': { 'uri': 'fd:fd-mig' }}");
migrate_incoming_qmp(to, "fd:fd-mig", "{}");
/* Send the 2nd socket to the target */
qtest_qmp_fds_assert_success(from, &pair[1], 1,
@ -2204,8 +2200,7 @@ test_migrate_precopy_tcp_multifd_start_common(QTestState *from,
migrate_set_capability(to, "multifd", true);
/* Start incoming migration from the 1st socket */
qtest_qmp_assert_success(to, "{ 'execute': 'migrate-incoming',"
" 'arguments': { 'uri': 'tcp:127.0.0.1:0' }}");
migrate_incoming_qmp(to, "tcp:127.0.0.1:0", "{}");
return NULL;
}
@ -2458,8 +2453,7 @@ static void test_multifd_tcp_cancel(void)
migrate_set_capability(to, "multifd", true);
/* Start incoming migration from the 1st socket */
qtest_qmp_assert_success(to, "{ 'execute': 'migrate-incoming',"
" 'arguments': { 'uri': 'tcp:127.0.0.1:0' }}");
migrate_incoming_qmp(to, "tcp:127.0.0.1:0", "{}");
/* Wait for the first serial output from the source */
wait_for_serial("src_serial");
@ -2489,8 +2483,7 @@ static void test_multifd_tcp_cancel(void)
migrate_set_capability(to2, "multifd", true);
/* Start incoming migration from the 1st socket */
qtest_qmp_assert_success(to2, "{ 'execute': 'migrate-incoming',"
" 'arguments': { 'uri': 'tcp:127.0.0.1:0' }}");
migrate_incoming_qmp(to2, "tcp:127.0.0.1:0", "{}");
g_free(uri);
uri = migrate_get_socket_address(to2, "socket-address");

View File

@ -11,6 +11,7 @@
#include "libqtest.h"
#include "libqos/pci.h"
#include "libqos/pci-pc.h"
#include "migration-helpers.h"
#include "qapi/qmp/qdict.h"
#include "qapi/qmp/qlist.h"
#include "qapi/qmp/qjson.h"
@ -736,26 +737,10 @@ static void test_migrate_out(gconstpointer opaque)
machine_stop(qts);
}
static QDict *get_migration_event(QTestState *qts)
{
QDict *resp;
QDict *data;
resp = qtest_qmp_eventwait_ref(qts, "MIGRATION");
g_assert(qdict_haskey(resp, "data"));
data = qdict_get_qdict(resp, "data");
g_assert(qdict_haskey(data, "status"));
qobject_ref(data);
qobject_unref(resp);
return data;
}
static void test_migrate_in(gconstpointer opaque)
{
QTestState *qts;
QDict *resp, *args, *ret;
QDict *resp, *ret;
g_autofree gchar *uri = g_strdup_printf("exec: cat %s", (gchar *)opaque);
qts = machine_start(BASE_MACHINE
@ -787,18 +772,7 @@ static void test_migrate_in(gconstpointer opaque)
check_one_card(qts, true, "standby0", MAC_STANDBY0);
check_one_card(qts, false, "primary0", MAC_PRIMARY0);
args = qdict_from_jsonf_nofail("{}");
g_assert_nonnull(args);
qdict_put_str(args, "uri", uri);
resp = qtest_qmp(qts, "{ 'execute': 'migrate-incoming', 'arguments': %p}",
args);
g_assert(qdict_haskey(resp, "return"));
qobject_unref(resp);
resp = get_migration_event(qts);
g_assert_cmpstr(qdict_get_str(resp, "status"), ==, "setup");
qobject_unref(resp);
migrate_incoming_qmp(qts, uri, "{}");
resp = get_failover_negociated_event(qts);
g_assert_cmpstr(qdict_get_str(resp, "device-id"), ==, "standby0");
@ -888,7 +862,7 @@ static void test_off_migrate_out(gconstpointer opaque)
static void test_off_migrate_in(gconstpointer opaque)
{
QTestState *qts;
QDict *resp, *args, *ret;
QDict *ret;
g_autofree gchar *uri = g_strdup_printf("exec: cat %s", (gchar *)opaque);
qts = machine_start(BASE_MACHINE
@ -920,18 +894,7 @@ static void test_off_migrate_in(gconstpointer opaque)
check_one_card(qts, true, "standby0", MAC_STANDBY0);
check_one_card(qts, true, "primary0", MAC_PRIMARY0);
args = qdict_from_jsonf_nofail("{}");
g_assert_nonnull(args);
qdict_put_str(args, "uri", uri);
resp = qtest_qmp(qts, "{ 'execute': 'migrate-incoming', 'arguments': %p}",
args);
g_assert(qdict_haskey(resp, "return"));
qobject_unref(resp);
resp = get_migration_event(qts);
g_assert_cmpstr(qdict_get_str(resp, "status"), ==, "setup");
qobject_unref(resp);
migrate_incoming_qmp(qts, uri, "{}");
check_one_card(qts, true, "standby0", MAC_STANDBY0);
check_one_card(qts, true, "primary0", MAC_PRIMARY0);
@ -1026,7 +989,7 @@ static void test_guest_off_migrate_out(gconstpointer opaque)
static void test_guest_off_migrate_in(gconstpointer opaque)
{
QTestState *qts;
QDict *resp, *args, *ret;
QDict *ret;
g_autofree gchar *uri = g_strdup_printf("exec: cat %s", (gchar *)opaque);
qts = machine_start(BASE_MACHINE
@ -1058,18 +1021,7 @@ static void test_guest_off_migrate_in(gconstpointer opaque)
check_one_card(qts, true, "standby0", MAC_STANDBY0);
check_one_card(qts, false, "primary0", MAC_PRIMARY0);
args = qdict_from_jsonf_nofail("{}");
g_assert_nonnull(args);
qdict_put_str(args, "uri", uri);
resp = qtest_qmp(qts, "{ 'execute': 'migrate-incoming', 'arguments': %p}",
args);
g_assert(qdict_haskey(resp, "return"));
qobject_unref(resp);
resp = get_migration_event(qts);
g_assert_cmpstr(qdict_get_str(resp, "status"), ==, "setup");
qobject_unref(resp);
migrate_incoming_qmp(qts, uri, "{}");
check_one_card(qts, true, "standby0", MAC_STANDBY0);
check_one_card(qts, false, "primary0", MAC_PRIMARY0);
@ -1728,7 +1680,7 @@ static void test_multi_out(gconstpointer opaque)
static void test_multi_in(gconstpointer opaque)
{
QTestState *qts;
QDict *resp, *args, *ret;
QDict *resp, *ret;
g_autofree gchar *uri = g_strdup_printf("exec: cat %s", (gchar *)opaque);
qts = machine_start(BASE_MACHINE
@ -1794,18 +1746,7 @@ static void test_multi_in(gconstpointer opaque)
check_one_card(qts, true, "standby1", MAC_STANDBY1);
check_one_card(qts, false, "primary1", MAC_PRIMARY1);
args = qdict_from_jsonf_nofail("{}");
g_assert_nonnull(args);
qdict_put_str(args, "uri", uri);
resp = qtest_qmp(qts, "{ 'execute': 'migrate-incoming', 'arguments': %p}",
args);
g_assert(qdict_haskey(resp, "return"));
qobject_unref(resp);
resp = get_migration_event(qts);
g_assert_cmpstr(qdict_get_str(resp, "status"), ==, "setup");
qobject_unref(resp);
migrate_incoming_qmp(qts, uri, "{}");
resp = get_failover_negociated_event(qts);
g_assert_cmpstr(qdict_get_str(resp, "device-id"), ==, "standby0");