2020-03-30 20:11:54 +00:00
|
|
|
package rbd
|
|
|
|
|
|
|
|
/*
|
|
|
|
#include <errno.h>
|
|
|
|
*/
|
|
|
|
import "C"
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
2024-10-02 13:49:54 +00:00
|
|
|
"fmt"
|
2020-03-30 20:11:54 +00:00
|
|
|
|
|
|
|
"github.com/ceph/go-ceph/internal/errutil"
|
|
|
|
)
|
|
|
|
|
|
|
|
func getError(err C.int) error {
|
|
|
|
if err != 0 {
|
|
|
|
if err == -C.ENOENT {
|
|
|
|
return ErrNotFound
|
|
|
|
}
|
2024-10-02 13:49:54 +00:00
|
|
|
return errutil.GetError("rbd", int(err))
|
2020-03-30 20:11:54 +00:00
|
|
|
}
|
2020-04-08 20:13:40 +00:00
|
|
|
return nil
|
2020-03-30 20:11:54 +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:11:54 +00:00
|
|
|
// Public go errors:
|
|
|
|
|
|
|
|
var (
|
|
|
|
// ErrNoIOContext may be returned if an api call requires an IOContext and
|
|
|
|
// it is not provided.
|
2020-06-11 01:00:10 +00:00
|
|
|
ErrNoIOContext = errors.New("IOContext is missing")
|
2020-03-30 20:11:54 +00:00
|
|
|
// ErrNoName may be returned if an api call requires a name and it is
|
|
|
|
// not provided.
|
|
|
|
ErrNoName = errors.New("RBD image does not have a name")
|
2020-06-11 01:00:10 +00:00
|
|
|
// ErrSnapshotNoName may be returned if an api call requires a snapshot
|
2020-03-30 20:11:54 +00:00
|
|
|
// name and it is not provided.
|
|
|
|
ErrSnapshotNoName = errors.New("RBD snapshot does not have a name")
|
2020-04-30 02:18:49 +00:00
|
|
|
// ErrImageNotOpen may be returned if an api call requires an open image handle and one is not provided.
|
2020-03-30 20:11:54 +00:00
|
|
|
ErrImageNotOpen = errors.New("RBD image not open")
|
2020-01-31 13:42:06 +00:00
|
|
|
// ErrImageIsOpen may be returned if an api call requires a closed image handle and one is not provided.
|
|
|
|
ErrImageIsOpen = errors.New("RBD image is open")
|
2020-03-30 20:11:54 +00:00
|
|
|
// ErrNotFound may be returned from an api call when the requested item is
|
|
|
|
// missing.
|
2024-10-02 13:49:54 +00:00
|
|
|
ErrNotFound = fmt.Errorf("RBD image not found: %w", errutil.GetError("rbd", -C.ENOENT))
|
2020-06-06 05:43:47 +00:00
|
|
|
// ErrNoNamespaceName maye be returned if an api call requires a namespace
|
|
|
|
// name and it is not provided.
|
|
|
|
ErrNoNamespaceName = errors.New("Namespace value is missing")
|
2020-03-30 20:11:54 +00:00
|
|
|
|
|
|
|
// revive:disable:exported for compatibility with old versions
|
|
|
|
RbdErrorImageNotOpen = ErrImageNotOpen
|
|
|
|
RbdErrorNotFound = ErrNotFound
|
|
|
|
// revive:enable:exported
|
2020-04-10 17:35:49 +00:00
|
|
|
|
2024-09-24 10:59:42 +00:00
|
|
|
// ErrExist indicates a non-specific already existing resource.
|
2024-10-02 13:49:54 +00:00
|
|
|
ErrExist = getError(-C.EEXIST)
|
2021-02-22 22:34:31 +00:00
|
|
|
// ErrNotExist indicates a non-specific missing resource.
|
2024-10-02 13:49:54 +00:00
|
|
|
ErrNotExist = getError(-C.ENOENT)
|
2024-07-12 16:49:19 +00:00
|
|
|
// ErrNotImplemented indicates a function is not implemented in by librbd.
|
2024-10-02 13:49:54 +00:00
|
|
|
ErrNotImplemented = getError(-C.ENOSYS)
|
2021-02-22 22:34:31 +00:00
|
|
|
|
2024-10-02 13:49:54 +00:00
|
|
|
// Private errors:
|
2020-04-10 17:35:49 +00:00
|
|
|
|
2024-10-02 13:49:54 +00:00
|
|
|
errRange = getError(-C.ERANGE)
|
2020-04-10 17:35:49 +00:00
|
|
|
)
|