mirror of https://github.com/ceph/go-ceph
rados: implement binding for rados_write_op_setxattr
This commit implements binding for rados_write_op_setxattr RADOS Write operation. Includes a unit test. Signed-off-by: Robert Vasek <robert.vasek@cern.ch>
This commit is contained in:
parent
c4cfd15e12
commit
4cf39ce07b
|
@ -970,6 +970,12 @@
|
||||||
"comment": "Ensure that the object exists and that its internal version number is equal\nto \"ver\" before writing. \"ver\" should be a version number previously\nobtained with IOContext.GetLastVersion().\n PREVIEW\n\nImplements:\n void rados_read_op_assert_version(rados_read_op_t read_op,\n uint64_t ver)\n",
|
"comment": "Ensure that the object exists and that its internal version number is equal\nto \"ver\" before writing. \"ver\" should be a version number previously\nobtained with IOContext.GetLastVersion().\n PREVIEW\n\nImplements:\n void rados_read_op_assert_version(rados_read_op_t read_op,\n uint64_t ver)\n",
|
||||||
"added_in_version": "v0.14.0",
|
"added_in_version": "v0.14.0",
|
||||||
"expected_stable_version": "v0.16.0"
|
"expected_stable_version": "v0.16.0"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "WriteOp.SetXattr",
|
||||||
|
"comment": "Set an xattr.\n PREVIEW\n\nImplements:\n void rados_write_op_setxattr(rados_write_op_t write_op,\n const char * name,\n const char * value,\n size_t value_len)\n",
|
||||||
|
"added_in_version": "v0.14.0",
|
||||||
|
"expected_stable_version": "v0.16.0"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|
|
@ -24,6 +24,7 @@ ReadOp.Read | v0.14.0 | v0.16.0 |
|
||||||
WriteOp.Remove | v0.14.0 | v0.16.0 |
|
WriteOp.Remove | v0.14.0 | v0.16.0 |
|
||||||
ReadOp.AssertVersion | v0.14.0 | v0.16.0 |
|
ReadOp.AssertVersion | v0.14.0 | v0.16.0 |
|
||||||
WriteOp.AssertVersion | v0.14.0 | v0.16.0 |
|
WriteOp.AssertVersion | v0.14.0 | v0.16.0 |
|
||||||
|
WriteOp.SetXattr | v0.14.0 | v0.16.0 |
|
||||||
|
|
||||||
## Package: rbd
|
## Package: rbd
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,34 @@
|
||||||
|
//go:build ceph_preview
|
||||||
|
// +build ceph_preview
|
||||||
|
|
||||||
|
package rados
|
||||||
|
|
||||||
|
// #cgo LDFLAGS: -lrados
|
||||||
|
// #include <rados/librados.h>
|
||||||
|
// #include <stdlib.h>
|
||||||
|
//
|
||||||
|
import "C"
|
||||||
|
|
||||||
|
import (
|
||||||
|
"unsafe"
|
||||||
|
)
|
||||||
|
|
||||||
|
// SetXattr sets an xattr.
|
||||||
|
// PREVIEW
|
||||||
|
//
|
||||||
|
// Implements:
|
||||||
|
// void rados_write_op_setxattr(rados_write_op_t write_op,
|
||||||
|
// const char * name,
|
||||||
|
// const char * value,
|
||||||
|
// size_t value_len)
|
||||||
|
func (w *WriteOp) SetXattr(name string, value []byte) {
|
||||||
|
cName := C.CString(name)
|
||||||
|
defer C.free(unsafe.Pointer(cName))
|
||||||
|
|
||||||
|
C.rados_write_op_setxattr(
|
||||||
|
w.op,
|
||||||
|
cName,
|
||||||
|
(*C.char)(unsafe.Pointer(&value[0])),
|
||||||
|
C.size_t(len(value)),
|
||||||
|
)
|
||||||
|
}
|
|
@ -0,0 +1,32 @@
|
||||||
|
//go:build ceph_preview
|
||||||
|
// +build ceph_preview
|
||||||
|
|
||||||
|
package rados
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (suite *RadosTestSuite) TestWriteOpSetXattr() {
|
||||||
|
suite.SetupConnection()
|
||||||
|
ta := assert.New(suite.T())
|
||||||
|
|
||||||
|
var (
|
||||||
|
oid = "TestWriteOpSetXattr"
|
||||||
|
xattrName = "attrname"
|
||||||
|
xattrValue = []byte("attrvalue")
|
||||||
|
)
|
||||||
|
|
||||||
|
// Create an object and populate it with data.
|
||||||
|
op1 := CreateWriteOp()
|
||||||
|
defer op1.Release()
|
||||||
|
op1.Create(CreateIdempotent)
|
||||||
|
op1.SetXattr(xattrName, xattrValue)
|
||||||
|
err := op1.Operate(suite.ioctx, oid, OperationNoFlag)
|
||||||
|
ta.NoError(err)
|
||||||
|
|
||||||
|
// Read object's xattrs and compare.
|
||||||
|
actualXattrs, err := suite.ioctx.ListXattrs(oid)
|
||||||
|
ta.NoError(err)
|
||||||
|
ta.Equal(map[string][]byte{xattrName: xattrValue}, actualXattrs)
|
||||||
|
}
|
Loading…
Reference in New Issue