コード例 #1
0
ファイル: conn.go プロジェクト: Xmagicer/origin
// GetConfigOption returns the value of the Ceph configuration option
// identified by the given name.
func (c *Conn) GetConfigOption(name string) (value string, err error) {
	buf := make([]byte, 4096)
	c_name := C.CString(name)
	defer C.free(unsafe.Pointer(c_name))
	ret := int(C.rados_conf_get(c.cluster, c_name,
		(*C.char)(unsafe.Pointer(&buf[0])), C.size_t(len(buf))))
	// FIXME: ret may be -ENAMETOOLONG if the buffer is not large enough. We
	// can handle this case, but we need a reliable way to test for
	// -ENAMETOOLONG constant. Will the syscall/Errno stuff in Go help?
	if ret == 0 {
		value = C.GoString((*C.char)(unsafe.Pointer(&buf[0])))
		return value, nil
	} else {
		return "", RadosError(ret)
	}
}
コード例 #2
0
ファイル: cluster.go プロジェクト: objStorage/grados
// GetConfig returns the configuration value of the given configName.
func (cluster *Cluster) GetConfigValue(configName string) (string, error) {
	cn := C.CString(configName)
	defer freeString(cn)
	bufLen := 8
	for {
		bufAddr := bufferAddress(bufLen)
		ret := C.rados_conf_get(cluster.handle, cn, bufAddr, C.size_t(bufLen))
		if int(ret) == -int(syscall.ENAMETOOLONG) {
			bufLen *= 2
			continue
		}
		if ret < 0 {
			err := toRadosError(ret)
			err.Message = fmt.Sprintf("Unable to get config value of %s.", configName)
			return "", err
		}
		value := C.GoString(bufAddr)
		return value, nil
	}
}