mirror of https://github.com/ceph/go-ceph
rados: use getError helper in general error conversion cases
For more consisistency use getError where possible. Changes produced using `gofmt -r 'RadosError(int(x)) -> getError(x)`, followed by a few manual fixups. Signed-off-by: John Mulligan <jmulligan@redhat.com>
This commit is contained in:
parent
5394d1c99f
commit
be7a90a2be
|
@ -47,7 +47,7 @@ func (c *Conn) PingMonitor(id string) (string, error) {
|
|||
reply := C.GoStringN(strout, (C.int)(strlen))
|
||||
return reply, nil
|
||||
}
|
||||
return "", RadosError(int(ret))
|
||||
return "", getError(ret)
|
||||
}
|
||||
|
||||
// Connect establishes a connection to a RADOS cluster. It returns an error,
|
||||
|
@ -55,7 +55,7 @@ func (c *Conn) PingMonitor(id string) (string, error) {
|
|||
func (c *Conn) Connect() error {
|
||||
ret := C.rados_connect(c.cluster)
|
||||
if ret != 0 {
|
||||
return RadosError(int(ret))
|
||||
return getError(ret)
|
||||
}
|
||||
c.connected = true
|
||||
return nil
|
||||
|
@ -97,20 +97,20 @@ func (c *Conn) OpenIOContext(pool string) (*IOContext, error) {
|
|||
if ret == 0 {
|
||||
return ioctx, nil
|
||||
}
|
||||
return nil, RadosError(int(ret))
|
||||
return nil, getError(ret)
|
||||
}
|
||||
|
||||
// ListPools returns the names of all existing pools.
|
||||
func (c *Conn) ListPools() (names []string, err error) {
|
||||
buf := make([]byte, 4096)
|
||||
for {
|
||||
ret := int(C.rados_pool_list(c.cluster,
|
||||
(*C.char)(unsafe.Pointer(&buf[0])), C.size_t(len(buf))))
|
||||
ret := C.rados_pool_list(c.cluster,
|
||||
(*C.char)(unsafe.Pointer(&buf[0])), C.size_t(len(buf)))
|
||||
if ret < 0 {
|
||||
return nil, RadosError(int(ret))
|
||||
return nil, getError(ret)
|
||||
}
|
||||
|
||||
if ret > len(buf) {
|
||||
if int(ret) > len(buf) {
|
||||
buf = make([]byte, ret)
|
||||
continue
|
||||
}
|
||||
|
@ -178,7 +178,7 @@ func (c *Conn) GetClusterStats() (stat ClusterStat, err error) {
|
|||
c_stat := C.struct_rados_cluster_stat_t{}
|
||||
ret := C.rados_cluster_stat(c.cluster, &c_stat)
|
||||
if ret < 0 {
|
||||
return ClusterStat{}, RadosError(int(ret))
|
||||
return ClusterStat{}, getError(ret)
|
||||
}
|
||||
return ClusterStat{
|
||||
Kb: uint64(c_stat.kb),
|
||||
|
@ -219,14 +219,14 @@ func (c *Conn) ParseDefaultConfigEnv() error {
|
|||
// is a unique identifier of an entire Ceph cluster.
|
||||
func (c *Conn) GetFSID() (fsid string, err error) {
|
||||
buf := make([]byte, 37)
|
||||
ret := int(C.rados_cluster_fsid(c.cluster,
|
||||
(*C.char)(unsafe.Pointer(&buf[0])), C.size_t(len(buf))))
|
||||
ret := C.rados_cluster_fsid(c.cluster,
|
||||
(*C.char)(unsafe.Pointer(&buf[0])), C.size_t(len(buf)))
|
||||
// FIXME: the success case isn't documented correctly in librados.h
|
||||
if ret == 36 {
|
||||
fsid = C.GoString((*C.char)(unsafe.Pointer(&buf[0])))
|
||||
return fsid, nil
|
||||
}
|
||||
return "", RadosError(int(ret))
|
||||
return "", getError(ret)
|
||||
}
|
||||
|
||||
// GetInstanceID returns a globally unique identifier for the cluster
|
||||
|
@ -323,7 +323,7 @@ func (c *Conn) monCommand(args, inputBuffer []byte) (buffer []byte, info string,
|
|||
C.free(unsafe.Pointer(outbuf))
|
||||
}
|
||||
if ret != 0 {
|
||||
err = RadosError(int(ret))
|
||||
err = getError(ret)
|
||||
return nil, info, err
|
||||
}
|
||||
|
||||
|
@ -394,7 +394,7 @@ func (c *Conn) pgCommand(pgid []byte, args [][]byte, inputBuffer []byte) (buffer
|
|||
C.free(unsafe.Pointer(outbuf))
|
||||
}
|
||||
if ret != 0 {
|
||||
err = RadosError(int(ret))
|
||||
err = getError(ret)
|
||||
return nil, info, err
|
||||
}
|
||||
|
||||
|
|
|
@ -445,7 +445,7 @@ func (ioctx *IOContext) LockExclusive(oid, name, cookie, desc string, duration t
|
|||
case -C.EEXIST:
|
||||
return int(ret), nil
|
||||
default:
|
||||
return int(ret), RadosError(int(ret))
|
||||
return int(ret), getError(ret)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -496,7 +496,7 @@ func (ioctx *IOContext) LockShared(oid, name, cookie, tag, desc string, duration
|
|||
case -C.EEXIST:
|
||||
return int(ret), nil
|
||||
default:
|
||||
return int(ret), RadosError(int(ret))
|
||||
return int(ret), getError(ret)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -525,7 +525,7 @@ func (ioctx *IOContext) Unlock(oid, name, cookie string) (int, error) {
|
|||
case -C.ENOENT:
|
||||
return int(ret), nil
|
||||
default:
|
||||
return int(ret), RadosError(int(ret))
|
||||
return int(ret), getError(ret)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -582,7 +582,7 @@ func (ioctx *IOContext) ListLockers(oid, name string) (*LockInfo, error) {
|
|||
}
|
||||
|
||||
if ret < 0 {
|
||||
return nil, RadosError(int(ret))
|
||||
return nil, RadosError(ret)
|
||||
}
|
||||
return &LockInfo{int(ret), c_exclusive == 1, C.GoString(c_tag), splitCString(c_clients, c_clients_len), splitCString(c_cookies, c_cookies_len), splitCString(c_addrs, c_addrs_len)}, nil
|
||||
}
|
||||
|
@ -618,6 +618,6 @@ func (ioctx *IOContext) BreakLock(oid, name, client, cookie string) (int, error)
|
|||
case -C.EINVAL: // -EINVAL
|
||||
return int(ret), nil
|
||||
default:
|
||||
return int(ret), RadosError(int(ret))
|
||||
return int(ret), getError(ret)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -106,7 +106,7 @@ func (ioctx *IOContext) ListOmapValues(oid string, startAfter string, filterPref
|
|||
if int(ret) != 0 {
|
||||
return getError(ret)
|
||||
} else if int(c_prval) != 0 {
|
||||
return RadosError(int(c_prval))
|
||||
return getError(c_prval)
|
||||
}
|
||||
|
||||
for {
|
||||
|
|
|
@ -42,7 +42,7 @@ func newConn(user *C.char) (*Conn, error) {
|
|||
ret := C.rados_create(&conn.cluster, user)
|
||||
|
||||
if ret != 0 {
|
||||
return nil, RadosError(int(ret))
|
||||
return nil, getError(ret)
|
||||
}
|
||||
|
||||
runtime.SetFinalizer(conn, freeConn)
|
||||
|
@ -75,7 +75,7 @@ func NewConnWithClusterAndUser(clusterName string, userName string) (*Conn, erro
|
|||
conn := makeConn()
|
||||
ret := C.rados_create2(&conn.cluster, c_cluster_name, c_name, 0)
|
||||
if ret != 0 {
|
||||
return nil, RadosError(int(ret))
|
||||
return nil, getError(ret)
|
||||
}
|
||||
|
||||
runtime.SetFinalizer(conn, freeConn)
|
||||
|
|
Loading…
Reference in New Issue