-
Notifications
You must be signed in to change notification settings - Fork 150
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: return the read sectors length when it reads the expansion part #986
fix: return the read sectors length when it reads the expansion part #986
Conversation
Test is now running
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The read count of the below d.files[target].ReadAt(newBuf, offset)
can be smaller than bufLength
.
For example:
buf [xxxxxxxx]
newBuf [xxxx]
disk [xxxx]
diffDisk.read
will return len(newBuf) = 4
rather than len(buf) = 8
. Then the upper caller final result won't be the length the application wants to read
Good catch. So maybe we should always return func (d *diffDisk) read(target byte, buf []byte, startOffset int64, startSector int64, sectors int64) (int, error) {
bufStart := startSector * d.sectorSize
bufLength := sectors * d.sectorSize
offset := startOffset + bufStart
size, err := d.files[target].Size()
if err != nil {
return 0, err
}
// Reading the out-of-bound part is not allowed
if bufLength > d.size-offset {
logrus.Warn("Trying to read the out-of-bound part")
return 0, io.ErrUnexpectedEOF
}
// May read the expanded part
if offset >= size {
return int(bufLength), nil
}
var newBuf []byte
if bufLength > size-offset {
newBuf = buf[bufStart : bufStart+size-offset]
} else {
newBuf = buf[bufStart : bufStart+bufLength]
}
count, err := d.files[target].ReadAt(newBuf, offset)
if err != nil {
return count, err
}
return int(bufLength), nil
} |
I have summarize all the case for I think the point here is that when reading from the
Steps:
But if the Note: the "fill in 0" here, we don't actually do anything, the buf[] is already init to 0
In this case the uppercaller
and even Volume EOF, the count would be correct and the |
f95a5d4
to
16392d2
Compare
Manual Test - PASSEDtest with the original harvester test case
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need some unit test for this modification
16392d2
to
a6a8e22
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
ref: longhorn/longhonr 6899 Signed-off-by: Jack Lin <[email protected]>
a6a8e22
to
4ea8da1
Compare
Hi @PhanLe1010 @derekbit |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM and just one remaining question.
@mergify backport v1.6.x v1.5.x v1.4.x |
✅ Backports have been created
|
ref: longhorn/longhorn#6899
I think we should still return
len(read sectors)
when reading out of the boundary (expansion part of the specific image)The reason is that, from the caller's perspective, it is reading from the
"Volume"
So it has no knowledge about the snapshot chain underneath.
If it reads outside of the boundary of the
"Volume"
, we do returnio.ErrUnexpectedEOF
error hereBut if it only reads outside of the boundary of
"specific snapshot image"
, and we allow it to do so, then we should consider it as reading a bunch of "0", and that is also true. The caller does get a bunch of "0".The caller should not take care of the situation.
It might get confused that it doesn't get EOF error but how come the data length is not correct.