UUID clean ups for 2.8
Subsystems (2)
v2 cover UUID clean ups for 2.8
v2: Fix the endianness wrongness. [Jeff]
Add tests/test-uuid.c. [Denial]
Add r-b of Stefan Weil to the VDI patch.
The facts how we use libuuid now are not particularly pleasant.
- VHDX driver depends on uuid, but is unconditionally checked in iotests 109. If it is not built, the test would fail, leaving no hint about that. In fact this even makes the feature implementation a bit ugly because it compromises the write protection on block 0 with image probing, silently.
- A few other libuuid users, in block/ and crypto/, use it as an optional dependency, and compromises certain functionalities if it is not available.
- On the other hand, there are already a few uuid function fallbacks in those callers.
So instead of making libuuid a hard requirement, let's simply move the fallbacks to util and implement the random version of uuid generation, and be done with it.
Fam
Fam Zheng (8):
util: Add UUID API
tests: Add uuid tests
vhdx: Use QEMU UUID API
vdi: Use QEMU UUID API
vpc: Use QEMU UUID API
crypto: Switch to QEMU UUID API
tests: No longer dependent on CONFIG_UUID
configure: Remove detection code for UUID
arch_init.c | 19 -------- block/Makefile.objs | 2 +- block/iscsi.c | 2 +- block/vdi.c | 49 +++++---------------- block/vhdx-endian.c | 3 -- block/vhdx.c | 7 ++- block/vpc.c | 8 +--- configure | 70 +++-------------------------- crypto/block-luks.c | 26 +++-------- hw/smbios/smbios.c | 1 + include/qemu/uuid.h | 40 +++++++++++++++++ include/sysemu/sysemu.h | 4 -- qmp.c | 1 + stubs/uuid.c | 2 +- tests/Makefile.include | 2 + tests/test-crypto-block.c | 2 +- tests/test-uuid.c | 110 ++++++++++++++++++++++++++++++++++++++++++++++ util/Makefile.objs | 1 + util/uuid.c | 68 ++++++++++++++++++++++++++++ vl.c | 1 + 20 files changed, 257 insertions(+), 161 deletions(-) create mode 100644 include/qemu/uuid.h create mode 100644 tests/test-uuid.c create mode 100644 util/uuid.c
Signature · 1 line
2.7.4
PATCH v2 1/8 util: Add UUID API
A number of different places across the code base use CONFIG_UUID. Some of them are soft dependency, some are not built if libuuid is not available, some come with dummy fallback, some throws runtime error.
It is hard to maintain, and hard to reason for users.
Since UUID is a simple standard with only a small number of operations, it is cleaner to have a central support in libqemuutil. This patch adds qemu_uuid_* the functions so that all uuid users in the code base can rely on. Except for qemu_uuid_generate which is new code, all other functions are just copy from existing fallbacks from other files.
--- arch_init.c | 19 -------------- block/iscsi.c | 2 +- hw/smbios/smbios.c | 1 + include/qemu/uuid.h | 40 +++++++++++++++++++++++++++++ include/sysemu/sysemu.h | 4 --- qmp.c | 1 + stubs/uuid.c | 2 +- util/Makefile.objs | 1 + util/uuid.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++++ vl.c | 1 + 10 files changed, 114 insertions(+), 25 deletions(-) create mode 100644 include/qemu/uuid.h create mode 100644 util/uuid.c
arch_init.c +0 -19
@@ -235,25 +235,6 @@ void audio_init(void) } } -int qemu_uuid_parse (const char *str,uint8_t *uuid) -{ -int ret; - -if (strlen (str) !=36 ) { -return -1 ; - } - - ret =sscanf (str,UUID_FMT , &uuid[0 ], &uuid[1 ], &uuid[2 ], &uuid[3 ], - &uuid[4 ], &uuid[5 ], &uuid[6 ], &uuid[7 ], &uuid[8 ], &uuid[9 ], - &uuid[10 ], &uuid[11 ], &uuid[12 ], &uuid[13 ], &uuid[14 ], - &uuid[15 ]); - -if (ret !=16 ) { -return -1 ; - } -return 0 ; -} -void do_acpitable_option (const QemuOpts *opts) {#ifdef TARGET_I386
block/iscsi.c +1 -1
@@ -36,7 +36,7 @@#include "block/block_int.h" #include "block/scsi.h" #include "qemu/iov.h" -#include "sysemu/sysemu.h" +#include "qemu/uuid.h" #include "qmp-commands.h" #include "qapi/qmp/qstring.h" #include "crypto/secret.h"
hw/smbios/smbios.c +1 -0
@@ -20,6 +20,7 @@#include "qemu/config-file.h" #include "qemu/error-report.h" #include "sysemu/sysemu.h" +#include "qemu/uuid.h" #include "sysemu/cpus.h" #include "hw/smbios/smbios.h" #include "hw/loader.h"
include/qemu/uuid.h new file +40 -0
@@ -0,0 +1,40 @@ +/* +* QEMU UUID functions +* +* Copyright 2016 Red Hat, Inc., +* +* Authors: +* Fam Zheng <[email protected]> +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the Free +* Software Foundation; either version 2 of the License, or (at your option) +* any later version. +* +*/ + +#ifndef QEMU_UUID_H +#define QEMU_UUID_H + +#include "qemu-common.h" + +typedef unsigned char QemuUUID [16 ]; + +#define UUID_FMT "%02hhx%02hhx%02hhx%02hhx-" \ + "%02hhx%02hhx-%02hhx%02hhx-" \ + "%02hhx%02hhx-" \ + "%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx" + +#define UUID_FMT_LEN 36 + +#define UUID_NONE "00000000-0000-0000-0000-000000000000" + +void qemu_uuid_generate (QemuUUID out); + +int qemu_uuid_is_null (const QemuUUID uu); + +void qemu_uuid_unparse (const QemuUUID uu,char *out); + +int qemu_uuid_parse (const char *str,uint8_t *uuid); + +#endif
include/sysemu/sysemu.h +0 -4
@@ -18,10 +18,6 @@ extern const char *bios_name;extern const char *qemu_name;extern uint8_t qemu_uuid[];extern bool qemu_uuid_set; -int qemu_uuid_parse (const char *str,uint8_t *uuid); - -#define UUID_FMT "%02hhx%02hhx%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx" -#define UUID_NONE "00000000-0000-0000-0000-000000000000"bool runstate_check (RunState state);void runstate_set (RunState new_state);
qmp.c +1 -0
@@ -35,6 +35,7 @@#include "qom/object_interfaces.h" #include "hw/mem/pc-dimm.h" #include "hw/acpi/acpi_dev_interface.h" +#include "qemu/uuid.h" NameInfo *qmp_query_name (Error **errp) {
stubs/uuid.c +1 -1
@@ -1,6 +1,6 @@#include "qemu/osdep.h" #include "qemu-common.h" -#include "sysemu/sysemu.h" +#include "qemu/uuid.h" #include "qmp-commands.h" UuidInfo *qmp_query_uuid (Error **errp)
util/Makefile.objs +1 -0
@@ -20,6 +20,7 @@ util-obj-y += iov.o qemu-config.o qemu-sockets.o uri.o notify.o util-obj-y += qemu-option.o qemu-progress.o util-obj-y += hexdump.o util-obj-y += crc32c.o +util-obj-y += uuid.o util-obj-y += throttle.o util-obj-y += getauxval.o util-obj-y += readline.o
util/uuid.c new file +68 -0
68 lines not on this page · raw message
vl.c +1 -0
@@ -25,6 +25,7 @@#include "qemu-version.h" #include "qemu/cutils.h" #include "qemu/help_option.h" +#include "qemu/uuid.h" #ifdef CONFIG_SECCOMP #include "sysemu/seccomp.h"
Signature · 1 line
2.7.4
Re: [Qemu-devel] [PATCH v2 1/8] util: Add UUID API
Quoted 100 lines · Fam Zheng
A number of different places across the code base use
CONFIG_UUID. Some of them are soft dependency, some are not built if libuuid is not available, some come with dummy fallback, some throws runtime error.It is hard to maintain, and hard to reason for users.
Since UUID is a simple standard with only a small number of operations, it is cleaner to have a central support in libqemuutil. This patch adds qemu_uuid_* the functions so that all uuid users in the code base can rely on. Except for
qemu_uuid_generatewhich is new code, all other functions are just copy from existing fallbacks from other files.Signed-off-by Fam Zheng <[email protected]>--- arch_init.c | 19 -------------- block/iscsi.c | 2 +- hw/smbios/smbios.c | 1 + include/qemu/uuid.h | 40 +++++++++++++++++++++++++++++ include/sysemu/sysemu.h | 4 --- qmp.c | 1 + stubs/uuid.c | 2 +- util/Makefile.objs | 1 + util/uuid.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++++ vl.c | 1 + 10 files changed, 114 insertions(+), 25 deletions(-) create mode 100644 include/qemu/uuid.h create mode 100644 util/uuid.carch_init.c +0
-19@@ -235,25 +235,6 @@ void audio_init(void) } } -int qemu_uuid_parse (const char *str,uint8_t *uuid) -{ -int ret; - -if (strlen (str) !=36 ) { -return -1 ; - } - - ret =sscanf (str,UUID_FMT , &uuid[0 ], &uuid[1 ], &uuid[2 ], &uuid[3 ], - &uuid[4 ], &uuid[5 ], &uuid[6 ], &uuid[7 ], &uuid[8 ], &uuid[9 ], - &uuid[10 ], &uuid[11 ], &uuid[12 ], &uuid[13 ], &uuid[14 ], - &uuid[15 ]); - -if (ret !=16 ) { -return -1 ; - } -return 0 ; -} -void do_acpitable_option (const QemuOpts *opts) {#ifdef TARGET_I386 block/iscsi.c +1
-1@@ -36,7 +36,7 @@#include "block/block_int.h" #include "block/scsi.h" #include "qemu/iov.h" -#include "sysemu/sysemu.h" +#include "qemu/uuid.h" #include "qmp-commands.h" #include "qapi/qmp/qstring.h" #include "crypto/secret.h" hw/smbios/smbios.c +1
-0@@ -20,6 +20,7 @@#include "qemu/config-file.h" #include "qemu/error-report.h" #include "sysemu/sysemu.h" +#include "qemu/uuid.h" #include "sysemu/cpus.h" #include "hw/smbios/smbios.h" #include "hw/loader.h" include/qemu/uuid.h new file +11
-0@@ -0,0 +1,40 @@ +/* +* QEMU UUID functions +* +* Copyright 2016 Red Hat, Inc., +* +* Authors: +* Fam Zheng <[email protected]> +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the Free +* Software Foundation; either version 2 of the License, or (at your option)
include/qemu/uuid.h line 21
Quoted 10 lines
include/qemu/uuid.h new file +10
-0+* any later version. +* +*/ + +#ifndef QEMU_UUID_H +#define QEMU_UUID_H + +#include "qemu-common.h" + +typedef unsigned char QemuUUID [16 ];
I'm afraid this typedef is problematic. Consider:
void use_uuid(QemuUUID uuid)
{
printf("sizeof(uuid) %zd\n", sizeof(uuid));
uuid[0]++;
}QemuUUID is obviously a typedef name, so a reasonable reader may assume
(1) sizeof(uuid) is the size of the uuid, and (2) since uuid is passed by value, the increment is not visible outside the function. Both assumptions are wrong, because array arguments degenerate into pointers.
I recommend to wrap it in a struct.
Quoted 94 lines
include/qemu/uuid.h new file +19
-0+ +#define UUID_FMT "%02hhx%02hhx%02hhx%02hhx-" \ + "%02hhx%02hhx-%02hhx%02hhx-" \ + "%02hhx%02hhx-" \ + "%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx" + +#define UUID_FMT_LEN 36 + +#define UUID_NONE "00000000-0000-0000-0000-000000000000" + +void qemu_uuid_generate (QemuUUID out); + +int qemu_uuid_is_null (const QemuUUID uu); + +void qemu_uuid_unparse (const QemuUUID uu,char *out); + +int qemu_uuid_parse (const char *str,uint8_t *uuid); + +#endif include/sysemu/sysemu.h +0
-4@@ -18,10 +18,6 @@ extern const char *bios_name;extern const char *qemu_name;extern uint8_t qemu_uuid[];extern bool qemu_uuid_set; -int qemu_uuid_parse (const char *str,uint8_t *uuid); - -#define UUID_FMT "%02hhx%02hhx%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx" -#define UUID_NONE "00000000-0000-0000-0000-000000000000"bool runstate_check (RunState state);void runstate_set (RunState new_state);qmp.c +1
-0@@ -35,6 +35,7 @@#include "qom/object_interfaces.h" #include "hw/mem/pc-dimm.h" #include "hw/acpi/acpi_dev_interface.h" +#include "qemu/uuid.h" NameInfo *qmp_query_name (Error **errp) {stubs/uuid.c +1
-1@@ -1,6 +1,6 @@#include "qemu/osdep.h" #include "qemu-common.h" -#include "sysemu/sysemu.h" +#include "qemu/uuid.h" #include "qmp-commands.h" UuidInfo *qmp_query_uuid (Error **errp)util/Makefile.objs +1
-0@@ -20,6 +20,7 @@ util-obj-y += iov.o qemu-config.o qemu-sockets.o uri.o notify.o util-obj-y += qemu-option.o qemu-progress.o util-obj-y += hexdump.o util-obj-y += crc32c.o +util-obj-y += uuid.o util-obj-y += throttle.o util-obj-y += getauxval.o util-obj-y += readline.outil/uuid.c new file +18
-0@@ -0,0 +1,68 @@ +/* +* QEMU UUID functions +* +* Copyright 2016 Red Hat, Inc., +* +* Authors: +* Fam Zheng <[email protected]> +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the Free +* Software Foundation; either version 2 of the License, or (at your option) +* any later version. +* +*/ + +#include "qemu/osdep.h" +#include "qemu-common.h" +#include "qemu/uuid.h"
util/uuid.c line 28
Quoted 10 lines
util/uuid.c new file +10
-0+#include <glib.h> + +void qemu_uuid_generate (QemuUUID out) +{ +/* Version 4 UUID, RFC4122 4.4. */ +QEMU_BUILD_BUG_ON (sizeof (QemuUUID) !=16 ); + *((guint32 *)out +0 ) =g_random_int (); + *((guint32 *)out +1 ) =g_random_int (); + *((guint32 *)out +2 ) =g_random_int (); + *((guint32 *)out +3 ) =g_random_int ();
I loathe GLib's pointless duplication of the standard integer types. Sure we can't simply use uint32_t?
Possibly:
uint32_t *out32 = (uint32_t)out;
out32[0] = g_random_int();
out32[1] = g_random_int();
out32[2] = g_random_int();
out32[3] = g_random_int();Quoted 6 lines
util/uuid.c new file +6
-0+/* Set the two most significant bits (bits 6 and 7) of the +clock_seq_hi_and_reserved to zero and one, respectively. */ + out[8 ] = (out[8 ] &0x3f ) |0x80 ; +/* Set the four most significant bits (bits 12 through 15) of the +time_hi_and_version field to the 4-bit version number. +*/
util/uuid.c line 44
Quoted 10 lines
util/uuid.c new file +10
-0+ out[6 ] = (out[6 ] &0xf ) |0x40 ; +} + +int qemu_uuid_is_null (const QemuUUID uu) +{ +QemuUUID null_uuid = {0 }; +return memcmp (uu, null_uuid,sizeof (QemuUUID)) ==0 ; +} + +void qemu_uuid_unparse (const QemuUUID uu,char *out)
While there, you could write a function contract that spells out that @out[] must have space for 37 characters.
Quoted 36 lines
util/uuid.c new file +24
-0+{ +snprintf (out,37 ,UUID_FMT , + uu[0 ], uu[1 ], uu[2 ], uu[3 ], uu[4 ], uu[5 ], uu[6 ], uu[7 ], + uu[8 ], uu[9 ], uu[10 ], uu[11 ], uu[12 ], uu[13 ], uu[14 ], uu[15 ]); +} + +int qemu_uuid_parse (const char *str,uint8_t *uuid) +{ +int ret; + +if (strlen (str) !=36 ) { +return -1 ; + } + + ret =sscanf (str,UUID_FMT , &uuid[0 ], &uuid[1 ], &uuid[2 ], &uuid[3 ], + &uuid[4 ], &uuid[5 ], &uuid[6 ], &uuid[7 ], &uuid[8 ], &uuid[9 ], + &uuid[10 ], &uuid[11 ], &uuid[12 ], &uuid[13 ], &uuid[14 ], + &uuid[15 ]); + +if (ret !=16 ) { +return -1 ; + } +return 0 ; +}vl.c +1
-0@@ -25,6 +25,7 @@#include "qemu-version.h" #include "qemu/cutils.h" #include "qemu/help_option.h" +#include "qemu/uuid.h" #ifdef CONFIG_SECCOMP #include "sysemu/seccomp.h"
Re: [Qemu-devel] [PATCH v2 1/8] util: Add UUID API
Quoted 121 lines · Markus Armbruster
Quoted 100 lines · Fam Zheng
A number of different places across the code base use
CONFIG_UUID. Some of them are soft dependency, some are not built if libuuid is not available, some come with dummy fallback, some throws runtime error.It is hard to maintain, and hard to reason for users.
Since UUID is a simple standard with only a small number of operations, it is cleaner to have a central support in libqemuutil. This patch adds qemu_uuid_* the functions so that all uuid users in the code base can rely on. Except for
qemu_uuid_generatewhich is new code, all other functions are just copy from existing fallbacks from other files.Signed-off-by Fam Zheng <[email protected]>--- arch_init.c | 19 -------------- block/iscsi.c | 2 +- hw/smbios/smbios.c | 1 + include/qemu/uuid.h | 40 +++++++++++++++++++++++++++++ include/sysemu/sysemu.h | 4 --- qmp.c | 1 + stubs/uuid.c | 2 +- util/Makefile.objs | 1 + util/uuid.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++++ vl.c | 1 + 10 files changed, 114 insertions(+), 25 deletions(-) create mode 100644 include/qemu/uuid.h create mode 100644 util/uuid.carch_init.c +0
-19@@ -235,25 +235,6 @@ void audio_init(void) } } -int qemu_uuid_parse (const char *str,uint8_t *uuid) -{ -int ret; - -if (strlen (str) !=36 ) { -return -1 ; - } - - ret =sscanf (str,UUID_FMT , &uuid[0 ], &uuid[1 ], &uuid[2 ], &uuid[3 ], - &uuid[4 ], &uuid[5 ], &uuid[6 ], &uuid[7 ], &uuid[8 ], &uuid[9 ], - &uuid[10 ], &uuid[11 ], &uuid[12 ], &uuid[13 ], &uuid[14 ], - &uuid[15 ]); - -if (ret !=16 ) { -return -1 ; - } -return 0 ; -} -void do_acpitable_option (const QemuOpts *opts) {#ifdef TARGET_I386 block/iscsi.c +1
-1@@ -36,7 +36,7 @@#include "block/block_int.h" #include "block/scsi.h" #include "qemu/iov.h" -#include "sysemu/sysemu.h" +#include "qemu/uuid.h" #include "qmp-commands.h" #include "qapi/qmp/qstring.h" #include "crypto/secret.h" hw/smbios/smbios.c +1
-0@@ -20,6 +20,7 @@#include "qemu/config-file.h" #include "qemu/error-report.h" #include "sysemu/sysemu.h" +#include "qemu/uuid.h" #include "sysemu/cpus.h" #include "hw/smbios/smbios.h" #include "hw/loader.h" include/qemu/uuid.h new file +11
-0@@ -0,0 +1,40 @@ +/* +* QEMU UUID functions +* +* Copyright 2016 Red Hat, Inc., +* +* Authors: +* Fam Zheng <[email protected]> +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the Free +* Software Foundation; either version 2 of the License, or (at your option) include/qemu/uuid.h line 21
Quoted 10 lines
include/qemu/uuid.h new file +10
-0+* any later version. +* +*/ + +#ifndef QEMU_UUID_H +#define QEMU_UUID_H + +#include "qemu-common.h" + +typedef unsigned char QemuUUID [16 ];I'm afraid this typedef is problematic. Consider:
void use_uuid(QemuUUID uuid) { printf("sizeof(uuid) %zd\n", sizeof(uuid)); uuid[0]++; }
Quoted 7 lines
QemuUUID is obviously a typedef name, so a reasonable reader may assume
(1) sizeof(uuid) is the size of the uuid, and (2) since uuid is passed by value, the increment is not visible outside the function. Both assumptions are wrong, because array arguments degenerate into pointers.I recommend to wrap it in a struct.
If we are going for a semantic drop-in replacement for libuuid's uuid_t, Fam's typedef here is consistent with libuuid:
typedef unsigned char uuid_t[16];
(Not to say that prohibits changing it, just pointing out there is value in mimicking libuuid's interfaces).
Quoted 173 lines
Quoted 94 lines
include/qemu/uuid.h new file +19
-0+ +#define UUID_FMT "%02hhx%02hhx%02hhx%02hhx-" \ + "%02hhx%02hhx-%02hhx%02hhx-" \ + "%02hhx%02hhx-" \ + "%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx" + +#define UUID_FMT_LEN 36 + +#define UUID_NONE "00000000-0000-0000-0000-000000000000" + +void qemu_uuid_generate (QemuUUID out); + +int qemu_uuid_is_null (const QemuUUID uu); + +void qemu_uuid_unparse (const QemuUUID uu,char *out); + +int qemu_uuid_parse (const char *str,uint8_t *uuid); + +#endif include/sysemu/sysemu.h +0
-4@@ -18,10 +18,6 @@ extern const char *bios_name;extern const char *qemu_name;extern uint8_t qemu_uuid[];extern bool qemu_uuid_set; -int qemu_uuid_parse (const char *str,uint8_t *uuid); - -#define UUID_FMT "%02hhx%02hhx%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx" -#define UUID_NONE "00000000-0000-0000-0000-000000000000"bool runstate_check (RunState state);void runstate_set (RunState new_state);qmp.c +1
-0@@ -35,6 +35,7 @@#include "qom/object_interfaces.h" #include "hw/mem/pc-dimm.h" #include "hw/acpi/acpi_dev_interface.h" +#include "qemu/uuid.h" NameInfo *qmp_query_name (Error **errp) {stubs/uuid.c +1
-1@@ -1,6 +1,6 @@#include "qemu/osdep.h" #include "qemu-common.h" -#include "sysemu/sysemu.h" +#include "qemu/uuid.h" #include "qmp-commands.h" UuidInfo *qmp_query_uuid (Error **errp)util/Makefile.objs +1
-0@@ -20,6 +20,7 @@ util-obj-y += iov.o qemu-config.o qemu-sockets.o uri.o notify.o util-obj-y += qemu-option.o qemu-progress.o util-obj-y += hexdump.o util-obj-y += crc32c.o +util-obj-y += uuid.o util-obj-y += throttle.o util-obj-y += getauxval.o util-obj-y += readline.outil/uuid.c new file +18
-0@@ -0,0 +1,68 @@ +/* +* QEMU UUID functions +* +* Copyright 2016 Red Hat, Inc., +* +* Authors: +* Fam Zheng <[email protected]> +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the Free +* Software Foundation; either version 2 of the License, or (at your option) +* any later version. +* +*/ + +#include "qemu/osdep.h" +#include "qemu-common.h" +#include "qemu/uuid.h" util/uuid.c line 28
Quoted 10 lines
util/uuid.c new file +10
-0+#include <glib.h> + +void qemu_uuid_generate (QemuUUID out) +{ +/* Version 4 UUID, RFC4122 4.4. */ +QEMU_BUILD_BUG_ON (sizeof (QemuUUID) !=16 ); + *((guint32 *)out +0 ) =g_random_int (); + *((guint32 *)out +1 ) =g_random_int (); + *((guint32 *)out +2 ) =g_random_int (); + *((guint32 *)out +3 ) =g_random_int ();I loathe GLib's pointless duplication of the standard integer types. Sure we can't simply use
uint32_t?Possibly:
uint32_t *out32 = (uint32_t)out; out32[0] = g_random_int(); out32[1] = g_random_int(); out32[2] = g_random_int(); out32[3] = g_random_int();Quoted 6 lines
util/uuid.c new file +6
-0+/* Set the two most significant bits (bits 6 and 7) of the +clock_seq_hi_and_reserved to zero and one, respectively. */ + out[8 ] = (out[8 ] &0x3f ) |0x80 ; +/* Set the four most significant bits (bits 12 through 15) of the +time_hi_and_version field to the 4-bit version number. +*/ util/uuid.c line 44
Quoted 10 lines
util/uuid.c new file +10
-0+ out[6 ] = (out[6 ] &0xf ) |0x40 ; +} + +int qemu_uuid_is_null (const QemuUUID uu) +{ +QemuUUID null_uuid = {0 }; +return memcmp (uu, null_uuid,sizeof (QemuUUID)) ==0 ; +} + +void qemu_uuid_unparse (const QemuUUID uu,char *out)While there, you could write a function contract that spells out that @out[] must have space for 37 characters.
Quoted 36 lines
util/uuid.c new file +24
-0+{ +snprintf (out,37 ,UUID_FMT , + uu[0 ], uu[1 ], uu[2 ], uu[3 ], uu[4 ], uu[5 ], uu[6 ], uu[7 ], + uu[8 ], uu[9 ], uu[10 ], uu[11 ], uu[12 ], uu[13 ], uu[14 ], uu[15 ]); +} + +int qemu_uuid_parse (const char *str,uint8_t *uuid) +{ +int ret; + +if (strlen (str) !=36 ) { +return -1 ; + } + + ret =sscanf (str,UUID_FMT , &uuid[0 ], &uuid[1 ], &uuid[2 ], &uuid[3 ], + &uuid[4 ], &uuid[5 ], &uuid[6 ], &uuid[7 ], &uuid[8 ], &uuid[9 ], + &uuid[10 ], &uuid[11 ], &uuid[12 ], &uuid[13 ], &uuid[14 ], + &uuid[15 ]); + +if (ret !=16 ) { +return -1 ; + } +return 0 ; +}vl.c +1
-0@@ -25,6 +25,7 @@#include "qemu-version.h" #include "qemu/cutils.h" #include "qemu/help_option.h" +#include "qemu/uuid.h" #ifdef CONFIG_SECCOMP #include "sysemu/seccomp.h"
Re: [Qemu-devel] [PATCH v2 1/8] util: Add UUID API
Quoted 18 lines · Jeff Cody
Quoted 10 lines
Quoted 1 line
+typedef unsigned char QemuUUID[16];
I'm afraid this typedef is problematic. Consider:
void use_uuid(QemuUUID uuid) { printf("sizeof(uuid) %zd\n", sizeof(uuid)); uuid[0]++; }Quoted 7 lines
QemuUUID is obviously a typedef name, so a reasonable reader may assume
(1) sizeof(uuid) is the size of the uuid, and (2) since uuid is passed by value, the increment is not visible outside the function. Both assumptions are wrong, because array arguments degenerate into pointers.I recommend to wrap it in a struct.
Quoted 7 lines
If we are going for a semantic drop-in replacement for libuuid's
uuid_t, Fam's typedef here is consistent with libuuid:typedef unsigned char uuid_t[16];(Not to say that prohibits changing it, just pointing out there is value in mimicking libuuid's interfaces).
I am not 100% comforatble with libuuid way, so yes, it was for consistency. But Markus' point is great, let's change it to the better way anyway, since it's not a hard requirement to mimic libuuid.
Fam
PATCH v2 2/8 tests: Add uuid tests
In reply to Fam Zheng--- tests/Makefile.include | 2 + tests/test-uuid.c | 110 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 112 insertions(+) create mode 100644 tests/test-uuid.c
tests/Makefile.include +2 -0
@@ -111,6 +111,7 @@ check-unit-y += tests/test-crypto-xts$(EXESUF) check-unit-y += tests/test-crypto-block$(EXESUF) gcov-files-test-logging-y = tests/test-logging.c check-unit-y += tests/test-logging$(EXESUF) +check-unit-y += tests/test-uuid$(EXESUF) check-block-$(CONFIG_POSIX) += tests/qemu-iotests-quick.sh
@@ -629,6 +630,7 @@ tests/test-filter-mirror$(EXESUF): tests/test-filter-mirror.o $(qtest-obj-y) tests/test-filter-redirector$(EXESUF): tests/test-filter-redirector.o $(qtest-obj-y) tests/ivshmem-test$(EXESUF): tests/ivshmem-test.o contrib/ivshmem-server/ivshmem-server.o $(libqos-pc-obj-y) tests/vhost-user-bridge$(EXESUF): tests/vhost-user-bridge.o +tests/test-uuid$(EXESUF): tests/test-uuid.o $(test-util-obj-y) tests/migration/stress$(EXESUF): tests/migration/stress.o $(call quiet-command, $(LINKPROG) -static -O3 $(PTHREAD_LIB) -o $@ $< ," LINK $(TARGET_DIR)$@")
tests/test-uuid.c new file +110 -0
110 lines not on this page · raw message
Signature · 1 line
2.7.4
Re: [Qemu-devel] [PATCH v2 2/8] tests: Add uuid tests
Quoted 53 lines · Fam Zheng
Signed-off-by Fam Zheng <[email protected]>--- tests/Makefile.include | 2 + tests/test-uuid.c | 110 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 112 insertions(+) create mode 100644 tests/test-uuid.ctests/Makefile.include +2
-0@@ -111,6 +111,7 @@ check-unit-y += tests/test-crypto-xts$(EXESUF) check-unit-y += tests/test-crypto-block$(EXESUF) gcov-files-test-logging-y = tests/test-logging.c check-unit-y += tests/test-logging$(EXESUF) +check-unit-y += tests/test-uuid$(EXESUF) check-block-$(CONFIG_POSIX) += tests/qemu-iotests-quick.sh@@ -629,6 +630,7 @@ tests/test-filter-mirror$(EXESUF): tests/test-filter-mirror.o $(qtest-obj-y) tests/test-filter-redirector$(EXESUF): tests/test-filter-redirector.o $(qtest-obj-y) tests/ivshmem-test$(EXESUF): tests/ivshmem-test.o contrib/ivshmem-server/ivshmem-server.o $(libqos-pc-obj-y) tests/vhost-user-bridge$(EXESUF): tests/vhost-user-bridge.o +tests/test-uuid$(EXESUF): tests/test-uuid.o $(test-util-obj-y) tests/migration/stress$(EXESUF): tests/migration/stress.o $(call quiet-command, $(LINKPROG) -static -O3 $(PTHREAD_LIB) -o $@ $< ," LINK $(TARGET_DIR)$@")tests/test-uuid.c new file +20
-0@@ -0,0 +1,110 @@ +/* +* QEMU UUID Library +* +* Copyright (c) 2016 Red Hat, Inc. +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2 of the License, or (at your option) any later version. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, see <http://www.gnu.org/licenses/>. +* +*/ +
tests/test-uuid.c line 30
Quoted 10 lines
tests/test-uuid.c new file +10
-0+#include "qemu/osdep.h" +#include "qemu/uuid.h" + +struct {const char *uuidstr;QemuUUID uuid; } uuid_test_data[] = { + { +"586ece27-7f09-41e0-9e74-e901317e9d42" , + {0x58 ,0x6e ,0xce ,0x27 ,0x7f ,0x09 ,0x41 ,0xe0 , +0x9e ,0x74 ,0xe9 ,0x01 ,0x31 ,0x7e ,0x9d ,0x42 }, + }, { +"0cc6c752-3961-4028-a286-c05cc616d396" ,
Use uppercase A-F in this one, so we're got a pair of uuids which cover both cases
tests/test-uuid.c line 36
Quoted 6 lines
tests/test-uuid.c new file +6
-0+ {0x0c ,0xc6 ,0xc7 ,0x52 ,0x39 ,0x61 ,0x40 ,0x28 , + 0xa2, 0x86, 0xc0, 0x5c, 0xc6, 0x16, 0xd3, 0x96} + }, { +"00000000-0000-0000-0000-000000000000" , + { 0 }, + }
We should do some negative tests. eg a uuid without '-' separators; a UUID which is too short; a UUID which is too long; a UUID which has non-hex characters, a zero length UUID.
Regards,
Daniel
Signature · 4 lines
|: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|
PATCH v2 3/8 vhdx: Use QEMU UUID API
In reply to Fam ZhengThis removes our dependency to libuuid, so that the driver can always be built.
Similar to how we handled data plane configure options, --enable-vhdx and --disable-vhdx are also changed to a nop with a message saying it's obsolete.
--- block/Makefile.objs | 2 +- block/vhdx-endian.c | 3 --- block/vhdx.c | 7 +++---- configure | 27 +++------------------------ 4 files changed, 7 insertions(+), 32 deletions(-)
block/Makefile.objs +1 -1
@@ -2,7 +2,7 @@ block-obj-y += raw_bsd.o qcow.o vdi.o vmdk.o cloop.o bochs.o vpc.o vvfat.o block-obj-y += qcow2.o qcow2-refcount.o qcow2-cluster.o qcow2-snapshot.o qcow2-cache.o block-obj-y += qed.o qed-gencb.o qed-l2-cache.o qed-table.o qed-cluster.o block-obj-y += qed-check.o -block-obj-$(CONFIG_VHDX) += vhdx.o vhdx-endian.o vhdx-log.o +block-obj-y += vhdx.o vhdx-endian.o vhdx-log.o block-obj-y += quorum.o block-obj-y += parallels.o blkdebug.o blkverify.o blkreplay.o block-obj-y += block-backend.o snapshot.o qapi.o
block/vhdx-endian.c +0 -3
@@ -21,9 +21,6 @@#include "qemu/bswap.h" #include "block/vhdx.h" -#include <uuid/uuid.h> - -/* * All the VHDX formats on disk are little endian - the following * are helper import/export functions to correctly convert
block/vhdx.c +3 -4
@@ -25,8 +25,7 @@#include "qemu/bswap.h" #include "block/vhdx.h" #include "migration/migration.h" - -#include <uuid/uuid.h> +#include "qemu/uuid.h" /* Options for VHDX creation */
@@ -213,10 +212,10 @@ bool vhdx_checksum_is_valid(uint8_t *buf, size_t size, int crc_offset)*/ void vhdx_guid_generate (MSGUID *guid) { -uuid_t uuid; +QemuUUID uuid;assert (guid !=NULL ); -uuid_generate (uuid); +qemu_uuid_generate (uuid);memcpy (guid, uuid,sizeof (MSGUID )); }
configure +3 -24
@@ -316,7 +316,6 @@ vte="" virglrenderer="" tpm="yes" libssh2="" -vhdx="" numa="" tcmalloc="no" jemalloc="no"
@@ -1094,6 +1093,9 @@ for opt do --disable-virtio-blk-data-plane|--enable-virtio-blk-data-plane) echo "$0: $opt is obsolete, virtio-blk data-plane is always on" >&2 ;; + --enable-vhdx|--disable-vhdx) + echo "$0: $opt is obsolete, VHDX driver is always built" + ;; --disable-gtk) gtk="no" ;; --enable-gtk) gtk="yes"
@@ -1134,10 +1136,6 @@ for opt do ;; --enable-libssh2) libssh2="yes" ;; - --enable-vhdx) vhdx="yes" - ;; - --disable-vhdx) vhdx="no" - ;; --disable-numa) numa="no" ;; --enable-numa) numa="yes"
@@ -1376,7 +1374,6 @@ disabled with --disable-FEATURE, default is enabled if available: archipelago Archipelago backend tpm TPM support libssh2 ssh block device support - vhdx support for the Microsoft VHDX image format numa libnuma support tcmalloc tcmalloc support jemalloc jemalloc support
@@ -2685,19 +2682,6 @@ EOF fi fi -if test "$vhdx" = "yes" ; then - if test "$uuid" = "no" ; then - error_exit "uuid required for VHDX support" - fi -elif test "$vhdx" != "no" ; then - if test "$uuid" = "yes" ; then - vhdx=yes - else - vhdx=no - fi -fi - -########################################## # xfsctl() probe, used for raw-posix if test "$xfs" != "no" ; then cat > $TMPC << EOF
@@ -4891,7 +4875,6 @@ echo "TPM support $tpm" echo "libssh2 support $libssh2" echo "TPM passthrough $tpm_passthrough" echo "QOM debugging $qom_cast_debug" -echo "vhdx $vhdx" echo "lzo support $lzo" echo "snappy support $snappy" echo "bzip2 support $bzip2"
@@ -5412,10 +5395,6 @@ if test "$libssh2" = "yes" ; then echo "LIBSSH2_LIBS=$libssh2_libs" >> $config_host_mak fi -if test "$vhdx" = "yes" ; then - echo "CONFIG_VHDX=y" >> $config_host_mak -fi - # USB host support if test "$libusb" = "yes"; then echo "HOST_USB=libusb legacy" >> $config_host_mak
Signature · 1 line
2.7.4
Re: [Qemu-devel] [PATCH v2 3/8] vhdx: Use QEMU UUID API
Quoted 8 lines · Fam Zheng
This removes our dependency to libuuid, so that the driver can always be built.
Similar to how we handled data plane configure options, --enable-vhdx and --disable-vhdx are also changed to a nop with a message saying it's obsolete.
Signed-off-by Fam Zheng <[email protected]>
It's nice to get rid of the extra dependency.
Quoted 74 lines
--- block/Makefile.objs | 2 +- block/vhdx-endian.c | 3 --- block/vhdx.c | 7 +++---- configure | 27 +++------------------------ 4 files changed, 7 insertions(+), 32 deletions(-)block/Makefile.objs +1
-1@@ -2,7 +2,7 @@ block-obj-y += raw_bsd.o qcow.o vdi.o vmdk.o cloop.o bochs.o vpc.o vvfat.o block-obj-y += qcow2.o qcow2-refcount.o qcow2-cluster.o qcow2-snapshot.o qcow2-cache.o block-obj-y += qed.o qed-gencb.o qed-l2-cache.o qed-table.o qed-cluster.o block-obj-y += qed-check.o -block-obj-$(CONFIG_VHDX) += vhdx.o vhdx-endian.o vhdx-log.o +block-obj-y += vhdx.o vhdx-endian.o vhdx-log.o block-obj-y += quorum.o block-obj-y += parallels.o blkdebug.o blkverify.o blkreplay.o block-obj-y += block-backend.o snapshot.o qapi.oblock/vhdx-endian.c +0
-3@@ -21,9 +21,6 @@#include "qemu/bswap.h" #include "block/vhdx.h" -#include <uuid/uuid.h> - -/* * All the VHDX formats on disk are little endian - the following * are helper import/export functions to correctly convert block/vhdx.c +3
-4@@ -25,8 +25,7 @@#include "qemu/bswap.h" #include "block/vhdx.h" #include "migration/migration.h" - -#include <uuid/uuid.h> +#include "qemu/uuid.h" /* Options for VHDX creation */ @@ -213,10 +212,10 @@ bool vhdx_checksum_is_valid(uint8_t *buf, size_t size, int crc_offset)*/ void vhdx_guid_generate (MSGUID *guid) { -uuid_t uuid; +QemuUUID uuid;assert (guid !=NULL ); -uuid_generate (uuid); +qemu_uuid_generate (uuid);memcpy (guid, uuid,sizeof (MSGUID )); }configure +0
-1@@ -316,7 +316,6 @@ vte="" virglrenderer="" tpm="yes" libssh2="" -vhdx="" numa="" tcmalloc="no" jemalloc="no"
configure for opt do · line 1098
Quoted 6 lines
configure +3
-0@@ -1094,6 +1093,9 @@ for opt do --disable-virtio-blk-data-plane|--enable-virtio-blk-data-plane) echo "$0: $opt is obsolete, virtio-blk data-plane is always on" >&2 ;; + --enable-vhdx|--disable-vhdx) + echo "$0: $opt is obsolete, VHDX driver is always built" + ;;
Data plan echoes this out to stderr, which is probably the best option. We should probably do the same for VHDX.
Quoted 64 lines
configure +0
-23--disable-gtk) gtk="no" ;; --enable-gtk) gtk="yes"@@ -1134,10 +1136,6 @@ for opt do ;; --enable-libssh2) libssh2="yes" ;; - --enable-vhdx) vhdx="yes" - ;; - --disable-vhdx) vhdx="no" - ;; --disable-numa) numa="no" ;; --enable-numa) numa="yes"@@ -1376,7 +1374,6 @@ disabled with --disable-FEATURE, default is enabled if available: archipelago Archipelago backend tpm TPM support libssh2 ssh block device support - vhdx support for the Microsoft VHDX image format numa libnuma support tcmalloc tcmalloc support jemalloc jemalloc support@@ -2685,19 +2682,6 @@ EOF fi fi -if test "$vhdx" = "yes" ; then - if test "$uuid" = "no" ; then - error_exit "uuid required for VHDX support" - fi -elif test "$vhdx" != "no" ; then - if test "$uuid" = "yes" ; then - vhdx=yes - else - vhdx=no - fi -fi - -########################################## # xfsctl() probe, used for raw-posix if test "$xfs" != "no" ; then cat > $TMPC << EOF@@ -4891,7 +4875,6 @@ echo "TPM support $tpm" echo "libssh2 support $libssh2" echo "TPM passthrough $tpm_passthrough" echo "QOM debugging $qom_cast_debug" -echo "vhdx $vhdx" echo "lzo support $lzo" echo "snappy support $snappy" echo "bzip2 support $bzip2"@@ -5412,10 +5395,6 @@ if test "$libssh2" = "yes" ; then echo "LIBSSH2_LIBS=$libssh2_libs" >> $config_host_mak fi -if test "$vhdx" = "yes" ; then - echo "CONFIG_VHDX=y" >> $config_host_mak -fi - # USB host support if test "$libusb" = "yes"; then echo "HOST_USB=libusb legacy" >> $config_host_makSignature · 1 line
2.7.4
PATCH v2 4/8 vdi: Use QEMU UUID API
In reply to Fam ZhengThe QEMU UUID api, including the data structure (QemuUUID), is fully compatible with libuuid. Use it, and remove the unused code.
--- block/vdi.c | 49 ++++++++++--------------------------------------- 1 file changed, 10 insertions(+), 39 deletions(-)
block/vdi.c +10 -39
@@ -58,14 +58,7 @@#include "migration/migration.h" #include "qemu/coroutine.h" #include "qemu/cutils.h" - -#if defined(CONFIG_UUID ) -#include <uuid/uuid.h> -#else -/* TODO: move uuid emulation to some central place in QEMU. */ -#include "sysemu/sysemu.h" /* UUID_FMT */ -typedef unsigned char uuid_t [16 ]; -#endif +#include "qemu/uuid.h" /* Code configuration options. */
@@ -140,28 +133,6 @@ typedef unsigned char uuid_t[16];#define VDI_DISK_SIZE_MAX ((uint64_t)VDI_BLOCKS_IN_IMAGE_MAX * \ (uint64_t)DEFAULT_CLUSTER_SIZE) -#if !defined(CONFIG_UUID ) -static inline void uuid_generate (uuid_t out) -{ -memset (out,0 ,sizeof (uuid_t)); -} - -static inline int uuid_is_null (const uuid_t uu) -{ -uuid_t null_uuid = {0 }; -return memcmp (uu, null_uuid,sizeof (uuid_t)) ==0 ; -} - -# if defined(CONFIG_VDI_DEBUG ) -static inline void uuid_unparse (const uuid_t uu,char *out) -{ -snprintf (out,37 ,UUID_FMT , - uu[0 ], uu[1 ], uu[2 ], uu[3 ], uu[4 ], uu[5 ], uu[6 ], uu[7 ], - uu[8 ], uu[9 ], uu[10 ], uu[11 ], uu[12 ], uu[13 ], uu[14 ], uu[15 ]); -} -# endif -#endif - typedef struct { char text[0x40]; uint32_t signature;
@@ -182,10 +153,10 @@ typedef struct {uint32_t block_extra;/* unused here */ uint32_t blocks_in_image;uint32_t blocks_allocated; -uuid_t uuid_image; -uuid_t uuid_last_snap; -uuid_t uuid_link; -uuid_t uuid_parent; +QemuUUID uuid_image; +QemuUUID uuid_last_snap; +QemuUUID uuid_link; +QemuUUID uuid_parent;uint64_t unused2[7 ]; }QEMU_PACKED VdiHeader;
@@ -209,7 +180,7 @@ typedef struct {/* Change UUID from little endian (IPRT = VirtualBox format) to big endian * format (network byte order, standard, see RFC 4122) and vice versa. */ -static void uuid_convert (uuid_t uuid) +static void uuid_convert (QemuUUID uuid) {bswap32s ((uint32_t *)&uuid[0 ]);bswap16s ((uint16_t *)&uuid[4 ]);
@@ -469,11 +440,11 @@ static int vdi_open(BlockDriverState *bs, QDict *options, int flags, (uint64_t)header.blocks_in_image * header.block_size); ret = -ENOTSUP ; goto fail; - }else if (!uuid_is_null (header.uuid_link)) { + }else if (!qemu_uuid_is_null (header.uuid_link)) {error_setg (errp,"unsupported VDI image (non-NULL link UUID)" ); ret = -ENOTSUP ; goto fail; - }else if (!uuid_is_null (header.uuid_parent)) { + }else if (!qemu_uuid_is_null (header.uuid_parent)) {error_setg (errp,"unsupported VDI image (non-NULL parent UUID)" ); ret = -ENOTSUP ; goto fail;
@@ -821,8 +792,8 @@ static int vdi_create(const char *filename, QemuOpts *opts, Error **errp)if (image_type ==VDI_TYPE_STATIC ) { header.blocks_allocated = blocks; } -uuid_generate (header.uuid_image); -uuid_generate (header.uuid_last_snap); +qemu_uuid_generate (header.uuid_image); +qemu_uuid_generate (header.uuid_last_snap);/* There is no need to set header.uuid_link or header.uuid_parent here. */ #if defined(CONFIG_VDI_DEBUG )vdi_header_print (&header);
Signature · 1 line
2.7.4
PATCH v2 5/8 vpc: Use QEMU UUID API
In reply to Fam ZhengPreviously we conditionally generate if footer->uuid, when libuuid is available. Now that we have a built-in implementation, we can switch to it.
--- block/vpc.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)
block/vpc.c +2 -6
@@ -30,9 +30,7 @@#include "qemu/module.h" #include "migration/migration.h" #include "qemu/bswap.h" -#if defined(CONFIG_UUID ) -#include <uuid/uuid.h> -#endif +#include "qemu/uuid.h" /**************************************************************/
@@ -980,9 +978,7 @@ static int vpc_create(const char *filename, QemuOpts *opts, Error **errp) footer->type =cpu_to_be32 (disk_type); -#if defined(CONFIG_UUID ) -uuid_generate (footer->uuid); -#endif +qemu_uuid_generate (footer->uuid); footer->checksum =cpu_to_be32 (vpc_checksum (buf,HEADER_SIZE ));
Signature · 1 line
2.7.4
Re: [Qemu-devel] [PATCH v2 5/8] vpc: Use QEMU UUID API
Quoted 1 line · Fam Zheng
Previously we conditionally generate if
footer->uuid, when libuuid is
s/generate if/generated/
s/is/was/
Quoted 37 lines
available. Now that we have a built-in implementation, we can switch to it.
Signed-off-by Fam Zheng <[email protected]>--- block/vpc.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)block/vpc.c +2
-6@@ -30,9 +30,7 @@#include "qemu/module.h" #include "migration/migration.h" #include "qemu/bswap.h" -#if defined(CONFIG_UUID ) -#include <uuid/uuid.h> -#endif +#include "qemu/uuid.h" /**************************************************************/ @@ -980,9 +978,7 @@ static int vpc_create(const char *filename, QemuOpts *opts, Error **errp) footer->type =cpu_to_be32 (disk_type); -#if defined(CONFIG_UUID ) -uuid_generate (footer->uuid); -#endif +qemu_uuid_generate (footer->uuid); footer->checksum =cpu_to_be32 (vpc_checksum (buf,HEADER_SIZE ));Signature · 1 line
2.7.4
Re: [Qemu-devel] [PATCH v2 5/8] vpc: Use QEMU UUID API
Quoted 6 lines · Jeff Cody
Quoted 1 line · Fam Zheng
Previously we conditionally generate if
footer->uuid, when libuuid iss/generate if/generated/
s/is/was/
Fixing, thanks!
Fam
PATCH v2 6/8 crypto: Switch to QEMU UUID API
In reply to Fam ZhengThe uuid generation doesn't return error, so update the function signature and calling code accordingly.
--- crypto/block-luks.c | 26 +++++++------------------- 1 file changed, 7 insertions(+), 19 deletions(-)
crypto/block-luks.c +7 -19
@@ -29,10 +29,7 @@#include "crypto/pbkdf.h" #include "crypto/secret.h" #include "crypto/random.h" - -#ifdef CONFIG_UUID -#include <uuid/uuid.h> -#endif +#include "qemu/uuid.h" #include "qemu/coroutine.h"
@@ -877,18 +874,12 @@ qcrypto_block_luks_open(QCryptoBlock *block, } -static int -qcrypto_block_luks_uuid_gen (uint8_t *uuidstr,Error **errp) +static void +qcrypto_block_luks_uuid_gen (uint8_t *uuidstr) { -#ifdef CONFIG_UUID -uuid_t uuid; -uuid_generate (uuid); -uuid_unparse (uuid, (char *)uuidstr); -return 0 ; -#else -error_setg (errp,"Unable to generate uuids on this platform" ); -return -1 ; -#endif +QemuUUID uuid; +qemu_uuid_generate (uuid); +qemu_uuid_unparse (uuid, (char *)uuidstr); } static int
@@ -961,10 +952,7 @@ qcrypto_block_luks_create(QCryptoBlock *block,* it out to disk */ luks->header.version =QCRYPTO_BLOCK_LUKS_VERSION ; -if (qcrypto_block_luks_uuid_gen (luks->header.uuid, - errp) <0 ) { - goto error; - } +qcrypto_block_luks_uuid_gen (luks->header.uuid); cipher_alg =qcrypto_block_luks_cipher_alg_lookup (luks_opts.cipher_alg, errp);
Signature · 1 line
2.7.4
Re: [Qemu-devel] [PATCH v2 6/8] crypto: Switch to QEMU UUID API
Quoted 7 lines · Fam Zheng
The uuid generation doesn't return error, so update the function signature and calling code accordingly.
Signed-off-by Fam Zheng <[email protected]>--- crypto/block-luks.c | 26 +++++++------------------- 1 file changed, 7 insertions(+), 19 deletions(-)
FWIW, I'm happy for this patch to be merged as part of this series - no need for it to go in via my crypto/ patches queue
Quoted 55 lines
crypto/block-luks.c +7
-19@@ -29,10 +29,7 @@#include "crypto/pbkdf.h" #include "crypto/secret.h" #include "crypto/random.h" - -#ifdef CONFIG_UUID -#include <uuid/uuid.h> -#endif +#include "qemu/uuid.h" #include "qemu/coroutine.h" @@ -877,18 +874,12 @@ qcrypto_block_luks_open(QCryptoBlock *block, } -static int -qcrypto_block_luks_uuid_gen (uint8_t *uuidstr,Error **errp) +static void +qcrypto_block_luks_uuid_gen (uint8_t *uuidstr) { -#ifdef CONFIG_UUID -uuid_t uuid; -uuid_generate (uuid); -uuid_unparse (uuid, (char *)uuidstr); -return 0 ; -#else -error_setg (errp,"Unable to generate uuids on this platform" ); -return -1 ; -#endif +QemuUUID uuid; +qemu_uuid_generate (uuid); +qemu_uuid_unparse (uuid, (char *)uuidstr); } static int@@ -961,10 +952,7 @@ qcrypto_block_luks_create(QCryptoBlock *block,* it out to disk */ luks->header.version =QCRYPTO_BLOCK_LUKS_VERSION ; -if (qcrypto_block_luks_uuid_gen (luks->header.uuid, - errp) <0 ) { - goto error; - } +qcrypto_block_luks_uuid_gen (luks->header.uuid); cipher_alg =qcrypto_block_luks_cipher_alg_lookup (luks_opts.cipher_alg, errp);Signature · 1 line
2.7.4
Regards,
Daniel
Signature · 4 lines
|: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|
PATCH v2 7/8 tests: No longer dependent on CONFIG_UUID
In reply to Fam Zhengcrypto now uses built-in uuid implementation, so this check is not needed.
--- tests/test-crypto-block.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tests/test-crypto-block.c +1 -1
@@ -28,7 +28,7 @@#include <sys/resource.h> #endif -#if defined(CONFIG_UUID ) && (defined(_WIN32) || definedRUSAGE_THREAD ) +#if (defined(_WIN32) || definedRUSAGE_THREAD )#define TEST_LUKS #else #undef TEST_LUKS
Signature · 1 line
2.7.4
PATCH v2 8/8 configure: Remove detection code for UUID
In reply to Fam ZhengAll code now uses built-in UUID implementation. Remove the code of libuuid and make --enable-uuid and --disable-uuid only print a message.
--- configure | 43 ++++--------------------------------------- 1 file changed, 4 insertions(+), 39 deletions(-)
configure +4 -39
@@ -212,7 +212,6 @@ sdlabi="" virtfs="" vnc="yes" sparse="no" -uuid="" vde="" vnc_sasl="" vnc_jpeg=""
@@ -881,10 +880,6 @@ for opt do ;; --disable-slirp) slirp="no" ;; - --disable-uuid) uuid="no" - ;; - --enable-uuid) uuid="yes" - ;; --disable-vde) vde="no" ;; --enable-vde) vde="yes"
@@ -1096,6 +1091,9 @@ for opt do --enable-vhdx|--disable-vhdx) echo "$0: $opt is obsolete, VHDX driver is always built" ;; + --enable-uuid|--disable-uuid) + echo "$0: $opt is obsolete, UUID support is always built" + ;; --disable-gtk) gtk="no" ;; --enable-gtk) gtk="yes"
@@ -1350,7 +1348,6 @@ disabled with --disable-FEATURE, default is enabled if available: bluez bluez stack connectivity kvm KVM acceleration support rdma RDMA-based migration support - uuid uuid support vde support for vde network netmap support for netmap network linux-aio Linux AIO support
@@ -2654,34 +2651,6 @@ if compile_prog "" "" ; then fi ########################################## -# uuid_generate() probe, used for vdi block driver -# Note that on some systems (notably MacOSX) no extra library -# need be linked to get the uuid functions. -if test "$uuid" != "no" ; then - uuid_libs="-luuid" - cat > $TMPC << EOF -#include <uuid/uuid.h> -int main(void) -{ - uuid_t my_uuid; - uuid_generate(my_uuid); - return 0; -} -EOF - if compile_prog "" "" ; then - uuid="yes" - elif compile_prog "" "$uuid_libs" ; then - uuid="yes" - libs_softmmu="$uuid_libs $libs_softmmu" - libs_tools="$uuid_libs $libs_tools" - else - if test "$uuid" = "yes" ; then - feature_not_found "uuid" "Install libuuid devel" - fi - uuid=no - fi -fi - # xfsctl() probe, used for raw-posix if test "$xfs" != "no" ; then cat > $TMPC << EOF
@@ -4054,7 +4023,7 @@ EOF if compile_prog "$vss_win32_include" "" ; then guest_agent_with_vss="yes" QEMU_CFLAGS="$QEMU_CFLAGS $vss_win32_include" - libs_qga="-lole32 -loleaut32 -lshlwapi -luuid -lstdc++ -Wl,--enable-stdcall-fixup $libs_qga" + libs_qga="-lole32 -loleaut32 -lshlwapi -lstdc++ -Wl,--enable-stdcall-fixup $libs_qga" qga_vss_provider="qga/vss-win32/qga-vss.dll qga/vss-win32/qga-vss.tlb" else if test "$vss_win32_sdk" != "" ; then
@@ -4842,7 +4811,6 @@ echo "preadv support $preadv" echo "fdatasync $fdatasync" echo "madvise $madvise" echo "posix_madvise $posix_madvise" -echo "uuid support $uuid" echo "libcap-ng support $cap_ng" echo "vhost-net support $vhost_net" echo "vhost-scsi support $vhost_scsi"
@@ -5030,9 +4998,6 @@ fi if test "$fnmatch" = "yes" ; then echo "CONFIG_FNMATCH=y" >> $config_host_mak fi -if test "$uuid" = "yes" ; then - echo "CONFIG_UUID=y" >> $config_host_mak -fi if test "$xfs" = "yes" ; then echo "CONFIG_XFS=y" >> $config_host_mak fi
Signature · 1 line
2.7.4
Re: [Qemu-devel] [PATCH v2 8/8] configure: Remove detection code for UUID
Quoted 32 lines · Fam Zheng
All code now uses built-in UUID implementation. Remove the code of libuuid and make --enable-uuid and --disable-uuid only print a message.
Signed-off-by Fam Zheng <[email protected]>--- configure | 43 ++++--------------------------------------- 1 file changed, 4 insertions(+), 39 deletions(-)configure +0
-5@@ -212,7 +212,6 @@ sdlabi="" virtfs="" vnc="yes" sparse="no" -uuid="" vde="" vnc_sasl="" vnc_jpeg=""@@ -881,10 +880,6 @@ for opt do ;; --disable-slirp) slirp="no" ;; - --disable-uuid) uuid="no" - ;; - --enable-uuid) uuid="yes" - ;; --disable-vde) vde="no" ;; --enable-vde) vde="yes"
configure for opt do · line 1096
Quoted 6 lines
configure +3
-0@@ -1096,6 +1091,9 @@ for opt do --enable-vhdx|--disable-vhdx) echo "$0: $opt is obsolete, VHDX driver is always built" ;; + --enable-uuid|--disable-uuid) + echo "$0: $opt is obsolete, UUID support is always built" + ;;
As with the vhdx line, this too should probably go out to stderr similar to the data plane option.
Quoted 76 lines
configure +1
-34--disable-gtk) gtk="no" ;; --enable-gtk) gtk="yes"@@ -1350,7 +1348,6 @@ disabled with --disable-FEATURE, default is enabled if available: bluez bluez stack connectivity kvm KVM acceleration support rdma RDMA-based migration support - uuid uuid support vde support for vde network netmap support for netmap network linux-aio Linux AIO support@@ -2654,34 +2651,6 @@ if compile_prog "" "" ; then fi ########################################## -# uuid_generate() probe, used for vdi block driver -# Note that on some systems (notably MacOSX) no extra library -# need be linked to get the uuid functions. -if test "$uuid" != "no" ; then - uuid_libs="-luuid" - cat > $TMPC << EOF -#include <uuid/uuid.h> -int main(void) -{ - uuid_t my_uuid; - uuid_generate(my_uuid); - return 0; -} -EOF - if compile_prog "" "" ; then - uuid="yes" - elif compile_prog "" "$uuid_libs" ; then - uuid="yes" - libs_softmmu="$uuid_libs $libs_softmmu" - libs_tools="$uuid_libs $libs_tools" - else - if test "$uuid" = "yes" ; then - feature_not_found "uuid" "Install libuuid devel" - fi - uuid=no - fi -fi - # xfsctl() probe, used for raw-posix if test "$xfs" != "no" ; then cat > $TMPC << EOF@@ -4054,7 +4023,7 @@ EOF if compile_prog "$vss_win32_include" "" ; then guest_agent_with_vss="yes" QEMU_CFLAGS="$QEMU_CFLAGS $vss_win32_include" - libs_qga="-lole32 -loleaut32 -lshlwapi -luuid -lstdc++ -Wl,--enable-stdcall-fixup $libs_qga" + libs_qga="-lole32 -loleaut32 -lshlwapi -lstdc++ -Wl,--enable-stdcall-fixup $libs_qga" qga_vss_provider="qga/vss-win32/qga-vss.dll qga/vss-win32/qga-vss.tlb" else if test "$vss_win32_sdk" != "" ; then@@ -4842,7 +4811,6 @@ echo "preadv support $preadv" echo "fdatasync $fdatasync" echo "madvise $madvise" echo "posix_madvise $posix_madvise" -echo "uuid support $uuid" echo "libcap-ng support $cap_ng" echo "vhost-net support $vhost_net" echo "vhost-scsi support $vhost_scsi"@@ -5030,9 +4998,6 @@ fi if test "$fnmatch" = "yes" ; then echo "CONFIG_FNMATCH=y" >> $config_host_mak fi -if test "$uuid" = "yes" ; then - echo "CONFIG_UUID=y" >> $config_host_mak -fi if test "$xfs" = "yes" ; then echo "CONFIG_XFS=y" >> $config_host_mak fiSignature · 1 line
2.7.4
Re: [Qemu-devel] [PATCH v2 8/8] configure: Remove detection code for UUID
Quoted 10 lines · Jeff Cody
configure for opt do · line 1096
Quoted 7 lines
configure +3
-0@@ -1096,6 +1091,9 @@ for opt do --enable-vhdx|--disable-vhdx) echo "$0: $opt is obsolete, VHDX driver is always built" ;; + --enable-uuid|--disable-uuid) + echo "$0: $opt is obsolete, UUID support is always built" + ;;As with the vhdx line, this too should probably go out to stderr similar to the data plane option.
Yes, will do.