Пример #1
0
// 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
}
Пример #2
0
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
}
Пример #3
0
// Connect establishes a connection to a RADOS cluster. It returns an error,
// if any.
func (c *Conn) Connect() error {
	ret := C.rados_connect(c.cluster)
	if ret == 0 {
		return nil
	} else {
		return RadosError(int(ret))
	}
}
Пример #4
0
func (r *Rados) ClusterConnect() error {
	cerr := C.rados_connect(*r.cluster)
	if cerr < 0 {
		log.Println("error is", C.GoString(C.strerror(-cerr)))
		return errors.New("connect to ceph failed")
	}

	return nil
}
Пример #5
0
// Connect will connect to the cluster based on the values it contains.
func (conn *Connection) Connect() (*Cluster, error) {
	if err := conn.createClusterHandle(); err != nil {
		return nil, err
	}

	if err := conn.configure(); err != nil {
		return nil, err
	}

	ret := C.rados_connect(conn.cluster.handle)
	if err := toRadosError(ret); err != nil {
		err.Message = fmt.Sprintf("Unable to connect to cluster. Make sure cluster is accessible and configuration is correct. %v", conn)
		return nil, err
	}
	return conn.cluster, nil
}
Пример #6
0
func ConnectWithExistingConfig(config *ClusterConfig) (*Cluster, error) {
	conn := &Connection{
		cluster: new(Cluster),
	}
	ret := C.rados_create_with_context(&conn.cluster.handle, config.context)
	if err := toRadosError(ret); err != nil {
		err.Message = "Unable to create cluster handle with existing config context"
		return nil, err
	}

	ret = C.rados_connect(conn.cluster.handle)
	if err := toRadosError(ret); err != nil {
		err.Message = "Unable to connect to cluster. Make sure cluster is accessible and configuration is correct."
		return nil, err
	}

	return conn.cluster, nil
}
Пример #7
0
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
}