mirror of
https://github.com/ceph/go-ceph
synced 2024-12-24 23:22:33 +00:00
ce64ef536a
Start organizing some of the cephfs functionality into functions grouped by files by moving the MDS command functions into a new file. Move the tests dedicated to those functions into a new matching file too. Signed-off-by: John Mulligan <jmulligan@redhat.com>
87 lines
2.2 KiB
Go
87 lines
2.2 KiB
Go
package cephfs
|
|
|
|
/*
|
|
#cgo LDFLAGS: -lcephfs
|
|
#cgo CPPFLAGS: -D_FILE_OFFSET_BITS=64
|
|
#include <stdlib.h>
|
|
#include <cephfs/libcephfs.h>
|
|
*/
|
|
import "C"
|
|
|
|
import (
|
|
"unsafe"
|
|
)
|
|
|
|
// MdsCommand sends commands to the specified MDS.
|
|
func (mount *MountInfo) MdsCommand(mdsSpec string, args [][]byte) ([]byte, string, error) {
|
|
return mount.mdsCommand(mdsSpec, args, nil)
|
|
}
|
|
|
|
// MdsCommandWithInputBuffer sends commands to the specified MDS, with an input
|
|
// buffer.
|
|
func (mount *MountInfo) MdsCommandWithInputBuffer(mdsSpec string, args [][]byte, inputBuffer []byte) ([]byte, string, error) {
|
|
return mount.mdsCommand(mdsSpec, args, inputBuffer)
|
|
}
|
|
|
|
// mdsCommand supports sending formatted commands to MDS.
|
|
//
|
|
// Implements:
|
|
// int ceph_mds_command(struct ceph_mount_info *cmount,
|
|
// const char *mds_spec,
|
|
// const char **cmd,
|
|
// size_t cmdlen,
|
|
// const char *inbuf, size_t inbuflen,
|
|
// char **outbuf, size_t *outbuflen,
|
|
// char **outs, size_t *outslen);
|
|
func (mount *MountInfo) mdsCommand(mdsSpec string, args [][]byte, inputBuffer []byte) (buffer []byte, info string, err error) {
|
|
spec := C.CString(mdsSpec)
|
|
defer C.free(unsafe.Pointer(spec))
|
|
|
|
argc := len(args)
|
|
argv := make([]*C.char, argc)
|
|
|
|
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(
|
|
mount.mount, // cephfs mount ref
|
|
spec, // mds spec
|
|
&argv[0], // cmd array
|
|
C.size_t(argc), // cmd array length
|
|
inbuf, // bulk input
|
|
C.size_t(inbufLen), // length inbuf
|
|
&outbuf, // buffer
|
|
&outbuflen, // buffer length
|
|
&outs, // status string
|
|
&outslen)
|
|
|
|
if outslen > 0 {
|
|
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
|
|
}
|