From 508f808017a73decdeb5e4d000d592b4527506d8 Mon Sep 17 00:00:00 2001 From: Niels de Vos Date: Wed, 22 Jan 2020 16:27:34 +0100 Subject: [PATCH] rbd: WriteAt() should return io.EOF on short reads The case of a short read is not detected correctly. This causes ReadAt() to not return io.EOF where it is expected. By comparing 'len(data)' instead of unassigned 'n' (set to 0), the number of bytes that have been read can be compared to the number of bytes that were requested. Signed-off-by: Niels de Vos --- rbd/rbd.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rbd/rbd.go b/rbd/rbd.go index 5b1a1e5..5b77aae 100644 --- a/rbd/rbd.go +++ b/rbd/rbd.go @@ -955,7 +955,7 @@ func (image *Image) Discard(ofs uint64, length uint64) (int, error) { return int(ret), nil } -func (image *Image) ReadAt(data []byte, off int64) (n int, err error) { +func (image *Image) ReadAt(data []byte, off int64) (int, error) { if err := image.validate(imageIsOpen); err != nil { return 0, err } @@ -974,7 +974,7 @@ func (image *Image) ReadAt(data []byte, off int64) (n int, err error) { return 0, RBDError(ret) } - if ret < n { + if ret < len(data) { return ret, io.EOF }