[libvirt PATCH v2 00/12] Automatic mutex management

V1: https://listman.redhat.com/archives/libvir-list/2021-August/msg00823.html Changes since V1: * Replaced vir_g_auto* macros with redefinitions of g_auto* if compiled with clang (patch 1). * Split up VIR_XPATH_NODE_AUTORESTORE simplification differently (patches 2 and 3). * Added virObjectLockGuard / VIR_WITH_OBJECT_LOCK_GUARD for automatic mutex management of virObjectLockable variables. * Used different set of example cleanups (patches 9 - 12). Regards, Tim Tim Wiederhake (12): glibcompat: Add G_GNUC_UNUSED to g_auto* definitions for clang virxml: Simplify VIR_XPATH_NODE_AUTORESTORE VIR_XPATH_NODE_AUTORESTORE: Require semicolon internal: Add CONCAT macro virthread: Introduce virLockGuard virthread: Introduce VIR_WITH_MUTEX_LOCK_GUARD virobject: Introduce virObjectLockGuard virobject: Introduce VIR_WITH_OBJECT_LOCK_GUARD virChrdevFDStreamCloseCb: Use virLockGuardNew virChrdevFree: Use VIR_WITH_MUTEX_LOCK bhyveAutostartDomain: Use virObjectLockGuard lxcDomainDetachDeviceHostdevUSBLive: Use VIR_WITH_OBJECT_LOCK_GUARD src/bhyve/bhyve_driver.c | 4 +- src/conf/backup_conf.c | 2 +- src/conf/checkpoint_conf.c | 2 +- src/conf/cpu_conf.c | 2 +- src/conf/domain_conf.c | 140 ++++++++++++++--------------- src/conf/interface_conf.c | 8 +- src/conf/netdev_vlan_conf.c | 2 +- src/conf/network_conf.c | 14 +-- src/conf/networkcommon_conf.c | 2 +- src/conf/node_device_conf.c | 42 ++++----- src/conf/numa_conf.c | 6 +- src/conf/snapshot_conf.c | 2 +- src/conf/storage_adapter_conf.c | 2 +- src/conf/storage_conf.c | 4 +- src/conf/storage_encryption_conf.c | 4 +- src/conf/storage_source_conf.c | 2 +- src/conf/virchrdev.c | 12 ++- src/conf/virsavecookie.c | 2 +- src/cpu/cpu_map.c | 4 +- src/cpu/cpu_x86.c | 2 +- src/internal.h | 3 + src/libvirt_private.syms | 4 + src/lxc/lxc_domain.c | 2 +- src/lxc/lxc_driver.c | 6 +- src/qemu/qemu_capabilities.c | 2 +- src/qemu/qemu_domain.c | 8 +- src/qemu/qemu_domainjob.c | 2 +- src/qemu/qemu_migration_cookie.c | 8 +- src/util/glibcompat.h | 19 ++++ src/util/virobject.c | 16 ++++ src/util/virobject.h | 24 +++++ src/util/virthread.c | 26 ++++++ src/util/virthread.h | 30 +++++++ src/util/virxml.h | 4 +- 34 files changed, 265 insertions(+), 147 deletions(-) -- 2.31.1

Workaround for a bug in clang. Clang emits an unused-variable warning if the variable is only accessed on scope exit by a destructor function. Note that gcc does not exhibit this behavior. See https://bugs.llvm.org/show_bug.cgi?id=3888 and https://bugs.llvm.org/show_bug.cgi?id=43482. Signed-off-by: Tim Wiederhake <twiederh@redhat.com> --- src/util/glibcompat.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/util/glibcompat.h b/src/util/glibcompat.h index 697687b967..ea486e32d5 100644 --- a/src/util/glibcompat.h +++ b/src/util/glibcompat.h @@ -86,3 +86,22 @@ char *vir_g_strdup_vprintf(const char *msg, va_list args) #define g_fsync vir_g_fsync void vir_g_source_unref(GSource *src, GMainContext *ctx); + +/* + * Workaround for a bug in clang. Clang emits an unused-variable warning if the + * variable is only accessed on scope exit by a destructor function. See + * https://bugs.llvm.org/show_bug.cgi?id=3888 and + * https://bugs.llvm.org/show_bug.cgi?id=43482. + */ +#if defined(__clang__) +# undef g_autoptr +# define g_autoptr(TypeName) _GLIB_CLEANUP(_GLIB_AUTOPTR_FUNC_NAME(TypeName)) _GLIB_AUTOPTR_TYPENAME(TypeName) G_GNUC_UNUSED +# undef g_autolist +# define g_autolist(TypeName) _GLIB_CLEANUP(_GLIB_AUTOPTR_LIST_FUNC_NAME(TypeName)) _GLIB_AUTOPTR_LIST_TYPENAME(TypeName) G_GNUC_UNUSED +# undef g_autoslist +# define g_autoslist(TypeName) _GLIB_CLEANUP(_GLIB_AUTOPTR_SLIST_FUNC_NAME(TypeName)) _GLIB_AUTOPTR_SLIST_TYPENAME(TypeName) G_GNUC_UNUSED +# undef g_autoqueue +# define g_autoqueue(TypeName) _GLIB_CLEANUP(_GLIB_AUTOPTR_QUEUE_FUNC_NAME(TypeName)) _GLIB_AUTOPTR_QUEUE_TYPENAME(TypeName) G_GNUC_UNUSED +# undef g_auto +# define g_auto(TypeName) _GLIB_CLEANUP(_GLIB_AUTO_FUNC_NAME(TypeName)) TypeName G_GNUC_UNUSED +#endif /* __clang__ */ -- 2.31.1

On Fri, Sep 10, 2021 at 12:45:43PM +0200, Tim Wiederhake wrote:
Workaround for a bug in clang. Clang emits an unused-variable warning if the variable is only accessed on scope exit by a destructor function. Note that gcc does not exhibit this behavior.
See https://bugs.llvm.org/show_bug.cgi?id=3888 and https://bugs.llvm.org/show_bug.cgi?id=43482.
Signed-off-by: Tim Wiederhake <twiederh@redhat.com> --- src/util/glibcompat.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)
diff --git a/src/util/glibcompat.h b/src/util/glibcompat.h index 697687b967..ea486e32d5 100644 --- a/src/util/glibcompat.h +++ b/src/util/glibcompat.h @@ -86,3 +86,22 @@ char *vir_g_strdup_vprintf(const char *msg, va_list args) #define g_fsync vir_g_fsync
void vir_g_source_unref(GSource *src, GMainContext *ctx); + +/* + * Workaround for a bug in clang. Clang emits an unused-variable warning if the + * variable is only accessed on scope exit by a destructor function. See + * https://bugs.llvm.org/show_bug.cgi?id=3888 and + * https://bugs.llvm.org/show_bug.cgi?id=43482. + */ +#if defined(__clang__) +# undef g_autoptr +# define g_autoptr(TypeName) _GLIB_CLEANUP(_GLIB_AUTOPTR_FUNC_NAME(TypeName)) _GLIB_AUTOPTR_TYPENAME(TypeName) G_GNUC_UNUSED +# undef g_autolist +# define g_autolist(TypeName) _GLIB_CLEANUP(_GLIB_AUTOPTR_LIST_FUNC_NAME(TypeName)) _GLIB_AUTOPTR_LIST_TYPENAME(TypeName) G_GNUC_UNUSED +# undef g_autoslist +# define g_autoslist(TypeName) _GLIB_CLEANUP(_GLIB_AUTOPTR_SLIST_FUNC_NAME(TypeName)) _GLIB_AUTOPTR_SLIST_TYPENAME(TypeName) G_GNUC_UNUSED +# undef g_autoqueue +# define g_autoqueue(TypeName) _GLIB_CLEANUP(_GLIB_AUTOPTR_QUEUE_FUNC_NAME(TypeName)) _GLIB_AUTOPTR_QUEUE_TYPENAME(TypeName) G_GNUC_UNUSED +# undef g_auto +# define g_auto(TypeName) _GLIB_CLEANUP(_GLIB_AUTO_FUNC_NAME(TypeName)) TypeName G_GNUC_UNUSED +#endif /* __clang__ */
This patch should not be needed anymore afaik since we addressed the problems that were triggering clang. Regards, Daniel -- |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|

On Fri, 2021-09-10 at 11:53 +0100, Daniel P. Berrangé wrote:
On Fri, Sep 10, 2021 at 12:45:43PM +0200, Tim Wiederhake wrote:
Workaround for a bug in clang. Clang emits an unused-variable warning if the variable is only accessed on scope exit by a destructor function. Note that gcc does not exhibit this behavior.
See https://bugs.llvm.org/show_bug.cgi?id=3888 and https://bugs.llvm.org/show_bug.cgi?id=43482.
Signed-off-by: Tim Wiederhake <twiederh@redhat.com> --- src/util/glibcompat.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)
diff --git a/src/util/glibcompat.h b/src/util/glibcompat.h index 697687b967..ea486e32d5 100644 --- a/src/util/glibcompat.h +++ b/src/util/glibcompat.h @@ -86,3 +86,22 @@ char *vir_g_strdup_vprintf(const char *msg, va_list args) #define g_fsync vir_g_fsync void vir_g_source_unref(GSource *src, GMainContext *ctx); + +/* + * Workaround for a bug in clang. Clang emits an unused-variable warning if the + * variable is only accessed on scope exit by a destructor function. See + * https://bugs.llvm.org/show_bug.cgi?id=3888 and + * https://bugs.llvm.org/show_bug.cgi?id=43482. + */ +#if defined(__clang__) +# undef g_autoptr +# define g_autoptr(TypeName) _GLIB_CLEANUP(_GLIB_AUTOPTR_FUNC_NAME(TypeName)) _GLIB_AUTOPTR_TYPENAME(TypeName) G_GNUC_UNUSED +# undef g_autolist +# define g_autolist(TypeName) _GLIB_CLEANUP(_GLIB_AUTOPTR_LIST_FUNC_NAME(TypeName)) _GLIB_AUTOPTR_LIST_TYPENAME(TypeName) G_GNUC_UNUSED +# undef g_autoslist +# define g_autoslist(TypeName) _GLIB_CLEANUP(_GLIB_AUTOPTR_SLIST_FUNC_NAME(TypeName)) _GLIB_AUTOPTR_SLIST_TYPENAME(TypeName) G_GNUC_UNUSED +# undef g_autoqueue +# define g_autoqueue(TypeName) _GLIB_CLEANUP(_GLIB_AUTOPTR_QUEUE_FUNC_NAME(TypeName)) _GLIB_AUTOPTR_QUEUE_TYPENAME(TypeName) G_GNUC_UNUSED +# undef g_auto +# define g_auto(TypeName) _GLIB_CLEANUP(_GLIB_AUTO_FUNC_NAME(TypeName)) TypeName G_GNUC_UNUSED +#endif /* __clang__ */
This patch should not be needed anymore afaik since we addressed the problems that were triggering clang.
Did you see patches 9 to 12? They introduce more "only used on scope exit" variables that trigger clangs warning otherwise. Regards, Tim

