示例#1
0
文件: zlog.go 项目: noahdesu/go-zlog
func OpenOrCreate(ioctx *rados.IOContext, name string, stripe_size int, host string, port string) (*Log, error) {
	c_name := C.CString(name)
	defer C.free(unsafe.Pointer(c_name))

	c_host := C.CString(host)
	defer C.free(unsafe.Pointer(c_host))

	c_port := C.CString(port)
	defer C.free(unsafe.Pointer(c_port))

	log := &Log{}

	ret := C.zlog_open_or_create(C.rados_ioctx_t(ioctx.Pointer()), c_name, C.int(stripe_size),
		c_host, c_port, &log.log)

	if ret == 0 {
		return log, nil
	} else {
		return nil, ZlogError(int(ret))
	}
}
示例#2
0
文件: rbd.go 项目: kallax/go-ceph-1
// int rbd_create(rados_ioctx_t io, const char *name, uint64_t size, int *order);
// int rbd_create2(rados_ioctx_t io, const char *name, uint64_t size,
//          uint64_t features, int *order);
// int rbd_create3(rados_ioctx_t io, const char *name, uint64_t size,
//        uint64_t features, int *order,
//        uint64_t stripe_unit, uint64_t stripe_count);
func Create(ioctx *rados.IOContext, name string, size uint64,
	args ...uint64) (image *Image, err error) {
	var ret C.int
	var c_order C.int
	var c_name *C.char = C.CString(name)
	defer C.free(unsafe.Pointer(c_name))

	switch len(args) {
	case 2:
		ret = C.rbd_create3(C.rados_ioctx_t(ioctx.Pointer()),
			c_name, C.uint64_t(size),
			C.uint64_t(args[0]), &c_order,
			C.uint64_t(args[1]), C.uint64_t(args[2]))
	case 1:
		ret = C.rbd_create2(C.rados_ioctx_t(ioctx.Pointer()),
			c_name, C.uint64_t(size),
			C.uint64_t(args[0]), &c_order)
	case 0:
		ret = C.rbd_create(C.rados_ioctx_t(ioctx.Pointer()),
			c_name, C.uint64_t(size), &c_order)
	default:
		return nil, errors.New("Wrong number of argument")
	}

	if ret < 0 {
		return nil, RBDError(int(ret))
	}

	return &Image{
		ioctx: ioctx,
		name:  name,
	}, nil
}
示例#3
0
文件: rbd.go 项目: kallax/go-ceph-1
// int rbd_clone(rados_ioctx_t p_ioctx, const char *p_name,
//           const char *p_snapname, rados_ioctx_t c_ioctx,
//           const char *c_name, uint64_t features, int *c_order);
// int rbd_clone2(rados_ioctx_t p_ioctx, const char *p_name,
//            const char *p_snapname, rados_ioctx_t c_ioctx,
//            const char *c_name, uint64_t features, int *c_order,
//            uint64_t stripe_unit, int stripe_count);
func (image *Image) Clone(snapname string, c_ioctx *rados.IOContext, c_name string, features uint64) (*Image, error) {
	var c_order C.int
	var c_p_name *C.char = C.CString(image.name)
	var c_p_snapname *C.char = C.CString(snapname)
	var c_c_name *C.char = C.CString(c_name)
	defer C.free(unsafe.Pointer(c_p_name))
	defer C.free(unsafe.Pointer(c_p_snapname))
	defer C.free(unsafe.Pointer(c_c_name))

	ret := C.rbd_clone(C.rados_ioctx_t(image.ioctx.Pointer()),
		c_p_name, c_p_snapname,
		C.rados_ioctx_t(c_ioctx.Pointer()),
		c_c_name, C.uint64_t(features), &c_order)
	if ret < 0 {
		return nil, RBDError(int(ret))
	}

	return &Image{
		ioctx: c_ioctx,
		name:  c_name,
	}, nil
}
示例#4
0
文件: rbd.go 项目: kallax/go-ceph-1
// GetImageNames returns the list of current RBD images.
func GetImageNames(ioctx *rados.IOContext) (names []string, err error) {
	buf := make([]byte, 4096)
	for {
		size := C.size_t(len(buf))
		ret := C.rbd_list(C.rados_ioctx_t(ioctx.Pointer()),
			(*C.char)(unsafe.Pointer(&buf[0])), &size)
		if ret == -34 { // FIXME
			buf = make([]byte, size)
			continue
		} else if ret < 0 {
			return nil, RBDError(ret)
		}
		tmp := bytes.Split(buf[:size-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
	}
}
示例#5
0
// goceph_shutdownContext will destroy any non-default ioctx
func (d *cephRBDVolumeDriver) goceph_shutdownContext(ioctx *rados.IOContext) {
	if ioctx != nil {
		ioctx.Destroy()
	}
}
示例#6
0
// shutdownContext will destroy any non-default ioctx
func (d *cephRBDVolumeDriver) shutdownContext(ioctx *rados.IOContext) {
	if ioctx != nil && ioctx != d.defaultIoctx {
		ioctx.Destroy()
	}
}