// List all the images for the pool. func (p *Pool) List() ([]string, error) { buf := make([]byte, 1024*1024) // FIXME number of entries, but it's an undocumented call so I don't know for sure sizeT := C.size_t(1024 * 1024) var i C.int if i = C.rbd_list(p.ioctx, (*C.char)(unsafe.Pointer(&buf[0])), &sizeT); i < 0 { return nil, strerror(i) } // the returned string is multiple null terminated strings with a double null // at the end. Hence GoStringN. items := strings.Split(C.GoStringN((*C.char)(unsafe.Pointer(&buf[0])), i), string([]byte{0})) return items[:len(items)-1], nil }
// List all the images for the pool. func (p *Pool) List() ([]string, error) { list := C.CString("") defer func() { C.free(unsafe.Pointer(list)) }() // FIXME number of entries, but it's an undocumented call so I don't know for sure sizeT := C.size_t(1024 * 1024) var i C.int if i = C.rbd_list(p.ioctx, list, &sizeT); i < 0 { return nil, strerror(i) } // the returned string is multiple null terminated strings with a double null // at the end. Hence GoStringN. items := strings.Split(C.GoStringN(list, i), string([]byte{0})) return items[:len(items)-1], nil }
// GetImageNames returns the list of current RBD images. func GetImageNames(ioctx *rados.IOContext) (names []string, err error) { buf := make([]byte, 4096) for { size := C.size_t(len(buf)) ret := C.rbd_list(C.rados_ioctx_t(ioctx.Pointer()), (*C.char)(unsafe.Pointer(&buf[0])), &size) if ret == -34 { // FIXME buf = make([]byte, size) continue } else if ret < 0 { return nil, RBDError(ret) } tmp := bytes.Split(buf[:size-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 } }