On Fri, Sep 10, 2021 at 02:26:32PM +0200, Tim Wiederhake wrote:
On Fri, 2021-09-10 at 11:53 +0100, Daniel P. Berrangé wrote:
On Fri, Sep 10, 2021 at 12:45:43PM +0200, Tim Wiederhake wrote:
Workaround for a bug in clang. Clang emits an unused-variable warning if the variable is only accessed on scope exit by a destructor function. Note that gcc does not exhibit this behavior.
See https://bugs.llvm.org/show_bug.cgi?id=3888 and https://bugs.llvm.org/show_bug.cgi?id=43482.
Signed-off-by: Tim Wiederhake <twiederh@redhat.com> --- src/util/glibcompat.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)
diff --git a/src/util/glibcompat.h b/src/util/glibcompat.h index 697687b967..ea486e32d5 100644 --- a/src/util/glibcompat.h +++ b/src/util/glibcompat.h @@ -86,3 +86,22 @@ char *vir_g_strdup_vprintf(const char *msg, va_list args) #define g_fsync vir_g_fsync void vir_g_source_unref(GSource *src, GMainContext *ctx); + +/* + * Workaround for a bug in clang. Clang emits an unused-variable warning if the + * variable is only accessed on scope exit by a destructor function. See + * https://bugs.llvm.org/show_bug.cgi?id=3888 and + * https://bugs.llvm.org/show_bug.cgi?id=43482. + */ +#if defined(__clang__) +# undef g_autoptr +# define g_autoptr(TypeName) _GLIB_CLEANUP(_GLIB_AUTOPTR_FUNC_NAME(TypeName)) _GLIB_AUTOPTR_TYPENAME(TypeName) G_GNUC_UNUSED +# undef g_autolist +# define g_autolist(TypeName) _GLIB_CLEANUP(_GLIB_AUTOPTR_LIST_FUNC_NAME(TypeName)) _GLIB_AUTOPTR_LIST_TYPENAME(TypeName) G_GNUC_UNUSED +# undef g_autoslist +# define g_autoslist(TypeName) _GLIB_CLEANUP(_GLIB_AUTOPTR_SLIST_FUNC_NAME(TypeName)) _GLIB_AUTOPTR_SLIST_TYPENAME(TypeName) G_GNUC_UNUSED +# undef g_autoqueue +# define g_autoqueue(TypeName) _GLIB_CLEANUP(_GLIB_AUTOPTR_QUEUE_FUNC_NAME(TypeName)) _GLIB_AUTOPTR_QUEUE_TYPENAME(TypeName) G_GNUC_UNUSED +# undef g_auto +# define g_auto(TypeName) _GLIB_CLEANUP(_GLIB_AUTO_FUNC_NAME(TypeName)) TypeName G_GNUC_UNUSED +#endif /* __clang__ */
This patch should not be needed anymore afaik since we addressed the problems that were triggering clang.
Did you see patches 9 to 12? They introduce more "only used on scope exit" variables that trigger clangs warning otherwise.
Why aren't they following the approach that Peter used to address this though, by adding the G_GNUC_UNUSED annotations to the usage sites ? We should only re-define the g_auto* macros if we have first submitted this change to GLib upstream and they merged it. Regards, Daniel -- |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|

On Fri, 2021-09-10 at 13:33 +0100, Daniel P. Berrangé wrote:
On Fri, Sep 10, 2021 at 02:26:32PM +0200, Tim Wiederhake wrote:
On Fri, 2021-09-10 at 11:53 +0100, Daniel P. Berrangé wrote:
On Fri, Sep 10, 2021 at 12:45:43PM +0200, Tim Wiederhake wrote:
Workaround for a bug in clang. Clang emits an unused-variable warning if the variable is only accessed on scope exit by a destructor function. Note that gcc does not exhibit this behavior.
See https://bugs.llvm.org/show_bug.cgi?id=3888 and https://bugs.llvm.org/show_bug.cgi?id=43482.
Signed-off-by: Tim Wiederhake <twiederh@redhat.com> --- src/util/glibcompat.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)
diff --git a/src/util/glibcompat.h b/src/util/glibcompat.h index 697687b967..ea486e32d5 100644 --- a/src/util/glibcompat.h +++ b/src/util/glibcompat.h @@ -86,3 +86,22 @@ char *vir_g_strdup_vprintf(const char *msg, va_list args) #define g_fsync vir_g_fsync void vir_g_source_unref(GSource *src, GMainContext *ctx); + +/* + * Workaround for a bug in clang. Clang emits an unused-variable warning if the + * variable is only accessed on scope exit by a destructor function. See + * https://bugs.llvm.org/show_bug.cgi?id=3888 and + * https://bugs.llvm.org/show_bug.cgi?id=43482. + */ +#if defined(__clang__) +# undef g_autoptr +# define g_autoptr(TypeName) _GLIB_CLEANUP(_GLIB_AUTOPTR_FUNC_NAME(TypeName)) _GLIB_AUTOPTR_TYPENAME(TypeName) G_GNUC_UNUSED +# undef g_autolist +# define g_autolist(TypeName) _GLIB_CLEANUP(_GLIB_AUTOPTR_LIST_FUNC_NAME(TypeName)) _GLIB_AUTOPTR_LIST_TYPENAME(TypeName) G_GNUC_UNUSED +# undef g_autoslist +# define g_autoslist(TypeName) _GLIB_CLEANUP(_GLIB_AUTOPTR_SLIST_FUNC_NAME(TypeName)) _GLIB_AUTOPTR_SLIST_TYPENAME(TypeName) G_GNUC_UNUSED +# undef g_autoqueue +# define g_autoqueue(TypeName) _GLIB_CLEANUP(_GLIB_AUTOPTR_QUEUE_FUNC_NAME(TypeName)) _GLIB_AUTOPTR_QUEUE_TYPENAME(TypeName) G_GNUC_UNUSED +# undef g_auto +# define g_auto(TypeName) _GLIB_CLEANUP(_GLIB_AUTO_FUNC_NAME(TypeName)) TypeName G_GNUC_UNUSED +#endif /* __clang__ */
This patch should not be needed anymore afaik since we addressed the problems that were triggering clang.
Did you see patches 9 to 12? They introduce more "only used on scope exit" variables that trigger clangs warning otherwise.
Why aren't they following the approach that Peter used to address this though, by adding the G_GNUC_UNUSED annotations to the usage sites ?
Adding G_GNUC_UNUSED at the usage sites (of which there will be a couple hundred), will disable unused variable detection irregardless of used compiler, just to work around a bug in one single compiler. I would rather use "G_GNUC_UNUSED" only for variables / function arguments that actually are unused. The lock guard variables are used, but at the end of the scope rather than during.
We should only re-define the g_auto* macros if we have first submitted this change to GLib upstream and they merged it.
What are your thoughts on macros (#if/#else'd over __clang__ to include G_GNUC_UNUSED as required) like this? #define VIR_LOCK_GUARD_MUTEX(mutex) \ g_autoptr(virLockGuard) G_GNUC_UNUSED lockguard ## __COUNTER__ = virLockGuardNew(mutex); #define VIR_LOCK_GUARD_OBJECT(object) \ g_autoptr(virLockGuard) G_GNUC_UNUSED lockguard ## __COUNTER__ = virObjectLockGuard(object); or: #define VIR_LOCK_GUARD_MUTEX g_autoptr(virLockGuard) G_GNUC_UNUSED VIR_LOCK_GUARD_MUTEX lock1 = virLockGuardNew(mutex); VIR_LOCK_GUARD_MUTEX lock2 = virObjectLockGuard(object); Regards, Tim
Regards, Daniel

On Tue, Sep 14, 2021 at 03:28:12PM +0200, Tim Wiederhake wrote:
Adding G_GNUC_UNUSED at the usage sites (of which there will be a couple hundred), will disable unused variable detection irregardless of used compiler, just to work around a bug in one single compiler.
AFAIK, there is /no/ unused variable detection once you start using g_auto, because there are always auto-inserted calls to the cleanup funcs that cause the variables to be "used". It is simply a bug in clang that it doesn't see this, while gcc does. I don't see ny impact on GCC from adding G_GNUC_UNUSED
I would rather use "G_GNUC_UNUSED" only for variables / function arguments that actually are unused. The lock guard variables are used, but at the end of the scope rather than during.
We should only re-define the g_auto* macros if we have first submitted this change to GLib upstream and they merged it.
What are your thoughts on macros (#if/#else'd over __clang__ to include G_GNUC_UNUSED as required) like this?
#define VIR_LOCK_GUARD_MUTEX(mutex) \ g_autoptr(virLockGuard) G_GNUC_UNUSED lockguard ## __COUNTER__ = virLockGuardNew(mutex); #define VIR_LOCK_GUARD_OBJECT(object) \ g_autoptr(virLockGuard) G_GNUC_UNUSED lockguard ## __COUNTER__ = virObjectLockGuard(object);
or:
#define VIR_LOCK_GUARD_MUTEX g_autoptr(virLockGuard) G_GNUC_UNUSED VIR_LOCK_GUARD_MUTEX lock1 = virLockGuardNew(mutex); VIR_LOCK_GUARD_MUTEX lock2 = virObjectLockGuard(object);
Those are reasonable as workarounds, but ultimately g_auto* still need fixing upstream to add G_GNUC_UNUSED to their definitions. Regards, Daniel -- |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|

On a Friday in 2021, Tim Wiederhake wrote:
Workaround for a bug in clang. Clang emits an unused-variable warning if the variable is only accessed on scope exit by a destructor function. Note that gcc does not exhibit this behavior.
See https://bugs.llvm.org/show_bug.cgi?id=3888 and https://bugs.llvm.org/show_bug.cgi?id=43482.
Signed-off-by: Tim Wiederhake <twiederh@redhat.com> --- src/util/glibcompat.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)
https://listman.redhat.com/archives/libvir-list/2021-August/msg00863.html Jano

On Fri, 2021-09-10 at 14:35 +0200, Ján Tomko wrote:
On a Friday in 2021, Tim Wiederhake wrote:
Workaround for a bug in clang. Clang emits an unused-variable warning if the variable is only accessed on scope exit by a destructor function. Note that gcc does not exhibit this behavior.
See https://bugs.llvm.org/show_bug.cgi?id=3888 and https://bugs.llvm.org/show_bug.cgi?id=43482.
Signed-off-by: Tim Wiederhake <twiederh@redhat.com> --- src/util/glibcompat.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)
https://listman.redhat.com/archives/libvir-list/2021-August/msg00863.html
Jano
From the mail you linked:
It's our usage that is weird here.
I disagree. I believe our usage of `g_auto*` (and in extension, `__attribute__((cleanup))`) is exactly as this feature is meant to be used.
These are not needed since in all cases, the G_GNUC_UNUSED can be used unconditionally for both gcc and CLang in the respective macros.
That would disable unused-variable-checking for other compilers as well, e.g. gcc, robbing us of a valuable diagnostic. Tim

