-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrados_pool.go
87 lines (73 loc) · 2.03 KB
/
rados_pool.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package gorados
/*
#cgo LDFLAGS: -lrados
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "rados/librados.h"
*/
import "C"
import (
"errors"
"unsafe"
"bytes"
)
func (r *Rados) PoolList() [][]byte {
buflen := C.rados_pool_list(*r.cluster, nil, C.size_t(0))
buf := make([]byte, buflen)
C.rados_pool_list(*r.cluster, (*C.char)(unsafe.Pointer(&buf[0])), C.size_t(buflen))
buf1 := buf[0:buflen-2]
return bytes.Split(buf1, []byte{0})
}
func (r *Rados) PoolLookUp(poolname string) (int64, error) {
cpoolname := C.CString(poolname)
defer func(){
C.free(unsafe.Pointer(cpoolname))
}()
cerr := C.rados_pool_lookup(*r.cluster, cpoolname)
if cerr < 0 {
return 0, errors.New("Pool not found")
}
return int64(cerr), nil
}
/*func (r *Rados) PoolReverseLookUp(poolid int64) (string, error) {
var buf [MAX_NAME_LEN]C.char
cerr := C.rados_pool_reverse_lookup(*r.cluster, C.int64_t(poolid), &buf[0], MAX_NAME_LEN)
if cerr < 0 {
return "", errors.New("Pool not found")
}
return C.GoString(&buf[0]), nil
}*/
func (r *Rados) PoolCreate(poolname string) error {
cpoolname := C.CString(poolname)
defer func(){
C.free(unsafe.Pointer(cpoolname))
}()
cerr := C.rados_pool_create(*r.cluster, cpoolname)
if cerr < 0 {
return errors.New("create pool failed")
}
return nil
}
func (r *Rados) PoolCreateWithAuid(poolname string, auid uint64) error {
cpoolname := C.CString(poolname)
defer func(){
C.free(unsafe.Pointer(cpoolname))
}()
cerr := C.rados_pool_create_with_auid(*r.cluster, cpoolname, C.uint64_t(auid))
if cerr < 0 {
return errors.New("create pool failed")
}
return nil
}
func (r *Rados) PoolDelete(poolname string) error {
cpoolname := C.CString(poolname)
defer func(){
C.free(unsafe.Pointer(cpoolname))
}()
cerr := C.rados_pool_delete(*r.cluster, cpoolname)
if cerr < 0 {
return errors.New("delete pool failed")
}
return nil
}