qemu with hax to log dma reads & writes jcs.org/2018/11/12/vfio

qlit: move qlit from check-qjson to qobject/

Fix code style issues while at it, to please checkpatch.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <20170825105913.4060-3-marcandre.lureau@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>

authored by

Marc-André Lureau and committed by
Markus Armbruster
28035bcd 0f9afc2a

+140 -96
+49
include/qapi/qmp/qlit.h
··· 1 + /* 2 + * Copyright IBM, Corp. 2009 3 + * Copyright (c) 2013, 2015, 2017 Red Hat Inc. 4 + * 5 + * Authors: 6 + * Anthony Liguori <aliguori@us.ibm.com> 7 + * Markus Armbruster <armbru@redhat.com> 8 + * Marc-André Lureau <marcandre.lureau@redhat.com> 9 + * 10 + * This work is licensed under the terms of the GNU LGPL, version 2.1 or later. 11 + * See the COPYING.LIB file in the top-level directory. 12 + * 13 + */ 14 + #ifndef QLIT_H 15 + #define QLIT_H 16 + 17 + #include "qapi-types.h" 18 + #include "qobject.h" 19 + 20 + typedef struct LiteralQDictEntry LiteralQDictEntry; 21 + typedef struct LiteralQObject LiteralQObject; 22 + 23 + struct LiteralQObject { 24 + int type; 25 + union { 26 + int64_t qnum; 27 + const char *qstr; 28 + LiteralQDictEntry *qdict; 29 + LiteralQObject *qlist; 30 + } value; 31 + }; 32 + 33 + struct LiteralQDictEntry { 34 + const char *key; 35 + LiteralQObject value; 36 + }; 37 + 38 + #define QLIT_QNUM(val) \ 39 + (LiteralQObject){.type = QTYPE_QNUM, .value.qnum = (val)} 40 + #define QLIT_QSTR(val) \ 41 + (LiteralQObject){.type = QTYPE_QSTRING, .value.qstr = (val)} 42 + #define QLIT_QDICT(val) \ 43 + (LiteralQObject){.type = QTYPE_QDICT, .value.qdict = (val)} 44 + #define QLIT_QLIST(val) \ 45 + (LiteralQObject){.type = QTYPE_QLIST, .value.qlist = (val)} 46 + 47 + int compare_litqobj_to_qobj(LiteralQObject *lhs, QObject *rhs); 48 + 49 + #endif /* QLIT_H */
+1 -1
qobject/Makefile.objs
··· 1 - util-obj-y = qnull.o qnum.o qstring.o qdict.o qlist.o qbool.o 1 + util-obj-y = qnull.o qnum.o qstring.o qdict.o qlist.o qbool.o qlit.o 2 2 util-obj-y += qjson.o qobject.o json-lexer.o json-streamer.o json-parser.o
+89
qobject/qlit.c
··· 1 + /* 2 + * QLit literal qobject 3 + * 4 + * Copyright IBM, Corp. 2009 5 + * Copyright (c) 2013, 2015, 2017 Red Hat Inc. 6 + * 7 + * Authors: 8 + * Anthony Liguori <aliguori@us.ibm.com> 9 + * Markus Armbruster <armbru@redhat.com> 10 + * Marc-André Lureau <marcandre.lureau@redhat.com> 11 + * 12 + * This work is licensed under the terms of the GNU LGPL, version 2.1 or later. 13 + * See the COPYING.LIB file in the top-level directory. 14 + */ 15 + 16 + #include "qemu/osdep.h" 17 + 18 + #include "qapi/qmp/qlit.h" 19 + #include "qapi/qmp/types.h" 20 + 21 + typedef struct QListCompareHelper { 22 + int index; 23 + LiteralQObject *objs; 24 + int result; 25 + } QListCompareHelper; 26 + 27 + static void compare_helper(QObject *obj, void *opaque) 28 + { 29 + QListCompareHelper *helper = opaque; 30 + 31 + if (helper->result == 0) { 32 + return; 33 + } 34 + 35 + if (helper->objs[helper->index].type == QTYPE_NONE) { 36 + helper->result = 0; 37 + return; 38 + } 39 + 40 + helper->result = 41 + compare_litqobj_to_qobj(&helper->objs[helper->index++], obj); 42 + } 43 + 44 + int compare_litqobj_to_qobj(LiteralQObject *lhs, QObject *rhs) 45 + { 46 + int64_t val; 47 + 48 + if (!rhs || lhs->type != qobject_type(rhs)) { 49 + return 0; 50 + } 51 + 52 + switch (lhs->type) { 53 + case QTYPE_QNUM: 54 + g_assert(qnum_get_try_int(qobject_to_qnum(rhs), &val)); 55 + return lhs->value.qnum == val; 56 + case QTYPE_QSTRING: 57 + return (strcmp(lhs->value.qstr, 58 + qstring_get_str(qobject_to_qstring(rhs))) == 0); 59 + case QTYPE_QDICT: { 60 + int i; 61 + 62 + for (i = 0; lhs->value.qdict[i].key; i++) { 63 + QObject *obj = qdict_get(qobject_to_qdict(rhs), 64 + lhs->value.qdict[i].key); 65 + 66 + if (!compare_litqobj_to_qobj(&lhs->value.qdict[i].value, obj)) { 67 + return 0; 68 + } 69 + } 70 + 71 + return 1; 72 + } 73 + case QTYPE_QLIST: { 74 + QListCompareHelper helper; 75 + 76 + helper.index = 0; 77 + helper.objs = lhs->value.qlist; 78 + helper.result = 1; 79 + 80 + qlist_iter(qobject_to_qlist(rhs), compare_helper, &helper); 81 + 82 + return helper.result; 83 + } 84 + default: 85 + break; 86 + } 87 + 88 + return 0; 89 + }
+1 -95
tests/check-qjson.c
··· 16 16 #include "qapi/error.h" 17 17 #include "qapi/qmp/types.h" 18 18 #include "qapi/qmp/qjson.h" 19 + #include "qapi/qmp/qlit.h" 19 20 #include "qemu-common.h" 20 21 21 22 static void escaped_string(void) ··· 1057 1058 1058 1059 qobject_decref(obj); 1059 1060 QDECREF(null); 1060 - } 1061 - 1062 - typedef struct LiteralQDictEntry LiteralQDictEntry; 1063 - typedef struct LiteralQObject LiteralQObject; 1064 - 1065 - struct LiteralQObject 1066 - { 1067 - int type; 1068 - union { 1069 - int64_t qnum; 1070 - const char *qstr; 1071 - LiteralQDictEntry *qdict; 1072 - LiteralQObject *qlist; 1073 - } value; 1074 - }; 1075 - 1076 - struct LiteralQDictEntry 1077 - { 1078 - const char *key; 1079 - LiteralQObject value; 1080 - }; 1081 - 1082 - #define QLIT_QNUM(val) (LiteralQObject){.type = QTYPE_QNUM, .value.qnum = (val)} 1083 - #define QLIT_QSTR(val) (LiteralQObject){.type = QTYPE_QSTRING, .value.qstr = (val)} 1084 - #define QLIT_QDICT(val) (LiteralQObject){.type = QTYPE_QDICT, .value.qdict = (val)} 1085 - #define QLIT_QLIST(val) (LiteralQObject){.type = QTYPE_QLIST, .value.qlist = (val)} 1086 - 1087 - typedef struct QListCompareHelper 1088 - { 1089 - int index; 1090 - LiteralQObject *objs; 1091 - int result; 1092 - } QListCompareHelper; 1093 - 1094 - static int compare_litqobj_to_qobj(LiteralQObject *lhs, QObject *rhs); 1095 - 1096 - static void compare_helper(QObject *obj, void *opaque) 1097 - { 1098 - QListCompareHelper *helper = opaque; 1099 - 1100 - if (helper->result == 0) { 1101 - return; 1102 - } 1103 - 1104 - if (helper->objs[helper->index].type == QTYPE_NONE) { 1105 - helper->result = 0; 1106 - return; 1107 - } 1108 - 1109 - helper->result = compare_litqobj_to_qobj(&helper->objs[helper->index++], obj); 1110 - } 1111 - 1112 - static int compare_litqobj_to_qobj(LiteralQObject *lhs, QObject *rhs) 1113 - { 1114 - int64_t val; 1115 - 1116 - if (!rhs || lhs->type != qobject_type(rhs)) { 1117 - return 0; 1118 - } 1119 - 1120 - switch (lhs->type) { 1121 - case QTYPE_QNUM: 1122 - g_assert(qnum_get_try_int(qobject_to_qnum(rhs), &val)); 1123 - return lhs->value.qnum == val; 1124 - case QTYPE_QSTRING: 1125 - return (strcmp(lhs->value.qstr, qstring_get_str(qobject_to_qstring(rhs))) == 0); 1126 - case QTYPE_QDICT: { 1127 - int i; 1128 - 1129 - for (i = 0; lhs->value.qdict[i].key; i++) { 1130 - QObject *obj = qdict_get(qobject_to_qdict(rhs), lhs->value.qdict[i].key); 1131 - 1132 - if (!compare_litqobj_to_qobj(&lhs->value.qdict[i].value, obj)) { 1133 - return 0; 1134 - } 1135 - } 1136 - 1137 - return 1; 1138 - } 1139 - case QTYPE_QLIST: { 1140 - QListCompareHelper helper; 1141 - 1142 - helper.index = 0; 1143 - helper.objs = lhs->value.qlist; 1144 - helper.result = 1; 1145 - 1146 - qlist_iter(qobject_to_qlist(rhs), compare_helper, &helper); 1147 - 1148 - return helper.result; 1149 - } 1150 - default: 1151 - break; 1152 - } 1153 - 1154 - return 0; 1155 1061 } 1156 1062 1157 1063 static void simple_dict(void)