static int process_jit_info(QemuHttpConnection *conn) { int i; TranslationBlock *tb; QList *res = qlist_new(); for (i = 0; i < nb_tbs; i++) { tb = &tbs[i]; QList *item = qlist_new(); qlist_append(item, qint_from_int(tb->pc)); qlist_append(item, qint_from_int(tb->size)); qlist_append(item, qint_from_int(tb->flags)); qlist_append(item, qint_from_int(tb->page_addr[1] != -1 ? 1 : 0)); qlist_append(item, qint_from_int(tb->tb_next_offset[0])); qlist_append(item, qint_from_int(tb->tb_next_offset[1])); qlist_append(res, item); } int st = 0; st = respond_with_json(conn, QOBJECT(res)); qobject_decref(QOBJECT(res)); return st; }
static int process_cpu_info(QemuHttpConnection *conn) { CPUState *env; QList *cpu_list; int i; cpu_list = qlist_new(); for (env = first_cpu; env != NULL; env = env->next_cpu) { QDict *cpu; QObject *obj; obj = qobject_from_jsonf("{ 'CPU': %d }", env->cpu_index); cpu = qobject_to_qdict(obj); qdict_put(cpu, "eip", qint_from_int(env->eip + env->segs[R_CS].base)); qdict_put(cpu, "eax", qint_from_int(EAX)); qdict_put(cpu, "ebx", qint_from_int(EBX)); qdict_put(cpu, "ecx", qint_from_int(ECX)); qdict_put(cpu, "edx", qint_from_int(EDX)); qdict_put(cpu, "esp", qint_from_int(ESP)); qdict_put(cpu, "ebp", qint_from_int(EBP)); qdict_put(cpu, "esi", qint_from_int(ESI)); qdict_put(cpu, "edi", qint_from_int(EDI)); qdict_put(cpu, "dt", qint_from_int(dev_time)); qdict_put(cpu, "qt", qint_from_int(qemu_time)); #ifdef CONFIG_PROFILER qdict_put(cpu, "tb_count", qint_from_int(tcg_ctx.tb_count)); qdict_put(cpu, "tb_count1", qint_from_int(tcg_ctx.tb_count1)); qdict_put(cpu, "op_count", qint_from_int(tcg_ctx.op_count)); qdict_put(cpu, "op_count_max", qint_from_int(tcg_ctx.op_count_max)); qdict_put(cpu, "temp_count", qint_from_int(tcg_ctx.temp_count)); qdict_put(cpu, "temp_count_max", qint_from_int(tcg_ctx.temp_count_max)); qdict_put(cpu, "del_op_count", qint_from_int(tcg_ctx.del_op_count)); qdict_put(cpu, "code_in_len", qint_from_int(tcg_ctx.code_in_len)); qdict_put(cpu, "code_out_len", qint_from_int(tcg_ctx.code_out_len)); qdict_put(cpu, "interm_time", qint_from_int(tcg_ctx.interm_time)); qdict_put(cpu, "code_time", qint_from_int(tcg_ctx.code_time)); qdict_put(cpu, "la_time", qint_from_int(tcg_ctx.la_time)); qdict_put(cpu, "restore_count", qint_from_int(tcg_ctx.restore_count)); qdict_put(cpu, "restore_time", qint_from_int(tcg_ctx.restore_time)); for (i = INDEX_op_end; i < NB_OPS; i++) { qdict_put(cpu, tcg_op_defs[i].name, qint_from_int(tcg_table_op_count[i])); } #endif qlist_append(cpu_list, cpu); } int st = 0; st = respond_with_json(conn, QOBJECT(cpu_list)); qobject_decref(QOBJECT(cpu_list)); return st; }
static void qobject_is_equal_list_test(void) { QList *list_0, *list_1, *list_cloned; QList *list_reordered, *list_longer, *list_shorter; list_0 = qlist_new(); list_1 = qlist_new(); list_reordered = qlist_new(); list_longer = qlist_new(); list_shorter = qlist_new(); qlist_append_int(list_0, 1); qlist_append_int(list_0, 2); qlist_append_int(list_0, 3); qlist_append_int(list_1, 1); qlist_append_int(list_1, 2); qlist_append_int(list_1, 3); qlist_append_int(list_reordered, 1); qlist_append_int(list_reordered, 3); qlist_append_int(list_reordered, 2); qlist_append_int(list_longer, 1); qlist_append_int(list_longer, 2); qlist_append_int(list_longer, 3); qlist_append_null(list_longer); qlist_append_int(list_shorter, 1); qlist_append_int(list_shorter, 2); list_cloned = qlist_copy(list_0); check_equal(list_0, list_1, list_cloned); check_unequal(list_0, list_reordered, list_longer, list_shorter); /* With a NaN in it, the list should no longer compare equal to * itself */ qlist_append(list_0, qnum_from_double(NAN)); g_assert(qobject_is_equal(QOBJECT(list_0), QOBJECT(list_0)) == false); free_all(list_0, list_1, list_cloned, list_reordered, list_longer, list_shorter); }
static void qobject_output_start_list(Visitor *v, const char *name, GenericList **listp, size_t size, Error **errp) { QObjectOutputVisitor *qov = to_qov(v); QList *list = qlist_new(); qobject_output_add(qov, name, list); qobject_output_push(qov, list, listp); }
static void qobject_to_qlist_test(void) { QList *qlist; qlist = qlist_new(); g_assert(qobject_to_qlist(QOBJECT(qlist)) == qlist); // destroy doesn't exist yet g_free(qlist); }
static int process_memory_info(QemuHttpConnection *conn) { int l1, l2; int st; uint32_t pgd, pde, pte; int buf_size; char buf[128]; CPUState *env = first_cpu; QList *res = qlist_new(); if (!(env->cr[0] & CR0_PG_MASK)) goto out; if (env->cr[4] & CR4_PAE_MASK) goto out; pgd = env->cr[3] & ~0xfff; for (l1 = 0; l1 < 1024; ++l1) { cpu_physical_memory_read(pgd + l1 * 4, &pde, 4); pde = le32_to_cpu(pde); if (pde & PG_PRESENT_MASK) { /* 4kb pages */ if (!(pde & PG_PSE_MASK) || !(env->cr[4] & CR4_PSE_MASK)) { for (l2 = 0; l2 < 1024; ++l2) { cpu_physical_memory_read((pde & ~0xfff) + l2 * 4, &pte, 4); pte = le32_to_cpu(pte); if (pte & PG_PRESENT_MASK) { buf_size = snprintf(buf, sizeof(buf), "%02X (%02X) (%c%c%c%c%c%c%c%c%c)", (l1 << 22) + (l2 << 12), (pde & ~0xfff) + l2 * 4, pte & PG_NX_MASK ? 'X' : '-', pte & PG_GLOBAL_MASK ? 'G' : '-', pte & PG_PSE_MASK ? 'P' : '-', pte & PG_DIRTY_MASK ? 'D' : '-', pte & PG_ACCESSED_MASK ? 'A' : '-', pte & PG_PCD_MASK ? 'C' : '-', pte & PG_PWT_MASK ? 'T' : '-', pte & PG_USER_MASK ? 'U' : '-', pte & PG_RW_MASK ? 'W' : '-'); buf[buf_size] = 0; qlist_append(res, qstring_from_str(buf)); } } } } } out: st = respond_with_json(conn, QOBJECT(res)); qobject_decref(QOBJECT(res)); return st; }
static void qlist_destroy_test(void) { int i; QList *qlist; qlist = qlist_new(); for (i = 0; i < 42; i++) qlist_append_int(qlist, i); QDECREF(qlist); }
static void qlist_new_test(void) { QList *qlist; qlist = qlist_new(); g_assert(qlist != NULL); g_assert(qlist->base.refcnt == 1); g_assert(qobject_type(QOBJECT(qlist)) == QTYPE_QLIST); // destroy doesn't exist yet g_free(qlist); }
static void qlit_equal_qobject_test(void) { QObject *qobj = make_qobject(); g_assert(qlit_equal_qobject(&qlit, qobj)); g_assert(!qlit_equal_qobject(&qlit_foo, qobj)); qdict_put(qobject_to(QDict, qobj), "bee", qlist_new()); g_assert(!qlit_equal_qobject(&qlit, qobj)); qobject_unref(qobj); }
static int process_irq_info(QemuHttpConnection *conn) { int i; int64_t count; QList *res = qlist_new(); for (i = 0; i < 16; ++i) { count = irq_count[i]; qlist_append(res, qint_from_int(count)); } int st = 0; st = respond_with_json(conn, QOBJECT(res)); qobject_decref(QOBJECT(res)); return st; }
static int process_disas_info(QemuHttpConnection *conn) { TranslationBlock *tb; DisasBuffer disas_buf = { {0}, 0 }; QList *res = qlist_new(); tb = &tbs[0]; disassemble_to_buffer(tb, &disas_buf); qlist_append(res, qstring_from_str(disas_buf.buffer)); int st = 0; st = respond_with_json(conn, QOBJECT(res)); qobject_decref(QOBJECT(res)); return st; }
static QObject *make_qobject(void) { QDict *qdict = qdict_new(); QList *list = qlist_new(); qdict_put_int(qdict, "foo", 42); qdict_put_str(qdict, "bar", "hello world"); qdict_put_null(qdict, "baz"); qlist_append_int(list, 43); qlist_append_int(list, 44); qlist_append_bool(list, true); qdict_put(qdict, "bee", list); return QOBJECT(qdict); }
static void qlist_iter_test(void) { int i; QList *qlist; qlist = qlist_new(); for (i = 0; i < iter_max; i++) qlist_append_int(qlist, i); iter_called = 0; qlist_iter(qlist, iter_func, NULL); g_assert(iter_called == iter_max); QDECREF(qlist); }
static void qlist_append_test(void) { QInt *qi; QList *qlist; QListEntry *entry; qi = qint_from_int(42); qlist = qlist_new(); qlist_append(qlist, qi); entry = QTAILQ_FIRST(&qlist->head); g_assert(entry != NULL); g_assert(entry->value == QOBJECT(qi)); // destroy doesn't exist yet QDECREF(qi); g_free(entry); g_free(qlist); }
static void qdict_flatten_test(void) { QList *e_1 = qlist_new(); QList *e = qlist_new(); QDict *e_1_2 = qdict_new(); QDict *f = qdict_new(); QList *y = qlist_new(); QDict *z = qdict_new(); QDict *root = qdict_new(); /* * Test the flattening of * * { * "e": [ * 42, * [ * 23, * 66, * { * "a": 0, * "b": 1 * } * ] * ], * "f": { * "c": 2, * "d": 3, * }, * "g": 4, * "y": [{}], * "z": {"a": []} * } * * to * * { * "e.0": 42, * "e.1.0": 23, * "e.1.1": 66, * "e.1.2.a": 0, * "e.1.2.b": 1, * "f.c": 2, * "f.d": 3, * "g": 4, * "y.0": {}, * "z.a": [] * } */ qdict_put_int(e_1_2, "a", 0); qdict_put_int(e_1_2, "b", 1); qlist_append_int(e_1, 23); qlist_append_int(e_1, 66); qlist_append(e_1, e_1_2); qlist_append_int(e, 42); qlist_append(e, e_1); qdict_put_int(f, "c", 2); qdict_put_int(f, "d", 3); qlist_append(y, qdict_new()); qdict_put(z, "a", qlist_new()); qdict_put(root, "e", e); qdict_put(root, "f", f); qdict_put_int(root, "g", 4); qdict_put(root, "y", y); qdict_put(root, "z", z); qdict_flatten(root); g_assert(qdict_get_int(root, "e.0") == 42); g_assert(qdict_get_int(root, "e.1.0") == 23); g_assert(qdict_get_int(root, "e.1.1") == 66); g_assert(qdict_get_int(root, "e.1.2.a") == 0); g_assert(qdict_get_int(root, "e.1.2.b") == 1); g_assert(qdict_get_int(root, "f.c") == 2); g_assert(qdict_get_int(root, "f.d") == 3); g_assert(qdict_get_int(root, "g") == 4); g_assert(!qdict_size(qdict_get_qdict(root, "y.0"))); g_assert(qlist_empty(qdict_get_qlist(root, "z.a"))); g_assert(qdict_size(root) == 10); qobject_unref(root); }
static void qdict_flatten_test(void) { QList *list1 = qlist_new(); QList *list2 = qlist_new(); QDict *dict1 = qdict_new(); QDict *dict2 = qdict_new(); QDict *dict3 = qdict_new(); /* * Test the flattening of * * { * "e": [ * 42, * [ * 23, * 66, * { * "a": 0, * "b": 1 * } * ] * ], * "f": { * "c": 2, * "d": 3, * }, * "g": 4 * } * * to * * { * "e.0": 42, * "e.1.0": 23, * "e.1.1": 66, * "e.1.2.a": 0, * "e.1.2.b": 1, * "f.c": 2, * "f.d": 3, * "g": 4 * } */ qdict_put(dict1, "a", qint_from_int(0)); qdict_put(dict1, "b", qint_from_int(1)); qlist_append_obj(list1, QOBJECT(qint_from_int(23))); qlist_append_obj(list1, QOBJECT(qint_from_int(66))); qlist_append_obj(list1, QOBJECT(dict1)); qlist_append_obj(list2, QOBJECT(qint_from_int(42))); qlist_append_obj(list2, QOBJECT(list1)); qdict_put(dict2, "c", qint_from_int(2)); qdict_put(dict2, "d", qint_from_int(3)); qdict_put_obj(dict3, "e", QOBJECT(list2)); qdict_put_obj(dict3, "f", QOBJECT(dict2)); qdict_put(dict3, "g", qint_from_int(4)); qdict_flatten(dict3); g_assert(qdict_get_int(dict3, "e.0") == 42); g_assert(qdict_get_int(dict3, "e.1.0") == 23); g_assert(qdict_get_int(dict3, "e.1.1") == 66); g_assert(qdict_get_int(dict3, "e.1.2.a") == 0); g_assert(qdict_get_int(dict3, "e.1.2.b") == 1); g_assert(qdict_get_int(dict3, "f.c") == 2); g_assert(qdict_get_int(dict3, "f.d") == 3); g_assert(qdict_get_int(dict3, "g") == 4); g_assert(qdict_size(dict3) == 8); QDECREF(dict3); }
static void qdict_crumple_test_recursive(void) { QDict *src, *dst, *rule, *vnc, *acl, *listen; QDict *empty, *empty_dict, *empty_list_0; QList *rules, *empty_list, *empty_dict_a; src = qdict_new(); qdict_put_str(src, "vnc.listen.addr", "127.0.0.1"); qdict_put_str(src, "vnc.listen.port", "5901"); qdict_put_str(src, "vnc.acl.rules.0.match", "fred"); qdict_put_str(src, "vnc.acl.rules.0.policy", "allow"); qdict_put_str(src, "vnc.acl.rules.1.match", "bob"); qdict_put_str(src, "vnc.acl.rules.1.policy", "deny"); qdict_put_str(src, "vnc.acl.default", "deny"); qdict_put_str(src, "vnc.acl..name", "acl0"); qdict_put_str(src, "vnc.acl.rule..name", "acl0"); qdict_put(src, "empty.dict.a", qlist_new()); qdict_put(src, "empty.list.0", qdict_new()); dst = qobject_to(QDict, qdict_crumple(src, &error_abort)); g_assert(dst); g_assert_cmpint(qdict_size(dst), ==, 2); vnc = qdict_get_qdict(dst, "vnc"); g_assert(vnc); g_assert_cmpint(qdict_size(vnc), ==, 3); listen = qdict_get_qdict(vnc, "listen"); g_assert(listen); g_assert_cmpint(qdict_size(listen), ==, 2); g_assert_cmpstr("127.0.0.1", ==, qdict_get_str(listen, "addr")); g_assert_cmpstr("5901", ==, qdict_get_str(listen, "port")); acl = qdict_get_qdict(vnc, "acl"); g_assert(acl); g_assert_cmpint(qdict_size(acl), ==, 3); rules = qdict_get_qlist(acl, "rules"); g_assert(rules); g_assert_cmpint(qlist_size(rules), ==, 2); rule = qobject_to(QDict, qlist_pop(rules)); g_assert(rule); g_assert_cmpint(qdict_size(rule), ==, 2); g_assert_cmpstr("fred", ==, qdict_get_str(rule, "match")); g_assert_cmpstr("allow", ==, qdict_get_str(rule, "policy")); qobject_unref(rule); rule = qobject_to(QDict, qlist_pop(rules)); g_assert(rule); g_assert_cmpint(qdict_size(rule), ==, 2); g_assert_cmpstr("bob", ==, qdict_get_str(rule, "match")); g_assert_cmpstr("deny", ==, qdict_get_str(rule, "policy")); qobject_unref(rule); /* With recursive crumpling, we should see all names unescaped */ g_assert_cmpstr("acl0", ==, qdict_get_str(vnc, "acl.name")); g_assert_cmpstr("acl0", ==, qdict_get_str(acl, "rule.name")); empty = qdict_get_qdict(dst, "empty"); g_assert(empty); g_assert_cmpint(qdict_size(empty), ==, 2); empty_dict = qdict_get_qdict(empty, "dict"); g_assert(empty_dict); g_assert_cmpint(qdict_size(empty_dict), ==, 1); empty_dict_a = qdict_get_qlist(empty_dict, "a"); g_assert(empty_dict_a && qlist_empty(empty_dict_a)); empty_list = qdict_get_qlist(empty, "list"); g_assert(empty_list); g_assert_cmpint(qlist_size(empty_list), ==, 1); empty_list_0 = qobject_to(QDict, qlist_pop(empty_list)); g_assert(empty_list_0); g_assert_cmpint(qdict_size(empty_list_0), ==, 0); qobject_unref(src); qobject_unref(dst); }
static void qemu_rbd_parse_filename(const char *filename, QDict *options, Error **errp) { const char *start; char *p, *buf; QList *keypairs = NULL; char *found_str; if (!strstart(filename, "rbd:", &start)) { error_setg(errp, "File name must start with 'rbd:'"); return; } buf = g_strdup(start); p = buf; found_str = qemu_rbd_next_tok(p, '/', &p); if (!p) { error_setg(errp, "Pool name is required"); goto done; } qemu_rbd_unescape(found_str); qdict_put_str(options, "pool", found_str); if (strchr(p, '@')) { found_str = qemu_rbd_next_tok(p, '@', &p); qemu_rbd_unescape(found_str); qdict_put_str(options, "image", found_str); found_str = qemu_rbd_next_tok(p, ':', &p); qemu_rbd_unescape(found_str); qdict_put_str(options, "snapshot", found_str); } else { found_str = qemu_rbd_next_tok(p, ':', &p); qemu_rbd_unescape(found_str); qdict_put_str(options, "image", found_str); } if (!p) { goto done; } /* The following are essentially all key/value pairs, and we treat * 'id' and 'conf' a bit special. Key/value pairs may be in any order. */ while (p) { char *name, *value; name = qemu_rbd_next_tok(p, '=', &p); if (!p) { error_setg(errp, "conf option %s has no value", name); break; } qemu_rbd_unescape(name); value = qemu_rbd_next_tok(p, ':', &p); qemu_rbd_unescape(value); if (!strcmp(name, "conf")) { qdict_put_str(options, "conf", value); } else if (!strcmp(name, "id")) { qdict_put_str(options, "user", value); } else { /* * We pass these internally to qemu_rbd_set_keypairs(), so * we can get away with the simpler list of [ "key1", * "value1", "key2", "value2" ] rather than a raw dict * { "key1": "value1", "key2": "value2" } where we can't * guarantee order, or even a more correct but complex * [ { "key1": "value1" }, { "key2": "value2" } ] */ if (!keypairs) { keypairs = qlist_new(); } qlist_append_str(keypairs, name); qlist_append_str(keypairs, value); } } if (keypairs) { qdict_put(options, "=keyvalue-pairs", qobject_to_json(QOBJECT(keypairs))); } done: g_free(buf); QDECREF(keypairs); return; }