Min glib patches
The following changes since commit 609ef9f451759151d0bfe7c3843410ab94d68f18:
Merge remote-tracking branch 'remotes/berrange/tags/qio-next-pull-request' into staging (2018-06-28 17:53:31 +0100)
are available in the Git repository at:
https://github.com/berrange/qemu tags/min-glib-pull-request
for you to fetch changes up to e71e8cc035558eabd6b3e19f6d3254c754c027ef:
glib: enforce the minimum required version and warn about old APIs (2018-06-29 12:22:28 +0100)
----------------------------------------------------------------
glib: update the min required version
This updates the minimum required glib version to 2.40
----------------------------------------------------------------
Daniel P. Berrangé (3):
util: remove redundant include of glib.h and add osdep.h
glib: bump min required glib library version to 2.40
glib: enforce the minimum required version and warn about old APIs
configure | 6 +- crypto/hash-glib.c | 4 - crypto/hmac-glib.c | 36 --- include/glib-compat.h | 373 ++++------------------- include/qemu/iova-tree.h | 1 - qga/commands.c | 11 +- tests/docker/dockerfiles/centos6.docker | 30 -- tests/docker/dockerfiles/min-glib.docker | 8 - tests/ivshmem-test.c | 6 - tests/test-qga.c | 2 - tests/test-qmp-event.c | 8 +- tests/tpm-emu.h | 4 +- tests/vhost-user-test.c | 26 +- trace/simple.c | 6 +- util/iova-tree.c | 2 +- util/osdep.c | 14 - 16 files changed, 73 insertions(+), 464 deletions(-) delete mode 100644 tests/docker/dockerfiles/centos6.docker delete mode 100644 tests/docker/dockerfiles/min-glib.docker
Signature · 1 line
2.17.1
[Qemu-devel] [PULL 1/3] util: remove redundant include of glib.h and add osdep.h
Code must only ever include glib.h indirectly via the glib-compat.h header file, because we will need some macros set before glib.h is pulled in. Adding extra includes of glib.h will (soon) cause compile failures such as:
In file included from /home/berrange/src/virt/qemu/include/qemu/osdep.h:107,
from /home/berrange/src/virt/qemu/include/qemu/iova-tree.h:26,
from util/iova-tree.c:13:/home/berrange/src/virt/qemu/include/glib-compat.h:22: error: "GLIB_VERSION_MIN_REQUIRED" redefined [-Werror]
#define GLIB_VERSION_MIN_REQUIRED GLIB_VERSION_2_40
In file included from /usr/include/glib-2.0/glib/gtypes.h:34,
from /usr/include/glib-2.0/glib/galloca.h:32,
from /usr/include/glib-2.0/glib.h:30,
from util/iova-tree.c:12:
/usr/include/glib-2.0/glib/gversionmacros.h:237: note: this is the location of the previous definition
# define GLIB_VERSION_MIN_REQUIRED (GLIB_VERSION_CUR_STABLE)Furthermore, the osdep.h include should always be done directly from the .c file rather than indirectly via any .h file.
--- include/qemu/iova-tree.h | 1 - util/iova-tree.c | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-)
include/qemu/iova-tree.h +0 -1
@@ -23,7 +23,6 @@* for the thread safety issue. */ -#include "qemu/osdep.h" #include "exec/memory.h" #include "exec/hwaddr.h"
util/iova-tree.c +1 -1
@@ -9,7 +9,7 @@* This work is licensed under the terms of the GNU GPL, version 2 or later. */ -#include <glib.h> +#include "qemu/osdep.h" #include "qemu/iova-tree.h" struct IOVATree {
Signature · 1 line
2.17.1
[Qemu-devel] [PULL 2/3] glib: bump min required glib library version to 2.40
In reply to Daniel P. BerrangéPer supported platforms doc[1], the various min glib on relevant distros is:
RHEL-7: 2.50.3
Debian (Stretch): 2.50.3
Debian (Jessie): 2.42.1
OpenBSD (Ports): 2.54.3
FreeBSD (Ports): 2.50.3
OpenSUSE Leap 15: 2.54.3
SLE12-SP2: 2.48.2
Ubuntu (Xenial): 2.48.0
macOS (Homebrew): 2.56.0
This suggests that a minimum glib of 2.42 is a reasonable target.
The GLibC compile farm, however, uses Ubuntu 14.04 (Trusty) which only has glib 2.40.0, and this is needed for testing during merge. Thus an exception is made to the documented platform support policy to allow for all three current LTS releases to be supported.
Docker jobs that not longer satisfy this new min version are removed.
[1] https://qemu.weilnetz.de/doc/qemu-doc.html#Supported-build-platforms
--- configure | 6 +- crypto/hash-glib.c | 4 - crypto/hmac-glib.c | 36 --- include/glib-compat.h | 319 ----------------------- qga/commands.c | 11 +- tests/docker/dockerfiles/centos6.docker | 30 --- tests/docker/dockerfiles/min-glib.docker | 8 - tests/ivshmem-test.c | 6 - tests/test-qmp-event.c | 8 +- tests/tpm-emu.h | 4 +- tests/vhost-user-test.c | 26 +- trace/simple.c | 6 +- util/osdep.c | 14 - 13 files changed, 11 insertions(+), 467 deletions(-) delete mode 100644 tests/docker/dockerfiles/centos6.docker delete mode 100644 tests/docker/dockerfiles/min-glib.docker
configure +1 -5
@@ -3433,11 +3433,7 @@ fi ########################################## # glib support probe -if test "$mingw32" = yes; then - glib_req_ver=2.30 -else - glib_req_ver=2.22 -fi +glib_req_ver=2.40 glib_modules=gthread-2.0 if test "$modules" = yes; then glib_modules="$glib_modules gmodule-export-2.0"
crypto/hash-glib.c +0 -4
@@ -30,11 +30,7 @@ static int qcrypto_hash_alg_map[QCRYPTO_HASH_ALG__MAX] = { [QCRYPTO_HASH_ALG_SHA224] = -1, [QCRYPTO_HASH_ALG_SHA256] = G_CHECKSUM_SHA256, [QCRYPTO_HASH_ALG_SHA384] = -1, -#if GLIB_CHECK_VERSION(2, 36, 0) [QCRYPTO_HASH_ALG_SHA512] = G_CHECKSUM_SHA512, -#else - [QCRYPTO_HASH_ALG_SHA512] = -1, -#endif [QCRYPTO_HASH_ALG_RIPEMD160] = -1, };
crypto/hmac-glib.c +0 -36
@@ -17,9 +17,6 @@#include "crypto/hmac.h" #include "hmacpriv.h" -/* Support for HMAC Algos has been added in GLib 2.30 */ -#if GLIB_CHECK_VERSION (2 ,30 ,0 ) -static int qcrypto_hmac_alg_map[QCRYPTO_HASH_ALG__MAX ] = { [QCRYPTO_HASH_ALG_MD5 ] =G_CHECKSUM_MD5 , [QCRYPTO_HASH_ALG_SHA1 ] =G_CHECKSUM_SHA1 ,
@@ -126,39 +123,6 @@ qcrypto_glib_hmac_bytesv(QCryptoHmac *hmac,return 0 ; } -#else - -bool qcrypto_hmac_supports (QCryptoHashAlgorithm alg) -{ -return false; -} - -void *qcrypto_hmac_ctx_new (QCryptoHashAlgorithm alg, -const uint8_t *key,size_t nkey, -Error **errp) -{ -return NULL ; -} - -static void -qcrypto_glib_hmac_ctx_free (QCryptoHmac *hmac) -{ -return ; -} - -static int -qcrypto_glib_hmac_bytesv (QCryptoHmac *hmac, -const struct iovec *iov, -size_t niov, -uint8_t **result, -size_t *resultlen, -Error **errp) -{ -return -1 ; -} - -#endif -QCryptoHmacDriver qcrypto_hmac_lib_driver = { .hmac_bytesv = qcrypto_glib_hmac_bytesv, .hmac_free = qcrypto_glib_hmac_ctx_free,
include/glib-compat.h +0 -319
335 lines not on this page · raw message
qga/commands.c +2 -9
@@ -414,10 +414,8 @@ GuestExec *qmp_guest_exec(const char *path, argv =guest_exec_get_args (&arglist, true); envp = has_env ?guest_exec_get_args (env, false) :NULL ; - flags =G_SPAWN_SEARCH_PATH |G_SPAWN_DO_NOT_REAP_CHILD ; -#if GLIB_CHECK_VERSION (2 ,33 ,2 ) - flags |=G_SPAWN_SEARCH_PATH_FROM_ENVP ; -#endif + flags =G_SPAWN_SEARCH_PATH |G_SPAWN_DO_NOT_REAP_CHILD | +G_SPAWN_SEARCH_PATH_FROM_ENVP ;if (!has_output) { flags |=G_SPAWN_STDOUT_TO_DEV_NULL |G_SPAWN_STDERR_TO_DEV_NULL ; }
@@ -514,7 +512,6 @@ GuestHostName *qmp_guest_get_host_name(Error **err)GuestTimezone *qmp_guest_get_timezone (Error **errp) { -#if GLIB_CHECK_VERSION (2 ,28 ,0 )GuestTimezone *info =NULL ;GTimeZone *tz =NULL ;gint64 now =0 ;
@@ -544,8 +541,4 @@ GuestTimezone *qmp_guest_get_timezone(Error **errp) error:g_free (info);return NULL ; -#else -error_setg (errp,QERR_UNSUPPORTED ); -return NULL ; -#endif }
tests/docker/dockerfiles/centos6.docker deleted +0 -30
@@ -1,30 +0,0 @@ -FROM centos:6 -RUN yum install -y epel-release centos-release-xen -ENV PACKAGES \ - bison \ - bzip2-devel \ - ccache \ - csnappy-devel \ - flex \ - g++ \ - gcc \ - gettext \ - git \ - glib2-devel \ - libepoxy-devel \ - libfdt-devel \ - librdmacm-devel \ - lzo-devel \ - make \ - mesa-libEGL-devel \ - mesa-libgbm-devel \ - pixman-devel \ - SDL-devel \ - spice-glib-devel \ - spice-server-devel \ - tar \ - vte-devel \ - xen-devel \ - zlib-devel -RUN yum install -y $PACKAGES -RUN rpm -q $PACKAGES | sort > /packages.txt
tests/docker/dockerfiles/min-glib.docker deleted +0 -8
@@ -1,8 +0,0 @@ -FROM centos:6 -RUN yum install -y \ - tar gettext git make gcc g++ \ - zlib-devel SDL-devel pixman-devel \ - epel-release -RUN yum install -y libfdt-devel ccache -RUN yum downgrade -y http://vault.centos.org/6.0/os/x86_64/Packages/glib2-2.22.5-5.el6.x86_64.rpm -RUN yum install -y http://vault.centos.org/6.0/os/x86_64/Packages/glib2-devel-2.22.5-5.el6.x86_64.rpm
tests/ivshmem-test.c +0 -6
@@ -504,12 +504,6 @@ int main(int argc, char **argv)const char *arch =qtest_get_arch ();gchar dir[] ="/tmp/ivshmem-test.XXXXXX" ; -#if !GLIB_CHECK_VERSION (2 ,31 ,0 ) -if (!g_thread_supported ()) { -g_thread_init (NULL ); - } -#endif -g_test_init (&argc, &argv,NULL );qtest_add_abrt_handler (abrt_handler,NULL );
tests/test-qmp-event.c +1 -7
@@ -32,7 +32,7 @@ typedef struct QDictCmpData { } QDictCmpData;TestEventData *test_event_data; -static CompatGMutex test_event_lock; +static GMutex test_event_lock;/* Only compares bool, int, string */ static
@@ -242,12 +242,6 @@ static void test_event_d(TestEventData *data,int main (int argc,char **argv) { -#if !GLIB_CHECK_VERSION (2 ,31 ,0 ) -if (!g_thread_supported ()) { -g_thread_init (NULL ); - } -#endif -qmp_event_set_func_emit (event_test_emit);g_test_init (&argc, &argv,NULL );
tests/tpm-emu.h +2 -2
@@ -24,8 +24,8 @@ struct tpm_hdr { }QEMU_PACKED ; typedef struct TestState { - CompatGMutex data_mutex; - CompatGCond data_cond; + GMutex data_mutex; + GCond data_cond; SocketAddress *addr; QIOChannel *tpm_ioc; GThread *emu_tpm_thread;
tests/vhost-user-test.c +2 -24
@@ -32,14 +32,6 @@#include <linux/virtio_net.h> #include <sys/vfs.h> -/* GLIB version compatibility flags */ -#if !GLIB_CHECK_VERSION (2 ,26 ,0 ) -#define G_TIME_SPAN_SECOND (G_GINT64_CONSTANT(1000000)) -#endif - -#if GLIB_CHECK_VERSION (2 ,28 ,0 ) -#define HAVE_MONOTONIC_TIME -#endif #define QEMU_CMD_MEM " -m %d -object memory-backend-file,id=mem,size=%dM," \ "mem-path=%s,share=on -numa node,memdev=mem"
@@ -150,8 +142,8 @@ typedef struct TestServer {int fds_num;int fds[VHOST_MEMORY_MAX_NREGIONS ];VhostUserMemory memory; -CompatGMutex data_mutex; -CompatGCond data_cond; +GMutex data_mutex; +GCond data_cond;int log_fd;uint64_t rings;bool test_fail;
@@ -642,21 +634,7 @@ test_migrate_source_check(GSource *source)return FALSE; } -#if !GLIB_CHECK_VERSION (2 ,36 ,0 ) -/* this callback is unnecessary with glib >2.36, the default -* prepare for the source does the same */ -static gboolean -test_migrate_source_prepare (GSource *source,gint *timeout) -{ - *timeout =-1 ; -return FALSE; -} -#endif -GSourceFuncs test_migrate_source_funcs = { -#if !GLIB_CHECK_VERSION(2,36,0) - .prepare = test_migrate_source_prepare, -#endif .check = test_migrate_source_check, };
trace/simple.c +3 -3
@@ -36,9 +36,9 @@* Trace records are written out by a dedicated thread. The thread waits for * records to become available, writes them out, and then waits again. */ -static CompatGMutex trace_lock; -static CompatGCond trace_available_cond; -static CompatGCond trace_empty_cond; +static GMutex trace_lock; +static GCond trace_available_cond; +static GCond trace_empty_cond;static bool trace_available;static bool trace_writeout_enabled;
util/osdep.c +0 -14
@@ -504,20 +504,6 @@ int socket_init(void)return 0 ; } -#if !GLIB_CHECK_VERSION (2 ,31 ,0 ) -/* Ensure that glib is running in multi-threaded mode -* Old versions of glib require explicit initialization. Failure to do -* this results in the single-threaded code paths being taken inside -* glib. For example, the g_slice allocator will not be thread-safe -* and cause crashes. -*/ -static void __attribute__((constructor))thread_init (void ) -{ -if (!g_thread_supported ()) { -g_thread_init (NULL ); - } -} -#endif #ifndef CONFIG_IOVEC /* helper function for iov_send_recv() */
Signature · 1 line
2.17.1
[Qemu-devel] [PULL 3/3] glib: enforce the minimum required version and warn about old APIs
In reply to Daniel P. BerrangéThere are two useful macros that can be defined before including glib.h that are related to the min required glib version
- GLIB_VERSION_MIN_REQUIRED
When this is defined, if code uses an API that was deprecated in this version, or older, a compiler warning will be emitted. This alerts maintainers to update their code to whatever new replacement API is now recommended best practice.
- GLIB_VERSION_MAX_ALLOWED
When this is defined, if code uses an API that was introduced in a version that is newer than the declared version, a compiler warning will be emitted. This alerts maintainers if new code accidentally uses functionality that won't be available on some supported platforms.
The GLIB_VERSION_MAX_ALLOWED constant makes it a bit harder to opt in to using specific new APIs with a GLIB_CHECK_VERSION conditional. To workaround this Pragmas can be used to temporarily turn off the -Wdeprecated-declarations compiler warning, while a static inline compat function is implemented. This workaround is illustrated with the implementation of the g_strv_contains method to satisfy the test suite.
--- include/glib-compat.h | 68 +++++++++++++++++++++++++++++++++++++++++++ tests/test-qga.c | 2 -- 2 files changed, 68 insertions(+), 2 deletions(-)
include/glib-compat.h +68 -0
@@ -16,8 +16,74 @@#ifndef QEMU_GLIB_COMPAT_H #define QEMU_GLIB_COMPAT_H +/* Ask for warnings for anything that was marked deprecated in +* the defined version, or before. It is a candidate for rewrite. +*/ +#define GLIB_VERSION_MIN_REQUIRED GLIB_VERSION_2_40 + +/* Ask for warnings if code tries to use function that did not +* exist in the defined version. These risk breaking builds +*/ +#define GLIB_VERSION_MAX_ALLOWED GLIB_VERSION_2_40 + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" +#include <glib.h> +/* +* Note that because of the GLIB_VERSION_MAX_ALLOWED constant above, allowing +* use of functions from newer GLib via this compat header needs a little +* trickery to prevent warnings being emitted. +* +* Consider a function from newer glib-X.Y that we want to use +* +* int g_foo(const char *wibble) +* +* We must define a static inline function with the same signature that does +* what we need, but with a "_qemu" suffix e.g. +* +* static inline void g_foo_qemu(const char *wibble) +* { +* #if GLIB_CHECK_VERSION(X, Y, 0) +* g_foo(wibble) +* #else +* g_something_equivalent_in_older_glib(wibble); +* #endif +* } +* +* The #pragma at the top of this file turns off -Wdeprecated-declarations, +* ensuring this wrapper function impl doesn't trigger the compiler warning +* about using too new glib APIs. Finally we can do +* +* #define g_foo(a) g_foo_qemu(a) +* +* So now the code elsewhere in QEMU, which *does* have the +* -Wdeprecated-declarations warning active, can call g_foo(...) as normal, +* without generating warnings. +*/ + +static inline gboolean g_strv_contains_qemu (const gchar *const *strv, +const gchar *str) +{ +#if GLIB_CHECK_VERSION (2 ,44 ,0 ) +return g_strv_contains (strv, str); +#else +g_return_val_if_fail (strv !=NULL , FALSE); +g_return_val_if_fail (str !=NULL , FALSE); + +for (; *strv !=NULL ; strv++) { +if (g_str_equal (str, *strv)) { +return TRUE; + } + } + +return FALSE; +#endif +} +#define g_strv_contains (a, b) g_strv_contains_qemu(a, b) + +#if defined(_WIN32) && !GLIB_CHECK_VERSION (2 ,50 ,0 )/* * g_poll has a problem on Windows when using
@@ -45,4 +111,6 @@ gint g_poll_fixed(GPollFD *fds, guint nfds, gint timeout); } while (0)#endif +#pragma GCC diagnostic pop +#endif
tests/test-qga.c +0 -2
@@ -744,12 +744,10 @@ static void test_qga_config(gconstpointer data) strv =g_key_file_get_string_list (kf,"general" ,"blacklist" , &n, &error); g_assert_cmpint(n, ==, 2); -#if GLIB_CHECK_VERSION (2 ,44 ,0 )g_assert_true (g_strv_contains ((const char *const *)strv,"guest-ping" ));g_assert_true (g_strv_contains ((const char *const *)strv,"guest-get-time" )); -#endif g_assert_no_error (error);g_strfreev (strv);
Signature · 1 line
2.17.1
Peter Maydell
AppliedQuoted 10 lines · Daniel P. Berrangé
The following changes since commit
609ef9f451759151d0bfe7c3843410ab94d68f18:Merge remote-tracking branch 'remotes/berrange/tags/qio-next-pull-request' into staging (2018-06-28 17:53:31 +0100)
are available in the Git repository at:
https://github.com/berrange/qemu tags/min-glib-pull-request
for you to fetch changes up to
e71e8cc035558eabd6b3e19f6d3254c754c027ef:
Quoted 8 lines
glib: enforce the minimum required version and warn about old APIs (2018-06-29 12:22:28 +0100)
----------------------------------------------------------------
glib: update the min required versionThis updates the minimum required glib version to 2.40
----------------------------------------------------------------
Applied, thanks.
-- PMM