Skip to content

Commit

Permalink
rados: replace radosError by cephError
Browse files Browse the repository at this point in the history
Signed-off-by: Niels de Vos <[email protected]>
  • Loading branch information
nixpanic authored and mergify[bot] committed Oct 14, 2024
1 parent e2ab470 commit 7154dac
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 49 deletions.
10 changes: 5 additions & 5 deletions rados/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,11 +291,11 @@ func (c *Conn) GetPoolByName(name string) (int64, error) {
}
cName := C.CString(name)
defer C.free(unsafe.Pointer(cName))
ret := int64(C.rados_pool_lookup(c.cluster, cName))
ret := C.rados_pool_lookup(c.cluster, cName)
if ret < 0 {
return 0, radosError(ret)
return 0, getError(C.int(ret))
}
return ret, nil
return int64(ret), nil
}

// GetPoolByID returns the name of a pool by a given ID.
Expand All @@ -305,9 +305,9 @@ func (c *Conn) GetPoolByID(id int64) (string, error) {
return "", err
}
cid := C.int64_t(id)
ret := int(C.rados_pool_reverse_lookup(c.cluster, cid, (*C.char)(unsafe.Pointer(&buf[0])), C.size_t(len(buf))))
ret := C.rados_pool_reverse_lookup(c.cluster, cid, (*C.char)(unsafe.Pointer(&buf[0])), C.size_t(len(buf)))
if ret < 0 {
return "", radosError(ret)
return "", getError(ret)
}
return C.GoString((*C.char)(unsafe.Pointer(&buf[0]))), nil
}
64 changes: 21 additions & 43 deletions rados/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,41 +11,12 @@ import (
"github.com/ceph/go-ceph/internal/errutil"
)

// radosError represents an error condition returned from the Ceph RADOS APIs.
type radosError int

// Error returns the error string for the radosError type.
func (e radosError) Error() string {
return errutil.FormatErrorCode("rados", int(e))
}

func (e radosError) ErrorCode() int {
return int(e)
}

func getError(e C.int) error {
if e == 0 {
return nil
}
return radosError(e)
}

// getErrorIfNegative converts a ceph return code to error if negative.
// This is useful for functions that return a usable positive value on
// success but a negative error number on error.
func getErrorIfNegative(ret C.int) error {
if ret >= 0 {
return nil
}
return getError(ret)
}

// Public go errors:

var (
// ErrNotConnected is returned when functions are called
// without a RADOS connection.
ErrNotConnected = errors.New("RADOS not connected")
ErrNotConnected = getError(-C.ENOTCONN)
// ErrEmptyArgument may be returned if a function argument is passed
// a zero-length slice or map.
ErrEmptyArgument = errors.New("Argument must contain at least one item")
Expand All @@ -55,17 +26,13 @@ var (
// ErrOperationIncomplete is returned from write op or read op steps for
// which the operation has not been performed yet.
ErrOperationIncomplete = errors.New("Operation has not been performed yet")
)

// Public radosErrors:

const (
// ErrNotFound indicates a missing resource.
ErrNotFound = radosError(-C.ENOENT)
ErrNotFound = getError(-C.ENOENT)
// ErrPermissionDenied indicates a permissions issue.
ErrPermissionDenied = radosError(-C.EPERM)
ErrPermissionDenied = getError(-C.EPERM)
// ErrObjectExists indicates that an exclusive object creation failed.
ErrObjectExists = radosError(-C.EEXIST)
ErrObjectExists = getError(-C.EEXIST)

// RadosErrorNotFound indicates a missing resource.
//
Expand All @@ -75,12 +42,23 @@ const (
//
// Deprecated: use ErrPermissionDenied instead
RadosErrorPermissionDenied = ErrPermissionDenied
)

// Private errors:

const (
errNameTooLong = radosError(-C.ENAMETOOLONG)
// Private errors:

errRange = radosError(-C.ERANGE)
errNameTooLong = getError(-C.ENAMETOOLONG)
errRange = getError(-C.ERANGE)
)

func getError(errno C.int) error {
return errutil.GetError("rados", int(errno))
}

// getErrorIfNegative converts a ceph return code to error if negative.
// This is useful for functions that return a usable positive value on
// success but a negative error number on error.
func getErrorIfNegative(ret C.int) error {
if ret >= 0 {
return nil
}
return getError(ret)
}
2 changes: 1 addition & 1 deletion rados/ioctx.go
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@ func (ioctx *IOContext) ListLockers(oid, name string) (*LockInfo, error) {
}

if ret < 0 {
return nil, radosError(ret)
return nil, getError(C.int(ret))
}
return &LockInfo{int(ret), cExclusive == 1, C.GoString(cTag), splitCString(cClients, cClientsLen), splitCString(cCookies, cCookiesLen), splitCString(cAddrs, cAddrsLen)}, nil
}
Expand Down

0 comments on commit 7154dac

Please sign in to comment.