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:
John Mulligan 2019-12-12 14:02:44 -05:00 committed by Niels de Vos
parent bd99f64517
commit 811f851c99
2 changed files with 6 additions and 14 deletions

View File

@ -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)
}
//

View File

@ -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)