mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-06-13 10:33:35 +00:00
rebase: use go-ceph v0.3.0
v0.3.0 adds support for rbd.FeatureSet that can be used to parse the features of an RBD image. This will be used in the followup commit that adds rbdVolume.getImageInfo(). Signed-off-by: Niels de Vos <ndevos@redhat.com>
This commit is contained in:
committed by
mergify[bot]
parent
323cc0e3bb
commit
772d1dfa77
64
vendor/github.com/ceph/go-ceph/internal/callbacks/callbacks.go
generated
vendored
Normal file
64
vendor/github.com/ceph/go-ceph/internal/callbacks/callbacks.go
generated
vendored
Normal file
@ -0,0 +1,64 @@
|
||||
package callbacks
|
||||
|
||||
import (
|
||||
"sync"
|
||||
)
|
||||
|
||||
// The logic of this file is largely adapted from:
|
||||
// https://github.com/golang/go/wiki/cgo#function-variables
|
||||
//
|
||||
// Also helpful:
|
||||
// https://eli.thegreenplace.net/2019/passing-callbacks-and-pointers-to-cgo/
|
||||
|
||||
// Callbacks provides a tracker for data that is to be passed between Go
|
||||
// and C callback functions. The Go callback/object may not be passed
|
||||
// by a pointer to C code and so instead integer indexes into an internal
|
||||
// map are used.
|
||||
// Typically the item being added will either be a callback function or
|
||||
// a data structure containing a callback function. It is up to the caller
|
||||
// to control and validate what "callbacks" get used.
|
||||
type Callbacks struct {
|
||||
mutex sync.RWMutex
|
||||
cmap map[int]interface{}
|
||||
}
|
||||
|
||||
// New returns a new callbacks tracker.
|
||||
func New() *Callbacks {
|
||||
return &Callbacks{cmap: make(map[int]interface{})}
|
||||
}
|
||||
|
||||
// Add a callback/object to the tracker and return a new index
|
||||
// for the object.
|
||||
func (cb *Callbacks) Add(v interface{}) int {
|
||||
cb.mutex.Lock()
|
||||
defer cb.mutex.Unlock()
|
||||
// this approach assumes that there are typically very few callbacks
|
||||
// in play at once and can just use the length of the map as our
|
||||
// index. But in case of collisions we fall back to simply incrementing
|
||||
// until we find a free key like in the cgo wiki page.
|
||||
// If this code ever becomes a hot path there's surely plenty of room
|
||||
// for optimization in the future :-)
|
||||
index := len(cb.cmap) + 1
|
||||
for {
|
||||
if _, found := cb.cmap[index]; !found {
|
||||
break
|
||||
}
|
||||
index++
|
||||
}
|
||||
cb.cmap[index] = v
|
||||
return index
|
||||
}
|
||||
|
||||
// Remove a callback/object given it's index.
|
||||
func (cb *Callbacks) Remove(index int) {
|
||||
cb.mutex.Lock()
|
||||
defer cb.mutex.Unlock()
|
||||
delete(cb.cmap, index)
|
||||
}
|
||||
|
||||
// Lookup returns a mapped callback/object given an index.
|
||||
func (cb *Callbacks) Lookup(index int) interface{} {
|
||||
cb.mutex.RLock()
|
||||
defer cb.mutex.RUnlock()
|
||||
return cb.cmap[index]
|
||||
}
|
45
vendor/github.com/ceph/go-ceph/internal/errutil/strerror.go
generated
vendored
Normal file
45
vendor/github.com/ceph/go-ceph/internal/errutil/strerror.go
generated
vendored
Normal file
@ -0,0 +1,45 @@
|
||||
/*
|
||||
Package errutil provides common functions for dealing with error conditions for
|
||||
all ceph api wrappers.
|
||||
*/
|
||||
package errutil
|
||||
|
||||
/* force XSI-complaint strerror_r() */
|
||||
|
||||
// #define _POSIX_C_SOURCE 200112L
|
||||
// #undef _GNU_SOURCE
|
||||
// #include <stdlib.h>
|
||||
// #include <errno.h>
|
||||
// #include <string.h>
|
||||
import "C"
|
||||
|
||||
import (
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
// FormatErrno returns the absolute value of the errno as well as a string
|
||||
// describing the errno. The string will be empty is the errno is not known.
|
||||
func FormatErrno(errno int) (int, string) {
|
||||
buf := make([]byte, 1024)
|
||||
// strerror expects errno >= 0
|
||||
if errno < 0 {
|
||||
errno = -errno
|
||||
}
|
||||
|
||||
ret := C.strerror_r(
|
||||
C.int(errno),
|
||||
(*C.char)(unsafe.Pointer(&buf[0])),
|
||||
C.size_t(len(buf)))
|
||||
if ret != 0 {
|
||||
return errno, ""
|
||||
}
|
||||
|
||||
return errno, C.GoString((*C.char)(unsafe.Pointer(&buf[0])))
|
||||
}
|
||||
|
||||
// StrError returns a string describing the errno. The string will be empty if
|
||||
// the errno is not known.
|
||||
func StrError(errno int) string {
|
||||
_, s := FormatErrno(errno)
|
||||
return s
|
||||
}
|
Reference in New Issue
Block a user