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

util: add is_equal to UUID API

It's going to be useful, in particular, in VMBus code massively using
uuids aka GUIDs.

Signed-off-by: Roman Kagan <rkagan@virtuozzo.com>
Message-Id: <20171127124355.26015-1-rkagan@virtuozzo.com>
Signed-off-by: Fam Zheng <famz@redhat.com>

authored by

Roman Kagan and committed by
Fam Zheng
bfab1aed dbd73b56

+15 -2
+2
include/qemu/uuid.h
··· 48 48 49 49 int qemu_uuid_is_null(const QemuUUID *uu); 50 50 51 + int qemu_uuid_is_equal(const QemuUUID *lhv, const QemuUUID *rhv); 52 + 51 53 void qemu_uuid_unparse(const QemuUUID *uuid, char *out); 52 54 53 55 char *qemu_uuid_unparse_strdup(const QemuUUID *uuid);
+7 -1
tests/test-uuid.c
··· 93 93 94 94 static void test_uuid_generate(void) 95 95 { 96 + QemuUUID uuid_not_null = { { { 97 + 0x58, 0x6e, 0xce, 0x27, 0x7f, 0x09, 0x41, 0xe0, 98 + 0x9e, 0x74, 0xe9, 0x01, 0x31, 0x7e, 0x9d, 0x42 99 + } } }; 96 100 QemuUUID uuid; 97 101 int i; 98 102 99 103 for (i = 0; i < 100; ++i) { 100 104 qemu_uuid_generate(&uuid); 101 105 g_assert(uuid_is_valid(&uuid)); 106 + g_assert_false(qemu_uuid_is_null(&uuid)); 107 + g_assert_false(qemu_uuid_is_equal(&uuid_not_null, &uuid)); 102 108 } 103 109 } 104 110 ··· 168 174 int main(int argc, char **argv) 169 175 { 170 176 g_test_init(&argc, &argv, NULL); 171 - g_test_add_func("/uuid/generate", test_uuid_generate); 172 177 g_test_add_func("/uuid/is_null", test_uuid_is_null); 178 + g_test_add_func("/uuid/generate", test_uuid_generate); 173 179 g_test_add_func("/uuid/parse", test_uuid_parse); 174 180 g_test_add_func("/uuid/unparse", test_uuid_unparse); 175 181 g_test_add_func("/uuid/unparse_strdup", test_uuid_unparse_strdup);
+6 -1
util/uuid.c
··· 41 41 int qemu_uuid_is_null(const QemuUUID *uu) 42 42 { 43 43 static QemuUUID null_uuid; 44 - return memcmp(uu, &null_uuid, sizeof(QemuUUID)) == 0; 44 + return qemu_uuid_is_equal(uu, &null_uuid); 45 + } 46 + 47 + int qemu_uuid_is_equal(const QemuUUID *lhv, const QemuUUID *rhv) 48 + { 49 + return memcmp(lhv, rhv, sizeof(QemuUUID)) == 0; 45 50 } 46 51 47 52 void qemu_uuid_unparse(const QemuUUID *uuid, char *out)