Skip to content

Commit

Permalink
rados: implement rados_getaddrs
Browse files Browse the repository at this point in the history
This commit implements binding for rados_getaddrs.

Includes a unit test.

Signed-off-by: Robert Vasek <[email protected]>
  • Loading branch information
Robert Vasek committed Oct 18, 2024
1 parent 10ec360 commit 25f15f2
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 1 deletion.
8 changes: 7 additions & 1 deletion docs/api-status.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 wraps the function to get the addresses of\nthe RADOS session, suitable 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"
}
]
},
Expand Down Expand Up @@ -2356,4 +2362,4 @@
}
]
}
}
}
1 change: 1 addition & 0 deletions docs/api-status.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
31 changes: 31 additions & 0 deletions rados/rados_getaddrs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//go:build ceph_preview
// +build ceph_preview

package rados

// #cgo LDFLAGS: -lrados
// #include <stdlib.h>
// #include <rados/librados.h>
import "C"

import (
"unsafe"
)

// GetAddrs wraps the function to get 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
}
16 changes: 16 additions & 0 deletions rados/rados_getaddrs_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//go:build ceph_preview
// +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")
}

0 comments on commit 25f15f2

Please sign in to comment.