On Tue, Sep 14, 2021 at 03:28:06PM +0200, Tim Wiederhake wrote:
On Fri, 2021-09-10 at 14:35 +0200, Ján Tomko wrote:
On a Friday in 2021, Tim Wiederhake wrote:
Workaround for a bug in clang. Clang emits an unused-variable warning if the variable is only accessed on scope exit by a destructor function. Note that gcc does not exhibit this behavior.
See https://bugs.llvm.org/show_bug.cgi?id=3888 and https://bugs.llvm.org/show_bug.cgi?id=43482.
Signed-off-by: Tim Wiederhake <twiederh@redhat.com> --- src/util/glibcompat.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)
https://listman.redhat.com/archives/libvir-list/2021-August/msg00863.html
Jano
From the mail you linked:
It's our usage that is weird here.
I disagree. I believe our usage of `g_auto*` (and in extension, `__attribute__((cleanup))`) is exactly as this feature is meant to be used.
These are not needed since in all cases, the G_GNUC_UNUSED can be used unconditionally for both gcc and CLang in the respective macros.
That would disable unused-variable-checking for other compilers as well, e.g. gcc, robbing us of a valuable diagnostic.
From GCC's POV, the attribute((cleanup(freefunc))) annotation gets expanded into a set of calls to freefunc(). So any variable declared with a "cleanup" attribute will always appear used to GCC, because of
I don't think G_GNUC_UNUSED impacts GCC warnings at all. these auto inserted calls. $ cat demo.c #include <stdlib.h> static void freeit(void *ptrptr) { void *ptr = *(void **)ptrptr; free(ptr); } void foo(void) { __attribute__((cleanup(freeit))) char *a = malloc(1); __attribute__((unused)) __attribute__((cleanup(freeit))) char *b = malloc(1); __attribute__((unused)) char *c = malloc(1); char *d = malloc(1); char *e = malloc(1); free(d); } $ gcc -c -Wall demo.c demo.c: In function ‘foo’: demo.c:13:9: warning: unused variable ‘b’ [-Wunused-variable] 13 | char *e = malloc(1); | ^ Regards, Daniel -- |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|

