Skip to content

Support rate-limiters and read-only for drive mounts. #332

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

Merged
merged 1 commit into from
Nov 19, 2019

Conversation

sipsma
Copy link
Contributor

@sipsma sipsma commented Nov 15, 2019

Signed-off-by: Erik Sipsma [email protected]

Resolves #296

There is an unrelated failing integ test that seems like it will be fixed by #331

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

// (Optional) If set to true, IsReadOnly results in the backing file for the
// drive being opened as read-only by the Firecracker VMM on the host, preventing
// any writes to the image from within the guest.
bool IsReadOnly = 6;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we negate the flag to IsWritable? Mostly because FirecrackerRootDrive has that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call, updated. As a result I needed to add a little more functionality though because Linux will default a mount to "rw" if not otherwise specified. So this meant that if a DriveMount was read-only by default then the user would get an error unless they explicitly set "ro" in their mount options, which kind of sucks. So I updated the implementation to check that the IsWritable field matches what was specified in the mount options or, if there was no ro/rw option specified, explicitly sets it on behalf of the user.


return paths, nil
func stubPathToDriveID(stubPath string) string {
Copy link
Contributor

@kzys kzys Nov 15, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain which characters are problematic in a comment?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Base64 will remove "/" but may contain "-" in the output. We could use Base32 instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! I didn't know that. Switched to Base32 and also switched to using just the base name of the stub file (which is unique per shim/vm anyways) so the length of the drive ids doesn't get too outrageous.

Copy link
Contributor

@xibz xibz Nov 16, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a test that has an invalid stubPath just to ensure that this doesn't regress and is being used properly?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a test that has an invalid stubPath just to ensure that this doesn't regress and is being used properly?

I'm not sure I follow how we could create an invalid stubPath as the implementation of our code now shouldn't have any invalid values for a stubPath. Would the test create a drive id with an invalid character and then provide that directly to the firecracker API? That wouldn't really be a test of our code.

The only thing I can think of here would be to do some kind of general fuzz testing on our api to try to find inputs that create errors, but that seems like a much, much larger effort outside of scope here.

Copy link
Contributor

@xibz xibz Nov 18, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would the test create a drive id with an invalid character and then provide that directly to the firecracker API? That wouldn't really be a test of our code.

Yea, I was thinking this, just to ensure that it is encoding it properly. You should then be able to read the stub drive at the given base32 path

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ohh you just mean this function in isolation, I see, I was thinking about some way to get an invalid stub path passed to this function. Yeah I will add a test that does a regex check on the output of this function for some paths with invalid chars.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated with that test

@sipsma sipsma force-pushed the drivemount-rl-ro branch 2 times, most recently from 02cd13e to 2182d33 Compare November 15, 2019 23:46
Copy link
Contributor

@xibz xibz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really like the changes here. I had a couple comments, but nothing major.

type StubDriveHandler struct {
freeDrives []*stubDrive
// map of id -> stub drive being used by that task
usedDrives map[string]*stubDrive
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the purpose of this field? I don't really see it used anywhere other than being set

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm just laying some groundwork for the implementation of #243 to build off of, which I am personally okay with since it's not complicating anything at the moment. If there's disagreement with including it even though it technically doesn't need to exist yet, then I can remove for now, let me know.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, okay. I was just making sure it was there intentionally. I am okay with leaving it.


return paths, nil
func stubPathToDriveID(stubPath string) string {
Copy link
Contributor

@xibz xibz Nov 16, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a test that has an invalid stubPath just to ensure that this doesn't regress and is being used properly?

@sipsma sipsma merged commit 092c57b into firecracker-microvm:master Nov 19, 2019
fangn2 pushed a commit to fangn2/firecracker-containerd that referenced this pull request Mar 23, 2023
Memory ballooning support on firecracker-go-sdk.
Add wrappers for the Firecracker endpoints "/ballloon", "/balloon/statistics".

Signed-off-by: Royce Zhao <[email protected]>
BenjaminChun pushed a commit to char-1ee/firecracker-containerd that referenced this pull request Apr 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support RateLimiters and ReadOnly for DriveMounts
3 participants