2020-03-30 20:22:07 +00:00
|
|
|
package cephfs
|
|
|
|
|
|
|
|
/*
|
|
|
|
#include <errno.h>
|
|
|
|
*/
|
|
|
|
import "C"
|
|
|
|
|
|
|
|
import (
|
2020-06-29 20:02:07 +00:00
|
|
|
"errors"
|
2020-03-30 20:22:07 +00:00
|
|
|
|
|
|
|
"github.com/ceph/go-ceph/internal/errutil"
|
|
|
|
)
|
|
|
|
|
2020-07-13 23:58:54 +00:00
|
|
|
// cephFSError represents an error condition returned from the CephFS APIs.
|
|
|
|
type cephFSError int
|
2020-03-30 20:22:07 +00:00
|
|
|
|
2020-07-13 23:58:54 +00:00
|
|
|
// Error returns the error string for the cephFSError type.
|
|
|
|
func (e cephFSError) Error() string {
|
2020-08-10 15:04:07 +00:00
|
|
|
return errutil.FormatErrorCode("cephfs", int(e))
|
2020-03-30 20:22:07 +00:00
|
|
|
}
|
|
|
|
|
2020-08-10 14:31:17 +00:00
|
|
|
func (e cephFSError) ErrorCode() int {
|
2020-07-13 23:58:54 +00:00
|
|
|
return int(e)
|
|
|
|
}
|
|
|
|
|
2020-03-30 20:22:07 +00:00
|
|
|
func getError(e C.int) error {
|
|
|
|
if e == 0 {
|
|
|
|
return nil
|
|
|
|
}
|
2020-07-13 23:58:54 +00:00
|
|
|
return cephFSError(e)
|
2020-03-30 20:22:07 +00:00
|
|
|
}
|
2020-04-10 17:35:49 +00:00
|
|
|
|
2020-06-18 17:35:35 +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-04-20 18:31:39 +00:00
|
|
|
// Public go errors:
|
|
|
|
|
2020-06-29 20:02:07 +00:00
|
|
|
var (
|
|
|
|
// 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")
|
|
|
|
)
|
|
|
|
|
|
|
|
// Public CephFSErrors:
|
|
|
|
|
2020-04-20 18:31:39 +00:00
|
|
|
const (
|
|
|
|
// ErrNotConnected may be returned when client is not connected
|
|
|
|
// to a cluster.
|
2020-07-13 23:58:54 +00:00
|
|
|
ErrNotConnected = cephFSError(-C.ENOTCONN)
|
2020-04-20 18:31:39 +00:00
|
|
|
)
|
|
|
|
|
2020-04-10 17:35:49 +00:00
|
|
|
// Private errors:
|
|
|
|
|
|
|
|
const (
|
2020-07-13 23:58:54 +00:00
|
|
|
errInvalid = cephFSError(-C.EINVAL)
|
|
|
|
errNameTooLong = cephFSError(-C.ENAMETOOLONG)
|
|
|
|
errNoEntry = cephFSError(-C.ENOENT)
|
2020-06-18 17:36:38 +00:00
|
|
|
errRange = cephFSError(-C.ERANGE)
|
2020-04-10 17:35:49 +00:00
|
|
|
)
|