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 <ndevos@redhat.com>
This commit is contained in:
Niels de Vos 2020-01-22 16:27:34 +01:00
parent 224217212d
commit 508f808017
1 changed files with 2 additions and 2 deletions

View File

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