// New returns a RADOS cluster handle that is used to create IO // Contexts and perform other RADOS actions. If configFile is // non-empty, RADOS will look for its configuration there, otherwise // the default paths will be searched (e.g., /etc/ceph/ceph.conf). // // TODO: allow caller to specify Ceph user. func New(configFile string) (*Rados, error) { r := &Rados{} var cerr C.int if cerr = C.rados_create(&r.rados, nil); cerr < 0 { return nil, radosReturnCodeError(cerr) } if configFile == "" { cerr = C.rados_conf_read_file(r.rados, nil) } else { cconfigFile := C.CString(configFile) defer C.free(unsafe.Pointer(cconfigFile)) cerr = C.rados_conf_read_file(r.rados, cconfigFile) } if cerr < 0 { return nil, radosReturnCodeError(cerr) } if cerr = C.rados_connect(r.rados); cerr < 0 { return nil, radosReturnCodeError(cerr) } // Fill in cluster statistics if err := r.Stat(); err != nil { r.Release() return nil, err } return r, nil }
func (rc *RadosCluster) Connect(conf string, pool string) (err error) { c_conf := C.CString(conf) c_pool := C.CString(pool) defer C.free(unsafe.Pointer(c_conf)) defer C.free(unsafe.Pointer(c_pool)) ret := C.rados_create(&rc.Cluster, nil) if ret < 0 { return errors.New("create cluster failed") } ret = C.rados_conf_read_file(rc.Cluster, c_conf) if ret < 0 { return errors.New("read conf file failed") } ret = C.rados_connect(rc.Cluster) if ret < 0 { return errors.New("connect to cluster failed") } ret = C.rados_ioctx_create(rc.Cluster, c_pool, &rc.Ioctx) if ret < 0 { return errors.New("create ioctx failed") } return nil }
// ReadDefaultConfigFile configures the connection using a Ceph configuration // file located at default locations. func (c *Conn) ReadDefaultConfigFile() error { ret := C.rados_conf_read_file(c.cluster, nil) if ret == 0 { return nil } else { return RadosError(int(ret)) } }
/* Configure the cluster handle using a Ceph config file. If path is NULL, the default locations are searched, and the first found is used. The locations are: $CEPH_CONF (environment variable) /etc/ceph/ceph.conf ~/.ceph/config ceph.conf (in the current working directory) */ func (r *Rados) ClusterAutoConfig() error { cerr := C.rados_conf_read_file(*r.cluster, nil) if cerr < 0 { return errors.New("read config failed") } return nil }
// ReadConfigFile configures the connection using a Ceph configuration file. func (c *Conn) ReadConfigFile(path string) error { c_path := C.CString(path) defer C.free(unsafe.Pointer(c_path)) ret := C.rados_conf_read_file(c.cluster, c_path) if ret == 0 { return nil } else { return RadosError(int(ret)) } }
func (r *Rados) ClusterConfig(filename string) error { cfilename := C.CString(filename) defer func() { C.free(unsafe.Pointer(cfilename)) }() cerr := C.rados_conf_read_file(*(r.cluster), cfilename) if cerr < 0 { return errors.New("read config failed") } return nil }
func getRados(username string) (C.rados_t, error) { var cluster C.rados_t str := C.CString(username) defer C.free(unsafe.Pointer(str)) if i := C.rados_create(&cluster, str); i < 0 { return nil, strerror(i) } if i := C.rados_conf_read_file(cluster, nil); i < 0 { return nil, strerror(i) } if i := C.rados_connect(cluster); i != 0 { return nil, strerror(i) } return cluster, nil }
func (conn *Connection) configure() error { // use default configuration if conn.ConfigFile == "" && !conn.ParseArgs && conn.ConfigEnv == "" && len(conn.ConfigMap) == 0 { ret := C.rados_conf_read_file(conn.cluster.handle, nil) if err := toRadosError(ret); err != nil { err.Message = "Unable to load default configuration." return err } return nil } // use config file if specified if conn.ConfigFile != "" { config := C.CString(conn.ConfigFile) defer freeString(config) ret := C.rados_conf_read_file(conn.cluster.handle, config) if err := toRadosError(ret); err != nil { err.Message = "Unable to load configuration file. Make sure it exists and is accessible." return err } } // use config env if specified if conn.ConfigEnv != "" { env := C.CString(conn.ConfigEnv) defer freeString(env) ret := C.rados_conf_parse_env(conn.cluster.handle, env) if err := toRadosError(ret); err != nil { err.Message = "Unable to load configuration from env." return err } } // use config from args if conn.ParseArgs { argc := C.int(len(os.Args)) argv := make([]*C.char, argc) for i, arg := range os.Args { argv[i] = C.CString(arg) defer freeString(argv[i+1]) } ret := C.rados_conf_parse_argv(conn.cluster.handle, argc, &argv[0]) if err := toRadosError(ret); err != nil { err.Message = "Unable to load configuration from args." return err } } if conn.ConfigMap != nil || len(conn.ConfigMap) > 0 { for k, v := range conn.ConfigMap { key := C.CString(k) val := C.CString(v) defer freeString(key) defer freeString(val) ret := C.rados_conf_set(conn.cluster.handle, key, val) if err := toRadosError(ret); err != nil { err.Message = fmt.Sprintf("Unable to load config %s=%s", key, val) return err } } } return nil }