Create wrapper functions for each nwfilter binding C API that accepts a
virErrorPtr parameter. This avoids accessing a thread local from a
goroutine which may race with other goroutines doing native API calls in
the same OS thread.
Signed-off-by: Daniel P. Berrangé <berrange(a)redhat.com>
---
nwfilter_binding.go | 30 +++++++++++-------
nwfilter_binding_wrapper.go | 63 +++++++++++++++++++++++++++++--------
nwfilter_binding_wrapper.h | 27 ++++++++++------
3 files changed, 85 insertions(+), 35 deletions(-)
diff --git a/nwfilter_binding.go b/nwfilter_binding.go
index 722303b..5999d3e 100644
--- a/nwfilter_binding.go
+++ b/nwfilter_binding.go
@@ -45,9 +45,10 @@ func (f *NWFilterBinding) Free() error {
if C.LIBVIR_VERSION_NUMBER < 4005000 {
return GetNotImplementedError("virNWFilterBindingFree")
}
- ret := C.virNWFilterBindingFreeWrapper(f.ptr)
+ var err C.virError
+ ret := C.virNWFilterBindingFreeWrapper(f.ptr, &err)
if ret == -1 {
- return GetLastError()
+ return makeError(&err)
}
return nil
}
@@ -57,9 +58,10 @@ func (c *NWFilterBinding) Ref() error {
if C.LIBVIR_VERSION_NUMBER < 4005000 {
return GetNotImplementedError("virNWFilterBindingRef")
}
- ret := C.virNWFilterBindingRefWrapper(c.ptr)
+ var err C.virError
+ ret := C.virNWFilterBindingRefWrapper(c.ptr, &err)
if ret == -1 {
- return GetLastError()
+ return makeError(&err)
}
return nil
}
@@ -69,9 +71,10 @@ func (f *NWFilterBinding) Delete() error {
if C.LIBVIR_VERSION_NUMBER < 4005000 {
return GetNotImplementedError("virNWFilterBindingDelete")
}
- result := C.virNWFilterBindingDeleteWrapper(f.ptr)
+ var err C.virError
+ result := C.virNWFilterBindingDeleteWrapper(f.ptr, &err)
if result == -1 {
- return GetLastError()
+ return makeError(&err)
}
return nil
}
@@ -81,9 +84,10 @@ func (f *NWFilterBinding) GetPortDev() (string, error) {
if C.LIBVIR_VERSION_NUMBER < 4005000 {
return "", GetNotImplementedError("virNWFilterBindingGetPortDev")
}
- result := C.virNWFilterBindingGetPortDevWrapper(f.ptr)
+ var err C.virError
+ result := C.virNWFilterBindingGetPortDevWrapper(f.ptr, &err)
if result == nil {
- return "", GetLastError()
+ return "", makeError(&err)
}
name := C.GoString(result)
C.free(unsafe.Pointer(result))
@@ -95,9 +99,10 @@ func (f *NWFilterBinding) GetFilterName() (string, error) {
if C.LIBVIR_VERSION_NUMBER < 4005000 {
return "",
GetNotImplementedError("virNWFilterBindingGetFilterName")
}
- result := C.virNWFilterBindingGetFilterNameWrapper(f.ptr)
+ var err C.virError
+ result := C.virNWFilterBindingGetFilterNameWrapper(f.ptr, &err)
if result == nil {
- return "", GetLastError()
+ return "", makeError(&err)
}
name := C.GoString(result)
C.free(unsafe.Pointer(result))
@@ -109,9 +114,10 @@ func (f *NWFilterBinding) GetXMLDesc(flags uint32) (string, error) {
if C.LIBVIR_VERSION_NUMBER < 4005000 {
return "", GetNotImplementedError("virNWFilterBindingGetXMLDesc")
}
- result := C.virNWFilterBindingGetXMLDescWrapper(f.ptr, C.uint(flags))
+ var err C.virError
+ result := C.virNWFilterBindingGetXMLDescWrapper(f.ptr, C.uint(flags), &err)
if result == nil {
- return "", GetLastError()
+ return "", makeError(&err)
}
xml := C.GoString(result)
C.free(unsafe.Pointer(result))
diff --git a/nwfilter_binding_wrapper.go b/nwfilter_binding_wrapper.go
index fdafaef..b0950b5 100644
--- a/nwfilter_binding_wrapper.go
+++ b/nwfilter_binding_wrapper.go
@@ -30,63 +30,100 @@ package libvirt
#include <assert.h>
#include "nwfilter_binding_wrapper.h"
-const char *virNWFilterBindingGetPortDevWrapper(virNWFilterBindingPtr binding)
+
+int
+virNWFilterBindingDeleteWrapper(virNWFilterBindingPtr binding,
+ virErrorPtr err)
{
#if LIBVIR_VERSION_NUMBER < 4005000
assert(0); // Caller should have checked version
#else
- return virNWFilterBindingGetPortDev(binding);
+ int ret = virNWFilterBindingDelete(binding);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
#endif
}
-const char *virNWFilterBindingGetFilterNameWrapper(virNWFilterBindingPtr binding)
+int
+virNWFilterBindingFreeWrapper(virNWFilterBindingPtr binding,
+ virErrorPtr err)
{
#if LIBVIR_VERSION_NUMBER < 4005000
assert(0); // Caller should have checked version
#else
- return virNWFilterBindingGetFilterName(binding);
+ int ret = virNWFilterBindingFree(binding);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
#endif
}
-char *virNWFilterBindingGetXMLDescWrapper(virNWFilterBindingPtr binding,
- unsigned int flags)
+const char *
+virNWFilterBindingGetFilterNameWrapper(virNWFilterBindingPtr binding,
+ virErrorPtr err)
{
#if LIBVIR_VERSION_NUMBER < 4005000
assert(0); // Caller should have checked version
#else
- return virNWFilterBindingGetXMLDesc(binding, flags);
+ const char * ret = virNWFilterBindingGetFilterName(binding);
+ if (!ret) {
+ virCopyLastError(err);
+ }
+ return ret;
#endif
}
-int virNWFilterBindingDeleteWrapper(virNWFilterBindingPtr binding)
+const char *
+virNWFilterBindingGetPortDevWrapper(virNWFilterBindingPtr binding,
+ virErrorPtr err)
{
#if LIBVIR_VERSION_NUMBER < 4005000
assert(0); // Caller should have checked version
#else
- return virNWFilterBindingDelete(binding);
+ const char * ret = virNWFilterBindingGetPortDev(binding);
+ if (!ret) {
+ virCopyLastError(err);
+ }
+ return ret;
#endif
}
-int virNWFilterBindingRefWrapper(virNWFilterBindingPtr binding)
+char *
+virNWFilterBindingGetXMLDescWrapper(virNWFilterBindingPtr binding,
+ unsigned int flags,
+ virErrorPtr err)
{
#if LIBVIR_VERSION_NUMBER < 4005000
assert(0); // Caller should have checked version
#else
- return virNWFilterBindingRef(binding);
+ char * ret = virNWFilterBindingGetXMLDesc(binding, flags);
+ if (!ret) {
+ virCopyLastError(err);
+ }
+ return ret;
#endif
}
-int virNWFilterBindingFreeWrapper(virNWFilterBindingPtr binding)
+int
+virNWFilterBindingRefWrapper(virNWFilterBindingPtr binding,
+ virErrorPtr err)
{
#if LIBVIR_VERSION_NUMBER < 4005000
assert(0); // Caller should have checked version
#else
- return virNWFilterBindingFree(binding);
+ int ret = virNWFilterBindingRef(binding);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
#endif
}
diff --git a/nwfilter_binding_wrapper.h b/nwfilter_binding_wrapper.h
index 63942be..0bcbfb7 100644
--- a/nwfilter_binding_wrapper.h
+++ b/nwfilter_binding_wrapper.h
@@ -30,24 +30,31 @@
#include <libvirt/virterror.h>
#include "nwfilter_binding_compat.h"
+
+int
+virNWFilterBindingDeleteWrapper(virNWFilterBindingPtr binding,
+ virErrorPtr err);
+
+int
+virNWFilterBindingFreeWrapper(virNWFilterBindingPtr binding,
+ virErrorPtr err);
+
const char *
-virNWFilterBindingGetPortDevWrapper(virNWFilterBindingPtr binding);
+virNWFilterBindingGetFilterNameWrapper(virNWFilterBindingPtr binding,
+ virErrorPtr err);
const char *
-virNWFilterBindingGetFilterNameWrapper(virNWFilterBindingPtr binding);
+virNWFilterBindingGetPortDevWrapper(virNWFilterBindingPtr binding,
+ virErrorPtr err);
char *
virNWFilterBindingGetXMLDescWrapper(virNWFilterBindingPtr binding,
- unsigned int flags);
-
-int
-virNWFilterBindingDeleteWrapper(virNWFilterBindingPtr binding);
-
-int
-virNWFilterBindingRefWrapper(virNWFilterBindingPtr binding);
+ unsigned int flags,
+ virErrorPtr err);
int
-virNWFilterBindingFreeWrapper(virNWFilterBindingPtr binding);
+virNWFilterBindingRefWrapper(virNWFilterBindingPtr binding,
+ virErrorPtr err);
#endif /* LIBVIRT_GO_NWFILTER_BINDING_WRAPPER_H__ */
--
2.17.1