mirror of https://github.com/ceph/go-ceph
rados: add Write, WriteFull, and WriteSame WriteOp functions
Add Write implementing rados_write_op_write. Add WriteFull implementing rados_write_op_write_full. Add WriteSame implementing rados_write_op_writesame. These are some of the basic functions needed to write data to a rados object using a WriteOp. Signed-off-by: John Mulligan <jmulligan@redhat.com>
This commit is contained in:
parent
e4e1257768
commit
c8d8d8c364
|
@ -124,3 +124,56 @@ func (w *WriteOp) CleanOmap() {
|
||||||
func (w *WriteOp) AssertExists() {
|
func (w *WriteOp) AssertExists() {
|
||||||
C.rados_write_op_assert_exists(w.op)
|
C.rados_write_op_assert_exists(w.op)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Write a given byte slice at the supplied offset.
|
||||||
|
//
|
||||||
|
// Implements:
|
||||||
|
// void rados_write_op_write(rados_write_op_t write_op,
|
||||||
|
// const char *buffer,
|
||||||
|
// size_t len,
|
||||||
|
// uint64_t offset);
|
||||||
|
func (w *WriteOp) Write(b []byte, offset uint64) {
|
||||||
|
oe := newWriteStep(b, 0, offset)
|
||||||
|
w.steps = append(w.steps, oe)
|
||||||
|
C.rados_write_op_write(
|
||||||
|
w.op,
|
||||||
|
oe.cBuffer,
|
||||||
|
oe.cDataLen,
|
||||||
|
oe.cOffset)
|
||||||
|
}
|
||||||
|
|
||||||
|
// WriteFull writes a given byte slice as the whole object,
|
||||||
|
// atomically replacing it.
|
||||||
|
//
|
||||||
|
// Implements:
|
||||||
|
// void rados_write_op_write_full(rados_write_op_t write_op,
|
||||||
|
// const char *buffer,
|
||||||
|
// size_t len);
|
||||||
|
func (w *WriteOp) WriteFull(b []byte) {
|
||||||
|
oe := newWriteStep(b, 0, 0)
|
||||||
|
w.steps = append(w.steps, oe)
|
||||||
|
C.rados_write_op_write_full(
|
||||||
|
w.op,
|
||||||
|
oe.cBuffer,
|
||||||
|
oe.cDataLen)
|
||||||
|
}
|
||||||
|
|
||||||
|
// WriteSame write a given byte slice to the object multiple times, until
|
||||||
|
// writeLen is satisfied.
|
||||||
|
//
|
||||||
|
// Implements:
|
||||||
|
// void rados_write_op_writesame(rados_write_op_t write_op,
|
||||||
|
// const char *buffer,
|
||||||
|
// size_t data_len,
|
||||||
|
// size_t write_len,
|
||||||
|
// uint64_t offset);
|
||||||
|
func (w *WriteOp) WriteSame(b []byte, writeLen, offset uint64) {
|
||||||
|
oe := newWriteStep(b, writeLen, offset)
|
||||||
|
w.steps = append(w.steps, oe)
|
||||||
|
C.rados_write_op_writesame(
|
||||||
|
w.op,
|
||||||
|
oe.cBuffer,
|
||||||
|
oe.cDataLen,
|
||||||
|
oe.cWriteLen,
|
||||||
|
oe.cOffset)
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,33 @@
|
||||||
|
package rados
|
||||||
|
|
||||||
|
// #include <stdint.h>
|
||||||
|
import "C"
|
||||||
|
|
||||||
|
import (
|
||||||
|
"unsafe"
|
||||||
|
)
|
||||||
|
|
||||||
|
type writeStep struct {
|
||||||
|
withoutUpdate
|
||||||
|
withoutFree
|
||||||
|
// the c pointer utilizes the Go byteslice data and no free is needed
|
||||||
|
|
||||||
|
// inputs:
|
||||||
|
b []byte
|
||||||
|
|
||||||
|
// arguments:
|
||||||
|
cBuffer *C.char
|
||||||
|
cDataLen C.size_t
|
||||||
|
cWriteLen C.size_t
|
||||||
|
cOffset C.uint64_t
|
||||||
|
}
|
||||||
|
|
||||||
|
func newWriteStep(b []byte, writeLen, offset uint64) *writeStep {
|
||||||
|
return &writeStep{
|
||||||
|
b: b,
|
||||||
|
cBuffer: (*C.char)(unsafe.Pointer(&b[0])),
|
||||||
|
cDataLen: C.size_t(len(b)),
|
||||||
|
cWriteLen: C.size_t(writeLen),
|
||||||
|
cOffset: C.uint64_t(offset),
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue