示例#1
0
文件: conn.go 项目: Xmagicer/origin
// ListPools returns the names of all existing pools.
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
	}
}
示例#2
0
// ListPools returns all the pools in the ceph cluster.
func (cluster *Cluster) ListPools() ([]string, error) {
	bufLen := 4096
	for {
		bufAddr := bufferAddress(bufLen)
		ret := C.rados_pool_list(cluster.handle, bufAddr, C.size_t(bufLen))
		if ret < 0 {
			err := toRadosError(ret)
			err.Message = "Unable to retrieve pool list"
			return nil, err
		}

		if int(ret) > bufLen {
			bufLen = int(ret)
			continue
		}

		pools := bufToStringSlice(bufAddr, ret)
		return pools, nil
	}
}
示例#3
0
// ListPools retuns a list of pools in the given RADOS cluster as
// a slice of strings.
func (r *Rados) ListPools() ([]string, error) {
	var buf []byte
	bufSize := 256 // Initial guess at amount of space we need

	// Get the list of pools from RADOS. Note we may need to
	// retry if our initial buffer size isn't big enough to
	// hold all pools.
	for {
		buf = make([]byte, bufSize)
		cdata, cdatalen := byteSliceToBuffer(buf)

		// rados_pool_list() returns the number of bytes needed
		// to return all pools.
		cbufsize := C.rados_pool_list(r.rados, cdata, cdatalen)

		if cbufsize < 0 {
			return nil, radosReturnCodeError(cbufsize)
		} else if int(cbufsize) > bufSize {
			// We didn't have enough space -- try again
			bufSize = int(cbufsize)
			continue
		}

		break
	}

	// rados_pool_list() returns an array strings separated by NULL bytes
	// with two NULL bytes at the end. Break these into individual strings.
	pools := make([]string, 0)
	poolsBuf := bytes.Split(buf, []byte{0})
	for i, _ := range poolsBuf {
		if len(poolsBuf[i]) == 0 {
			continue
		}
		pools = append(pools, string(poolsBuf[i]))
	}

	return pools, nil
}