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 }
// GetPool instantiates a Pool object from librados. It must be able to // authenticate to ceph through normal (e.g., CLI) means to perform this // operation. The RBDConfig is used to supply parts of the configuration which // cannot be necessarily parsed by the C versions of librados and librbd. This // struct will need to be populated; if you want a way to fill it from JSON, // see ReadConfig. func GetPool(config RBDConfig, poolName string) (*Pool, error) { if err := modprobeRBD(); err != nil { return nil, err } var err error pool := &Pool{poolName: poolName, rbdConfig: config} str := C.CString(poolName) defer C.free(unsafe.Pointer(str)) pool.cluster, err = getRados(config.UserName) if err != nil { return nil, err } if i := C.rados_ioctx_create(pool.cluster, str, &pool.ioctx); i < 0 { return nil, strerror(i) } runtime.SetFinalizer(pool, freePool) return pool, nil }
func (c *Conn) OpenIOContext(pool string) (*IOContext, error) { c_pool := C.CString(pool) defer C.free(unsafe.Pointer(c_pool)) ioctx := &IOContext{} ret := C.rados_ioctx_create(c.cluster, c_pool, &ioctx.ioctx) if ret == 0 { return ioctx, nil } else { return nil, RadosError(int(ret)) } }
// ManagePool opens a pool for query, read, and write operations. func (cluster *Cluster) ManagePool(poolName string) (*Pool, error) { p := C.CString(poolName) defer freeString(p) var ioContext C.rados_ioctx_t ret := C.rados_ioctx_create(cluster.handle, p, &ioContext) if err := toRadosError(ret); err != nil { err.Message = fmt.Sprintf("Unable to create IO Context for %s.", poolName) return nil, err } return &Pool{ioContext}, nil }
func (r *Rados) IoCtxCreate(poolname string) (*RadosIoCtx, error) { cpoolname := C.CString(poolname) defer func() { C.free(unsafe.Pointer(cpoolname)) }() var ctx C.rados_ioctx_t cerr := C.rados_ioctx_create(*r.cluster, cpoolname, &ctx) if cerr < 0 { return nil, errors.New("create io contxt failed:" + C.GoString(C.strerror(-cerr))) } return &RadosIoCtx{&ctx}, nil }
// NewContext creates a new RADOS IO context for a given pool, which used to // do IO operations. The pool must exist (see Rados.PoolCreate()). func (r *Rados) NewContext(pool string) (*Context, error) { if r.rados == nil { return nil, fmt.Errorf("RADOS not connected") } cpool := C.CString(pool) defer C.free(unsafe.Pointer(cpool)) c := &Context{Pool: pool} if cerr := C.rados_ioctx_create(r.rados, cpool, &c.ctx); cerr < 0 { return nil, radosReturnCodeError(cerr) } return c, nil }