From be7a90a2be9939e0dccc562d40566be625e2a69c Mon Sep 17 00:00:00 2001 From: John Mulligan Date: Mon, 30 Mar 2020 17:03:52 -0400 Subject: [PATCH] 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 --- rados/conn.go | 26 +++++++++++++------------- rados/ioctx.go | 10 +++++----- rados/omap.go | 2 +- rados/rados.go | 4 ++-- 4 files changed, 21 insertions(+), 21 deletions(-) diff --git a/rados/conn.go b/rados/conn.go index 5f2256b..cd69a18 100644 --- a/rados/conn.go +++ b/rados/conn.go @@ -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 } diff --git a/rados/ioctx.go b/rados/ioctx.go index 0653e33..45069a9 100644 --- a/rados/ioctx.go +++ b/rados/ioctx.go @@ -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) } } diff --git a/rados/omap.go b/rados/omap.go index 32656a4..7d279c2 100644 --- a/rados/omap.go +++ b/rados/omap.go @@ -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 { diff --git a/rados/rados.go b/rados/rados.go index ea1cae2..d1f000a 100644 --- a/rados/rados.go +++ b/rados/rados.go @@ -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)