mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-06-13 02:33:34 +00:00
rebase: update go-ceph to v0.10.0
This commit updates the go-ceph to latest release. More details about release at https://github.com/ceph/go-ceph/releases/tag/v0.10.0 Signed-off-by: Madhu Rajanna <madhupr007@gmail.com>
This commit is contained in:
committed by
mergify[bot]
parent
17b0091cba
commit
5b7b5f1e3a
3
vendor/github.com/ceph/go-ceph/internal/cutil/aliases.go
generated
vendored
3
vendor/github.com/ceph/go-ceph/internal/cutil/aliases.go
generated
vendored
@ -8,12 +8,13 @@ typedef void* voidptr;
|
||||
import "C"
|
||||
|
||||
import (
|
||||
"math"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
const (
|
||||
// MaxIdx is the maximum index on 32 bit systems
|
||||
MaxIdx = 1<<31 - 1 // 2GB, max int32 value, should be safe
|
||||
MaxIdx = math.MaxInt32 // 2GB, max int32 value, should be safe
|
||||
|
||||
// PtrSize is the size of a pointer
|
||||
PtrSize = C.sizeof_voidptr
|
||||
|
76
vendor/github.com/ceph/go-ceph/internal/cutil/cslice.go
generated
vendored
Normal file
76
vendor/github.com/ceph/go-ceph/internal/cutil/cslice.go
generated
vendored
Normal file
@ -0,0 +1,76 @@
|
||||
package cutil
|
||||
|
||||
// The following code needs some explanation:
|
||||
// This creates slices on top of the C memory buffers allocated before in
|
||||
// order to safely and comfortably use them as arrays. First the void pointer
|
||||
// is cast to a pointer to an array of the type that will be stored in the
|
||||
// array. Because the size of an array is a constant, but the real array size
|
||||
// is dynamic, we just use the biggest possible index value MaxIdx, to make
|
||||
// sure it's always big enough. (Nothing is allocated by casting, so the size
|
||||
// can be arbitrarily big.) So, if the array should store items of myType, the
|
||||
// cast would be (*[MaxIdx]myItem)(myCMemPtr).
|
||||
// From that array pointer a slice is created with the [start:end:capacity]
|
||||
// syntax. The capacity must be set explicitly here, because by default it
|
||||
// would be set to the size of the original array, which is MaxIdx, which
|
||||
// doesn't reflect reality in this case. This results in definitions like:
|
||||
// cSlice := (*[MaxIdx]myItem)(myCMemPtr)[:numOfItems:numOfItems]
|
||||
|
||||
////////// CPtr //////////
|
||||
|
||||
// CPtrCSlice is a C allocated slice of C pointers.
|
||||
type CPtrCSlice []CPtr
|
||||
|
||||
// NewCPtrCSlice returns a CPtrSlice.
|
||||
// Similar to CString it must be freed with slice.Free()
|
||||
func NewCPtrCSlice(size int) CPtrCSlice {
|
||||
if size == 0 {
|
||||
return nil
|
||||
}
|
||||
cMem := Malloc(SizeT(size) * PtrSize)
|
||||
cSlice := (*[MaxIdx]CPtr)(cMem)[:size:size]
|
||||
return cSlice
|
||||
}
|
||||
|
||||
// Ptr returns a pointer to CPtrSlice
|
||||
func (v *CPtrCSlice) Ptr() CPtr {
|
||||
if len(*v) == 0 {
|
||||
return nil
|
||||
}
|
||||
return CPtr(&(*v)[0])
|
||||
}
|
||||
|
||||
// Free frees a CPtrSlice
|
||||
func (v *CPtrCSlice) Free() {
|
||||
Free(v.Ptr())
|
||||
*v = nil
|
||||
}
|
||||
|
||||
////////// SizeT //////////
|
||||
|
||||
// SizeTCSlice is a C allocated slice of C.size_t.
|
||||
type SizeTCSlice []SizeT
|
||||
|
||||
// NewSizeTCSlice returns a SizeTCSlice.
|
||||
// Similar to CString it must be freed with slice.Free()
|
||||
func NewSizeTCSlice(size int) SizeTCSlice {
|
||||
if size == 0 {
|
||||
return nil
|
||||
}
|
||||
cMem := Malloc(SizeT(size) * SizeTSize)
|
||||
cSlice := (*[MaxIdx]SizeT)(cMem)[:size:size]
|
||||
return cSlice
|
||||
}
|
||||
|
||||
// Ptr returns a pointer to SizeTCSlice
|
||||
func (v *SizeTCSlice) Ptr() CPtr {
|
||||
if len(*v) == 0 {
|
||||
return nil
|
||||
}
|
||||
return CPtr(&(*v)[0])
|
||||
}
|
||||
|
||||
// Free frees a SizeTCSlice
|
||||
func (v *SizeTCSlice) Free() {
|
||||
Free(v.Ptr())
|
||||
*v = nil
|
||||
}
|
13
vendor/github.com/ceph/go-ceph/internal/cutil/ptrguard.go
generated
vendored
13
vendor/github.com/ceph/go-ceph/internal/cutil/ptrguard.go
generated
vendored
@ -57,6 +57,17 @@ func (v *PtrGuard) Release() {
|
||||
}
|
||||
}
|
||||
|
||||
// The uintptrPtr() helper function below assumes that uintptr has the same size
|
||||
// as a pointer, although in theory it could be larger. Therefore we use this
|
||||
// constant expression to assert size equality as a safeguard at compile time.
|
||||
// How it works: the difference of both sizes is converted into an 8 bit value
|
||||
// and left-bit-shifted by 8. This always creates an overflow error at compile
|
||||
// time, if the difference of the sizes is not 0.
|
||||
const _ = uint8(unsafe.Sizeof(uintptr(0))-PtrSize) << 8 // size assert
|
||||
func uintptrPtr(p *CPtr) *uintptr {
|
||||
return (*uintptr)(unsafe.Pointer(p))
|
||||
}
|
||||
|
||||
//go:uintptrescapes
|
||||
|
||||
// From https://golang.org/src/cmd/compile/internal/gc/lex.go:
|
||||
@ -69,7 +80,7 @@ func (v *PtrGuard) Release() {
|
||||
// Also see https://golang.org/cmd/compile/#hdr-Compiler_Directives
|
||||
|
||||
func storeUntilRelease(v *PtrGuard, cPtr *CPtr, goPtr uintptr) {
|
||||
uip := (*uintptr)(unsafe.Pointer(cPtr))
|
||||
uip := uintptrPtr(cPtr)
|
||||
*uip = goPtr // store Go pointer in C memory at c_ptr
|
||||
v.stored.Unlock() // send "stored" signal to main thread -->(1)
|
||||
v.release.Lock() // wait for "release" signal from main thread when
|
||||
|
Reference in New Issue
Block a user