2020-04-09 11:52:39 +00:00
|
|
|
package rados
|
|
|
|
|
|
|
|
// #cgo LDFLAGS: -lrados
|
|
|
|
// #include <stdlib.h>
|
|
|
|
// #include <rados/librados.h>
|
|
|
|
import "C"
|
|
|
|
|
|
|
|
import (
|
|
|
|
"unsafe"
|
2020-04-11 14:23:19 +00:00
|
|
|
|
|
|
|
"github.com/ceph/go-ceph/internal/cutil"
|
2020-04-09 11:52:39 +00:00
|
|
|
)
|
|
|
|
|
2020-04-23 15:10:15 +00:00
|
|
|
func radosBufferFree(p unsafe.Pointer) {
|
|
|
|
C.rados_buffer_free((*C.char)(p))
|
|
|
|
}
|
|
|
|
|
2020-04-09 11:52:39 +00:00
|
|
|
// MonCommand sends a command to one of the monitors
|
2020-04-09 14:42:29 +00:00
|
|
|
func (c *Conn) MonCommand(args []byte) ([]byte, string, error) {
|
2020-04-09 11:52:39 +00:00
|
|
|
return c.monCommand(args, nil)
|
|
|
|
}
|
|
|
|
|
|
|
|
// MonCommandWithInputBuffer sends a command to one of the monitors, with an input buffer
|
2020-04-09 14:42:29 +00:00
|
|
|
func (c *Conn) MonCommandWithInputBuffer(args, inputBuffer []byte) ([]byte, string, error) {
|
2020-04-09 11:52:39 +00:00
|
|
|
return c.monCommand(args, inputBuffer)
|
|
|
|
}
|
|
|
|
|
2020-04-09 14:42:29 +00:00
|
|
|
func (c *Conn) monCommand(args, inputBuffer []byte) ([]byte, string, error) {
|
2020-04-11 14:23:19 +00:00
|
|
|
ci := cutil.NewCommandInput([][]byte{args}, inputBuffer)
|
|
|
|
defer ci.Free()
|
2020-04-23 15:10:15 +00:00
|
|
|
co := cutil.NewCommandOutput().SetFreeFunc(radosBufferFree)
|
2020-04-11 14:23:19 +00:00
|
|
|
defer co.Free()
|
2020-04-09 11:52:39 +00:00
|
|
|
|
2020-04-11 14:23:19 +00:00
|
|
|
ret := C.rados_mon_command(
|
|
|
|
c.cluster,
|
|
|
|
(**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-04-09 11:52:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// PGCommand sends a command to one of the PGs
|
|
|
|
//
|
|
|
|
// Implements:
|
|
|
|
// int rados_pg_command(rados_t cluster, const char *pgstr,
|
|
|
|
// const char **cmd, size_t cmdlen,
|
|
|
|
// const char *inbuf, size_t inbuflen,
|
|
|
|
// char **outbuf, size_t *outbuflen,
|
|
|
|
// char **outs, size_t *outslen);
|
2020-04-09 14:42:29 +00:00
|
|
|
func (c *Conn) PGCommand(pgid []byte, args [][]byte) ([]byte, string, error) {
|
2020-04-09 11:52:39 +00:00
|
|
|
return c.pgCommand(pgid, args, nil)
|
|
|
|
}
|
|
|
|
|
|
|
|
// PGCommandWithInputBuffer sends a command to one of the PGs, with an input buffer
|
|
|
|
//
|
|
|
|
// Implements:
|
|
|
|
// int rados_pg_command(rados_t cluster, const char *pgstr,
|
|
|
|
// const char **cmd, size_t cmdlen,
|
|
|
|
// const char *inbuf, size_t inbuflen,
|
|
|
|
// char **outbuf, size_t *outbuflen,
|
|
|
|
// char **outs, size_t *outslen);
|
2020-04-09 14:42:29 +00:00
|
|
|
func (c *Conn) PGCommandWithInputBuffer(pgid []byte, args [][]byte, inputBuffer []byte) ([]byte, string, error) {
|
2020-04-09 11:52:39 +00:00
|
|
|
return c.pgCommand(pgid, args, inputBuffer)
|
|
|
|
}
|
|
|
|
|
2020-04-09 14:42:29 +00:00
|
|
|
func (c *Conn) pgCommand(pgid []byte, args [][]byte, inputBuffer []byte) ([]byte, string, error) {
|
2020-04-09 11:52:39 +00:00
|
|
|
name := C.CString(string(pgid))
|
|
|
|
defer C.free(unsafe.Pointer(name))
|
2020-04-11 14:23:19 +00:00
|
|
|
ci := cutil.NewCommandInput(args, inputBuffer)
|
|
|
|
defer ci.Free()
|
2020-04-23 15:10:15 +00:00
|
|
|
co := cutil.NewCommandOutput().SetFreeFunc(radosBufferFree)
|
2020-04-11 14:23:19 +00:00
|
|
|
defer co.Free()
|
2020-04-09 11:52:39 +00:00
|
|
|
|
2020-04-11 14:23:19 +00:00
|
|
|
ret := C.rados_pg_command(
|
|
|
|
c.cluster,
|
2020-04-09 11:52:39 +00:00
|
|
|
name,
|
2020-04-11 14:23:19 +00:00
|
|
|
(**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-04-09 11:52:39 +00:00
|
|
|
}
|
2020-04-09 17:59:50 +00:00
|
|
|
|
|
|
|
// MgrCommand sends a command to a ceph-mgr.
|
|
|
|
func (c *Conn) MgrCommand(args [][]byte) ([]byte, string, error) {
|
|
|
|
return c.mgrCommand(args, nil)
|
|
|
|
}
|
|
|
|
|
|
|
|
// MgrCommandWithInputBuffer sends a command, with an input buffer, to a ceph-mgr.
|
|
|
|
func (c *Conn) MgrCommandWithInputBuffer(args [][]byte, inputBuffer []byte) ([]byte, string, error) {
|
|
|
|
return c.mgrCommand(args, inputBuffer)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Implements:
|
|
|
|
// int rados_mgr_command(rados_t cluster, const char **cmd,
|
|
|
|
// size_t cmdlen, const char *inbuf,
|
|
|
|
// size_t inbuflen, char **outbuf,
|
|
|
|
// size_t *outbuflen, char **outs,
|
|
|
|
// size_t *outslen);
|
|
|
|
func (c *Conn) mgrCommand(args [][]byte, inputBuffer []byte) ([]byte, string, error) {
|
2020-04-11 14:23:19 +00:00
|
|
|
ci := cutil.NewCommandInput(args, inputBuffer)
|
|
|
|
defer ci.Free()
|
2020-04-23 15:10:15 +00:00
|
|
|
co := cutil.NewCommandOutput().SetFreeFunc(radosBufferFree)
|
2020-04-11 14:23:19 +00:00
|
|
|
defer co.Free()
|
2020-04-09 17:59:50 +00:00
|
|
|
|
|
|
|
ret := C.rados_mgr_command(
|
|
|
|
c.cluster,
|
2020-04-11 14:23:19 +00:00
|
|
|
(**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-04-09 17:59:50 +00:00
|
|
|
}
|