Signed-off-by: Tim Wiederhake <twiederh@redhat.com> --- src/util/virxml.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/util/virxml.h b/src/util/virxml.h index 06fb7aebd8..e69fd08ea6 100644 --- a/src/util/virxml.h +++ b/src/util/virxml.h @@ -358,10 +358,8 @@ G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(virXPathContextNodeSave, virXPathContextNodeRes * node pointer is reset to the original value when this macro was used. */ #define VIR_XPATH_NODE_AUTORESTORE(_ctxt) \ - VIR_WARNINGS_NO_UNUSED_VARIABLE \ g_auto(virXPathContextNodeSave) _ctxt ## CtxtSave = { .ctxt = _ctxt,\ - .node = _ctxt->node}; \ - VIR_WARNINGS_RESET + .node = _ctxt->node}; G_DEFINE_AUTOPTR_CLEANUP_FUNC(xmlDoc, xmlFreeDoc); G_DEFINE_AUTOPTR_CLEANUP_FUNC(xmlXPathContext, xmlXPathFreeContext); -- 2.31.1

On a Friday in 2021, Tim Wiederhake wrote:
Signed-off-by: Tim Wiederhake <twiederh@redhat.com> --- src/util/virxml.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/src/util/virxml.h b/src/util/virxml.h index 06fb7aebd8..e69fd08ea6 100644 --- a/src/util/virxml.h +++ b/src/util/virxml.h @@ -358,10 +358,8 @@ G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(virXPathContextNodeSave, virXPathContextNodeRes * node pointer is reset to the original value when this macro was used. */ #define VIR_XPATH_NODE_AUTORESTORE(_ctxt) \ - VIR_WARNINGS_NO_UNUSED_VARIABLE \ g_auto(virXPathContextNodeSave) _ctxt ## CtxtSave = { .ctxt = _ctxt,\ - .node = _ctxt->node}; \ - VIR_WARNINGS_RESET + .node = _ctxt->node};
G_DEFINE_AUTOPTR_CLEANUP_FUNC(xmlDoc, xmlFreeDoc); G_DEFINE_AUTOPTR_CLEANUP_FUNC(xmlXPathContext, xmlXPathFreeContext);
https://listman.redhat.com/archives/libvir-list/2021-August/msg00851.html Jano

On Fri, 2021-09-10 at 14:36 +0200, Ján Tomko wrote:
On a Friday in 2021, Tim Wiederhake wrote:
Signed-off-by: Tim Wiederhake <twiederh@redhat.com> --- src/util/virxml.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/src/util/virxml.h b/src/util/virxml.h index 06fb7aebd8..e69fd08ea6 100644 --- a/src/util/virxml.h +++ b/src/util/virxml.h @@ -358,10 +358,8 @@ G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(virXPathContextNodeSave, virXPathContextNodeRes * node pointer is reset to the original value when this macro was used. */ #define VIR_XPATH_NODE_AUTORESTORE(_ctxt) \ - VIR_WARNINGS_NO_UNUSED_VARIABLE \ g_auto(virXPathContextNodeSave) _ctxt ## CtxtSave = { .ctxt = _ctxt,\ - .node = _ctxt->node}; \ - VIR_WARNINGS_RESET + .node = _ctxt->node};
G_DEFINE_AUTOPTR_CLEANUP_FUNC(xmlDoc, xmlFreeDoc); G_DEFINE_AUTOPTR_CLEANUP_FUNC(xmlXPathContext, xmlXPathFreeContext);
https://listman.redhat.com/archives/libvir-list/2021-August/msg00851.html
Patch #1 adds G_GNUC_UNUSED to g_auto if compiled with clang. This removes the need to disable unused-variable-detection for VIR_XPATH_NODE_AUTORESTORE. Disabling unused-variable-detection unconditionally to work around a bug in one compiler (see llvm bugs 3888 and 43482) does more harm than good I think. Tim

Use of semicolons after VIR_XPATH_NODE_AUTORESTORE was inconsistent. Make it mandatory. Signed-off-by: Tim Wiederhake <twiederh@redhat.com> --- src/conf/backup_conf.c | 2 +- src/conf/checkpoint_conf.c | 2 +- src/conf/cpu_conf.c | 2 +- src/conf/domain_conf.c | 140 ++++++++++++++--------------- src/conf/interface_conf.c | 8 +- src/conf/netdev_vlan_conf.c | 2 +- src/conf/network_conf.c | 14 +-- src/conf/networkcommon_conf.c | 2 +- src/conf/node_device_conf.c | 42 ++++----- src/conf/numa_conf.c | 6 +- src/conf/snapshot_conf.c | 2 +- src/conf/storage_adapter_conf.c | 2 +- src/conf/storage_conf.c | 4 +- src/conf/storage_encryption_conf.c | 4 +- src/conf/storage_source_conf.c | 2 +- src/conf/virsavecookie.c | 2 +- src/cpu/cpu_map.c | 4 +- src/cpu/cpu_x86.c | 2 +- src/lxc/lxc_domain.c | 2 +- src/qemu/qemu_capabilities.c | 2 +- src/qemu/qemu_domain.c | 8 +- src/qemu/qemu_domainjob.c | 2 +- src/qemu/qemu_migration_cookie.c | 8 +- src/util/virxml.h | 2 +- 24 files changed, 133 insertions(+), 133 deletions(-) diff --git a/src/conf/backup_conf.c b/src/conf/backup_conf.c index 694553a544..9c67f5c232 100644 --- a/src/conf/backup_conf.c +++ b/src/conf/backup_conf.c @@ -102,7 +102,7 @@ virDomainBackupDiskDefParseXML(xmlNodePtr node, unsigned int flags, virDomainXMLOption *xmlopt) { - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); g_autofree char *type = NULL; g_autofree char *format = NULL; g_autofree char *idx = NULL; diff --git a/src/conf/checkpoint_conf.c b/src/conf/checkpoint_conf.c index 175a95fed7..aebdc2cb6d 100644 --- a/src/conf/checkpoint_conf.c +++ b/src/conf/checkpoint_conf.c @@ -96,7 +96,7 @@ virDomainCheckpointDiskDefParseXML(xmlNodePtr node, virDomainCheckpointDiskDef *def) { g_autofree char *checkpoint = NULL; - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); ctxt->node = node; diff --git a/src/conf/cpu_conf.c b/src/conf/cpu_conf.c index 1674cd6957..c42083d018 100644 --- a/src/conf/cpu_conf.c +++ b/src/conf/cpu_conf.c @@ -320,7 +320,7 @@ virCPUDefParseXML(xmlXPathContextPtr ctxt, { g_autoptr(virCPUDef) def = NULL; g_autofree xmlNodePtr *nodes = NULL; - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); int n; size_t i; g_autofree char *cpuMode = NULL; diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index cb9e7218ff..f94ac128db 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -1695,7 +1695,7 @@ virDomainBlkioDeviceParseXML(xmlNodePtr root, g_autofree char *write_bytes_sec = NULL; g_autofree char *read_iops_sec = NULL; g_autofree char *write_iops_sec = NULL; - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); ctxt->node = root; @@ -6650,7 +6650,7 @@ virDomainDeviceInfoParseXML(virDomainXMLOption *xmlopt, xmlNodePtr rom = NULL; int ret = -1; g_autofree char *aliasStr = NULL; - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); virDomainDeviceInfoClear(info); ctxt->node = node; @@ -6722,7 +6722,7 @@ virDomainHostdevSubsysUSBDefParseXML(xmlNodePtr node, xmlNodePtr productNode; xmlNodePtr addressNode; virTristateBool autoAddress; - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); ctxt->node = node; @@ -6824,7 +6824,7 @@ virDomainHostdevSubsysPCIDefParseXML(xmlNodePtr node, g_autofree char *filtering = NULL; xmlNodePtr address = NULL; xmlNodePtr origstates = NULL; - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); ctxt->node = node; @@ -6923,7 +6923,7 @@ virDomainStorageNetworkParseHosts(xmlNodePtr node, g_autofree xmlNodePtr *hostnodes = NULL; ssize_t nhostnodes; size_t i; - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); ctxt->node = node; @@ -6968,7 +6968,7 @@ virDomainHostdevSubsysSCSIHostDefParseXML(xmlNodePtr sourcenode, { virDomainHostdevSubsysSCSIHost *scsihostsrc = &scsisrc->u.host; xmlNodePtr addressnode = NULL; - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); ctxt->node = sourcenode; @@ -7020,7 +7020,7 @@ virDomainHostdevSubsysSCSIiSCSIDefParseXML(xmlNodePtr sourcenode, virDomainHostdevSubsysSCSIiSCSI *iscsisrc = &def->u.iscsi; g_autoptr(virStorageAuthDef) authdef = NULL; xmlNodePtr node; - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); ctxt->node = sourcenode; @@ -7510,7 +7510,7 @@ virDomainNetDefCoalesceParseXML(xmlNodePtr node, xmlXPathContextPtr ctxt, virNetDevCoalesce **coalesce) { - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); unsigned long long tmp = 0; g_autofree char *str = NULL; @@ -7881,7 +7881,7 @@ virSecurityLabelDefsParseXML(virDomainDef *def, virDomainXMLOption *xmlopt, unsigned int flags) { - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); size_t i = 0, j; int n; g_autofree xmlNodePtr *list = NULL; @@ -7978,7 +7978,7 @@ virSecurityDeviceLabelDefParseXML(virSecurityDeviceLabelDef ***seclabels_rtn, xmlXPathContextPtr ctxt, unsigned int flags) { - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); virSecurityDeviceLabelDef **seclabels = NULL; size_t nseclabels = 0; int n; @@ -8070,7 +8070,7 @@ virDomainLeaseDefParseXML(xmlNodePtr node, g_autofree char *key = NULL; g_autofree char *path = NULL; xmlNodePtr targetNode = NULL; - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); ctxt->node = node; def = g_new0(virDomainLeaseDef, 1); @@ -8161,7 +8161,7 @@ static virStorageNetCookieDef * virDomainStorageNetCookieParse(xmlNodePtr node, xmlXPathContextPtr ctxt) { - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); g_autoptr(virStorageNetCookieDef) cookie = NULL; ctxt->node = node; @@ -8188,7 +8188,7 @@ virDomainStorageNetCookiesParse(xmlNodePtr node, xmlXPathContextPtr ctxt, virStorageSource *src) { - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); g_autofree xmlNodePtr *nodes = NULL; ssize_t nnodes; size_t i; @@ -8424,7 +8424,7 @@ virDomainDiskSourcePRParse(xmlNodePtr node, xmlXPathContextPtr ctxt, virStoragePRDef **pr) { - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); ctxt->node = node; @@ -8477,7 +8477,7 @@ static virStorageSourceSlice * virDomainStorageSourceParseSlice(xmlNodePtr node, xmlXPathContextPtr ctxt) { - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); g_autofree char *offset = NULL; g_autofree char *size = NULL; g_autofree virStorageSourceSlice *ret = g_new0(virStorageSourceSlice, 1); @@ -8543,7 +8543,7 @@ virDomainStorageSourceParse(xmlNodePtr node, unsigned int flags, virDomainXMLOption *xmlopt) { - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); xmlNodePtr tmp; ctxt->node = node; @@ -8625,7 +8625,7 @@ virDomainDiskBackingStoreParse(xmlXPathContextPtr ctxt, unsigned int flags, virDomainXMLOption *xmlopt) { - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); xmlNodePtr source; g_autoptr(virStorageSource) backingStore = NULL; g_autofree char *type = NULL; @@ -8768,7 +8768,7 @@ virDomainDiskDefMirrorParse(virDomainDiskDef *def, virDomainXMLOption *xmlopt) { xmlNodePtr mirrorNode; - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); g_autofree char *mirrorFormat = NULL; g_autofree char *mirrorType = NULL; g_autofree char *ready = NULL; @@ -8873,7 +8873,7 @@ virDomainDiskDefDriverParseXML(virDomainDiskDef *def, xmlNodePtr cur, xmlXPathContextPtr ctxt) { - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); ctxt->node = cur; @@ -8941,7 +8941,7 @@ virDomainDiskDefDriverSourceParseXML(virStorageSource *src, xmlXPathContextPtr ctxt) { g_autofree char *tmp = NULL; - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); ctxt->node = cur; @@ -8974,7 +8974,7 @@ virDomainDiskDefParsePrivateData(xmlXPathContextPtr ctxt, virDomainXMLOption *xmlopt) { xmlNodePtr private_node = virXPathNode("./privateData", ctxt); - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); if (!xmlopt || !xmlopt->privateData.diskParse || @@ -8997,7 +8997,7 @@ virDomainDiskDefParseSourceXML(virDomainXMLOption *xmlopt, unsigned int flags) { g_autoptr(virStorageSource) src = virStorageSourceNew(); - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); g_autofree char *type = NULL; xmlNodePtr tmp; @@ -9077,7 +9077,7 @@ virDomainDiskDefParseXML(virDomainXMLOption *xmlopt, unsigned int flags) { g_autoptr(virDomainDiskDef) def = NULL; - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); xmlNodePtr sourceNode; xmlNodePtr targetNode; xmlNodePtr geometryNode; @@ -9434,7 +9434,7 @@ virDomainControllerDefParseXML(virDomainXMLOption *xmlopt, int nmodelNodes = 0; int numaNode = -1; int ports; - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); int rc; g_autofree char *idx = NULL; g_autofree char *model = NULL; @@ -9702,7 +9702,7 @@ virDomainFSDefParseXML(virDomainXMLOption *xmlopt, xmlXPathContextPtr ctxt, unsigned int flags) { - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); virDomainFSDef *def; xmlNodePtr driver_node = NULL; xmlNodePtr source_node = NULL; @@ -9962,7 +9962,7 @@ virDomainActualNetDefParseXML(xmlNodePtr node, { virDomainActualNetDef *actual = NULL; int ret = -1; - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); xmlNodePtr bandwidth_node = NULL; xmlNodePtr vlanNode; xmlNodePtr virtPortNode; @@ -10142,7 +10142,7 @@ virDomainChrSourceReconnectDefParseXML(virDomainChrSourceReconnectDef *def, xmlNodePtr node, xmlXPathContextPtr ctxt) { - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); xmlNodePtr cur; ctxt->node = node; @@ -10209,7 +10209,7 @@ virDomainNetDefParseXML(virDomainXMLOption *xmlopt, xmlNodePtr tmpNode; GHashTable *filterparams = NULL; virDomainActualNetDef *actual = NULL; - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); virDomainChrSourceReconnectDef reconnect = {0}; int rv, val; g_autofree char *macaddr = NULL; @@ -11026,7 +11026,7 @@ virDomainChrDefParseTargetXML(virDomainChrDef *def, g_autofree char *targetModel = NULL; g_autofree char *addrStr = NULL; g_autofree char *portStr = NULL; - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); ctxt->node = cur; @@ -11295,7 +11295,7 @@ virDomainChrSourceDefParseXML(virDomainChrSourceDef *def, int nprotocols = 0; g_autofree xmlNodePtr *sources = NULL; int nsources = 0; - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); ctxt->node = cur; @@ -11516,7 +11516,7 @@ virDomainChrDefParseXML(virDomainXMLOption *xmlopt, const char *nodeName; virDomainChrDef *def; g_autofree char *type = NULL; - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); ctxt->node = node; @@ -11593,7 +11593,7 @@ virDomainSmartcardDefParseXML(virDomainXMLOption *xmlopt, g_autofree char *type = NULL; g_autofree xmlNodePtr *certificates = NULL; int n = 0; - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); ctxt->node = node; def = g_new0(virDomainSmartcardDef, 1); @@ -11723,7 +11723,7 @@ virDomainTPMDefParseXML(virDomainXMLOption *xmlopt, unsigned int flags) { virDomainTPMDef *def; - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); int nbackends; g_autofree char *path = NULL; g_autofree char *model = NULL; @@ -11866,7 +11866,7 @@ virDomainInputDefParseXML(virDomainXMLOption *xmlopt, xmlXPathContextPtr ctxt, unsigned int flags) { - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); virDomainInputDef *def; g_autofree char *type = NULL; g_autofree char *bus = NULL; @@ -12091,7 +12091,7 @@ virDomainTimerDefParseXML(xmlNodePtr node, xmlXPathContextPtr ctxt) { virDomainTimerDef *def; - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); xmlNodePtr catchup; int ret; g_autofree char *name = NULL; @@ -12421,7 +12421,7 @@ virDomainGraphicsListensParseXML(virDomainGraphicsDef *def, xmlXPathContextPtr ctxt, unsigned int flags) { - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); virDomainGraphicsListenDef newListen = {0}; int nListens; int ret = -1; @@ -12504,7 +12504,7 @@ virDomainGraphicsDefParseXMLVNC(virDomainGraphicsDef *def, g_autofree char *websocketGenerated = virXMLPropString(node, "websocketGenerated"); g_autofree char *autoport = virXMLPropString(node, "autoport"); xmlNodePtr audioNode; - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); if (virDomainGraphicsListensParseXML(def, node, ctxt, flags) < 0) return -1; @@ -12574,7 +12574,7 @@ virDomainGraphicsDefParseXMLSDL(virDomainGraphicsDef *def, xmlNodePtr node, xmlXPathContextPtr ctxt) { - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); xmlNodePtr glNode; virTristateBool fullscreen; @@ -12671,7 +12671,7 @@ virDomainGraphicsDefParseXMLSpice(virDomainGraphicsDef *def, size_t i = 0; virTristateBool autoport; xmlNodePtr cur; - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); ctxt->node = node; @@ -12828,7 +12828,7 @@ virDomainGraphicsDefParseXMLEGLHeadless(virDomainGraphicsDef *def, xmlNodePtr node, xmlXPathContextPtr ctxt) { - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); xmlNodePtr glNode; ctxt->node = node; @@ -12956,7 +12956,7 @@ virDomainSoundDefParseXML(virDomainXMLOption *xmlopt, unsigned int flags) { virDomainSoundDef *def; - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); xmlNodePtr audioNode; def = g_new0(virDomainSoundDef, 1); @@ -13200,7 +13200,7 @@ virDomainAudioDefParseXML(virDomainXMLOption *xmlopt G_GNUC_UNUSED, xmlXPathContextPtr ctxt) { virDomainAudioDef *def; - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); xmlNodePtr inputNode, outputNode; def = g_new0(virDomainAudioDef, 1); @@ -13388,7 +13388,7 @@ virDomainRNGDefParseXML(virDomainXMLOption *xmlopt, unsigned int flags) { virDomainRNGDef *def; - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); int nbackends; g_autofree xmlNodePtr *backends = NULL; g_autofree char *model = NULL; @@ -13500,7 +13500,7 @@ virDomainMemballoonDefParseXML(virDomainXMLOption *xmlopt, unsigned int flags) { virDomainMemballoonDef *def; - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); xmlNodePtr stats; ctxt->node = node; @@ -13576,7 +13576,7 @@ virDomainShmemDefParseXML(virDomainXMLOption *xmlopt, xmlNodePtr model; xmlNodePtr msi; xmlNodePtr server; - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); ctxt->node = node; @@ -13646,7 +13646,7 @@ virSysinfoBIOSParseXML(xmlNodePtr node, xmlXPathContextPtr ctxt, virSysinfoBIOSDef **bios) { - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); int ret = -1; virSysinfoBIOSDef *def; @@ -13708,7 +13708,7 @@ virSysinfoSystemParseXML(xmlNodePtr node, unsigned char *domUUID, bool uuid_generated) { - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); int ret = -1; virSysinfoSystemDef *def; g_autofree char *tmpUUID = NULL; @@ -13781,7 +13781,7 @@ virSysinfoBaseBoardParseXML(xmlXPathContextPtr ctxt, size_t *nbaseBoard) { size_t i, nboards = 0; - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); int n; g_autofree virSysinfoBaseBoardDef *boards = NULL; g_autofree xmlNodePtr *nodes = NULL; @@ -13830,7 +13830,7 @@ virSysinfoOEMStringsParseXML(xmlNodePtr node, xmlXPathContextPtr ctxt, virSysinfoOEMStringsDef **oem) { - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); int ret = -1; virSysinfoOEMStringsDef *def; int nstrings; @@ -13868,7 +13868,7 @@ virSysinfoChassisParseXML(xmlNodePtr node, xmlXPathContextPtr ctxt, virSysinfoChassisDef **chassisdef) { - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); int ret = -1; virSysinfoChassisDef *def; @@ -13952,7 +13952,7 @@ virSysinfoParseFWCfgDef(virSysinfoDef *def, xmlNodePtr node, xmlXPathContextPtr ctxt) { - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); g_autofree xmlNodePtr *nodes = NULL; int n; size_t i; @@ -14013,7 +14013,7 @@ virSysinfoParseXML(xmlNodePtr node, unsigned char *domUUID, bool uuid_generated) { - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); virSysinfoDef *def; g_autofree char *typeStr = NULL; int type; @@ -14171,7 +14171,7 @@ virDomainVideoDriverDefParseXML(xmlNodePtr node, { g_autofree virDomainVideoDriverDef *def = NULL; xmlNodePtr driver = NULL; - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); ctxt->node = node; @@ -14198,7 +14198,7 @@ virDomainVideoDefParseXML(virDomainXMLOption *xmlopt, xmlNodePtr driver; xmlNodePtr accel_node; xmlNodePtr res_node; - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); g_autofree char *type = NULL; g_autofree char *heads = NULL; g_autofree char *vram = NULL; @@ -14297,7 +14297,7 @@ virDomainHostdevDefParseXML(virDomainXMLOption *xmlopt, unsigned int flags) { virDomainHostdevDef *def; - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); g_autofree char *mode = virXMLPropString(node, "mode"); g_autofree char *type = virXMLPropString(node, "type"); @@ -14521,7 +14521,7 @@ virDomainRedirFilterDefParseXML(xmlNodePtr node, { int n; size_t i; - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); virDomainRedirFilterDef *def = NULL; g_autofree xmlNodePtr *nodes = NULL; @@ -14643,7 +14643,7 @@ virDomainMemorySourceDefParseXML(xmlNodePtr node, xmlXPathContextPtr ctxt, virDomainMemoryDef *def) { - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); g_autofree char *nodemask = NULL; ctxt->node = node; @@ -14697,7 +14697,7 @@ virDomainMemoryTargetDefParseXML(xmlNodePtr node, xmlXPathContextPtr ctxt, virDomainMemoryDef *def) { - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); int rv; ctxt->node = node; @@ -14789,7 +14789,7 @@ static virDomainSecDef * virDomainSecDefParseXML(xmlNodePtr lsecNode, xmlXPathContextPtr ctxt) { - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); g_autoptr(virDomainSecDef) sec = g_new0(virDomainSecDef, 1); ctxt->node = lsecNode; @@ -14825,7 +14825,7 @@ virDomainMemoryDefParseXML(virDomainXMLOption *xmlopt, xmlXPathContextPtr ctxt, unsigned int flags) { - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); xmlNodePtr node; virDomainMemoryDef *def; g_autofree char *tmp = NULL; @@ -14890,7 +14890,7 @@ static virDomainIOMMUDef * virDomainIOMMUDefParseXML(xmlNodePtr node, xmlXPathContextPtr ctxt) { - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); xmlNodePtr driver; g_autofree virDomainIOMMUDef *iommu = NULL; @@ -14934,7 +14934,7 @@ virDomainVsockDefParseXML(virDomainXMLOption *xmlopt, xmlXPathContextPtr ctxt, unsigned int flags) { - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); xmlNodePtr cid; g_autoptr(virDomainVsockDef) vsock = NULL; @@ -16906,7 +16906,7 @@ virDomainIdmapDefParseXML(xmlXPathContextPtr ctxt, { size_t i; virDomainIdMapEntry *idmap = NULL; - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); idmap = g_new0(virDomainIdMapEntry, num); @@ -17249,7 +17249,7 @@ virDomainHugepagesParseXML(xmlNodePtr node, xmlXPathContextPtr ctxt, virDomainHugePage *hugepage) { - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); g_autofree char *nodeset = NULL; ctxt->node = node; @@ -17284,7 +17284,7 @@ static virDomainResourceDef * virDomainResourceDefParse(xmlNodePtr node, xmlXPathContextPtr ctxt) { - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); virDomainResourceDef *def = NULL; char *partition = NULL; char *appid = NULL; @@ -18398,7 +18398,7 @@ virDomainCachetuneDefParseCache(xmlXPathContextPtr ctxt, xmlNodePtr node, virResctrlAlloc *alloc) { - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); unsigned int level; unsigned int cache; virCacheType type; @@ -18509,7 +18509,7 @@ virDomainResctrlMonDefParse(virDomainDef *def, virDomainResctrlDef *resctrl) { virDomainResctrlMonDef *domresmon = NULL; - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); unsigned int level = 0; size_t i = 0; int n = 0; @@ -18636,7 +18636,7 @@ virDomainCachetuneDefParse(virDomainDef *def, xmlNodePtr node, unsigned int flags) { - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); virDomainResctrlDef *resctrl = NULL; ssize_t i = 0; int n; @@ -18964,7 +18964,7 @@ virDomainMemorytuneDefParseMemory(xmlXPathContextPtr ctxt, xmlNodePtr node, virResctrlAlloc *alloc) { - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); unsigned int id; unsigned int bandwidth; @@ -18990,7 +18990,7 @@ virDomainMemorytuneDefParse(virDomainDef *def, xmlNodePtr node, unsigned int flags) { - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); virDomainResctrlDef *resctrl = NULL; virDomainResctrlDef *newresctrl = NULL; g_autoptr(virBitmap) vcpus = NULL; diff --git a/src/conf/interface_conf.c b/src/conf/interface_conf.c index b45dc37379..ccb8cec4dd 100644 --- a/src/conf/interface_conf.c +++ b/src/conf/interface_conf.c @@ -262,7 +262,7 @@ static int virInterfaceDefParseDhcp(virInterfaceProtocolDef *def, xmlNodePtr dhcp, xmlXPathContextPtr ctxt) { - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); char *tmp; int ret = 0; @@ -420,7 +420,7 @@ static int virInterfaceDefParseIfAdressing(virInterfaceDef *def, xmlXPathContextPtr ctxt) { - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); xmlNodePtr *protoNodes = NULL; int nProtoNodes, pp, ret = -1; char *tmp; @@ -544,7 +544,7 @@ virInterfaceDefParseBondItfs(virInterfaceDef *def, xmlXPathContextPtr ctxt) { xmlNodePtr *interfaces = NULL; - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); virInterfaceDef *itf; int nbItf; size_t i; @@ -682,7 +682,7 @@ virInterfaceDefParseXML(xmlXPathContextPtr ctxt, virInterfaceDef *def; int type; char *tmp; - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); xmlNodePtr lnk; diff --git a/src/conf/netdev_vlan_conf.c b/src/conf/netdev_vlan_conf.c index 9d7cc732ba..734a61843f 100644 --- a/src/conf/netdev_vlan_conf.c +++ b/src/conf/netdev_vlan_conf.c @@ -33,7 +33,7 @@ int virNetDevVlanParse(xmlNodePtr node, xmlXPathContextPtr ctxt, virNetDevVlan *def) { int ret = -1; - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); char *trunk = NULL; char *nativeMode = NULL; xmlNodePtr *tagNodes = NULL; diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c index f23599abac..6606331390 100644 --- a/src/conf/network_conf.c +++ b/src/conf/network_conf.c @@ -774,7 +774,7 @@ virNetworkDNSSrvDefParseXML(const char *networkName, bool partialOkay) { int ret; - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); ctxt->node = node; @@ -932,7 +932,7 @@ virNetworkDNSDefParseXML(const char *networkName, g_autofree char *enable = NULL; int nhosts, nsrvs, ntxts, nfwds; size_t i; - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); ctxt->node = node; @@ -1072,7 +1072,7 @@ virNetworkIPDefParseXML(const char *networkName, * On failure clear it out, but don't free it. */ - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); xmlNodePtr dhcp; g_autofree char *address = NULL; g_autofree char *netmask = NULL; @@ -1243,7 +1243,7 @@ virNetworkPortGroupParseXML(virPortGroupDef *def, * On failure clear it out, but don't free it. */ - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); xmlNodePtr virtPortNode; xmlNodePtr vlanNode; xmlNodePtr bandwidth_node; @@ -1312,7 +1312,7 @@ virNetworkForwardNatDefParseXML(const char *networkName, g_autofree xmlNodePtr *natPortNodes = NULL; g_autofree char *addrStart = NULL; g_autofree char *addrEnd = NULL; - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); ctxt->node = node; @@ -1441,7 +1441,7 @@ virNetworkForwardDefParseXML(const char *networkName, g_autofree char *forwardManaged = NULL; g_autofree char *forwardDriverName = NULL; g_autofree char *type = NULL; - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); ctxt->node = node; @@ -1677,7 +1677,7 @@ virNetworkDefParseXML(xmlXPathContextPtr ctxt, xmlNodePtr forwardNode = NULL; g_autofree char *ipv6nogwStr = NULL; g_autofree char *trustGuestRxFilters = NULL; - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); xmlNodePtr bandwidthNode = NULL; xmlNodePtr vlanNode; xmlNodePtr metadataNode = NULL; diff --git a/src/conf/networkcommon_conf.c b/src/conf/networkcommon_conf.c index 2f543ced70..c5e55dff33 100644 --- a/src/conf/networkcommon_conf.c +++ b/src/conf/networkcommon_conf.c @@ -222,7 +222,7 @@ virNetDevIPRouteParseXML(const char *errorDetail, * of an array. On failure clear: it out, but don't free it. */ - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); g_autofree char *family = NULL; g_autofree char *address = NULL; g_autofree char *netmask = NULL; diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c index b4c1acb6a5..642e9cb89f 100644 --- a/src/conf/node_device_conf.c +++ b/src/conf/node_device_conf.c @@ -778,7 +778,7 @@ virNodeDevCapDRMParseXML(xmlXPathContextPtr ctxt, xmlNodePtr node, virNodeDevCapDRM *drm) { - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); int val; g_autofree char *type = NULL; @@ -866,7 +866,7 @@ virNodeDevAPMatrixCapabilityParseXML(xmlXPathContextPtr ctxt, virNodeDevCapAPMatrix *apm_dev) { g_autofree char *type = virXMLPropString(node, "type"); - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); ctxt->node = node; @@ -893,7 +893,7 @@ virNodeDevCSSCapabilityParseXML(xmlXPathContextPtr ctxt, virNodeDevCapCCW *ccw_dev) { g_autofree char *type = virXMLPropString(node, "type"); - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); ctxt->node = node; @@ -920,7 +920,7 @@ virNodeDevCapCCWParseXML(xmlXPathContextPtr ctxt, xmlNodePtr node, virNodeDevCapCCW *ccw_dev) { - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); g_autofree xmlNodePtr *nodes = NULL; int n = 0; size_t i = 0; @@ -1011,7 +1011,7 @@ virNodeDevCapAPCardParseXML(xmlXPathContextPtr ctxt, xmlNodePtr node, virNodeDevCapAPCard *ap_card) { - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); ctxt->node = node; return virNodeDevCapAPAdapterParseXML(ctxt, def, &ap_card->ap_adapter); @@ -1025,7 +1025,7 @@ virNodeDevCapAPQueueParseXML(xmlXPathContextPtr ctxt, virNodeDevCapAPQueue *ap_queue) { int ret = -1; - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); g_autofree char *dom = NULL; ctxt->node = node; @@ -1065,7 +1065,7 @@ virNodeDevCapAPMatrixParseXML(xmlXPathContextPtr ctxt, xmlNodePtr node, virNodeDevCapAPMatrix *ap_matrix) { - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); g_autofree xmlNodePtr *nodes = NULL; int n = 0; size_t i = 0; @@ -1090,7 +1090,7 @@ virNodeDevCapStorageParseXML(xmlXPathContextPtr ctxt, xmlNodePtr node, virNodeDevCapStorage *storage) { - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); g_autofree xmlNodePtr *nodes = NULL; size_t i; int n; @@ -1176,7 +1176,7 @@ virNodeDevCapSCSIParseXML(xmlXPathContextPtr ctxt, xmlNodePtr node, virNodeDevCapSCSI *scsi) { - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); ctxt->node = node; @@ -1216,7 +1216,7 @@ virNodeDevCapSCSITargetParseXML(xmlXPathContextPtr ctxt, xmlNodePtr node, virNodeDevCapSCSITarget *scsi_target) { - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); g_autofree xmlNodePtr *nodes = NULL; int n = 0; size_t i; @@ -1285,7 +1285,7 @@ virNodeDevCapSCSIHostParseXML(xmlXPathContextPtr ctxt, int create, const char *virt_type) { - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); g_autofree xmlNodePtr *nodes = NULL; int n = 0; size_t i; @@ -1378,7 +1378,7 @@ virNodeDevCapNetParseXML(xmlXPathContextPtr ctxt, xmlNodePtr node, virNodeDevCapNet *net) { - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); xmlNodePtr lnk; size_t i = -1; int n = -1; @@ -1449,7 +1449,7 @@ virNodeDevCapUSBInterfaceParseXML(xmlXPathContextPtr ctxt, xmlNodePtr node, virNodeDevCapUSBIf *usb_if) { - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); ctxt->node = node; @@ -1513,7 +1513,7 @@ virNodeDevCapUSBDevParseXML(xmlXPathContextPtr ctxt, xmlNodePtr node, virNodeDevCapUSBDev *usb_dev) { - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); ctxt->node = node; @@ -1553,7 +1553,7 @@ virNodeDevCapPCIDevIommuGroupParseXML(xmlXPathContextPtr ctxt, xmlNodePtr iommuGroupNode, virNodeDevCapPCIDev *pci_dev) { - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); g_autofree xmlNodePtr *addrNodes = NULL; int nAddrNodes; size_t i; @@ -1604,7 +1604,7 @@ virPCIEDeviceInfoParseXML(xmlXPathContextPtr ctxt, xmlNodePtr pciExpressNode, virPCIEDeviceInfo *pci_express) { - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); xmlNodePtr lnk; ctxt->node = pciExpressNode; @@ -1697,7 +1697,7 @@ virNodeDevPCICapabilityParseXML(xmlXPathContextPtr ctxt, virNodeDevCapPCIDev *pci_dev) { g_autofree char *type = virXMLPropString(node, "type"); - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); ctxt->node = node; @@ -1735,7 +1735,7 @@ virNodeDevCapPCIDevParseXML(xmlXPathContextPtr ctxt, xmlNodePtr node, virNodeDevCapPCIDev *pci_dev) { - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); xmlNodePtr iommuGroupNode; xmlNodePtr pciExpress; g_autofree xmlNodePtr *nodes = NULL; @@ -1844,7 +1844,7 @@ virNodeDevCapSystemParseXML(xmlXPathContextPtr ctxt, { virNodeDevCapSystemHardware *hardware = &syscap->hardware; virNodeDevCapSystemFirmware *firmware = &syscap->firmware; - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); g_autofree char *tmp = NULL; ctxt->node = node; @@ -1880,7 +1880,7 @@ virNodeDevCapMdevAttributeParseXML(xmlXPathContextPtr ctxt, xmlNodePtr node, virNodeDevCapMdev *mdev) { - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); g_autoptr(virMediatedDeviceAttr) attr = virMediatedDeviceAttrNew(); ctxt->node = node; @@ -1903,7 +1903,7 @@ virNodeDevCapMdevParseXML(xmlXPathContextPtr ctxt, xmlNodePtr node, virNodeDevCapMdev *mdev) { - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); int nattrs = 0; g_autofree xmlNodePtr *attrs = NULL; size_t i; diff --git a/src/conf/numa_conf.c b/src/conf/numa_conf.c index 9a9b5f4b60..5fb4efb34f 100644 --- a/src/conf/numa_conf.c +++ b/src/conf/numa_conf.c @@ -829,7 +829,7 @@ virDomainNumaDefNodeCacheParseXML(virDomainNuma *def, def->mem_nodes[cur_cell].caches = g_new0(virNumaCache, n); for (i = 0; i < n; i++) { - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); virNumaCache *cache = &def->mem_nodes[cur_cell].caches[i]; g_autofree char *tmp = NULL; unsigned int level; @@ -928,7 +928,7 @@ virDomainNumaDefParseXML(virDomainNuma *def, def->nmem_nodes = n; for (i = 0; i < n; i++) { - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); g_autofree char *tmp = NULL; int rc; unsigned int cur_cell; @@ -1026,7 +1026,7 @@ virDomainNumaDefParseXML(virDomainNuma *def, VIR_XML_PROP_REQUIRED, &value) < 0) return -1; } else if (virXMLNodeNameEqual(interconnect[i], "bandwidth")) { - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); type = VIR_NUMA_INTERCONNECT_TYPE_BANDWIDTH; ctxt->node = interconnect[i]; diff --git a/src/conf/snapshot_conf.c b/src/conf/snapshot_conf.c index fc6f0a859d..e1eab609d7 100644 --- a/src/conf/snapshot_conf.c +++ b/src/conf/snapshot_conf.c @@ -144,7 +144,7 @@ virDomainSnapshotDiskDefParseXML(xmlNodePtr node, char *type = NULL; char *driver = NULL; xmlNodePtr cur; - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); ctxt->node = node; diff --git a/src/conf/storage_adapter_conf.c b/src/conf/storage_adapter_conf.c index 135deeb933..dcc4cf8a55 100644 --- a/src/conf/storage_adapter_conf.c +++ b/src/conf/storage_adapter_conf.c @@ -169,7 +169,7 @@ virStorageAdapterParseXML(virStorageAdapter *adapter, xmlXPathContextPtr ctxt) { int type; - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); ctxt->node = node; diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c index c78456695c..b2fcde531c 100644 --- a/src/conf/storage_conf.c +++ b/src/conf/storage_conf.c @@ -533,7 +533,7 @@ virStoragePoolDefParseSource(xmlXPathContextPtr ctxt, g_autofree char *ver = NULL; g_autofree xmlNodePtr *nodeset = NULL; g_autofree char *sourcedir = NULL; - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); ctxt->node = node; @@ -693,7 +693,7 @@ virStorageDefParsePerms(xmlXPathContextPtr ctxt, { long long val; int ret = -1; - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); xmlNodePtr node; g_autofree char *mode = NULL; diff --git a/src/conf/storage_encryption_conf.c b/src/conf/storage_encryption_conf.c index 9112b96cc7..fabe3334cf 100644 --- a/src/conf/storage_encryption_conf.c +++ b/src/conf/storage_encryption_conf.c @@ -140,7 +140,7 @@ static virStorageEncryptionSecret * virStorageEncryptionSecretParse(xmlXPathContextPtr ctxt, xmlNodePtr node) { - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); virStorageEncryptionSecret *ret; g_autofree char *type_str = NULL; @@ -213,7 +213,7 @@ virStorageEncryption * virStorageEncryptionParseNode(xmlNodePtr node, xmlXPathContextPtr ctxt) { - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); xmlNodePtr *nodes = NULL; virStorageEncryption *encdef = NULL; virStorageEncryption *ret = NULL; diff --git a/src/conf/storage_source_conf.c b/src/conf/storage_source_conf.c index 5ca06fa30a..5e1960cee8 100644 --- a/src/conf/storage_source_conf.c +++ b/src/conf/storage_source_conf.c @@ -234,7 +234,7 @@ virStorageAuthDef * virStorageAuthDefParse(xmlNodePtr node, xmlXPathContextPtr ctxt) { - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); virStorageAuthDef *ret = NULL; xmlNodePtr secretnode = NULL; g_autoptr(virStorageAuthDef) authdef = NULL; diff --git a/src/conf/virsavecookie.c b/src/conf/virsavecookie.c index 6cb7fafb1f..f95b85913e 100644 --- a/src/conf/virsavecookie.c +++ b/src/conf/virsavecookie.c @@ -57,7 +57,7 @@ virSaveCookieParse(xmlXPathContextPtr ctxt, virObject **obj, virSaveCookieCallbacks *saveCookie) { - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); int ret = -1; *obj = NULL; diff --git a/src/cpu/cpu_map.c b/src/cpu/cpu_map.c index 6baaa77776..dd7e99f525 100644 --- a/src/cpu/cpu_map.c +++ b/src/cpu/cpu_map.c @@ -39,7 +39,7 @@ loadData(const char *mapfile, cpuMapLoadCallback callback, void *data) { - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); g_autofree xmlNodePtr *nodes = NULL; int n; size_t i; @@ -113,7 +113,7 @@ loadIncludes(xmlXPathContextPtr ctxt, cpuMapLoadCallback modelCB, void *data) { - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); g_autofree xmlNodePtr *nodes = NULL; int n; size_t i; diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c index 1b829e5658..7a1b54e9d0 100644 --- a/src/cpu/cpu_x86.c +++ b/src/cpu/cpu_x86.c @@ -1509,7 +1509,7 @@ x86ModelParseSignatures(virCPUx86Model *model, xmlXPathContextPtr ctxt) { g_autofree xmlNodePtr *nodes = NULL; - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); size_t i; int n; diff --git a/src/lxc/lxc_domain.c b/src/lxc/lxc_domain.c index 0920e91fd1..33f4066a51 100644 --- a/src/lxc/lxc_domain.c +++ b/src/lxc/lxc_domain.c @@ -210,7 +210,7 @@ lxcDomainDefNamespaceParse(xmlXPathContextPtr ctxt, { lxcDomainDef *lxcDef = NULL; g_autofree xmlNodePtr *nodes = NULL; - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); int n; size_t i; int ret = -1; diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index f27a621f8c..0af9a45d52 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -3751,7 +3751,7 @@ virQEMUCapsLoadHostCPUModelInfo(virQEMUCapsAccel *caps, char *str = NULL; xmlNodePtr hostCPUNode; g_autofree xmlNodePtr *nodes = NULL; - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); g_autoptr(qemuMonitorCPUModelInfo) hostCPU = NULL; g_autofree char *xpath = g_strdup_printf("./hostCPU[@type='%s']", typeStr); int ret = -1; diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 5de7461fb3..bf46fa594f 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -231,7 +231,7 @@ qemuDomainObjPrivateXMLParseJobNBDSource(xmlNodePtr node, virDomainDiskDef *disk, virDomainXMLOption *xmlopt) { - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); qemuDomainDiskPrivate *diskPriv = QEMU_DOMAIN_DISK_PRIVATE(disk); g_autofree char *format = NULL; g_autofree char *type = NULL; @@ -2645,7 +2645,7 @@ qemuDomainObjPrivateXMLParseBlockjobChain(xmlNodePtr node, virDomainXMLOption *xmlopt) { - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); g_autofree char *format = NULL; g_autofree char *type = NULL; g_autofree char *index = NULL; @@ -2845,7 +2845,7 @@ qemuDomainObjPrivateXMLParseBlockjobData(virDomainObj *vm, xmlXPathContextPtr ctxt, virDomainXMLOption *xmlopt) { - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); virDomainDiskDef *disk = NULL; g_autoptr(qemuBlockJobData) job = NULL; g_autofree char *name = NULL; @@ -3027,7 +3027,7 @@ qemuDomainObjPrivateXMLParseSlirpFeatures(xmlNodePtr featuresNode, xmlXPathContextPtr ctxt, qemuSlirp *slirp) { - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); g_autofree xmlNodePtr *nodes = NULL; size_t i; int n; diff --git a/src/qemu/qemu_domainjob.c b/src/qemu/qemu_domainjob.c index 03a8d9ba5f..21d41c552e 100644 --- a/src/qemu/qemu_domainjob.c +++ b/src/qemu/qemu_domainjob.c @@ -1244,7 +1244,7 @@ qemuDomainObjPrivateXMLParseJob(virDomainObj *vm, { qemuDomainObjPrivate *priv = vm->privateData; qemuDomainJobObj *job = &priv->job; - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); g_autofree char *tmp = NULL; if (!(ctxt->node = virXPathNode("./job[1]", ctxt))) diff --git a/src/qemu/qemu_migration_cookie.c b/src/qemu/qemu_migration_cookie.c index c7b010f0a0..add32c634d 100644 --- a/src/qemu/qemu_migration_cookie.c +++ b/src/qemu/qemu_migration_cookie.c @@ -948,7 +948,7 @@ qemuMigrationCookieNetworkXMLParse(xmlXPathContextPtr ctxt) size_t i; int n; g_autofree xmlNodePtr *interfaces = NULL; - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); if ((n = virXPathNodeSet("./network/interface", ctxt, &interfaces)) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -986,7 +986,7 @@ qemuMigrationCookieNBDXMLParse(xmlXPathContextPtr ctxt) size_t i; int n; g_autofree xmlNodePtr *disks = NULL; - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); port = virXPathString("string(./nbd/@port)", ctxt); if (port && virStrToLong_i(port, NULL, 10, &ret->port) < 0) { @@ -1035,7 +1035,7 @@ qemuMigrationCookieStatisticsXMLParse(xmlXPathContextPtr ctxt) { qemuDomainJobInfo *jobInfo = NULL; qemuMonitorMigrationStats *stats; - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); if (!(ctxt->node = virXPathNode("./statistics", ctxt))) return NULL; @@ -1206,7 +1206,7 @@ qemuMigrationCookieBlockDirtyBitmapsParse(xmlXPathContextPtr ctxt, g_autofree xmlNodePtr *disknodes = NULL; int ndisknodes; size_t i; - VIR_XPATH_NODE_AUTORESTORE(ctxt) + VIR_XPATH_NODE_AUTORESTORE(ctxt); if ((ndisknodes = virXPathNodeSet("./blockDirtyBitmaps/disk", ctxt, &disknodes)) < 0) return -1; diff --git a/src/util/virxml.h b/src/util/virxml.h index e69fd08ea6..6fef9ae28c 100644 --- a/src/util/virxml.h +++ b/src/util/virxml.h @@ -359,7 +359,7 @@ G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(virXPathContextNodeSave, virXPathContextNodeRes */ #define VIR_XPATH_NODE_AUTORESTORE(_ctxt) \ g_auto(virXPathContextNodeSave) _ctxt ## CtxtSave = { .ctxt = _ctxt,\ - .node = _ctxt->node}; + .node = _ctxt->node} G_DEFINE_AUTOPTR_CLEANUP_FUNC(xmlDoc, xmlFreeDoc); G_DEFINE_AUTOPTR_CLEANUP_FUNC(xmlXPathContext, xmlXPathFreeContext); -- 2.31.1

Using the two-step idiom to force resolution of other macros, e.g.: #define bar BAR CONCAT_(foo, bar) // foobar CONCAT(foo, bar) // fooBAR Signed-off-by: Tim Wiederhake <twiederh@redhat.com> --- src/internal.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/internal.h b/src/internal.h index e1250a59fe..48188e6fa3 100644 --- a/src/internal.h +++ b/src/internal.h @@ -93,6 +93,9 @@ #define NUL_TERMINATE(buf) do { (buf)[sizeof(buf)-1] = '\0'; } while (0) +#define CONCAT_(a, b) a ## b +#define CONCAT(a, b) CONCAT_(a, b) + #ifdef WIN32 # ifndef O_CLOEXEC # define O_CLOEXEC _O_NOINHERIT -- 2.31.1

Locks a virMutex on creation and unlocks it in its destructor. Typical usage: void function(virMutex *m) { g_autoptr(virLockGuard) lock = virLockGuardNew(m); /* `m` is locked, and released automatically on scope exit */ ... while (expression) { g_autoptr(virLockGuard) lock2 = virLockGuardNew(...); /* similar */ } } Signed-off-by: Tim Wiederhake <twiederh@redhat.com> --- src/libvirt_private.syms | 3 +++ src/util/virthread.c | 26 ++++++++++++++++++++++++++ src/util/virthread.h | 10 ++++++++++ 3 files changed, 39 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 2778fe7f8f..5701ea98a8 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -3370,6 +3370,9 @@ virCondInit; virCondSignal; virCondWait; virCondWaitUntil; +virLockGuardFree; +virLockGuardNew; +virLockGuardUnlock; virMutexDestroy; virMutexInit; virMutexInitRecursive; diff --git a/src/util/virthread.c b/src/util/virthread.c index e89c1a09fb..a5a948985f 100644 --- a/src/util/virthread.c +++ b/src/util/virthread.c @@ -96,6 +96,32 @@ void virMutexUnlock(virMutex *m) pthread_mutex_unlock(&m->lock); } +virLockGuard *virLockGuardNew(virMutex *m) +{ + virLockGuard *l = g_new0(virLockGuard, 1); + l->mutex = m; + + virMutexLock(l->mutex); + return l; +} + +void virLockGuardFree(virLockGuard *l) +{ + if (!l) + return; + + virLockGuardUnlock(l); + g_free(l); +} + +void virLockGuardUnlock(virLockGuard *l) +{ + if (!l) + return; + + virMutexUnlock(g_steal_pointer(&l->mutex)); +} + int virRWLockInit(virRWLock *m) { diff --git a/src/util/virthread.h b/src/util/virthread.h index 55c8263ae6..b394dbd226 100644 --- a/src/util/virthread.h +++ b/src/util/virthread.h @@ -31,6 +31,11 @@ struct virMutex { pthread_mutex_t lock; }; +typedef struct virLockGuard virLockGuard; +struct virLockGuard { + virMutex *mutex; +}; + typedef struct virRWLock virRWLock; struct virRWLock { pthread_rwlock_t lock; @@ -121,6 +126,11 @@ void virMutexLock(virMutex *m); void virMutexUnlock(virMutex *m); +virLockGuard *virLockGuardNew(virMutex *m); +void virLockGuardFree(virLockGuard *l); +void virLockGuardUnlock(virLockGuard *l); +G_DEFINE_AUTOPTR_CLEANUP_FUNC(virLockGuard, virLockGuardFree); + int virRWLockInit(virRWLock *m) G_GNUC_WARN_UNUSED_RESULT; void virRWLockDestroy(virRWLock *m); -- 2.31.1

Modeled after "WITH_QEMU_LOCK_GUARD" (see qemu's include/qemu/lockable.h). Uses "__LINE__" instead of "__COUNTER__", as the latter is a GNU extension. See comment for typical usage. Signed-off-by: Tim Wiederhake <twiederh@redhat.com> --- src/util/virthread.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/util/virthread.h b/src/util/virthread.h index b394dbd226..eaa64fa73e 100644 --- a/src/util/virthread.h +++ b/src/util/virthread.h @@ -209,3 +209,23 @@ int virThreadLocalSet(virThreadLocal *l, void*) G_GNUC_WARN_UNUSED_RESULT; return 0; \ } \ struct classname ## EatSemicolon + +/** + * VIR_WITH_MUTEX_LOCK_GUARD: + * + * This macro defines a lock scope such that entering the scope takes the lock + * and leaving the scope releases the lock. Return statements are allowed + * within the scope and release the lock. Break and continue statements leave + * the scope early and release the lock. + * + * virMutex *mutex = ...; + * + * VIR_WITH_MUTEX_LOCK_GUARD(mutex) { + * // `mutex` is locked, and released automatically on scope exit + * ... + * } + */ +#define VIR_WITH_MUTEX_LOCK_GUARD(m) \ + for (g_autoptr(virLockGuard) CONCAT(var, __LINE__) = virLockGuardNew(m); \ + CONCAT(var, __LINE__); \ + CONCAT(var, __LINE__) = (virLockGuardFree(CONCAT(var, __LINE__)), NULL)) -- 2.31.1

Typical usage: void foobar(virObjectLockable *obj) { g_autoptr(virLockGuard) lock = virObjectLockGuard(obj); /* `obj` is locked, and released automatically on scope exit */ ... } Signed-off-by: Tim Wiederhake <twiederh@redhat.com> --- src/libvirt_private.syms | 1 + src/util/virobject.c | 16 ++++++++++++++++ src/util/virobject.h | 4 ++++ 3 files changed, 21 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 5701ea98a8..e290f62a8a 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2943,6 +2943,7 @@ virObjectListFree; virObjectListFreeCount; virObjectLock; virObjectLockableNew; +virObjectLockGuard; virObjectNew; virObjectRef; virObjectRWLockableNew; diff --git a/src/util/virobject.c b/src/util/virobject.c index 3412985b79..4812b79d56 100644 --- a/src/util/virobject.c +++ b/src/util/virobject.c @@ -426,6 +426,22 @@ virObjectGetRWLockableObj(void *anyobj) } +/** + * virObjectLockGuard: + * @anyobj: any instance of virObjectLockable + * + * Acquire a lock on @anyobj that will be managed by the virLockGuard object + * returned to the caller. + */ +virLockGuard * +virObjectLockGuard(void *anyobj) +{ + virObjectLockable *obj = virObjectGetLockableObj(anyobj); + + return virLockGuardNew(&obj->lock); +} + + /** * virObjectLock: * @anyobj: any instance of virObjectLockable diff --git a/src/util/virobject.h b/src/util/virobject.h index 1e34c77744..0c9cbea726 100644 --- a/src/util/virobject.h +++ b/src/util/virobject.h @@ -118,6 +118,10 @@ void * virObjectRWLockableNew(virClass *klass) ATTRIBUTE_NONNULL(1); +virLockGuard * +virObjectLockGuard(void *lockableobj) + ATTRIBUTE_NONNULL(1); + void virObjectLock(void *lockableobj) ATTRIBUTE_NONNULL(1); -- 2.31.1

Modeled after "WITH_QEMU_LOCK_GUARD" (see qemu's include/qemu/lockable.h). Uses "__LINE__" instead of "__COUNTER__", as the latter is a GNU extension. See comment for typical usage. Signed-off-by: Tim Wiederhake <twiederh@redhat.com> --- src/util/virobject.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/util/virobject.h b/src/util/virobject.h index 0c9cbea726..a95985b69a 100644 --- a/src/util/virobject.h +++ b/src/util/virobject.h @@ -148,3 +148,23 @@ virObjectListFree(void *list); void virObjectListFreeCount(void *list, size_t count); + +/** + * VIR_WITH_OBJECT_LOCK_GUARD: + * + * This macro defines a lock scope such that entering the scope takes the lock + * and leaving the scope releases the lock. Return statements are allowed + * within the scope and release the lock. Break and continue statements leave + * the scope early and release the lock. + * + * virObjectLockable *lockable = ...; + * + * VIR_WITH_OBJECT_LOCK_GUARD(lockable) { + * // `lockable` is locked, and released automatically on scope exit + * ... + * } + */ +#define VIR_WITH_OBJECT_LOCK_GUARD(o) \ + for (g_autoptr(virLockGuard) CONCAT(var, __LINE__) = virObjectLockGuard(o); \ + CONCAT(var, __LINE__); \ + CONCAT(var, __LINE__) = (virLockGuardFree(CONCAT(var, __LINE__)), NULL)) -- 2.31.1

Signed-off-by: Tim Wiederhake <twiederh@redhat.com> --- src/conf/virchrdev.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/conf/virchrdev.c b/src/conf/virchrdev.c index 5d6de68427..fe11e10437 100644 --- a/src/conf/virchrdev.c +++ b/src/conf/virchrdev.c @@ -237,12 +237,10 @@ static void virChrdevFDStreamCloseCb(virStreamPtr st G_GNUC_UNUSED, void *opaque) { virChrdevStreamInfo *priv = opaque; - virMutexLock(&priv->devs->lock); + g_autoptr(virLockGuard) lock = virLockGuardNew(&priv->devs->lock); /* remove entry from hash */ virHashRemoveEntry(priv->devs->hash, priv->path); - - virMutexUnlock(&priv->devs->lock); } /** -- 2.31.1

Signed-off-by: Tim Wiederhake <twiederh@redhat.com> --- src/conf/virchrdev.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/conf/virchrdev.c b/src/conf/virchrdev.c index fe11e10437..58e3c84aad 100644 --- a/src/conf/virchrdev.c +++ b/src/conf/virchrdev.c @@ -291,10 +291,10 @@ void virChrdevFree(virChrdevs *devs) if (!devs) return; - virMutexLock(&devs->lock); - virHashForEachSafe(devs->hash, virChrdevFreeClearCallbacks, NULL); - virHashFree(devs->hash); - virMutexUnlock(&devs->lock); + VIR_WITH_MUTEX_LOCK_GUARD(&devs->lock) { + virHashForEachSafe(devs->hash, virChrdevFreeClearCallbacks, NULL); + virHashFree(devs->hash); + } virMutexDestroy(&devs->lock); g_free(devs); -- 2.31.1

Signed-off-by: Tim Wiederhake <twiederh@redhat.com> --- src/bhyve/bhyve_driver.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c index 516490f6cd..cdd833f896 100644 --- a/src/bhyve/bhyve_driver.c +++ b/src/bhyve/bhyve_driver.c @@ -87,7 +87,8 @@ bhyveAutostartDomain(virDomainObj *vm, void *opaque) { const struct bhyveAutostartData *data = opaque; int ret = 0; - virObjectLock(vm); + g_autoptr(virLockGuard) lock = virObjectLockGuard(vm); + if (vm->autostart && !virDomainObjIsActive(vm)) { virResetLastError(); ret = virBhyveProcessStart(data->conn, vm, @@ -98,7 +99,6 @@ bhyveAutostartDomain(virDomainObj *vm, void *opaque) vm->def->name, virGetLastErrorMessage()); } } - virObjectUnlock(vm); return ret; } -- 2.31.1

Signed-off-by: Tim Wiederhake <twiederh@redhat.com> --- src/lxc/lxc_driver.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index e2720a6f89..528af5d164 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -4079,9 +4079,9 @@ lxcDomainDetachDeviceHostdevUSBLive(virLXCDriver *driver, VIR_WARN("cannot deny device %s for domain %s: %s", dst, vm->def->name, virGetLastErrorMessage()); - virObjectLock(hostdev_mgr->activeUSBHostdevs); - virUSBDeviceListDel(hostdev_mgr->activeUSBHostdevs, usb); - virObjectUnlock(hostdev_mgr->activeUSBHostdevs); + VIR_WITH_OBJECT_LOCK_GUARD(hostdev_mgr->activeUSBHostdevs) { + virUSBDeviceListDel(hostdev_mgr->activeUSBHostdevs, usb); + } virDomainHostdevRemove(vm->def, idx); virDomainHostdevDefFree(def); -- 2.31.1
participants (3)
-
Daniel P. Berrangé
-
Ján Tomko
-
Tim Wiederhake