mirror of
https://github.com/ceph/go-ceph
synced 2024-12-23 06:33:24 +00:00
lib: add conn.ListPools
Signed-off-by: Noah Watkins <noahwatkins@gmail.com>
This commit is contained in:
parent
8ba5ad18e5
commit
eb1efa6edb
29
conn.go
29
conn.go
@ -6,6 +6,7 @@ package rados
|
||||
import "C"
|
||||
|
||||
import "unsafe"
|
||||
import "bytes"
|
||||
|
||||
type Conn struct {
|
||||
cluster C.rados_t
|
||||
@ -75,3 +76,31 @@ func (c *Conn) OpenPool(pool string) (*Pool, error) {
|
||||
return nil, RadosError(int(ret))
|
||||
}
|
||||
}
|
||||
|
||||
// ListPools returns the current list of pool names. It returns an error, if
|
||||
// any.
|
||||
func (c *Conn) ListPools() (names []string, err error) {
|
||||
buf := make([]byte, 4096)
|
||||
for {
|
||||
ret := int(C.rados_pool_list(c.cluster,
|
||||
(*C.char)(unsafe.Pointer(&buf[0])), C.size_t(len(buf))))
|
||||
if ret < 0 {
|
||||
return nil, RadosError(int(ret))
|
||||
}
|
||||
|
||||
if ret > len(buf) {
|
||||
buf = make([]byte, ret)
|
||||
continue
|
||||
}
|
||||
|
||||
tmp := bytes.SplitAfter(buf[:ret-1], []byte{0})
|
||||
for _, s := range tmp {
|
||||
if len(s) > 0 {
|
||||
name := C.GoString((*C.char)(unsafe.Pointer(&s[0])))
|
||||
names = append(names, name)
|
||||
}
|
||||
}
|
||||
|
||||
return names, nil
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user