-
Notifications
You must be signed in to change notification settings - Fork 257
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rados: implement binding for rados_write_op_cmpext
This commit implements binding for rados_write_op_cmpext RADOS Write operation. Includes a unit test. Signed-off-by: Robert Vasek <[email protected]>
- Loading branch information
Showing
5 changed files
with
128 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
//go:build ceph_preview | ||
// +build ceph_preview | ||
|
||
package rados | ||
|
||
// #cgo LDFLAGS: -lrados | ||
// #include <rados/librados.h> | ||
// #include <stdlib.h> | ||
// | ||
import "C" | ||
|
||
import ( | ||
"unsafe" | ||
|
||
"github.com/ceph/go-ceph/internal/cutil" | ||
) | ||
|
||
// WriteOpCmpExtStep holds result of the CmpExt write operation. | ||
// Result is valid only after Operate() was called. | ||
type WriteOpCmpExtStep struct { | ||
// C returned data: | ||
prval *C.int | ||
|
||
// Result of the CmpExt write operation. | ||
Result int | ||
} | ||
|
||
func (s *WriteOpCmpExtStep) update() error { | ||
s.Result = (int)(*s.prval) | ||
return nil | ||
} | ||
|
||
func (s *WriteOpCmpExtStep) free() { | ||
C.free(unsafe.Pointer(s.prval)) | ||
s.prval = nil | ||
} | ||
|
||
func newWriteOpCmpExtStep() *WriteOpCmpExtStep { | ||
return &WriteOpCmpExtStep{ | ||
prval: (*C.int)(C.malloc(cutil.IntSize)), | ||
} | ||
} | ||
|
||
// CmpExt ensures that given object range (extent) satisfies comparison. | ||
// PREVIEW | ||
// | ||
// Implements: | ||
// void rados_write_op_cmpext(rados_write_op_t write_op, | ||
// const char * cmp_buf, | ||
// size_t cmp_len, | ||
// uint64_t off, | ||
// int * prval); | ||
func (w *WriteOp) CmpExt(b []byte, offset uint64) *WriteOpCmpExtStep { | ||
oe := newWriteStep(b, 0, offset) | ||
cmpExtStep := newWriteOpCmpExtStep() | ||
w.steps = append(w.steps, oe, cmpExtStep) | ||
C.rados_write_op_cmpext( | ||
w.op, | ||
oe.cBuffer, | ||
oe.cDataLen, | ||
oe.cOffset, | ||
cmpExtStep.prval) | ||
|
||
return cmpExtStep | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
//go:build ceph_preview | ||
// +build ceph_preview | ||
|
||
package rados | ||
|
||
import ( | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func (suite *RadosTestSuite) TestWriteOpCmpExt() { | ||
suite.SetupConnection() | ||
ta := assert.New(suite.T()) | ||
|
||
oid := "TestWriteOpCmpExt" | ||
data := []byte("compare this") | ||
|
||
// Create an object and populate it with data. | ||
op1 := CreateWriteOp() | ||
defer op1.Release() | ||
op1.Create(CreateIdempotent) | ||
op1.WriteFull([]byte(data)) | ||
err := op1.Operate(suite.ioctx, oid, OperationNoFlag) | ||
ta.NoError(err) | ||
|
||
// Compare contents of the object. Should succeed. | ||
op2 := CreateWriteOp() | ||
defer op2.Release() | ||
cmpExtRes1 := op2.CmpExt(data, 0) | ||
err = op2.Operate(suite.ioctx, oid, OperationNoFlag) | ||
ta.NoError(err) | ||
ta.Equal(cmpExtRes1.Result, int(0)) | ||
|
||
// Compare contents of the object. Should fail. | ||
op3 := CreateWriteOp() | ||
defer op3.Release() | ||
cmpExtRes2 := op3.CmpExt([]byte("xxx"), 0) | ||
err = op3.Operate(suite.ioctx, oid, OperationNoFlag) | ||
ta.Error(err) | ||
ta.NotEqual(cmpExtRes2.Result, int(0)) | ||
} |