From 872e50a2e158e23ed0da0fbe33423db7d851870b Mon Sep 17 00:00:00 2001 From: Sven Anderson Date: Mon, 11 Oct 2021 23:09:35 +0900 Subject: [PATCH 1/2] rados: C-allocate return parameters in GetOmapStep Signed-off-by: Sven Anderson --- rados/omap.go | 16 ++++++++++------ rados/read_op.go | 4 ++-- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/rados/omap.go b/rados/omap.go index e71f84b67f..c2756ce327 100644 --- a/rados/omap.go +++ b/rados/omap.go @@ -99,8 +99,8 @@ type GetOmapStep struct { // C returned data: iter C.rados_omap_iter_t - more C.uchar - rval C.int + more *C.uchar + rval *C.int // internal state: @@ -116,6 +116,8 @@ func newGetOmapStep(startAfter, filterPrefix string, maxReturn uint64) *GetOmapS maxReturn: maxReturn, cStartAfter: C.CString(startAfter), cFilterPrefix: C.CString(filterPrefix), + more: (*C.uchar)(C.malloc(C.sizeof_uchar)), + rval: (*C.int)(C.malloc(C.sizeof_int)), } runtime.SetFinalizer(gos, opStepFinalizer) return gos @@ -127,8 +129,10 @@ func (gos *GetOmapStep) free() { C.rados_omap_get_end(gos.iter) } gos.iter = nil - gos.more = 0 - gos.rval = 0 + C.free(unsafe.Pointer(gos.more)) + gos.more = nil + C.free(unsafe.Pointer(gos.rval)) + gos.rval = nil C.free(unsafe.Pointer(gos.cStartAfter)) gos.cStartAfter = nil C.free(unsafe.Pointer(gos.cFilterPrefix)) @@ -136,7 +140,7 @@ func (gos *GetOmapStep) free() { } func (gos *GetOmapStep) update() error { - err := getError(gos.rval) + err := getError(*gos.rval) gos.canIterate = (err == nil) return err } @@ -168,7 +172,7 @@ func (gos *GetOmapStep) Next() (*OmapKeyValue, error) { func (gos *GetOmapStep) More() bool { // tad bit hacky, but go can't automatically convert from // unsigned char to bool - return gos.more != 0 + return *gos.more != 0 } // removeOmapKeysStep is a write operation step used to track state, especially diff --git a/rados/read_op.go b/rados/read_op.go index 4f95e630c9..74f2eb2bd4 100644 --- a/rados/read_op.go +++ b/rados/read_op.go @@ -77,8 +77,8 @@ func (r *ReadOp) GetOmapValues(startAfter, filterPrefix string, maxReturn uint64 gos.cFilterPrefix, C.uint64_t(gos.maxReturn), &gos.iter, - &gos.more, - &gos.rval, + gos.more, + gos.rval, ) return gos } From 8d9865e618ca7f552801416817a69e5e6500049f Mon Sep 17 00:00:00 2001 From: Sven Anderson Date: Tue, 16 Nov 2021 00:28:50 +0900 Subject: [PATCH 2/2] rados: add comment about missing pinning in writeStep Signed-off-by: Sven Anderson --- rados/write_step.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rados/write_step.go b/rados/write_step.go index 7ece03f128..3774a6e9fa 100644 --- a/rados/write_step.go +++ b/rados/write_step.go @@ -25,7 +25,7 @@ type writeStep struct { func newWriteStep(b []byte, writeLen, offset uint64) *writeStep { return &writeStep{ b: b, - cBuffer: (*C.char)(unsafe.Pointer(&b[0])), + cBuffer: (*C.char)(unsafe.Pointer(&b[0])), // TODO: must be pinned cDataLen: C.size_t(len(b)), cWriteLen: C.size_t(writeLen), cOffset: C.uint64_t(offset),