// Remove the specified `keys` from the omap `oid` func (ioctx *IOContext) RmOmapKeys(oid string, keys []string) error { c_oid := C.CString(oid) defer C.free(unsafe.Pointer(c_oid)) var c *C.char ptrSize := unsafe.Sizeof(c) c_keys := C.malloc(C.size_t(len(keys)) * C.size_t(ptrSize)) defer C.free(unsafe.Pointer(c_keys)) i := 0 for _, key := range keys { c_key_ptr := (**C.char)(unsafe.Pointer(uintptr(c_keys) + uintptr(i)*ptrSize)) *c_key_ptr = C.CString(key) defer C.free(unsafe.Pointer(*c_key_ptr)) i++ } op := C.rados_create_write_op() C.rados_write_op_omap_rm_keys( op, (**C.char)(c_keys), C.size_t(len(keys))) ret := C.rados_write_op_operate(op, ioctx.ioctx, c_oid, nil, 0) C.rados_release_write_op(op) return GetRadosError(ret) }
// Append the map `pairs` to the omap `oid` func (ioctx *IOContext) SetOmap(oid string, pairs map[string][]byte) error { c_oid := C.CString(oid) defer C.free(unsafe.Pointer(c_oid)) var s C.size_t var c *C.char ptrSize := unsafe.Sizeof(c) c_keys := C.malloc(C.size_t(len(pairs)) * C.size_t(ptrSize)) c_values := C.malloc(C.size_t(len(pairs)) * C.size_t(ptrSize)) c_lengths := C.malloc(C.size_t(len(pairs)) * C.size_t(unsafe.Sizeof(s))) defer C.free(unsafe.Pointer(c_keys)) defer C.free(unsafe.Pointer(c_values)) defer C.free(unsafe.Pointer(c_lengths)) i := 0 for key, value := range pairs { // key c_key_ptr := (**C.char)(unsafe.Pointer(uintptr(c_keys) + uintptr(i)*ptrSize)) *c_key_ptr = C.CString(key) defer C.free(unsafe.Pointer(*c_key_ptr)) // value and its length c_value_ptr := (**C.char)(unsafe.Pointer(uintptr(c_values) + uintptr(i)*ptrSize)) var c_length C.size_t if len(value) > 0 { *c_value_ptr = (*C.char)(unsafe.Pointer(&value[0])) c_length = C.size_t(len(value)) } else { *c_value_ptr = nil c_length = C.size_t(0) } c_length_ptr := (*C.size_t)(unsafe.Pointer(uintptr(c_lengths) + uintptr(i)*ptrSize)) *c_length_ptr = c_length i++ } op := C.rados_create_write_op() C.rados_write_op_omap_set( op, (**C.char)(c_keys), (**C.char)(c_values), (*C.size_t)(c_lengths), C.size_t(len(pairs))) ret := C.rados_write_op_operate(op, ioctx.ioctx, c_oid, nil, 0) C.rados_release_write_op(op) if ret == 0 { return nil } else { return RadosError(int(ret)) } }
// Clear the omap `oid` func (ioctx *IOContext) CleanOmap(oid string) error { c_oid := C.CString(oid) defer C.free(unsafe.Pointer(c_oid)) op := C.rados_create_write_op() C.rados_write_op_omap_clear(op) ret := C.rados_write_op_operate(op, ioctx.ioctx, c_oid, nil, 0) C.rados_release_write_op(op) return GetRadosError(ret) }
func (ioctx *IOContext) WriteTaggedFull(oid string, tagName string, tag string, newTag string, data []byte) error { c_oid := C.CString(oid) c_tagName := C.CString(tagName) defer C.free(unsafe.Pointer(c_oid)) defer C.free(unsafe.Pointer(c_tagName)) b_tag := []byte(tag) b_newTag := []byte(newTag) op := C.rados_create_write_op() if tag == "" || tag == "0" { C.rados_write_op_create( op, LIBRADOS_CREATE_EXCLUSIVE, nil) } else { C.rados_write_op_cmpxattr( op, c_tagName, LIBRADOS_CMPXATTR_OP_EQ, (*C.char)(unsafe.Pointer(&b_tag[0])), (C.size_t)(len(b_tag))) } C.rados_write_op_write_full( op, (*C.char)(unsafe.Pointer(&data[0])), (C.size_t)(len(data))) C.rados_write_op_setxattr( op, c_tagName, (*C.char)(unsafe.Pointer(&b_newTag[0])), (C.size_t)(len(b_newTag))) ret := C.rados_write_op_operate(op, ioctx.ioctx, c_oid, nil, 0) C.rados_release_write_op(op) return GetRadosError(ret) }
func (wo *WriteOperation) Operate(object *Object, modifiedTime *time.Time, flags ...LibradosOperation) error { oid := C.CString(object.name) defer freeString(oid) var mtime C.time_t if modifiedTime != nil { mtime = C.time_t(modifiedTime.Unix()) } var f C.int = 0 for _, flag := range flags { f |= C.int(flag) } ret := C.rados_write_op_operate(wo.opContext, wo.ioContext, oid, &mtime, f) if err := toRadosError(ret); err != nil { err.Message = "Unable to perform write operation." return err } return nil }