mirror of https://github.com/ceph/go-ceph
cephfs: replace copy-n-paste *_command functions argument handling
Similar to the functions in the rados pkg, cephfs package has a function MdsCommand that is mostly boilerplate that to set up the C function's arguments. Replace it with the types from the new cutil internal package. Signed-off-by: John Mulligan <jmulligan@redhat.com>
This commit is contained in:
parent
817b6b68c2
commit
f2d0bb4692
|
@ -10,6 +10,8 @@ import "C"
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"unsafe"
|
"unsafe"
|
||||||
|
|
||||||
|
"github.com/ceph/go-ceph/internal/cutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
// MdsCommand sends commands to the specified MDS.
|
// MdsCommand sends commands to the specified MDS.
|
||||||
|
@ -36,51 +38,22 @@ func (mount *MountInfo) MdsCommandWithInputBuffer(mdsSpec string, args [][]byte,
|
||||||
func (mount *MountInfo) mdsCommand(mdsSpec string, args [][]byte, inputBuffer []byte) (buffer []byte, info string, err error) {
|
func (mount *MountInfo) mdsCommand(mdsSpec string, args [][]byte, inputBuffer []byte) (buffer []byte, info string, err error) {
|
||||||
spec := C.CString(mdsSpec)
|
spec := C.CString(mdsSpec)
|
||||||
defer C.free(unsafe.Pointer(spec))
|
defer C.free(unsafe.Pointer(spec))
|
||||||
|
ci := cutil.NewCommandInput(args, inputBuffer)
|
||||||
argc := len(args)
|
defer ci.Free()
|
||||||
argv := make([]*C.char, argc)
|
co := cutil.NewCommandOutput()
|
||||||
|
defer co.Free()
|
||||||
for i, arg := range args {
|
|
||||||
argv[i] = C.CString(string(arg))
|
|
||||||
}
|
|
||||||
// free all array elements in a single defer
|
|
||||||
defer func() {
|
|
||||||
for i := range argv {
|
|
||||||
C.free(unsafe.Pointer(argv[i]))
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
var (
|
|
||||||
outs, outbuf *C.char
|
|
||||||
outslen, outbuflen C.size_t
|
|
||||||
)
|
|
||||||
inbuf := C.CString(string(inputBuffer))
|
|
||||||
inbufLen := len(inputBuffer)
|
|
||||||
defer C.free(unsafe.Pointer(inbuf))
|
|
||||||
|
|
||||||
ret := C.ceph_mds_command(
|
ret := C.ceph_mds_command(
|
||||||
mount.mount, // cephfs mount ref
|
mount.mount, // cephfs mount ref
|
||||||
spec, // mds spec
|
spec, // mds spec
|
||||||
&argv[0], // cmd array
|
(**C.char)(ci.Cmd()),
|
||||||
C.size_t(argc), // cmd array length
|
C.size_t(ci.CmdLen()),
|
||||||
inbuf, // bulk input
|
(*C.char)(ci.InBuf()),
|
||||||
C.size_t(inbufLen), // length inbuf
|
C.size_t(ci.InBufLen()),
|
||||||
&outbuf, // buffer
|
(**C.char)(co.OutBuf()),
|
||||||
&outbuflen, // buffer length
|
(*C.size_t)(co.OutBufLen()),
|
||||||
&outs, // status string
|
(**C.char)(co.Outs()),
|
||||||
&outslen)
|
(*C.size_t)(co.OutsLen()))
|
||||||
|
buf, status := co.GoValues()
|
||||||
if outslen > 0 {
|
return buf, status, getError(ret)
|
||||||
info = C.GoStringN(outs, C.int(outslen))
|
|
||||||
C.free(unsafe.Pointer(outs))
|
|
||||||
}
|
|
||||||
if outbuflen > 0 {
|
|
||||||
buffer = C.GoBytes(unsafe.Pointer(outbuf), C.int(outbuflen))
|
|
||||||
C.free(unsafe.Pointer(outbuf))
|
|
||||||
}
|
|
||||||
if ret != 0 {
|
|
||||||
return nil, info, getError(ret)
|
|
||||||
}
|
|
||||||
|
|
||||||
return buffer, info, nil
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue