mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-06-13 02:33:34 +00:00
rebase: Make use of latest go ceph library
The go-ceph version 0.4.0 is available now which got some important library changes required for ceph csi project. Signed-off-by: Humble Chirammal <hchiramm@redhat.com>
This commit is contained in:
committed by
mergify[bot]
parent
306d5b1da0
commit
58bf45a13e
62
vendor/github.com/ceph/go-ceph/internal/cutil/command_input.go
generated
vendored
Normal file
62
vendor/github.com/ceph/go-ceph/internal/cutil/command_input.go
generated
vendored
Normal file
@ -0,0 +1,62 @@
|
||||
package cutil
|
||||
|
||||
/*
|
||||
#include <stdlib.h>
|
||||
*/
|
||||
import "C"
|
||||
|
||||
import (
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
// CommandInput can be used to manage the input to ceph's *_command functions.
|
||||
type CommandInput struct {
|
||||
cmd []*C.char
|
||||
inbuf []byte
|
||||
}
|
||||
|
||||
// NewCommandInput creates C-level pointers from go byte buffers suitable
|
||||
// for passing off to ceph's *_command functions.
|
||||
func NewCommandInput(cmd [][]byte, inputBuffer []byte) *CommandInput {
|
||||
ci := &CommandInput{
|
||||
cmd: make([]*C.char, len(cmd)),
|
||||
inbuf: inputBuffer,
|
||||
}
|
||||
for i := range cmd {
|
||||
ci.cmd[i] = C.CString(string(cmd[i]))
|
||||
}
|
||||
return ci
|
||||
}
|
||||
|
||||
// Free any C memory managed by this CommandInput.
|
||||
func (ci *CommandInput) Free() {
|
||||
for i := range ci.cmd {
|
||||
C.free(unsafe.Pointer(ci.cmd[i]))
|
||||
}
|
||||
ci.cmd = nil
|
||||
}
|
||||
|
||||
// Cmd returns an unsafe wrapper around an array of C-strings.
|
||||
func (ci *CommandInput) Cmd() CharPtrPtr {
|
||||
ptr := &ci.cmd[0]
|
||||
return CharPtrPtr(ptr)
|
||||
}
|
||||
|
||||
// CmdLen returns the length of the array of C-strings returned by
|
||||
// Cmd.
|
||||
func (ci *CommandInput) CmdLen() SizeT {
|
||||
return SizeT(len(ci.cmd))
|
||||
}
|
||||
|
||||
// InBuf returns an unsafe wrapper to a C char*.
|
||||
func (ci *CommandInput) InBuf() CharPtr {
|
||||
if len(ci.inbuf) == 0 {
|
||||
return nil
|
||||
}
|
||||
return CharPtr(&ci.inbuf[0])
|
||||
}
|
||||
|
||||
// InBufLen returns the length of the buffer returned by InBuf.
|
||||
func (ci *CommandInput) InBufLen() SizeT {
|
||||
return SizeT(len(ci.inbuf))
|
||||
}
|
100
vendor/github.com/ceph/go-ceph/internal/cutil/command_output.go
generated
vendored
Normal file
100
vendor/github.com/ceph/go-ceph/internal/cutil/command_output.go
generated
vendored
Normal file
@ -0,0 +1,100 @@
|
||||
package cutil
|
||||
|
||||
/*
|
||||
#include <stdlib.h>
|
||||
*/
|
||||
import "C"
|
||||
|
||||
import (
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
// CommandOutput can be used to manage the outputs of ceph's *_command
|
||||
// functions.
|
||||
type CommandOutput struct {
|
||||
free FreeFunc
|
||||
outBuf *C.char
|
||||
outBufLen C.size_t
|
||||
outs *C.char
|
||||
outsLen C.size_t
|
||||
}
|
||||
|
||||
// NewCommandOutput returns an empty CommandOutput. The pointers that
|
||||
// a CommandOutput provides can be used to get the results of ceph's
|
||||
// *_command functions.
|
||||
func NewCommandOutput() *CommandOutput {
|
||||
return &CommandOutput{
|
||||
free: free,
|
||||
}
|
||||
}
|
||||
|
||||
// SetFreeFunc sets the function used to free memory held by CommandOutput.
|
||||
// Not all uses of CommandOutput expect to use the basic C.free function
|
||||
// and either require or prefer the use of a custom deallocation function.
|
||||
// Use SetFreeFunc to change the free function and return the modified
|
||||
// CommandOutput object.
|
||||
func (co *CommandOutput) SetFreeFunc(f FreeFunc) *CommandOutput {
|
||||
co.free = f
|
||||
return co
|
||||
}
|
||||
|
||||
// Free any C memory tracked by this object.
|
||||
func (co *CommandOutput) Free() {
|
||||
if co.outBuf != nil {
|
||||
co.free(unsafe.Pointer(co.outBuf))
|
||||
}
|
||||
if co.outs != nil {
|
||||
co.free(unsafe.Pointer(co.outs))
|
||||
}
|
||||
}
|
||||
|
||||
// OutBuf returns an unsafe wrapper around a pointer to a `char*`.
|
||||
func (co *CommandOutput) OutBuf() CharPtrPtr {
|
||||
return CharPtrPtr(&co.outBuf)
|
||||
}
|
||||
|
||||
// OutBufLen returns an unsafe wrapper around a pointer to a size_t.
|
||||
func (co *CommandOutput) OutBufLen() SizeTPtr {
|
||||
return SizeTPtr(&co.outBufLen)
|
||||
}
|
||||
|
||||
// Outs returns an unsafe wrapper around a pointer to a `char*`.
|
||||
func (co *CommandOutput) Outs() CharPtrPtr {
|
||||
return CharPtrPtr(&co.outs)
|
||||
}
|
||||
|
||||
// OutsLen returns an unsafe wrapper around a pointer to a size_t.
|
||||
func (co *CommandOutput) OutsLen() SizeTPtr {
|
||||
return SizeTPtr(&co.outsLen)
|
||||
}
|
||||
|
||||
// GoValues returns native go values converted from the internal C-language
|
||||
// values tracked by this object.
|
||||
func (co *CommandOutput) GoValues() (buf []byte, status string) {
|
||||
if co.outBufLen > 0 {
|
||||
buf = C.GoBytes(unsafe.Pointer(co.outBuf), C.int(co.outBufLen))
|
||||
}
|
||||
if co.outsLen > 0 {
|
||||
status = C.GoStringN(co.outs, C.int(co.outsLen))
|
||||
}
|
||||
return buf, status
|
||||
}
|
||||
|
||||
// testSetString is only used by the unit tests for this file.
|
||||
// It is located here due to the restriction on having import "C" in
|
||||
// go test files. :-(
|
||||
// It mimics a C function that takes a pointer to a
|
||||
// string and length and allocates memory and sets the pointers
|
||||
// to the new string and its length.
|
||||
func testSetString(strp CharPtrPtr, lenp SizeTPtr, s string) {
|
||||
sp := (**C.char)(strp)
|
||||
lp := (*C.size_t)(lenp)
|
||||
*sp = C.CString(s)
|
||||
*lp = C.size_t(len(s))
|
||||
}
|
||||
|
||||
// free wraps C.free.
|
||||
// Required for unit tests that may not use cgo directly.
|
||||
func free(p unsafe.Pointer) {
|
||||
C.free(p)
|
||||
}
|
28
vendor/github.com/ceph/go-ceph/internal/cutil/type_aliases.go
generated
vendored
Normal file
28
vendor/github.com/ceph/go-ceph/internal/cutil/type_aliases.go
generated
vendored
Normal file
@ -0,0 +1,28 @@
|
||||
package cutil
|
||||
|
||||
import "C"
|
||||
|
||||
import (
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
// Basic types from C that we can make "public" without too much fuss.
|
||||
|
||||
// SizeT wraps size_t from C.
|
||||
type SizeT C.size_t
|
||||
|
||||
// This section contains a bunch of types that are basically just
|
||||
// unsafe.Pointer but have specific types to help "self document" what the
|
||||
// underlying pointer is really meant to represent.
|
||||
|
||||
// CharPtrPtr is an unsafe pointer wrapping C's `char**`.
|
||||
type CharPtrPtr unsafe.Pointer
|
||||
|
||||
// CharPtr is an unsafe pointer wrapping C's `char*`.
|
||||
type CharPtr unsafe.Pointer
|
||||
|
||||
// SizeTPtr is an unsafe pointer wrapping C's `size_t*`.
|
||||
type SizeTPtr unsafe.Pointer
|
||||
|
||||
// FreeFunc is a wrapper around calls to, or act like, C's free function.
|
||||
type FreeFunc func(unsafe.Pointer)
|
Reference in New Issue
Block a user