-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
machine: add sparse file writer #21763
Conversation
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: giuseppe The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
this is great work @giuseppe I am currently testing this ... code wise, LGTM |
8f4eab0
to
9320bb2
Compare
circling back, seems to work nicely |
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.
I'll need to test this in crc as this is a more sophisticated version of what we have, code makes sense, though devil will be in the small details.
9320bb2
to
3b0c391
Compare
Logic looks fine. Not sure about not letting the caller control the permissions bits. |
should we export |
Signed-off-by: Giuseppe Scrivano <[email protected]>
3b0c391
to
0b86135
Compare
I've changed the API to export only newSparseWriterToFile and not have the method to create directly a file. That can be done by the caller. @baude does the new API work fine for you? |
it looks fine i think ... /hold |
/hold cancel |
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.
This LGTM as for correctness of the output. As for creating the holes exactly in the desired situations, that seems that it might be possible to improve.
Also it vaguely seems to me that we shouldn’t need 3 separate state variables, but I’m not sure about that part yet.
} | ||
} | ||
|
||
m.buffer.Next(int(m.pos) - m.buffer.Len()) |
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.
I don’t understand what this is intended to do.
- AFAICS it always calls
Next(0)
, which does nothing - If it did something, moving the read offset would interfere with the
bytes.Equal
ensuring the expected output.
return nil | ||
} | ||
|
||
func testInputWithWriteLen(t *testing.T, input []byte, chunkSize int) { |
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.
Ensuring the implementation correctly preserves data is definitely valuable; I’d also like the test to ensure that code does create the expected holes.
// add "hello" in the middle | ||
largeInput = make([]byte, 1024*1024) | ||
copy(largeInput[len(largeInput)/2:], []byte("hello")) | ||
testInput(t, largeInput) |
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.
A hole (small and large) in the middle is also a possible case to test.
sw.file.Close() | ||
return err | ||
} | ||
if sw.lastIsZero { |
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.
In many (all I think?) situations this code can create a 1-byte shorter hole in the first place, instead of having to seek back.
1d4651b
into
containers:main
Consider reformulating as https://github.com/mtrmac/libpod/tree/sparse ; AFAICS that’s exactly the same logic, but, I think, rather easier to prove correct. |
would you mind opening a PR with your fixes? |
#21797, for the record. And yes, it is exactly the same logic, apart from the handling of zeroes at the very end. |
Does this PR introduce a user-facing change?