mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-06-13 02:33:34 +00:00
rebase: update go-ceph to v0.5.0
as go-ceph is 0.5.0 is released updating the dependency to latest release. more info about release at https://github.com/ceph/go-ceph/releases/tag/v0.5.0 Signed-off-by: Madhu Rajanna <madhupr007@gmail.com>
This commit is contained in:
committed by
mergify[bot]
parent
5f6fec5f0a
commit
2808d526bb
97
vendor/github.com/ceph/go-ceph/rbd/watchers_mimic.go
generated
vendored
97
vendor/github.com/ceph/go-ceph/rbd/watchers_mimic.go
generated
vendored
@ -4,12 +4,30 @@
|
||||
|
||||
package rbd
|
||||
|
||||
// #cgo LDFLAGS: -lrbd
|
||||
// #include <errno.h>
|
||||
// #include <rbd/librbd.h>
|
||||
/*
|
||||
#cgo LDFLAGS: -lrbd
|
||||
#include <rbd/librbd.h>
|
||||
|
||||
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
|
||||
// the arg to be a pointer, which is pretty much the opposite of what we
|
||||
// actually want. This shim exists to help coerce the auto-type-conversion
|
||||
// to do the right thing for us.
|
||||
static inline int wrap_rbd_update_watch(
|
||||
rbd_image_t image,
|
||||
uint64_t *handle,
|
||||
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"
|
||||
)
|
||||
|
||||
@ -59,3 +77,76 @@ func (image *Image) ListWatchers() ([]ImageWatcher, error) {
|
||||
}
|
||||
return imageWatchers, nil
|
||||
}
|
||||
|
||||
// watchCallbacks tracks the active callbacks for rbd watches
|
||||
var watchCallbacks = callbacks.New()
|
||||
|
||||
// WatchCallback defines the function signature needed for the UpdateWatch
|
||||
// callback.
|
||||
type WatchCallback func(interface{})
|
||||
|
||||
type watchCallbackCtx struct {
|
||||
callback WatchCallback
|
||||
data interface{}
|
||||
}
|
||||
|
||||
// Watch represents an ongoing image metadata watch.
|
||||
type Watch struct {
|
||||
image *Image
|
||||
wcc watchCallbackCtx
|
||||
handle C.uint64_t
|
||||
cbIndex int
|
||||
}
|
||||
|
||||
// UpdateWatch updates the image object to watch metadata changes to the
|
||||
// image, returning a Watch object.
|
||||
//
|
||||
// Implements:
|
||||
// int rbd_update_watch(rbd_image_t image, uint64_t *handle,
|
||||
// rbd_update_callback_t watch_cb, void *arg);
|
||||
func (image *Image) UpdateWatch(cb WatchCallback, data interface{}) (*Watch, error) {
|
||||
if err := image.validate(imageIsOpen); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
wcc := watchCallbackCtx{
|
||||
callback: cb,
|
||||
data: data,
|
||||
}
|
||||
w := &Watch{
|
||||
image: image,
|
||||
wcc: wcc,
|
||||
cbIndex: watchCallbacks.Add(wcc),
|
||||
}
|
||||
|
||||
ret := C.wrap_rbd_update_watch(
|
||||
image.image,
|
||||
&w.handle,
|
||||
C.uintptr_t(w.cbIndex))
|
||||
if ret != 0 {
|
||||
return nil, getError(ret)
|
||||
}
|
||||
return w, nil
|
||||
}
|
||||
|
||||
// Unwatch un-registers the image watch.
|
||||
//
|
||||
// Implements:
|
||||
// int rbd_update_unwatch(rbd_image_t image, uint64_t handle);
|
||||
func (w *Watch) Unwatch() error {
|
||||
if w.image == nil {
|
||||
return ErrImageNotOpen
|
||||
}
|
||||
if err := w.image.validate(imageIsOpen); err != nil {
|
||||
return err
|
||||
}
|
||||
ret := C.rbd_update_unwatch(w.image.image, w.handle)
|
||||
watchCallbacks.Remove(w.cbIndex)
|
||||
return getError(ret)
|
||||
}
|
||||
|
||||
//export imageWatchCallback
|
||||
func imageWatchCallback(index unsafe.Pointer) {
|
||||
v := watchCallbacks.Lookup(int(uintptr(index)))
|
||||
wcc := v.(watchCallbackCtx)
|
||||
wcc.callback(wcc.data)
|
||||
}
|
||||
|
Reference in New Issue
Block a user