2020-03-30 20:02:07 +00:00
|
|
|
package rados
|
|
|
|
|
|
|
|
/*
|
|
|
|
#include <errno.h>
|
|
|
|
*/
|
|
|
|
import "C"
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
|
|
|
|
"github.com/ceph/go-ceph/internal/errutil"
|
|
|
|
)
|
|
|
|
|
2020-07-13 23:51:20 +00:00
|
|
|
// radosError represents an error condition returned from the Ceph RADOS APIs.
|
|
|
|
type radosError int
|
2020-03-30 20:02:07 +00:00
|
|
|
|
2020-07-13 23:51:20 +00:00
|
|
|
// Error returns the error string for the radosError type.
|
|
|
|
func (e radosError) Error() string {
|
2020-08-10 15:04:32 +00:00
|
|
|
return errutil.FormatErrorCode("rados", int(e))
|
2020-03-30 20:02:07 +00:00
|
|
|
}
|
|
|
|
|
2020-08-10 14:31:40 +00:00
|
|
|
func (e radosError) ErrorCode() int {
|
2020-07-13 23:51:20 +00:00
|
|
|
return int(e)
|
|
|
|
}
|
|
|
|
|
2020-03-30 20:57:54 +00:00
|
|
|
func getError(e C.int) error {
|
|
|
|
if e == 0 {
|
2020-03-30 20:02:07 +00:00
|
|
|
return nil
|
|
|
|
}
|
2020-07-13 23:51:20 +00:00
|
|
|
return radosError(e)
|
2020-03-30 20:02:07 +00:00
|
|
|
}
|
|
|
|
|
2020-04-10 17:35:49 +00:00
|
|
|
// 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)
|
|
|
|
}
|
|
|
|
|
2020-03-30 20:02:07 +00:00
|
|
|
// Public go errors:
|
|
|
|
|
|
|
|
var (
|
2020-07-30 02:18:53 +00:00
|
|
|
// ErrNotConnected is returned when functions are called
|
|
|
|
// without a RADOS connection.
|
2020-03-30 20:02:07 +00:00
|
|
|
ErrNotConnected = errors.New("RADOS not connected")
|
2020-06-29 20:10:18 +00:00
|
|
|
// 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")
|
2020-07-30 02:23:59 +00:00
|
|
|
// ErrInvalidIOContext may be returned if an api call requires an IOContext
|
|
|
|
// but IOContext is not ready for use.
|
|
|
|
ErrInvalidIOContext = errors.New("IOContext is not ready for use")
|
2020-06-25 21:23:19 +00:00
|
|
|
// 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")
|
2020-03-30 20:02:07 +00:00
|
|
|
)
|
|
|
|
|
2020-07-13 23:51:20 +00:00
|
|
|
// Public radosErrors:
|
2020-03-30 20:02:07 +00:00
|
|
|
|
|
|
|
const (
|
|
|
|
// ErrNotFound indicates a missing resource.
|
2020-07-13 23:51:20 +00:00
|
|
|
ErrNotFound = radosError(-C.ENOENT)
|
2020-03-30 20:02:07 +00:00
|
|
|
// ErrPermissionDenied indicates a permissions issue.
|
2020-07-13 23:51:20 +00:00
|
|
|
ErrPermissionDenied = radosError(-C.EPERM)
|
2020-03-30 20:02:07 +00:00
|
|
|
// ErrObjectExists indicates that an exclusive object creation failed.
|
2020-07-13 23:51:20 +00:00
|
|
|
ErrObjectExists = radosError(-C.EEXIST)
|
2020-03-30 20:02:07 +00:00
|
|
|
|
|
|
|
// RadosErrorNotFound indicates a missing resource.
|
|
|
|
//
|
|
|
|
// Deprecated: use ErrNotFound instead
|
|
|
|
RadosErrorNotFound = ErrNotFound
|
|
|
|
// RadosErrorPermissionDenied indicates a permissions issue.
|
|
|
|
//
|
|
|
|
// Deprecated: use ErrPermissionDenied instead
|
|
|
|
RadosErrorPermissionDenied = ErrPermissionDenied
|
|
|
|
)
|
2020-04-10 17:35:49 +00:00
|
|
|
|
|
|
|
// Private errors:
|
|
|
|
|
|
|
|
const (
|
2020-07-13 23:51:20 +00:00
|
|
|
errNameTooLong = radosError(-C.ENAMETOOLONG)
|
2020-04-10 17:35:49 +00:00
|
|
|
|
2020-07-13 23:51:20 +00:00
|
|
|
errRange = radosError(-C.ERANGE)
|
2020-04-10 17:35:49 +00:00
|
|
|
)
|