static int openfile(char *name, int flags, bool writethrough, bool force_share, QDict *opts) { Error *local_err = NULL; if (qemuio_blk) { error_report("file open already, try 'help close'"); QDECREF(opts); return 1; } if (force_share) { if (!opts) { opts = qdict_new(); } if (qdict_haskey(opts, BDRV_OPT_FORCE_SHARE) && !qdict_get_bool(opts, BDRV_OPT_FORCE_SHARE)) { error_report("-U conflicts with image options"); QDECREF(opts); return 1; } qdict_put_bool(opts, BDRV_OPT_FORCE_SHARE, true); } qemuio_blk = blk_new_open(name, NULL, opts, flags, &local_err); if (!qemuio_blk) { error_reportf_err(local_err, "can't open%s%s: ", name ? " device " : "", name ?: ""); return 1; }
static void test_baddest(void) { QTestState *from, *to; QDict *rsp, *rsp_return; const char *status; bool failed; test_migrate_start(&from, &to, "tcp:0:0", true); migrate(from, "tcp:0:0"); do { rsp = wait_command(from, "{ 'execute': 'query-migrate' }"); rsp_return = qdict_get_qdict(rsp, "return"); status = qdict_get_str(rsp_return, "status"); g_assert(!strcmp(status, "setup") || !(strcmp(status, "failed"))); failed = !strcmp(status, "failed"); qobject_unref(rsp); } while (!failed); /* Is the machine currently running? */ rsp = wait_command(from, "{ 'execute': 'query-status' }"); g_assert(qdict_haskey(rsp, "return")); rsp_return = qdict_get_qdict(rsp, "return"); g_assert(qdict_haskey(rsp_return, "running")); g_assert(qdict_get_bool(rsp_return, "running")); qobject_unref(rsp); test_migrate_end(from, to, false); }
TestStruct *p = &test_struct; Error *errp = NULL; QObject *obj; QDict *qdict; visit_type_TestStruct(data->ov, &p, NULL, &errp); g_assert(!error_is_set(&errp)); obj = qmp_output_get_qobject(data->qov); g_assert(obj != NULL); g_assert(qobject_type(obj) == QTYPE_QDICT); qdict = qobject_to_qdict(obj); g_assert_cmpint(qdict_size(qdict), ==, 3); g_assert_cmpint(qdict_get_int(qdict, "integer"), ==, 42); g_assert_cmpint(qdict_get_bool(qdict, "boolean"), ==, 0); g_assert_cmpstr(qdict_get_str(qdict, "string"), ==, "foo"); QDECREF(qdict); } static void test_visitor_out_struct_nested(TestOutputVisitorData *data, const void *unused) { int64_t value = 42; Error *errp = NULL; UserDefNested *ud2; QObject *obj; QDict *qdict, *dict1, *dict2, *dict3, *userdef; const char *string = "user def string"; const char *strings[] = { "forty two", "forty three", "forty four",
void migrate(QOSState *from, QOSState *to, const char *uri) { const char *st; QDict *rsp, *sub; bool running; set_context(from); /* Is the machine currently running? */ rsp = qmp_execute(from->qts, "query-status"); g_assert(qdict_haskey(rsp, "return")); sub = qdict_get_qdict(rsp, "return"); g_assert(qdict_haskey(sub, "running")); running = qdict_get_bool(sub, "running"); qobject_unref(rsp); /* Issue the migrate command. */ rsp = qtest_qmp(from->qts, "{ 'execute': 'migrate', 'arguments': { 'uri': %s }}", uri); g_assert(qdict_haskey(rsp, "return")); qobject_unref(rsp); /* Wait for STOP event, but only if we were running: */ if (running) { qtest_qmp_eventwait(from->qts, "STOP"); } /* If we were running, we can wait for an event. */ if (running) { migrate_allocator(from->alloc, to->alloc); set_context(to); qtest_qmp_eventwait(to->qts, "RESUME"); return; } /* Otherwise, we need to wait: poll until migration is completed. */ while (1) { rsp = qmp_execute(from->qts, "query-migrate"); g_assert(qdict_haskey(rsp, "return")); sub = qdict_get_qdict(rsp, "return"); g_assert(qdict_haskey(sub, "status")); st = qdict_get_str(sub, "status"); /* "setup", "active", "completed", "failed", "cancelled" */ if (strcmp(st, "completed") == 0) { qobject_unref(rsp); break; } if ((strcmp(st, "setup") == 0) || (strcmp(st, "active") == 0)) { qobject_unref(rsp); g_usleep(5000); continue; } fprintf(stderr, "Migration did not complete, status: %s\n", st); g_assert_not_reached(); } migrate_allocator(from->alloc, to->alloc); set_context(to); }