rbd: Read() should return io.EOF on short reads

The case of a short read is not detected correctly. This causes Read()
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 17:03:06 +01:00
parent de60dcb33b
commit 522182cbc3
1 changed files with 2 additions and 2 deletions

View File

@ -876,7 +876,7 @@ func (image *Image) BreakLock(client string, cookie string) error {
// const char *fromsnapname,
// uint64_t ofs, uint64_t len,
// int (*cb)(uint64_t, size_t, int, void *), void *arg);
func (image *Image) Read(data []byte) (n int, err error) {
func (image *Image) Read(data []byte) (int, error) {
if err := image.validate(imageIsOpen); err != nil {
return 0, err
}
@ -896,7 +896,7 @@ func (image *Image) Read(data []byte) (n int, err error) {
}
image.offset += int64(ret)
if ret < n {
if ret < len(data) {
return ret, io.EOF
}