2020-03-25 13:20:32 +00:00
|
|
|
package cephfs
|
|
|
|
|
|
|
|
/*
|
|
|
|
#cgo LDFLAGS: -lcephfs
|
|
|
|
#cgo CPPFLAGS: -D_FILE_OFFSET_BITS=64
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <cephfs/libcephfs.h>
|
|
|
|
*/
|
|
|
|
import "C"
|
|
|
|
|
|
|
|
import (
|
|
|
|
"unsafe"
|
2020-04-18 18:25:24 +00:00
|
|
|
|
|
|
|
"github.com/ceph/go-ceph/internal/cutil"
|
2020-03-25 13:20:32 +00:00
|
|
|
)
|
|
|
|
|
2020-04-23 15:10:15 +00:00
|
|
|
func cephBufferFree(p unsafe.Pointer) {
|
|
|
|
C.ceph_buffer_free((*C.char)(p))
|
|
|
|
}
|
|
|
|
|
2020-03-25 13:20:32 +00:00
|
|
|
// 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:
|
2023-02-09 17:23:11 +00:00
|
|
|
//
|
|
|
|
// 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);
|
2020-03-25 13:20:32 +00:00
|
|
|
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))
|
2020-04-18 18:25:24 +00:00
|
|
|
ci := cutil.NewCommandInput(args, inputBuffer)
|
|
|
|
defer ci.Free()
|
2020-04-23 15:10:15 +00:00
|
|
|
co := cutil.NewCommandOutput().SetFreeFunc(cephBufferFree)
|
2020-04-18 18:25:24 +00:00
|
|
|
defer co.Free()
|
2020-03-25 13:20:32 +00:00
|
|
|
|
|
|
|
ret := C.ceph_mds_command(
|
2020-04-18 18:25:24 +00:00
|
|
|
mount.mount, // cephfs mount ref
|
|
|
|
spec, // mds spec
|
|
|
|
(**C.char)(ci.Cmd()),
|
|
|
|
C.size_t(ci.CmdLen()),
|
|
|
|
(*C.char)(ci.InBuf()),
|
|
|
|
C.size_t(ci.InBufLen()),
|
|
|
|
(**C.char)(co.OutBuf()),
|
|
|
|
(*C.size_t)(co.OutBufLen()),
|
|
|
|
(**C.char)(co.Outs()),
|
|
|
|
(*C.size_t)(co.OutsLen()))
|
|
|
|
buf, status := co.GoValues()
|
|
|
|
return buf, status, getError(ret)
|
2020-03-25 13:20:32 +00:00
|
|
|
}
|