diff --git a/rbd/callback_shims.go b/rbd/callback_shims.go deleted file mode 100644 index ab040e7..0000000 --- a/rbd/callback_shims.go +++ /dev/null @@ -1,13 +0,0 @@ -package rbd - -/* - -#include - -extern int diffIterateCallback(uint64_t ofs, size_t len, int exists, int index); - -int callDiffIterateCallback(uint64_t ofs, size_t len, int exists, int index) { - return diffIterateCallback(ofs, len, exists, index); -} -*/ -import "C" diff --git a/rbd/callback_shims_mimic.go b/rbd/callback_shims_mimic.go deleted file mode 100644 index fdf0303..0000000 --- a/rbd/callback_shims_mimic.go +++ /dev/null @@ -1,15 +0,0 @@ -// +build !luminous - -package rbd - -/* - -#include - -extern void imageWatchCallback(int index); - -void callWatchCallback(int index) { - imageWatchCallback(index); -} -*/ -import "C" diff --git a/rbd/diff_iterate.go b/rbd/diff_iterate.go index 1699ce2..b8fcadc 100644 --- a/rbd/diff_iterate.go +++ b/rbd/diff_iterate.go @@ -7,7 +7,7 @@ package rbd #include #include -extern int callDiffIterateCallback(uint64_t ofs, size_t len, int exists, int index); +extern int diffIterateCallback(uint64_t, size_t, int, void *); // cgo is having trouble converting the callback from the librbd header // to a unsafe.Pointer. This shim exists solely to help it along. @@ -16,9 +16,8 @@ static inline int wrap_rbd_diff_iterate2( const char *fromsnapname, uint64_t ofs, uint64_t len, uint8_t include_parent, uint8_t whole_object, - void *cb, - uintptr_t arg) { - return rbd_diff_iterate2(image, fromsnapname, ofs, len, include_parent, whole_object, cb, (void*)arg); + uintptr_t index) { + return rbd_diff_iterate2(image, fromsnapname, ofs, len, include_parent, whole_object, diffIterateCallback, (void*)index); } */ import "C" @@ -118,7 +117,6 @@ func (image *Image) DiffIterate(config DiffIterateConfig) error { C.uint64_t(config.Length), C.uint8_t(config.IncludeParent), C.uint8_t(config.WholeObject), - C.callDiffIterateCallback, C.uintptr_t(cbIndex)) return getError(ret) @@ -126,9 +124,9 @@ func (image *Image) DiffIterate(config DiffIterateConfig) error { //export diffIterateCallback func diffIterateCallback( - offset C.uint64_t, length C.size_t, exists, index C.int) C.int { + offset C.uint64_t, length C.size_t, exists C.int, index unsafe.Pointer) C.int { - v := diffIterateCallbacks.Lookup(int(index)) + v := diffIterateCallbacks.Lookup(int(uintptr(index))) config := v.(DiffIterateConfig) return C.int(config.Callback( uint64(offset), uint64(length), int(exists), config.Data)) diff --git a/rbd/watchers_mimic.go b/rbd/watchers_mimic.go index 54d5dfd..7e2de49 100644 --- a/rbd/watchers_mimic.go +++ b/rbd/watchers_mimic.go @@ -8,7 +8,7 @@ package rbd #cgo LDFLAGS: -lrbd #include -extern int callWatchCallback(int index); +extern void imageWatchCallback(void *); // cgo has trouble converting the types of the callback and data arg defined in // librbd header. It wants the callback function to be a byte pointer and @@ -18,14 +18,15 @@ extern int callWatchCallback(int index); static inline int wrap_rbd_update_watch( rbd_image_t image, uint64_t *handle, - void *watch_cb, - uintptr_t arg) { - return rbd_update_watch(image, handle, watch_cb, (void*)arg); + uintptr_t index) { + return rbd_update_watch(image, handle, imageWatchCallback, (void*)index); } */ import "C" import ( + "unsafe" + "github.com/ceph/go-ceph/internal/callbacks" "github.com/ceph/go-ceph/internal/retry" ) @@ -120,7 +121,6 @@ func (image *Image) UpdateWatch(cb WatchCallback, data interface{}) (*Watch, err ret := C.wrap_rbd_update_watch( image.image, &w.handle, - C.callWatchCallback, C.uintptr_t(w.cbIndex)) if ret != 0 { return nil, getError(ret) @@ -145,8 +145,8 @@ func (w *Watch) Unwatch() error { } //export imageWatchCallback -func imageWatchCallback(index C.int) { - v := watchCallbacks.Lookup(int(index)) +func imageWatchCallback(index unsafe.Pointer) { + v := watchCallbacks.Lookup(int(uintptr(index))) wi := v.(watchInstance) wi.callback(wi.data) }