From da1e31354bda5cd8478862d44c0c92c0afdd096f Mon Sep 17 00:00:00 2001 From: Robert Vasek Date: Fri, 18 Oct 2024 17:57:42 +0200 Subject: [PATCH] rados: implement rados_getaddrs This commit implements binding for rados_getaddrs. Includes a unit test. Signed-off-by: Robert Vasek --- docs/api-status.json | 8 +++++++- docs/api-status.md | 1 + rados/rados_getaddrs.go | 30 ++++++++++++++++++++++++++++++ rados/rados_getaddrs_test.go | 15 +++++++++++++++ 4 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 rados/rados_getaddrs.go create mode 100644 rados/rados_getaddrs_test.go diff --git a/docs/api-status.json b/docs/api-status.json index 4cccad42e..4762f7119 100644 --- a/docs/api-status.json +++ b/docs/api-status.json @@ -1159,6 +1159,12 @@ "comment": "Exec executes an OSD class method on an object.\nSee rados_exec() in the RADOS C api documentation for a general description.\n\nImplements:\n\n\tvoid rados_write_op_exec(rados_write_op_t write_op,\n\t const char *cls,\n\t const char *method,\n\t const char *in_buf,\n\t size_t in_len,\n\t int *prval)\n", "added_in_version": "v0.29.0", "expected_stable_version": "v0.31.0" + }, + { + "name": "Conn.GetAddrs", + "comment": "GetAddrs returns the addresses of the RADOS session,\nsuitable for blocklisting.\n\nImplements:\n\n\tint rados_getaddrs(rados_t cluster, char **addrs)\n", + "added_in_version": "$NEXT_RELEASE", + "expected_stable_version": "$NEXT_RELEASE_STABLE" } ] }, @@ -2356,4 +2362,4 @@ } ] } -} +} \ No newline at end of file diff --git a/docs/api-status.md b/docs/api-status.md index be6b183d2..ba2a2deb9 100644 --- a/docs/api-status.md +++ b/docs/api-status.md @@ -19,6 +19,7 @@ Name | Added in Version | Expected Stable Version | ReadOpExecStep.Bytes | v0.29.0 | v0.31.0 | ReadOp.Exec | v0.29.0 | v0.31.0 | WriteOp.Exec | v0.29.0 | v0.31.0 | +Conn.GetAddrs | $NEXT_RELEASE | $NEXT_RELEASE_STABLE | ## Package: rbd diff --git a/rados/rados_getaddrs.go b/rados/rados_getaddrs.go new file mode 100644 index 000000000..093e373d4 --- /dev/null +++ b/rados/rados_getaddrs.go @@ -0,0 +1,30 @@ +//go:build ceph_preview + +package rados + +// #cgo LDFLAGS: -lrados +// #include +// #include +import "C" + +import ( + "unsafe" +) + +// GetAddrs returns the addresses of the RADOS session, +// suitable for blocklisting. +// +// Implements: +// +// int rados_getaddrs(rados_t cluster, char **addrs) +func (c *Conn) GetAddrs() (string, error) { + var cAddrs *C.char + defer C.free(unsafe.Pointer(cAddrs)) + + ret := C.rados_getaddrs(c.cluster, &cAddrs) + if ret < 0 { + return "", getError(ret) + } + + return C.GoString(cAddrs), nil +} diff --git a/rados/rados_getaddrs_test.go b/rados/rados_getaddrs_test.go new file mode 100644 index 000000000..909f6ef0d --- /dev/null +++ b/rados/rados_getaddrs_test.go @@ -0,0 +1,15 @@ +//go:build ceph_preview + +package rados + +import ( + "github.com/stretchr/testify/assert" +) + +func (suite *RadosTestSuite) TestGetAddrs() { + suite.SetupConnection() + + addrs, err := suite.conn.GetAddrs() + assert.NoError(suite.T(), err) + assert.NotEmpty(suite.T(), addrs, "rados_getaddrs") +}