From nobody Mon Apr 29 23:41:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1567101788; cv=none; d=zoho.com; s=zohoarc; b=gajykAqS6AvDnCMoniVwxeNaOYukJbuWun0lBD2u4vwZaLk5g3bf0n5JYLCfbfUkFSyZAh0QkAdGgesvWBauxJrLYTmBRIbfGcSqXYwfaADe877HjVmcM5yDFwuMvzEzjxqx00zb6Uiju/DF0zPZQSjvr9VQCIdu5k/syzewGrY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1567101788; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=t+FykHztOMVcKYefBlYChG2lC8mGxXg4KSyl4WZt6MU=; b=iarfenONP4AQbU/TlLexefySoyOUaR1meQARsTLxZjhudjhRzENpUqlloT4bmshPJuUb9WvtOJusrZD4bng2/QHV83160yWbLaCXGaP74qotrd3rFOOCvqFdH4KhsdSZPOue89TU61PtOlN+Bt5u6zj7kQdEeNIgO3gu4QhvYEA= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1567101788255384.4334145587376; Thu, 29 Aug 2019 11:03:08 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1021158569; Thu, 29 Aug 2019 18:03:07 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E09DF19C58; Thu, 29 Aug 2019 18:03:06 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id A133924F30; Thu, 29 Aug 2019 18:03:06 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x7TI2vm2020446 for ; Thu, 29 Aug 2019 14:02:57 -0400 Received: by smtp.corp.redhat.com (Postfix) id C83396060D; Thu, 29 Aug 2019 18:02:57 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-112-60.ams2.redhat.com [10.36.112.60]) by smtp.corp.redhat.com (Postfix) with ESMTP id 87A586092D; Thu, 29 Aug 2019 18:02:56 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Thu, 29 Aug 2019 19:02:44 +0100 Message-Id: <20190829180250.3290-2-berrange@redhat.com> In-Reply-To: <20190829180250.3290-1-berrange@redhat.com> References: <20190829180250.3290-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 1/7] util: purge all code for testing OOM handling X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Thu, 29 Aug 2019 18:03:07 +0000 (UTC) The OOM handling requires special build time options which we never enable in our CI. Even once enabled the tests are incredibly slow and typically require manual inspection of the results to weed out false positives. Since there was previous agreement to switch to abort on OOM in libvirt code, there's no point continuing to keep the unused OOM testing code. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: J=C3=A1n Tomko --- configure.ac | 17 --- docs/docs.html.in | 3 - docs/internals/oomtesting.html.in | 213 ------------------------------ src/libvirt_private.syms | 4 - src/util/viralloc.c | 111 ---------------- src/util/viralloc.h | 5 - tests/Makefile.am | 1 - tests/oomtrace.pl | 41 ------ tests/qemuxml2argvtest.c | 12 +- tests/testutils.c | 189 +------------------------- tests/testutils.h | 2 - tests/virfirewalltest.c | 12 -- 12 files changed, 6 insertions(+), 604 deletions(-) delete mode 100644 docs/internals/oomtesting.html.in delete mode 100755 tests/oomtrace.pl diff --git a/configure.ac b/configure.ac index 7c76a9c9ec..36e75ac3c0 100644 --- a/configure.ac +++ b/configure.ac @@ -766,22 +766,6 @@ if test "$enable_test_coverage" =3D yes; then WARN_CFLAGS=3D$save_WARN_CFLAGS fi =20 -LIBVIRT_ARG_ENABLE([TEST_OOM], [memory allocation failure checking], [no]) -case "$enable_test_oom" in - yes|no) ;; - *) AC_MSG_ERROR([bad value ${enable_test_oom} for test-oom option]) ;; -esac - -if test "$enable_test_oom" =3D yes; then - have_trace=3Dyes - AC_CHECK_HEADER([execinfo.h],[],[have_trace=3Dno]) - AC_CHECK_FUNC([backtrace],[],[have_trace=3Dno]) - if test "$have_trace" =3D "yes"; then - AC_DEFINE([TEST_OOM_TRACE], 1, [Whether backtrace() is available]) - fi - AC_DEFINE([TEST_OOM], 1, [Whether malloc OOM checking is enabled]) -fi - LIBVIRT_ARG_ENABLE([TEST_LOCKING], [thread locking tests using CIL], [no]) case "$enable_test_locking" in yes|no) ;; @@ -1052,7 +1036,6 @@ AC_MSG_NOTICE([]) AC_MSG_NOTICE([Test suite]) AC_MSG_NOTICE([]) AC_MSG_NOTICE([ Coverage: $enable_test_coverage]) -AC_MSG_NOTICE([ Alloc OOM: $enable_test_oom]) AC_MSG_NOTICE([]) AC_MSG_NOTICE([Miscellaneous]) AC_MSG_NOTICE([]) diff --git a/docs/docs.html.in b/docs/docs.html.in index ba9514279a..c1741c89b4 100644 --- a/docs/docs.html.in +++ b/docs/docs.html.in @@ -155,9 +155,6 @@
Lock managers
Use lock managers to protect disk content
=20 -
Out of memory testing
-
Simulating OOM conditions in the test suite
-
Functional testing
Testing libvirt with TCK test suite and Libvirt-test-API
diff --git a/docs/internals/oomtesting.html.in b/docs/internals/oomtesting.= html.in deleted file mode 100644 index 72d0f2c6ff..0000000000 --- a/docs/internals/oomtesting.html.in +++ /dev/null @@ -1,213 +0,0 @@ - - - - -

Out of memory testing

