rados: add a connected flag to the conn obj

Signed-off-by: Noah Watkins <nwatkins@redhat.com>
This commit is contained in:
Noah Watkins 2018-07-28 14:23:18 -07:00
parent 3b687cfa99
commit c14a3857fa
2 changed files with 17 additions and 16 deletions

View File

@ -18,7 +18,8 @@ type ClusterStat struct {
// Conn is a connection handle to a Ceph cluster.
type Conn struct {
cluster C.rados_t
cluster C.rados_t
connected bool
}
// PingMonitor sends a ping to a monitor and returns the reply.

View File

@ -37,11 +37,13 @@ func Version() (int, int, int) {
return int(c_major), int(c_minor), int(c_patch)
}
// NewConn creates a new connection object. It returns the connection and an
// error, if any.
func NewConn() (*Conn, error) {
conn := &Conn{}
ret := C.rados_create(&conn.cluster, nil)
func makeConn() *Conn {
return &Conn{connected: false}
}
func newConn(user *C.char) (*Conn, error) {
conn := makeConn()
ret := C.rados_create(&conn.cluster, user)
if ret == 0 {
return conn, nil
@ -50,20 +52,18 @@ func NewConn() (*Conn, error) {
}
}
// NewConn creates a new connection object. It returns the connection and an
// error, if any.
func NewConn() (*Conn, error) {
return newConn(nil)
}
// NewConnWithUser creates a new connection object with a custom username.
// It returns the connection and an error, if any.
func NewConnWithUser(user string) (*Conn, error) {
c_user := C.CString(user)
defer C.free(unsafe.Pointer(c_user))
conn := &Conn{}
ret := C.rados_create(&conn.cluster, c_user)
if ret == 0 {
return conn, nil
} else {
return nil, RadosError(int(ret))
}
return newConn(c_user)
}
// NewConnWithClusterAndUser creates a new connection object for a specific cluster and username.
@ -75,7 +75,7 @@ func NewConnWithClusterAndUser(clusterName string, userName string) (*Conn, erro
c_name := C.CString(userName)
defer C.free(unsafe.Pointer(c_name))
conn := &Conn{}
conn := makeConn()
ret := C.rados_create2(&conn.cluster, c_cluster_name, c_name, 0)
if ret == 0 {
return conn, nil