mirror of
https://github.com/ceph/go-ceph
synced 2024-12-24 07:03:00 +00:00
rbd: convert to common errno handling
Use the errno handling function originally created for rbd and then made common in rbd package. Signed-off-by: John Mulligan <jmulligan@redhat.com>
This commit is contained in:
parent
bd99f64517
commit
811f851c99
18
rbd/rbd.go
18
rbd/rbd.go
@ -19,6 +19,7 @@ import (
|
||||
"time"
|
||||
"unsafe"
|
||||
|
||||
"github.com/ceph/go-ceph/errutil"
|
||||
"github.com/ceph/go-ceph/rados"
|
||||
)
|
||||
|
||||
@ -173,21 +174,12 @@ func (snapshot *Snapshot) validate(req uint32) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
//
|
||||
func (e RBDError) Error() string {
|
||||
buf := make([]byte, 1024)
|
||||
// strerror expects errno >= 0
|
||||
errno := e
|
||||
if errno < 0 {
|
||||
errno = -errno
|
||||
errno, s := errutil.FormatErrno(int(e))
|
||||
if s == "" {
|
||||
return fmt.Sprintf("rbd: ret=%d", errno)
|
||||
}
|
||||
|
||||
ret := C.strerror_r(C.int(errno), (*C.char)(unsafe.Pointer(&buf[0])), C.size_t(len(buf)))
|
||||
if ret != 0 {
|
||||
return fmt.Sprintf("rbd: ret=%d", e)
|
||||
}
|
||||
|
||||
return fmt.Sprintf("rbd: ret=%d, %s", e, C.GoString((*C.char)(unsafe.Pointer(&buf[0]))))
|
||||
return fmt.Sprintf("rbd: ret=%d, %s", errno, s)
|
||||
}
|
||||
|
||||
//
|
||||
|
@ -23,7 +23,7 @@ func TestRBDError(t *testing.T) {
|
||||
|
||||
err = GetError(-39) // NOTEMPTY (image still has a snapshot)
|
||||
assert.Error(t, err)
|
||||
assert.Equal(t, err.Error(), "rbd: ret=-39, Directory not empty")
|
||||
assert.Equal(t, err.Error(), "rbd: ret=39, Directory not empty")
|
||||
|
||||
err = GetError(345) // no such errno
|
||||
assert.Error(t, err)
|
||||
|
Loading…
Reference in New Issue
Block a user