- -
    - - -

    - This page describes how to use the test suite todo out of memory - testing. -

    - -

    Building with OOM testing

    - -

    - Since OOM testing requires hooking into the malloc APIs, it is - not enabled by default. The flag --enable-test-oom - must be given to configure. When this is done the - libvirt allocation APIs will have some hooks enabled. -

    - -
    -$ ./configure --enable-test-oom
    -
    - - -

    Basic OOM testing support

    - -

    - The first step in validating OOM usage is to run a test suite - with full OOM testing enabled. This is done by setting the - VIR_TEST_OOM=3D1 environment variable. The way this - works is that it runs the test once normally to "prime" any - static memory allocations. Then it runs it once more counting - the total number of memory allocations. Then it runs it in a - loop failing a different memory allocation each time. For every - memory allocation failure triggered, it expects the test case - to return an error. OOM testing is quite slow requiring each - test case to be executed O(n) times, where 'n' is the total - number of memory allocations. This results in a total number - of memory allocations of '(n * (n + 1) ) / 2' -

    - -
    -$ VIR_TEST_OOM=3D1 ./qemuxml2argvtest
    - 1) QEMU XML-2-ARGV minimal                                           ... =
    OK
    -    Test OOM for nalloc=3D42 .......................................... OK
    - 2) QEMU XML-2-ARGV minimal-s390                                      ... =
    OK
    -    Test OOM for nalloc=3D28 ............................ OK
    - 3) QEMU XML-2-ARGV machine-aliases1                                  ... =
    OK
    -    Test OOM for nalloc=3D38 ...................................... OK
    - 4) QEMU XML-2-ARGV machine-aliases2                                  ... =
    OK
    -    Test OOM for nalloc=3D38 ...................................... OK
    - 5) QEMU XML-2-ARGV machine-core-on                                   ... =
    OK
    -    Test OOM for nalloc=3D37 ..................................... OK
    -...snip...
    -
    - -

    - In this output, the first line shows the normal execution and - the test number, and the second line shows the total number - of memory allocations from that test case. -

    - -

    Tracking failures with valgrind

    - -

    - The test suite should obviously *not* crash during OOM testing. - If it does crash, then to assist in tracking down the problem - it is worth using valgrind and only running a single test case. - For example, supposing test case 5 crashed. Then re-run the - test with -

    - -
    -$ VIR_TEST_OOM=3D1 VIR_TEST_RANGE=3D5 ../run valgrind ./qemuxml2argvtest
    -...snip...
    - 5) QEMU XML-2-ARGV machine-core-on                                   ... =
    OK
    -    Test OOM for nalloc=3D37 ..................................... OK
    -...snip...
    -    
    - -

    - Valgrind should report the cause of the crash - for example a - double free or use of uninitialized memory or NULL pointer - access. -

    - -

    Tracking failures with stack traces

    - -

    - With some really difficult bugs valgrind is not sufficient to - identify the cause. In this case, it is useful to identify the - precise allocation which was failed, to allow the code path - to the error to be traced. The VIR_TEST_OOM - env variable can be given a range of memory allocations to - test. So if a test case has 150 allocations, it can be told - to only test allocation numbers 7-10. The VIR_TEST_OOM_TRACE - variable can be used to print out stack traces. -

    - -
    -$ VIR_TEST_OOM_TRACE=3D2 VIR_TEST_OOM=3D1:7-10 VIR_TEST_RANGE=3D5 \
    -    ../run valgrind ./qemuxml2argvtest
    - 5) QEMU XML-2-ARGV machine-core-on                                   ... =
    OK
    -    Test OOM for nalloc=3D37 !virAllocN
    -/home/berrange/src/virt/libvirt/src/util/viralloc.c:180
    -virDomainDefParseXML
    -/home/berrange/src/virt/libvirt/src/conf/domain_conf.c:11786 (discriminato=
    r 1)
    -virDomainDefParseNode
    -/home/berrange/src/virt/libvirt/src/conf/domain_conf.c:12677
    -virDomainDefParse
    -/home/berrange/src/virt/libvirt/src/conf/domain_conf.c:12621
    -testCompareXMLToArgvFiles
    -/home/berrange/src/virt/libvirt/tests/qemuxml2argvtest.c:107
    -virtTestRun
    -/home/berrange/src/virt/libvirt/tests/testutils.c:266
    -mymain
    -/home/berrange/src/virt/libvirt/tests/qemuxml2argvtest.c:388 (discriminato=
    r 2)
    -virtTestMain
    -/home/berrange/src/virt/libvirt/tests/testutils.c:791
    -__libc_start_main
    -??:?
    -_start
    -??:?
    -!virAlloc
    -/home/berrange/src/virt/libvirt/src/util/viralloc.c:133
    -virDomainDiskDefParseXML
    -/home/berrange/src/virt/libvirt/src/conf/domain_conf.c:4790
    -virDomainDefParseXML
    -/home/berrange/src/virt/libvirt/src/conf/domain_conf.c:11797
    -virDomainDefParseNode
    -/home/berrange/src/virt/libvirt/src/conf/domain_conf.c:12677
    -virDomainDefParse
    -/home/berrange/src/virt/libvirt/src/conf/domain_conf.c:12621
    -testCompareXMLToArgvFiles
    -/home/berrange/src/virt/libvirt/tests/qemuxml2argvtest.c:107
    -virtTestRun
    -/home/berrange/src/virt/libvirt/tests/testutils.c:266
    -mymain
    -/home/berrange/src/virt/libvirt/tests/qemuxml2argvtest.c:388 (discriminato=
    r 2)
    -virtTestMain
    -/home/berrange/src/virt/libvirt/tests/testutils.c:791
    -__libc_start_main
    -??:?
    -_start
    -??:?
    -!virAllocN
    -/home/berrange/src/virt/libvirt/src/util/viralloc.c:180
    -virXPathNodeSet
    -/home/berrange/src/virt/libvirt/src/util/virxml.c:609
    -virDomainDefParseXML
    -/home/berrange/src/virt/libvirt/src/conf/domain_conf.c:11805
    -virDomainDefParseNode
    -/home/berrange/src/virt/libvirt/src/conf/domain_conf.c:12677
    -virDomainDefParse
    -/home/berrange/src/virt/libvirt/src/conf/domain_conf.c:12621
    -testCompareXMLToArgvFiles
    -/home/berrange/src/virt/libvirt/tests/qemuxml2argvtest.c:107
    -virtTestRun
    -/home/berrange/src/virt/libvirt/tests/testutils.c:266
    -mymain
    -/home/berrange/src/virt/libvirt/tests/qemuxml2argvtest.c:388 (discriminato=
    r 2)
    -virtTestMain
    -/home/berrange/src/virt/libvirt/tests/testutils.c:791
    -__libc_start_main
    -??:?
    -_start
    -??:?
    -!virAllocN
    -/home/berrange/src/virt/libvirt/src/util/viralloc.c:180
    -virDomainDefParseXML
    -/home/berrange/src/virt/libvirt/src/conf/domain_conf.c:11808 (discriminato=
    r 1)
    -virDomainDefParseNode
    -/home/berrange/src/virt/libvirt/src/conf/domain_conf.c:12677
    -virDomainDefParse
    -/home/berrange/src/virt/libvirt/src/conf/domain_conf.c:12621
    -testCompareXMLToArgvFiles
    -/home/berrange/src/virt/libvirt/tests/qemuxml2argvtest.c:107
    -virtTestRun
    -/home/berrange/src/virt/libvirt/tests/testutils.c:266
    -mymain
    -/home/berrange/src/virt/libvirt/tests/qemuxml2argvtest.c:388 (discriminato=
    r 2)
    -virtTestMain
    -/home/berrange/src/virt/libvirt/tests/testutils.c:791
    -__libc_start_main
    -??:?
    -_start
    -??:?
    -    
    - -

    Non-crash related problems

    - -

    - Not all memory allocation bugs result in code crashing. Sometimes - the code will be silently ignoring the allocation failure, resulting - in incorrect data being produced. For example the XML parser may - mistakenly treat an allocation failure as indicating that an XML - attribute was not set in the input document. It is hard to identify - these problems from the test suite automatically. For this, the - test suites should be run with VIR_TEST_DEBUG=3D1 set - and then stderr analysed for any unexpected data. For example, - the XML conversion may show an embedded "(null)" literal, or the - test suite might complain about missing elements / attributes - in the actual vs expected data. These are all signs of bugs in - OOM handling. In the future the OOM tests will be enhanced to - validate that an error VIR_ERR_NO_MEMORY is returned for each - allocation failed, rather than some other error. -

    - - diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index a34d92f5ef..cd9e29cac1 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1483,10 +1483,6 @@ virSecurityManagerVerify; # util/viralloc.h virAlloc; virAllocN; -virAllocTestCount; -virAllocTestHook; -virAllocTestInit; -virAllocTestOOM; virAllocVar; virDeleteElementsN; virDispose; diff --git a/src/util/viralloc.c b/src/util/viralloc.c index e82bfa0acd..5a0adcc706 100644 --- a/src/util/viralloc.c +++ b/src/util/viralloc.c @@ -30,80 +30,6 @@ =20 VIR_LOG_INIT("util.alloc"); =20 -#if TEST_OOM -static int testMallocNext; -static int testMallocFailFirst; -static int testMallocFailLast; -static void (*testMallocHook)(int, void*); -static void *testMallocHookData; - -void virAllocTestInit(void) -{ - testMallocNext =3D 1; - testMallocFailFirst =3D 0; - testMallocFailLast =3D 0; -} - -int virAllocTestCount(void) -{ - return testMallocNext - 1; -} - -void virAllocTestHook(void (*func)(int, void*), void *data) -{ - testMallocHook =3D func; - testMallocHookData =3D data; -} - -void virAllocTestOOM(int n, int m) -{ - testMallocNext =3D 1; - testMallocFailFirst =3D n; - testMallocFailLast =3D n + m - 1; -} - -static int virAllocTestFail(void) -{ - int fail =3D 0; - if (testMallocNext =3D=3D 0) - return 0; - - fail =3D - testMallocNext >=3D testMallocFailFirst && - testMallocNext <=3D testMallocFailLast; - - if (fail && testMallocHook) - (testMallocHook)(testMallocNext, testMallocHookData); - - testMallocNext++; - return fail; -} - -#else - -void virAllocTestOOM(int n ATTRIBUTE_UNUSED, - int m ATTRIBUTE_UNUSED) -{ - /* nada */ -} - -int virAllocTestCount(void) -{ - return 0; -} - -void virAllocTestInit(void) -{ - /* nada */ -} - -void virAllocTestHook(void (*func)(int, void*) ATTRIBUTE_UNUSED, - void *data ATTRIBUTE_UNUSED) -{ - /* nada */ -} -#endif - =20 /** * virAlloc: @@ -130,16 +56,6 @@ int virAlloc(void *ptrptr, const char *funcname, size_t linenr) { -#if TEST_OOM - if (virAllocTestFail()) { - *(void **)ptrptr =3D NULL; - if (report) - virReportOOMErrorFull(domcode, filename, funcname, linenr); - errno =3D ENOMEM; - return -1; - } -#endif - *(void **)ptrptr =3D calloc(1, size); if (*(void **)ptrptr =3D=3D NULL) { if (report) @@ -177,16 +93,6 @@ int virAllocN(void *ptrptr, const char *funcname, size_t linenr) { -#if TEST_OOM - if (virAllocTestFail()) { - *(void **)ptrptr =3D NULL; - if (report) - virReportOOMErrorFull(domcode, filename, funcname, linenr); - errno =3D ENOMEM; - return -1; - } -#endif - *(void**)ptrptr =3D calloc(count, size); if (*(void**)ptrptr =3D=3D NULL) { if (report) @@ -226,14 +132,6 @@ int virReallocN(void *ptrptr, size_t linenr) { void *tmp; -#if TEST_OOM - if (virAllocTestFail()) { - if (report) - virReportOOMErrorFull(domcode, filename, funcname, linenr); - errno =3D ENOMEM; - return -1; - } -#endif =20 if (xalloc_oversized(count, size)) { if (report) @@ -539,15 +437,6 @@ int virAllocVar(void *ptrptr, { size_t alloc_size =3D 0; =20 -#if TEST_OOM - if (virAllocTestFail()) { - if (report) - virReportOOMErrorFull(domcode, filename, funcname, linenr); - errno =3D ENOMEM; - return -1; - } -#endif - if (VIR_ALLOC_VAR_OVERSIZED(struct_size, count, element_size)) { if (report) virReportOOMErrorFull(domcode, filename, funcname, linenr); diff --git a/src/util/viralloc.h b/src/util/viralloc.h index 2b82096fde..3e169e272c 100644 --- a/src/util/viralloc.h +++ b/src/util/viralloc.h @@ -600,11 +600,6 @@ void virDisposeString(char **strptr) sizeof(*(ptr)), NULL) =20 =20 -void virAllocTestInit(void); -int virAllocTestCount(void); -void virAllocTestOOM(int n, int m); -void virAllocTestHook(void (*func)(int, void*), void *data); - /** * VIR_AUTOFREE: * @type: type of the variable to be freed automatically diff --git a/tests/Makefile.am b/tests/Makefile.am index f92710db43..a319e386ec 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -109,7 +109,6 @@ EXTRA_DIST =3D \ nwfilterxml2firewalldata \ nwfilterxml2xmlin \ nwfilterxml2xmlout \ - oomtrace.pl \ qemuagentdata \ qemublocktestdata \ qemucapabilitiesdata \ diff --git a/tests/oomtrace.pl b/tests/oomtrace.pl deleted file mode 100755 index f799262f2c..0000000000 --- a/tests/oomtrace.pl +++ /dev/null @@ -1,41 +0,0 @@ -#!/usr/bin/env perl - -use strict; -use warnings; - -(my $ME =3D $0) =3D~ s|.*/||; -# use File::Coda; # http://meyering.net/code/Coda/ -END { - defined fileno STDOUT or return; - close STDOUT and return; - warn "$ME: failed to close standard output: $!\n"; - $? ||=3D 1; -} - - -my @data =3D <>; - - -my %trace; -my %lines; - -foreach (@data) { - if (/^\s*TRACE:\s+(\S+?)(?:\(.*\))?\s+\[0x(.*)\]\s*$/ ) { - $trace{$2} =3D $1; - } -} - -foreach my $key (keys %trace) { - my $val =3D $trace{$key}; - my $info =3D $val =3D~ /\?\?/ ? $val : `addr2line -e $val $key`; - $lines{$key} =3D $info; -} - - -foreach (@data) { - if (/^\s*TRACE:\s+(\S+?)(?:\(.*\))?\s+\[0x(.*)\]\s*$/ ) { - print $lines{$2}; - } else { - print; - } -} diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index 9395cc19a2..ac54f088e0 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -552,14 +552,12 @@ testCompareXMLToArgv(const void *data) VIR_TEST_DEBUG("Error expected but there wasn't any."); goto cleanup; } - if (!virTestOOMActive()) { - if (flags & FLAG_EXPECT_FAILURE) { - if ((log =3D virTestLogContentAndReset())) - VIR_TEST_DEBUG("Got expected error: \n%s", log); - } - virResetLastError(); - ret =3D 0; + if (flags & FLAG_EXPECT_FAILURE) { + if ((log =3D virTestLogContentAndReset())) + VIR_TEST_DEBUG("Got expected error: \n%s", log); } + virResetLastError(); + ret =3D 0; =20 cleanup: VIR_FREE(log); diff --git a/tests/testutils.c b/tests/testutils.c index 8b2c51044e..b4009f0a48 100644 --- a/tests/testutils.c +++ b/tests/testutils.c @@ -42,13 +42,6 @@ #include "virprocess.h" #include "virstring.h" =20 -#ifdef TEST_OOM -# ifdef TEST_OOM_TRACE -# include -# include -# endif -#endif - #define VIR_FROM_THIS VIR_FROM_NONE =20 VIR_LOG_INIT("tests.testutils"); @@ -61,17 +54,6 @@ static unsigned int testVerbose =3D -1; static unsigned int testExpensive =3D -1; static unsigned int testRegenerate =3D -1; =20 -#ifdef TEST_OOM -static unsigned int testOOM; -static unsigned int testOOMStart =3D -1; -static unsigned int testOOMEnd =3D -1; -static unsigned int testOOMTrace; -# ifdef TEST_OOM_TRACE -void *testAllocStack[30]; -int ntestAllocStack; -# endif -#endif -static bool testOOMActive; =20 static size_t testCounter; static virBitmapPtr testBitmap; @@ -79,11 +61,6 @@ static virBitmapPtr testBitmap; char *progname; static char *perl; =20 -bool virTestOOMActive(void) -{ - return testOOMActive; -} - static int virTestUseTerminalColors(void) { return isatty(STDOUT_FILENO); @@ -104,42 +81,6 @@ virTestGetFlag(const char *name) return flag; } =20 -#ifdef TEST_OOM_TRACE -static void virTestAllocHook(int nalloc ATTRIBUTE_UNUSED, - void *opaque ATTRIBUTE_UNUSED) -{ - ntestAllocStack =3D backtrace(testAllocStack, ARRAY_CARDINALITY(testAl= locStack)); -} -#endif - -#ifdef TEST_OOM_TRACE -static void -virTestShowTrace(void) -{ - size_t j; - for (j =3D 2; j < ntestAllocStack; j++) { - Dl_info info; - char *cmd; - - dladdr(testAllocStack[j], &info); - if (info.dli_fname && - strstr(info.dli_fname, ".so")) { - if (virAsprintf(&cmd, ADDR2LINE " -f -e %s %p", - info.dli_fname, - ((void*)((unsigned long long)testAllocStack[j] - - (unsigned long long)info.dli_fbase)= )) < 0) - continue; - } else { - if (virAsprintf(&cmd, ADDR2LINE " -f -e %s %p", - (char*)(info.dli_fname ? info.dli_fname : ""), - testAllocStack[j]) < 0) - continue; - } - ignore_value(system(cmd)); - VIR_FREE(cmd); - } -} -#endif =20 /* * Runs test @@ -207,76 +148,6 @@ virTestRun(const char *title, fprintf(stderr, "!"); } =20 -#ifdef TEST_OOM - if (testOOM && ret !=3D EXIT_AM_SKIP) { - int nalloc; - int oomret; - int start, end; - size_t i; - virResetLastError(); - virAllocTestInit(); -# ifdef TEST_OOM_TRACE - virAllocTestHook(virTestAllocHook, NULL); -# endif - oomret =3D body(data); - nalloc =3D virAllocTestCount(); - fprintf(stderr, " Test OOM for nalloc=3D%d ", nalloc); - if (testOOMStart =3D=3D -1 || - testOOMEnd =3D=3D -1) { - start =3D 0; - end =3D nalloc; - } else { - start =3D testOOMStart; - end =3D testOOMEnd + 1; - } - testOOMActive =3D true; - for (i =3D start; i < end; i++) { - bool missingFail =3D false; -# ifdef TEST_OOM_TRACE - memset(testAllocStack, 0, sizeof(testAllocStack)); - ntestAllocStack =3D 0; -# endif - virAllocTestOOM(i + 1, 1); - oomret =3D body(data); - - /* fprintf() disabled because XML parsing APIs don't allow - * distinguish between element / attribute not present - * in the XML (which is non-fatal), vs OOM / malformed - * which should be fatal. Thus error reporting for - * optionally present XML is mostly broken. - */ - if (oomret =3D=3D 0) { - missingFail =3D true; -# if 0 - fprintf(stderr, " alloc %zu failed but no err status\n", i= + 1); -# endif - } else { - if (virGetLastErrorCode() =3D=3D VIR_ERR_OK) { -# if 0 - fprintf(stderr, " alloc %zu failed but no error report= \n", i + 1); -# endif - missingFail =3D true; - } - } - if ((missingFail && testOOMTrace) || (testOOMTrace > 1)) { - fprintf(stderr, "%s", "!"); -# ifdef TEST_OOM_TRACE - virTestShowTrace(); -# endif - ret =3D -1; - } else { - fprintf(stderr, "%s", "."); - } - } - testOOMActive =3D false; - if (ret =3D=3D 0) - fprintf(stderr, " OK\n"); - else - fprintf(stderr, " FAILED\n"); - virAllocTestInit(); - } -#endif /* TEST_OOM */ - unsetenv("VIR_TEST_MOCK_TESTNAME"); return ret; } @@ -876,8 +747,7 @@ virtTestLogOutput(virLogSourcePtr source ATTRIBUTE_UNUS= ED, { struct virtTestLogData *log =3D data; virCheckFlags(VIR_LOG_STACK_TRACE,); - if (!testOOMActive) - virBufferAsprintf(&log->buf, "%s: %s", timestamp, str); + virBufferAsprintf(&log->buf, "%s: %s", timestamp, str); } =20 static void @@ -971,9 +841,6 @@ int virTestMain(int argc, va_list ap; int ret; char *testRange =3D NULL; -#ifdef TEST_OOM - char *oomstr; -#endif size_t noutputs =3D 0; virLogOutputPtr output =3D NULL; virLogOutputPtr *outputs =3D NULL; @@ -1034,60 +901,6 @@ int virTestMain(int argc, } } =20 -#ifdef TEST_OOM - if ((oomstr =3D getenv("VIR_TEST_OOM")) !=3D NULL) { - char *next; - if (testDebug =3D=3D -1) - testDebug =3D 1; - testOOM =3D 1; - if (oomstr[0] !=3D '\0' && - oomstr[1] =3D=3D ':') { - if (virStrToLong_ui(oomstr + 2, &next, 10, &testOOMStart) < 0)= { - fprintf(stderr, "Cannot parse range %s\n", oomstr); - return EXIT_FAILURE; - } - if (*next =3D=3D '\0') { - testOOMEnd =3D testOOMStart; - } else { - if (*next !=3D '-') { - fprintf(stderr, "Cannot parse range %s\n", oomstr); - return EXIT_FAILURE; - } - if (virStrToLong_ui(next+1, NULL, 10, &testOOMEnd) < 0) { - fprintf(stderr, "Cannot parse range %s\n", oomstr); - return EXIT_FAILURE; - } - } - } else { - testOOMStart =3D -1; - testOOMEnd =3D -1; - } - } - -# ifdef TEST_OOM_TRACE - if ((oomstr =3D getenv("VIR_TEST_OOM_TRACE")) !=3D NULL) { - if (virStrToLong_ui(oomstr, NULL, 10, &testOOMTrace) < 0) { - fprintf(stderr, "Cannot parse oom trace %s\n", oomstr); - return EXIT_FAILURE; - } - } -# else - if (getenv("VIR_TEST_OOM_TRACE")) { - fprintf(stderr, "%s", "OOM test tracing not enabled in this build\= n"); - return EXIT_FAILURE; - } -# endif -#else /* TEST_OOM */ - if (getenv("VIR_TEST_OOM")) { - fprintf(stderr, "%s", "OOM testing not enabled in this build\n"); - return EXIT_FAILURE; - } - if (getenv("VIR_TEST_OOM_TRACE")) { - fprintf(stderr, "%s", "OOM test tracing not enabled in this build\= n"); - return EXIT_FAILURE; - } -#endif /* TEST_OOM */ - /* Find perl early because some tests override PATH */ perl =3D virFindFileInPath("perl"); =20 diff --git a/tests/testutils.h b/tests/testutils.h index f273ca4240..85ba9fbc0b 100644 --- a/tests/testutils.h +++ b/tests/testutils.h @@ -43,8 +43,6 @@ extern char *progname; # error Fix Makefile.am #endif =20 -bool virTestOOMActive(void); - int virTestRun(const char *title, int (*body)(const void *data), const void *data); diff --git a/tests/virfirewalltest.c b/tests/virfirewalltest.c index 78685a3bf4..7e4e80e09b 100644 --- a/tests/virfirewalltest.c +++ b/tests/virfirewalltest.c @@ -611,9 +611,6 @@ testFirewallNoRollback(const void *opaque ATTRIBUTE_UNU= SED) goto cleanup; } =20 - if (virTestOOMActive()) - goto cleanup; - if (virBufferError(&cmdbuf)) goto cleanup; =20 @@ -701,9 +698,6 @@ testFirewallSingleRollback(const void *opaque ATTRIBUTE= _UNUSED) goto cleanup; } =20 - if (virTestOOMActive()) - goto cleanup; - if (virBufferError(&cmdbuf)) goto cleanup; =20 @@ -794,9 +788,6 @@ testFirewallManyRollback(const void *opaque ATTRIBUTE_U= NUSED) goto cleanup; } =20 - if (virTestOOMActive()) - goto cleanup; - if (virBufferError(&cmdbuf)) goto cleanup; =20 @@ -917,9 +908,6 @@ testFirewallChainedRollback(const void *opaque ATTRIBUT= E_UNUSED) goto cleanup; } =20 - if (virTestOOMActive()) - goto cleanup; - if (virBufferError(&cmdbuf)) goto cleanup; =20 --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon Apr 29 23:41:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1567101792; cv=none; d=zoho.com; s=zohoarc; b=jaiKCrRjl2v8p2ICGp/p6OrlBoaVigd8ohoOBV+MBYFxS4oMW9esX4J93JYcUzSp4h/lPQCEUVMn58zP7IAAjs8lyaXMd5HL85fEplE2Jyc8aZCogrNtguMffhCGzQIAdQm2zbEE53W4J2L0F4fA4O6WiaDUIwGH4H53scSwEQM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1567101792; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=Nqx+s16HxQKQyT6FEgqnWVtMe+SVyDCIIoqYQvb4oUQ=; b=oJo3OibuId/ui7hhpMGE9aXnaPb8aembUi2qEdApGu6iG6OGY4+RfWZgTwOyblBxCdPj8HwOHus9yRf2yioVAOTRLoBtrzEbR1/EnfmbE1+iuH3mMgwrUCPMV0u0iwkQS+ocO9Gp5lOuxw+zy2K9wvsV6RoyGjuqomFYOBPQb80= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1567101792317912.4987253906233; Thu, 29 Aug 2019 11:03:12 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id EB1713175298; Thu, 29 Aug 2019 18:03:10 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B4A073DE1; Thu, 29 Aug 2019 18:03:10 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 5C5D0180B536; Thu, 29 Aug 2019 18:03:10 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x7TI2xa9020453 for ; Thu, 29 Aug 2019 14:02:59 -0400 Received: by smtp.corp.redhat.com (Postfix) id 21EEE6060D; Thu, 29 Aug 2019 18:02:59 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-112-60.ams2.redhat.com [10.36.112.60]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2C42A60605; Thu, 29 Aug 2019 18:02:57 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Thu, 29 Aug 2019 19:02:45 +0100 Message-Id: <20190829180250.3290-3-berrange@redhat.com> In-Reply-To: <20190829180250.3290-1-berrange@redhat.com> References: <20190829180250.3290-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 2/7] util: make allocation functions abort on OOM X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Thu, 29 Aug 2019 18:03:11 +0000 (UTC) The functions are left returning an "int" to avoid an immediate big-bang cleanup. They'll simply never return anything other than 0, except for virInsertN which can still return an error if the requested insertion index is out of range. Interestingly in that case, the _QUIET function would none the less report an error. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: J=C3=A1n Tomko --- src/util/viralloc.c | 201 +++++++++++--------------------------------- src/util/viralloc.h | 145 +++++++++++--------------------- 2 files changed, 97 insertions(+), 249 deletions(-) diff --git a/src/util/viralloc.c b/src/util/viralloc.c index 5a0adcc706..b74f657733 100644 --- a/src/util/viralloc.c +++ b/src/util/viralloc.c @@ -35,33 +35,20 @@ VIR_LOG_INIT("util.alloc"); * virAlloc: * @ptrptr: pointer to pointer for address of allocated memory * @size: number of bytes to allocate - * @report: whether to report OOM error, if there is one - * @domcode: error domain code - * @filename: caller's filename - * @funcname: caller's funcname - * @linenr: caller's line number * * Allocate 'size' bytes of memory. Return the address of the * allocated memory in 'ptrptr'. The newly allocated memory is - * filled with zeros. If @report is true, OOM errors are - * reported automatically. + * filled with zeros. * - * Returns -1 on failure to allocate, zero on success + * Returns zero on success, aborts on OOM */ int virAlloc(void *ptrptr, - size_t size, - bool report, - int domcode, - const char *filename, - const char *funcname, - size_t linenr) + size_t size) { *(void **)ptrptr =3D calloc(1, size); - if (*(void **)ptrptr =3D=3D NULL) { - if (report) - virReportOOMErrorFull(domcode, filename, funcname, linenr); - return -1; - } + if (*(void **)ptrptr =3D=3D NULL) + abort(); + return 0; } =20 @@ -70,35 +57,22 @@ int virAlloc(void *ptrptr, * @ptrptr: pointer to pointer for address of allocated memory * @size: number of bytes to allocate * @count: number of elements to allocate - * @report: whether to report OOM error, if there is one - * @domcode: error domain code - * @filename: caller's filename - * @funcname: caller's funcname - * @linenr: caller's line number * * Allocate an array of memory 'count' elements long, * each with 'size' bytes. Return the address of the * allocated memory in 'ptrptr'. The newly allocated - * memory is filled with zeros. If @report is true, - * OOM errors are reported automatically. + * memory is filled with zeros. * - * Returns -1 on failure to allocate, zero on success + * Returns zero on success, aborts on OOM */ int virAllocN(void *ptrptr, size_t size, - size_t count, - bool report, - int domcode, - const char *filename, - const char *funcname, - size_t linenr) + size_t count) { *(void**)ptrptr =3D calloc(count, size); - if (*(void**)ptrptr =3D=3D NULL) { - if (report) - virReportOOMErrorFull(domcode, filename, funcname, linenr); - return -1; - } + if (*(void**)ptrptr =3D=3D NULL) + abort(); + return 0; } =20 @@ -107,44 +81,28 @@ int virAllocN(void *ptrptr, * @ptrptr: pointer to pointer for address of allocated memory * @size: number of bytes to allocate * @count: number of elements in array - * @report: whether to report OOM error, if there is one - * @domcode: error domain code - * @filename: caller's filename - * @funcname: caller's funcname - * @linenr: caller's line number * * Resize the block of memory in 'ptrptr' to be an array of * 'count' elements, each 'size' bytes in length. Update 'ptrptr' * with the address of the newly allocated memory. On failure, * 'ptrptr' is not changed and still points to the original memory * block. Any newly allocated memory in 'ptrptr' is uninitialized. - * If @report is true, OOM errors are reported automatically. * - * Returns -1 on failure to allocate, zero on success + * Returns zero on success, aborts on OOM */ int virReallocN(void *ptrptr, size_t size, - size_t count, - bool report, - int domcode, - const char *filename, - const char *funcname, - size_t linenr) + size_t count) { void *tmp; =20 - if (xalloc_oversized(count, size)) { - if (report) - virReportOOMErrorFull(domcode, filename, funcname, linenr); - errno =3D ENOMEM; - return -1; - } + if (xalloc_oversized(count, size)) + abort(); + tmp =3D realloc(*(void**)ptrptr, size * count); - if (!tmp && ((size * count) !=3D 0)) { - if (report) - virReportOOMErrorFull(domcode, filename, funcname, linenr); - return -1; - } + if (!tmp && ((size * count) !=3D 0)) + abort(); + *(void**)ptrptr =3D tmp; return 0; } @@ -155,46 +113,27 @@ int virReallocN(void *ptrptr, * @size: number of bytes per element * @countptr: pointer to number of elements in array * @add: number of elements to add - * @report: whether to report OOM error, if there is one - * @domcode: error domain code - * @filename: caller's filename - * @funcname: caller's funcname - * @linenr: caller's line number * * Resize the block of memory in 'ptrptr' to be an array of * '*countptr' + 'add' elements, each 'size' bytes in length. * Update 'ptrptr' and 'countptr' with the details of the newly * allocated memory. On failure, 'ptrptr' and 'countptr' are not * changed. Any newly allocated memory in 'ptrptr' is zero-filled. - * If @report is true, OOM errors are reported automatically. * - * Returns -1 on failure to allocate, zero on success + * Returns zero on success, aborts on OOM */ int virExpandN(void *ptrptr, size_t size, size_t *countptr, - size_t add, - bool report, - int domcode, - const char *filename, - const char *funcname, - size_t linenr) + size_t add) { - int ret; + if (*countptr + add < *countptr) + abort(); =20 - if (*countptr + add < *countptr) { - if (report) - virReportOOMErrorFull(domcode, filename, funcname, linenr); - errno =3D ENOMEM; - return -1; - } - ret =3D virReallocN(ptrptr, size, *countptr + add, report, - domcode, filename, funcname, linenr); - if (ret =3D=3D 0) { - memset(*(char **)ptrptr + (size * *countptr), 0, size * add); - *countptr +=3D add; - } - return ret; + virReallocN(ptrptr, size, *countptr + add); + memset(*(char **)ptrptr + (size * *countptr), 0, size * add); + *countptr +=3D add; + return 0; } =20 /** @@ -204,50 +143,35 @@ int virExpandN(void *ptrptr, * @allocptr: pointer to number of elements allocated in array * @count: number of elements currently used in array * @add: minimum number of additional elements to support in array - * @report: whether to report OOM error, if there is one - * @domcode: error domain code - * @filename: caller's filename - * @funcname: caller's funcname - * @linenr: caller's line number * * If 'count' + 'add' is larger than '*allocptr', then resize the * block of memory in 'ptrptr' to be an array of at least 'count' + * 'add' elements, each 'size' bytes in length. Update 'ptrptr' and * 'allocptr' with the details of the newly allocated memory. On * failure, 'ptrptr' and 'allocptr' are not changed. Any newly - * allocated memory in 'ptrptr' is zero-filled. If @report is true, - * OOM errors are reported automatically. - * + * allocated memory in 'ptrptr' is zero-filled. * - * Returns -1 on failure to allocate, zero on success + * Returns zero on success, aborts on OOM */ int virResizeN(void *ptrptr, size_t size, size_t *allocptr, size_t count, - size_t add, - bool report, - int domcode, - const char *filename, - const char *funcname, - size_t linenr) + size_t add) { size_t delta; =20 - if (count + add < count) { - if (report) - virReportOOMErrorFull(domcode, filename, funcname, linenr); - errno =3D ENOMEM; - return -1; - } + if (count + add < count) + abort(); + if (count + add <=3D *allocptr) return 0; =20 delta =3D count + add - *allocptr; if (delta < *allocptr / 2) delta =3D *allocptr / 2; - return virExpandN(ptrptr, size, allocptr, delta, report, - domcode, filename, funcname, linenr); + virExpandN(ptrptr, size, allocptr, delta); + return 0; } =20 /** @@ -266,8 +190,7 @@ int virResizeN(void *ptrptr, void virShrinkN(void *ptrptr, size_t size, size_t *countptr, size_t toremo= ve) { if (toremove < *countptr) { - ignore_value(virReallocN(ptrptr, size, *countptr -=3D toremove, - false, 0, NULL, NULL, 0)); + virReallocN(ptrptr, size, *countptr -=3D toremove); } else { virFree(ptrptr); *countptr =3D 0; @@ -290,11 +213,6 @@ void virShrinkN(void *ptrptr, size_t size, size_t *cou= ntptr, size_t toremove) * @inPlace: false if we should expand the allocated memory before * moving, true if we should assume someone else *has * already* done that. - * @report: whether to report OOM error, if there is one - * @domcode: error domain code - * @filename: caller's filename - * @funcname: caller's funcname - * @linenr: caller's line number * * Re-allocate an array of *countptr elements, each sizeof(*ptrptr) bytes * long, to be *countptr+add elements long, then appropriately move @@ -303,8 +221,7 @@ void virShrinkN(void *ptrptr, size_t size, size_t *coun= tptr, size_t toremove) * allocated memory in *ptrptr and the new size in *countptr. If * newelems is NULL, the new elements at ptrptr[at] are instead filled * with zero. at must be between [0,*countptr], except that -1 is - * treated the same as *countptr for convenience. If @report is true, - * OOM errors are reported automatically. + * treated the same as *countptr for convenience. * * Returns -1 on failure, 0 on success */ @@ -312,12 +229,7 @@ int virInsertElementsN(void *ptrptr, size_t size, size_t at, size_t *countptr, size_t add, void *newelems, - bool clearOriginal, bool inPlace, - bool report, - int domcode, - const char *filename, - const char *funcname, - size_t linenr) + bool clearOriginal, bool inPlace) { if (at =3D=3D -1) { at =3D *countptr; @@ -330,9 +242,8 @@ virInsertElementsN(void *ptrptr, size_t size, size_t at, =20 if (inPlace) { *countptr +=3D add; - } else if (virExpandN(ptrptr, size, countptr, add, report, - domcode, filename, funcname, linenr) < 0) { - return -1; + } else { + virExpandN(ptrptr, size, countptr, add); } =20 /* memory was successfully re-allocated. Move up all elements from @@ -407,11 +318,6 @@ virDeleteElementsN(void *ptrptr, size_t size, size_t a= t, * @struct_size: size of initial struct * @element_size: size of array elements * @count: number of array elements to allocate - * @report: whether to report OOM error, if there is one - * @domcode: error domain code - * @filename: caller's filename - * @funcname: caller's funcname - * @linenr: caller's line number * * Allocate struct_size bytes plus an array of 'count' elements, each * of size element_size. This sort of allocation is useful for @@ -420,37 +326,24 @@ virDeleteElementsN(void *ptrptr, size_t size, size_t = at, * The caller of this type of API is expected to know the length of * the array that will be returned and allocate a suitable buffer to * contain the returned data. C99 refers to these variable length - * objects as structs containing flexible array members. If @report - * is true, OOM errors are reported automatically. + * objects as structs containing flexible array members. * * Returns -1 on failure, 0 on success */ int virAllocVar(void *ptrptr, size_t struct_size, size_t element_size, - size_t count, - bool report, - int domcode, - const char *filename, - const char *funcname, - size_t linenr) + size_t count) { size_t alloc_size =3D 0; =20 - if (VIR_ALLOC_VAR_OVERSIZED(struct_size, count, element_size)) { - if (report) - virReportOOMErrorFull(domcode, filename, funcname, linenr); - errno =3D ENOMEM; - return -1; - } + if (VIR_ALLOC_VAR_OVERSIZED(struct_size, count, element_size)) + abort(); =20 alloc_size =3D struct_size + (element_size * count); *(void **)ptrptr =3D calloc(1, alloc_size); - if (*(void **)ptrptr =3D=3D NULL) { - if (report) - virReportOOMErrorFull(domcode, filename, funcname, linenr); - return -1; - } + if (*(void **)ptrptr =3D=3D NULL) + abort(); return 0; } =20 diff --git a/src/util/viralloc.h b/src/util/viralloc.h index 3e169e272c..1437ad4b29 100644 --- a/src/util/viralloc.h +++ b/src/util/viralloc.h @@ -44,36 +44,27 @@ =20 =20 /* Don't call these directly - use the macros below */ -int virAlloc(void *ptrptr, size_t size, bool report, int domcode, - const char *filename, const char *funcname, size_t linenr) - ATTRIBUTE_RETURN_CHECK ATTRIBUTE_NONNULL(1); -int virAllocN(void *ptrptr, size_t size, size_t count, bool report, int do= mcode, - const char *filename, const char *funcname, size_t linenr) - ATTRIBUTE_RETURN_CHECK ATTRIBUTE_NONNULL(1); -int virReallocN(void *ptrptr, size_t size, size_t count, bool report, int = domcode, - const char *filename, const char *funcname, size_t linenr) - ATTRIBUTE_RETURN_CHECK ATTRIBUTE_NONNULL(1); -int virExpandN(void *ptrptr, size_t size, size_t *count, size_t add, bool = report, - int domcode, const char *filename, const char *funcname, si= ze_t linenr) - ATTRIBUTE_RETURN_CHECK ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(3); -int virResizeN(void *ptrptr, size_t size, size_t *alloc, size_t count, siz= e_t desired, - bool report, int domcode, const char *filename, - const char *funcname, size_t linenr) - ATTRIBUTE_RETURN_CHECK ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(3); +int virAlloc(void *ptrptr, size_t size) + ATTRIBUTE_NONNULL(1); +int virAllocN(void *ptrptr, size_t size, size_t count) + ATTRIBUTE_NONNULL(1); +int virReallocN(void *ptrptr, size_t size, size_t count) + ATTRIBUTE_NONNULL(1); +int virExpandN(void *ptrptr, size_t size, size_t *count, size_t add) + ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(3); +int virResizeN(void *ptrptr, size_t size, size_t *alloc, size_t count, siz= e_t desired) + ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(3); void virShrinkN(void *ptrptr, size_t size, size_t *count, size_t toremove) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(3); int virInsertElementsN(void *ptrptr, size_t size, size_t at, size_t *count= ptr, size_t add, void *newelem, - bool clearOriginal, bool inPlace, bool report, int = domcode, - const char *filename, const char *funcname, size_t = linenr) + bool clearOriginal, bool inPlace) ATTRIBUTE_RETURN_CHECK ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(4); int virDeleteElementsN(void *ptrptr, size_t size, size_t at, size_t *count= ptr, size_t toremove, bool inPlace) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(4); -int virAllocVar(void *ptrptr, size_t struct_size, size_t element_size, siz= e_t count, - bool report, int domcode, const char *filename, - const char *funcname, size_t linenr) - ATTRIBUTE_RETURN_CHECK ATTRIBUTE_NONNULL(1); +int virAllocVar(void *ptrptr, size_t struct_size, size_t element_size, siz= e_t count) + ATTRIBUTE_NONNULL(1); void virFree(void *ptrptr) ATTRIBUTE_NONNULL(1); =20 void virDispose(void *ptrptr, size_t count, size_t element_size, size_t *c= ountptr) @@ -91,10 +82,9 @@ void virDisposeString(char **strptr) * * This macro is safe to use on arguments with side effects. * - * Returns -1 on failure (with OOM error reported), 0 on success + * Returns 0 on success, aborts on OOM */ -#define VIR_ALLOC(ptr) virAlloc(&(ptr), sizeof(*(ptr)), true, VIR_FROM_THI= S, \ - __FILE__, __FUNCTION__, __LINE__) +#define VIR_ALLOC(ptr) virAlloc(&(ptr), sizeof(*(ptr))) =20 /** * VIR_ALLOC_QUIET: @@ -106,9 +96,9 @@ void virDisposeString(char **strptr) * * This macro is safe to use on arguments with side effects. * - * Returns -1 on failure, 0 on success + * Returns 0 on success, aborts on OOM */ -#define VIR_ALLOC_QUIET(ptr) virAlloc(&(ptr), sizeof(*(ptr)), false, 0, NU= LL, NULL, 0) +#define VIR_ALLOC_QUIET(ptr) VIR_ALLOC(ptr) =20 /** * VIR_ALLOC_N: @@ -121,10 +111,9 @@ void virDisposeString(char **strptr) * * This macro is safe to use on arguments with side effects. * - * Returns -1 on failure (with OOM error reported), 0 on success + * Returns 0 on success, aborts on OOM */ -#define VIR_ALLOC_N(ptr, count) virAllocN(&(ptr), sizeof(*(ptr)), (count),= true, \ - VIR_FROM_THIS, __FILE__, __FUNCT= ION__, __LINE__) +#define VIR_ALLOC_N(ptr, count) virAllocN(&(ptr), sizeof(*(ptr)), (count)) =20 /** * VIR_ALLOC_N_QUIET: @@ -137,10 +126,9 @@ void virDisposeString(char **strptr) * * This macro is safe to use on arguments with side effects. * - * Returns -1 on failure, 0 on success + * Returns 0 on success, aborts on OOM */ -#define VIR_ALLOC_N_QUIET(ptr, count) virAllocN(&(ptr), sizeof(*(ptr)), (c= ount), \ - false, 0, NULL, NULL, 0) +#define VIR_ALLOC_N_QUIET(ptr, count) VIR_ALLOC_N(ptr, count) =20 /** * VIR_REALLOC_N: @@ -153,11 +141,9 @@ void virDisposeString(char **strptr) * * This macro is safe to use on arguments with side effects. * - * Returns -1 on failure (with OOM error reported), 0 on success + * Returns 0 on success, aborts on OOM */ -#define VIR_REALLOC_N(ptr, count) virReallocN(&(ptr), sizeof(*(ptr)), (cou= nt), \ - true, VIR_FROM_THIS, __FILE_= _, \ - __FUNCTION__, __LINE__) +#define VIR_REALLOC_N(ptr, count) virReallocN(&(ptr), sizeof(*(ptr)), (cou= nt)) =20 /** * VIR_REALLOC_N_QUIET: @@ -170,10 +156,9 @@ void virDisposeString(char **strptr) * * This macro is safe to use on arguments with side effects. * - * Returns -1 on failure, 0 on success + * Returns 0 on success, aborts on OOM */ -#define VIR_REALLOC_N_QUIET(ptr, count) virReallocN(&(ptr), sizeof(*(ptr))= , (count), \ - false, 0, NULL, NULL, = 0) +#define VIR_REALLOC_N_QUIET(ptr, count) VIR_REALLOC_N(ptr, count) =20 /** * VIR_EXPAND_N: @@ -188,11 +173,9 @@ void virDisposeString(char **strptr) * * This macro is safe to use on arguments with side effects. * - * Returns -1 on failure (with OOM error reported), 0 on success + * Returns 0 on success, aborts on OOM */ -#define VIR_EXPAND_N(ptr, count, add) \ - virExpandN(&(ptr), sizeof(*(ptr)), &(count), add, true, VIR_FROM_THIS,= \ - __FILE__, __FUNCTION__, __LINE__) +#define VIR_EXPAND_N(ptr, count, add) virExpandN(&(ptr), sizeof(*(ptr)), &= (count), add) =20 /** * VIR_EXPAND_N_QUIET: @@ -207,10 +190,9 @@ void virDisposeString(char **strptr) * * This macro is safe to use on arguments with side effects. * - * Returns -1 on failure, 0 on success + * Returns 0 on success, aborts on OOM */ -#define VIR_EXPAND_N_QUIET(ptr, count, add) \ - virExpandN(&(ptr), sizeof(*(ptr)), &(count), add, false, 0, NULL, NULL= , 0) +#define VIR_EXPAND_N_QUIET(ptr, count, add) VIR_EXPAND_N(ptr, count, add) =20 /** * VIR_RESIZE_N: @@ -232,11 +214,10 @@ void virDisposeString(char **strptr) * * This macro is safe to use on arguments with side effects. * - * Returns -1 on failure (with OOM error reported), 0 on success + * Returns 0 on success, aborts on OOM */ #define VIR_RESIZE_N(ptr, alloc, count, add) \ - virResizeN(&(ptr), sizeof(*(ptr)), &(alloc), count, add, true, \ - VIR_FROM_THIS, __FILE__, __FUNCTION__, __LINE__) + virResizeN(&(ptr), sizeof(*(ptr)), &(alloc), count, add) =20 /** * VIR_RESIZE_N_QUIET: @@ -258,11 +239,9 @@ void virDisposeString(char **strptr) * * This macro is safe to use on arguments with side effects. * - * Returns -1 on failure, 0 on success + * Returns 0 on success, aborts on OOM */ -#define VIR_RESIZE_N_QUIET(ptr, alloc, count, add) \ - virResizeN(&(ptr), sizeof(*(ptr)), &(alloc), count, add, \ - false, 0, NULL, NULL, 0) +#define VIR_RESIZE_N_QUIET(ptr, alloc, count, add) VIR_RESIZE_N(ptr, alloc= , count, add) =20 /** * VIR_SHRINK_N: @@ -359,38 +338,26 @@ void virDisposeString(char **strptr) */ #define VIR_INSERT_ELEMENT(ptr, at, count, newelem) \ virInsertElementsN(&(ptr), sizeof(*(ptr)), at, &(count), \ - VIR_TYPEMATCH(ptr, &(newelem)), &(newelem), true, f= alse, \ - true, VIR_FROM_THIS, __FILE__, __FUNCTION__, __LINE= __) + VIR_TYPEMATCH(ptr, &(newelem)), &(newelem), true, f= alse) #define VIR_INSERT_ELEMENT_COPY(ptr, at, count, newelem) \ virInsertElementsN(&(ptr), sizeof(*(ptr)), at, &(count), \ - VIR_TYPEMATCH(ptr, &(newelem)), &(newelem), false, = false, \ - true, VIR_FROM_THIS, __FILE__, __FUNCTION__, __LINE= __) + VIR_TYPEMATCH(ptr, &(newelem)), &(newelem), false, = false) #define VIR_INSERT_ELEMENT_INPLACE(ptr, at, count, newelem) \ virInsertElementsN(&(ptr), sizeof(*(ptr)), at, &(count), \ - VIR_TYPEMATCH(ptr, &(newelem)), &(newelem), true, t= rue, \ - true, VIR_FROM_THIS, __FILE__, __FUNCTION__, __LINE= __) + VIR_TYPEMATCH(ptr, &(newelem)), &(newelem), true, t= rue) #define VIR_INSERT_ELEMENT_COPY_INPLACE(ptr, at, count, newelem) \ virInsertElementsN(&(ptr), sizeof(*(ptr)), at, &(count), \ - VIR_TYPEMATCH(ptr, &(newelem)), &(newelem), false, = true, \ - true, VIR_FROM_THIS, __FILE__, __FUNCTION__, __LINE= __) + VIR_TYPEMATCH(ptr, &(newelem)), &(newelem), false, = true) =20 /* Quiet version of macros above */ #define VIR_INSERT_ELEMENT_QUIET(ptr, at, count, newelem) \ - virInsertElementsN(&(ptr), sizeof(*(ptr)), at, &(count), \ - VIR_TYPEMATCH(ptr, &(newelem)), &(newelem), true, f= alse, \ - false, 0, NULL, NULL, 0) + VIR_INSERT_ELEMENT(ptr, at, count, newelem) #define VIR_INSERT_ELEMENT_COPY_QUIET(ptr, at, count, newelem) \ - virInsertElementsN(&(ptr), sizeof(*(ptr)), at, &(count), \ - VIR_TYPEMATCH(ptr, &(newelem)), &(newelem), false, = false, \ - false, 0, NULL, NULL, 0) + VIR_INSERT_ELEMENT_COPY(ptr, at, count, newelem) #define VIR_INSERT_ELEMENT_INPLACE_QUIET(ptr, at, count, newelem) \ - virInsertElementsN(&(ptr), sizeof(*(ptr)), at, &(count), \ - VIR_TYPEMATCH(ptr, &(newelem)), &(newelem), true, t= rue, \ - false, 0, NULL, NULL, 0) + VIR_INSERT_ELEMENT_INPLACE(ptr, at, count, newelem) #define VIR_INSERT_ELEMENT_COPY_INPLACE_QUIET(ptr, at, count, newelem) \ - virInsertElementsN(&(ptr), sizeof(*(ptr)), at, &(count), \ - VIR_TYPEMATCH(ptr, &(newelem)), &(newelem), false, = true, \ - false, 0, NULL, NULL, 0) + VIR_INSERT_ELEMENT_COPY_INPLACE(ptr, at, count, newelem) =20 /** * VIR_APPEND_ELEMENT: @@ -429,34 +396,24 @@ void virDisposeString(char **strptr) */ #define VIR_APPEND_ELEMENT(ptr, count, newelem) \ virInsertElementsN(&(ptr), sizeof(*(ptr)), -1, &(count), \ - VIR_TYPEMATCH(ptr, &(newelem)), &(newelem), true, f= alse, \ - true, VIR_FROM_THIS, __FILE__, __FUNCTION__, __LINE= __) + VIR_TYPEMATCH(ptr, &(newelem)), &(newelem), true, f= alse) #define VIR_APPEND_ELEMENT_COPY(ptr, count, newelem) \ virInsertElementsN(&(ptr), sizeof(*(ptr)), -1, &(count), \ - VIR_TYPEMATCH(ptr, &(newelem)), &(newelem), false, = false, \ - true, VIR_FROM_THIS, __FILE__, __FUNCTION__, __LINE= __) + VIR_TYPEMATCH(ptr, &(newelem)), &(newelem), false, = false) #define VIR_APPEND_ELEMENT_INPLACE(ptr, count, newelem) \ ignore_value(virInsertElementsN(&(ptr), sizeof(*(ptr)), -1, &(count), \ VIR_TYPEMATCH(ptr, &(newelem)), \ - &(newelem), true, true, false, \ - VIR_FROM_THIS, __FILE__, \ - __FUNCTION__, __LINE__)) + &(newelem), true, true)) #define VIR_APPEND_ELEMENT_COPY_INPLACE(ptr, count, newelem) \ ignore_value(virInsertElementsN(&(ptr), sizeof(*(ptr)), -1, &(count), \ VIR_TYPEMATCH(ptr, &(newelem)), \ - &(newelem), false, true, false, \ - VIR_FROM_THIS, __FILE__, \ - __FUNCTION__, __LINE__)) + &(newelem), false, true)) =20 /* Quiet version of macros above */ #define VIR_APPEND_ELEMENT_QUIET(ptr, count, newelem) \ - virInsertElementsN(&(ptr), sizeof(*(ptr)), -1, &(count), \ - VIR_TYPEMATCH(ptr, &(newelem)), &(newelem), true, f= alse, \ - false, 0, NULL, NULL, 0) + VIR_APPEND_ELEMENT(ptr, count, newelem) #define VIR_APPEND_ELEMENT_COPY_QUIET(ptr, count, newelem) \ - virInsertElementsN(&(ptr), sizeof(*(ptr)), -1, &(count), \ - VIR_TYPEMATCH(ptr, &(newelem)), &(newelem), false, = false, \ - false, 0, NULL, NULL, 0) + VIR_APPEND_ELEMENT_COPY(ptr, count, newelem) =20 /** * VIR_DELETE_ELEMENT: @@ -510,11 +467,10 @@ void virDisposeString(char **strptr) * * This macro is safe to use on arguments with side effects. * - * Returns -1 on failure (with OOM error reported), 0 on success + * Returns 0 on success, aborts on OOM */ #define VIR_ALLOC_VAR(ptr, type, count) \ - virAllocVar(&(ptr), sizeof(*(ptr)), sizeof(type), (count), true, \ - VIR_FROM_THIS, __FILE__, __FUNCTION__, __LINE__) + virAllocVar(&(ptr), sizeof(*(ptr)), sizeof(type), (count)) =20 /** * VIR_ALLOC_VAR_QUIET: @@ -535,8 +491,7 @@ void virDisposeString(char **strptr) * * Returns -1 on failure, 0 on success */ -#define VIR_ALLOC_VAR_QUIET(ptr, type, count) \ - virAllocVar(&(ptr), sizeof(*(ptr)), sizeof(type), (count), false, 0, N= ULL, NULL, 0) +#define VIR_ALLOC_VAR_QUIET(ptr, type, count) VIR_ALLOC_VAR(ptr, type, cou= nt) =20 /** * VIR_FREE: --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon Apr 29 23:41:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1567101785; cv=none; d=zoho.com; s=zohoarc; b=Z/4BPmASIVLI0h4JAch22BN540cClDUivROKZ/mzLquTXimzlzw9QUmSwiuvCIaMTsFiVa44/6Hu4vbwGfgPREQ18TAIpc2pddkNrlPORGkpeJXwLJcfVFNIZ78Ao1FexjBy3orbGGEAMLXYCOdfHvyT5/fT6oizoveA7FvhdU0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1567101785; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=LSyhk5qjxBW1l46dvul24+Befli8k+tHXoxqN+EuWrk=; b=Za/jtCq13WR0oajNBJ0/R0Hj7ibIYGKc9gSt651T+MWT59zXiCuZzv1NkecX+7kkO5b+kUWxNMWTeU9bhyGk6fezuuzwFCrlgEiWDr/ZlwTfFB8DDmeWIg3DjRIIsbSaNK0CUhUcf2YDQdLB4nQzn+imMnE3hkSqRVhnV3iprPM= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1567101785610516.6237673706521; Thu, 29 Aug 2019 11:03:05 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1F30C30821B2; Thu, 29 Aug 2019 18:03:04 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BA11119C58; Thu, 29 Aug 2019 18:03:03 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 340B4180B536; Thu, 29 Aug 2019 18:03:02 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x7TI30Aa020463 for ; Thu, 29 Aug 2019 14:03:00 -0400 Received: by smtp.corp.redhat.com (Postfix) id 6C6AE60605; Thu, 29 Aug 2019 18:03:00 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-112-60.ams2.redhat.com [10.36.112.60]) by smtp.corp.redhat.com (Postfix) with ESMTP id 784F36092D; Thu, 29 Aug 2019 18:02:59 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Thu, 29 Aug 2019 19:02:46 +0100 Message-Id: <20190829180250.3290-4-berrange@redhat.com> In-Reply-To: <20190829180250.3290-1-berrange@redhat.com> References: <20190829180250.3290-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 3/7] util: remove several unused _QUIET allocation macro variants X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Thu, 29 Aug 2019 18:03:04 +0000 (UTC) Only a few of the _QUIET allocation macros are used. Since we're no longer reporting OOM as errors, we want to eliminate all the _QUIET variants. This starts with the easy, unused, cases. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: J=C3=A1n Tomko --- src/util/viralloc.h | 74 --------------------------------------------- 1 file changed, 74 deletions(-) diff --git a/src/util/viralloc.h b/src/util/viralloc.h index 1437ad4b29..1d1cc0ba42 100644 --- a/src/util/viralloc.h +++ b/src/util/viralloc.h @@ -177,23 +177,6 @@ void virDisposeString(char **strptr) */ #define VIR_EXPAND_N(ptr, count, add) virExpandN(&(ptr), sizeof(*(ptr)), &= (count), add) =20 -/** - * VIR_EXPAND_N_QUIET: - * @ptr: pointer to hold address of allocated memory - * @count: variable tracking number of elements currently allocated - * @add: number of elements to add - * - * Re-allocate an array of 'count' elements, each sizeof(*ptr) - * bytes long, to be 'count' + 'add' elements long, then store the - * address of allocated memory in 'ptr' and the new size in 'count'. - * The new elements are filled with zero. - * - * This macro is safe to use on arguments with side effects. - * - * Returns 0 on success, aborts on OOM - */ -#define VIR_EXPAND_N_QUIET(ptr, count, add) VIR_EXPAND_N(ptr, count, add) - /** * VIR_RESIZE_N: * @ptr: pointer to hold address of allocated memory @@ -219,30 +202,6 @@ void virDisposeString(char **strptr) #define VIR_RESIZE_N(ptr, alloc, count, add) \ virResizeN(&(ptr), sizeof(*(ptr)), &(alloc), count, add) =20 -/** - * VIR_RESIZE_N_QUIET: - * @ptr: pointer to hold address of allocated memory - * @alloc: variable tracking number of elements currently allocated - * @count: number of elements currently in use - * @add: minimum number of elements to additionally support - * - * Blindly using VIR_EXPAND_N(array, alloc, 1) in a loop scales - * quadratically, because every iteration must copy contents from - * all prior iterations. But amortized linear scaling can be achieved - * by tracking allocation size separately from the number of used - * elements, and growing geometrically only as needed. - * - * If 'count' + 'add' is larger than 'alloc', then geometrically reallocate - * the array of 'alloc' elements, each sizeof(*ptr) bytes long, and store - * the address of allocated memory in 'ptr' and the new size in 'alloc'. - * The new elements are filled with zero. - * - * This macro is safe to use on arguments with side effects. - * - * Returns 0 on success, aborts on OOM - */ -#define VIR_RESIZE_N_QUIET(ptr, alloc, count, add) VIR_RESIZE_N(ptr, alloc= , count, add) - /** * VIR_SHRINK_N: * @ptr: pointer to hold address of allocated memory @@ -349,16 +308,6 @@ void virDisposeString(char **strptr) virInsertElementsN(&(ptr), sizeof(*(ptr)), at, &(count), \ VIR_TYPEMATCH(ptr, &(newelem)), &(newelem), false, = true) =20 -/* Quiet version of macros above */ -#define VIR_INSERT_ELEMENT_QUIET(ptr, at, count, newelem) \ - VIR_INSERT_ELEMENT(ptr, at, count, newelem) -#define VIR_INSERT_ELEMENT_COPY_QUIET(ptr, at, count, newelem) \ - VIR_INSERT_ELEMENT_COPY(ptr, at, count, newelem) -#define VIR_INSERT_ELEMENT_INPLACE_QUIET(ptr, at, count, newelem) \ - VIR_INSERT_ELEMENT_INPLACE(ptr, at, count, newelem) -#define VIR_INSERT_ELEMENT_COPY_INPLACE_QUIET(ptr, at, count, newelem) \ - VIR_INSERT_ELEMENT_COPY_INPLACE(ptr, at, count, newelem) - /** * VIR_APPEND_ELEMENT: * @ptr: pointer to array of objects (*not* ptr to ptr) @@ -412,8 +361,6 @@ void virDisposeString(char **strptr) /* Quiet version of macros above */ #define VIR_APPEND_ELEMENT_QUIET(ptr, count, newelem) \ VIR_APPEND_ELEMENT(ptr, count, newelem) -#define VIR_APPEND_ELEMENT_COPY_QUIET(ptr, count, newelem) \ - VIR_APPEND_ELEMENT_COPY(ptr, count, newelem) =20 /** * VIR_DELETE_ELEMENT: @@ -472,27 +419,6 @@ void virDisposeString(char **strptr) #define VIR_ALLOC_VAR(ptr, type, count) \ virAllocVar(&(ptr), sizeof(*(ptr)), sizeof(type), (count)) =20 -/** - * VIR_ALLOC_VAR_QUIET: - * @ptr: pointer to hold address of allocated memory - * @type: element type of trailing array - * @count: number of array elements to allocate - * - * Allocate sizeof(*ptr) bytes plus an array of 'count' elements, each - * sizeof('type'). This sort of allocation is useful for receiving - * the data of certain ioctls and other APIs which return a struct in - * which the last element is an array of undefined length. The caller - * of this type of API is expected to know the length of the array - * that will be returned and allocate a suitable buffer to contain the - * returned data. C99 refers to these variable length objects as - * structs containing flexible array members. - * - * This macro is safe to use on arguments with side effects. - * - * Returns -1 on failure, 0 on success - */ -#define VIR_ALLOC_VAR_QUIET(ptr, type, count) VIR_ALLOC_VAR(ptr, type, cou= nt) - /** * VIR_FREE: * @ptr: pointer holding address to be freed --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon Apr 29 23:41:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1567101787; cv=none; d=zoho.com; s=zohoarc; b=KSFv6rKKAInD20DEBCejE19vkaHmNnFi8Kzb/gdJBjrBU5DI+N/uLzIz/MtY4V8R3HK4gnCgPpEQJ8mbXFIDsm2t2Lb7foniOcYOnlr1Div4NHx6+ohFgQTtyZp11P/sOl2lbdslp3jS9O4S2XgCg3m6GgatuiyJqYGNE35SAM0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1567101787; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=+SVV76HyBLprJI1/h3cybt9sbqEcj/dnjs5h69cL7I8=; b=Xj7cGy2QswiGY4kbHk9QgoIl6U+aOpQbjduwOYrUAfQP62DpLaW1h/+Yb32andpIHkGuZQHvLKRLEsgDR22VxCbkkGTA0/o9XL5zsK33n+MWXL4rhitxu55SaOlbwDF5gGloBghnMHqK2HAcr3S1+JQXdn9zk10rxU+E2N2bS2Q= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1567101787359163.81484647417005; Thu, 29 Aug 2019 11:03:07 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E3C65875223; Thu, 29 Aug 2019 18:03:05 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B7E216060D; Thu, 29 Aug 2019 18:03:05 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 636E924FDE; Thu, 29 Aug 2019 18:03:05 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x7TI31LX020471 for ; Thu, 29 Aug 2019 14:03:01 -0400 Received: by smtp.corp.redhat.com (Postfix) id A3DD26092D; Thu, 29 Aug 2019 18:03:01 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-112-60.ams2.redhat.com [10.36.112.60]) by smtp.corp.redhat.com (Postfix) with ESMTP id BCD8260605; Thu, 29 Aug 2019 18:03:00 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Thu, 29 Aug 2019 19:02:47 +0100 Message-Id: <20190829180250.3290-5-berrange@redhat.com> In-Reply-To: <20190829180250.3290-1-berrange@redhat.com> References: <20190829180250.3290-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 4/7] util: make string functions abort on OOM X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.68]); Thu, 29 Aug 2019 18:03:06 +0000 (UTC) The functions are left returning an "int" to avoid an immediate big-bang cleanup. They'll simply never return anything other than 0. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: J=C3=A1n Tomko --- src/util/virstring.c | 93 +++++++++++--------------------------------- src/util/virstring.h | 79 +++++++++++++------------------------ 2 files changed, 49 insertions(+), 123 deletions(-) diff --git a/src/util/virstring.c b/src/util/virstring.c index bd269e98fe..2064944b0b 100644 --- a/src/util/virstring.c +++ b/src/util/virstring.c @@ -726,40 +726,27 @@ virDoubleToStr(char **strp, double number) =20 =20 int -virVasprintfInternal(bool report, - int domcode, - const char *filename, - const char *funcname, - size_t linenr, - char **strp, +virVasprintfInternal(char **strp, const char *fmt, va_list list) { int ret; =20 - if ((ret =3D vasprintf(strp, fmt, list)) =3D=3D -1) { - if (report) - virReportOOMErrorFull(domcode, filename, funcname, linenr); - *strp =3D NULL; - } + if ((ret =3D vasprintf(strp, fmt, list)) =3D=3D -1) + abort(); + return ret; } =20 int -virAsprintfInternal(bool report, - int domcode, - const char *filename, - const char *funcname, - size_t linenr, - char **strp, +virAsprintfInternal(char **strp, const char *fmt, ...) { va_list ap; int ret; =20 va_start(ap, fmt); - ret =3D virVasprintfInternal(report, domcode, filename, - funcname, linenr, strp, fmt, ap); + ret =3D virVasprintfInternal(strp, fmt, ap); va_end(ap); return ret; } @@ -937,37 +924,20 @@ virStringIsEmpty(const char *str) * virStrdup: * @dest: where to store duplicated string * @src: the source string to duplicate - * @report: whether to report OOM error, if there is one - * @domcode: error domain code - * @filename: caller's filename - * @funcname: caller's funcname - * @linenr: caller's line number - * - * Wrapper over strdup, which reports OOM error if told so, - * in which case callers wants to pass @domcode, @filename, - * @funcname and @linenr which should represent location in - * caller's body where virStrdup is called from. Consider - * using VIR_STRDUP which sets these automatically. - * - * Returns: 0 for NULL src, 1 on successful copy, -1 otherwise. + * + * Wrapper over strdup, which aborts on OOM error. + * + * Returns: 0 for NULL src, 1 on successful copy, aborts on OOM */ int virStrdup(char **dest, - const char *src, - bool report, - int domcode, - const char *filename, - const char *funcname, - size_t linenr) + const char *src) { *dest =3D NULL; if (!src) return 0; - if (!(*dest =3D strdup(src))) { - if (report) - virReportOOMErrorFull(domcode, filename, funcname, linenr); - return -1; - } + if (!(*dest =3D strdup(src))) + abort(); =20 return 1; } @@ -977,45 +947,28 @@ virStrdup(char **dest, * @dest: where to store duplicated string * @src: the source string to duplicate * @n: how many bytes to copy - * @report: whether to report OOM error, if there is one - * @domcode: error domain code - * @filename: caller's filename - * @funcname: caller's funcname - * @linenr: caller's line number - * - * Wrapper over strndup, which reports OOM error if told so, - * in which case callers wants to pass @domcode, @filename, - * @funcname and @linenr which should represent location in - * caller's body where virStrndup is called from. Consider - * using VIR_STRNDUP which sets these automatically. + * + * Wrapper over strndup, which aborts on OOM error. * * In case @n is smaller than zero, the whole @src string is * copied. * - * Returns: 0 for NULL src, 1 on successful copy, -1 otherwise. + * Returns: 0 for NULL src, 1 on successful copy, aborts on OOM */ int virStrndup(char **dest, const char *src, - ssize_t n, - bool report, - int domcode, - const char *filename, - const char *funcname, - size_t linenr) + ssize_t n) { *dest =3D NULL; if (!src) return 0; if (n < 0) n =3D strlen(src); - if (!(*dest =3D strndup(src, n))) { - if (report) - virReportOOMErrorFull(domcode, filename, funcname, linenr); - return -1; - } + if (!(*dest =3D strndup(src, n))) + abort(); =20 - return 1; + return 1; } =20 =20 @@ -1483,10 +1436,8 @@ virStringEncodeBase64(const uint8_t *buf, size_t buf= len) char *ret; =20 base64_encode_alloc((const char *) buf, buflen, &ret); - if (!ret) { - virReportOOMError(); - return NULL; - } + if (!ret) + abort(); =20 return ret; } diff --git a/src/util/virstring.h b/src/util/virstring.h index 5e64ad1bb9..7d1ae1306b 100644 --- a/src/util/virstring.h +++ b/src/util/virstring.h @@ -128,23 +128,15 @@ int virStrcpy(char *dest, const char *src, size_t des= tbytes) #define virStrcpyStatic(dest, src) virStrcpy((dest), (src), sizeof(dest)) =20 /* Don't call these directly - use the macros below */ -int virStrdup(char **dest, const char *src, bool report, int domcode, - const char *filename, const char *funcname, size_t linenr) - ATTRIBUTE_RETURN_CHECK ATTRIBUTE_NONNULL(1); - -int virStrndup(char **dest, const char *src, ssize_t n, bool report, int d= omcode, - const char *filename, const char *funcname, size_t linenr) - ATTRIBUTE_RETURN_CHECK ATTRIBUTE_NONNULL(1); -int virAsprintfInternal(bool report, int domcode, const char *filename, - const char *funcname, size_t linenr, char **strp, - const char *fmt, ...) - ATTRIBUTE_NONNULL(6) ATTRIBUTE_NONNULL(7) ATTRIBUTE_FMT_PRINTF(7, 8) - ATTRIBUTE_RETURN_CHECK; -int virVasprintfInternal(bool report, int domcode, const char *filename, - const char *funcname, size_t linenr, char **strp, - const char *fmt, va_list list) - ATTRIBUTE_NONNULL(6) ATTRIBUTE_NONNULL(7) ATTRIBUTE_FMT_PRINTF(7, 0) - ATTRIBUTE_RETURN_CHECK; +int virStrdup(char **dest, const char *src) + ATTRIBUTE_NONNULL(1); + +int virStrndup(char **dest, const char *src, ssize_t n) + ATTRIBUTE_NONNULL(1); +int virAsprintfInternal(char **strp, const char *fmt, ...) + ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_FMT_PRINTF(2, 3); +int virVasprintfInternal(char **strp, const char *fmt, va_list list) + ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_FMT_PRINTF(2, 0); =20 /** * VIR_STRDUP: @@ -155,11 +147,9 @@ int virVasprintfInternal(bool report, int domcode, con= st char *filename, * * This macro is safe to use on arguments with side effects. * - * Returns -1 on failure (with OOM error reported), 0 if @src was NULL, - * 1 if @src was copied + * Returns 0 if @src was NULL, 1 if @src was copied, aborts on OOM */ -#define VIR_STRDUP(dst, src) virStrdup(&(dst), src, true, VIR_FROM_THIS, \ - __FILE__, __FUNCTION__, __LINE__) +#define VIR_STRDUP(dst, src) virStrdup(&(dst), src) =20 /** * VIR_STRDUP_QUIET: @@ -170,9 +160,9 @@ int virVasprintfInternal(bool report, int domcode, cons= t char *filename, * * This macro is safe to use on arguments with side effects. * - * Returns -1 on failure, 0 if @src was NULL, 1 if @src was copied + * Returns 0 if @src was NULL, 1 if @src was copied, aborts on OOM */ -#define VIR_STRDUP_QUIET(dst, src) virStrdup(&(dst), src, false, 0, NULL, = NULL, 0) +#define VIR_STRDUP_QUIET(dst, src) VIR_STRDUP(dst, src) =20 /** * VIR_STRNDUP: @@ -187,12 +177,9 @@ int virVasprintfInternal(bool report, int domcode, con= st char *filename, * * This macro is safe to use on arguments with side effects. * - * Returns -1 on failure (with OOM error reported), 0 if @src was NULL, - * 1 if @src was copied + * Returns 0 if @src was NULL, 1 if @src was copied, aborts on OOM */ -#define VIR_STRNDUP(dst, src, n) virStrndup(&(dst), src, n, true, \ - VIR_FROM_THIS, __FILE__, \ - __FUNCTION__, __LINE__) +#define VIR_STRNDUP(dst, src, n) virStrndup(&(dst), src, n) =20 /** * VIR_STRNDUP_QUIET: @@ -208,51 +195,41 @@ int virVasprintfInternal(bool report, int domcode, co= nst char *filename, * * This macro is safe to use on arguments with side effects. * - * Returns -1 on failure, 0 if @src was NULL, 1 if @src was copied + * Returns 0 if @src was NULL, 1 if @src was copied, aborts on OOM */ -#define VIR_STRNDUP_QUIET(dst, src, n) virStrndup(&(dst), src, n, false, \ - 0, NULL, NULL, 0) +#define VIR_STRNDUP_QUIET(dst, src, n) virStrndup(&(dst), src, n) =20 size_t virStringListLength(const char * const *strings); =20 /** * virVasprintf * - * Like glibc's vasprintf but makes sure *strp =3D=3D NULL on failure, in = which - * case the OOM error is reported too. + * Like glibc's vasprintf but aborts on OOM * - * Returns -1 on failure (with OOM error reported), number of bytes printed - * on success. + * Returns number of bytes printed on success, aborts on OOM */ -#define virVasprintf(strp, fmt, list) \ - virVasprintfInternal(true, VIR_FROM_THIS, __FILE__, __FUNCTION__, \ - __LINE__, strp, fmt, list) +#define virVasprintf(strp, fmt, list) virVasprintfInternal(strp, fmt, list) =20 /** * virVasprintfQuiet * - * Like glibc's vasprintf but makes sure *strp =3D=3D NULL on failure. + * Like glibc's vasprintf but aborts on OOM. * - * Returns -1 on failure, number of bytes printed on success. + * Returns number of bytes printed on success, aborts on OOM */ -#define virVasprintfQuiet(strp, fmt, list) \ - virVasprintfInternal(false, 0, NULL, NULL, 0, strp, fmt, list) +#define virVasprintfQuiet(strp, fmt, list) virVasprintf(strp, fmt, list) =20 /** * virAsprintf: * @strp: variable to hold result (char **) * @fmt: printf format * - * Like glibc's asprintf but makes sure *strp =3D=3D NULL on failure, in w= hich case - * the OOM error is reported too. + * Like glibc's asprintf but aborts on OOM. * - * Returns -1 on failure (with OOM error reported), number of bytes printed - * on success. + * Returns number of bytes printed on success, aborts on OOM */ =20 -#define virAsprintf(strp, ...) \ - virAsprintfInternal(true, VIR_FROM_THIS, __FILE__, __FUNCTION__, __LIN= E__, \ - strp, __VA_ARGS__) +#define virAsprintf(strp, ...) virAsprintfInternal(strp, __VA_ARGS__) =20 /** * virAsprintfQuiet: @@ -264,9 +241,7 @@ size_t virStringListLength(const char * const *strings); * Returns -1 on failure, number of bytes printed on success. */ =20 -#define virAsprintfQuiet(strp, ...) \ - virAsprintfInternal(false, 0, NULL, NULL, 0, \ - strp, __VA_ARGS__) +#define virAsprintfQuiet(strp, ...) virAsprintf(strp, __VA_ARGS__) =20 int virStringSortCompare(const void *a, const void *b); int virStringSortRevCompare(const void *a, const void *b); --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon Apr 29 23:41:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1567101789; cv=none; d=zoho.com; s=zohoarc; b=MZl9wPAC6+eLQu1Het2tcRQY0hvAXU8i9K4oox5bHMYGf8sNCJ+Wnh3gSIYfNQWaWykmE0BkJHM/t8yHy15p4spqwzB4cCSsS6QyVDAeii9rQFEi0wWCnFeA9mkULPiGiBLDxiN7EAo+aQ4qE9SmlMOwu1P6cMDhxSbuzTZb1L0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1567101789; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=xcMaUxKmokHVI7NC32pqGLB5qS1YXLMGSUQ8ZsPJWJA=; b=hHbOPgDRJTTMjrRqNk1COOMSxj5/n78utoC90ZP5qzuLblIuFOtWKr7bks4wM9cDXUXLDi54W5PCUuxHBymSFJaScwYFiy5lD0nemIfRMhddw11CRLiVQEhNXnYSFdjWjlCTT8nhTqLSIYDWh8P8L+DiS/peOGu4+eb/725j2Ns= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1567101789873315.08948073328054; Thu, 29 Aug 2019 11:03:09 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7C95E3D966; Thu, 29 Aug 2019 18:03:08 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5559A60C05; Thu, 29 Aug 2019 18:03:08 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 1A3351802220; Thu, 29 Aug 2019 18:03:08 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x7TI33ib020487 for ; Thu, 29 Aug 2019 14:03:03 -0400 Received: by smtp.corp.redhat.com (Postfix) id F28F06092D; Thu, 29 Aug 2019 18:03:02 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-112-60.ams2.redhat.com [10.36.112.60]) by smtp.corp.redhat.com (Postfix) with ESMTP id 14F7560610; Thu, 29 Aug 2019 18:03:01 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Thu, 29 Aug 2019 19:02:48 +0100 Message-Id: <20190829180250.3290-6-berrange@redhat.com> In-Reply-To: <20190829180250.3290-1-berrange@redhat.com> References: <20190829180250.3290-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 5/7] build: probe for glib-2 library in configure X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Thu, 29 Aug 2019 18:03:09 +0000 (UTC) Prepare for linking with glib by probing for it at configure time. Per supported platforms target, the min glib versions on relevant distros are: RHEL-8: 2.56.1 RHEL-7: 2.50.3 Debian (Buster): 2.58.3 Debian (Stretch): 2.50.3 OpenBSD (Ports): 2.58.3 FreeBSD (Ports): 2.56.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.48 is a reasonable target. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: J=C3=A1n Tomko --- configure.ac | 2 ++ libvirt.spec.in | 1 + m4/virt-glib.m4 | 30 ++++++++++++++++++++++++++++++ mingw-libvirt.spec.in | 2 ++ 4 files changed, 35 insertions(+) create mode 100644 m4/virt-glib.m4 diff --git a/configure.ac b/configure.ac index 36e75ac3c0..5036957865 100644 --- a/configure.ac +++ b/configure.ac @@ -317,6 +317,7 @@ LIBVIRT_CHECK_DLOPEN LIBVIRT_CHECK_FIREWALLD LIBVIRT_CHECK_FIREWALLD_ZONE LIBVIRT_CHECK_FUSE +LIBVIRT_CHECK_GLIB LIBVIRT_CHECK_GLUSTER LIBVIRT_CHECK_GNUTLS LIBVIRT_CHECK_HAL @@ -998,6 +999,7 @@ LIBVIRT_RESULT_DLOPEN LIBVIRT_RESULT_FIREWALLD LIBVIRT_RESULT_FIREWALLD_ZONE LIBVIRT_RESULT_FUSE +LIBVIRT_RESULT_GLIB LIBVIRT_RESULT_GLUSTER LIBVIRT_RESULT_GNUTLS LIBVIRT_RESULT_HAL diff --git a/libvirt.spec.in b/libvirt.spec.in index 41c4a142d6..cbd36577a4 100644 --- a/libvirt.spec.in +++ b/libvirt.spec.in @@ -274,6 +274,7 @@ BuildRequires: systemd-units %if %{with_libxl} BuildRequires: xen-devel %endif +BuildRequires: glib2-devel >=3D 2.48 BuildRequires: libxml2-devel BuildRequires: libxslt BuildRequires: readline-devel diff --git a/m4/virt-glib.m4 b/m4/virt-glib.m4 new file mode 100644 index 0000000000..9c7acb7889 --- /dev/null +++ b/m4/virt-glib.m4 @@ -0,0 +1,30 @@ +dnl The glib.so library +dnl +dnl Copyright (C) 2016 Red Hat, Inc. +dnl +dnl This library is free software; you can redistribute it and/or +dnl modify it under the terms of the GNU Lesser General Public +dnl License as published by the Free Software Foundation; either +dnl version 2.1 of the License, or (at your option) any later version. +dnl +dnl This library is distributed in the hope that it will be useful, +dnl but WITHOUT ANY WARRANTY; without even the implied warranty of +dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +dnl Lesser General Public License for more details. +dnl +dnl You should have received a copy of the GNU Lesser General Public +dnl License along with this library. If not, see +dnl . +dnl + +AC_DEFUN([LIBVIRT_ARG_GLIB], [ + LIBVIRT_ARG_WITH([GLIB], [glib-2.0 location], [check]) +]) + +AC_DEFUN([LIBVIRT_CHECK_GLIB],[ + LIBVIRT_CHECK_PKG([GLIB], [gthread-2.0], [2.48.0]) +]) + +AC_DEFUN([LIBVIRT_RESULT_GLIB], [ + LIBVIRT_RESULT_LIB([GLIB]) +]) diff --git a/mingw-libvirt.spec.in b/mingw-libvirt.spec.in index a20c4b7d74..c29f3eeed2 100644 --- a/mingw-libvirt.spec.in +++ b/mingw-libvirt.spec.in @@ -52,6 +52,8 @@ BuildRequires: mingw32-gcc BuildRequires: mingw64-gcc BuildRequires: mingw32-binutils BuildRequires: mingw64-binutils +BuildRequires: mingw32-glib2 >=3D 2.48 +BuildRequires: mingw64-glib2 >=3D 2.48 BuildRequires: mingw32-libgpg-error BuildRequires: mingw64-libgpg-error BuildRequires: mingw32-libgcrypt --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon Apr 29 23:41:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1567101797; cv=none; d=zoho.com; s=zohoarc; b=OtK6U0sTUeE/wgbDvSx8p7PdslORlenv2iF/pUiZ3+EY0H+UvMwsMTWGA6wwinSbrqJjMkFi6BB9yBG2Fmmdwv0W5Semlc4JEHe98BH8IiXfEYUyR6ZS3UoF/QRCQmFQAK+WpB5CVcnaNa7Pgn3i8UcB7LGwe/IXKZ9ew7nSsaI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1567101797; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=6aZpiMAVkD95NOAhqltENdTZR1lnth35hGjIJyRbQIg=; b=m1AidHG+dYt8YlmH57NPGFlmnjp44GPWahK1ZoxXKCsOy6IsGlN6xGgo/h4Xep6MMmy7iTK3+rG72Cmj8uHqSYPuBHhMtHQGgPglkZAmGB9pcey8b+5vtXwuhgMenpixqmrMy18hT565AQXeM6Mj4vpvgu6GUG2X25kP1VnCqGc= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1567101797375671.4395588844146; Thu, 29 Aug 2019 11:03:17 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E0805308FBA0; Thu, 29 Aug 2019 18:03:15 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id AC50A6060D; Thu, 29 Aug 2019 18:03:15 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 60041180BA9A; Thu, 29 Aug 2019 18:03:15 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x7TI34BP020495 for ; Thu, 29 Aug 2019 14:03:04 -0400 Received: by smtp.corp.redhat.com (Postfix) id 21DB860623; Thu, 29 Aug 2019 18:03:04 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-112-60.ams2.redhat.com [10.36.112.60]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4EAD56060D; Thu, 29 Aug 2019 18:03:03 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Thu, 29 Aug 2019 19:02:49 +0100 Message-Id: <20190829180250.3290-7-berrange@redhat.com> In-Reply-To: <20190829180250.3290-1-berrange@redhat.com> References: <20190829180250.3290-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 6/7] build: link to glib library X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Thu, 29 Aug 2019 18:03:16 +0000 (UTC) Add the main glib.h to internal.h so that all common code can use it. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: J=C3=A1n Tomko --- src/Makefile.am | 2 ++ src/internal.h | 1 + src/lxc/Makefile.inc.am | 2 ++ src/remote/Makefile.inc.am | 1 + src/util/Makefile.inc.am | 1 + tests/Makefile.am | 3 ++- tools/Makefile.am | 1 + 7 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Makefile.am b/src/Makefile.am index f5093b9c90..85993309d9 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -34,6 +34,7 @@ AM_CPPFLAGS =3D -I../gnulib/lib \ WARN_CFLAGS +=3D $(STRICT_FRAME_LIMIT_CFLAGS) =20 AM_CFLAGS =3D $(LIBXML_CFLAGS) \ + $(GLIB_CFLAGS) \ $(WARN_CFLAGS) \ $(LOCK_CHECKING_CFLAGS) \ $(WIN32_EXTRA_CFLAGS) \ @@ -560,6 +561,7 @@ libvirt_admin_la_LIBADD +=3D \ $(YAJL_LIBS) \ $(DEVMAPPER_LIBS) \ $(LIBXML_LIBS) \ + $(GLIB_LIBS) \ $(SSH2_LIBS) \ $(SASL_LIBS) \ $(GNUTLS_LIBS) \ diff --git a/src/internal.h b/src/internal.h index adc1e3f496..55aaf937cf 100644 --- a/src/internal.h +++ b/src/internal.h @@ -27,6 +27,7 @@ #include #include #include +#include =20 #if STATIC_ANALYSIS # undef NDEBUG /* Don't let a prior NDEBUG definition cause trouble. */ diff --git a/src/lxc/Makefile.inc.am b/src/lxc/Makefile.inc.am index b4d560702c..0c9618e185 100644 --- a/src/lxc/Makefile.inc.am +++ b/src/lxc/Makefile.inc.am @@ -184,6 +184,7 @@ libvirt_lxc_LDFLAGS =3D \ $(PIE_LDFLAGS) \ $(CAPNG_LIBS) \ $(LIBXML_LIBS) \ + $(GLIB_LIBS) \ $(NULL) libvirt_lxc_LDADD =3D \ libvirt.la \ @@ -200,6 +201,7 @@ libvirt_lxc_CFLAGS =3D \ $(PIE_CFLAGS) \ $(CAPNG_CFLAGS) \ $(LIBXML_CFLAGS) \ + $(GLIB_CFLAGS) \ $(LIBNL_CFLAGS) \ $(FUSE_CFLAGS) \ $(DBUS_CFLAGS) \ diff --git a/src/remote/Makefile.inc.am b/src/remote/Makefile.inc.am index abf04d998a..e05ae64169 100644 --- a/src/remote/Makefile.inc.am +++ b/src/remote/Makefile.inc.am @@ -38,6 +38,7 @@ REMOTE_DAEMON_SOURCES =3D \ =20 REMOTE_DAEMON_CFLAGS =3D \ $(LIBXML_CFLAGS) \ + $(GLIB_CFLAGS) \ $(GNUTLS_CFLAGS) \ $(SASL_CFLAGS) \ $(XDR_CFLAGS) \ diff --git a/src/util/Makefile.inc.am b/src/util/Makefile.inc.am index 46866cf213..73ada1d6a3 100644 --- a/src/util/Makefile.inc.am +++ b/src/util/Makefile.inc.am @@ -288,6 +288,7 @@ libvirt_util_la_LIBADD =3D \ $(DBUS_LIBS) \ $(WIN32_EXTRA_LIBS) \ $(LIBXML_LIBS) \ + $(GLIB_LIBS) \ $(SECDRIVER_LIBS) \ $(NUMACTL_LIBS) \ $(ACL_LIBS) \ diff --git a/tests/Makefile.am b/tests/Makefile.am index a319e386ec..fdc991a97a 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -35,6 +35,7 @@ AM_CFLAGS =3D \ -Dabs_srcdir=3D"\"$(abs_srcdir)\"" \ -Dabs_top_srcdir=3D"\"$(abs_top_srcdir)\"" \ $(LIBXML_CFLAGS) \ + $(GLIB_CFLAGS) \ $(LIBNL_CFLAGS) \ $(GNUTLS_CFLAGS) \ $(SASL_CFLAGS) \ @@ -522,7 +523,7 @@ libxlxml2domconfigtest_LDADD =3D $(libxl_LDADDS) $(LIBX= ML_LIBS) =20 libxlmock_la_SOURCES =3D \ libxlmock.c -libxlmock_la_CFLAGS =3D $(LIBXL_CFLAGS) $(LIBXML_CFLAGS) +libxlmock_la_CFLAGS =3D $(LIBXL_CFLAGS) $(LIBXML_CFLAGS) $(GLIB_CFLAGS) libxlmock_la_LDFLAGS =3D $(MOCKLIBS_LDFLAGS) libxlmock_la_LIBADD =3D $(MOCKLIBS_LIBS) =20 diff --git a/tools/Makefile.am b/tools/Makefile.am index 29fdbfe846..9489cb35db 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -36,6 +36,7 @@ AM_CFLAGS =3D \ $(COVERAGE_CFLAGS) \ $(PIE_CFLAGS) \ $(LIBXML_CFLAGS) \ + $(GLIB_CFLAGS) \ $(NULL) =20 AM_LDFLAGS =3D \ --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon Apr 29 23:41:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1567101792; cv=none; d=zoho.com; s=zohoarc; b=OrCN4UQDi8UgGhmuErT6mDyMQ4to2s8W//wP7P7pxsxVfxq4snpa2o9Dot/ABGAXpXdTxS/ifr/olLTc/LX3CZShl+H5lhek/apH82uS88T1zOriWbiHlFlQwzdZOYvxc+cAsfERbXlcN0ebehtgfnaJo4HfSouzCkvvS/YSrbc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1567101792; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=ZB1mtY2buGHcdytJhLbgJmPUko8Rza+gRmzGFqEKunQ=; b=P+w83DqKKoIKQPfoJtfNmWtel6ea/H4PkelGLrb78TQA4eR+OuFN6Tl5wJmuf8/6CKxMXTKiWdsgTOXkGhKa4lRHrk5fFOWGzGxpzZ88OytPRGNLCB51whDWi1EUVd0bQktDT/30qtTgdG37pnt/FBZSxarRl92jAmM9r1IrT7s= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1567101792256211.3937801522369; Thu, 29 Aug 2019 11:03:12 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B982410F23F2; Thu, 29 Aug 2019 18:03:10 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 853B15D9D3; Thu, 29 Aug 2019 18:03:10 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 2DC5724F36; Thu, 29 Aug 2019 18:03:10 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x7TI35vt020501 for ; Thu, 29 Aug 2019 14:03:05 -0400 Received: by smtp.corp.redhat.com (Postfix) id 705E46060D; Thu, 29 Aug 2019 18:03:05 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-112-60.ams2.redhat.com [10.36.112.60]) by smtp.corp.redhat.com (Postfix) with ESMTP id A1C416061E; Thu, 29 Aug 2019 18:03:04 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Thu, 29 Aug 2019 19:02:50 +0100 Message-Id: <20190829180250.3290-8-berrange@redhat.com> In-Reply-To: <20190829180250.3290-1-berrange@redhat.com> References: <20190829180250.3290-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 7/7] util: use glib allocation functions X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.66]); Thu, 29 Aug 2019 18:03:11 +0000 (UTC) GLib requires that any memory allocated with g_new/g_malloc/etc is free'd by g_free. This means mixing virAlloc with g_free, or g_new with virFree will violate API rules. The easy way to dea with this is to simply make our allocation functions wrappers to the glib functions. Use of our allocation functions can be phased out gradually over time. When doing such conversions, the return values checks can be dropped at the same time. Signed-off-by: Daniel P. Berrang=C3=A9 --- src/util/viralloc.c | 29 ++++++----------------------- 1 file changed, 6 insertions(+), 23 deletions(-) diff --git a/src/util/viralloc.c b/src/util/viralloc.c index b74f657733..b50d989415 100644 --- a/src/util/viralloc.c +++ b/src/util/viralloc.c @@ -45,10 +45,7 @@ VIR_LOG_INIT("util.alloc"); int virAlloc(void *ptrptr, size_t size) { - *(void **)ptrptr =3D calloc(1, size); - if (*(void **)ptrptr =3D=3D NULL) - abort(); - + *(void **)ptrptr =3D g_malloc0(size); return 0; } =20 @@ -69,10 +66,7 @@ int virAllocN(void *ptrptr, size_t size, size_t count) { - *(void**)ptrptr =3D calloc(count, size); - if (*(void**)ptrptr =3D=3D NULL) - abort(); - + *(void**)ptrptr =3D g_malloc0_n(count, size); return 0; } =20 @@ -94,16 +88,7 @@ int virReallocN(void *ptrptr, size_t size, size_t count) { - void *tmp; - - if (xalloc_oversized(count, size)) - abort(); - - tmp =3D realloc(*(void**)ptrptr, size * count); - if (!tmp && ((size * count) !=3D 0)) - abort(); - - *(void**)ptrptr =3D tmp; + *(void **)ptrptr =3D g_realloc_n(*(void**)ptrptr, size, count); return 0; } =20 @@ -341,9 +326,7 @@ int virAllocVar(void *ptrptr, abort(); =20 alloc_size =3D struct_size + (element_size * count); - *(void **)ptrptr =3D calloc(1, alloc_size); - if (*(void **)ptrptr =3D=3D NULL) - abort(); + *(void **)ptrptr =3D g_malloc0(alloc_size); return 0; } =20 @@ -360,7 +343,7 @@ void virFree(void *ptrptr) { int save_errno =3D errno; =20 - free(*(void**)ptrptr); + g_free(*(void**)ptrptr); *(void**)ptrptr =3D NULL; errno =3D save_errno; } @@ -393,7 +376,7 @@ void virDispose(void *ptrptr, if (*(void**)ptrptr && count > 0) memset(*(void **)ptrptr, 0, count * element_size); =20 - free(*(void**)ptrptr); + g_free(*(void**)ptrptr); *(void**)ptrptr =3D NULL; =20 if (countptr) --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list